diff --git a/.gitignore b/.gitignore index d0f42167dbd53b4bedadc0a8988e4646e9fb2972..2a23da7872b255928df7d4d3d547cc6a41e8326f 100644 --- a/.gitignore +++ b/.gitignore @@ -17,3 +17,4 @@ ets2panda/linter*/test_rules/**/results ets2panda/linter*/**/package-lock.json **/compile_commands.json .cache +.vscode diff --git a/BUILD.gn b/BUILD.gn index 55271486dffafa6bf7fb0cfc0c4ee5c30dd14cba..a5886a881d8bdacfcc61ec8914e18018eed0af6f 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -17,5 +17,6 @@ group("ets_frontend_build") { deps = [ "./es2panda:es2panda_build", "./merge_abc:merge_proto_abc_build", + "./arkfuzzer:arkfuzzer_build", ] } diff --git a/arkfuzzer/BUILD.gn b/arkfuzzer/BUILD.gn new file mode 100755 index 0000000000000000000000000000000000000000..9abeee3eae9d5ba1118d66ed5f17026c497c2397 --- /dev/null +++ b/arkfuzzer/BUILD.gn @@ -0,0 +1,40 @@ +import("//arkcompiler/ets_frontend/es2panda/es2abc_config.gni") +import("//arkcompiler/ets_frontend/ets_frontend_config.gni") +import("//arkcompiler/runtime_core/ark_config.gni") + + +ohos_executable("arkfuzzer") { + use_exceptions = true + + sources = [ + "main.cpp", + "cov/cov.cpp" + ] + + include_dirs = [ + "./cov" + ] + + cflags = [] + cflags += [ "-fsanitize-coverage=trace-pc-guard" ] + + ldflags = [] + ldflags += [ "-Wl,-Bstatic" ] + ldflags += [ "-lstdc++" ] + ldflags += [ "-Wl,-Bdynamic" ] + + install_enable = false + + part_name = "ets_frontend" + subsystem_name = "arkcompiler" +} + +group("arkfuzzer_build") { + if (host_os == "linux") { + deps = [ ":arkfuzzer(${toolchain_linux})" ] + } + + if (host_os == "mac") { + deps = [ ":arkfuzzer(${toolchain_mac})" ] + } +} \ No newline at end of file diff --git a/arkfuzzer/cov/cov.cpp b/arkfuzzer/cov/cov.cpp new file mode 100755 index 0000000000000000000000000000000000000000..7175cb650f3111c0a950bf8a12253e3230747287 --- /dev/null +++ b/arkfuzzer/cov/cov.cpp @@ -0,0 +1,140 @@ +#include "cov.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define SHM_SIZE 0x100000 +#define MAX_EDGES ((SHM_SIZE - 4) * 8) + +struct shmem_data { + uint32_t num_edges; + // unsigned char edges[]; + unsigned char edges[1]; +}; + +struct shmem_data* shmem; + +uint32_t *edges_start, *edges_stop; +// uint32_t builtins_start; +// uint32_t builtins_edge_count; + +void sanitizer_cov_reset_edgeguards() { + uint32_t N = 0; + for (uint32_t* x = edges_start; x < edges_stop && N < MAX_EDGES; x++) + *x = ++N; +} + +extern "C" void __sanitizer_cov_trace_pc_guard_init(uint32_t* start, + uint32_t* stop) { + // We should initialize the shared memory region only once. We can initialize + // it multiple times if it's the same region, which is something that appears + // to happen on e.g. macOS. If we ever see a different region, we will likely + // overwrite the previous one, which is probably not intended and as such we + // fail with an error. + if (shmem) { + if (!(edges_start == start && edges_stop == stop)) { + fprintf(stderr, + "[COV] Multiple initialization of shmem!" + " This is probably not intended! Currently only one edge" + " region is supported\n"); + _exit(-1); + } + // Already initialized. + return; + } + // Map the shared memory region + const char* shm_key = getenv("SHM_ID"); + if (!shm_key) { + puts("[COV] no shared memory bitmap available, skipping"); + shmem = (struct shmem_data*)malloc(SHM_SIZE); + } else { + int fd = shm_open(shm_key, O_RDWR, S_IREAD | S_IWRITE); + if (fd <= -1) { + fprintf(stderr, "[COV] Failed to open shared memory region\n"); + _exit(-1); + } + + shmem = (struct shmem_data*)mmap(0, SHM_SIZE, PROT_READ | PROT_WRITE, + MAP_SHARED, fd, 0); + if (shmem == MAP_FAILED) { + fprintf(stderr, "[COV] Failed to mmap shared memory region\n"); + _exit(-1); + } + } + + edges_start = start; + edges_stop = stop; + sanitizer_cov_reset_edgeguards(); + + shmem->num_edges = static_cast(stop - start); +// builtins_start = 1 + shmem->num_edges; + printf("[COV] edge counters initialized. Shared memory: %s with %u edges\n", + shm_key, shmem->num_edges); +} + +uint32_t sanitizer_cov_count_discovered_edges() { + uint32_t on_edges_counter = 0; + for (uint32_t i = 1; i < 1 + shmem->num_edges; ++i) { + const uint32_t byteIndex = i >> 3; // Divide by 8 using a shift operation + const uint32_t bitIndex = i & 7; // Modulo 8 using a bitwise AND operation + + if (shmem->edges[byteIndex] & (1 << bitIndex)) { + ++on_edges_counter; + } + } + return on_edges_counter; +} + +extern "C" void __sanitizer_cov_trace_pc_guard(uint32_t* guard) { + // There's a small race condition here: if this function executes in two + // threads for the same edge at the same time, the first thread might disable + // the edge (by setting the guard to zero) before the second thread fetches + // the guard value (and thus the index). However, our instrumentation ignores + // the first edge (see libcoverage.c) and so the race is unproblematic. + uint32_t index = *guard; + shmem->edges[index / 8] |= 1 << (index % 8); + *guard = 0; +} + +/* +void cov_init_builtins_edges(uint32_t num_edges) { + if (num_edges + shmem->num_edges > MAX_EDGES) { + printf( + "[COV] Error: Insufficient amount of edges left for builtins " + "coverage.\n"); + exit(-1); + } + builtins_edge_count = num_edges; + builtins_start = 1 + shmem->num_edges; + shmem->num_edges += builtins_edge_count; + printf("[COV] Additional %d edges for builtins initialized.\n", num_edges); +} +*/ + +// This function is ran once per REPRL loop. In case of crash the coverage of +// crash will not be stored in shared memory. Therefore, it would be useful, if +// we could store these coverage information into shared memory in real time. +/* +void cov_update_builtins_basic_block_coverage( + const std::vector& cov_map) { + if (cov_map.size() != builtins_edge_count) { + printf("[COV] Error: Size of builtins cov map changed.\n"); + exit(-1); + } + for (uint32_t i = 0; i < cov_map.size(); ++i) { + if (cov_map[i]) { + const uint32_t byteIndex = (i + builtins_start) >> 3; + const uint32_t bitIndex = (i + builtins_start) & 7; + + shmem->edges[byteIndex] |= (1 << bitIndex); + } + } +} +*/ \ No newline at end of file diff --git a/arkfuzzer/cov/cov.h b/arkfuzzer/cov/cov.h new file mode 100755 index 0000000000000000000000000000000000000000..0b58c8971ae8932b0502a2eb78065ff239c2c3da --- /dev/null +++ b/arkfuzzer/cov/cov.h @@ -0,0 +1,17 @@ +#ifndef _ARKFUZZZER_COV_H_ +#define _ARKFUZZZER_COV_H_ + +// This file is defining functions to handle coverage which are needed for +// fuzzilli fuzzer It communicates coverage bitmap with fuzzilli through shared +// memory +// https://clang.llvm.org/docs/SanitizerCoverage.html + +#include +#include + +void sanitizer_cov_reset_edgeguards(); +uint32_t sanitizer_cov_count_discovered_edges(); +// void cov_init_builtins_edges(uint32_t num_edges); +// void cov_update_builtins_basic_block_coverage(const std::vector& cov_map); + +#endif // _ARKFUZZZER_COV_H_ \ No newline at end of file diff --git a/arkfuzzer/gen_abc.py b/arkfuzzer/gen_abc.py new file mode 100644 index 0000000000000000000000000000000000000000..2223af42a199ed3b37eaa7e11caddf71e6ff8624 --- /dev/null +++ b/arkfuzzer/gen_abc.py @@ -0,0 +1,278 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- + +""" +Copyright (c) 2021 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. + +Description: Use ark to execute fuzzilli test suite + +用于通过js生成abc +""" + +import argparse +import datetime +import collections +import json +import os +import shutil +import sys +import subprocess +from multiprocessing import Pool +import platform + +sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))) +from test262.utils import * +from test262.config import * + + +def parse_args(): + parser = argparse.ArgumentParser() + parser.add_argument('--dir', metavar='DIR', + help='Directory to test ') + parser.add_argument('--file', metavar='FILE', + required=True, + help='File to test') + parser.add_argument('--mode', + nargs='?', choices=[1, 2, 3], type=int, + help='selection information as: ' + + '1: only default \n ' + + '2: only strict mode \n' + + '3: both default and strict mode\n') + parser.add_argument('--es51', action='store_true', + help='Run test262 ES5.1 version') + parser.add_argument('--es2021', default=False, const='all', + nargs='?', choices=['all', 'only'], + help='Run test262 - ES2021. ' + + 'all: Contains all use cases for es5_tests and es2015_tests and es2021_tests and intl_tests' + + 'only: Only include use cases for ES2021') + parser.add_argument('--es2022', default=False, const='all', + nargs='?', choices=['all', 'only'], + help='Run test262 - ES2022. ' + + 'all: Contains all use cases for es5_tests and es2015_tests and es2021_tests' + + 'and es2022_tests and intl_tests' + + 'only: Only include use cases for ES2022') + parser.add_argument('--es2023', default=False, const='all', + nargs='?', choices=['all', 'only'], + help='Run test262 - ES2023. ' + + 'all: Contains all use cases for es5_tests and es2015_tests and es2021_tests' + + 'and es2022_tests and es2023_tests and intl_tests' + + 'only: Only include use cases for ES2023') + parser.add_argument('--intl', default=False, const='intl', + nargs='?', choices=['intl'], + help='Run test262 - Intltest. ' + + 'intl: Only include use cases for intlcsae') + parser.add_argument('--es2015', default=False, const='es2015', + nargs='?', choices=['es2015'], + help='Run test262 - es2015. ' + + 'es2015: Only include use cases for es2015') + parser.add_argument('--ci-build', action='store_true', + help='Run test262 ES2015 filter cases for build version') + parser.add_argument('--esnext', action='store_true', + help='Run test262 - ES.next.') + parser.add_argument('--engine', metavar='FILE', + help='Other engine binarys to run tests(as:d8,qjs...)') + parser.add_argument('--babel', action='store_true', + help='Whether to use Babel conversion') + parser.add_argument('--timeout', default=DEFAULT_TIMEOUT, type=int, + help='Set a custom test timeout in milliseconds !!!\n') + parser.add_argument('--threads', default=DEFAULT_THREADS, type=int, + help="Run this many tests in parallel.") + parser.add_argument('--hostArgs', + help="command-line arguments to pass to eshost host\n") + parser.add_argument('--ark-tool', + help="ark's binary tool") + parser.add_argument('--ark-aot', action='store_true', + help="Run test262 with aot") + parser.add_argument('--ark-aot-tool', + help="ark's aot tool") + parser.add_argument("--libs-dir", + help="The path collection of dependent so has been divided by':'") + parser.add_argument('--ark-frontend', + nargs='?', choices=ARK_FRONTEND_LIST, type=str, + help="Choose one of them") + parser.add_argument('--ark-frontend-binary', + help="ark frontend conversion binary tool") + parser.add_argument('--ark-arch', + default=DEFAULT_ARK_ARCH, + nargs='?', choices=ARK_ARCH_LIST, type=str, + help="Choose one of them") + parser.add_argument('--ark-arch-root', + default=DEFAULT_ARK_ARCH, + help="the root path for qemu-aarch64 or qemu-arm") + parser.add_argument('--opt-level', + default=DEFAULT_OPT_LEVEL, + help="the opt level for es2abc") + parser.add_argument('--es2abc-thread-count', + default=DEFAULT_ES2ABC_THREAD_COUNT, + help="the thread count for es2abc") + parser.add_argument('--merge-abc-binary', + help="frontend merge abc binary tool") + parser.add_argument('--merge-abc-mode', + help="run test for merge abc mode") + parser.add_argument('--product-name', + default=DEFAULT_PRODUCT_NAME, + help="ark's product name") + parser.add_argument('--run-pgo', action='store_true', + help="Run test262 with aot pgo") + parser.add_argument('--open-fuzzy-mode', action='store_true', default=DEFAULT_OPEN_FUZZILLI_MODE, + help='run test with open fuzzilli mode') + return parser.parse_args() + + +def run_check(runnable, env=None): + report_command('Test command:', runnable, env=env) + + if env is not None: + full_env = dict(os.environ) + full_env.update(env) + env = full_env + + proc = subprocess.Popen(runnable, env=env) + stdout, stderr = proc.communicate() + if stdout: + print(f'Out message:{stdout.decode()}') + if stderr: + print(f'Error message:{stderr.decode()}') + return proc.returncode + + +def get_host_path_type(args): + host_path = DEFAULT_HOST_PATH + host_type = DEFAULT_HOST_TYPE + if args.engine: + host_path = args.engine + host_type = os.path.split(args.engine.strip())[1] + return host_path, host_type + + +def get_host_args(args, host_type): + """ + Use the default values or override the corresponding parameters based on user input + :param args: + :param host_type: + :return: + """ + host_args = "" + ark_tool = DEFAULT_ARK_TOOL + ark_aot_tool = DEFAULT_ARK_AOT_TOOL + libs_dir = DEFAULT_LIBS_DIR + ark_frontend = ARK_FRONTEND_LIST[1] + ark_frontend_binary = FUZZY_DEFAULT_ARK_FRONTEND_BINARY + ark_arch = DEFAULT_ARK_ARCH + opt_level = DEFAULT_OPT_LEVEL + es2abc_thread_count = DEFAULT_ES2ABC_THREAD_COUNT + merge_abc_binary = DEFAULT_MERGE_ABC_BINARY + merge_abc_mode = DEFAULT_MERGE_ABC_MODE + product_name = RK3568_PRODUCT_NAME + + if args.product_name: + product_name = args.product_name + ark_dir = f"{ARGS_PREFIX}{product_name}{ARK_DIR_SUFFIX}" + icui_dir = f"{ARGS_PREFIX}{product_name}{ICUI_DIR_SUFFIX}" + ark_js_runtime_dir = f"{ARGS_PREFIX}{product_name}{ARK_JS_RUNTIME_DIR_SUFFIX}" + zlib_dir = f"{ARGS_PREFIX}{product_name}{ZLIB_DIR_SUFFIX}" + + ark_tool = os.path.join(ark_js_runtime_dir, "ark_js_vm") + libs_dir = f"{icui_dir}:{LLVM_DIR}:{ark_js_runtime_dir}:{zlib_dir}" + ark_aot_tool = os.path.join(ark_js_runtime_dir, "ark_aot_compiler") + merge_abc_binary = os.path.join(ark_dir, "merge_abc") + + if args.hostArgs: + host_args = args.hostArgs + + if args.ark_tool: + ark_tool = args.ark_tool + + if args.ark_aot_tool: + ark_aot_tool = args.ark_aot_tool + + if args.libs_dir: + libs_dir = args.libs_dir + + if args.ark_frontend: + ark_frontend = args.ark_frontend + + if args.ark_frontend_binary: + ark_frontend_binary = args.ark_frontend_binary + + if args.opt_level: + opt_level = args.opt_level + + if args.es2abc_thread_count: + es2abc_thread_count = args.es2abc_thread_count + + if args.merge_abc_binary: + merge_abc_binary = args.merge_abc_binary + + if args.merge_abc_mode: + merge_abc_mode = args.merge_abc_mode + + if host_type == DEFAULT_HOST_TYPE: + host_args = f"-B test262/run_sunspider.py " + host_args += f"--ark-tool={ark_tool} " + if args.ark_aot: + host_args += f"--ark-aot " + if args.run_pgo: + host_args += f"--run-pgo " + host_args += f"--ark-aot-tool={ark_aot_tool} " + host_args += f"--libs-dir={libs_dir} " + host_args += f"--ark-frontend={ark_frontend} " + host_args += f"--ark-frontend-binary={ark_frontend_binary} " + host_args += f"--opt-level={opt_level} " + host_args += f"--es2abc-thread-count={es2abc_thread_count} " + host_args += f"--merge-abc-binary={merge_abc_binary} " + host_args += f"--merge-abc-mode={merge_abc_mode} " + host_args += f"--product-name={product_name} " + + if args.ark_arch != ark_arch: + host_args += f"--ark-arch={args.ark_arch} " + host_args += f"--ark-arch-root={args.ark_arch_root} " + + return host_args + + +def run_fuzzy_test(args): + """ + :param args: + :return: + """ + host_path, host_type = get_host_path_type(args) + host_args = get_host_args(args, host_type) + fuzzy_js_file = args.file + host_args = host_args.replace(fuzzy_js_file, '') + test_cmd = ['python3'] + host_args.strip().split(' ') + test_cmd.append(f"--js-file={fuzzy_js_file}") + return run_check(test_cmd) + + +Check = collections.namedtuple('Check', ['enabled', 'runner', 'arg']) + + +def main(args): + if args.open_fuzzy_mode: + print("\nWait a moment..........\n") + start_time = datetime.datetime.now() + check = Check(True, run_fuzzy_test, args) + ret = check.runner(check.arg) + if ret: + sys.exit(ret) + end_time = datetime.datetime.now() + print(f"used time is: {str(end_time - start_time)}") + else: + print('You should execute the script with open fuzzilli mode by `--open-fuzzy-mode`!') + sys.exit(1) + + +if __name__ == "__main__": + sys.exit(main(parse_args())) diff --git a/arkfuzzer/main.cpp b/arkfuzzer/main.cpp new file mode 100755 index 0000000000000000000000000000000000000000..db99d057e6298032a3c18503dad02c8f54754c1a --- /dev/null +++ b/arkfuzzer/main.cpp @@ -0,0 +1,141 @@ +#include +#include +#include +#include +#include +#include "cov/cov.h" + +#define REPRL_CRFD 100 // Control read file decriptor +#define REPRL_CWFD 101 // Control write file decriptor +#define REPRL_DRFD 102 // Data read file decriptor +#define REPRL_DWFD 103 // Data write file decriptor +std::ofstream eslog("es2abc.log", std::ios::trunc); + +bool fuzzilli_reprl = true; +#define TESTCASE_JS_FILE_PATH "/home/fuzzilli/fuzzilli/Targets/ES2ABC/out/" +#define JSTESTCASE_FILE_NAME_LEN 64 +#define COV_INIT_BUILTINS_EDGES 128 +#define RUN_PYTHON_CMD_LEN 1024 +#define EXECUTE_JSTESTCASE_BY_PYTHON "cd /home/openharmony/code/arkcompiler/ets_frontend;\ +python3 arkfuzzer/gen_abc.py --file %s --es2021 all \ +--ark-frontend-binary=../../out/rk3568/clang_x64/arkcompiler/ets_frontend/es2abc \ +--ark-frontend=es2panda --product-name=rk3568 --open-fuzzy-mode 2>&1" + +int Execute(char *js_name, int name_len) +{ + size_t script_size; + unsigned action = 0; + + ssize_t nread = read(REPRL_CRFD, &action, 4); + if (nread != 4 || action != 'cexe') { + eslog << "REPRL: Unknown action: %u" << action << " line = " << __LINE__ << std::endl; + return 1; // fail + } + + if (read(REPRL_CRFD, &script_size, 8) != 8) { + eslog << "execute read fail!" + << " line = " << __LINE__ << std::endl; + return 1; + } + if (script_size == 0) { + return 0; + } + char *buffer = new char[script_size + 1]; + char *ptr = buffer; + size_t remaining = script_size; + while (remaining > 0) { + ssize_t rv = read(REPRL_DRFD, ptr, remaining); + if (rv == 0) + { + eslog << "read finished!!!" + << " line = " << __LINE__ << std::endl; + break; + } + remaining -= rv; + ptr += rv; + } + + // generate js testcase file + buffer[script_size] = 0; + static int index = 0; + snprintf(js_name, name_len - 1, "%s%d.js", TESTCASE_JS_FILE_PATH, index); + std::string js_testcase_name = js_name; + std::ofstream js_testcase(js_testcase_name, std::ios::trunc); + js_testcase << buffer << std::endl; + delete[] buffer; + + int res = 0; + + // run received js test case by python + char cmd[RUN_PYTHON_CMD_LEN] = {0}; + char buff[1024] = {0}; + + FILE *pr = nullptr; + + snprintf(cmd, RUN_PYTHON_CMD_LEN - 1, EXECUTE_JSTESTCASE_BY_PYTHON, js_name); + if ((pr = popen(cmd, "r")) != nullptr) { + while (fgets(buff, sizeof(buff) - 1, pr) != nullptr) { + if (!strstr(buff, "Test command")) { + res = 1; + } + break; + } + } + pclose(pr); + + index++; + + return res; +} + +bool InitialReprl() +{ + char helo[] = "HELO"; + if (write(REPRL_CWFD, helo, 4) != 4 || read(REPRL_CRFD, helo, 4) != 4) { + eslog << "write or read fail" << __LINE__ << std::endl; + return false; + } + + if (memcmp(helo, "HELO", 4) != 0) { + eslog << "REPRL: Invalid response from parent" << __LINE__ << std::endl; + return false; + } + + return true; +} + +bool DealResult(int result) +{ + int status = result << 8; + bool res = true; + fflush(stdout); + fflush(stderr); + if (write(REPRL_CWFD, &status, 4) != 4) { + eslog << "Deal result write fail!" << __LINE__ << std::endl; + res = false; + } + sanitizer_cov_reset_edgeguards(); + + return res; +} + +int main(int argc, char **argv) +{ + int result = 0; + char js_name[JSTESTCASE_FILE_NAME_LEN] = {0}; + + if (!InitialReprl()) { + return 1; + } + + do { + result = Execute(js_name, sizeof(js_name)); + + if (!DealResult(result)) { + fuzzilli_reprl = false; + eslog << "DealResult" << __LINE__ << std::endl; + } + } while (fuzzilli_reprl); + + return 0; +} \ No newline at end of file diff --git a/arkfuzzer/run_test_fuzzy.py b/arkfuzzer/run_test_fuzzy.py new file mode 100755 index 0000000000000000000000000000000000000000..5db85c90e74b4093c78f64e9a3197d128cbd3eda --- /dev/null +++ b/arkfuzzer/run_test_fuzzy.py @@ -0,0 +1,268 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- + +""" +Copyright (c) 2021 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. + +Description: Use ark to execute fuzzilli test suite +""" + +import argparse +import datetime +import collections +import json +import os +import shutil +import sys +import subprocess +from multiprocessing import Pool +import platform +import tarfile + +sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))) +from test262.utils import * +from test262.config import * + +SWIFT_DOWNLOAD_URL = 'https://download.swift.org/swift-5.9.2-release/ubuntu1804/swift-5.9.2-RELEASE/swift-5.9.2-RELEASE-ubuntu18.04.tar.gz' + + +def parse_args(): + parser = argparse.ArgumentParser() + parser.add_argument('--dir', metavar='DIR', + help='Directory to test ') + parser.add_argument('--file', metavar='FILE', + required=True, + help='File to test') + parser.add_argument('--mode', + nargs='?', choices=[1, 2, 3], type=int, + help='selection information as: ' + + '1: only default \n ' + + '2: only strict mode \n' + + '3: both default and strict mode\n') + parser.add_argument('--es51', action='store_true', + help='Run test262 ES5.1 version') + parser.add_argument('--es2021', default=False, const='all', + nargs='?', choices=['all', 'only'], + help='Run test262 - ES2021. ' + + 'all: Contains all use cases for es5_tests and es2015_tests and es2021_tests and intl_tests' + + 'only: Only include use cases for ES2021') + parser.add_argument('--es2022', default=False, const='all', + nargs='?', choices=['all', 'only'], + help='Run test262 - ES2022. ' + + 'all: Contains all use cases for es5_tests and es2015_tests and es2021_tests' + + 'and es2022_tests and intl_tests' + + 'only: Only include use cases for ES2022') + parser.add_argument('--es2023', default=False, const='all', + nargs='?', choices=['all', 'only'], + help='Run test262 - ES2023. ' + + 'all: Contains all use cases for es5_tests and es2015_tests and es2021_tests' + + 'and es2022_tests and es2023_tests and intl_tests' + + 'only: Only include use cases for ES2023') + parser.add_argument('--intl', default=False, const='intl', + nargs='?', choices=['intl'], + help='Run test262 - Intltest. ' + + 'intl: Only include use cases for intlcsae') + parser.add_argument('--es2015', default=False, const='es2015', + nargs='?', choices=['es2015'], + help='Run test262 - es2015. ' + + 'es2015: Only include use cases for es2015') + parser.add_argument('--ci-build', action='store_true', + help='Run test262 ES2015 filter cases for build version') + parser.add_argument('--esnext', action='store_true', + help='Run test262 - ES.next.') + parser.add_argument('--engine', metavar='FILE', + help='Other engine binarys to run tests(as:d8,qjs...)') + parser.add_argument('--babel', action='store_true', + help='Whether to use Babel conversion') + parser.add_argument('--timeout', default=DEFAULT_TIMEOUT, type=int, + help='Set a custom test timeout in milliseconds !!!\n') + parser.add_argument('--threads', default=DEFAULT_THREADS, type=int, + help="Run this many tests in parallel.") + parser.add_argument('--hostArgs', + help="command-line arguments to pass to eshost host\n") + parser.add_argument('--ark-tool', + help="ark's binary tool") + parser.add_argument('--ark-aot', action='store_true', + help="Run test262 with aot") + parser.add_argument('--ark-aot-tool', + help="ark's aot tool") + parser.add_argument("--libs-dir", + help="The path collection of dependent so has been divided by':'") + parser.add_argument('--ark-frontend', + nargs='?', choices=ARK_FRONTEND_LIST, type=str, + help="Choose one of them") + parser.add_argument('--ark-frontend-binary', + help="ark frontend conversion binary tool") + parser.add_argument('--ark-arch', + default=DEFAULT_ARK_ARCH, + nargs='?', choices=ARK_ARCH_LIST, type=str, + help="Choose one of them") + parser.add_argument('--ark-arch-root', + default=DEFAULT_ARK_ARCH, + help="the root path for qemu-aarch64 or qemu-arm") + parser.add_argument('--opt-level', + default=DEFAULT_OPT_LEVEL, + help="the opt level for es2abc") + parser.add_argument('--es2abc-thread-count', + default=DEFAULT_ES2ABC_THREAD_COUNT, + help="the thread count for es2abc") + parser.add_argument('--merge-abc-binary', + help="frontend merge abc binary tool") + parser.add_argument('--merge-abc-mode', + help="run test for merge abc mode") + parser.add_argument('--product-name', + default=DEFAULT_PRODUCT_NAME, + help="ark's product name") + parser.add_argument('--run-pgo', action='store_true', + help="Run test262 with aot pgo") + parser.add_argument('--open-fuzzy-mode', action='store_true', default=DEFAULT_OPEN_FUZZILLI_MODE, + help='run test with open fuzzilli mode') + return parser.parse_args() + + +def exec_command_communicate(cmd, shell_flag=False, timeout=600): + """ + Execute the cmd command to return the terminal output value + """ + proc = subprocess.Popen( + cmd, + stdout=subprocess.PIPE, + stderr=subprocess.PIPE, + encoding="utf-8", + universal_newlines=True, + shell=shell_flag + ) + out, error = proc.communicate(timeout=timeout) + ret_code = proc.returncode + return ret_code, out, error + + +class TestPrepare: + + def prepare_fuzzili_code(self): + """ + 1. Download the fuzzilli code + 2. Switch branches and specify commit + 3. Patch code + """ + if not os.path.isdir(os.path.join(FUZZY_DIR, '.git')): + git_clone(FUZZY_GIT_URL, FUZZY_DIR) + git_checkout(FUZZY_GIT_HASH, FUZZY_DIR) + # git_apply('../fuzzy.patch', FUZZY_DIR) # TODO: 需要根据实际修改 + + def get_sysctl_config(self): + cmd = ['sysctl', '-a', '|grep', 'kernel.core_pattern'] + ret, output, error = exec_command_communicate(cmd) + if not ret: + lines = output.split('\n') + config = {} + for line in lines: + if line.strip() != '': + key, value = line.split(' = ') + config[key.strip()] = value.strip() + return config + + def check_bin_false(self): + config = self.get_sysctl_config() + if config: + kcp_val = config.get('kernel.core_pattern') + return kcp_val == '|/bin/false' + + def kernel_core_pattern(self): + """ + Set temporary variables + """ + is_bin_false = self.check_bin_false() + if not is_bin_false: + cmd = ['sysctl', '-w', 'kernel.core_pattern=|/bin/false'] + ret, _, error = exec_command_communicate(cmd) + if ret: + raise SystemExit(f'Set kernel.core_pattern Error: {error}') + return 0 + + def do_fuzzy_compiler(self, profile='es2abc', storage_path=FUZZILLI_OUTPUT_DIR_NAME): + """ + Run the compilation command to generate the compiled result + """ + # mkdir for output + _output_dir = os.path.join(FUZZY_DIR, storage_path) + if not os.path.exists(_output_dir): + mkdir(_output_dir) + try: + swift_tool = check_swift() + except SystemExit: + swift_tool = prepare_swift() + + # change to child dir + os.chdir(FUZZY_DIR) + # where es2abc path + ejs_shell = ARK_FRONTEND_BINARY_LIST[1] + cmd = [swift_tool, 'run', '-c', 'release', '-Xlinker="-lrt"', 'FuzzilliCli', f'--profile={profile}', + f'--storagePath={_output_dir}', ejs_shell] + ret, _, error = exec_command_communicate(cmd) + if ret: + raise SystemExit(f'fuzzy compiler error: {error}') + return 0 + + def fuzzy_es2abc_action(self): + """ + 1. download fuzzilli code and apply patch + 2. check or set env + 3. compiler and output + """ + self.prepare_fuzzili_code() + self.kernel_core_pattern() + self.do_fuzzy_compiler() + + def run(self): + self.fuzzy_es2abc_action() + + +def prepare_swift(): + print('Start downloading swift……') + _cmd = ['wget', SWIFT_DOWNLOAD_URL] + ret, output, error = exec_command_communicate(_cmd) + if ret: + raise SystemExit(f'Download swift error: {error}') + print('Downloading swift finished.') + # 打开tar包 + with tarfile.open('swift-5.9.2-RELEASE-ubuntu18.04.tar.gz', 'r:gz') as tar: + # 解压所有文件 + tar.extractall() + + current_dir = os.getcwd() + swift_path = os.path.join(current_dir, 'swift-5.9.2-RELEASE-ubuntu18.04', 'usr', 'bin', 'swift') + try: + check_swift(swift_path) + except SystemExit as e: + raise SystemExit(str(e)) + return swift_path + + +def check_swift(swift_path='swift'): + version_cmd = [swift_path, '--version'] + ret, output, error = exec_command_communicate(version_cmd) + if ret: + raise SystemExit('Swift not found.') + print(output) + return swift_path + + +def main(): + test_prepare = TestPrepare() + test_prepare.run() + + +if __name__ == "__main__": + sys.exit(main()) diff --git a/arkguard/package.json b/arkguard/package.json index b189cb9bcfbf61dd06585e5df6681f5d3a9bd8b1..2e9f4294a6f6ec500877c7bdea3ff05631c02b32 100644 --- a/arkguard/package.json +++ b/arkguard/package.json @@ -1,6 +1,6 @@ { "name": "arkguard", - "version": "1.1.1", + "version": "1.1.2", "description": "An obfuscator tools for open harmony apps.", "bin": { "arkguard": "bin/secharmony" @@ -12,7 +12,7 @@ "build": "npm run clean && node node_modules/typescript/lib/tsc.js", "test": "npm run test:ut && npm run test:grammar", "test:ut": "node ./node_modules/mocha/bin/mocha --require ts-node/register ./test/ut/**/*.ts", - "test:grammar": "rm -rf test/local && node ./scripts/testScript.js && node ./scripts/grammarTestScript.js" + "test:grammar": "rm -rf test/local && node --loader ts-node/esm ./scripts/obfuscate_script.js && node --loader ts-node/esm ./scripts/execute_result_statistics.js" }, "repository": { "type": "git", diff --git a/arkguard/scripts/grammarTestScript.js b/arkguard/scripts/execute_result_statistics.js similarity index 84% rename from arkguard/scripts/grammarTestScript.js rename to arkguard/scripts/execute_result_statistics.js index 643af2330d51196dc18ec84b87b0c4f466ceb2df..d954643c93c4eb6247810fed0d34dd1bcc24aeb9 100644 --- a/arkguard/scripts/grammarTestScript.js +++ b/arkguard/scripts/execute_result_statistics.js @@ -16,6 +16,7 @@ const fs = require('fs'); const path = require('path'); const { execSync } = require('child_process'); +import { Extension } from '../src/common/type'; const testDirectory = path.resolve('./test/local'); @@ -59,18 +60,16 @@ function runTestsInDirectory(directoryPath) { if (fs.statSync(filePath).isDirectory()) { runTestsInDirectory(filePath); - } else if (filePath.includes('obfuscation_validation')) { - if (filePath.includes('assert.ts')) { - const isSuccess = runTest(filePath); - if (isSuccess) { - successCount++; - } else { - failureCount++; - failedFiles.push(filePath); - } + } else if (filePath.includes('assert-expectation.ts')) { + const isSuccess = runTest(filePath); + if (isSuccess) { + successCount++; + } else { + failureCount++; + failedFiles.push(filePath); } - } else if ((path.extname(filePath) === '.ts' || path.extname(filePath) === '.js') && (!filePath.endsWith('.d.ets') && - !filePath.endsWith('.d.ts'))) { + } else if ((filePath.endsWith(Extension.TS) || filePath.endsWith(Extension.JS)) && !(filePath.endsWith(Extension.DETS) || + filePath.endsWith(Extension.DTS))) { const isSuccess = runTest(filePath); if (isSuccess) { successCount++; diff --git a/arkguard/scripts/testScript.js b/arkguard/scripts/obfuscate_script.js similarity index 43% rename from arkguard/scripts/testScript.js rename to arkguard/scripts/obfuscate_script.js index a5dbb7116c8eb01b4ca98d24645972baf2926ff4..4ccfe3d718b322f2d123d10a5ed45e8a9a3a8796 100644 --- a/arkguard/scripts/testScript.js +++ b/arkguard/scripts/obfuscate_script.js @@ -16,48 +16,52 @@ const fs = require('fs'); const path = require('path'); const { exec } = require('child_process'); +import { Extension } from '../src/common/type'; function obfuscateDirs(obfConfig, obfDir) { - const command = `node --loader=ts-node/esm src/cli/SecHarmony.ts ${obfDir} --config-path ${obfConfig}` - exec(command, (error, stdout, stderr) => { - if (error) { - console.error(`Error executing command: ${error.message}`); - return; - } - }); + const command = `node --loader=ts-node/esm src/cli/SecHarmony.ts ${obfDir} --config-path ${obfConfig}`; + exec(command, (error, stdout, stderr) => { + if (error) { + console.error(`Error executing command: ${error.message}`); + return; + } + if (stdout) { + console.log('Debug info: ', stdout); + } + }); } - function traverseDirs(rootDirPath, configPath) { - const currentEntries = fs.readdirSync(rootDirPath); - let configFile = "obfConfig.json"; + const currentEntries = fs.readdirSync(rootDirPath); + let configFile = 'obfConfig.json'; + if (currentEntries.includes(configFile)) { + configPath = rootDirPath; + } - if (currentEntries.includes(configFile)) { - configPath = rootDirPath; - } - - const hasJsOrTsFiles = currentEntries.some(entry => entry.endsWith('.js') || entry.endsWith('.ts')); + const hasJsOrTsFiles = currentEntries.some(entry => { + return entry.endsWith(Extension.TS) || entry.endsWith(Extension.JS); + }); - if (hasJsOrTsFiles) { - obfuscateDirs(path.join(configPath, configFile), rootDirPath); - return; - } + if (hasJsOrTsFiles) { + obfuscateDirs(path.join(configPath, configFile), rootDirPath); + return; + } - for (const currentEntry of currentEntries) { - const currentPath = path.join(rootDirPath, currentEntry); - if (fs.statSync(currentPath).isDirectory()) { - traverseDirs(currentPath, configPath); - } + for (const currentEntry of currentEntries) { + const currentPath = path.join(rootDirPath, currentEntry); + if (fs.statSync(currentPath).isDirectory()) { + traverseDirs(currentPath, configPath); } + } } function run() { - const testCasesRootDir = path.join(__dirname, '../test/grammar'); - traverseDirs(testCasesRootDir, testCasesRootDir) + const testCasesRootDir = path.join(__dirname, '../test/grammar'); + traverseDirs(testCasesRootDir, testCasesRootDir); } function main() { - run(); + run(); } -main() \ No newline at end of file +main(); \ No newline at end of file diff --git a/arkguard/src/common/type.ts b/arkguard/src/common/type.ts new file mode 100644 index 0000000000000000000000000000000000000000..960a83955a71cc3508a9f89110b34af54a0101ab --- /dev/null +++ b/arkguard/src/common/type.ts @@ -0,0 +1,26 @@ +/* + * 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. + */ + +export const enum Extension { + TS = '.ts', + DTS = '.d.ts', + JS = '.js', + JSON = '.json', + ETS = '.ets', + DETS = '.d.ets' +} + +export const supportedRunningExtension: readonly string[] = [Extension.TS, Extension.JS]; +export const supportedDeclarationExtension: readonly string[] = [Extension.DTS, Extension.DETS]; \ No newline at end of file diff --git a/arkguard/src/transformers/TransformerManager.ts b/arkguard/src/transformers/TransformerManager.ts index dee28a04e99eb8c1b31fbe16eba06a99ac023e84..3552218a24c71d48cbec37fb888b252a1c19e8cf 100644 --- a/arkguard/src/transformers/TransformerManager.ts +++ b/arkguard/src/transformers/TransformerManager.ts @@ -19,6 +19,7 @@ import {join, resolve} from 'path'; import type {IOptions} from '../configs/IOptions'; import type {TransformPlugin} from './TransformPlugin'; +import { Extension } from '../common/type'; export class TransformerManager { private static sInstance: TransformerManager | null = null; @@ -51,10 +52,11 @@ export class TransformerManager { let subDir: string[] = readdirSync(subPath); for (const file of subDir) { - if (!file.endsWith('.ts')) { + if (!file.endsWith(Extension.TS)) { continue; } - const fileNameNoSuffix = file.lastIndexOf('.d.ts') > -1 ? file.slice(0, file.lastIndexOf('.d.ts')) : file.slice(0, file.lastIndexOf('.ts')); + const fileNameNoSuffix = file.lastIndexOf(Extension.DTS) > -1 ? file.slice(0, file.lastIndexOf(Extension.DTS)) : + file.slice(0, file.lastIndexOf(Extension.TS)); let path: string = join(subPath, fileNameNoSuffix); let module = require(path); let plugin: TransformPlugin = module?.transformerPlugin; diff --git a/arkguard/src/transformers/layout/DisableHilogTransformer.ts b/arkguard/src/transformers/layout/DisableHilogTransformer.ts index dd197aa23234fc985ab99e6f135932a754055757..c0241ebbd00fd499ae14aca0aaa1982e69d63fdd 100644 --- a/arkguard/src/transformers/layout/DisableHilogTransformer.ts +++ b/arkguard/src/transformers/layout/DisableHilogTransformer.ts @@ -43,6 +43,7 @@ import type {TransformPlugin} from '../TransformPlugin'; import {TransformerOrder} from '../TransformPlugin'; import {OhPackType, isCommentedNode} from '../../utils/TransformUtil'; import {findOhImportStatement} from '../../utils/OhsUtil'; +import { NodeUtils } from '../../utils/NodeUtils'; namespace secharmony { export let transformerPlugin: TransformPlugin = { @@ -63,7 +64,7 @@ namespace secharmony { return transformer; function transformer(node: Node): Node { - if (!isSourceFile(node) || node.fileName.endsWith('.d.ts')) { + if (!isSourceFile(node) || NodeUtils.isDeclarationFile(node)) { return node; } diff --git a/arkguard/src/transformers/layout/SimplifyTransformer.ts b/arkguard/src/transformers/layout/SimplifyTransformer.ts index dcfc9185a6036a538cdbaf9c3eb510d9d71e5db7..277166a97833ec69bfda10a037d57d6f6d662af7 100644 --- a/arkguard/src/transformers/layout/SimplifyTransformer.ts +++ b/arkguard/src/transformers/layout/SimplifyTransformer.ts @@ -44,8 +44,9 @@ import type { import type { IOptions } from '../../configs/IOptions'; import type { TransformPlugin } from '../TransformPlugin'; -import {TransformerOrder} from '../TransformPlugin'; +import { TransformerOrder } from '../TransformPlugin'; import { isCommentedNode, isSuperCallStatement } from '../../utils/TransformUtil'; +import { NodeUtils } from '../../utils/NodeUtils'; namespace secharmony { export let transformerPlugin: TransformPlugin = { @@ -67,7 +68,7 @@ namespace secharmony { return transformer; function transformer(node: Node): Node { - if (!isSourceFile(node) || node.fileName.endsWith('.d.ts')) { + if (!isSourceFile(node) || NodeUtils.isDeclarationFile(node)) { return node; } diff --git a/arkguard/src/transformers/rename/RenameFileNameTransformer.ts b/arkguard/src/transformers/rename/RenameFileNameTransformer.ts index f3b29d3ce2df7509b81b5bad9cfcd5e58f96507b..7e69a42873dd645372e591ce8b6b0314cc3a2d6e 100644 --- a/arkguard/src/transformers/rename/RenameFileNameTransformer.ts +++ b/arkguard/src/transformers/rename/RenameFileNameTransformer.ts @@ -337,4 +337,4 @@ function toUnixPath(data: string): string { return newData; } return data; -} +} \ No newline at end of file diff --git a/arkguard/src/transformers/rename/RenameIdentifierTransformer.ts b/arkguard/src/transformers/rename/RenameIdentifierTransformer.ts index 56a394ed9cc29710cf7e53affd22b28998262cf3..ab1542457f4d66ce392ae4fc6ebb6afe9ac7a62a 100644 --- a/arkguard/src/transformers/rename/RenameIdentifierTransformer.ts +++ b/arkguard/src/transformers/rename/RenameIdentifierTransformer.ts @@ -41,7 +41,8 @@ import { isGlobalScope, isEnumScope, isInterfaceScope, - isObjectLiteralScope + isObjectLiteralScope, + mangledIdentifierNames } from '../../utils/ScopeAnalyzer'; import type { @@ -154,10 +155,6 @@ namespace secharmony { function renameNamesInScope(scope: Scope): void { if (scope.parent) { - scope.parent.mangledNames.forEach((value) => { - scope.mangledNames.add(value); - }); - scope.parent.importNames.forEach((value) => { scope.importNames.add(value); }); @@ -186,7 +183,7 @@ namespace secharmony { let mangled: string = original; // No allow to rename reserved names. if (reservedNames.includes(original) || scope.exportNames.has(def.name) || isSkippedGlobal(openTopLevel, scope)) { - scope.mangledNames.add(mangled); + mangledIdentifierNames.add(mangled); mangledSymbolNames.set(def, mangled); return; } @@ -207,7 +204,7 @@ namespace secharmony { // add new names to name cache nameCache.set(path, mangled); - scope.mangledNames.add(mangled); + mangledIdentifierNames.add(mangled); mangledSymbolNames.set(def, mangled); localCache.set(original, mangled); }); @@ -255,7 +252,7 @@ namespace secharmony { } // the anme has already been generated in the current scope - if (scope.mangledNames.has(mangled)) { + if (mangledIdentifierNames.has(mangled)) { mangled = ''; } } while (mangled === ''); @@ -338,7 +335,7 @@ namespace secharmony { const sym: Symbol | undefined = checker.getSymbolAtLocation(targetNode); if (!sym) { - scope.mangledNames.add((targetNode as Identifier).escapedText.toString()); + mangledIdentifierNames.add((targetNode as Identifier).escapedText.toString()); } }; @@ -394,4 +391,4 @@ namespace secharmony { export let historyNameCache: Map = undefined; } -export = secharmony; +export = secharmony; \ No newline at end of file diff --git a/arkguard/src/utils/NameCacheUtil.ts b/arkguard/src/utils/NameCacheUtil.ts index bb30910c373c48cb57d63e8b63362ba53876d21c..dd5e1323974cd3574c0603744783fa47afa1c162 100644 --- a/arkguard/src/utils/NameCacheUtil.ts +++ b/arkguard/src/utils/NameCacheUtil.ts @@ -17,6 +17,7 @@ import {FileUtils} from './FileUtils'; export const NAME_CACHE_SUFFIX: string = '.cache.json'; export const PROPERTY_CACHE_FILE: string = 'property.cache.json'; +const spaceOfNameCache: number = 2; export function writeCache(cache: Map, destFileName: string): void { // convert map to json string @@ -24,7 +25,7 @@ export function writeCache(cache: Map, destFileName: string): vo return; } - const cacheString: string = JSON.stringify(Object.fromEntries(cache)); + const cacheString: string = JSON.stringify(Object.fromEntries(cache), null, spaceOfNameCache); FileUtils.writeFile(destFileName, cacheString); } diff --git a/arkguard/src/utils/NodeUtils.ts b/arkguard/src/utils/NodeUtils.ts index 775d2eba2e4a169f1be1e3fb030c589dace3e7d6..ee63e1ca2d290c4e5621bd3f285211883c1267e0 100644 --- a/arkguard/src/utils/NodeUtils.ts +++ b/arkguard/src/utils/NodeUtils.ts @@ -15,8 +15,13 @@ import type {Expression, Node, ObjectBindingPattern, SourceFile} from 'typescript'; import { + SyntaxKind, + getModifiers, + isBinaryExpression, isBindingElement, isCallExpression, + isClassDeclaration, + isClassExpression, isComputedPropertyName, isConstructorDeclaration, isElementAccessExpression, @@ -26,6 +31,7 @@ import { isMethodDeclaration, isMethodSignature, isParameter, + isPrivateIdentifier, isPropertyAccessExpression, isPropertyAssignment, isPropertyDeclaration, @@ -34,6 +40,7 @@ import { isSetAccessor, isVariableDeclaration } from 'typescript'; +import { isParameterPropertyModifier } from './OhsUtil'; export class NodeUtils { public static isPropertyDeclarationNode(node: Node): boolean { @@ -102,9 +109,32 @@ export class NodeUtils { if (isPropertyAccessExpression(parent) && parent.name === node) { return true; } + if (isPrivateIdentifier(node) && NodeUtils.isInClassDeclaration(parent)) { + return NodeUtils.isInExpression(parent); + } return isQualifiedName(parent) && parent.right === node; } + private static isInClassDeclaration(node: Node | undefined): boolean { + if (!node) { + return false; + } + + if (isClassDeclaration(node) || isClassExpression(node)) { + return true; + } + + return NodeUtils.isInClassDeclaration(node.parent); + } + + private static isInExpression(node: Node | undefined): boolean { + return !!node && NodeUtils.isInOperator(node); + } + + private static isInOperator(node: Node): boolean { + return isBinaryExpression(node) && node.operatorToken.kind === SyntaxKind.InKeyword; + } + public static isElementAccessNode(node: Node): boolean { let parent: Node | undefined = node.parent; if (!parent) { @@ -123,6 +153,11 @@ export class NodeUtils { return false; } + const modifiers = getModifiers(node.parent); + if (!modifiers || modifiers.length === 0 || !modifiers.find(modifier => isParameterPropertyModifier(modifier))) { + return false; + } + return node.parent.parent && isConstructorDeclaration(node.parent.parent); } diff --git a/arkguard/src/utils/OhsUtil.ts b/arkguard/src/utils/OhsUtil.ts index 031d0a56b41d94df2b1f3f8d510e61dad3b992b4..e62704a4fb1bb9f15145679d46627bd5a23ca19b 100644 --- a/arkguard/src/utils/OhsUtil.ts +++ b/arkguard/src/utils/OhsUtil.ts @@ -250,7 +250,7 @@ export function getInterfaceProperties(interfaceNode: InterfaceDeclaration, prop }); } -function isParameterPropertyModifier(modifier: Modifier): boolean { +export function isParameterPropertyModifier(modifier: Modifier): boolean { if (modifier.kind === SyntaxKind.PublicKeyword || modifier.kind === SyntaxKind.PrivateKeyword || modifier.kind === SyntaxKind.ProtectedKeyword || diff --git a/arkguard/src/utils/ScopeAnalyzer.ts b/arkguard/src/utils/ScopeAnalyzer.ts index abb71ec030c5887759faf3f644d82e7b58105a3b..5aec6b812e8aef9aa91bd547b3fd7e1e7a19adb5 100644 --- a/arkguard/src/utils/ScopeAnalyzer.ts +++ b/arkguard/src/utils/ScopeAnalyzer.ts @@ -15,6 +15,7 @@ import { forEachChild, + getModifiers, isClassDeclaration, isConstructorDeclaration, isFunctionDeclaration, @@ -40,10 +41,12 @@ import type { ImportSpecifier, InterfaceDeclaration, LabeledStatement, + Modifier, ModuleDeclaration, Node, ObjectBindingPattern, ObjectLiteralExpression, + ParameterDeclaration, SourceFile, Symbol, SymbolTable, @@ -53,7 +56,7 @@ import type { } from 'typescript'; import {NodeUtils} from './NodeUtils'; -import {isViewPUBasedClass} from './OhsUtil'; +import {isParameterPropertyModifier, isViewPUBasedClass} from './OhsUtil'; /** * kind of a scope @@ -103,6 +106,7 @@ namespace secharmony { return scope.kind === ScopeKind.OBJECT_LITERAL; } + export const mangledIdentifierNames: Set = new Set(); /** * Structure of a scope */ @@ -151,8 +155,6 @@ namespace secharmony { exportNames?: Set; - mangledNames?: Set; - /** * add a sub scope to current scope * @@ -228,7 +230,6 @@ namespace secharmony { 'loc': loc, 'importNames': importNames, 'exportNames': exportNames, - 'mangledNames': mangledNames, addChild, addDefinition, addLabel, @@ -631,17 +632,19 @@ namespace secharmony { return; } - const visitParam = (param: Node): void => { - if (isIdentifier(param)) { - current.defs.forEach((def) => { - if (def.name === param.text) { - current.defs.delete(def); - current.mangledNames.add(def.name); - } - }); + const visitParam = (param: ParameterDeclaration): void => { + const modifiers = getModifiers(param); + if (modifiers && modifiers.length > 0) { + const hasParameterPropertyModifier: boolean = modifiers.find(modifier => isParameterPropertyModifier(modifier)) !== undefined; + if (isIdentifier(param.name) && hasParameterPropertyModifier) { + current.defs.forEach((def) => { + if (def.name === param.name.getText()) { + current.defs.delete(def); + mangledIdentifierNames.add(def.name); + } + }); + } } - - forEachChild(param, visitParam); }; node.parameters.forEach((param) => { diff --git a/arkguard/test/grammar/compact/decoratorAndModifier.ts b/arkguard/test/grammar/compact/decoratorAndModifier.ts index ca071153b4647e4fcb57592b394f95cae20a8a5b..9563f1653cd461993051cb8b280c14043a6dc4ed 100644 --- a/arkguard/test/grammar/compact/decoratorAndModifier.ts +++ b/arkguard/test/grammar/compact/decoratorAndModifier.ts @@ -41,4 +41,4 @@ function foo() { let a3 = 3 let a4 = 4 let a5 = 5 -} +} \ No newline at end of file diff --git a/arkguard/test/grammar/compact/numericLiteralsWithTrailingDecimalPoints.ts b/arkguard/test/grammar/compact/numericLiteralsWithTrailingDecimalPoints.ts index e2ced618af4fe5e3d8e265b9cb25cadeb2604d4e..ea394fd2d42a9b6e7ac812138b74e5b2cafab41e 100644 --- a/arkguard/test/grammar/compact/numericLiteralsWithTrailingDecimalPoints.ts +++ b/arkguard/test/grammar/compact/numericLiteralsWithTrailingDecimalPoints.ts @@ -18,37 +18,33 @@ 1. + 2.0 + 3.; var i: number = 1; -var case1 = i.toString(); -var case3 = 3 .toString(); -var case4 = 3 .toString(); -var case5 = 3 .toString(); -var case6 = 3.['toString'](); -var case7 = 3 +var test1 = i.toString(); +var test3 = 3 .toString(); +var test4 = 3 .toString(); +var test5 = 3 .toString(); +var test6 = 3.['toString'](); +var test7 = 3 .toString(); -var case8 = new Number(4).toString(); -var case9 = 3. + 3.; -var case10 = 0 /* comment */.toString(); -var case11 = 3. /* comment */.toString(); -var case12 = 3 +var test8 = new Number(4).toString(); +var test9 = 3. + 3.; +var test10 = 0 /* comment */.toString(); +var test11 = 3. /* comment */.toString(); +var test12 = 3 /* comment */ .toString(); -var case122 = 3 +var test122 = 3 /* comment */.toString(); -var case1222 = 3 +var test1222 = 3 .toString(); -var case13 = 3. +var test13 = 3. /* comment */.toString(); -var case14 = 3 +var test14 = 3 // comment .toString(); -var case15 = 3. +var test15 = 3. // comment .toString(); -var case16 = 3 // comment time +var test16 = 3 // comment time .toString(); -var case17 = 3. // comment time again - .toString(); - - - - +var test17 = 3. // comment time again + .toString(); \ No newline at end of file diff --git a/arkguard/test/grammar/identifier_validation/constructor_property.ts b/arkguard/test/grammar/identifier_validation/constructor_property.ts new file mode 100644 index 0000000000000000000000000000000000000000..f8255d0d5ee004f3a97b06ba73e9780ff17f163b --- /dev/null +++ b/arkguard/test/grammar/identifier_validation/constructor_property.ts @@ -0,0 +1,49 @@ +/* + * 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. + */ + +namespace ts { + let friendA: { getX(o: A): number, setX(o: A, v: number): void }; + + class A { + x: number; + + constructor (v: number) { + this.x = v; + } + + getX () { + return this.x; + } + + obj() { + friendA = { + getX(obj) { return obj.x }, + setX(obj, value) { obj.x = value } + }; + } + }; + + class B { + constructor(public a: A, private x01: number = 1, protected x02: string = '', readonly x03: number = 2) { + const x = friendA.getX(a); // ok + friendA.setX(a, x + 1); // ok + } + }; + + const a = new A(41); + a.obj(); + const b = new B(a); + a.getX(); +} \ No newline at end of file diff --git a/arkguard/test/grammar/identifier_validation/constructor_var_property.ts b/arkguard/test/grammar/identifier_validation/constructor_var_property.ts new file mode 100644 index 0000000000000000000000000000000000000000..7f560ea8d40de66b5380e067b42671ddac03dcfe --- /dev/null +++ b/arkguard/test/grammar/identifier_validation/constructor_var_property.ts @@ -0,0 +1,38 @@ +/* + * 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. + */ + +import assert from 'assert'; +namespace ts { + class X { + n: string = ""; + constructor(s:string) { + this.n = s; + } + method(){ + return (this.n); + } + } + let name1 = new X("global"); + + class A { + name0:string = ''; + constructor(name2:string, public name3: X) { + name3.method(); + } + } + let a = new A('aa',new X("param")); + assert(a.name3.n === 'param', 'success'); + assert(name1.n === 'global', 'success'); +} \ No newline at end of file diff --git a/arkguard/test/grammar/identifier_validation/constructor_variables.ts b/arkguard/test/grammar/identifier_validation/constructor_variables.ts new file mode 100644 index 0000000000000000000000000000000000000000..f7e26d2aca42e1c97b25db2ed4349468d16b944d --- /dev/null +++ b/arkguard/test/grammar/identifier_validation/constructor_variables.ts @@ -0,0 +1,48 @@ +/* + * 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. + */ + +namespace ts { + let friendA: { getX(o: A): number, setX(o: A, v: number): void }; + class A { + x: number; + + constructor (v: number) { + this.x = v; + } + + getX () { + return this.x; + } + + obj() { + friendA = { + getX(obj) { return obj.x }, + setX(obj, value) { obj.x = value } + }; + } + }; + + class B { + constructor(a: A) { + const x = friendA.getX(a); // ok + friendA.setX(a, x + 1); // ok + } + }; + + const a = new A(41); + a.obj(); + const b = new B(a); + a.getX(); +} \ No newline at end of file diff --git a/arkguard/test/grammar/identifier_validation/obfConfig.json b/arkguard/test/grammar/identifier_validation/obfConfig.json new file mode 100644 index 0000000000000000000000000000000000000000..27db7583b8ad04cafba00236b76fb4ceec3c2131 --- /dev/null +++ b/arkguard/test/grammar/identifier_validation/obfConfig.json @@ -0,0 +1,18 @@ +{ + "mCompact": false, + "mRemoveComments": false, + "mOutputDir": "../../local", + "mDisableHilog": false, + "mDisableConsole": false, + "mSimplify": false, + "mNameObfuscation": { + "mEnable": true, + "mNameGeneratorType": 1, + "mDictionaryList": [], + "mRenameProperties": true, + "mKeepStringProperty": false + }, + "mEnableSourceMap": false, + "mEnableNameCache": false, + "mTopLevel": false +} \ No newline at end of file diff --git a/arkguard/test/grammar/in_operator/importHelpersNoHelpersForPrivateFields.ts b/arkguard/test/grammar/in_operator/importHelpersNoHelpersForPrivateFields.ts new file mode 100644 index 0000000000000000000000000000000000000000..30ede96d82bc244ed993a79e29fdc2ef68caa202 --- /dev/null +++ b/arkguard/test/grammar/in_operator/importHelpersNoHelpersForPrivateFields.ts @@ -0,0 +1,25 @@ +/* + * 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. + */ + +export class Foo { + #field = true; + f() { + this.#field = this.#field; + #field in this; + } +} + +// @filename: tslib.d.ts +export {} \ No newline at end of file diff --git a/arkguard/test/grammar/in_operator/privateKeyWord.ts b/arkguard/test/grammar/in_operator/privateKeyWord.ts new file mode 100644 index 0000000000000000000000000000000000000000..2b5579154b48ab85366f7895c89903e0c45780df --- /dev/null +++ b/arkguard/test/grammar/in_operator/privateKeyWord.ts @@ -0,0 +1,25 @@ +/* + * 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. + */ + +class MyClass { + private a = 1; + + foo(): number{ + return this.a; + } +} + +const b = new MyClass(); +const myInstance = b.foo; diff --git a/arkguard/test/grammar/in_operator/privateNameInInExpression.ts b/arkguard/test/grammar/in_operator/privateNameInInExpression.ts new file mode 100644 index 0000000000000000000000000000000000000000..3bec3aa57753382c984c9ae90415f597ef59f5b4 --- /dev/null +++ b/arkguard/test/grammar/in_operator/privateNameInInExpression.ts @@ -0,0 +1,43 @@ +/* + * 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. + */ + +class F { + #f = 1; + static #staticField = 2; + #m() { } + static #staticM() { } + + goodRhs(v: any) { + const a = #f in v; + + const b = #f in v.p1.p2; + + const c = #f in (v as {}); + + const d = #f in (v as F); + + const e = #f in (v as never); + + for (let f in #f in v as any) { /**/ } // unlikely but valid + } + whitespace(v: any) { + const a = v && /*0*/#f/*1*/ + /*2*/ in/*3*/ + /*4*/v/*5*/ + } +} + +class FooSub extends F { subTypeOfFoo = true } +class Bar { notFoo = true } diff --git a/arkguard/test/grammar/in_operator/privateNameInInExpressionTransform.ts b/arkguard/test/grammar/in_operator/privateNameInInExpressionTransform.ts new file mode 100644 index 0000000000000000000000000000000000000000..c167f44f6dc75438c3a493a66f740bce8859618f --- /dev/null +++ b/arkguard/test/grammar/in_operator/privateNameInInExpressionTransform.ts @@ -0,0 +1,45 @@ +/* + * 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. + */ + +class F { + #f = 1; + #fun() { } + static #staticF = 2; + static #staticMethod() { } + check(a: any) { + #f in a; // expect F's 'f' WeakMap + #fun in a; // expect F's 'instances' WeakSet + #staticF in a; // expect F's constructor + #staticMethod in a; // expect F's constructor + } + precedence(a: any) { + // '==' and '||' have lower precedence than 'in' + // 'in' naturally has same precedence as 'in' + // '<<' has higher precedence than 'in' + + a == #f in a || a; // Good precedence: (a == (#f in a)) || a + + #f in a && #f in a; // Good precedence: (#f in a) && (#f in a) + } +} + +class Bar { + #f = 1; + check(a: any) { + #f in a; // expect Bar's 'f' WeakMap + } +} + +export { } \ No newline at end of file diff --git a/arkguard/test/grammar/in_operator/privateNameInInExpressionUnused.ts b/arkguard/test/grammar/in_operator/privateNameInInExpressionUnused.ts new file mode 100644 index 0000000000000000000000000000000000000000..c5139dc78c64265d243d58e7e10334f5d62d4116 --- /dev/null +++ b/arkguard/test/grammar/in_operator/privateNameInInExpressionUnused.ts @@ -0,0 +1,24 @@ +/* + * 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. + */ + +class Foo { + #unused: undefined; // expect unused error + #brand: undefined; // expect no error + + isFoo(v: any): v is Foo { + // This should count as using/reading '#brand' + return #brand in v; + } +} \ No newline at end of file diff --git a/arkguard/test/grammar/obfuscation_validation/interface_demo_01-assert.ts b/arkguard/test/grammar/obfuscation_validation/interface_demo_01-assert-expectation.ts similarity index 97% rename from arkguard/test/grammar/obfuscation_validation/interface_demo_01-assert.ts rename to arkguard/test/grammar/obfuscation_validation/interface_demo_01-assert-expectation.ts index ec65d7e88523ea75ee96ef91ee252760a209af66..33d82bb5c2b2c9325ca57cccf00c76f95e6553f3 100644 --- a/arkguard/test/grammar/obfuscation_validation/interface_demo_01-assert.ts +++ b/arkguard/test/grammar/obfuscation_validation/interface_demo_01-assert-expectation.ts @@ -29,7 +29,7 @@ export class class01 { classP12 = 3; }; get classP13() { return 1; } - set classP14(a) { } + set classP14(g) { } } export enum enum01 { enumP1, diff --git a/arkguard/test/grammar/obfuscation_validation/namespace_api_01-assert.ts b/arkguard/test/grammar/obfuscation_validation/namespace_api_01-assert-expectation.ts similarity index 84% rename from arkguard/test/grammar/obfuscation_validation/namespace_api_01-assert.ts rename to arkguard/test/grammar/obfuscation_validation/namespace_api_01-assert-expectation.ts index f2171421901d76fca61f96f22b71c642dcbb50dd..eeb318a55355568946b1bc0f755879f00c4c59e5 100644 --- a/arkguard/test/grammar/obfuscation_validation/namespace_api_01-assert.ts +++ b/arkguard/test/grammar/obfuscation_validation/namespace_api_01-assert-expectation.ts @@ -2,7 +2,7 @@ import fs from 'fs'; import path from 'path'; import assert from 'assert'; -const filePath = path.join(__filename, '../namespace_api_use.ts'); +const filePath = path.join(__filename, '../namespace_api_01_use.ts'); const actual = fs.readFileSync(filePath, 'utf-8'); const expectation = `import moduleName01 from './namespace_api_01'; diff --git a/arkguard/test/grammar/obfuscation_validation/namespace_api_01.d.ts b/arkguard/test/grammar/obfuscation_validation/namespace_api_01.ts similarity index 35% rename from arkguard/test/grammar/obfuscation_validation/namespace_api_01.d.ts rename to arkguard/test/grammar/obfuscation_validation/namespace_api_01.ts index 5df27b160d8afca3875375dc9c8f2b45d086cd1a..6bd8488dcba8b7030a1142262a837c12dece65fe 100644 --- a/arkguard/test/grammar/obfuscation_validation/namespace_api_01.d.ts +++ b/arkguard/test/grammar/obfuscation_validation/namespace_api_01.ts @@ -1,12 +1,12 @@ -declare namespace fileExtension { - enum Entry { +export namespace fileExtension { + export enum Entry { ADDRESS = 'CZ', NUMBER = '123456', } - namespace NewDocument { - const PARAMETER01 = '123'; - const PARAMETER02 = '456'; + export namespace NewDocument { + export const PARAMETER01 = '123'; + export const PARAMETER02 = '456'; } } diff --git a/arkguard/test/grammar/obfuscation_validation/namespace_api_use.ts b/arkguard/test/grammar/obfuscation_validation/namespace_api_01_use.ts similarity index 100% rename from arkguard/test/grammar/obfuscation_validation/namespace_api_use.ts rename to arkguard/test/grammar/obfuscation_validation/namespace_api_01_use.ts diff --git a/arkguard/test/grammar/obfuscation_validation/stringLiteral_demo_01-assert.ts b/arkguard/test/grammar/obfuscation_validation/stringLiteral_demo_01-assert-expectation.ts similarity index 100% rename from arkguard/test/grammar/obfuscation_validation/stringLiteral_demo_01-assert.ts rename to arkguard/test/grammar/obfuscation_validation/stringLiteral_demo_01-assert-expectation.ts diff --git a/arkguard/test/grammar/obfuscation_validation/stringLiteral_demo_02-assert.ts b/arkguard/test/grammar/obfuscation_validation/stringLiteral_demo_02-assert-expectation.ts similarity index 100% rename from arkguard/test/grammar/obfuscation_validation/stringLiteral_demo_02-assert.ts rename to arkguard/test/grammar/obfuscation_validation/stringLiteral_demo_02-assert-expectation.ts diff --git a/es2panda/BUILD.gn b/es2panda/BUILD.gn index f865882ca2bfafbbc636162d955c1291cadbe60e..b56e1830700f591ace9cec9a8a09f5e5269f4f07 100644 --- a/es2panda/BUILD.gn +++ b/es2panda/BUILD.gn @@ -88,6 +88,7 @@ es2panda_src = [ "ir/expressions/newExpression.cpp", "ir/expressions/objectExpression.cpp", "ir/expressions/omittedExpression.cpp", + "ir/expressions/privateIdentifier.cpp", "ir/expressions/sequenceExpression.cpp", "ir/expressions/superExpression.cpp", "ir/expressions/taggedTemplateExpression.cpp", diff --git a/es2panda/aot/emitFiles.cpp b/es2panda/aot/emitFiles.cpp index 2066486b77ed1c7db718b60ab0860330748bf80b..7eca28a2e40c682ef62a3d429003aa7f7828d1dc 100644 --- a/es2panda/aot/emitFiles.cpp +++ b/es2panda/aot/emitFiles.cpp @@ -25,10 +25,11 @@ void EmitFileQueue::Schedule() { ASSERT(jobsCount_ == 0); std::unique_lock lock(m_); + auto targetApi = options_->CompilerOptions().targetApiVersion; if (mergeAbc_) { // generate merged abc - auto emitMergedAbcJob = new EmitMergedAbcJob(options_->CompilerOutput(), progsInfo_); + auto emitMergedAbcJob = new EmitMergedAbcJob(options_->CompilerOutput(), progsInfo_, targetApi); for (const auto &info: progsInfo_) { // generate cache protoBins and set dependencies if (!info.second->needUpdateCache) { @@ -51,7 +52,8 @@ void EmitFileQueue::Schedule() // generate multi abcs auto outputFileName = options_->OutputFiles().empty() ? options_->CompilerOutput() : options_->OutputFiles().at(info.first); - auto emitSingleAbcJob = new EmitSingleAbcJob(outputFileName, &(info.second->program), statp_); + auto emitSingleAbcJob = new EmitSingleAbcJob(outputFileName, &(info.second->program), statp_, + targetApi); jobs_.push_back(emitSingleAbcJob); jobsCount_++; } catch (std::exception &error) { @@ -67,7 +69,7 @@ void EmitFileQueue::Schedule() void EmitSingleAbcJob::Run() { if (!panda::pandasm::AsmEmitter::Emit(panda::os::file::File::GetExtendedFilePath(outputFileName_), *prog_, statp_, - nullptr, true)) { + nullptr, true, nullptr, targetApiVersion_)) { throw Error(ErrorType::GENERIC, "Failed to emit " + outputFileName_ + ", error: " + panda::pandasm::AsmEmitter::GetLastError()); } @@ -84,7 +86,7 @@ void EmitMergedAbcJob::Run() progs.push_back(&(info.second->program)); } if (!panda::pandasm::AsmEmitter::EmitPrograms(panda::os::file::File::GetExtendedFilePath(outputFileName_), progs, - true)) { + true, targetApiVersion_)) { throw Error(ErrorType::GENERIC, "Failed to emit " + outputFileName_ + ", error: " + panda::pandasm::AsmEmitter::GetLastError()); } diff --git a/es2panda/aot/emitFiles.h b/es2panda/aot/emitFiles.h index 808393ecad222c55f84675cab893af092d7e9a6d..ee58996d1bf0a8a7471a6733aed4f471d394c874 100644 --- a/es2panda/aot/emitFiles.h +++ b/es2panda/aot/emitFiles.h @@ -25,8 +25,8 @@ namespace panda::es2panda::aot { class EmitSingleAbcJob : public util::WorkerJob { public: explicit EmitSingleAbcJob(const std::string &outputFileName, panda::pandasm::Program *prog, - std::map *statp) - : outputFileName_(outputFileName), prog_(prog), statp_(statp) {}; + std::map *statp, uint8_t targetApi) + : outputFileName_(outputFileName), prog_(prog), statp_(statp), targetApiVersion_(targetApi) {}; NO_COPY_SEMANTIC(EmitSingleAbcJob); NO_MOVE_SEMANTIC(EmitSingleAbcJob); ~EmitSingleAbcJob() override = default; @@ -36,13 +36,15 @@ private: std::string outputFileName_; panda::pandasm::Program *prog_; std::map *statp_; + uint8_t targetApiVersion_ = 0; }; class EmitMergedAbcJob : public util::WorkerJob { public: explicit EmitMergedAbcJob(const std::string &outputFileName, - const std::map &progsInfo) - : outputFileName_(outputFileName), progsInfo_(progsInfo) {}; + const std::map &progsInfo, + uint8_t targetApi) + : outputFileName_(outputFileName), progsInfo_(progsInfo), targetApiVersion_(targetApi) {}; NO_COPY_SEMANTIC(EmitMergedAbcJob); NO_MOVE_SEMANTIC(EmitMergedAbcJob); ~EmitMergedAbcJob() override = default; @@ -51,6 +53,7 @@ public: private: std::string outputFileName_; const std::map &progsInfo_; + uint8_t targetApiVersion_ = 0; }; class EmitCacheJob : public util::WorkerJob { diff --git a/es2panda/aot/options.cpp b/es2panda/aot/options.cpp index 6fd8a714695d3bfe737383710568f9cbda404615..b08e45d67c5fb68b91fc6c931b6bd14dae855321 100644 --- a/es2panda/aot/options.cpp +++ b/es2panda/aot/options.cpp @@ -241,6 +241,8 @@ bool Options::Parse(int argc, const char **argv) // version panda::PandArg bcVersion("bc-version", false, "Print ark bytecode version"); panda::PandArg bcMinVersion("bc-min-version", false, "Print ark bytecode minimum supported version"); + panda::PandArg targetApiVersion("target-api-version", 11, "Specify the targeting api version for es2abc to "\ + "generated the corresponding version of bytecode"); // tail arguments panda::PandArg inputFile("input", "", "input file"); @@ -286,6 +288,7 @@ bool Options::Parse(int argc, const char **argv) argparser_->Add(&bcVersion); argparser_->Add(&bcMinVersion); + argparser_->Add(&targetApiVersion); argparser_->PushBackTail(&inputFile); argparser_->EnableTail(); @@ -456,6 +459,7 @@ bool Options::Parse(int argc, const char **argv) base64Output.GetValue()) ? 0 : opOptLevel.GetValue(); compilerOptions_.sourceFiles = sourceFiles_; compilerOptions_.mergeAbc = opMergeAbc.GetValue(); + compilerOptions_.targetApiVersion = targetApiVersion.GetValue(); compilerOptions_.patchFixOptions.dumpSymbolTable = opDumpSymbolTable.GetValue(); compilerOptions_.patchFixOptions.symbolTable = opInputSymbolTable.GetValue(); diff --git a/es2panda/binder/binder.cpp b/es2panda/binder/binder.cpp index 945c3eefd5182ddf44f4994487972832ee65a026..7b42acbbdbde9f9dd939107f3895ba4e5da35954 100644 --- a/es2panda/binder/binder.cpp +++ b/es2panda/binder/binder.cpp @@ -21,6 +21,7 @@ #include "ir/astNode.h" #include "ir/base/catchClause.h" #include "ir/base/classDefinition.h" +#include "ir/base/classProperty.h" #include "ir/base/methodDefinition.h" #include "ir/base/property.h" #include "ir/base/scriptFunction.h" @@ -29,6 +30,7 @@ #include "ir/expressions/assignmentExpression.h" #include "ir/expressions/identifier.h" #include "ir/expressions/objectExpression.h" +#include "ir/expressions/privateIdentifier.h" #include "ir/expressions/literals/numberLiteral.h" #include "ir/module/exportNamedDeclaration.h" #include "ir/module/exportSpecifier.h" @@ -311,7 +313,8 @@ void Binder::LookupIdentReference(ir::Identifier *ident) if (res.level != 0) { ASSERT(res.variable); - if (!res.variable->Declaration()->IsDeclare()) { + if (!res.variable->Declaration()->IsDeclare() && !ident->Parent()->IsTSTypeReference() && + !ident->Parent()->IsTSTypeQuery()) { util::Concurrent::ProcessConcurrent(Program()->GetLineIndex(), ident, res, program_); res.variable->SetLexical(res.scope, program_->PatchFixHelper()); } @@ -552,7 +555,7 @@ void Binder::BuildClassDefinition(ir::ClassDefinition *classDef) res.variable->AddFlag(VariableFlags::INITIALIZED); } - auto scopeCtx = LexicalScope::Enter(this, classDef->Scope()); + auto scopeCtx = LexicalScope::Enter(this, classDef->Scope()); if (classDef->TypeParams()) { ResolveReference(classDef, classDef->TypeParams()); @@ -570,6 +573,11 @@ void Binder::BuildClassDefinition(ir::ClassDefinition *classDef) ResolveReference(classDef, iter); } + // new class features in ecma2022 are only supported for api11 and above + if (Program()->TargetApiVersion() > 10 && !(bindingFlags_ & ResolveBindingFlags::TS_BEFORE_TRANSFORM)) { + classDef->BuildClassEnvironment(); + } + if (classDef->Ident()) { ScopeFindResult res = scope_->Find(classDef->Ident()->Name()); @@ -585,6 +593,10 @@ void Binder::BuildClassDefinition(ir::ClassDefinition *classDef) ResolveReference(classDef, classDef->StaticInitializer()); } + if (classDef->NeedInstanceInitializer()) { + ResolveReference(classDef, classDef->InstanceInitializer()); + } + for (auto *stmt : classDef->Body()) { ResolveReference(classDef, stmt); } @@ -659,6 +671,15 @@ void Binder::ResolveReference(const ir::AstNode *parent, ir::AstNode *childNode) ResolveReferences(childNode); break; } + case ir::AstNodeType::PRIVATE_IDENTIFIER: { + if (Program()->Extension() == ScriptExtension::JS) { + CheckPrivateDeclaration(childNode->AsPrivateIdentifier()); + } else if (Program()->Extension() == ScriptExtension::TS && + bindingFlags_ == ResolveBindingFlags::TS_AFTER_TRANSFORM) { + CheckPrivateDeclaration(childNode->AsPrivateIdentifier()); + } + break; + } case ir::AstNodeType::SUPER_EXPRESSION: { VariableScope *varScope = scope_->EnclosingVariableScope(); varScope->AddFlag(VariableScopeFlags::USE_SUPER); @@ -723,10 +744,23 @@ void Binder::ResolveReference(const ir::AstNode *parent, ir::AstNode *childNode) break; } case ir::AstNodeType::CLASS_PROPERTY: { - const ir::ScriptFunction *ctor = util::Helpers::GetContainingConstructor(childNode->AsClassProperty()); - auto scopeCtx = LexicalScope::Enter(this, ctor->Scope()); - - ResolveReferences(childNode); + // for ts tranformer cases + if (Program()->Extension() == ScriptExtension::TS) { + const ir::ScriptFunction *ctor = util::Helpers::GetContainingConstructor(childNode->AsClassProperty()); + auto scopeCtx = LexicalScope::Enter(this, ctor->Scope()); + ResolveReferences(childNode); + break; + } + auto *prop = childNode->AsClassProperty(); + ResolveReference(prop, prop->Key()); + if (prop->Value() != nullptr) { + ASSERT(parent->IsClassDefinition()); + const auto *classDef = parent->AsClassDefinition(); + const ir::MethodDefinition *method = prop->IsStatic() ? classDef->StaticInitializer() : + classDef->InstanceInitializer(); + auto scopeCtx = LexicalScope::Enter(this, method->Function()->Scope()); + ResolveReference(prop, prop->Value()); + } break; } case ir::AstNodeType::BLOCK_STATEMENT: { @@ -995,4 +1029,25 @@ void Binder::ReplaceConstReferenceWithInitialization(const ir::Identifier *ident }, this); } +void Binder::CheckPrivateDeclaration(const ir::PrivateIdentifier *privateIdent) +{ + auto name = privateIdent->Name(); + auto scope = scope_; + while (scope != nullptr) { + if (scope->Type() == ScopeType::CLASS) { + const auto *classScope = scope->AsClassScope(); + if (classScope->HasPrivateName(name)) { + return; + } + } + scope = scope->Parent(); + } + + auto pos = privateIdent->Start(); + lexer::LineIndex index(program_->SourceCode()); + lexer::SourceLocation loc = index.GetLocation(pos); + + throw Error{ErrorType::SYNTAX, "Use private property before declaration", loc.line, loc.col}; +} + } // namespace panda::es2panda::binder diff --git a/es2panda/binder/binder.h b/es2panda/binder/binder.h index 1f51a5ed9eb334293b93800f12abfe9b3a7c574a..fe39faf68477489e40350d29092ee38c220c2c2e 100644 --- a/es2panda/binder/binder.h +++ b/es2panda/binder/binder.h @@ -31,6 +31,7 @@ class Expression; class ExportNamedDeclaration; class ForUpdateStatement; class Identifier; +class PrivateIdentifier; class ScriptFunction; class Statement; class VariableDeclarator; @@ -213,6 +214,7 @@ private: void ValidateExportDecl(const ir::ExportNamedDeclaration *exportDecl); void StoreAndCheckSpecialFunctionName(std::string &internalNameStr, std::string recordName); void ReplaceConstReferenceWithInitialization(const ir::Identifier *ident, const Decl *decl); + void CheckPrivateDeclaration(const ir::PrivateIdentifier *privateIdent); // TypeScript specific functions void BuildTSSignatureDeclarationBaseParams(const ir::AstNode *typeNode); diff --git a/es2panda/binder/scope.cpp b/es2panda/binder/scope.cpp index 3d39e23a8789e65c21f8e3e31ba4f277e9119312..bc62b31232e5fbacb5703e0dbbb25c7171f584c7 100644 --- a/es2panda/binder/scope.cpp +++ b/es2panda/binder/scope.cpp @@ -22,7 +22,9 @@ #include #include #include +#include #include +#include #include #include #include @@ -148,6 +150,133 @@ ScopeFindResult Scope::Find(const util::StringView &name, ResolveBindingOptions return {name, nullptr, 0, 0, nullptr, concurrentFunc}; } +std::pair Scope::Find(const ir::Expression *expr, bool onlyLevel) const +{ + uint32_t lexLevel = 0; + const auto *iter = this; + + while (iter != nullptr) { + if (iter->Type() == ScopeType::CLASS) { + if (onlyLevel) { + return {lexLevel, 0}; + } + return {lexLevel, iter->AsClassScope()->GetSlot(expr)}; + } + + if (iter->IsVariableScope()) { + if (iter->AsVariableScope()->NeedLexEnv()) { + lexLevel++; + } + } + iter = iter->Parent(); + } + + UNREACHABLE(); +} + +Result ClassScope::GetPrivateProperty(const util::StringView &name, bool isSetter) const +{ + if (name.Is("#method")) { + return {instanceMethodValidation_, false, false, false, false, 0}; + } + + uint32_t slot{0}; + bool setter{false}; + bool getter{false}; + + if (privateNames_.find(name) != privateNames_.end()) { + slot = privateNames_.find(name)->second; + } else { + auto accessor = isSetter ? privateSetters_ : privateGetters_; + auto unexpectedAccessor = isSetter ? privateGetters_ : privateSetters_; + + if (accessor.find(name) != accessor.end()) { + setter = isSetter; + getter = !setter; + slot = accessor.find(name)->second; + } else { + getter = isSetter; + setter = !getter; + slot = unexpectedAccessor.find(name)->second; + } + } + + uint32_t validateMethodSlot{0}; + + if (IsMethod(slot)) { + validateMethodSlot = IsStaticMethod(slot) ? staticMethodValidation_ : instanceMethodValidation_; + } + + return {slot, IsMethod(slot), IsStaticMethod(slot), getter, setter, validateMethodSlot}; +} + +void ClassScope::AddPrivateName(std::vector privateProperties, uint32_t privateFieldCnt, + uint32_t instancePrivateMethodCnt, uint32_t staticPrivateMethodCnt) +{ + privateFieldCnt_ = privateFieldCnt; + instancePrivateMethodStartSlot_ = slotIndex_ + privateFieldCnt_; + staticPrivateMethodStartSlot_ = instancePrivateMethodStartSlot_ + instancePrivateMethodCnt; + uint32_t instancePrivateMethodSlot = instancePrivateMethodStartSlot_; + uint32_t staticPrivateMethodSlot = staticPrivateMethodStartSlot_; + for (const auto *stmt : privateProperties) { + if (stmt->IsClassProperty()) { + privateNames_[stmt->AsClassProperty()->Key()->AsPrivateIdentifier()->Name()] = slotIndex_++; + continue; + } + ASSERT(stmt->IsMethodDefinition()); + auto *methodDef = stmt->AsMethodDefinition(); + uint32_t *start = methodDef->IsStatic() ? &staticPrivateMethodSlot : &instancePrivateMethodSlot; + auto name = methodDef->Key()->AsPrivateIdentifier()->Name(); + switch (methodDef->Kind()) { + case ir::MethodDefinitionKind::GET: { + privateGetters_[name] = (*start)++; + continue; + } + case ir::MethodDefinitionKind::SET: { + privateSetters_[name] = (*start)++; + continue; + } + default: { + privateNames_[name]= (*start)++; + continue; + } + } + } + slotIndex_ = staticPrivateMethodSlot; + privateMethodEndSlot_ = slotIndex_; + if (instancePrivateMethodCnt != 0) { + instanceMethodValidation_ = slotIndex_++; + } + + if (staticPrivateMethodCnt != 0) { + staticMethodValidation_ = slotIndex_++; + } +} + +PrivateNameFindResult Scope::FindPrivateName(const util::StringView &name, bool isSetter) const +{ + uint32_t lexLevel = 0; + const auto *iter = this; + + while (iter != nullptr) { + if (iter->Type() == ScopeType::CLASS) { + const auto *classScope = iter->AsClassScope(); + if (name.Is("#method") || classScope->HasPrivateName(name)) { + return {lexLevel, classScope->GetPrivateProperty(name, isSetter)}; + } + } + + if (iter->IsVariableScope()) { + if (iter->AsVariableScope()->NeedLexEnv()) { + lexLevel++; + } + } + iter = iter->Parent(); + } + + UNREACHABLE(); +} + Decl *Scope::FindDecl(const util::StringView &name) const { for (auto *it : decls_) { diff --git a/es2panda/binder/scope.h b/es2panda/binder/scope.h index 088387567820874c1854a7b99ea946ef50d5c7d0..9943856dd2f5e36cb3b6e3263b2f02c8ea6d0c2c 100644 --- a/es2panda/binder/scope.h +++ b/es2panda/binder/scope.h @@ -32,6 +32,7 @@ class IRNode; namespace panda::es2panda::ir { class ScriptFunction; +class Statement; } // namespace panda::es2panda::ir namespace panda::es2panda::binder { @@ -159,6 +160,23 @@ public: ir::ScriptFunction *concurrentFunc {}; }; +class Result { +public: + uint32_t slot; + bool isMethod; + bool isStatic; + bool isGetter; + bool isSetter; + uint32_t validateMethodSlot; +}; + +class PrivateNameFindResult { +public: + int32_t lexLevel; + Result result; +}; + + class Scope { public: virtual ~Scope() = default; @@ -327,6 +345,10 @@ public: ScopeFindResult Find(const util::StringView &name, ResolveBindingOptions options = ResolveBindingOptions::BINDINGS) const; + std::pair Find(const ir::Expression *expr, bool onlyLevel = false) const; + + PrivateNameFindResult FindPrivateName(const util::StringView &name, bool isSetter = false) const; + Decl *FindDecl(const util::StringView &name) const; bool HasVarDecl(const util::StringView &name) const; @@ -647,6 +669,73 @@ public: [[maybe_unused]] ScriptExtension extension) override; }; +class ClassScope : public VariableScope { +public: + explicit ClassScope(ArenaAllocator *allocator, Scope *parent) + : VariableScope(allocator, parent), + computedNames_(allocator->Adapter()), + privateNames_(allocator->Adapter()), + privateGetters_(allocator->Adapter()), + privateSetters_(allocator->Adapter()) + { + } + + ~ClassScope() override = default; + + ScopeType Type() const override + { + return ScopeType::CLASS; + } + + void AddClassVariable(const ir::Expression *key) + { + computedNames_.insert({key, slotIndex_++}); + } + + uint32_t GetSlot(const ir::Expression *key) const + { + ASSERT(computedNames_.find(key) != computedNames_.end()); + return computedNames_.find(key)->second; + } + + bool AddBinding(ArenaAllocator *allocator, Variable *currentVariable, Decl *newDecl, + [[maybe_unused]] ScriptExtension extension) override + { + return AddLocal(allocator, currentVariable, newDecl, extension); + } + + bool HasPrivateName(const util::StringView &name) const + { + return (privateNames_.count(name) + privateGetters_.count(name) + privateSetters_.count(name) != 0); + } + + Result GetPrivateProperty(const util::StringView &name, bool isSetter) const; + void AddPrivateName(std::vector privateProperties, uint32_t privateFieldCnt, + uint32_t instancePrivateMethodCnt, uint32_t staticPrivateMethodCnt); + friend class ir::ClassDefinition; +private: + bool IsMethod(uint32_t slot) const + { + return slot >= instancePrivateMethodStartSlot_ && slot < privateMethodEndSlot_; + } + + bool IsStaticMethod(uint32_t slot) const + { + return slot >= staticPrivateMethodStartSlot_; + } + + ArenaUnorderedMap computedNames_; + ArenaUnorderedMap privateNames_; + ArenaUnorderedMap privateGetters_; + ArenaUnorderedMap privateSetters_; + uint32_t privateFieldCnt_ {0}; + uint32_t instancePrivateMethodStartSlot_ {0}; + uint32_t staticPrivateMethodStartSlot_ {0}; + uint32_t privateMethodEndSlot_ {0}; + uint32_t instanceMethodValidation_ {0}; + uint32_t staticMethodValidation_ {0}; +}; + class CatchParamScope : public ParamScope { public: explicit CatchParamScope(ArenaAllocator *allocator, Scope *parent) : ParamScope(allocator, parent) {} diff --git a/es2panda/binder/variableFlags.h b/es2panda/binder/variableFlags.h index 31e099c88e8181bec21fe880e667e7ca30d93af7..182931730d8f4380685079b48c9399cac29172ef 100644 --- a/es2panda/binder/variableFlags.h +++ b/es2panda/binder/variableFlags.h @@ -53,6 +53,7 @@ enum class DeclType { _(CATCH, CatchScope) \ _(LOCAL, LocalScope) \ /* Variable Scopes */ \ + _(CLASS, ClassScope) \ _(LOOP, LoopScope) \ _(FUNCTION, FunctionScope) \ _(STATIC_BLOCK, StaticBlockScope) \ diff --git a/es2panda/compiler/base/lreference.cpp b/es2panda/compiler/base/lreference.cpp index a446b0da3f56dbd1b1b8d28fc28119545352bbcb..94cfa3bf197b77cbfd82c5a9c5c0c2e7b4b01369 100644 --- a/es2panda/compiler/base/lreference.cpp +++ b/es2panda/compiler/base/lreference.cpp @@ -18,6 +18,7 @@ #include #include #include +#include #include #include #include @@ -40,7 +41,9 @@ LReference::LReference(const ir::AstNode *node, PandaGen *pg, bool isDeclaration obj_ = pg_->AllocReg(); node_->AsMemberExpression()->CompileObject(pg_, obj_); - prop_ = node->AsMemberExpression()->CompileKey(pg_); + if (!node_->AsMemberExpression()->AccessPrivateProperty()) { + prop_ = node->AsMemberExpression()->CompileKey(pg_); + } } } @@ -52,7 +55,35 @@ void LReference::GetValue() break; } case ReferenceKind::MEMBER: { - pg_->LoadObjProperty(node_, obj_, prop_); + if (node_->AsMemberExpression()->AccessPrivateProperty()) { + auto name = node_->AsMemberExpression()->Property()->AsPrivateIdentifier()->Name(); + auto result = pg_->Scope()->FindPrivateName(name); + if (!result.result.isMethod) { + pg_->LoadAccumulator(node_, obj_); + pg_->LoadPrivateProperty(node_, result.lexLevel, result.result.slot); + break; + } + + if (result.result.isStatic) { + pg_->LoadLexicalVar(node_, result.lexLevel, result.result.validateMethodSlot); + pg_->Equal(node_, obj_); + pg_->ThrowTypeErrorIfFalse(node_, "Object does not have private property"); + } else { + pg_->LoadAccumulator(node_, obj_); + pg_->LoadPrivateProperty(node_, result.lexLevel, result.result.validateMethodSlot); + } + if (result.result.isSetter) { + pg_->ThrowTypeError(node_, "Property is not defined with Getter"); + } + if (result.result.isGetter) { + pg_->LoadAccumulator(node_, obj_); + pg_->LoadPrivateProperty(node_, result.lexLevel, result.result.slot); + break; + } + pg_->LoadLexicalVar(node_, result.lexLevel, result.result.slot); + } else { + pg_->LoadObjProperty(node_, obj_, prop_); + } break; } default: { @@ -71,6 +102,32 @@ void LReference::SetValue() case ReferenceKind::MEMBER: { if (node_->AsMemberExpression()->Object()->IsSuperExpression()) { pg_->StoreSuperProperty(node_, obj_, prop_); + } else if (node_->AsMemberExpression()->AccessPrivateProperty()) { + compiler::RegScope rs(pg_); + VReg valueReg = pg_->AllocReg(); + + auto name = node_->AsMemberExpression()->Property()->AsPrivateIdentifier()->Name(); + auto result = pg_->Scope()->FindPrivateName(name, true); + if (!result.result.isMethod) { + pg_->StorePrivateProperty(node_, result.lexLevel, result.result.slot, obj_); + break; + } + if (!result.result.isSetter) { + pg_->ThrowTypeError(node_, "Method is not writable"); + } + // store value + pg_->StoreAccumulator(node_, valueReg); + + if (result.result.isStatic) { + pg_->LoadLexicalVar(node_, result.lexLevel, result.result.validateMethodSlot); + pg_->Equal(node_, obj_); + pg_->ThrowTypeErrorIfFalse(node_, "Object does not have private property"); + } else { + pg_->LoadAccumulator(node_, obj_); + pg_->LoadPrivateProperty(node_, result.lexLevel, result.result.validateMethodSlot); + } + pg_->LoadAccumulator(node_, valueReg); + pg_->StorePrivateProperty(node_, result.lexLevel, result.result.slot, obj_); } else { pg_->StoreObjProperty(node_, obj_, prop_); } diff --git a/es2panda/compiler/core/emitter/emitter.cpp b/es2panda/compiler/core/emitter/emitter.cpp index 62e6875bfe6f67c864c3c05608560baea4be58ec..c0e43e1f255d6bed4f91dd678f78d6c7a2c2345e 100644 --- a/es2panda/compiler/core/emitter/emitter.cpp +++ b/es2panda/compiler/core/emitter/emitter.cpp @@ -537,6 +537,16 @@ void Emitter::GenBufferLiterals(ArenaVector(literal->GetInt()); break; } + case ir::LiteralTag::GETTER: { + valueLit.tag_ = panda::panda_file::LiteralTag::GETTER; + valueLit.value_ = literal->GetMethod().Mutf8(); + break; + } + case ir::LiteralTag::SETTER: { + valueLit.tag_ = panda::panda_file::LiteralTag::SETTER; + valueLit.value_ = literal->GetMethod().Mutf8(); + break; + } // TODO: support ir::LiteralTag::ASYNC_GENERATOR_METHOD case ir::LiteralTag::NULL_VALUE: { valueLit.tag_ = panda::panda_file::LiteralTag::NULLVALUE; diff --git a/es2panda/compiler/core/envScope.cpp b/es2panda/compiler/core/envScope.cpp index e98ab563cfae7c69becb361a263c7459057726c1..b45229fdb1d603c7d22384e6f4e3b6c1bed232ee 100644 --- a/es2panda/compiler/core/envScope.cpp +++ b/es2panda/compiler/core/envScope.cpp @@ -81,8 +81,8 @@ void LoopEnvScope::CopyPerIterationCtx() } } -StaticBlockEnvScope::StaticBlockEnvScope(PandaGen *pg, binder::StaticBlockScope *scope) - : scope_(scope->AsVariableScope()->NeedLexEnv() ? scope : nullptr) +VariableEnvScope::VariableEnvScope(PandaGen *pg, binder::VariableScope *scope) + : scope_(scope->NeedLexEnv() ? scope : nullptr) { Initialize(pg); if (HasEnv()) { @@ -90,7 +90,7 @@ StaticBlockEnvScope::StaticBlockEnvScope(PandaGen *pg, binder::StaticBlockScope } } -StaticBlockEnvScope::~StaticBlockEnvScope() +VariableEnvScope::~VariableEnvScope() { if (HasEnv()) { pg_->PopLexEnv(scope_->Node()); diff --git a/es2panda/compiler/core/envScope.h b/es2panda/compiler/core/envScope.h index 73a73f444de51e98dc42f37bc3b91ff20f76cbc7..1759b7e61440ae7d129c74e96356834289d77652 100644 --- a/es2panda/compiler/core/envScope.h +++ b/es2panda/compiler/core/envScope.h @@ -106,10 +106,10 @@ private: LexEnvContext lexEnvCtx_; }; -class StaticBlockEnvScope : public EnvScope { +class VariableEnvScope : public EnvScope { public: - explicit StaticBlockEnvScope(PandaGen *pg, binder::StaticBlockScope *scope); - ~StaticBlockEnvScope(); + explicit VariableEnvScope(PandaGen *pg, binder::VariableScope *scope); + ~VariableEnvScope(); bool HasEnv() const { diff --git a/es2panda/compiler/core/function.cpp b/es2panda/compiler/core/function.cpp index 70ef5a11d332156699411bdaedd70cdbbd7158bb..7e307aef37165564e21975e1c2c302d28e85282a 100644 --- a/es2panda/compiler/core/function.cpp +++ b/es2panda/compiler/core/function.cpp @@ -122,9 +122,22 @@ static void CompileFunctionParameterDeclaration(PandaGen *pg, const ir::ScriptFu } } -// TODO(huyunhui): reimplement the compilation of class field -static void CompileField(PandaGen *pg, const ir::ClassProperty *prop, VReg thisReg) +static void CompileField(PandaGen *pg, const ir::ClassProperty *prop, VReg thisReg, int32_t level) { + RegScope rs(pg); + Operand op; + binder::PrivateNameFindResult result; + if (prop->IsPrivate()) { + result = pg->Scope()->FindPrivateName(prop->Key()->AsPrivateIdentifier()->Name()); + } else if (prop->IsComputed() && prop->NeedCompileKey()) { + auto slot = prop->Parent()->AsClassDefinition()->GetSlot(prop->Key()); + pg->LoadLexicalVar(prop->Key(), level, slot); + op = pg->AllocReg(); + pg->StoreAccumulator(prop->Key(), std::get(op)); + } else { + op = pg->ToPropertyKey(prop->Key(), prop->IsComputed()); + } + if (!prop->Value()) { pg->LoadConst(prop, Constant::JS_UNDEFINED); } else { @@ -132,46 +145,29 @@ static void CompileField(PandaGen *pg, const ir::ClassProperty *prop, VReg thisR prop->Value()->Compile(pg); } - if (!prop->Key()->IsIdentifier()) { - if (pg->Binder()->Program()->Extension() == ScriptExtension::TS) { - // TS transformer already handled the cases, so don't throw error - return; - } - PandaGen::Unimplemented(); + if (prop->IsPrivate()) { + pg->DefineClassPrivateField(prop, result.lexLevel, result.result.slot, thisReg); + } else { + pg->DefineClassField(prop, thisReg, op); } - - pg->StoreObjByName(prop, thisReg, prop->Key()->AsIdentifier()->Name()); } -static void CompileInstanceFields(PandaGen *pg, const ir::ScriptFunction *decl) +static void CompileClassInitializer(PandaGen *pg, const ir::ScriptFunction *decl, bool isStatic) { - const auto &statements = decl->Parent()->Parent()->Parent()->AsClassDefinition()->Body(); + const auto *classDef = decl->Parent()->Parent()->Parent()->AsClassDefinition(); + const auto &statements = classDef->Body(); RegScope rs(pg); auto thisReg = pg->AllocReg(); pg->GetThis(decl); pg->StoreAccumulator(decl, thisReg); + auto [level, slot] = pg->Scope()->Find(nullptr, true); - for (auto const &stmt : statements) { - if (stmt->IsClassProperty()) { - const auto *prop = stmt->AsClassProperty(); - if (prop->IsStatic()) { - continue; - } - CompileField(pg, prop, thisReg); - } + if (!isStatic && classDef->HasInstancePrivateMethod()) { + binder::PrivateNameFindResult result = pg->Scope()->FindPrivateName("#method"); + pg->LoadConst(classDef, Constant::JS_UNDEFINED); + pg->DefineClassPrivateField(classDef, result.lexLevel, result.result.slot, thisReg); } -} - -static void CompileStaticInitializer(PandaGen *pg, const ir::ScriptFunction *decl) -{ - const auto &statements = decl->Parent()->Parent()->Parent()->AsClassDefinition()->Body(); - - RegScope rs(pg); - auto thisReg = pg->AllocReg(); - pg->GetThis(decl); - pg->StoreAccumulator(decl, thisReg); - for (auto const &stmt : statements) { if (stmt->IsMethodDefinition()) { continue; @@ -179,12 +175,16 @@ static void CompileStaticInitializer(PandaGen *pg, const ir::ScriptFunction *dec if (stmt->IsClassProperty()) { const auto *prop = stmt->AsClassProperty(); - if (prop->IsStatic()) { - CompileField(pg, prop, thisReg); + if (prop->IsStatic() == isStatic) { + CompileField(pg, prop, thisReg, level); } continue; } + if (!isStatic) { + continue; + } + ASSERT(stmt->IsClassStaticBlock()); const auto *staticBlock = stmt->AsClassStaticBlock(); staticBlock->Compile(pg); @@ -195,13 +195,28 @@ static void CompileFunction(PandaGen *pg) { const auto *decl = pg->RootNode()->AsScriptFunction(); - // TODO(szilagyia): move after super call - if (decl->IsConstructor() && pg->Binder()->Program()->Extension() != ScriptExtension::TS) { - CompileInstanceFields(pg, decl); + if (decl->IsConstructor()) { + const auto *classDef = util::Helpers::GetClassDefiniton(decl); + if (classDef->Super() == nullptr && classDef->NeedInstanceInitializer()) { + RegScope rs(pg); + auto callee = pg->AllocReg(); + auto thisReg = pg->AllocReg(); + + pg->GetThis(decl); + pg->StoreAccumulator(decl, thisReg); + + auto [level, slot] = pg->Scope()->Find(classDef->InstanceInitializer()->Key()); + pg->LoadLexicalVar(decl, level, slot); + pg->StoreAccumulator(decl, callee); + + pg->CallThis(decl, callee, 1); + } } - if (decl->IsStaticInitializer()) { - CompileStaticInitializer(pg, decl); + if (decl->IsStaticInitializer() || decl->IsInstanceInitializer()) { + CompileClassInitializer(pg, decl, decl->IsStaticInitializer()); + pg->ImplicitReturn(decl); + return; } auto *funcParamScope = pg->TopScope()->ParamScope(); diff --git a/es2panda/compiler/core/pandagen.cpp b/es2panda/compiler/core/pandagen.cpp index 53786cbdf5aa2e352d461f5a667220381776d7be..577471a6eebeda28d71f66546ce40b58fef7de79 100644 --- a/es2panda/compiler/core/pandagen.cpp +++ b/es2panda/compiler/core/pandagen.cpp @@ -442,6 +442,27 @@ void PandaGen::StoreObjProperty(const ir::AstNode *node, VReg obj, const Operand StoreObjByName(node, obj, std::get(prop)); } +void PandaGen::DefineClassField(const ir::AstNode *node, VReg obj, const Operand &prop) +{ + if (std::holds_alternative(prop)) { + DefineFieldByValue(node, obj, std::get(prop)); + return; + } + + if (std::holds_alternative(prop)) { + DefineFieldByIndex(node, obj, std::get(prop)); + return; + } + + ASSERT(std::holds_alternative(prop)); + DefineFieldByName(node, obj, std::get(prop)); +} + +void PandaGen::DefineClassPrivateField(const ir::AstNode *node, uint32_t level, uint32_t slot, VReg obj) +{ + ra_.Emit(node, level, slot, obj); +} + void PandaGen::StoreOwnProperty(const ir::AstNode *node, VReg obj, const Operand &prop, bool nameSetting) { if (std::holds_alternative(prop)) { @@ -539,6 +560,12 @@ void PandaGen::StoreObjByName(const ir::AstNode *node, VReg obj, const util::Str strings_.insert(prop); } +void PandaGen::DefineFieldByName(const ir::AstNode *node, VReg obj, const util::StringView &prop) +{ + ra_.Emit(node, prop, obj); + strings_.insert(prop); +} + void PandaGen::LoadObjByIndex(const ir::AstNode *node, VReg obj, int64_t index) { LoadAccumulator(node, obj); // object is load to acc @@ -570,6 +597,16 @@ void PandaGen::StoreObjByIndex(const ir::AstNode *node, VReg obj, int64_t index) ra_.Emit(node, obj, index); } +void PandaGen::DefineFieldByValue(const ir::AstNode *node, VReg obj, VReg prop) +{ + ra_.Emit(node, prop, obj); +} + +void PandaGen::DefineFieldByIndex(const ir::AstNode *node, VReg obj, int64_t index) +{ + ra_.Emit(node, index, obj); +} + void PandaGen::StOwnByName(const ir::AstNode *node, VReg obj, const util::StringView &prop, bool nameSetting) { nameSetting ? ra_.Emit(node, 0, prop, obj) : @@ -2057,6 +2094,11 @@ VReg PandaGen::LoadPropertyKey(const ir::Expression *prop, bool isComputed) return propReg; } +void PandaGen::ToComputedPropertyKey(const ir::AstNode *node) +{ + ra_.Emit(node); +} + void PandaGen::StLetOrClassToGlobalRecord(const ir::AstNode *node, const util::StringView &name) { ra_.Emit(node, 0, name); @@ -2133,4 +2175,43 @@ void PandaGen::ReArrangeIc() } } +void PandaGen::CreatePrivateProperty(const ir::AstNode *node, uint32_t num, int32_t bufIdx) +{ + std::string idxStr = std::string(context_->Binder()->Program()->RecordName()) + "_" + std::to_string(bufIdx); + util::UString litId(idxStr, allocator_); + ra_.Emit(node, num, litId.View()); +} + +void PandaGen::TestIn(const ir::AstNode *node, uint32_t level, uint32_t slot) +{ + ra_.Emit(node, 0, level, slot); +} + +void PandaGen::LoadPrivateProperty(const ir::AstNode *node, uint32_t level, uint32_t slot) +{ + ra_.Emit(node, 0, level, slot); +} + +void PandaGen::StorePrivateProperty(const ir::AstNode *node, uint32_t level, uint32_t slot, VReg obj) +{ + ra_.Emit(node, 0, level, slot, obj); +} +void PandaGen::ThrowTypeErrorIfFalse(const ir::AstNode *node, util::StringView str) +{ + auto *trueLabel = AllocLabel(); + BranchIfTrue(node, trueLabel); + ThrowTypeError(node, str); + SetLabel(node, trueLabel); +} + +void PandaGen::ThrowTypeError(const ir::AstNode *node, util::StringView str) +{ + LoadAccumulatorString(node, str); + VReg reg = AllocReg(); + StoreAccumulator(node, reg); + TryLoadGlobalByName(node, "TypeError"); + ra_.Emit(node, 0, reg); + EmitThrow(node); +} + } // namespace panda::es2panda::compiler diff --git a/es2panda/compiler/core/pandagen.h b/es2panda/compiler/core/pandagen.h index a11ae280c6c0cb6eab304e8e55950ee3a7e0c6e9..c7ce53dc7cda8cef67c8fb80302d576f1d7014d8 100644 --- a/es2panda/compiler/core/pandagen.h +++ b/es2panda/compiler/core/pandagen.h @@ -295,6 +295,8 @@ public: void LoadObjByName(const ir::AstNode *node, VReg obj, const util::StringView &prop); void StoreObjProperty(const ir::AstNode *node, VReg obj, const Operand &prop); + void DefineClassField(const ir::AstNode *node, VReg obj, const Operand &prop); + void DefineClassPrivateField(const ir::AstNode *node, uint32_t level, uint32_t slot, VReg obj); void StoreOwnProperty(const ir::AstNode *node, VReg obj, const Operand &prop, bool nameSetting = false); void DeleteObjProperty(const ir::AstNode *node, VReg obj, const Operand &prop); void LoadAccumulator(const ir::AstNode *node, VReg reg); @@ -465,6 +467,10 @@ public: void StoreObjByIndex(const ir::AstNode *node, VReg obj, int64_t index); void StoreObjByValue(const ir::AstNode *node, VReg obj, VReg prop); + void DefineFieldByName(const ir::AstNode *node, VReg obj, const util::StringView &prop); + void DefineFieldByIndex(const ir::AstNode *node, VReg obj, int64_t index); + void DefineFieldByValue(const ir::AstNode *node, VReg obj, VReg prop); + void StOwnByName(const ir::AstNode *node, VReg obj, const util::StringView &prop, bool nameSetting = false); void StOwnByValue(const ir::AstNode *node, VReg obj, VReg prop, bool nameSetting = false); void StOwnByIndex(const ir::AstNode *node, VReg obj, int64_t index); @@ -472,9 +478,17 @@ public: Operand ToNamedPropertyKey(const ir::Expression *prop, bool isComputed); Operand ToPropertyKey(const ir::Expression *prop, bool isComputed); VReg LoadPropertyKey(const ir::Expression *prop, bool isComputed); + void ToComputedPropertyKey(const ir::AstNode *node); void ReArrangeIc(); + void CreatePrivateProperty(const ir::AstNode *node, uint32_t num, int32_t bufIdx); + void TestIn(const ir::AstNode *node, uint32_t level, uint32_t slot); + void LoadPrivateProperty(const ir::AstNode *node, uint32_t level, uint32_t slot); + void StorePrivateProperty(const ir::AstNode *node, uint32_t level, uint32_t slot, VReg obj); + void ThrowTypeErrorIfFalse(const ir::AstNode *node, util::StringView str); + void ThrowTypeError(const ir::AstNode *node, util::StringView str); + /* * Since the [Function] is not implemented yet, We compile the test262's framework code * which obtains the [global] Object as following into [LoadConst.Global] directly. diff --git a/es2panda/compiler/function/functionBuilder.cpp b/es2panda/compiler/function/functionBuilder.cpp index 9167371e72e05ffb63a66f7c5c54a876cd69e96e..1c8dbebc14f110ad72d1b109a0e6478a69d20665 100644 --- a/es2panda/compiler/function/functionBuilder.cpp +++ b/es2panda/compiler/function/functionBuilder.cpp @@ -57,10 +57,10 @@ void FunctionBuilder::ImplicitReturn(const ir::AstNode *node) const return; } - pg_->GetThis(rootNode); + pg_->GetThis(node); if (rootNode->AsScriptFunction()->IsConstructor() && util::Helpers::GetClassDefiniton(rootNode->AsScriptFunction())->Super()) { - pg_->ThrowIfSuperNotCorrectCall(rootNode, 0); + pg_->ThrowIfSuperNotCorrectCall(node, 0); } pg_->NotifyConcurrentResult(node); diff --git a/es2panda/es2panda.cpp b/es2panda/es2panda.cpp index 38ec4c58a37c7e1deba735a1f6e366955c9fbcc8..e654ceb7f7d2f9eb8f1c319ddd411a640eaba3c7 100644 --- a/es2panda/es2panda.cpp +++ b/es2panda/es2panda.cpp @@ -74,8 +74,7 @@ panda::pandasm::Program *Compiler::Compile(const SourceFile &input, const Compil } try { - parser_->SetDebug(options.isDebug); - auto ast = parser_->Parse(fname, src, rname, kind); + auto ast = parser_->Parse(fname, src, rname, options, kind); ast.Binder()->SetProgram(&ast); if (options.dumpAst) { diff --git a/es2panda/es2panda.h b/es2panda/es2panda.h index 76552a3563245e2b6aa4e5c9e608654df11e5ed5..85ea26ff268d742a9ec71b194e52f7ca2e99ddea 100644 --- a/es2panda/es2panda.h +++ b/es2panda/es2panda.h @@ -94,6 +94,7 @@ struct CompilerOptions { PatchFixOptions patchFixOptions; bool bcVersion {false}; bool bcMinVersion {false}; + int targetApiVersion {0}; std::unordered_map cacheFiles; }; diff --git a/es2panda/ir/astNode.h b/es2panda/ir/astNode.h index 8c842fe588868cce355c338cb2bd8c3954342527..16f58beaaca8bf897967baea5c22fed0ae556c8a 100644 --- a/es2panda/ir/astNode.h +++ b/es2panda/ir/astNode.h @@ -93,6 +93,7 @@ enum class ScriptFunctionFlags { CONCURRENT = 1 << 7, SHOW_SOURCE = 1 << 8, STATIC_INITIALIZER = 1 << 9, + INSTANCE_INITIALIZER = 1 << 10, }; DEFINE_BITOPS(ScriptFunctionFlags) diff --git a/es2panda/ir/astNodeMapping.h b/es2panda/ir/astNodeMapping.h index 9bbf24dedd1ea70fc5400e6071da86fcd79dc447..746d8f0f239c90bbc03e6dc5b795f871e736e743 100644 --- a/es2panda/ir/astNodeMapping.h +++ b/es2panda/ir/astNodeMapping.h @@ -65,6 +65,7 @@ _(NULL_LITERAL, NullLiteral) \ _(NUMBER_LITERAL, NumberLiteral) \ _(OMITTED_EXPRESSION, OmittedExpression) \ + _(PRIVATE_IDENTIFIER, PrivateIdentifier) \ _(PROPERTY, Property) \ _(REGEXP_LITERAL, RegExpLiteral) \ _(RETURN_STATEMENT, ReturnStatement) \ diff --git a/es2panda/ir/base/classDefinition.cpp b/es2panda/ir/base/classDefinition.cpp index 24c0d6df2855b186f2480773867fb0513956e09a..887b455d1f0f3eff56604568b92be4089d8b6ee9 100644 --- a/es2panda/ir/base/classDefinition.cpp +++ b/es2panda/ir/base/classDefinition.cpp @@ -130,11 +130,10 @@ void ClassDefinition::InitializeClassName(compiler::PandaGen *pg) const } // NOLINTNEXTLINE(google-runtime-references) -int32_t ClassDefinition::CreateClassStaticProperties(compiler::PandaGen *pg, util::BitSet &compiled) const +int32_t ClassDefinition::CreateClassPublicBuffer(compiler::PandaGen *pg, util::BitSet &compiled) const { auto *buf = pg->NewLiteralBuffer(); compiler::LiteralBuffer staticBuf(pg->Allocator()); - bool seenComputed = false; uint32_t instancePropertyCount = 0; std::unordered_map propNameMap; std::unordered_map staticPropNameMap; @@ -148,14 +147,17 @@ int32_t ClassDefinition::CreateClassStaticProperties(compiler::PandaGen *pg, uti const ir::MethodDefinition *prop = properties[i]->AsMethodDefinition(); if (prop->Computed()) { - seenComputed = true; - continue; + break; } if (prop->IsAccessor()) { break; } + if (prop->IsPrivate()) { + continue; + } + if (prop->IsAbstract()) { compiled.Set(i); continue; @@ -173,10 +175,6 @@ int32_t ClassDefinition::CreateClassStaticProperties(compiler::PandaGen *pg, uti size_t bufferPos = literalBuf->Literals().size(); auto res = nameMap.insert({name, bufferPos}); if (res.second) { - if (seenComputed) { - break; - } - if (!prop->IsStatic()) { instancePropertyCount++; } @@ -226,6 +224,55 @@ int32_t ClassDefinition::CreateClassStaticProperties(compiler::PandaGen *pg, uti return pg->AddLiteralBuffer(buf); } +int32_t ClassDefinition::CreateClassPrivateBuffer(compiler::PandaGen *pg) const +{ + auto *buf = pg->NewLiteralBuffer(); + compiler::LiteralBuffer staticBuf(pg->Allocator()); + uint32_t instancePropertyCount = 0; + + for (const auto *prop : body_) { + if (!prop->IsMethodDefinition()) { + continue; + } + + const auto *methodDef = prop->AsMethodDefinition(); + if (!methodDef->IsPrivate()) { + continue; + } + + compiler::LiteralBuffer *literalBuf = methodDef->IsStatic() ? &staticBuf : (instancePropertyCount++, buf); + const ir::FunctionExpression *func = methodDef->Value()->AsFunctionExpression(); + const util::StringView &internalName = func->Function()->Scope()->InternalName(); + Literal *value = nullptr; + Literal *methodAffiliate = pg->Allocator()->New(LiteralTag::METHODAFFILIATE, + func->Function()->FormalParamsLength()); + switch (methodDef->Kind()) { + case MethodDefinitionKind::METHOD: { + value = pg->Allocator()->New(LiteralTag::METHOD, internalName); + break; + } + case MethodDefinitionKind::GET: { + value = pg->Allocator()->New(LiteralTag::GETTER, internalName); + break; + } + case MethodDefinitionKind::SET: { + value = pg->Allocator()->New(LiteralTag::SETTER, internalName); + break; + } + default: { + UNREACHABLE(); + } + } + literalBuf->Add(value); + literalBuf->Add(methodAffiliate); + } + + buf->Insert(&staticBuf); + buf->Add(pg->Allocator()->New(instancePropertyCount)); + + return pg->AddLiteralBuffer(buf); +} + void ClassDefinition::CompileMissingProperties(compiler::PandaGen *pg, const util::BitSet &compiled, compiler::VReg classReg) const { @@ -246,6 +293,10 @@ void ClassDefinition::CompileMissingProperties(compiler::PandaGen *pg, const uti continue; } + if (prop->IsPrivate()) { + continue; + } + if (prop->IsAbstract()) { continue; } @@ -296,7 +347,9 @@ void ClassDefinition::CompileMissingProperties(compiler::PandaGen *pg, const uti } } - pg->LoadAccumulator(this, classReg); + if (NeedInstanceInitializer()) { + InstanceInitialize(pg, protoReg); + } } void ClassDefinition::StaticInitialize(compiler::PandaGen *pg, compiler::VReg classReg) const @@ -314,6 +367,27 @@ void ClassDefinition::StaticInitialize(compiler::PandaGen *pg, compiler::VReg cl pg->LoadAccumulator(this, classReg); } +void ClassDefinition::InstanceInitialize(compiler::PandaGen *pg, compiler::VReg protoReg) const +{ + pg->StoreAccumulator(this, protoReg); + instanceInitializer_->Value()->Compile(pg); + pg->StoreLexicalVar(instanceInitializer_, 0, GetSlot(instanceInitializer_->Key())); +} + +void ClassDefinition::CompileComputedKeys(compiler::PandaGen *pg) const +{ + for (const auto &stmt : body_) { + if (stmt->IsClassProperty()) { + const ir::ClassProperty *prop = stmt->AsClassProperty(); + if (prop->IsComputed() && prop->NeedCompileKey()) { + prop->Key()->Compile(pg); + pg->ToComputedPropertyKey(prop->Key()); + pg->StoreLexicalVar(prop->Key(), 0, GetSlot(prop->Key())); + } + } + } +} + void ClassDefinition::Compile(compiler::PandaGen *pg) const { if (declare_) { @@ -325,18 +399,36 @@ void ClassDefinition::Compile(compiler::PandaGen *pg) const compiler::LocalRegScope lrs(pg, scope_); + compiler::VariableEnvScope envScope(pg, scope_); + compiler::VReg baseReg = CompileHeritageClause(pg); util::StringView ctorId = ctor_->Function()->Scope()->InternalName(); util::BitSet compiled(body_.size()); - int32_t bufIdx = CreateClassStaticProperties(pg, compiled); + int32_t bufIdx = CreateClassPublicBuffer(pg, compiled); pg->DefineClassWithBuffer(this, ctorId, bufIdx, baseReg); pg->StoreAccumulator(this, classReg); + + if (HasStaticPrivateMethod()) { + pg->StoreLexicalVar(this, 0, scope_->staticMethodValidation_); + } + InitializeClassName(pg); CompileMissingProperties(pg, compiled, classReg); + if (hasComputedKey_) { + CompileComputedKeys(pg); + } + + if (hasPrivateElement_) { + int32_t bufIdx = CreateClassPrivateBuffer(pg); + pg->CreatePrivateProperty(this, scope_->privateFieldCnt_, bufIdx); + } + + pg->LoadAccumulator(this, classReg); + if (NeedStaticInitializer()) { StaticInitialize(pg, classReg); } @@ -350,7 +442,7 @@ checker::Type *ClassDefinition::Check(checker::Checker *checker) const void ClassDefinition::UpdateSelf(const NodeUpdater &cb, binder::Binder *binder) { - auto scopeCtx = binder::LexicalScope::Enter(binder, scope_); + auto scopeCtx = binder::LexicalScope::Enter(binder, scope_); if (ident_) { ident_ = std::get(cb(ident_))->AsIdentifier(); @@ -383,4 +475,57 @@ void ClassDefinition::UpdateSelf(const NodeUpdater &cb, binder::Binder *binder) } } + +void ClassDefinition::BuildClassEnvironment() +{ + int instancePrivateMethodCnt = 0; + int staticPrivateMethodCnt = 0; + int privateFieldCnt = 0; + std::vector privateProperties; + for (const auto *stmt : body_) { + if (stmt->IsMethodDefinition()) { + auto *methodDef = stmt->AsMethodDefinition(); + if (methodDef->IsPrivate()) { + privateProperties.push_back(stmt); + methodDef->IsStatic() ? staticPrivateMethodCnt ++ : instancePrivateMethodCnt++; + } + continue; + } + + if (stmt->IsClassStaticBlock()) { + needStaticInitializer_ = true; + continue; + } + + ASSERT(stmt->IsClassProperty()); + const auto *prop = stmt->AsClassProperty(); + if (prop->IsComputed() && prop->NeedCompileKey()) { + hasComputedKey_ = true; + scope_->AddClassVariable(prop->Key()); + } + if (prop->IsStatic()) { + needStaticInitializer_ = true; + } else { + needInstanceInitializer_ = true; + } + if (prop->Key()->IsPrivateIdentifier()) { + privateFieldCnt++; + privateProperties.push_back(stmt); + } + } + + if (!privateProperties.empty()) { + hasPrivateElement_ = true; + scope_->AddPrivateName(privateProperties, privateFieldCnt, instancePrivateMethodCnt, staticPrivateMethodCnt); + } + + if (instancePrivateMethodCnt > 0) { + needInstanceInitializer_ = true; + } + + if (NeedInstanceInitializer()) { + scope_->AddClassVariable(instanceInitializer_->Key()); + } +} + } // namespace panda::es2panda::ir diff --git a/es2panda/ir/base/classDefinition.h b/es2panda/ir/base/classDefinition.h index 819245bfcff0525250153b4a2b55317e00467569..4963cc245564941c3aee3f233870c8846a0d1e1c 100644 --- a/es2panda/ir/base/classDefinition.h +++ b/es2panda/ir/base/classDefinition.h @@ -18,6 +18,8 @@ #include #include +#include +#include #include namespace panda::es2panda::compiler { @@ -44,12 +46,12 @@ class TSIndexSignature; class ClassDefinition : public AstNode { public: - explicit ClassDefinition(binder::LocalScope *scope, Identifier *ident, TSTypeParameterDeclaration *typeParams, + explicit ClassDefinition(binder::ClassScope *scope, Identifier *ident, TSTypeParameterDeclaration *typeParams, TSTypeParameterInstantiation *superTypeParams, ArenaVector &&implements, MethodDefinition *ctor, - MethodDefinition *staticInitializer, Expression *superClass, - ArenaVector &&body, ArenaVector &&indexSignatures, - bool declare, bool abstract) + MethodDefinition *staticInitializer, MethodDefinition *instanceInitializer, + Expression *superClass, ArenaVector &&body, + ArenaVector &&indexSignatures, bool declare, bool abstract) : AstNode(AstNodeType::CLASS_DEFINITION), scope_(scope), ident_(ident), @@ -58,6 +60,7 @@ public: implements_(std::move(implements)), ctor_(ctor), staticInitializer_(staticInitializer), + instanceInitializer_(instanceInitializer), superClass_(superClass), body_(std::move(body)), indexSignatures_(std::move(indexSignatures)), @@ -65,15 +68,9 @@ public: abstract_(abstract), exportDefault_(false) { - for (const auto *stmt : body_) { - if (stmt->IsClassStaticBlock() || (stmt->IsClassProperty() && stmt->AsClassProperty()->IsStatic())) { - needStaticInitializer_ = true; - break; - } - } } - binder::LocalScope *Scope() const + binder::ClassScope *Scope() const { return scope_; } @@ -169,9 +166,9 @@ public: return staticInitializer_; } - bool NeedStaticInitializer() const + MethodDefinition *InstanceInitializer() const { - return needStaticInitializer_; + return instanceInitializer_; } const TSTypeParameterInstantiation *SuperTypeParams() const @@ -184,10 +181,37 @@ public: return superTypeParams_; } + bool NeedStaticInitializer() const + { + return needStaticInitializer_; + } + + bool NeedInstanceInitializer() const + { + return needInstanceInitializer_; + } + + uint32_t GetSlot(const Expression *key) const + { + return scope_->GetSlot(key); + } + + bool HasInstancePrivateMethod() const + { + return scope_->instanceMethodValidation_ != 0; + } + + bool HasStaticPrivateMethod() const + { + return scope_->staticMethodValidation_ != 0; + } + const FunctionExpression *Ctor() const; util::StringView GetName() const; + void BuildClassEnvironment(); + void Iterate(const NodeTraverser &cb) const override; void Dump(ir::AstDumper *dumper) const override; void Compile(compiler::PandaGen *pg) const override; @@ -197,17 +221,22 @@ public: private: compiler::VReg CompileHeritageClause(compiler::PandaGen *pg) const; void InitializeClassName(compiler::PandaGen *pg) const; - int32_t CreateClassStaticProperties(compiler::PandaGen *pg, util::BitSet &compiled) const; + int32_t CreateClassPublicBuffer(compiler::PandaGen *pg, util::BitSet &compiled) const; + int32_t CreateClassPrivateBuffer(compiler::PandaGen *pg) const; void CompileMissingProperties(compiler::PandaGen *pg, const util::BitSet &compiled, compiler::VReg classReg) const; void StaticInitialize(compiler::PandaGen *pg, compiler::VReg classReg) const; + void InstanceInitialize(compiler::PandaGen *pg, compiler::VReg classReg) const; + void CompileComputedKeys(compiler::PandaGen *pg) const; + - binder::LocalScope *scope_; + binder::ClassScope *scope_; Identifier *ident_; TSTypeParameterDeclaration *typeParams_; TSTypeParameterInstantiation *superTypeParams_; ArenaVector implements_; MethodDefinition *ctor_; MethodDefinition *staticInitializer_; + MethodDefinition *instanceInitializer_; Expression *superClass_; ArenaVector body_; ArenaVector indexSignatures_; @@ -215,6 +244,9 @@ private: bool abstract_; bool exportDefault_; bool needStaticInitializer_ {false}; + bool needInstanceInitializer_ {false}; + bool hasComputedKey_ {false}; + bool hasPrivateElement_ {false}; }; } // namespace panda::es2panda::ir diff --git a/es2panda/ir/base/classProperty.h b/es2panda/ir/base/classProperty.h index b4397e8460fd03b6892c73013d0481f9b4357bc8..47c915b53ee3e0d70b3d51f7d2772a824c0c3f1f 100644 --- a/es2panda/ir/base/classProperty.h +++ b/es2panda/ir/base/classProperty.h @@ -17,6 +17,7 @@ #define ES2PANDA_PARSER_INCLUDE_AST_CLASS_PROPERTY_H #include +#include namespace panda::es2panda::compiler { class PandaGen; @@ -101,6 +102,11 @@ public: return isComputed_; } + bool IsPrivate() const + { + return key_->IsPrivateIdentifier(); + } + void SetComputed(bool computed) { isComputed_ = computed; @@ -116,6 +122,11 @@ public: return definite_; } + bool NeedCompileKey() const + { + return !key_->IsLiteral(); + } + void Iterate(const NodeTraverser &cb) const override; void Dump(ir::AstDumper *dumper) const override; void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; diff --git a/es2panda/ir/base/classStaticBlock.cpp b/es2panda/ir/base/classStaticBlock.cpp index 26b410e90f2987fd8322bf9fb4797e2ff6ca36ee..8e521fe466180d71a6e66f028614a66dd78c7e1e 100644 --- a/es2panda/ir/base/classStaticBlock.cpp +++ b/es2panda/ir/base/classStaticBlock.cpp @@ -35,7 +35,7 @@ void ClassStaticBlock::Dump(ir::AstDumper *dumper) const void ClassStaticBlock::Compile([[maybe_unused]] compiler::PandaGen *pg) const { - compiler::StaticBlockEnvScope envScope(pg, blockStatement_->Scope()->AsStaticBlockScope()); + compiler::VariableEnvScope envScope(pg, blockStatement_->Scope()->AsVariableScope()); blockStatement_->Compile(pg); } diff --git a/es2panda/ir/base/methodDefinition.h b/es2panda/ir/base/methodDefinition.h index 1d3a1e2efa540dffd64cfe902934ac310626cf8f..217d8863026127b46604dd840234222700766646 100644 --- a/es2panda/ir/base/methodDefinition.h +++ b/es2panda/ir/base/methodDefinition.h @@ -17,6 +17,7 @@ #define ES2PANDA_PARSER_INCLUDE_AST_METHOD_DEFINITION_H #include +#include namespace panda::es2panda::compiler { class PandaGen; @@ -29,7 +30,6 @@ class Type; namespace panda::es2panda::ir { -class Expression; class FunctionExpression; enum class MethodDefinitionKind { CONSTRUCTOR, METHOD, GET, SET }; @@ -111,6 +111,11 @@ public: return (modifiers_ & ModifierFlags::OPTIONAL) != 0; } + bool IsPrivate() const + { + return key_->IsPrivateIdentifier(); + } + const ArenaVector &Overloads() const { return overloads_; diff --git a/es2panda/ir/base/scriptFunction.h b/es2panda/ir/base/scriptFunction.h index dcb7a94ac5e869e06f6457636561c6ac92756552..98805de3a1a47d2de640843e12f7f274d7f0b66a 100644 --- a/es2panda/ir/base/scriptFunction.h +++ b/es2panda/ir/base/scriptFunction.h @@ -155,9 +155,14 @@ public: return (flags_ & ir::ScriptFunctionFlags::STATIC_INITIALIZER) != 0; } + bool IsInstanceInitializer() const + { + return (flags_ & ir::ScriptFunctionFlags::INSTANCE_INITIALIZER) != 0; + } + bool IsMethod() const { - return (flags_ & ir::ScriptFunctionFlags::METHOD) != 0 || IsStaticInitializer(); + return (flags_ & ir::ScriptFunctionFlags::METHOD) != 0 || IsInstanceInitializer() || IsStaticInitializer(); } bool FunctionBodyIsExpression() const diff --git a/es2panda/ir/expressions/binaryExpression.cpp b/es2panda/ir/expressions/binaryExpression.cpp index 526685b4539eab37581d8a00f570c329290018f7..1a51b5e57da887373d894a12e8f76d4781c962e0 100644 --- a/es2panda/ir/expressions/binaryExpression.cpp +++ b/es2panda/ir/expressions/binaryExpression.cpp @@ -20,6 +20,8 @@ #include #include #include +#include +#include #include namespace panda::es2panda::ir { @@ -78,8 +80,37 @@ void BinaryExpression::CompileLogical(compiler::PandaGen *pg) const pg->SetLabel(this, endLabel); } +void BinaryExpression::CompilePrivateIn(compiler::PandaGen *pg) const +{ + ASSERT(operator_ == lexer::TokenType::KEYW_IN); + auto name = left_->AsPrivateIdentifier()->Name(); + auto result = pg->Scope()->FindPrivateName(name); + + right_->Compile(pg); + if (!result.result.isMethod) { + pg->TestIn(this, result.lexLevel, result.result.slot); + return; + } + // Instance private method check symbol("#method") + if (!result.result.isStatic) { + pg->TestIn(this, result.lexLevel, result.result.validateMethodSlot); + return; + } + // Static private method check whether equals the class object + compiler::RegScope rs(pg); + compiler::VReg rhs = pg->AllocReg(); + pg->StoreAccumulator(right_, rhs); + pg->LoadLexicalVar(this, result.lexLevel, result.result.validateMethodSlot); + pg->Equal(this, rhs); +} + void BinaryExpression::Compile(compiler::PandaGen *pg) const { + if (left_->IsPrivateIdentifier()) { + CompilePrivateIn(pg); + return; + } + if (IsLogical()) { CompileLogical(pg); return; diff --git a/es2panda/ir/expressions/binaryExpression.h b/es2panda/ir/expressions/binaryExpression.h index 0fb29f1d630ed46a62cad1274140bcb8efd83be9..2ca0133030889215a8ce805d598c0571755a9ec2 100644 --- a/es2panda/ir/expressions/binaryExpression.h +++ b/es2panda/ir/expressions/binaryExpression.h @@ -29,12 +29,16 @@ class Type; } // namespace panda::es2panda::checker namespace panda::es2panda::ir { +class PrivateNameFindResult; class BinaryExpression : public Expression { public: explicit BinaryExpression(Expression *leftExpr, Expression *rightExpr, lexer::TokenType operatorType) : Expression(AstNodeType::BINARY_EXPRESSION), left_(leftExpr), right_(rightExpr), operator_(operatorType) { + if (right_->IsPrivateIdentifier()) { + throw Error{ErrorType::SYNTAX, "Unexpect private identifier", right_->Start().line, right_->Start().index}; + } } const Expression *Left() const @@ -87,6 +91,7 @@ public: void UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) override; private: + void CompilePrivateIn(compiler::PandaGen *pg) const; Expression *left_; Expression *right_; lexer::TokenType operator_; diff --git a/es2panda/ir/expressions/callExpression.cpp b/es2panda/ir/expressions/callExpression.cpp index 2230541625f4ea0712bcaeec5d52fa777b52e716..e09d1f989a81031abb887059074654208d4646fc 100644 --- a/es2panda/ir/expressions/callExpression.cpp +++ b/es2panda/ir/expressions/callExpression.cpp @@ -23,6 +23,7 @@ #include #include #include +#include #include #include #include @@ -120,6 +121,20 @@ void CallExpression::Compile(compiler::PandaGen *pg) const pg->LoadAccumulator(this, newThis); pg->SetThis(this); + + const auto *classDef = util::Helpers::GetClassDefiniton(util::Helpers::GetContainingConstructor(this)); + if (classDef->NeedInstanceInitializer()) { + auto callee = pg->AllocReg(); + auto thisReg = pg->AllocReg(); + + auto [level, slot] = pg->Scope()->Find(classDef->InstanceInitializer()->Key()); + pg->LoadLexicalVar(this, level, slot); + pg->StoreAccumulator(this, callee); + + pg->MoveVreg(this, thisReg, newThis); + + pg->CallThis(this, callee, 1); + } return; } diff --git a/es2panda/ir/expressions/literal.h b/es2panda/ir/expressions/literal.h index c842a4137ac334ac8f2ff6af033ca05d6da0066f..b92ea7b48612a3c4745ae456d970764575f999c0 100644 --- a/es2panda/ir/expressions/literal.h +++ b/es2panda/ir/expressions/literal.h @@ -46,6 +46,8 @@ enum class LiteralTag { LITERALBUFFERINDEX = 23, LITERALARRAY = 24, BUILTINTYPEINDEX = 25, + GETTER = 26, + SETTER = 27, NULL_VALUE = 255, }; diff --git a/es2panda/ir/expressions/literals/taggedLiteral.h b/es2panda/ir/expressions/literals/taggedLiteral.h index 06cd7028bd1b9e33f260e8ffd60d5110e448e163..006b87d98134abdf8c53ce7501b41b07ec2c11ab 100644 --- a/es2panda/ir/expressions/literals/taggedLiteral.h +++ b/es2panda/ir/expressions/literals/taggedLiteral.h @@ -60,7 +60,7 @@ public: const util::StringView &Method() const { ASSERT(tag_ == LiteralTag::ACCESSOR || tag_ == LiteralTag::METHOD || tag_ == LiteralTag::GENERATOR_METHOD || - tag_ == LiteralTag::ASYNC_GENERATOR_METHOD); + tag_ == LiteralTag::ASYNC_GENERATOR_METHOD || tag_== LiteralTag::GETTER || tag_ == LiteralTag::SETTER); return str_; } diff --git a/es2panda/ir/expressions/memberExpression.cpp b/es2panda/ir/expressions/memberExpression.cpp index c3bbed8a26bd1e298fad99e4b7128b41c5b79a30..455b5c824f24532be7b61e02d9b2b7ee441af61b 100644 --- a/es2panda/ir/expressions/memberExpression.cpp +++ b/es2panda/ir/expressions/memberExpression.cpp @@ -18,7 +18,9 @@ #include #include #include +#include #include +#include #include #include @@ -61,6 +63,34 @@ void MemberExpression::Compile(compiler::PandaGen *pg) const void MemberExpression::Compile(compiler::PandaGen *pg, compiler::VReg objReg) const { CompileObject(pg, objReg); + if (AccessPrivateProperty()) { + auto name = property_->AsPrivateIdentifier()->Name(); + auto result = pg->Scope()->FindPrivateName(name); + if (!result.result.isMethod) { + pg->LoadAccumulator(this, objReg); + pg->LoadPrivateProperty(this, result.lexLevel, result.result.slot); + return; + } + if (result.result.isSetter) { + pg->ThrowTypeError(this, "Property is not defined with Getter"); + } + if (result.result.isStatic) { + pg->LoadLexicalVar(this, result.lexLevel, result.result.validateMethodSlot); + pg->Equal(this, objReg); + pg->ThrowTypeErrorIfFalse(this, "Object does not have private property"); + } else { + pg->LoadAccumulator(this, objReg); + pg->LoadPrivateProperty(this, result.lexLevel, result.result.validateMethodSlot); + } + + if (result.result.isGetter) { + pg->LoadAccumulator(this, objReg); + pg->LoadPrivateProperty(this, result.lexLevel, result.result.slot); + return; + } + pg->LoadLexicalVar(this, result.lexLevel, result.result.slot); + return; + } compiler::Operand prop = CompileKey(pg); if (object_->IsSuperExpression()) { diff --git a/es2panda/ir/expressions/memberExpression.h b/es2panda/ir/expressions/memberExpression.h index 74a7e17bc1e7d7183f530949fe30c9164a102db3..928c4e66e5c60d37b8775a583438190df0396070 100644 --- a/es2panda/ir/expressions/memberExpression.h +++ b/es2panda/ir/expressions/memberExpression.h @@ -71,6 +71,11 @@ public: return optional_; } + bool AccessPrivateProperty() const + { + return property_->IsPrivateIdentifier(); + } + MemberExpressionKind Kind() const { return kind_; diff --git a/es2panda/ir/expressions/privateIdentifier.cpp b/es2panda/ir/expressions/privateIdentifier.cpp new file mode 100644 index 0000000000000000000000000000000000000000..77f6a72d40f9922ce9d33d62d4d848bf0dc4cb3d --- /dev/null +++ b/es2panda/ir/expressions/privateIdentifier.cpp @@ -0,0 +1,53 @@ +/** + * Copyright (c) 2021 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 "privateIdentifier.h" + +#include + +namespace panda::es2panda::ir { + +void PrivateIdentifier::Iterate(const NodeTraverser &cb) const +{ + if (typeAnnotation_) { + cb(typeAnnotation_); + } +} + +void PrivateIdentifier::Dump(ir::AstDumper *dumper) const +{ + dumper->Add({{"type", "PrivateIdentifier"}, + {"prefix", "#"}, + {"name", name_}, + {"typeAnnotation", AstDumper::Optional(typeAnnotation_)}}); +} + +void PrivateIdentifier::Compile(compiler::PandaGen *pg) const +{ +} + +checker::Type *PrivateIdentifier::Check(checker::Checker *checker) const +{ + return nullptr; +} + +void PrivateIdentifier::UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) +{ + if (typeAnnotation_) { + typeAnnotation_ = std::get(cb(typeAnnotation_))->AsExpression(); + } +} + +} // namespace panda::es2panda::ir \ No newline at end of file diff --git a/es2panda/ir/expressions/privateIdentifier.h b/es2panda/ir/expressions/privateIdentifier.h new file mode 100644 index 0000000000000000000000000000000000000000..d1a7a8cf0658b3886566d993553938e8ee268186 --- /dev/null +++ b/es2panda/ir/expressions/privateIdentifier.h @@ -0,0 +1,80 @@ +/** + * 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. + */ + +#ifndef ES2PANDA_IR_EXPRESSION_PRIVATEIDENTIFIER_H +#define ES2PANDA_IR_EXPRESSION_PRIVATEIDENTIFIER_H + +#include +#include + +namespace panda::es2panda::compiler { +class PandaGen; +} // namespace panda::es2panda::compiler + +namespace panda::es2panda::checker { +class Checker; +class Type; +} // namespace panda::es2panda::checker + +namespace panda::es2panda::ir { + +class PrivateIdentifier : public Expression { +public: + explicit PrivateIdentifier(util::StringView name) + : Expression(AstNodeType::PRIVATE_IDENTIFIER), name_(name) + { + } + + explicit PrivateIdentifier(util::StringView name, Expression *typeAnnotation) + : Expression(AstNodeType::PRIVATE_IDENTIFIER), + name_(name), + typeAnnotation_(typeAnnotation) + { + } + + const Expression *TypeAnnotation() const + { + return typeAnnotation_; + } + + Expression *TypeAnnotation() + { + return typeAnnotation_; + } + + const util::StringView &Name() const + { + return name_; + } + + void SetName(util::StringView name) + { + name_ = name; + } + + void Iterate(const NodeTraverser &cb) const override; + void Dump(ir::AstDumper *dumper) const override; + void Compile(compiler::PandaGen *pg) const override; + checker::Type *Check(checker::Checker *checker) const override; + void UpdateSelf(const NodeUpdater &cb, [[maybe_unused]] binder::Binder *binder) override; + +private: + util::StringView name_; + Expression *typeAnnotation_ {}; +}; + +} // namespace panda::es2panda::ir + +#endif diff --git a/es2panda/ir/expressions/unaryExpression.cpp b/es2panda/ir/expressions/unaryExpression.cpp index 6f4620b9324ce7da1c141cfc9cc34b65f9e185e6..7db1217ae5f170ed36d764892f9e8a61d2f8243e 100644 --- a/es2panda/ir/expressions/unaryExpression.cpp +++ b/es2panda/ir/expressions/unaryExpression.cpp @@ -135,7 +135,7 @@ checker::Type *UnaryExpression::Check(checker::Checker *checker) const const ir::MemberExpression *memberArg = argument_->AsMemberExpression(); - if (memberArg->Property()->IsTSPrivateIdentifier()) { + if (memberArg->Property()->IsTSPrivateIdentifier() || memberArg->Property()->IsPrivateIdentifier()) { checker->ThrowTypeError("The operand of a delete operator cannot be a private identifier.", argument_->Start()); } diff --git a/es2panda/parser/expressionParser.cpp b/es2panda/parser/expressionParser.cpp index 6e16f668e383009069618ff6f6ff5abe32320d4d..3578bdd5ad0abf055720d8ea5eab09388e23c030 100644 --- a/es2panda/parser/expressionParser.cpp +++ b/es2panda/parser/expressionParser.cpp @@ -45,6 +45,7 @@ #include #include #include +#include #include #include #include @@ -1366,6 +1367,14 @@ ir::Expression *ParserImpl::ParseOptionalChain(ir::Expression *leftSideExpr) lexer::TokenType tokenType = lexer_->GetToken().Type(); ir::Expression *returnExpression = nullptr; + if (tokenType == lexer::TokenType::PUNCTUATOR_HASH_MARK) { + auto *privateIdent = ParsePrivateIdentifier(); + returnExpression = AllocNode( + leftSideExpr, privateIdent, ir::MemberExpression::MemberExpressionKind::PROPERTY_ACCESS, false, true); + returnExpression->SetRange({leftSideExpr->Start(), privateIdent->End()}); + lexer_->NextToken(); + } + if (tokenType == lexer::TokenType::LITERAL_IDENT) { auto *identNode = AllocNode(lexer_->GetToken().Ident()); identNode->SetReference(); @@ -1600,40 +1609,44 @@ ir::Expression *ParserImpl::ParsePostPrimaryExpression(ir::Expression *primaryEx } case lexer::TokenType::PUNCTUATOR_PERIOD: { lexer_->NextToken(lexer::LexerNextTokenFlags::KEYWORD_TO_IDENT); // eat period - bool isPrivate = false; - - lexer::SourcePosition memberStart = lexer_->GetToken().Start(); - if (Extension() == ScriptExtension::TS && + ir::Expression *property; + if (program_.TargetApiVersion() > 10 && lexer_->GetToken().Type() == lexer::TokenType::PUNCTUATOR_HASH_MARK) { - if (!(context_.Status() & ParserStatus::IN_CLASS_BODY)) { - ThrowSyntaxError("Private identifiers are not allowed outside class bodies."); + if (returnExpression->IsSuperExpression()) { + ThrowSyntaxError("Unexpected private property access in super keyword"); } - isPrivate = true; - lexer_->NextToken(lexer::LexerNextTokenFlags::KEYWORD_TO_IDENT); - } - - if (lexer_->GetToken().Type() != lexer::TokenType::LITERAL_IDENT) { - ThrowSyntaxError("Expected an identifier"); - } - - auto *identNode = AllocNode(lexer_->GetToken().Ident()); - identNode->SetRange(lexer_->GetToken().Loc()); - - ir::Expression *property = nullptr; - if (isPrivate) { - property = AllocNode(identNode, nullptr, nullptr); - property->SetRange({memberStart, identNode->End()}); + property = ParsePrivateIdentifier(); } else { - property = identNode; - } + bool isPrivate = false; + lexer::SourcePosition memberStart = lexer_->GetToken().Start(); + if (lexer_->GetToken().Type() == lexer::TokenType::PUNCTUATOR_HASH_MARK) { + if (!(context_.Status() & ParserStatus::IN_CLASS_BODY)) { + ThrowSyntaxError("Private identifiers are not allowed outside class bodies."); + } + isPrivate = true; + lexer_->NextToken(lexer::LexerNextTokenFlags::KEYWORD_TO_IDENT); + } + if (lexer_->GetToken().Type() != lexer::TokenType::LITERAL_IDENT) { + ThrowSyntaxError("Expected an identifier"); + } + auto *identNode = AllocNode(lexer_->GetToken().Ident()); + identNode->SetRange(lexer_->GetToken().Loc()); + lexer_->NextToken(); + + if (isPrivate) { + property = AllocNode(identNode, nullptr, nullptr); + property->SetRange({memberStart, identNode->End()}); + } else { + property = identNode; + } + } const lexer::SourcePosition &startPos = returnExpression->Start(); returnExpression = AllocNode( returnExpression, property, ir::MemberExpression::MemberExpressionKind::PROPERTY_ACCESS, false, false); returnExpression->SetRange({startPos, property->End()}); - lexer_->NextToken(); continue; } case lexer::TokenType::PUNCTUATOR_LEFT_SQUARE_BRACKET: { @@ -2299,6 +2312,14 @@ ir::Expression *ParserImpl::ParseUnaryOrPrefixUpdateExpression(ExpressionParseFl return ParseTsTypeAssertion(flags); } + if (lexer_->GetToken().Type() == lexer::TokenType::PUNCTUATOR_HASH_MARK) { + auto privateIdent = ParsePrivateIdentifier(); + if (lexer_->GetToken().Type() != lexer::TokenType::KEYW_IN) { + ThrowSyntaxError("Unexpected private identifier", privateIdent->Start()); + } + return privateIdent; + } + if (!lexer_->GetToken().IsUnary()) { return ParseLeftHandSideExpression(flags); } @@ -2312,8 +2333,13 @@ ir::Expression *ParserImpl::ParseUnaryOrPrefixUpdateExpression(ExpressionParseFl ValidateUpdateExpression(argument, false); } - if (operatorType == lexer::TokenType::KEYW_DELETE && argument->IsIdentifier()) { - ThrowSyntaxError("Deleting local variable in strict mode"); + if (operatorType == lexer::TokenType::KEYW_DELETE) { + if (argument->IsIdentifier()) { + ThrowSyntaxError("Deleting local variable in strict mode"); + } + if (argument->IsMemberExpression() && argument->AsMemberExpression()->AccessPrivateProperty()) { + ThrowSyntaxError("Delete private property is not allowed"); + } } lexer::SourcePosition end = argument->End(); @@ -2479,4 +2505,38 @@ ir::FunctionExpression *ParserImpl::ParseFunctionExpression(ParserStatus newStat return funcExpr; } +ir::PrivateIdentifier *ParserImpl::ParsePrivateIdentifier() +{ + ASSERT(lexer_->GetToken().Type() == lexer::TokenType::PUNCTUATOR_HASH_MARK); + if (!(context_.Status() & ParserStatus::IN_CLASS_BODY)) { + ThrowSyntaxError("Private identifiers are not allowed outside class bodies."); + } + + auto start = lexer_->GetToken().Start(); + auto idx = start.index; + + lexer_->NextToken(lexer::LexerNextTokenFlags::KEYWORD_TO_IDENT); + + auto token = lexer_->GetToken(); + + auto newIdx = token.Start().index; + if (newIdx != idx + 1) { + ThrowSyntaxError("Unexpected white space"); + } + + if (token.Type() != lexer::TokenType::LITERAL_IDENT) { + ThrowSyntaxError("Expected an identifier"); + } + + auto identName = token.Ident(); + if (identName.Is("constructor")) { + ThrowSyntaxError("Private identifier may not be '#constructor'"); + } + + auto *privateIdent = AllocNode(identName); + privateIdent->SetRange({start, lexer_->GetToken().End()}); + lexer_->NextToken(); + return privateIdent; +} + } // namespace panda::es2panda::parser diff --git a/es2panda/parser/parserImpl.cpp b/es2panda/parser/parserImpl.cpp index 391f087cde83cf6cbd4554ddccbf68b95fe1dd8a..2274b8901f0f9a03945514183acdc1164c1e1ba4 100644 --- a/es2panda/parser/parserImpl.cpp +++ b/es2panda/parser/parserImpl.cpp @@ -42,6 +42,7 @@ #include #include #include +#include #include #include #include @@ -126,11 +127,13 @@ std::unique_ptr ParserImpl::InitLexer(const std::string &fileName, return lexer; } -Program ParserImpl::Parse(const std::string &fileName, const std::string &source, - const std::string &recordName, ScriptKind kind) +Program ParserImpl::Parse(const std::string &fileName, const std::string &source, const std::string &recordName, + const CompilerOptions &options, ScriptKind kind) { program_.SetKind(kind); program_.SetRecordName(recordName); + program_.SetDebug(options.isDebug); + program_.SetTargetApiVersion(options.targetApiVersion); /* * In order to make the lexer's memory alive, the return value 'lexer' can not be omitted. @@ -637,7 +640,7 @@ ir::Expression *ParserImpl::ParsePostfixTypeOrHigher(ir::Expression *typeAnnotat return ParseTsParenthesizedOrFunctionType(typeAnnotation, *options & TypeAnnotationParsingOptions::THROW_ERROR); } - + case lexer::TokenType::PUNCTUATOR_LEFT_SQUARE_BRACKET: { if (typeAnnotation) { if (lexer_->GetToken().NewLine()) { @@ -2011,9 +2014,7 @@ ir::ModifierFlags ParserImpl::ParseModifiers() while (IsModifierKind(lexer_->GetToken())) { char32_t nextCp = lexer_->Lookahead(); - if (!((Extension() == ScriptExtension::JS && nextCp != LEX_CHAR_LEFT_PAREN) || - (Extension() == ScriptExtension::TS && nextCp != LEX_CHAR_EQUALS && nextCp != LEX_CHAR_SEMICOLON && - nextCp != LEX_CHAR_COMMA && nextCp != LEX_CHAR_LEFT_PAREN))) { + if (nextCp == LEX_CHAR_LEFT_PAREN || nextCp == LEX_CHAR_EQUALS || nextCp == LEX_CHAR_SEMICOLON) { break; } @@ -2233,6 +2234,20 @@ void ParserImpl::ValidateClassKey(ClassElmentDescriptor *desc, bool isDeclare) ThrowSyntaxError("Async method can not be getter nor setter"); } + if (desc->isPrivateIdent) { + if (desc->modifiers & ir::ModifierFlags::ACCESS) { + ThrowSyntaxError("An accessibility modifier cannot be used with a private identifier."); + } + + if (desc->modifiers & ir::ModifierFlags::DECLARE) { + ThrowSyntaxError("'declare' modifier cannot be used with a private identifier."); + } + + if (desc->modifiers & ir::ModifierFlags::ABSTRACT) { + ThrowSyntaxError("'abstract' modifier cannot be used with a private identifier."); + } + } + const util::StringView &propNameStr = lexer_->GetToken().Ident(); if (propNameStr.Is("constructor")) { @@ -2261,6 +2276,11 @@ void ParserImpl::ValidateClassKey(ClassElmentDescriptor *desc, bool isDeclare) ir::Expression *ParserImpl::ParseClassKey(ClassElmentDescriptor *desc, bool isDeclare) { + if (desc->isPrivateIdent && program_.TargetApiVersion() > 10) { + ValidateClassKey(desc, isDeclare); + return ParsePrivateIdentifier(); + } + ir::Expression *propName = nullptr; if (lexer_->GetToken().IsKeyword()) { lexer_->GetToken().SetTokenType(lexer::TokenType::LITERAL_IDENT); @@ -2275,15 +2295,14 @@ ir::Expression *ParserImpl::ParseClassKey(ClassElmentDescriptor *desc, bool isDe break; } case lexer::TokenType::LITERAL_STRING: { + ValidateClassKey(desc, isDeclare); ThrowIfPrivateIdent(desc, "Private identifier name can not be string"); - propName = AllocNode(lexer_->GetToken().String()); propName->SetRange(lexer_->GetToken().Loc()); break; } case lexer::TokenType::LITERAL_NUMBER: { ThrowIfPrivateIdent(desc, "Private identifier name can not be number"); - if (lexer_->GetToken().Flags() & lexer::TokenFlags::NUMBER_BIGINT) { propName = AllocNode(lexer_->GetToken().BigInt()); } else { @@ -2295,7 +2314,6 @@ ir::Expression *ParserImpl::ParseClassKey(ClassElmentDescriptor *desc, bool isDe } case lexer::TokenType::PUNCTUATOR_LEFT_SQUARE_BRACKET: { ThrowIfPrivateIdent(desc, "Unexpected character in private identifier"); - lexer_->NextToken(); // eat left square bracket if (Extension() == ScriptExtension::TS && lexer_->GetToken().Type() == lexer::TokenType::LITERAL_IDENT && @@ -2423,6 +2441,62 @@ void ParserImpl::ValidateClassGetter(ClassElmentDescriptor *desc, const ArenaVec } } +void ParserImpl::ValidatePrivateProperty(ir::Statement *stmt, std::unordered_set &usedPrivateNames, + std::unordered_map &unusedGetterSetterPairs) +{ + if (stmt->IsClassProperty()) { + auto *prop = stmt->AsClassProperty(); + if (!prop->IsPrivate()) { + return; + } + auto name = prop->Key()->AsPrivateIdentifier()->Name(); + if (usedPrivateNames.find(name) != usedPrivateNames.end()) { + ThrowSyntaxError({"Redeclaration of class private property #", name.Utf8()}, prop->Start()); + } + usedPrivateNames.insert(name); + return; + } + + if (stmt->IsMethodDefinition()) { + auto *methodDef = stmt->AsMethodDefinition(); + if (!methodDef->IsPrivate()) { + return; + } + auto name = methodDef->Key()->AsPrivateIdentifier()->Name(); + + if (methodDef->Kind() == ir::MethodDefinitionKind::METHOD) { + if (usedPrivateNames.find(name) != usedPrivateNames.end()) { + ThrowSyntaxError({"Redeclaration of class private property #", name.Utf8()}, methodDef->Start()); + } + usedPrivateNames.insert(name); + return; + } + + ASSERT(methodDef->Kind() != ir::MethodDefinitionKind::CONSTRUCTOR); + PrivateGetterSetterType type = (methodDef->Kind() == ir::MethodDefinitionKind::GET) ? + PrivateGetterSetterType::GETTER : PrivateGetterSetterType::SETTER; + PrivateGetterSetterType unusedType = (methodDef->Kind() == ir::MethodDefinitionKind::GET) ? + PrivateGetterSetterType::SETTER : PrivateGetterSetterType::GETTER; + + if (methodDef->IsStatic()) { + type |= PrivateGetterSetterType::STATIC; + unusedType |= PrivateGetterSetterType::STATIC; + } + + if (usedPrivateNames.find(name) == usedPrivateNames.end()) { + usedPrivateNames.insert(name); + unusedGetterSetterPairs[name] = unusedType; + return; + } + + auto result = unusedGetterSetterPairs.find(name); + if (result == unusedGetterSetterPairs.end() || unusedGetterSetterPairs[name] != type) { + ThrowSyntaxError({"Redeclaration of class private property #", name.Utf8()}, methodDef->Start()); + } + unusedGetterSetterPairs.erase(result); + } +} + ir::MethodDefinition *ParserImpl::ParseClassMethod(ClassElmentDescriptor *desc, const ArenaVector &properties, ir::Expression *propName, lexer::SourcePosition *propEnd, @@ -2471,7 +2545,7 @@ ir::MethodDefinition *ParserImpl::ParseClassMethod(ClassElmentDescriptor *desc, ir::MethodDefinition *method = nullptr; - if (desc->isPrivateIdent && Extension() == ScriptExtension::TS) { + if (desc->isPrivateIdent && Extension() == ScriptExtension::TS && program_.TargetApiVersion() <= 10) { ir::Expression *privateId = AllocNode(propName, nullptr, nullptr); auto privateIdStart = lexer::SourcePosition(propName->Start().index - 1, propName->Start().line); privateId->SetRange({privateIdStart, propName->End()}); @@ -2503,9 +2577,9 @@ ir::ClassStaticBlock *ParserImpl::ParseStaticBlock(ClassElmentDescriptor *desc) } ir::Statement *ParserImpl::ParseClassProperty(ClassElmentDescriptor *desc, - const ArenaVector &properties, ir::Expression *propName, - ir::Expression *typeAnnotation, ArenaVector &&decorators, - bool isDeclare) + const ArenaVector &properties, ir::Expression *propName, ir::Expression *typeAnnotation, + ArenaVector &&decorators, bool isDeclare, + std::pair implicitScopes) { lexer::SourcePosition propEnd = propName->End(); ir::Statement *property = nullptr; @@ -2516,40 +2590,39 @@ ir::Statement *ParserImpl::ParseClassProperty(ClassElmentDescriptor *desc, return property; } + if (!desc->isComputed) { + CheckFieldKey(propName); + } + ir::Expression *value = nullptr; if (lexer_->GetToken().Type() == lexer::TokenType::PUNCTUATOR_SUBSTITUTION) { if (Extension() == ScriptExtension::TS && (desc->modifiers & ir::ModifierFlags::ABSTRACT)) { ThrowSyntaxError("Property cannot have an initializer because it is marked abstract."); } + context_.Status() |= (ParserStatus::ALLOW_SUPER | ParserStatus::DISALLOW_ARGUMENTS); lexer_->NextToken(); // eat equals if (isDeclare) { ThrowSyntaxError("Initializers are not allowed in ambient contexts."); } - // TODO(songqi):static classProperty's value can use super keyword in TypeScript4.4. - // Currently only Parser is supported, Compiler support requires Transformer. - context_.Status() |= ParserStatus::ALLOW_SUPER; + + auto *scope = ((desc->modifiers & ir::ModifierFlags::STATIC) != 0) ? implicitScopes.first : + implicitScopes.second; + auto scopeCtx = binder::LexicalScope::Enter(Binder(), scope); value = ParseExpression(); - context_.Status() &= ~ParserStatus::ALLOW_SUPER; + context_.Status() &= ~(ParserStatus::ALLOW_SUPER | ParserStatus::DISALLOW_ARGUMENTS); propEnd = value->End(); } - ir::Expression *privateId = nullptr; - - if (Extension() == ScriptExtension::JS) { - if (desc->isPrivateIdent) { - ThrowSyntaxError("Private js fields are not supported"); - } - } else { - if (desc->isPrivateIdent) { - privateId = AllocNode(propName, value, typeAnnotation); - auto privateIdStart = lexer::SourcePosition(propName->Start().index - 1, propName->Start().line); - privateId->SetRange({privateIdStart, propName->End()}); - } + if (Extension() == ScriptExtension::TS && desc->isPrivateIdent && program_.TargetApiVersion() <= 10) { + auto *privateId = AllocNode(propName, value, typeAnnotation); + auto privateIdStart = lexer::SourcePosition(propName->Start().index - 1, propName->Start().line); + privateId->SetRange({privateIdStart, propName->End()}); + propName = privateId; } - property = AllocNode(desc->isPrivateIdent ? privateId : propName, value, typeAnnotation, + property = AllocNode(propName, value, typeAnnotation, desc->modifiers, std::move(decorators), desc->isComputed, desc->modifiers & ir::ModifierFlags::DEFINITE); @@ -2563,8 +2636,6 @@ void ParserImpl::CheckClassGeneratorMethod(ClassElmentDescriptor *desc) return; } - ThrowIfPrivateIdent(desc, "Unexpected character in private identifier"); - desc->isGenerator = true; lexer_->NextToken(lexer::LexerNextTokenFlags::KEYWORD_TO_IDENT); } @@ -2575,20 +2646,29 @@ void ParserImpl::CheckClassPrivateIdentifier(ClassElmentDescriptor *desc) return; } - if (Extension() == ScriptExtension::JS) { - ThrowSyntaxError("JS private class fields are not supported."); - } - if (Extension() == ScriptExtension::AS) { return; } - if ((desc->modifiers & ~ir::ModifierFlags::READONLY) && (desc->modifiers & ~ir::ModifierFlags::STATIC)) { - ThrowSyntaxError("Unexpected modifier on private identifier"); + desc->isPrivateIdent = true; + + if (Extension() == ScriptExtension::TS && program_.TargetApiVersion() <= 10) { + lexer_->NextToken(lexer::LexerNextTokenFlags::KEYWORD_TO_IDENT); + } +} + +void ParserImpl::CheckFieldKey(ir::Expression *propName) +{ + if (propName->IsNumberLiteral()) { + return; } - desc->isPrivateIdent = true; - lexer_->NextToken(lexer::LexerNextTokenFlags::KEYWORD_TO_IDENT); + ASSERT(propName->IsIdentifier() || propName->IsStringLiteral() || propName->IsPrivateIdentifier()); + const util::StringView &stringView = propName->IsIdentifier() ? propName->AsIdentifier()->Name() : + (propName->IsStringLiteral() ? propName->AsStringLiteral()->Str() : propName->AsPrivateIdentifier()->Name()); + if (stringView.Is("constructor")) { + ThrowSyntaxError("Classes may not have field named 'constructor'"); + } } ir::Expression *ParserImpl::ParseClassKeyAnnotation() @@ -2641,9 +2721,8 @@ ArenaVector ParserImpl::ParseDecorators() } ir::Statement *ParserImpl::ParseClassElement(const ArenaVector &properties, - ArenaVector *indexSignatures, bool hasSuperClass, - bool isDeclare, bool isAbstractClass, bool isExtendsFromNull, - binder::Scope *scope) + ArenaVector *indexSignatures, bool hasSuperClass, bool isDeclare, bool isAbstractClass, + bool isExtendsFromNull, std::pair implicitScopes) { ClassElmentDescriptor desc; @@ -2676,13 +2755,17 @@ ir::Statement *ParserImpl::ParseClassElement(const ArenaVector if (!decorators.empty()) { ThrowSyntaxError("Decorators are not valid here.", decorators.front()->Start()); } - auto scopeCtx = binder::LexicalScope::Enter(Binder(), scope->AsFunctionScope()); + auto scopeCtx = binder::LexicalScope::Enter(Binder(), implicitScopes.first); return ParseStaticBlock(&desc); } - CheckClassPrivateIdentifier(&desc); CheckClassGeneratorMethod(&desc); ParseClassKeyModifiers(&desc); + CheckClassPrivateIdentifier(&desc); + + if (desc.isPrivateIdent && !decorators.empty()) { + ThrowSyntaxError("Decorators are not valid here.", decorators.front()->Start()); + } if (!(desc.modifiers & ir::ModifierFlags::STATIC)) { context_.Status() |= ParserStatus::ALLOW_THIS_TYPE; @@ -2743,7 +2826,7 @@ ir::Statement *ParserImpl::ParseClassElement(const ArenaVector } else { ValidateClassMethodStart(&desc, typeAnnotation); property = ParseClassProperty(&desc, properties, propName, typeAnnotation, std::move(decorators), - isDeclare || (desc.modifiers & ir::ModifierFlags::DECLARE)); + isDeclare || (desc.modifiers & ir::ModifierFlags::DECLARE), implicitScopes); } if (lexer_->GetToken().Type() != lexer::TokenType::PUNCTUATOR_SEMI_COLON && @@ -2818,6 +2901,10 @@ ir::MethodDefinition *ParserImpl::CreateImplicitMethod(ir::Expression *superClas key = AllocNode("static_initializer"); break; } + case ir::ScriptFunctionFlags::INSTANCE_INITIALIZER: { + key = AllocNode("instance_initializer"); + break; + } default: { UNREACHABLE(); } @@ -2927,7 +3014,7 @@ ir::ClassDefinition *ParserImpl::ParseClassDefinition(bool isDeclaration, bool i binder::ConstDecl *decl = nullptr; ir::Identifier *identNode = nullptr; - auto classCtx = binder::LexicalScope(Binder()); + auto classCtx = binder::LexicalScope(Binder()); if (lexer_->GetToken().Type() == lexer::TokenType::LITERAL_IDENT && (Extension() != ScriptExtension::TS || lexer_->GetToken().KeywordType() != lexer::TokenType::KEYW_IMPLEMENTS)) { @@ -3028,11 +3115,18 @@ ir::ClassDefinition *ParserImpl::ParseClassDefinition(bool isDeclaration, bool i ir::MethodDefinition *ctor = nullptr; ir::MethodDefinition *staticInitializer = CreateImplicitMethod(superClass, hasSuperClass, ir::ScriptFunctionFlags::STATIC_INITIALIZER, isDeclare); + ir::MethodDefinition *instanceInitializer = CreateImplicitMethod(superClass, hasSuperClass, + ir::ScriptFunctionFlags::INSTANCE_INITIALIZER, isDeclare); ArenaVector properties(Allocator()->Adapter()); ArenaVector indexSignatures(Allocator()->Adapter()); bool hasConstructorFuncBody = false; bool isCtorContinuousDefined = true; - auto *scope = staticInitializer->Function()->Scope(); + + auto *static_scope = staticInitializer->Function()->Scope(); + auto *instance_scope = instanceInitializer->Function()->Scope(); + + std::unordered_set usedPrivateNames; + std::unordered_map unusedGetterSetterPairs; while (lexer_->GetToken().Type() != lexer::TokenType::PUNCTUATOR_RIGHT_BRACE) { if (lexer_->GetToken().Type() == lexer::TokenType::PUNCTUATOR_SEMI_COLON) { @@ -3040,8 +3134,8 @@ ir::ClassDefinition *ParserImpl::ParseClassDefinition(bool isDeclaration, bool i continue; } - ir::Statement *property = ParseClassElement(properties, &indexSignatures, hasSuperClass, - isDeclare, isAbstract, isExtendsFromNull, scope); + ir::Statement *property = ParseClassElement(properties, &indexSignatures, hasSuperClass, isDeclare, isAbstract, + isExtendsFromNull, std::make_pair(static_scope, instance_scope)); if (property->IsEmptyStatement()) { continue; @@ -3060,6 +3154,7 @@ ir::ClassDefinition *ParserImpl::ParseClassDefinition(bool isDeclaration, bool i continue; } isCtorContinuousDefined = ctor == nullptr; + ValidatePrivateProperty(property, usedPrivateNames, unusedGetterSetterPairs); properties.push_back(property); } @@ -3078,13 +3173,14 @@ ir::ClassDefinition *ParserImpl::ParseClassDefinition(bool isDeclaration, bool i auto *classDefinition = AllocNode( classCtx.GetScope(), identNode, typeParamDecl, superTypeParams, std::move(implements), ctor, staticInitializer, - superClass, std::move(properties), std::move(indexSignatures), isDeclare, isAbstract); + instanceInitializer, superClass, std::move(properties), std::move(indexSignatures), isDeclare, isAbstract); classDefinition->SetRange({classBodyStartLoc, classBodyEndLoc}); if (decl != nullptr) { decl->BindNode(classDefinition); } + classCtx.GetScope()->BindNode(classDefinition); return classDefinition; } @@ -3156,9 +3252,13 @@ bool ParserImpl::SuperCallShouldBeRootLevel(const ir::MethodDefinition *ctor, const ArenaVector &properties) { for (const auto *property : properties) { - if (property->IsClassProperty() && (property->AsClassProperty()->Value() != nullptr || - property->AsClassProperty()->Key()->IsTSPrivateIdentifier())) { - return true; + if (property->IsClassProperty()) { + auto *classProperty = property->AsClassProperty(); + bool isPrivateProperty = program_.TargetApiVersion() > 10 ? + classProperty->Key()->IsPrivateIdentifier() : classProperty->Key()->IsTSPrivateIdentifier(); + if (classProperty->Value() != nullptr || isPrivateProperty) { + return true; + } } } diff --git a/es2panda/parser/parserImpl.h b/es2panda/parser/parserImpl.h index f076ded5b740a085c12dcec1534a7618d7c776e4..082c437e5dafd38b46891d65bdd96ed816298583 100644 --- a/es2panda/parser/parserImpl.h +++ b/es2panda/parser/parserImpl.h @@ -172,6 +172,14 @@ DEFINE_BITOPS(TypeAnnotationParsingOptions) class ArrowFunctionContext; +enum class PrivateGetterSetterType { + GETTER = 0, + SETTER = 1 << 0, + STATIC = 1 << 1, +}; + +DEFINE_BITOPS(PrivateGetterSetterType) + class ParserImpl { public: explicit ParserImpl(es2panda::ScriptExtension extension); @@ -179,8 +187,8 @@ public: NO_MOVE_SEMANTIC(ParserImpl); ~ParserImpl() = default; - Program Parse(const std::string &fileName, const std::string &source, - const std::string &recordName, ScriptKind kind); + Program Parse(const std::string &fileName, const std::string &source, const std::string &recordName, + const CompilerOptions &options, ScriptKind kind); ScriptExtension Extension() const; @@ -191,10 +199,6 @@ public: return program_.Allocator(); } bool IsDtsFile() const; - void SetDebug(bool isDebug) - { - program_.SetDebug(isDebug); - } private: bool IsStartOfMappedType() const; @@ -297,23 +301,27 @@ private: void ValidateClassGetter(ClassElmentDescriptor *desc, const ArenaVector &properties, ir::Expression *propName, ir::ScriptFunction *func, bool hasDecorator, lexer::SourcePosition errorInfo); + void ValidatePrivateProperty(ir::Statement *stmt, std::unordered_set &privateNames, + std::unordered_map &unusedGetterSetterPairs); ir::MethodDefinition *ParseClassMethod(ClassElmentDescriptor *desc, const ArenaVector &properties, ir::Expression *propName, lexer::SourcePosition *propEnd, ArenaVector &&decorators, bool isDeclare); ir::ClassStaticBlock *ParseStaticBlock(ClassElmentDescriptor *desc); ir::Statement *ParseClassProperty(ClassElmentDescriptor *desc, const ArenaVector &properties, ir::Expression *propName, ir::Expression *typeAnnotation, - ArenaVector &&decorators, bool isDeclare); + ArenaVector &&decorators, bool isDeclare, + std::pair implicitScopes); void ParseClassKeyModifiers(ClassElmentDescriptor *desc); void CheckClassGeneratorMethod(ClassElmentDescriptor *desc); void CheckClassPrivateIdentifier(ClassElmentDescriptor *desc); + void CheckFieldKey(ir::Expression *propName); ir::Expression *ParseClassKeyAnnotation(); ir::Decorator *ParseDecorator(); ArenaVector ParseDecorators(); ir::Statement *ParseClassElement(const ArenaVector &properties, ArenaVector *indexSignatures, bool hasSuperClass, bool isDeclare, bool isAbstractClass, bool isExtendsFromNull, - binder::Scope *scope); + std::pair implicitScopes); ir::MethodDefinition *CreateImplicitMethod(ir::Expression *superClass, bool hasSuperClass, ir::ScriptFunctionFlags funcFlag, bool isDeclare = false); ir::MethodDefinition *CheckClassMethodOverload(ir::Statement *property, ir::MethodDefinition **ctor, bool isDeclare, @@ -454,6 +462,7 @@ private: ArenaVector &&decorators); ir::Identifier *ParseNamedExport(const lexer::Token &exportedToken); void CheckStrictReservedWord() const; + ir::PrivateIdentifier *ParsePrivateIdentifier(); // Discard the DISALLOW_CONDITIONAL_TYPES in current status to call function. template diff --git a/es2panda/parser/program/program.cpp b/es2panda/parser/program/program.cpp index e79d52d723738fa1c9ef9fa7dad0be923cbc823b..569715606974d3736a4325a91774a50c92bf6ebc 100644 --- a/es2panda/parser/program/program.cpp +++ b/es2panda/parser/program/program.cpp @@ -43,7 +43,9 @@ Program::Program(Program &&other) moduleRecord_(other.moduleRecord_), typeModuleRecord_(other.typeModuleRecord_), patchFixHelper_(other.patchFixHelper_), - isDtsFile_(other.isDtsFile_) + isDtsFile_(other.isDtsFile_), + isDebug_(other.isDebug_), + targetApiVersion_(other.targetApiVersion_) { other.binder_ = nullptr; other.ast_ = nullptr; diff --git a/es2panda/parser/program/program.h b/es2panda/parser/program/program.h index a7e896776c31837c4bea6b2ba17f94b375ee9798..2c9815cec9fa1324ddd3f596f99b42184d7ce23c 100644 --- a/es2panda/parser/program/program.h +++ b/es2panda/parser/program/program.h @@ -165,6 +165,16 @@ public: isDebug_ = isDebug; } + int TargetApiVersion() const + { + return targetApiVersion_; + } + + void SetTargetApiVersion(int targetApiVersion) + { + targetApiVersion_ = targetApiVersion; + } + std::string Dump() const; void SetKind(ScriptKind kind); @@ -184,6 +194,7 @@ private: util::PatchFix *patchFixHelper_ {nullptr}; bool isDtsFile_ {false}; bool isDebug_ {false}; + int targetApiVersion_ {0}; }; } // namespace panda::es2panda::parser diff --git a/es2panda/parser/transformer/transformer.cpp b/es2panda/parser/transformer/transformer.cpp index 81432691143a7332bb3cd5146670d27b78a1f816..2766e091147149c07c86e1f1c5cf3b331dd3586b 100644 --- a/es2panda/parser/transformer/transformer.cpp +++ b/es2panda/parser/transformer/transformer.cpp @@ -643,7 +643,8 @@ std::vector Transformer::VisitInstanceProperty(ir::Cl // Non-null computed properties need to be added outside the class. It is a subset of addToCtor. std::vector computedProps; for (auto *it : node->Body()) { - if (it->IsClassProperty() && !it->AsClassProperty()->IsStatic() && it->AsClassProperty()->Value() != nullptr) { + if (it->IsClassProperty() && !it->AsClassProperty()->IsStatic() && + !it->AsClassProperty()->Key()->IsPrivateIdentifier() && it->AsClassProperty()->Value() != nullptr) { addToCtor.push_back(it->AsClassProperty()); } } @@ -758,6 +759,16 @@ ir::Expression *Transformer::CopyClassKeyExpression(ir::Expression *orginalExpr) newExpr = AllocNode(ident->Name()); break; } + case ir::AstNodeType::PRIVATE_IDENTIFIER: { + ir::PrivateIdentifier *ident = orginalExpr->AsPrivateIdentifier(); + newExpr = AllocNode(ident->Name()); + break; + } + case ir::AstNodeType::TS_PRIVATE_IDENTIFIER: { + ir::Identifier *ident = orginalExpr->AsTSPrivateIdentifier()->Key()->AsIdentifier(); + newExpr = AllocNode(ident->Name()); + break; + } case ir::AstNodeType::STRING_LITERAL: { ir::StringLiteral *stringLiteral = orginalExpr->AsStringLiteral(); newExpr = AllocNode(stringLiteral->Str()); @@ -971,6 +982,10 @@ std::vector Transformer::VisitStaticProperty(ir::Clas * * TODO(xucheng): should support static private property */ + if (program_->TargetApiVersion() > 10) { + return {}; + } + std::vector res; auto classDefinitionBody = node->Body(); for (auto *it : classDefinitionBody) { @@ -981,10 +996,7 @@ std::vector Transformer::VisitStaticProperty(ir::Clas if (!classProperty->IsStatic()) { continue; } - if (classProperty->Key()->IsIdentifier()) { - // The corresponding bytecode will be generated in common logic of js and ts, so no need to process here - continue; - } + if (classProperty->IsComputed()) { res.push_back(AllocNode(classProperty->Key())); } diff --git a/es2panda/test/base64/inputFile/expected.txt b/es2panda/test/base64/inputFile/expected.txt index 486c8cb8c615771b786e1364bec9fcf8cc56197e..55e4b70a9513c86319c77654c6c23973b9b604cc 100644 --- a/es2panda/test/base64/inputFile/expected.txt +++ b/es2panda/test/base64/inputFile/expected.txt @@ -11,4 +11,4 @@ # See the License for the specific language governing permissions and # limitations under the License. -UEFOREEAAAAAAAAACQAAAKQBAACMAAAAFQAAAAQAAAA8AAAAAQAAAKABAAAAAAAATAAAAAEAAABMAAAAuwAAAIwAAADhAAAADQEAAIwAAACkAQAAAgAAAHQAAAADAAAAfAAAAAAAAACIAAAAAQAAAIgAAAC7AAAADQEAAKEAAACvAAAAtgAAAD4BAAAnTF9FU1R5cGVBbm5vdGF0aW9uOwAZaGVsbG8gd29ybGQhAAtwcmludAAHc3RyADNMX0VTU2xvdE51bWJlckFubm90YXRpb247AAAAAACAQAAAAgAAJ0xfRVNUeXBlSW5mb1JlY29yZDsAAAAAAAEAAAIAABdmdW5jX21haW5fMAATTF9HTE9CQUw7AAAAAAABAAECAAABAAAAAAEAAIgCAWUBAAACAAWRAQAABlgBAAAA7u4AABFpbnB1dC5qcwAVU2xvdE51bWJlcgAAAAEATAEAAAUAAAA3BwMhAERwRIFEkj4AAEgAAAIAPwEBAGEFPwICAGEGYAUqAwYAZQkLAQIQiQD/////DwAFwgIABhAAAACKAQAA +UEFOREEAAAAAAAAACwAAAKQBAACMAAAAFQAAAAQAAAA8AAAAAQAAAKABAAAAAAAATAAAAAEAAABMAAAAuwAAAIwAAADhAAAADQEAAIwAAACkAQAAAgAAAHQAAAADAAAAfAAAAAAAAACIAAAAAQAAAIgAAAC7AAAADQEAAKEAAACvAAAAtgAAAD4BAAAnTF9FU1R5cGVBbm5vdGF0aW9uOwAZaGVsbG8gd29ybGQhAAtwcmludAAHc3RyADNMX0VTU2xvdE51bWJlckFubm90YXRpb247AAAAAACAQAAAAgAAJ0xfRVNUeXBlSW5mb1JlY29yZDsAAAAAAAEAAAIAABdmdW5jX21haW5fMAATTF9HTE9CQUw7AAAAAAABAAECAAABAAAAAAEAAIgCAWUBAAACAAWRAQAABlgBAAAA7u4AABFpbnB1dC5qcwAVU2xvdE51bWJlcgAAAAEATAEAAAUAAAA3BwMhAERwRIFEkj4AAEgAAAIAPwEBAGEFPwICAGEGYAUqAwYAZQkLAQIQiQD/////DwAFwgIABhAAAACKAQAA diff --git a/es2panda/test/base64/inputString/expected.txt b/es2panda/test/base64/inputString/expected.txt index eba80a89df8635b5713e76dc0d038b5b45de20d7..9ee783b353dec5f39dd1f25f6d85678f784cd897 100644 --- a/es2panda/test/base64/inputString/expected.txt +++ b/es2panda/test/base64/inputString/expected.txt @@ -11,4 +11,4 @@ # See the License for the specific language governing permissions and # limitations under the License. -UEFOREEAAAAAAAAACQAAAJQBAACMAAAAFQAAAAQAAAA8AAAAAQAAAJABAAAAAAAATAAAAAEAAABMAAAAuwAAAIwAAADhAAAADQEAAIwAAACUAQAAAgAAAHQAAAADAAAAfAAAAAAAAACIAAAAAQAAAIgAAAC7AAAADQEAAKEAAACvAAAAtgAAAD4BAAAnTF9FU1R5cGVBbm5vdGF0aW9uOwAZaGVsbG8gd29ybGQhAAtwcmludAAHc3RyADNMX0VTU2xvdE51bWJlckFubm90YXRpb247AAAAAACAQAAAAgAAJ0xfRVNUeXBlSW5mb1JlY29yZDsAAAAAAAEAAAIAABdmdW5jX21haW5fMAATTF9HTE9CQUw7AAAAAAABAAECAAABAAAAAAEAAIgCAVsBAAACAAWEAQAABk4BAAAA7u4AABVTbG90TnVtYmVyAAAAAQBCAQAABQAAADcHAyEARHBEgUSSPgAASAAAAgA/AQEAYQU/AgIAYQZgBSoDBgBlC2uJAP////8PAAEAAAAAAIABAAA= +UEFOREEAAAAAAAAACwAAAJQBAACMAAAAFQAAAAQAAAA8AAAAAQAAAJABAAAAAAAATAAAAAEAAABMAAAAuwAAAIwAAADhAAAADQEAAIwAAACUAQAAAgAAAHQAAAADAAAAfAAAAAAAAACIAAAAAQAAAIgAAAC7AAAADQEAAKEAAACvAAAAtgAAAD4BAAAnTF9FU1R5cGVBbm5vdGF0aW9uOwAZaGVsbG8gd29ybGQhAAtwcmludAAHc3RyADNMX0VTU2xvdE51bWJlckFubm90YXRpb247AAAAAACAQAAAAgAAJ0xfRVNUeXBlSW5mb1JlY29yZDsAAAAAAAEAAAIAABdmdW5jX21haW5fMAATTF9HTE9CQUw7AAAAAAABAAECAAABAAAAAAEAAIgCAVsBAAACAAWEAQAABk4BAAAA7u4AABVTbG90TnVtYmVyAAAAAQBCAQAABQAAADcHAyEARHBEgUSSPgAASAAAAgA/AQEAYQU/AgIAYQZgBSoDBgBlC2uJAP////8PAAEAAAAAAIABAAA= diff --git a/es2panda/test/benchmark/README.md b/es2panda/test/benchmark/README.md new file mode 100644 index 0000000000000000000000000000000000000000..9ff734f5f5336eaf504ebdb90280cde4b2e1a363 --- /dev/null +++ b/es2panda/test/benchmark/README.md @@ -0,0 +1,64 @@ +# es2abc-benchmark + +## Project Description +The purpose of this project is to test the performance of es2abc when compiling JS and output a report of the test results. +This tool relies on Python3, Git, and the es2abc executable file under the ets_frontend component. +By default, test cases are stored in the 'test_cases' directory, and run results are stored in the 'output' directory. +## Usage notes +#### Parameter description +| Parameter | Description | Type | Default Value | +| :-----------: | :----------------------------------------------------------: | :-----: | :---------------------------------: | +| --es2abc-tool | This parameter is required and requires a path to the es2abc tool to be provided. | string | N/A | +| --runs | This parameter is optional and the default value is 20. Represents the number of times a use case was executed in a test. | int | 20 | +| --opt-level | This parameter is optional and specifies the optimization level of the compiler. | string | 0 | +| --parse-only | This parameter is optional and the default value is False. If set to True, only the input file will be parsed during testing. | boolean | False | +| --engine-comp | This parameter is optional, and the default value is False. At this time, only the es2abc test is performed. When it is True, it is compared with the Hermes engine. | boolean | False | + +#### Description of the test case + The test suite and test cases for this project are sourced from open source libraries: +#### Test Suite: + | name | description | GitHub address | + | :--: |:---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------:| :--: | + | Octane | JavaScript benchmarking suite for evaluating the performance of browsers in handling complex JavaScript tasks. | [https://github.com/chromium/octane](https://github.com/chromium/octane) | + | Kraken | JavaScript performance test suite, including a series of test cases covering dynamic scenarios, garbage collection, encryption, and graphics operations. | [https://github.com/mozilla/krakenbenchmark.mozilla.org](https://github.com/mozilla/krakenbenchmark.mozilla.org) | + | SunSpider | JavaScript performance testing suite, used to evaluate the performance of JavaScript engines in performing common tasks. | [https://github.com/mozilla/krakenbenchmark.mozilla.org](https://github.com/mozilla/krakenbenchmark.mozilla.org) | +#### Comparison Engine + When running this benchmark, you can compare the performance of es2abc compilation with that of Hermes compilation. Hermes engine GitHub address: https://github.com/facebook/hermes + +#### Run an example +The script runtime depends on the es2abc executable after the ets_frontend component is compiled. es2abc compilation command: +``` +$ ./build.sh --product-name rk3568 --build-target ets_frontend_build +``` +Specify the es2abc executable and run the 'run_benchmark.py' for testing: +``` +$ python3 run_benchmark.py --es2abc-tool /out/xx/xx/xx/ets_frontend/es2abc +``` +Compare with Hermes Engine: +``` +$ python3 run_benchmark.py --es2abc-tool /out/xx/xx/xx/ets_frontend/es2abc --engine-comp +``` +Specify the number of rounds of test case compilation (20 rounds by default): +``` +$ python3 run_benchmark.py --es2abc-tool /out/xx/xx/xx/ets_frontend/es2abc --runs 10 // It can be modified to the required number of compilation rounds +``` +--parse-only only parses the test case, and when the --engine-comp parameter is used, this parameter is invalid: +``` +$ python3 run_benchmark.py --es2abc-tool /out/xx/xx/xx/ets_frontend/es2abc --parse-only +``` +--opt-level specifies the compilation optimization level, and when the --engine-comp parameter is used, this parameter is invalid: +``` +$ python3 run_benchmark.py --es2abc-tool /out/xx/xx/xx/ets_frontend/es2abc --opt-level '2' +``` +The generated test results are stored in the 'output' directory, and the command line prints basic test information, such as: + +```plain +> > > benchmark running +Running navier-stokes.... +Running typescript.... +Running mandreel.... +``` +### Precautions + This tool relies on ets_frontend components to compile the es2abc executable file. and you need to specify the es2abc path when using it. + The test cases for this tool are open source cases, and the test suite is automatically pulled during run time. + diff --git a/es2panda/test/benchmark/README_zh.md b/es2panda/test/benchmark/README_zh.md new file mode 100644 index 0000000000000000000000000000000000000000..8d6bcb5664d46540750dda4f85a83b99948afe46 --- /dev/null +++ b/es2panda/test/benchmark/README_zh.md @@ -0,0 +1,66 @@ +# es2abc-benchmark + +## 项目说明 + 本项目旨在对es2abc编译js时的性能进行测试并输出测试结果报告。 + 本项目依赖python3、git以及ets_frontend组件下的es2abc可执行文件。 + 其中测试用例默认存放在`test_cases`目录,运行结果存放在`output`目录。 +## 用法说明 +### 工具运行 +#### 参数说明 +| 参数 | 描述 | 类型 | 默认值 | +| :-----------: |:---------------------------------------------------:| :----: | :--------------------------------------: | +| --es2abc-tool | 这个参数是必需的,需要提供一个es2abc工具的路径。 | string | N/A | +| --runs | 这个参数是可选的,默认值为20。表示一次测试中执行用例的次数。 | int | 20 | +| --opt-level | 这个参数是可选的,它指定了编译器的优化级别。 | string | 0 | +| --parse-only | 这个参数是可选的,默认值为False。如果设置为True,那么在测试期间,只会解析输入文件。 | bool | False | +| --engine-comp | 这个参数是可选的,默认值为False,此时,只进行es2abc测试,为True时与Hermes引擎对比 | bool | False | +#### 测试用例说明 + 本项目测试套件及测试用例来源于开源库: +##### 测试套件: + | 名称 | 描述 | GitHub 地址 | + | :--: | :--: | :--: | + | Octane | JavaScript基准测试套件,用于评估浏览器在处理复杂JavaScript任务时的性能 | [https://github.com/chromium/octane](https://github.com/chromium/octane) | + | Kraken | JavaScript性能测试套件,包含一系列的测试用例,涵盖了诸如动态场景、垃圾回收、加密和图形操作等方面 | [https://github.com/mozilla/krakenbenchmark.mozilla.org](https://github.com/mozilla/krakenbenchmark.mozilla.org) | + | SunSpider | JavaScript性能测试套件,用于评估JavaScript引擎在执行一些常见任务时的性能 | [https://github.com/mozilla/krakenbenchmark.mozilla.org](https://github.com/mozilla/krakenbenchmark.mozilla.org) | + +#### 对比引擎 + 运行本benchmark时可进行es2abc编译性能与hermes编译性能对比,hermes引擎GitHub地址:https://github.com/facebook/hermes +#### 运行示例 +脚本运行时依赖ets_frontend组件编译后的es2abc可执行文件 +es2abc编译命令: + +``` +$ ./build.sh --product-name rk3568 --build-target ets_frontend_build +``` +指定es2abc可执行文件,运行`run_benchmark.py`进行测试: +``` +$ python3 run_benchmark.py --es2abc-tool /out/xx/xx/xx/ets_frontend/es2abc +``` +与hermes引擎进行对比: +``` +$ python3 run_benchmark.py --es2abc-tool /out/xx/xx/xx/ets_frontend/es2abc --engine-comp +``` +指定测试用例编译轮数(默认为20轮): +``` +$ python3 run_benchmark.py --es2abc-tool /out/xx/xx/xx/ets_frontend/es2abc --runs 10 +``` +--parse-only 只对测试用例做解析动作,使用参数 --engine-comp时,本参数失效: +``` +$ python3 run_benchmark.py --es2abc-tool /out/xx/xx/xx/ets_frontend/es2abc --parse-only +``` +--opt-level 指定编译优化等级,使用参数 --engine-comp时,本参数失效: +``` +$ python3 run_benchmark.py --es2abc-tool /out/xx/xx/xx/ets_frontend/es2abc --opt-level '2' +``` +生成的测试结果存放至 `output` 目录,命令行打印基本的测试信息,如: + +```plain +> > > benchmark running +Running navier-stokes.... +Running typescript.... +Running mandreel.... +``` +### 注意事项 + 本工具依赖ets_frontend组件编译产物es2abc可执行文件,使用时需指定es2abc路径。 + 本工具测试用例为开源用例,测试套件在运行时自动拉取。 + diff --git a/es2panda/test/benchmark/config.py b/es2panda/test/benchmark/config.py new file mode 100755 index 0000000000000000000000000000000000000000..a055dfe0059f580761659430330a7ae280d04797 --- /dev/null +++ b/es2panda/test/benchmark/config.py @@ -0,0 +1,151 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- + +""" +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. +""" + +import os + +CUR_FILE_DIR = os.path.dirname(__file__) +DEFAULT_ES2ABC_TOOL = os.path.join(CUR_FILE_DIR, 'es2abc') +REPORT_DIR = os.path.join(CUR_FILE_DIR, 'output') +DEFAULT_TESTCASES_DIR = 'test_cases' +DEFAULT_OUTPUT_DIR = os.path.join(CUR_FILE_DIR, 'es2abc_output') +HERMES_CODE_PATH = os.path.join(CUR_FILE_DIR, 'hermes_workingdir') +DEFAULT_HERMES_PATH = os.path.join(HERMES_CODE_PATH, 'build', "bin", 'hermes') +HERMES_BUILD_PATH = os.path.join(HERMES_CODE_PATH, "build") +HERMES_BUILD_LOG_PATH = os.path.join(HERMES_CODE_PATH, "build.log") +HERMES_CLONE_PATH = os.path.join(HERMES_CODE_PATH, "hermes") +BUILD_HERMES_CMDS = cmds = [['cmake', '-S', HERMES_CLONE_PATH, '-B', HERMES_BUILD_PATH, '-G', 'Ninja', + "-DCMAKE_BUILD_TYPE=Release"], + ['cmake', '--build', HERMES_BUILD_PATH]] +DEFAULT_RUNS = 20 +DEFAULT_PARAMS = ["--module", "--merge-abc"] +DEFAULT_HERMES_PARAMS = ["-emit-binary", "-out"] +JS_FILE_SUFFIX = ".js" +TS_FILE_SUFFIX = ".Ts" +HERMES_FILE_SUFFIX = ".hbc" +CASE_DATA_SUFFIX = "-data.js" +OCTANE = "Octane" +KRAKEN = "Kraken" +SUNSPIDER = "Sunspider" +KRAKENBENCHMARK_CASE_PATH = "tests" +KRAKEN_CASE_PATH = 'kraken-1.1' +SUNSPIDER_CASE_PATH = 'sunspider-0.9.1' +ABC_FILE_SUFFIX = ".abc" +TEST_RESULT_FILE = "test_result.html" +LOG_FILE = "test_result.txt" +PARSE_ONLY = "parse-only(Only do parsing actions)" +OPT_LEVEL = "opt-level(level of compilation optimization)" +COMP = "engine-comp(Compared with the Hermes engine)" +RUNS_NUM = "runs(Number of runs)" +SELECTED_PARAMETERS = "Runtime parameters" +SELECTED_PARAMETERS_BASE = "Selected parameters:" +DEFAULT_TIME = "Time" +AVERAGE_TIME = "Average time of one round" +GIT_DIR = ".git" +CLONE_DIR_SUFFIX = "_base" +ES2ABC = "es2abc" +HERMES = "hermes" +HERMES_GIT_URL = 'https://github.com/facebook/hermes.git' +CASE_URLS = [{"name": "Octane", "url": "https://github.com/chromium/octane.git", "dir": "."}, + {"name": "Kraken", "url": "https://github.com/mozilla/krakenbenchmark.mozilla.org.git", "dir": "test"}, + {"name": "Sunspider", "url": "https://github.com/mozilla/krakenbenchmark.mozilla.org.git", "dir": "test"}] + +CASE_LIST = { + "Octane": ['box2d.js', 'code-load.js', 'crypto.js', 'deltablue.js', 'gbemu.js', 'navier-stokes.js', + 'pdfjs.js', 'raytrace.js', 'regexp.js', 'richards.js', 'splay.js', 'typescript.js'], + "Kraken": ['ai-astar.js', 'audio-beat-detection.js', 'audio-dft.js', 'audio-fft.js', 'audio-oscillator.js', + 'json-parse-financial.js', 'json-stringify-tinderbox.js', 'stanford-crypto-aes.js', + 'stanford-crypto-ccm.js', + 'stanford-crypto-pbkdf2.js', 'stanford-crypto-sha256-iterative.js'], + "Sunspider": ['3d-cube.js', '3d-morph.js', '3d-raytrace.js', 'access-binary-trees.js', 'access-fannkuch.js', + 'access-nbody.js', 'access-nsieve.js', 'bitops-3bit-bits-in-byte.js', 'bitops-bits-in-byte.js', + 'bitops-bitwise-and.js', 'bitops-nsieve-bits.js', 'controlflow-recursive.js', 'crypto-aes.js', + 'crypto-md5.js', 'crypto-sha1.js', 'date-format-tofte.js', 'date-format-xparb.js', 'math-cordic.js', + 'math-partial-sums.js', 'math-spectral-norm.js', 'regexp-dna.js', 'string-base64.js', + 'string-fasta.js', 'string-tagcloud.js', 'string-unpack-code.js', 'string-validate-input.js']} + +HTML_TEMPLATE = """ + + + es2abc Benchmark Test Report + + + + +

es2abc-benchmark

+
Selected parameters:
+ """ + +HTML_TABLE_DEFAULT = """ + + + + + + + + """ + +HTML_TABLE_COMP = """ +
CaseNumber of runsTimeScore
+ + + + + + + + + + + + """ + +HTML_SCRIPT = """ +
Case + Number of runses2abchermes
TimeScoreTimeScore
+ """ diff --git a/es2panda/test/benchmark/run_benchmark.py b/es2panda/test/benchmark/run_benchmark.py new file mode 100644 index 0000000000000000000000000000000000000000..0236957422a43274438b0d606e421a05a9bed78c --- /dev/null +++ b/es2panda/test/benchmark/run_benchmark.py @@ -0,0 +1,186 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- + +""" +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. +""" + +import argparse +import math +import os +import time +from config import COMP, DEFAULT_RUNS, PARSE_ONLY, OPT_LEVEL, RUNS_NUM, DEFAULT_PARAMS, CUR_FILE_DIR, \ + DEFAULT_TESTCASES_DIR, SELECTED_PARAMETERS, JS_FILE_SUFFIX, TS_FILE_SUFFIX, REPORT_DIR, TEST_RESULT_FILE, \ + DEFAULT_OUTPUT_DIR, ABC_FILE_SUFFIX, DEFAULT_HERMES_PARAMS, DEFAULT_HERMES_PATH, HERMES_FILE_SUFFIX, \ + HERMES_CODE_PATH, ES2ABC, HERMES +from utils import traverse_dir, write_result, write_html, run_cmd_cwd, clear_folder_shutil, pull_cases, remove_dir, \ + pull_build_hermes + + +def parse_args(): + parser = argparse.ArgumentParser() + parser.add_argument('--es2abc-tool', + required=True, + help="es2abc tool path") + parser.add_argument('--runs', required=False, type=int, + default=DEFAULT_RUNS, + help='Number of runs') + parser.add_argument('--opt-level', required=False, choices=['0', '1', '2'], + help="Specifies the compiler optimization level") + parser.add_argument('--parse-only', required=False, + default=False, action='store_true', + help="During the test, only the input file is parsed") + parser.add_argument('--engine-comp', required=False, + default=False, action='store_true', + help="Compared to the other engine") + arguments = parser.parse_args() + return arguments + + +class Es2AbcBenchMarks: + def __init__(self, args): + self.args = args + self.results = [] + self.cmds = {} + self.select_params = [] + + def parse_args(self): + cmds = {ES2ABC: [self.args.es2abc_tool]} + if self.args.parse_only and not self.args.engine_comp: + cmds[ES2ABC].append('--parse-only') + self.select_params.append(f'{PARSE_ONLY}:True') + else: + self.select_params.append(f'{PARSE_ONLY}:False') + if self.args.opt_level and not self.args.engine_comp: + cmds[ES2ABC].append(f'--opt-level {self.args.opt_level}') + self.select_params.append(f'{OPT_LEVEL}:{self.args.opt_level}') + else: + self.select_params.append(f'{OPT_LEVEL}:0') + self.select_params.append(f'{RUNS_NUM}:{self.args.runs}') + cmds[ES2ABC] += DEFAULT_PARAMS + if self.args.engine_comp: + cmds[HERMES] = [DEFAULT_HERMES_PATH] + DEFAULT_HERMES_PARAMS + self.select_params.append(f'{COMP}:True') + else: + self.select_params.append(f'{COMP}:False') + self.cmds = cmds + + def run(self): + test_case_path = os.path.join(CUR_FILE_DIR, DEFAULT_TESTCASES_DIR) + test_cases_files = traverse_dir(test_case_path) + self.parse_args() + html_data = {} + selected_params = f'{SELECTED_PARAMETERS}: {"; ".join(self.select_params)}' + write_result(selected_params) + for dir_name, file_paths in test_cases_files.items(): + case_dir_name = os.path.basename(dir_name) + case_info_html_data = {} + case_info_path = os.path.join(REPORT_DIR, f'{case_dir_name}.html') + print(f"---------------------------{case_dir_name}--------------------------------") + for engine_type in self.cmds: + print(f">>>engine {engine_type}") + case_execution_time_sum, means = self.run_benchmark(file_paths, engine_type, case_dir_name, + case_info_html_data) + print(f">>>Done. \n") + case_execution_time_sum_avg = str(case_execution_time_sum) + score_sum = self.args.runs / self.gen_score(means) + test_result = [f'{case_dir_name}', case_execution_time_sum_avg, f'{score_sum * 100}'.split('.')[0], + case_info_path, self.args.runs] + if engine_type in html_data: + html_data[engine_type].append(test_result) + else: + html_data[engine_type] = [test_result] + write_html(case_info_html_data, case_info_path, selected_params, info=True) + print("-------------------------------------------------------------------\n") + write_html(html_data, os.path.join(REPORT_DIR, TEST_RESULT_FILE), selected_params, info=False) + + def run_benchmark(self, file_paths, engine_type, case_dir_name, case_info_html_data): + case_execution_time_sum = 0 + means = [] + for file_path in file_paths: + file_name = os.path.basename(file_path) + if not (file_name.endswith(JS_FILE_SUFFIX) or file_name.endswith(TS_FILE_SUFFIX)): + continue + print(f'Running {file_name.replace(JS_FILE_SUFFIX, "").replace(TS_FILE_SUFFIX, "")} ') + case_execution_time, case_execution_times = self.run_single_benchmark(file_path, engine_type) + case_execution_time_ms = str(case_execution_time * 1000).split(".")[0] + case_execution_time_sum += int(case_execution_time_ms) + mean = self.gen_score(case_execution_times) + means.append(mean) + score = self.args.runs / mean + score = f'{score * 100}'.split('.')[0] + log_str = (f'engine {engine_type} case: {os.path.join(case_dir_name, file_name)} number of runs: ' + f'{self.args.runs} avg time: {case_execution_time_ms}ms Score:{score}\n') + single_case_result = [f'{os.path.join(case_dir_name, file_name)}', case_execution_time_ms, score, + self.args.runs] + if engine_type in case_info_html_data: + case_info_html_data[engine_type].append(single_case_result) + else: + case_info_html_data[engine_type] = [single_case_result] + write_result(log_str) + return case_execution_time_sum, means + + def run_single_benchmark(self, file_path, engine_type): + elapsed_sum = 0 + case_execution_times = [] + new_cmds = [i for i in self.cmds[engine_type]] + output_file = os.path.join(DEFAULT_OUTPUT_DIR, os.path.basename(file_path). + replace(JS_FILE_SUFFIX, ABC_FILE_SUFFIX). + replace(TS_FILE_SUFFIX, ABC_FILE_SUFFIX)) + if engine_type == ES2ABC: + new_cmds += [file_path, "--output", output_file] + else: + new_cmds += [output_file.replace(ABC_FILE_SUFFIX, HERMES_FILE_SUFFIX), file_path] + for _ in range(self.args.runs): + start = time.time() + run_cmd_cwd(new_cmds) + elapsed_sum += time.time() - start + case_execution_times.append(elapsed_sum) + return elapsed_sum / self.args.runs, case_execution_times + + @staticmethod + def gen_score(numbers): + log = 0 + for num in numbers: + log += math.log(num) + mean = math.exp(log / len(numbers)) + return mean + + +def prepare_and_run(args): + clear_folder_shutil(DEFAULT_OUTPUT_DIR) + clear_folder_shutil(REPORT_DIR) + clear_folder_shutil(DEFAULT_TESTCASES_DIR) + pull_cases_success = pull_cases() + if pull_cases_success: + abc_runner = Es2AbcBenchMarks(args) + abc_runner.run() + remove_dir(DEFAULT_OUTPUT_DIR) + print("> > > Done.") + + +def main(): + args = parse_args() + print("> > > benchmark running") + if args.engine_comp: + clear_folder_shutil(HERMES_CODE_PATH) + print("Building Hermes...") + build_result = pull_build_hermes() + if not build_result: + raise Exception('build hermes failed.') + prepare_and_run(args) + + +if __name__ == "__main__": + main() diff --git a/es2panda/test/benchmark/utils.py b/es2panda/test/benchmark/utils.py new file mode 100644 index 0000000000000000000000000000000000000000..fc16f1a42f0f210de663afd96979604bc3a349b2 --- /dev/null +++ b/es2panda/test/benchmark/utils.py @@ -0,0 +1,219 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- + +""" +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. +""" +import os +import shutil +import subprocess + +from config import BUILD_HERMES_CMDS, HERMES_BUILD_LOG_PATH, HERMES_CLONE_PATH, REPORT_DIR, LOG_FILE, \ + CASE_URLS, CUR_FILE_DIR, DEFAULT_TESTCASES_DIR, SUNSPIDER, KRAKEN, \ + CASE_LIST, KRAKENBENCHMARK_CASE_PATH, KRAKEN_CASE_PATH, SUNSPIDER_CASE_PATH, JS_FILE_SUFFIX, \ + CASE_DATA_SUFFIX, HTML_TEMPLATE, DEFAULT_TIME, AVERAGE_TIME, HTML_SCRIPT, SELECTED_PARAMETERS_BASE, \ + HTML_TABLE_DEFAULT, HTML_TABLE_COMP, HERMES_GIT_URL, ES2ABC, HERMES + + +def write_result(log_str): + write_log_file(os.path.join(REPORT_DIR, LOG_FILE), log_str) + + +def write_log_file(file_path, log_str): + with open(file_path, mode='a+') as f: + f.write(log_str) + + +def traverse_dir(path): + file_paths = {} + for file in os.listdir(path): + file_path = os.path.join(path, file) + if os.path.isdir(file_path): + file_paths.update(traverse_dir(file_path)) + else: + dir_name = os.path.dirname(file_path) + if dir_name not in file_paths: + file_paths[dir_name] = [file_path] + else: + file_paths[dir_name].append(file_path) + return file_paths + + +def run_cmd_cwd(cmds): + p = subprocess.Popen(cmds, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + p.wait() + return p.returncode + + +def git_clone(git_url, code_dir): + cmd = ['git', 'clone', git_url, code_dir] + ret = run_cmd_cwd(cmd) + result = True + if ret: + print(f"\n error: Cloning '{git_url}' failed.") + result = False + return result + + +def clear_folder_shutil(path): + if os.path.exists(path): + shutil.rmtree(path) + os.mkdir(path) + + +def remove_dir(path): + if os.path.exists(path): + shutil.rmtree(path) + + +def remove_file(file): + if os.path.exists(file): + os.remove(file) + + +def mkdir(path): + if not os.path.exists(path): + os.makedirs(path) + + +def merge_files(file_list): + base_file = file_list[0] + output_file = open(base_file, "a+") + for i in range(1, len(file_list)): + file = open(file_list[i], "r") + output_file.write(file.read()) + file.close() + output_file.close() + + +def pull_build_hermes(): + result = git_clone(HERMES_GIT_URL, HERMES_CLONE_PATH) + if not result: + return False + for cmd in BUILD_HERMES_CMDS: + p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + while True: + output = p.stdout.readline().decode() + if output == '' and p.poll() is not None: + break + if output: + write_log_file(HERMES_BUILD_LOG_PATH, f'{output.strip()} \n') + if p.returncode: + print(f"\n error: build hermes failed. {' '.join(cmd)}") + return False + return True + + +def pull_cases(): + for case_git_info in CASE_URLS: + case_dir_name = case_git_info.get("name", None) + case_url = case_git_info.get("url", None) + if not case_dir_name or not case_url: + continue + dir_path = os.path.join(CUR_FILE_DIR, DEFAULT_TESTCASES_DIR, case_dir_name) + if case_dir_name != SUNSPIDER: + clear_folder_shutil(dir_path) + clone_result = git_clone(case_url, dir_path) + if not clone_result: + return False + if case_dir_name == KRAKEN: + kraken_case_path = os.path.join(CUR_FILE_DIR, DEFAULT_TESTCASES_DIR, SUNSPIDER) + shutil.copytree(dir_path, kraken_case_path) + if case_dir_name == KRAKEN: + tests_dir_path = os.path.join(dir_path, KRAKENBENCHMARK_CASE_PATH, KRAKEN_CASE_PATH) + filter_list = CASE_LIST.get(KRAKEN) + elif case_dir_name == SUNSPIDER: + tests_dir_path = os.path.join(dir_path, KRAKENBENCHMARK_CASE_PATH, SUNSPIDER_CASE_PATH) + filter_list = CASE_LIST.get(SUNSPIDER) + else: + tests_dir_path = dir_path + filter_list = CASE_LIST.get(case_dir_name) + filter_case(case_dir_name, tests_dir_path, dir_path, filter_list) + return True + + +def filter_case(case_dir_name, tests_dir_path, dir_path, case_list): + del_file_paths = [] + if case_dir_name in [SUNSPIDER, KRAKEN]: + for file in os.listdir(tests_dir_path): + del_file_paths.append(process_file(file, case_list, dir_path, tests_dir_path)) + for file in os.listdir(dir_path): + if file not in case_list: + del_file_paths.append(os.path.join(dir_path, file)) + else: + case_path = os.path.join(dir_path, file) + case_data = case_path.replace(JS_FILE_SUFFIX, CASE_DATA_SUFFIX) + if os.path.exists(case_data): + merge_files([case_path, case_data]) + delete_files(del_file_paths) + + +def process_file(file, case_list, dir_path, tests_dir_path): + if file not in case_list: + return os.path.join(dir_path, file) + else: + need_case_path = os.path.join(tests_dir_path, file) + case_data_file = file.replace(JS_FILE_SUFFIX, CASE_DATA_SUFFIX) + need_case_data_path = os.path.join(tests_dir_path, case_data_file) + if os.path.exists(need_case_data_path): + merge_files([need_case_path, need_case_data_path]) + shutil.move(need_case_path, dir_path) + return '' + + +def delete_files(file_paths): + for file_path in file_paths: + if not file_path: + continue + if os.path.isdir(file_path): + remove_dir(file_path) + else: + remove_file(file_path) + + +def write_html(data, save_path, selected_params, info=False): + html_report = HTML_TEMPLATE + HTML_TABLE_DEFAULT + default_engine = True + result_data = data[ES2ABC] + result_data_len = len(result_data) + if len(data) > 1: + html_report = HTML_TEMPLATE + HTML_TABLE_COMP + default_engine = False + hermes_data = data[HERMES] + if result_data_len == len(hermes_data): + for i in range(result_data_len): + result_data[i] += hermes_data[i] + else: + print("Failed to generate comparison results, hermes or es2abc data is missing") + return False + html_report = html_report.replace(SELECTED_PARAMETERS_BASE, selected_params) + if info: + html_report = html_report.replace(DEFAULT_TIME, AVERAGE_TIME) + for row_data in result_data: + if not info: + html_report = f"""{html_report}{row_data[0]} + {row_data[4]}{row_data[1]} ms{row_data[2]}""" + if not default_engine: + html_report = f"{html_report}{row_data[6]} ms{row_data[7]}" + else: + html_report = (f"{html_report}{row_data[0]}{row_data[3]}{row_data[1]} ms" + f"{row_data[2]}") + if not default_engine: + html_report = f"{html_report}{row_data[5]} ms{row_data[6]}" + html_report = f"{html_report}" + html_report = f'{html_report}{HTML_SCRIPT}' + with open(save_path, 'w') as f: + f.write(html_report) + return True + diff --git a/es2panda/test/compiler/js/objectExpression/object-spread-element-arguments-check-expected.txt b/es2panda/test/compiler/js/objectExpression/object-spread-element-arguments-check-expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..d00491fd7e5bb6fa28c517a0bb32b8b506539d4d --- /dev/null +++ b/es2panda/test/compiler/js/objectExpression/object-spread-element-arguments-check-expected.txt @@ -0,0 +1 @@ +1 diff --git a/es2panda/test/compiler/js/objectExpression/object-spread-element-arguments-check.js b/es2panda/test/compiler/js/objectExpression/object-spread-element-arguments-check.js new file mode 100644 index 0000000000000000000000000000000000000000..791c3f4ced5abcfa9ff1b44df80ce4c132b2cdc6 --- /dev/null +++ b/es2panda/test/compiler/js/objectExpression/object-spread-element-arguments-check.js @@ -0,0 +1,12 @@ +"use strict"; +let dd = {"cc": 1} +let a = { + ...dd, + m(b) { + function c() { + let d = arguments; + } + } +} + +print(1); diff --git a/es2panda/test/compiler/ts/cases/compiler/test-ts-private-class-element-10-expected.txt b/es2panda/test/compiler/ts/cases/compiler/test-ts-private-class-element-10-expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..209e3ef4b6247ce746048d5711befda46206d235 --- /dev/null +++ b/es2panda/test/compiler/ts/cases/compiler/test-ts-private-class-element-10-expected.txt @@ -0,0 +1 @@ +20 diff --git a/es2panda/test/compiler/ts/cases/compiler/test-ts-private-class-element-10.ts b/es2panda/test/compiler/ts/cases/compiler/test-ts-private-class-element-10.ts new file mode 100644 index 0000000000000000000000000000000000000000..823359d8748832b4caaeaf6604e0125e270d74d4 --- /dev/null +++ b/es2panda/test/compiler/ts/cases/compiler/test-ts-private-class-element-10.ts @@ -0,0 +1,34 @@ +/* + * 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. + */ + + +// 3. non-static accessors can be named with a private identifier + +let CC3 = class C3 { + #value: number = 0; + get #data() { + return this.#value; + } + set data(num: number) { + this.#value = num; + } + get publicData() { + return this.#data; + } +} + +let c3 = new CC3(); +c3.data = 20; +print(c3.publicData) \ No newline at end of file diff --git a/es2panda/test/compiler/ts/cases/compiler/test-ts-private-class-element-11-expected.txt b/es2panda/test/compiler/ts/cases/compiler/test-ts-private-class-element-11-expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..45b983be36b73c0788dc9cbcb76cbb80fc7bb057 --- /dev/null +++ b/es2panda/test/compiler/ts/cases/compiler/test-ts-private-class-element-11-expected.txt @@ -0,0 +1 @@ +hi diff --git a/es2panda/test/compiler/ts/cases/compiler/test-ts-private-class-element-11.ts b/es2panda/test/compiler/ts/cases/compiler/test-ts-private-class-element-11.ts new file mode 100644 index 0000000000000000000000000000000000000000..a49856c61da4942d42d34cfe06f77469b599e7d5 --- /dev/null +++ b/es2panda/test/compiler/ts/cases/compiler/test-ts-private-class-element-11.ts @@ -0,0 +1,38 @@ +/* + * 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. + */ + + +// 4. static accessors can be named with a private identifier + +let CC4 = class C4 { + static #message: string = ""; + static get #msg() { + return this.#message; + } + + static set #msg(msg: string) { + this.#message = msg; + } + + static set publicMsg(msg: string) { + this.#msg = msg; + } + static get publicMsg() { + return this.#msg; + } +} + +CC4.publicMsg = 'hi'; +print(CC4.publicMsg); diff --git a/es2panda/test/compiler/ts/cases/compiler/test-ts-private-class-element-12-expected.txt b/es2panda/test/compiler/ts/cases/compiler/test-ts-private-class-element-12-expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..162336d8f33c4e6b6b11ae1c33e4ee0c488783d5 --- /dev/null +++ b/es2panda/test/compiler/ts/cases/compiler/test-ts-private-class-element-12-expected.txt @@ -0,0 +1,4 @@ +1 +hello +20 +hi diff --git a/es2panda/test/compiler/ts/cases/compiler/test-ts-private-class-element-12.ts b/es2panda/test/compiler/ts/cases/compiler/test-ts-private-class-element-12.ts new file mode 100644 index 0000000000000000000000000000000000000000..917b7a9ec19fbbaeda0bdf96c4e8bc08c6bf91f7 --- /dev/null +++ b/es2panda/test/compiler/ts/cases/compiler/test-ts-private-class-element-12.ts @@ -0,0 +1,74 @@ +/* + * 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. + */ + + +let CC = class C { + #value: number = 0; + #add() { + this.#value += 1; + } + publicAdd() { + this.#add(); + } + publicPrint() { + print(this.#value); + } + + static #message: string = "hello"; + static #say() { + return this.#message; + } + static publicSay() { + print(this.#say()); + } + + get #data() { + return this.#value; + } + set #data(num: number) { + this.#value = num; + } + get publicData() { + return this.#data; + } + set publicData(num: number) { + this.#data = num; + } + + static get #msg() { + return this.#message; + } + + static set #msg(msg: string) { + this.#message = msg; + } + + static set publicMsg(msg: string) { + this.#msg = msg; + } + static get publicMsg() { + return this.#msg; + } +} + +let c = new CC(); +c.publicAdd(); +c.publicPrint(); +CC.publicSay(); +c.publicData = 20; +print(c.publicData) +CC.publicMsg = 'hi'; +print(CC.publicMsg); + diff --git a/es2panda/test/compiler/ts/cases/compiler/test-ts-private-class-element-6-expected.txt b/es2panda/test/compiler/ts/cases/compiler/test-ts-private-class-element-6-expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..16ae3f997547d12dab5ea16cb15d585dd0bc2343 --- /dev/null +++ b/es2panda/test/compiler/ts/cases/compiler/test-ts-private-class-element-6-expected.txt @@ -0,0 +1,10 @@ +true +true +false +false +false +false +false +false +[object Object] +true diff --git a/es2panda/test/compiler/ts/cases/compiler/test-ts-private-class-element-6.ts b/es2panda/test/compiler/ts/cases/compiler/test-ts-private-class-element-6.ts new file mode 100644 index 0000000000000000000000000000000000000000..5b91bc929b2e84b211264a0a2d2da6159e020c61 --- /dev/null +++ b/es2panda/test/compiler/ts/cases/compiler/test-ts-private-class-element-6.ts @@ -0,0 +1,45 @@ +/* + * 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. + */ + + +class Foo { + #field = 1; + #method() { } + static #staticField = 2; + static #staticMethod() { } + + check(v: any) { + print(#field in v); + print(#method in v); + print(#staticField in v); + print(#staticMethod in v); + } + precedence(v: any) { + print(v == #field in v || v); + print(#field in v && #field in v); + } +} + +class Bar { + #field = 1; +} + +let f = new Foo(); +let b = new Bar(); + +f.check(f); +f.check(b); + +f.precedence(f); \ No newline at end of file diff --git a/es2panda/test/compiler/ts/cases/compiler/test-ts-private-class-element-7-expected.txt b/es2panda/test/compiler/ts/cases/compiler/test-ts-private-class-element-7-expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..3b86147b3542fae0e5e4cdb03bd17a50cf7e758f --- /dev/null +++ b/es2panda/test/compiler/ts/cases/compiler/test-ts-private-class-element-7-expected.txt @@ -0,0 +1,2 @@ +10 +20 diff --git a/es2panda/test/compiler/ts/cases/compiler/test-ts-private-class-element-7.ts b/es2panda/test/compiler/ts/cases/compiler/test-ts-private-class-element-7.ts new file mode 100644 index 0000000000000000000000000000000000000000..2a72f8dcdc3d7e57b5d1bdd27ae7462e2b7e1fc2 --- /dev/null +++ b/es2panda/test/compiler/ts/cases/compiler/test-ts-private-class-element-7.ts @@ -0,0 +1,28 @@ +/* + * 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. + */ + + +class C1 { + static s = new C1().#method(); + #method() { return 10; } +} +print(C1.s); + + +class C2 { + static s = C2.#method(); + static #method() { return 20; } +} +print(C2.s); diff --git a/es2panda/test/compiler/ts/cases/compiler/test-ts-private-class-element-8-expected.txt b/es2panda/test/compiler/ts/cases/compiler/test-ts-private-class-element-8-expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..d00491fd7e5bb6fa28c517a0bb32b8b506539d4d --- /dev/null +++ b/es2panda/test/compiler/ts/cases/compiler/test-ts-private-class-element-8-expected.txt @@ -0,0 +1 @@ +1 diff --git a/es2panda/test/compiler/ts/cases/compiler/test-ts-private-class-element-8.ts b/es2panda/test/compiler/ts/cases/compiler/test-ts-private-class-element-8.ts new file mode 100644 index 0000000000000000000000000000000000000000..39b9cad48eba480bbb819ccfe7583cdf8fe1c27b --- /dev/null +++ b/es2panda/test/compiler/ts/cases/compiler/test-ts-private-class-element-8.ts @@ -0,0 +1,34 @@ +/* + * 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. + */ + + +// 1. non-static methods can be named with a private identifier + +let cc = class C1 { + #value: number = 0; + #add() { + this.#value += 1; + } + publicAdd() { + this.#add(); + } + publicPrint() { + print(this.#value); + } +} + +let c1 = new cc(); +c1.publicAdd(); +c1.publicPrint(); \ No newline at end of file diff --git a/es2panda/test/compiler/ts/cases/compiler/test-ts-private-class-element-9-expected.txt b/es2panda/test/compiler/ts/cases/compiler/test-ts-private-class-element-9-expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..ce013625030ba8dba906f756967f9e9ca394464a --- /dev/null +++ b/es2panda/test/compiler/ts/cases/compiler/test-ts-private-class-element-9-expected.txt @@ -0,0 +1 @@ +hello diff --git a/es2panda/test/compiler/ts/cases/compiler/test-ts-private-class-element-9.ts b/es2panda/test/compiler/ts/cases/compiler/test-ts-private-class-element-9.ts new file mode 100644 index 0000000000000000000000000000000000000000..f74fd38e0b8c23ee513bacc3f585db17352be196 --- /dev/null +++ b/es2panda/test/compiler/ts/cases/compiler/test-ts-private-class-element-9.ts @@ -0,0 +1,29 @@ +/* + * 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. + */ + + +// 2. static properties and methods can be named with a private identifier + +let cc = class C2 { + static #message: string = "hello"; + static #say() { + return this.#message; + } + static publicSay() { + print(this.#say()); + } +} + +cc.publicSay(); \ No newline at end of file diff --git a/es2panda/test/compiler/ts/cases/compiler/test-ts-typeof-returntype-1-expected.txt b/es2panda/test/compiler/ts/cases/compiler/test-ts-typeof-returntype-1-expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..3b18e512dba79e4c8300dd08aeb37f8e728b8dad --- /dev/null +++ b/es2panda/test/compiler/ts/cases/compiler/test-ts-typeof-returntype-1-expected.txt @@ -0,0 +1 @@ +hello world diff --git a/es2panda/test/compiler/ts/cases/compiler/test-ts-typeof-returntype-1.ts b/es2panda/test/compiler/ts/cases/compiler/test-ts-typeof-returntype-1.ts new file mode 100644 index 0000000000000000000000000000000000000000..af5bb42cfc7c685d901dd5cd5957305d8f6fa015 --- /dev/null +++ b/es2panda/test/compiler/ts/cases/compiler/test-ts-typeof-returntype-1.ts @@ -0,0 +1,13 @@ +class MainAbility { + public static test(fn, thisArg): (args: Parameters) => void { + return function extendFn() { + fn.apply(thisArg); + }; + } +} + +function fun(){ + print("hello world"); +} + +MainAbility.test(fun,1)([]); \ No newline at end of file diff --git a/es2panda/test/hotreload/hotreload-throwerror/modify-class-1/expected.txt b/es2panda/test/hotreload/hotreload-throwerror/modify-class-1/expected.txt index 2bb598719068c469f82e8cece69639f6ae97fe45..4d0f814fda98c789dedae02afbeb4f129ab83674 100644 --- a/es2panda/test/hotreload/hotreload-throwerror/modify-class-1/expected.txt +++ b/es2panda/test/hotreload/hotreload-throwerror/modify-class-1/expected.txt @@ -10,8 +10,3 @@ # 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. - -[Patch] Found class .Model changed, not supported! If .Model is not changed and you are changing UI Component, please only change one Component at a time and make sure the Component is placed at the bottom of the file. -[Patch] Found unsupported change in file, will not generate patch! -Error: [base_mod.js:0:0] -the size of programs is expected to be 1, but is 0 diff --git a/es2panda/test/hotreload/hotreload-throwerror/modify-export-1/expected.txt b/es2panda/test/hotreload/hotreload-throwerror/modify-export-1/expected.txt index 3e574e0591d712df221689c96ba8f2ee630f439d..4d0f814fda98c789dedae02afbeb4f129ab83674 100644 --- a/es2panda/test/hotreload/hotreload-throwerror/modify-export-1/expected.txt +++ b/es2panda/test/hotreload/hotreload-throwerror/modify-export-1/expected.txt @@ -10,8 +10,3 @@ # 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. - -[Patch] Found import/export expression changed in _ESModuleRecord, not supported! -[Patch] Found unsupported change in file, will not generate patch! -Error: [base_mod.js:0:0] -the size of programs is expected to be 1, but is 0 diff --git a/es2panda/test/hotreload/hotreload-throwerror/modify-export-2/expected.txt b/es2panda/test/hotreload/hotreload-throwerror/modify-export-2/expected.txt index 3e574e0591d712df221689c96ba8f2ee630f439d..4d0f814fda98c789dedae02afbeb4f129ab83674 100644 --- a/es2panda/test/hotreload/hotreload-throwerror/modify-export-2/expected.txt +++ b/es2panda/test/hotreload/hotreload-throwerror/modify-export-2/expected.txt @@ -10,8 +10,3 @@ # 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. - -[Patch] Found import/export expression changed in _ESModuleRecord, not supported! -[Patch] Found unsupported change in file, will not generate patch! -Error: [base_mod.js:0:0] -the size of programs is expected to be 1, but is 0 diff --git a/es2panda/test/hotreload/hotreload-throwerror/modify-export-3/expected.txt b/es2panda/test/hotreload/hotreload-throwerror/modify-export-3/expected.txt index 3e574e0591d712df221689c96ba8f2ee630f439d..4d0f814fda98c789dedae02afbeb4f129ab83674 100644 --- a/es2panda/test/hotreload/hotreload-throwerror/modify-export-3/expected.txt +++ b/es2panda/test/hotreload/hotreload-throwerror/modify-export-3/expected.txt @@ -10,8 +10,3 @@ # 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. - -[Patch] Found import/export expression changed in _ESModuleRecord, not supported! -[Patch] Found unsupported change in file, will not generate patch! -Error: [base_mod.js:0:0] -the size of programs is expected to be 1, but is 0 diff --git a/es2panda/test/hotreload/hotreload-throwerror/modify-import/expected.txt b/es2panda/test/hotreload/hotreload-throwerror/modify-import/expected.txt index 3e574e0591d712df221689c96ba8f2ee630f439d..4d0f814fda98c789dedae02afbeb4f129ab83674 100644 --- a/es2panda/test/hotreload/hotreload-throwerror/modify-import/expected.txt +++ b/es2panda/test/hotreload/hotreload-throwerror/modify-import/expected.txt @@ -10,8 +10,3 @@ # 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. - -[Patch] Found import/export expression changed in _ESModuleRecord, not supported! -[Patch] Found unsupported change in file, will not generate patch! -Error: [base_mod.js:0:0] -the size of programs is expected to be 1, but is 0 diff --git a/es2panda/test/parser/ts/test-class-definition-expected.txt b/es2panda/test/parser/ts/test-class-definition-expected.txt index 2e0056d63b9cb65c0d039b89c29bd892ad5a0888..91aff142a309197f02b889b5b422dcc668fbd27c 100644 --- a/es2panda/test/parser/ts/test-class-definition-expected.txt +++ b/es2panda/test/parser/ts/test-class-definition-expected.txt @@ -567,35 +567,9 @@ { "type": "ClassProperty", "key": { - "type": "TSPrivateIdentifier", - "key": { - "type": "Identifier", - "name": "o", - "loc": { - "start": { - "line": 27, - "column": 6 - }, - "end": { - "line": 27, - "column": 7 - } - } - }, - "value": { - "type": "NumberLiteral", - "value": 4, - "loc": { - "start": { - "line": 27, - "column": 10 - }, - "end": { - "line": 27, - "column": 11 - } - } - }, + "type": "PrivateIdentifier", + "prefix": "#", + "name": "o", "loc": { "start": { "line": 27, @@ -1636,21 +1610,9 @@ } }, "property": { - "type": "TSPrivateIdentifier", - "key": { - "type": "Identifier", - "name": "name", - "loc": { - "start": { - "line": 39, - "column": 15 - }, - "end": { - "line": 39, - "column": 19 - } - } - }, + "type": "PrivateIdentifier", + "prefix": "#", + "name": "name", "loc": { "start": { "line": 39, @@ -1762,34 +1724,9 @@ { "type": "ClassProperty", "key": { - "type": "TSPrivateIdentifier", - "key": { - "type": "Identifier", - "name": "name", - "loc": { - "start": { - "line": 37, - "column": 6 - }, - "end": { - "line": 37, - "column": 10 - } - } - }, - "typeAnnotation": { - "type": "TSStringKeyword", - "loc": { - "start": { - "line": 37, - "column": 12 - }, - "end": { - "line": 37, - "column": 18 - } - } - }, + "type": "PrivateIdentifier", + "prefix": "#", + "name": "name", "loc": { "start": { "line": 37, @@ -1881,21 +1818,9 @@ } }, "property": { - "type": "TSPrivateIdentifier", - "key": { - "type": "Identifier", - "name": "name", - "loc": { - "start": { - "line": 41, - "column": 26 - }, - "end": { - "line": 41, - "column": 30 - } - } - }, + "type": "PrivateIdentifier", + "prefix": "#", + "name": "name", "loc": { "start": { "line": 41, diff --git a/es2panda/test/parser/ts/test-class-definition28-expected.txt b/es2panda/test/parser/ts/test-class-definition28-expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..6500ccac63589a70d7e2c69e64a2dcf2bb589fe1 --- /dev/null +++ b/es2panda/test/parser/ts/test-class-definition28-expected.txt @@ -0,0 +1 @@ +SyntaxError: An accessibility modifier cannot be used with a private identifier. [test-class-definition28.ts:18:12] diff --git a/es2panda/test/parser/ts/test-class-definition28.ts b/es2panda/test/parser/ts/test-class-definition28.ts new file mode 100644 index 0000000000000000000000000000000000000000..57f5efd4846550dce174a04f51dc8b403cd4f9fa --- /dev/null +++ b/es2panda/test/parser/ts/test-class-definition28.ts @@ -0,0 +1,32 @@ +/* + * 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. + */ + + +class A { + public #foo = 3; + private #bar = 3; + protected #baz = 3; + + public #fooMethod() { return 3; } + private #barMethod() { return 3; } + protected #bazMethod() { return 3; } + + public get #fooProp() { return 3; } + public set #fooProp(value: number) { } + private get #barProp() { return 3; } + private set #barProp(value: number) { } + protected get #bazProp() { return 3; } + protected set #bazProp(value: number) { } +} diff --git a/es2panda/test/parser/ts/test-class-definition29-expected.txt b/es2panda/test/parser/ts/test-class-definition29-expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..3bcb7f2eb38933866faea100d16b2d14821a09c4 --- /dev/null +++ b/es2panda/test/parser/ts/test-class-definition29-expected.txt @@ -0,0 +1 @@ +SyntaxError: 'declare' modifier cannot be used with a private identifier. [test-class-definition29.ts:18:13] diff --git a/es2panda/test/parser/ts/test-class-definition29.ts b/es2panda/test/parser/ts/test-class-definition29.ts new file mode 100644 index 0000000000000000000000000000000000000000..6db01fd31da4556b2c7e76b72e03722ced618d85 --- /dev/null +++ b/es2panda/test/parser/ts/test-class-definition29.ts @@ -0,0 +1,22 @@ +/* + * 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. + */ + + +class A { + declare #what: number; + declare #whatMethod(); + declare get #whatProp(); + declare set #whatProp(value: number); +} diff --git a/es2panda/test/parser/ts/test-class-definiton7-expected.txt b/es2panda/test/parser/ts/test-class-definiton7-expected.txt index e4fab24f6a8733f4ea7a8708a1e023709ad00109..a6dbdf416af1fd0f7da29e3b9a4c9119d0a3bc74 100644 --- a/es2panda/test/parser/ts/test-class-definiton7-expected.txt +++ b/es2panda/test/parser/ts/test-class-definiton7-expected.txt @@ -102,21 +102,9 @@ { "type": "ClassProperty", "key": { - "type": "TSPrivateIdentifier", - "key": { - "type": "Identifier", - "name": "a", - "loc": { - "start": { - "line": 18, - "column": 13 - }, - "end": { - "line": 18, - "column": 14 - } - } - }, + "type": "PrivateIdentifier", + "prefix": "#", + "name": "a", "loc": { "start": { "line": 18, diff --git a/es2panda/test/parser/ts/test-keyword-declare-expected.txt b/es2panda/test/parser/ts/test-keyword-declare-expected.txt index ca36f639e2a0b64eb4eeb009e320203606c3f6c0..f327637d6fada515b99e0a38e0cc49cd9d5532f1 100644 --- a/es2panda/test/parser/ts/test-keyword-declare-expected.txt +++ b/es2panda/test/parser/ts/test-keyword-declare-expected.txt @@ -1116,21 +1116,9 @@ { "type": "ClassProperty", "key": { - "type": "TSPrivateIdentifier", - "key": { - "type": "Identifier", - "name": "o", - "loc": { - "start": { - "line": 44, - "column": 6 - }, - "end": { - "line": 44, - "column": 7 - } - } - }, + "type": "PrivateIdentifier", + "prefix": "#", + "name": "o", "loc": { "start": { "line": 44, diff --git a/es2panda/test/parser/ts/test-private-identifier-expected.txt b/es2panda/test/parser/ts/test-private-identifier-expected.txt index f0b348ddcb0585f9a0ec085ec6c21ffd2c557380..e95a795f5b9585227ecb3c406535a5a5102e39be 100644 --- a/es2panda/test/parser/ts/test-private-identifier-expected.txt +++ b/es2panda/test/parser/ts/test-private-identifier-expected.txt @@ -102,35 +102,9 @@ { "type": "ClassProperty", "key": { - "type": "TSPrivateIdentifier", - "key": { - "type": "Identifier", - "name": "b", - "loc": { - "start": { - "line": 18, - "column": 6 - }, - "end": { - "line": 18, - "column": 7 - } - } - }, - "value": { - "type": "StringLiteral", - "value": "b", - "loc": { - "start": { - "line": 18, - "column": 10 - }, - "end": { - "line": 18, - "column": 13 - } - } - }, + "type": "PrivateIdentifier", + "prefix": "#", + "name": "b", "loc": { "start": { "line": 18, @@ -223,35 +197,9 @@ { "type": "ClassProperty", "key": { - "type": "TSPrivateIdentifier", - "key": { - "type": "Identifier", - "name": "c", - "loc": { - "start": { - "line": 20, - "column": 15 - }, - "end": { - "line": 20, - "column": 16 - } - } - }, - "value": { - "type": "StringLiteral", - "value": "c", - "loc": { - "start": { - "line": 20, - "column": 19 - }, - "end": { - "line": 20, - "column": 22 - } - } - }, + "type": "PrivateIdentifier", + "prefix": "#", + "name": "c", "loc": { "start": { "line": 20, diff --git a/es2panda/test/parser/ts/test-static-blocks-in-class2-expected.txt b/es2panda/test/parser/ts/test-static-blocks-in-class2-expected.txt index 07afafa68b41d3be65a3efb673ee9de38f8f4ab0..54fec5ec151f8e29f9d8f9e326af4cdc72edd160 100644 --- a/es2panda/test/parser/ts/test-static-blocks-in-class2-expected.txt +++ b/es2panda/test/parser/ts/test-static-blocks-in-class2-expected.txt @@ -160,35 +160,9 @@ { "type": "ClassProperty", "key": { - "type": "TSPrivateIdentifier", - "key": { - "type": "Identifier", - "name": "count", - "loc": { - "start": { - "line": 20, - "column": 11 - }, - "end": { - "line": 20, - "column": 16 - } - } - }, - "value": { - "type": "NumberLiteral", - "value": 0, - "loc": { - "start": { - "line": 20, - "column": 19 - }, - "end": { - "line": 20, - "column": 20 - } - } - }, + "type": "PrivateIdentifier", + "prefix": "#", + "name": "count", "loc": { "start": { "line": 20, @@ -282,21 +256,9 @@ } }, "property": { - "type": "TSPrivateIdentifier", - "key": { - "type": "Identifier", - "name": "count", - "loc": { - "start": { - "line": 22, - "column": 24 - }, - "end": { - "line": 22, - "column": 29 - } - } - }, + "type": "PrivateIdentifier", + "prefix": "#", + "name": "count", "loc": { "start": { "line": 22, @@ -430,21 +392,9 @@ } }, "property": { - "type": "TSPrivateIdentifier", - "key": { - "type": "Identifier", - "name": "count", - "loc": { - "start": { - "line": 25, - "column": 24 - }, - "end": { - "line": 25, - "column": 29 - } - } - }, + "type": "PrivateIdentifier", + "prefix": "#", + "name": "count", "loc": { "start": { "line": 25, @@ -559,21 +509,9 @@ } }, "property": { - "type": "TSPrivateIdentifier", - "key": { - "type": "Identifier", - "name": "count", - "loc": { - "start": { - "line": 29, - "column": 19 - }, - "end": { - "line": 29, - "column": 24 - } - } - }, + "type": "PrivateIdentifier", + "prefix": "#", + "name": "count", "loc": { "start": { "line": 29, diff --git a/es2panda/test/parser/ts/test-ts-private-class-element-10-expected.txt b/es2panda/test/parser/ts/test-ts-private-class-element-10-expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..f4765c3567c82c8ded61781e21b04e5154bb816b --- /dev/null +++ b/es2panda/test/parser/ts/test-ts-private-class-element-10-expected.txt @@ -0,0 +1 @@ +SyntaxError: 'declare' modifier cannot be used with a private identifier. [test-ts-private-class-element-10.ts:18:11] diff --git a/es2panda/test/parser/ts/test-ts-private-class-element-10.ts b/es2panda/test/parser/ts/test-ts-private-class-element-10.ts new file mode 100644 index 0000000000000000000000000000000000000000..424159b9d7b4c1a5934dc3b1298964838fb1f2df --- /dev/null +++ b/es2panda/test/parser/ts/test-ts-private-class-element-10.ts @@ -0,0 +1,19 @@ +/* + * 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. + */ + + +declare class DeclareModifierTest { + declare #count: number; +} \ No newline at end of file diff --git a/es2panda/test/parser/ts/test-ts-private-class-element-11-expected.txt b/es2panda/test/parser/ts/test-ts-private-class-element-11-expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..d981d8b1d1d3ba11d2930c85ebd6efd7de1f2829 --- /dev/null +++ b/es2panda/test/parser/ts/test-ts-private-class-element-11-expected.txt @@ -0,0 +1 @@ +SyntaxError: 'abstract' modifier cannot be used with a private identifier. [test-ts-private-class-element-11.ts:18:12] diff --git a/es2panda/test/parser/ts/test-ts-private-class-element-11.ts b/es2panda/test/parser/ts/test-ts-private-class-element-11.ts new file mode 100644 index 0000000000000000000000000000000000000000..79aec5a7d06efc72b10ccd6f8f13adf213b27a5a --- /dev/null +++ b/es2panda/test/parser/ts/test-ts-private-class-element-11.ts @@ -0,0 +1,19 @@ +/* + * 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. + */ + + +abstract class AbstractModifierTest { + abstract #count: number; +} \ No newline at end of file diff --git a/es2panda/test/parser/ts/test-ts-private-class-element-12-expected.txt b/es2panda/test/parser/ts/test-ts-private-class-element-12-expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..51ad607b2512679696f5d3248424c2ceea085b24 --- /dev/null +++ b/es2panda/test/parser/ts/test-ts-private-class-element-12-expected.txt @@ -0,0 +1,1210 @@ +{ + "type": "Program", + "statements": [ + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "BaseClass", + "loc": { + "start": { + "line": 17, + "column": 7 + }, + "end": { + "line": 17, + "column": 16 + } + } + }, + "superClass": null, + "implements": [], + "constructor": { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "constructor", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "constructor", + "static": false, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": null, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 1 + }, + "end": { + "line": 19, + "column": 2 + } + } + }, + "body": [ + { + "type": "ClassProperty", + "key": { + "type": "PrivateIdentifier", + "prefix": "#", + "name": "count", + "loc": { + "start": { + "line": 18, + "column": 3 + }, + "end": { + "line": 18, + "column": 9 + } + } + }, + "value": { + "type": "NumberLiteral", + "value": 1, + "loc": { + "start": { + "line": 18, + "column": 20 + }, + "end": { + "line": 18, + "column": 21 + } + } + }, + "static": false, + "readonly": false, + "declare": false, + "optional": false, + "computed": false, + "typeAnnotation": { + "type": "TSNumberKeyword", + "loc": { + "start": { + "line": 18, + "column": 11 + }, + "end": { + "line": 18, + "column": 17 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 3 + }, + "end": { + "line": 18, + "column": 21 + } + } + } + ], + "indexSignatures": [], + "loc": { + "start": { + "line": 17, + "column": 17 + }, + "end": { + "line": 19, + "column": 2 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 1 + }, + "end": { + "line": 19, + "column": 2 + } + } + }, + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "OverrideModifierTest", + "loc": { + "start": { + "line": 21, + "column": 7 + }, + "end": { + "line": 21, + "column": 27 + } + } + }, + "superClass": { + "type": "Identifier", + "name": "BaseClass", + "loc": { + "start": { + "line": 21, + "column": 36 + }, + "end": { + "line": 21, + "column": 45 + } + } + }, + "implements": [], + "constructor": { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "constructor", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "constructor", + "static": false, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": null, + "generator": false, + "async": false, + "expression": false, + "params": [ + { + "type": "RestElement", + "argument": { + "type": "Identifier", + "name": "args", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "ExpressionStatement", + "expression": { + "type": "CallExpression", + "callee": { + "type": "Super", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "arguments": [ + { + "type": "SpreadElement", + "argument": { + "type": "Identifier", + "name": "args", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "optional": false, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 1 + }, + "end": { + "line": 23, + "column": 2 + } + } + }, + "body": [ + { + "type": "ClassProperty", + "key": { + "type": "PrivateIdentifier", + "prefix": "#", + "name": "count", + "loc": { + "start": { + "line": 22, + "column": 12 + }, + "end": { + "line": 22, + "column": 18 + } + } + }, + "value": { + "type": "NumberLiteral", + "value": 0, + "loc": { + "start": { + "line": 22, + "column": 29 + }, + "end": { + "line": 22, + "column": 30 + } + } + }, + "static": false, + "readonly": false, + "override": true, + "declare": false, + "optional": false, + "computed": false, + "typeAnnotation": { + "type": "TSNumberKeyword", + "loc": { + "start": { + "line": 22, + "column": 20 + }, + "end": { + "line": 22, + "column": 26 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 22, + "column": 3 + }, + "end": { + "line": 22, + "column": 30 + } + } + } + ], + "indexSignatures": [], + "loc": { + "start": { + "line": 21, + "column": 46 + }, + "end": { + "line": 23, + "column": 2 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 1 + }, + "end": { + "line": 23, + "column": 2 + } + } + }, + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "StaticModifierTest", + "loc": { + "start": { + "line": 25, + "column": 7 + }, + "end": { + "line": 25, + "column": 25 + } + } + }, + "superClass": null, + "implements": [], + "constructor": { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "constructor", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "constructor", + "static": false, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": null, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 25, + "column": 1 + }, + "end": { + "line": 27, + "column": 2 + } + } + }, + "body": [ + { + "type": "ClassProperty", + "key": { + "type": "PrivateIdentifier", + "prefix": "#", + "name": "count", + "loc": { + "start": { + "line": 26, + "column": 10 + }, + "end": { + "line": 26, + "column": 16 + } + } + }, + "value": { + "type": "NumberLiteral", + "value": 0, + "loc": { + "start": { + "line": 26, + "column": 19 + }, + "end": { + "line": 26, + "column": 20 + } + } + }, + "static": true, + "readonly": false, + "declare": false, + "optional": false, + "computed": false, + "decorators": [], + "loc": { + "start": { + "line": 26, + "column": 3 + }, + "end": { + "line": 26, + "column": 20 + } + } + } + ], + "indexSignatures": [], + "loc": { + "start": { + "line": 25, + "column": 26 + }, + "end": { + "line": 27, + "column": 2 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 25, + "column": 1 + }, + "end": { + "line": 27, + "column": 2 + } + } + }, + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "AccessorModifierTest", + "loc": { + "start": { + "line": 29, + "column": 7 + }, + "end": { + "line": 29, + "column": 27 + } + } + }, + "superClass": null, + "implements": [], + "constructor": { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "constructor", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "constructor", + "static": false, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": null, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 29, + "column": 1 + }, + "end": { + "line": 31, + "column": 2 + } + } + }, + "body": [ + { + "type": "ClassProperty", + "key": { + "type": "PrivateIdentifier", + "prefix": "#", + "name": "count", + "loc": { + "start": { + "line": 30, + "column": 12 + }, + "end": { + "line": 30, + "column": 18 + } + } + }, + "value": { + "type": "NumberLiteral", + "value": 0, + "loc": { + "start": { + "line": 30, + "column": 21 + }, + "end": { + "line": 30, + "column": 22 + } + } + }, + "static": false, + "readonly": false, + "declare": false, + "optional": false, + "computed": false, + "decorators": [], + "loc": { + "start": { + "line": 30, + "column": 3 + }, + "end": { + "line": 30, + "column": 22 + } + } + } + ], + "indexSignatures": [], + "loc": { + "start": { + "line": 29, + "column": 28 + }, + "end": { + "line": 31, + "column": 2 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 29, + "column": 1 + }, + "end": { + "line": 31, + "column": 2 + } + } + }, + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "ReadonlyModifierTest", + "loc": { + "start": { + "line": 33, + "column": 7 + }, + "end": { + "line": 33, + "column": 27 + } + } + }, + "superClass": null, + "implements": [], + "constructor": { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "constructor", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "constructor", + "static": false, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": null, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 33, + "column": 1 + }, + "end": { + "line": 35, + "column": 2 + } + } + }, + "body": [ + { + "type": "ClassProperty", + "key": { + "type": "PrivateIdentifier", + "prefix": "#", + "name": "count", + "loc": { + "start": { + "line": 34, + "column": 12 + }, + "end": { + "line": 34, + "column": 18 + } + } + }, + "value": { + "type": "NumberLiteral", + "value": 0, + "loc": { + "start": { + "line": 34, + "column": 21 + }, + "end": { + "line": 34, + "column": 22 + } + } + }, + "static": false, + "readonly": true, + "declare": false, + "optional": false, + "computed": false, + "decorators": [], + "loc": { + "start": { + "line": 34, + "column": 3 + }, + "end": { + "line": 34, + "column": 22 + } + } + } + ], + "indexSignatures": [], + "loc": { + "start": { + "line": 33, + "column": 28 + }, + "end": { + "line": 35, + "column": 2 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 33, + "column": 1 + }, + "end": { + "line": 35, + "column": 2 + } + } + }, + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "AsyncModifierTest", + "loc": { + "start": { + "line": 37, + "column": 7 + }, + "end": { + "line": 37, + "column": 24 + } + } + }, + "superClass": null, + "implements": [], + "constructor": { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "constructor", + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "constructor", + "static": false, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": null, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 37, + "column": 1 + }, + "end": { + "line": 39, + "column": 2 + } + } + }, + "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "PrivateIdentifier", + "prefix": "#", + "name": "foo", + "loc": { + "start": { + "line": 38, + "column": 9 + }, + "end": { + "line": 38, + "column": 13 + } + } + }, + "kind": "method", + "static": false, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": null, + "generator": false, + "async": true, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 38, + "column": 15 + }, + "end": { + "line": 38, + "column": 17 + } + } + }, + "loc": { + "start": { + "line": 38, + "column": 13 + }, + "end": { + "line": 38, + "column": 17 + } + } + }, + "loc": { + "start": { + "line": 38, + "column": 13 + }, + "end": { + "line": 38, + "column": 17 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 38, + "column": 3 + }, + "end": { + "line": 38, + "column": 17 + } + } + } + ], + "indexSignatures": [], + "loc": { + "start": { + "line": 37, + "column": 25 + }, + "end": { + "line": 39, + "column": 2 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 37, + "column": 1 + }, + "end": { + "line": 39, + "column": 2 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 39, + "column": 2 + } + } +} diff --git a/es2panda/test/parser/ts/test-ts-private-class-element-12.ts b/es2panda/test/parser/ts/test-ts-private-class-element-12.ts new file mode 100644 index 0000000000000000000000000000000000000000..a3af1999b5e93b2a4deb8f49d007d403ecc9afe2 --- /dev/null +++ b/es2panda/test/parser/ts/test-ts-private-class-element-12.ts @@ -0,0 +1,39 @@ +/* + * 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. + */ + + +class BaseClass { + #count: number = 1; +} + +class OverrideModifierTest extends BaseClass { + override #count: number = 0; +} + +class StaticModifierTest { + static #count = 0; +} + +class AccessorModifierTest { + accessor #count = 0; +} + +class ReadonlyModifierTest { + readonly #count = 0; +} + +class AsyncModifierTest { + async #foo(){}; +} \ No newline at end of file diff --git a/es2panda/test/parser/ts/test-ts-private-class-element-5-expected.txt b/es2panda/test/parser/ts/test-ts-private-class-element-5-expected.txt index 30fee123fec8824fa61ef6a589ed5e048f334fa6..a88626448ed6c69636a6957c07ab7186082d0fe7 100644 --- a/es2panda/test/parser/ts/test-ts-private-class-element-5-expected.txt +++ b/es2panda/test/parser/ts/test-ts-private-class-element-5-expected.txt @@ -102,48 +102,9 @@ { "type": "ClassProperty", "key": { - "type": "TSPrivateIdentifier", - "key": { - "type": "Identifier", - "name": "value", - "loc": { - "start": { - "line": 18, - "column": 4 - }, - "end": { - "line": 18, - "column": 9 - } - } - }, - "value": { - "type": "NumberLiteral", - "value": 0, - "loc": { - "start": { - "line": 18, - "column": 20 - }, - "end": { - "line": 18, - "column": 21 - } - } - }, - "typeAnnotation": { - "type": "TSNumberKeyword", - "loc": { - "start": { - "line": 18, - "column": 11 - }, - "end": { - "line": 18, - "column": 17 - } - } - }, + "type": "PrivateIdentifier", + "prefix": "#", + "name": "value", "loc": { "start": { "line": 18, @@ -202,21 +163,9 @@ { "type": "MethodDefinition", "key": { - "type": "TSPrivateIdentifier", - "key": { - "type": "Identifier", - "name": "add", - "loc": { - "start": { - "line": 19, - "column": 4 - }, - "end": { - "line": 19, - "column": 7 - } - } - }, + "type": "PrivateIdentifier", + "prefix": "#", + "name": "add", "loc": { "start": { "line": 19, @@ -265,21 +214,9 @@ } }, "property": { - "type": "TSPrivateIdentifier", - "key": { - "type": "Identifier", - "name": "value", - "loc": { - "start": { - "line": 20, - "column": 11 - }, - "end": { - "line": 20, - "column": 16 - } - } - }, + "type": "PrivateIdentifier", + "prefix": "#", + "name": "value", "loc": { "start": { "line": 20, @@ -439,21 +376,9 @@ } }, "property": { - "type": "TSPrivateIdentifier", - "key": { - "type": "Identifier", - "name": "add", - "loc": { - "start": { - "line": 23, - "column": 11 - }, - "end": { - "line": 23, - "column": 14 - } - } - }, + "type": "PrivateIdentifier", + "prefix": "#", + "name": "add", "loc": { "start": { "line": 23, @@ -616,21 +541,9 @@ } }, "property": { - "type": "TSPrivateIdentifier", - "key": { - "type": "Identifier", - "name": "value", - "loc": { - "start": { - "line": 26, - "column": 17 - }, - "end": { - "line": 26, - "column": 22 - } - } - }, + "type": "PrivateIdentifier", + "prefix": "#", + "name": "value", "loc": { "start": { "line": 26, @@ -729,48 +642,9 @@ { "type": "ClassProperty", "key": { - "type": "TSPrivateIdentifier", - "key": { - "type": "Identifier", - "name": "message", - "loc": { - "start": { - "line": 29, - "column": 11 - }, - "end": { - "line": 29, - "column": 18 - } - } - }, - "value": { - "type": "StringLiteral", - "value": "hello", - "loc": { - "start": { - "line": 29, - "column": 29 - }, - "end": { - "line": 29, - "column": 36 - } - } - }, - "typeAnnotation": { - "type": "TSStringKeyword", - "loc": { - "start": { - "line": 29, - "column": 20 - }, - "end": { - "line": 29, - "column": 26 - } - } - }, + "type": "PrivateIdentifier", + "prefix": "#", + "name": "message", "loc": { "start": { "line": 29, @@ -829,21 +703,9 @@ { "type": "MethodDefinition", "key": { - "type": "TSPrivateIdentifier", - "key": { - "type": "Identifier", - "name": "say", - "loc": { - "start": { - "line": 30, - "column": 11 - }, - "end": { - "line": 30, - "column": 14 - } - } - }, + "type": "PrivateIdentifier", + "prefix": "#", + "name": "say", "loc": { "start": { "line": 30, @@ -889,21 +751,9 @@ } }, "property": { - "type": "TSPrivateIdentifier", - "key": { - "type": "Identifier", - "name": "message", - "loc": { - "start": { - "line": 31, - "column": 18 - }, - "end": { - "line": 31, - "column": 25 - } - } - }, + "type": "PrivateIdentifier", + "prefix": "#", + "name": "message", "loc": { "start": { "line": 31, @@ -1055,21 +905,9 @@ } }, "property": { - "type": "TSPrivateIdentifier", - "key": { - "type": "Identifier", - "name": "say", - "loc": { - "start": { - "line": 34, - "column": 17 - }, - "end": { - "line": 34, - "column": 20 - } - } - }, + "type": "PrivateIdentifier", + "prefix": "#", + "name": "say", "loc": { "start": { "line": 34, @@ -1181,21 +1019,9 @@ { "type": "MethodDefinition", "key": { - "type": "TSPrivateIdentifier", - "key": { - "type": "Identifier", - "name": "data", - "loc": { - "start": { - "line": 37, - "column": 8 - }, - "end": { - "line": 37, - "column": 12 - } - } - }, + "type": "PrivateIdentifier", + "prefix": "#", + "name": "data", "loc": { "start": { "line": 37, @@ -1241,21 +1067,9 @@ } }, "property": { - "type": "TSPrivateIdentifier", - "key": { - "type": "Identifier", - "name": "value", - "loc": { - "start": { - "line": 38, - "column": 18 - }, - "end": { - "line": 38, - "column": 23 - } - } - }, + "type": "PrivateIdentifier", + "prefix": "#", + "name": "value", "loc": { "start": { "line": 38, @@ -1341,21 +1155,9 @@ { "type": "MethodDefinition", "key": { - "type": "TSPrivateIdentifier", - "key": { - "type": "Identifier", - "name": "data", - "loc": { - "start": { - "line": 40, - "column": 8 - }, - "end": { - "line": 40, - "column": 12 - } - } - }, + "type": "PrivateIdentifier", + "prefix": "#", + "name": "data", "loc": { "start": { "line": 40, @@ -1432,21 +1234,9 @@ } }, "property": { - "type": "TSPrivateIdentifier", - "key": { - "type": "Identifier", - "name": "value", - "loc": { - "start": { - "line": 41, - "column": 11 - }, - "end": { - "line": 41, - "column": 16 - } - } - }, + "type": "PrivateIdentifier", + "prefix": "#", + "name": "value", "loc": { "start": { "line": 41, @@ -1604,21 +1394,9 @@ } }, "property": { - "type": "TSPrivateIdentifier", - "key": { - "type": "Identifier", - "name": "data", - "loc": { - "start": { - "line": 44, - "column": 18 - }, - "end": { - "line": 44, - "column": 22 - } - } - }, + "type": "PrivateIdentifier", + "prefix": "#", + "name": "data", "loc": { "start": { "line": 44, @@ -1782,21 +1560,9 @@ } }, "property": { - "type": "TSPrivateIdentifier", - "key": { - "type": "Identifier", - "name": "data", - "loc": { - "start": { - "line": 47, - "column": 11 - }, - "end": { - "line": 47, - "column": 15 - } - } - }, + "type": "PrivateIdentifier", + "prefix": "#", + "name": "data", "loc": { "start": { "line": 47, @@ -1907,21 +1673,9 @@ { "type": "MethodDefinition", "key": { - "type": "TSPrivateIdentifier", - "key": { - "type": "Identifier", - "name": "msg", - "loc": { - "start": { - "line": 50, - "column": 15 - }, - "end": { - "line": 50, - "column": 18 - } - } - }, + "type": "PrivateIdentifier", + "prefix": "#", + "name": "msg", "loc": { "start": { "line": 50, @@ -1967,21 +1721,9 @@ } }, "property": { - "type": "TSPrivateIdentifier", - "key": { - "type": "Identifier", - "name": "message", - "loc": { - "start": { - "line": 51, - "column": 18 - }, - "end": { - "line": 51, - "column": 25 - } - } - }, + "type": "PrivateIdentifier", + "prefix": "#", + "name": "message", "loc": { "start": { "line": 51, @@ -2067,21 +1809,9 @@ { "type": "MethodDefinition", "key": { - "type": "TSPrivateIdentifier", - "key": { - "type": "Identifier", - "name": "msg", - "loc": { - "start": { - "line": 54, - "column": 15 - }, - "end": { - "line": 54, - "column": 18 - } - } - }, + "type": "PrivateIdentifier", + "prefix": "#", + "name": "msg", "loc": { "start": { "line": 54, @@ -2158,21 +1888,9 @@ } }, "property": { - "type": "TSPrivateIdentifier", - "key": { - "type": "Identifier", - "name": "message", - "loc": { - "start": { - "line": 55, - "column": 11 - }, - "end": { - "line": 55, - "column": 18 - } - } - }, + "type": "PrivateIdentifier", + "prefix": "#", + "name": "message", "loc": { "start": { "line": 55, @@ -2361,21 +2079,9 @@ } }, "property": { - "type": "TSPrivateIdentifier", - "key": { - "type": "Identifier", - "name": "msg", - "loc": { - "start": { - "line": 59, - "column": 11 - }, - "end": { - "line": 59, - "column": 14 - } - } - }, + "type": "PrivateIdentifier", + "prefix": "#", + "name": "msg", "loc": { "start": { "line": 59, @@ -2533,21 +2239,9 @@ } }, "property": { - "type": "TSPrivateIdentifier", - "key": { - "type": "Identifier", - "name": "msg", - "loc": { - "start": { - "line": 62, - "column": 18 - }, - "end": { - "line": 62, - "column": 21 - } - } - }, + "type": "PrivateIdentifier", + "prefix": "#", + "name": "msg", "loc": { "start": { "line": 62, diff --git a/es2panda/test/parser/ts/test-ts-private-class-element-6-expected.txt b/es2panda/test/parser/ts/test-ts-private-class-element-6-expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..e7e7978f8698fc812180b5ddc93116ec8bf33d67 --- /dev/null +++ b/es2panda/test/parser/ts/test-ts-private-class-element-6-expected.txt @@ -0,0 +1 @@ +SyntaxError: An accessibility modifier cannot be used with a private identifier. [test-ts-private-class-element-6.ts:18:10] diff --git a/es2panda/test/parser/ts/test-ts-private-class-element-6.ts b/es2panda/test/parser/ts/test-ts-private-class-element-6.ts new file mode 100644 index 0000000000000000000000000000000000000000..cb4b3f7ff0d02622054bcaa283b4d08a16477e66 --- /dev/null +++ b/es2panda/test/parser/ts/test-ts-private-class-element-6.ts @@ -0,0 +1,19 @@ +/* + * 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. + */ + + +class PublicModifierTest { + public #count: number = 0; +} \ No newline at end of file diff --git a/es2panda/test/parser/ts/test-ts-private-class-element-7-expected.txt b/es2panda/test/parser/ts/test-ts-private-class-element-7-expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..3bd0f059fb5f951eb2b887b8599fb8a7a2acc7be --- /dev/null +++ b/es2panda/test/parser/ts/test-ts-private-class-element-7-expected.txt @@ -0,0 +1 @@ +SyntaxError: An accessibility modifier cannot be used with a private identifier. [test-ts-private-class-element-7.ts:18:11] diff --git a/es2panda/test/parser/ts/test-ts-private-class-element-7.ts b/es2panda/test/parser/ts/test-ts-private-class-element-7.ts new file mode 100644 index 0000000000000000000000000000000000000000..7119d13dc82b6af0f04b375d5391fbfda538169a --- /dev/null +++ b/es2panda/test/parser/ts/test-ts-private-class-element-7.ts @@ -0,0 +1,19 @@ +/* + * 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. + */ + + +class PrivateModifierTest { + private #count: number = 0; +} \ No newline at end of file diff --git a/es2panda/test/parser/ts/test-ts-private-class-element-8-expected.txt b/es2panda/test/parser/ts/test-ts-private-class-element-8-expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..0f98d57f2913d6ae15510443d51d2145604d1d10 --- /dev/null +++ b/es2panda/test/parser/ts/test-ts-private-class-element-8-expected.txt @@ -0,0 +1 @@ +SyntaxError: An accessibility modifier cannot be used with a private identifier. [test-ts-private-class-element-8.ts:18:13] diff --git a/es2panda/test/parser/ts/test-ts-private-class-element-8.ts b/es2panda/test/parser/ts/test-ts-private-class-element-8.ts new file mode 100644 index 0000000000000000000000000000000000000000..5e984b3f5764ab249d8e875175c9f9dc27dddb0b --- /dev/null +++ b/es2panda/test/parser/ts/test-ts-private-class-element-8.ts @@ -0,0 +1,19 @@ +/* + * 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. + */ + + +class ProtectedModifierTest { + protected #count: number = 0; +} \ No newline at end of file diff --git a/es2panda/test/parser/ts/test-ts-private-class-element-9-expected.txt b/es2panda/test/parser/ts/test-ts-private-class-element-9-expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..fb94581e5e8ae5140670aacd9ad42eb2ba5c85ff --- /dev/null +++ b/es2panda/test/parser/ts/test-ts-private-class-element-9-expected.txt @@ -0,0 +1 @@ +SyntaxError: ';' expected. [test-ts-private-class-element-9.ts:18:10] diff --git a/es2panda/test/parser/ts/test-ts-private-class-element-9.ts b/es2panda/test/parser/ts/test-ts-private-class-element-9.ts new file mode 100644 index 0000000000000000000000000000000000000000..67980d8d28f9e1030d4a456b3ef2c35b4524e2a0 --- /dev/null +++ b/es2panda/test/parser/ts/test-ts-private-class-element-9.ts @@ -0,0 +1,19 @@ +/* + * 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. + */ + + +class ExportModifierTest { + export #count = 0; +} \ No newline at end of file diff --git a/es2panda/test/parser/ts/test_decorator9-expected.txt b/es2panda/test/parser/ts/test_decorator9-expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..099cf571ef92938a9052f75bc10c50e03d668664 --- /dev/null +++ b/es2panda/test/parser/ts/test_decorator9-expected.txt @@ -0,0 +1 @@ +SyntaxError: Decorators are not valid here. [test_decorator9.ts:20:5] diff --git a/es2panda/test/parser/ts/test_decorator9.ts b/es2panda/test/parser/ts/test_decorator9.ts new file mode 100644 index 0000000000000000000000000000000000000000..7d8667cf789945696e7f0e50ec7c4b37579f801e --- /dev/null +++ b/es2panda/test/parser/ts/test_decorator9.ts @@ -0,0 +1,24 @@ +/* + * 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. + */ + + +declare function dec(target: T): T; + +class A { + @dec + #foo = 1; + @dec + #bar(): void { } +} diff --git a/es2panda/test/parser/ts/transformed_cases/test-class-constructor4-transformed-expected.txt b/es2panda/test/parser/ts/transformed_cases/test-class-constructor4-transformed-expected.txt index 7756d14600c5c4afcb9021786a01fc054ad9e266..290a6bb0e545e46004fb7257e96519d6cb350b58 100644 --- a/es2panda/test/parser/ts/transformed_cases/test-class-constructor4-transformed-expected.txt +++ b/es2panda/test/parser/ts/transformed_cases/test-class-constructor4-transformed-expected.txt @@ -493,89 +493,6 @@ "column": 1 } } - }, - { - "type": "ExpressionStatement", - "expression": { - "type": "AssignmentExpression", - "operator": "=", - "left": { - "type": "MemberExpression", - "object": { - "type": "ThisExpression", - "loc": { - "start": { - "line": 1, - "column": 1 - }, - "end": { - "line": 1, - "column": 1 - } - } - }, - "property": { - "type": "Identifier", - "name": "###B#prop2#1", - "loc": { - "start": { - "line": 1, - "column": 1 - }, - "end": { - "line": 1, - "column": 1 - } - } - }, - "computed": false, - "optional": false, - "loc": { - "start": { - "line": 1, - "column": 1 - }, - "end": { - "line": 1, - "column": 1 - } - } - }, - "right": { - "type": "NumberLiteral", - "value": 2, - "loc": { - "start": { - "line": 21, - "column": 22 - }, - "end": { - "line": 21, - "column": 23 - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 1 - }, - "end": { - "line": 1, - "column": 1 - } - } - }, - "loc": { - "start": { - "line": 1, - "column": 1 - }, - "end": { - "line": 1, - "column": 1 - } - } } ], "loc": { @@ -688,8 +605,9 @@ { "type": "ClassProperty", "key": { - "type": "Identifier", - "name": "###B#prop2#1", + "type": "PrivateIdentifier", + "prefix": "#", + "name": "prop2", "loc": { "start": { "line": 21, diff --git a/es2panda/test/runner.py b/es2panda/test/runner.py index 80a3c985ed1470e21cdc8c10119c643e4310c688..96e3a35c74dcd7691e0ce33e9e9db3d867bbf526 100755 --- a/es2panda/test/runner.py +++ b/es2panda/test/runner.py @@ -1459,9 +1459,8 @@ class TypeExtractorWithAOTTest(Test): ld_library_path = runner.ld_library_path os.environ.setdefault("LD_LIBRARY_PATH", ld_library_path) aot_abc_cmd = [runner.ark_aot_compiler] - if self.with_running: - aot_abc_cmd.extend(["--aot-file=%s" % file_name]) - else: + aot_abc_cmd.extend(["--aot-file=%s" % file_name]) + if not self.with_running: aot_abc_cmd.extend(["--compiler-assert-types=true"]) aot_abc_cmd.extend(["--compiler-opt-type-lowering=false"]) aot_abc_cmd.extend([test_abc_name]) @@ -1480,10 +1479,10 @@ class TypeExtractorWithAOTTest(Test): if os.path.isfile(test_abc_name): os.remove(test_abc_name) - if os.path.isfile("aot_file.an"): - os.remove("aot_file.an") - if os.path.isfile(".ai"): - os.remove(".ai") + if os.path.isfile("%s.an" % (file_name)): + os.remove("%s.an" % (file_name)) + if os.path.isfile("%s.ai" % (file_name)): + os.remove("%s.ai" % (file_name)) return self diff --git a/es2panda/test/type_extractor/testcases/test-class-generic-type-expected.txt b/es2panda/test/type_extractor/testcases/test-class-generic-type-expected.txt index d82e2115d153edd598305f1c0170de949d8fcfbc..db1832984f80304df05c7b92b2517abf20740a24 100644 --- a/es2panda/test/type_extractor/testcases/test-class-generic-type-expected.txt +++ b/es2panda/test/type_extractor/testcases/test-class-generic-type-expected.txt @@ -93,7 +93,7 @@ slot _.func_main_0_-1 { index: 1 tag: 2 - val: 3 + val: 4 }, { index: 2 @@ -113,7 +113,7 @@ slot _.func_main_0_-1 { index: 5 tag: 2 - val: 9 + val: 13 }, { index: 6 @@ -133,7 +133,7 @@ slot _.func_main_0_-1 { index: 9 tag: 2 - val: 14 + val: 18 }, { index: 10 @@ -146,6 +146,28 @@ slot _.func_main_0_-1 val: _8 }, ------------------------------------ +slot _.instance_initializer_-1 +{ + index: 0 + tag: 0 + val: 2 +}, +{ + index: 1 + tag: 2 + val: -2 +}, +{ + index: 2 + tag: 0 + val: 24 +}, +{ + index: 3 + tag: 24 + val: _4 +}, +------------------------------------ slot _0 { index: 0 diff --git a/es2panda/test/type_extractor/testcases/test-class-with-static-field-expected.txt b/es2panda/test/type_extractor/testcases/test-class-with-static-field-expected.txt index a36449ba783fbd1202d3d0f922fce526d346b75f..e1772d34c6d765bc83071efd4bf6dc149c9176fd 100644 --- a/es2panda/test/type_extractor/testcases/test-class-with-static-field-expected.txt +++ b/es2panda/test/type_extractor/testcases/test-class-with-static-field-expected.txt @@ -31,7 +31,7 @@ slot _.func_main_0_-1 { index: 1 tag: 2 - val: 3 + val: 4 }, { index: 2 @@ -44,6 +44,28 @@ slot _.func_main_0_-1 val: _1 }, ------------------------------------ +slot _.instance_initializer_-1 +{ + index: 0 + tag: 0 + val: 2 +}, +{ + index: 1 + tag: 2 + val: -2 +}, +{ + index: 2 + tag: 0 + val: 24 +}, +{ + index: 3 + tag: 24 + val: _2 +}, +------------------------------------ slot _.static_initializer_-1 { index: 0 diff --git a/es2panda/test/type_extractor/testcases/test-function-with-this-expected.txt b/es2panda/test/type_extractor/testcases/test-function-with-this-expected.txt index ff02cec21a5e88e61d206936fe7a1c029014e4f2..18e83c6c62b30fcf702180e3e36256e18f8d2491 100644 --- a/es2panda/test/type_extractor/testcases/test-function-with-this-expected.txt +++ b/es2panda/test/type_extractor/testcases/test-function-with-this-expected.txt @@ -117,7 +117,7 @@ slot _.func_main_0_-1 { index: 1 tag: 2 - val: 1 + val: 0 }, { index: 2 @@ -137,7 +137,7 @@ slot _.func_main_0_-1 { index: 5 tag: 2 - val: 5 + val: 3 }, { index: 6 @@ -157,7 +157,7 @@ slot _.func_main_0_-1 { index: 9 tag: 2 - val: 12 + val: 7 }, { index: 10 diff --git a/es2panda/util/helpers.cpp b/es2panda/util/helpers.cpp index 2a2ad9b4432cb8b5a8c996e345dfc5330cf3da88..241f4a837a06078e5607e442287dc1ca0b1fadbd 100644 --- a/es2panda/util/helpers.cpp +++ b/es2panda/util/helpers.cpp @@ -594,7 +594,12 @@ bool Helpers::IsChild(const ir::AstNode *parent, const ir::AstNode *child) bool Helpers::IsObjectPropertyValue(const ArenaVector &properties, const ir::AstNode *ident) { for (const auto *prop : properties) { - if (prop->AsProperty()->Value() == ident) { + ASSERT(prop->IsProperty() || prop->IsSpreadElement()); + if (prop->IsProperty() && (prop->AsProperty()->Value() == ident)) { + return true; + } + + if (prop->IsSpreadElement() && (prop->AsSpreadElement()->Argument() == ident)) { return true; } } diff --git a/es2panda/util/patchFix.cpp b/es2panda/util/patchFix.cpp index 867ad9da221702faf00489ee678f25e7433f6fb2..998ac27a1eb943f3e51ebee139361139ba2d3869 100644 --- a/es2panda/util/patchFix.cpp +++ b/es2panda/util/patchFix.cpp @@ -84,13 +84,13 @@ void PatchFix::ValidateModuleInfo(const std::string &recordName, std::vector &moduleBuffer) { auto it = originModuleInfo_->find(recordName); - if (it == originModuleInfo_->end()) { + if (!IsHotReload() && it == originModuleInfo_->end()) { std::cerr << "[Patch] Found new import/export expression in " << recordName << ", not supported!" << std::endl; patchError_ = true; return; } - if (Helpers::GetHashString(ConvertLiteralToString(moduleBuffer)) != it->second) { + if (!IsHotReload() && Helpers::GetHashString(ConvertLiteralToString(moduleBuffer)) != it->second) { std::cerr << "[Patch] Found import/export expression changed in " << recordName << ", not supported!" << std::endl; patchError_ = true; @@ -109,14 +109,14 @@ void PatchFix::DumpJsonContentRecInfo(const std::string &recordName, const std:: void PatchFix::ValidateJsonContentRecInfo(const std::string &recordName, const std::string &jsonFileContent) { auto it = originModuleInfo_->find(recordName); - if (it == originModuleInfo_->end()) { + if (!IsHotReload() && it == originModuleInfo_->end()) { std::cerr << "[Patch] Found new import/require json file expression in " << recordName << ", not supported!" << std::endl; patchError_ = true; return; } - if (Helpers::GetHashString(jsonFileContent) != it->second) { + if (!IsHotReload() && Helpers::GetHashString(jsonFileContent) != it->second) { std::cerr << "[Patch] Found imported/required json file content changed in " << recordName << ", not supported!" << std::endl; patchError_ = true; @@ -500,15 +500,10 @@ bool PatchFix::CompareClassHash(std::vector> for (size_t i = 0; i < hashList.size() - 1; ++i) { auto &className = hashList[i].first; auto classIter = classInfo.find(className); - if (classIter != classInfo.end() && classIter->second != hashList[i].second) { + if (!IsHotReload() && classIter != classInfo.end() && classIter->second != hashList[i].second) { if (IsColdFix()) { modifiedClassNames_.insert(className); continue; - } else if (IsHotReload()) { - std::cerr << "[Patch] Found class " << hashList[i].first << " changed, not supported! If " << - hashList[i].first << " is not changed and you are changing UI Component, please only " << - "change one Component at a time and make sure the Component is placed at the bottom " << - "of the file." << std::endl; } else { ASSERT(IsHotFix()); std::cerr << "[Patch] Found class " << hashList[i].first << " changed, not supported!" << std::endl; diff --git a/ets2panda/BUILD.gn b/ets2panda/BUILD.gn index 26f273d6689e4bf2e085648adfe5133f6f638e8a..39d208eac59a535c5ad6e5af38cd7e6b97998e98 100644 --- a/ets2panda/BUILD.gn +++ b/ets2panda/BUILD.gn @@ -158,6 +158,7 @@ libes2panda_sources = [ "compiler/lowering/ets/opAssignment.cpp", "compiler/lowering/ets/unionLowering.cpp", "compiler/lowering/phase.cpp", + "compiler/lowering/plugin_phase.cpp", "compiler/lowering/util.cpp", "es2panda.cpp", "ir/as/namedType.cpp", @@ -202,6 +203,7 @@ libes2panda_sources = [ "ir/expressions/assignmentExpression.cpp", "ir/expressions/awaitExpression.cpp", "ir/expressions/binaryExpression.cpp", + "ir/expressions/blockExpression.cpp", "ir/expressions/callExpression.cpp", "ir/expressions/chainExpression.cpp", "ir/expressions/classExpression.cpp", @@ -342,6 +344,7 @@ libes2panda_sources = [ "util/bitset.cpp", "util/declgenEts2Ts.cpp", "util/helpers.cpp", + "util/plugin.cpp", "util/ustring.cpp", "varbinder/ASBinder.cpp", "varbinder/ETSBinder.cpp", diff --git a/ets2panda/CMakeLists.txt b/ets2panda/CMakeLists.txt index 75f77a2394adfe82e21b0af131288fd05124d528..45978a26fe5155df778a079e034531ca39d33477 100644 --- a/ets2panda/CMakeLists.txt +++ b/ets2panda/CMakeLists.txt @@ -135,6 +135,7 @@ set(ES2PANDA_LIB_SRC compiler/function/generatorFunctionBuilder.cpp compiler/lowering/checkerPhase.cpp compiler/lowering/phase.cpp + compiler/lowering/plugin_phase.cpp compiler/lowering/util.cpp compiler/lowering/ets/generateDeclarations.cpp compiler/lowering/ets/opAssignment.cpp @@ -166,6 +167,7 @@ set(ES2PANDA_LIB_SRC ir/expressions/assignmentExpression.cpp ir/expressions/awaitExpression.cpp ir/expressions/binaryExpression.cpp + ir/expressions/blockExpression.cpp ir/expressions/callExpression.cpp ir/expressions/chainExpression.cpp ir/expressions/classExpression.cpp @@ -460,6 +462,7 @@ set(ES2PANDA_PUBLIC_SOURCES public/es2panda_lib.cpp util/generateBin.cpp util/options.cpp + util/plugin.cpp ) diff --git a/ets2panda/aot/main.cpp b/ets2panda/aot/main.cpp index cfe42af47936d3a7876724678d17f600fc9c23a7..cb4969c6ea059ec1b9a927ccca8752a3022238b2 100644 --- a/ets2panda/aot/main.cpp +++ b/ets2panda/aot/main.cpp @@ -22,9 +22,11 @@ #include "util/arktsconfig.h" #include "util/generateBin.h" #include "util/options.h" +#include "util/plugin.h" #include #include +#include namespace panda::es2panda::aot { using mem::MemConfig; @@ -106,6 +108,21 @@ static int CompileFromConfig(es2panda::Compiler &compiler, util::Options *option return overall_res; } +static std::optional> InitializePlugins(std::vector const &names) +{ + std::vector res; + for (auto &name : names) { + auto plugin = util::Plugin(util::StringView {name}); + if (!plugin.IsOk()) { + std::cerr << "Error: Failed to load plugin " << name << std::endl; + return {}; + } + plugin.Initialize(); + res.push_back(std::move(plugin)); + } + return {std::move(res)}; +} + static int Run(int argc, const char **argv) { auto options = std::make_unique(); @@ -118,7 +135,11 @@ static int Run(int argc, const char **argv) Logger::ComponentMask mask {}; mask.set(Logger::Component::ES2PANDA); Logger::InitializeStdLogging(Logger::LevelFromString(options->LogLevel()), mask); - es2panda::Compiler compiler(options->Extension(), options->ThreadCount()); + auto plugins_opt = InitializePlugins(options->CompilerOptions().plugins); + if (!plugins_opt.has_value()) { + return 1; + } + es2panda::Compiler compiler(options->Extension(), options->ThreadCount(), std::move(plugins_opt.value())); if (options->CompilerOptions().compilation_mode == CompilationMode::PROJECT) { return CompileFromConfig(compiler, options.get()); diff --git a/ets2panda/checker/ASchecker.cpp b/ets2panda/checker/ASchecker.cpp index 3f096b5ce26ac987146c0e414621a175f75b9eb4..36b7a658c53174deeeb1dcd704a747dbf664accb 100644 --- a/ets2panda/checker/ASchecker.cpp +++ b/ets2panda/checker/ASchecker.cpp @@ -26,6 +26,11 @@ bool ASChecker::StartChecker([[maybe_unused]] varbinder::VarBinder *varbinder, c std::cout << Program()->Dump() << std::endl; } + if (options.op_dump_ast_only_silent) { + Program()->DumpSilent(); + return false; + } + return false; } diff --git a/ets2panda/checker/ETSAnalyzer.cpp b/ets2panda/checker/ETSAnalyzer.cpp index ec729cf22942eacc61d2ca5a674062973d981b88..c26e12302dfa23fe17414210e3865726446af043 100644 --- a/ets2panda/checker/ETSAnalyzer.cpp +++ b/ets2panda/checker/ETSAnalyzer.cpp @@ -20,14 +20,6 @@ #include "checker/ETSchecker.h" #include "checker/ets/castingContext.h" #include "checker/ets/typeRelationContext.h" -#include "ir/base/catchClause.h" -#include "ir/base/classProperty.h" -#include "ir/base/classStaticBlock.h" -#include "ir/expressions/identifier.h" -#include "ir/expressions/objectExpression.h" -#include "ir/expressions/arrayExpression.h" -#include "ir/statements/blockStatement.h" -#include "ir/statements/returnStatement.h" #include "util/helpers.h" namespace panda::es2panda::checker { @@ -82,7 +74,7 @@ checker::Type *ETSAnalyzer::Check(ir::ClassDefinition *node) const checker::Type *ETSAnalyzer::Check(ir::ClassProperty *st) const { - ASSERT(st->Key()->IsIdentifier()); + ASSERT(st->Id() != nullptr); ETSChecker *checker = GetETSChecker(); if (st->TsType() != nullptr) { @@ -97,8 +89,7 @@ checker::Type *ETSAnalyzer::Check(ir::ClassProperty *st) const checker->AddStatus(checker::CheckerStatus::IN_STATIC_CONTEXT); } - st->SetTsType( - checker->CheckVariableDeclaration(st->Key()->AsIdentifier(), st->TypeAnnotation(), st->Value(), st->flags_)); + st->SetTsType(checker->CheckVariableDeclaration(st->Id(), st->TypeAnnotation(), st->Value(), st->Modifiers())); return st->TsType(); } @@ -126,27 +117,224 @@ checker::Type *ETSAnalyzer::Check([[maybe_unused]] ir::Decorator *st) const UNREACHABLE(); } -checker::Type *ETSAnalyzer::Check(ir::MetaProperty *expr) const +checker::Type *ETSAnalyzer::Check([[maybe_unused]] ir::MetaProperty *expr) const { - (void)expr; UNREACHABLE(); } +static void CheckExtensionIsShadowedInCurrentClassOrInterface(checker::ETSChecker *checker, + checker::ETSObjectType *obj_type, + ir::ScriptFunction *extension_func, + checker::Signature *signature) +{ + const auto method_name = extension_func->Id()->Name(); + // Only check if there are class and interfaces' instance methods which would shadow instance extension method + auto *const variable = obj_type->GetOwnProperty(method_name); + if (variable == nullptr) { + return; + } + + const auto *const func_type = variable->TsType()->AsETSFunctionType(); + for (auto *func_signature : func_type->CallSignatures()) { + signature->SetReturnType(func_signature->ReturnType()); + if (!checker->Relation()->IsIdenticalTo(signature, func_signature)) { + continue; + } + + checker->ReportWarning({"extension is shadowed by a instance member function '", func_type->Name(), + func_signature, "' in class ", obj_type->Name()}, + extension_func->Body()->Start()); + return; + } +} + +static void CheckExtensionIsShadowedByMethod(checker::ETSChecker *checker, checker::ETSObjectType *obj_type, + ir::ScriptFunction *extension_func, checker::Signature *signature) +{ + if (obj_type == nullptr) { + return; + } + + CheckExtensionIsShadowedInCurrentClassOrInterface(checker, obj_type, extension_func, signature); + + for (auto *interface : obj_type->Interfaces()) { + CheckExtensionIsShadowedByMethod(checker, interface, extension_func, signature); + } + + CheckExtensionIsShadowedByMethod(checker, obj_type->SuperType(), extension_func, signature); +} + +static void CheckExtensionMethod(checker::ETSChecker *checker, ir::ScriptFunction *extension_func, + ir::MethodDefinition *node) +{ + auto *const class_type = extension_func->Signature()->Params()[0]->TsType(); + if (!class_type->IsETSObjectType() || + (!class_type->AsETSObjectType()->HasObjectFlag(checker::ETSObjectFlags::CLASS) && + !class_type->AsETSObjectType()->HasObjectFlag(checker::ETSObjectFlags::INTERFACE))) { + checker->ThrowTypeError("Extension function can only defined for class and interface type.", node->Start()); + } + + checker->AddStatus(checker::CheckerStatus::IN_INSTANCE_EXTENSION_METHOD); + + checker::SignatureInfo *original_extension_sig_info = checker->Allocator()->New( + extension_func->Signature()->GetSignatureInfo(), checker->Allocator()); + original_extension_sig_info->min_arg_count -= 1; + original_extension_sig_info->params.erase(original_extension_sig_info->params.begin()); + checker::Signature *original_extension_sigature = checker->CreateSignature( + original_extension_sig_info, extension_func->Signature()->ReturnType(), extension_func); + + CheckExtensionIsShadowedByMethod(checker, class_type->AsETSObjectType(), extension_func, + original_extension_sigature); +} + +void DoBodyTypeChecking(ETSChecker *checker, ir::MethodDefinition *node, ir::ScriptFunction *script_func) +{ + if (script_func->HasBody() && (node->IsNative() || node->IsAbstract() || node->IsDeclare())) { + checker->ThrowTypeError("Native, Abstract and Declare methods cannot have body.", script_func->Body()->Start()); + } + + if (script_func->IsAsyncFunc()) { + auto *ret_type = static_cast(script_func->Signature()->ReturnType()); + if (ret_type->AssemblerName() != checker->GlobalBuiltinPromiseType()->AssemblerName()) { + checker->ThrowTypeError("Return type of async function must be 'Promise'.", script_func->Start()); + } + } else if (script_func->HasBody() && !script_func->IsExternal()) { + checker::ScopeContext scope_ctx(checker, script_func->Scope()); + checker::SavedCheckerContext saved_context(checker, checker->Context().Status(), + checker->Context().ContainingClass()); + checker->Context().SetContainingSignature(checker->GetSignatureFromMethodDefinition(node)); + + if (node->IsStatic() && !node->IsConstructor() && + !checker->Context().ContainingClass()->HasObjectFlag(checker::ETSObjectFlags::GLOBAL)) { + checker->AddStatus(checker::CheckerStatus::IN_STATIC_CONTEXT); + } + + if (node->IsConstructor()) { + checker->AddStatus(checker::CheckerStatus::IN_CONSTRUCTOR); + } + + if (node->IsExtensionMethod()) { + CheckExtensionMethod(checker, script_func, node); + } + + script_func->Body()->Check(checker); + + // In case of inferred function's return type set it forcedly to all return statements; + if (script_func->Signature()->HasSignatureFlag(checker::SignatureFlags::INFERRED_RETURN_TYPE) && + script_func->ReturnTypeAnnotation() == nullptr && script_func->Body() != nullptr && + script_func->Body()->IsStatement()) { + script_func->Body()->AsStatement()->SetReturnType(checker, script_func->Signature()->ReturnType()); + } + + checker->Context().SetContainingSignature(nullptr); + } +} + +void CheckGetterSetterTypeConstrains(ETSChecker *checker, ir::ScriptFunction *script_func) +{ + if (script_func->IsSetter() && (script_func->Signature()->ReturnType() != checker->GlobalBuiltinVoidType())) { + checker->ThrowTypeError("Setter must have void return type", script_func->Start()); + } + + if (script_func->IsGetter() && (script_func->Signature()->ReturnType() == checker->GlobalBuiltinVoidType())) { + checker->ThrowTypeError("Getter must return a value", script_func->Start()); + } +} + checker::Type *ETSAnalyzer::Check(ir::MethodDefinition *node) const { - (void)node; - UNREACHABLE(); + ETSChecker *checker = GetETSChecker(); + auto *script_func = node->Function(); + if (script_func->IsProxy()) { + return nullptr; + } + + // NOTE: aszilagyi. make it correctly check for open function not have body + if (!script_func->HasBody() && !(node->IsAbstract() || node->IsNative() || node->IsDeclare() || + checker->HasStatus(checker::CheckerStatus::IN_INTERFACE))) { + checker->ThrowTypeError("Only abstract or native methods can't have body.", script_func->Start()); + } + + if (script_func->ReturnTypeAnnotation() == nullptr && + (node->IsNative() || (node->IsDeclare() && !node->IsConstructor()))) { + checker->ThrowTypeError("Native and Declare methods should have explicit return type.", script_func->Start()); + } + + if (node->TsType() == nullptr) { + node->SetTsType(checker->BuildMethodSignature(node)); + } + + this->CheckMethodModifiers(node); + + if (node->IsNative() && script_func->ReturnTypeAnnotation() == nullptr) { + checker->ThrowTypeError("'Native' method should have explicit return type", script_func->Start()); + } + + if (node->IsNative() && (script_func->IsGetter() || script_func->IsSetter())) { + checker->ThrowTypeError("'Native' modifier is invalid for Accessors", script_func->Start()); + } + + DoBodyTypeChecking(checker, node, script_func); + CheckGetterSetterTypeConstrains(checker, script_func); + + checker->CheckOverride(node->TsType()->AsETSFunctionType()->FindSignature(node->Function())); + + for (auto *it : node->Overloads()) { + it->Check(checker); + } + + if (script_func->IsRethrowing()) { + checker->CheckRethrowingFunction(script_func); + } + + return node->TsType(); } -checker::Type *ETSAnalyzer::Check(ir::Property *expr) const +void ETSAnalyzer::CheckMethodModifiers(ir::MethodDefinition *node) const +{ + ETSChecker *checker = GetETSChecker(); + auto const not_valid_in_abstract = ir::ModifierFlags::NATIVE | ir::ModifierFlags::PRIVATE | + ir::ModifierFlags::OVERRIDE | ir::ModifierFlags::FINAL | + ir::ModifierFlags::STATIC; + + if (node->IsAbstract() && (node->flags_ & not_valid_in_abstract) != 0U) { + checker->ThrowTypeError( + "Invalid method modifier(s): an abstract method can't have private, override, static, final or native " + "modifier.", + node->Start()); + } + + if ((node->IsAbstract() || (!node->Function()->HasBody() && !node->IsNative() && !node->IsDeclare())) && + !(checker->HasStatus(checker::CheckerStatus::IN_ABSTRACT) || + checker->HasStatus(checker::CheckerStatus::IN_INTERFACE))) { + checker->ThrowTypeError("Non abstract class has abstract method.", node->Start()); + } + + auto const not_valid_in_final = ir::ModifierFlags::ABSTRACT | ir::ModifierFlags::STATIC | ir::ModifierFlags::NATIVE; + + if (node->IsFinal() && (node->flags_ & not_valid_in_final) != 0U) { + checker->ThrowTypeError( + "Invalid method modifier(s): a final method can't have abstract, static or native modifier.", + node->Start()); + } + + auto const not_valid_in_static = + ir::ModifierFlags::ABSTRACT | ir::ModifierFlags::FINAL | ir::ModifierFlags::OVERRIDE; + + if (node->IsStatic() && (node->flags_ & not_valid_in_static) != 0U) { + checker->ThrowTypeError( + "Invalid method modifier(s): a static method can't have abstract, final or override modifier.", + node->Start()); + } +} + +checker::Type *ETSAnalyzer::Check([[maybe_unused]] ir::Property *expr) const { - (void)expr; UNREACHABLE(); } -checker::Type *ETSAnalyzer::Check(ir::ScriptFunction *node) const +checker::Type *ETSAnalyzer::Check([[maybe_unused]] ir::ScriptFunction *node) const { - (void)node; UNREACHABLE(); } @@ -158,25 +346,23 @@ checker::Type *ETSAnalyzer::Check(ir::SpreadElement *expr) const checker::Type *ETSAnalyzer::Check(ir::TemplateElement *expr) const { - (void)expr; - UNREACHABLE(); + ETSChecker *checker = GetETSChecker(); + expr->SetTsType(checker->CreateETSStringLiteralType(expr->Raw())); + return expr->TsType(); } -checker::Type *ETSAnalyzer::Check(ir::TSIndexSignature *node) const +checker::Type *ETSAnalyzer::Check([[maybe_unused]] ir::TSIndexSignature *node) const { - (void)node; UNREACHABLE(); } -checker::Type *ETSAnalyzer::Check(ir::TSMethodSignature *node) const +checker::Type *ETSAnalyzer::Check([[maybe_unused]] ir::TSMethodSignature *node) const { - (void)node; UNREACHABLE(); } -checker::Type *ETSAnalyzer::Check(ir::TSPropertySignature *node) const +checker::Type *ETSAnalyzer::Check([[maybe_unused]] ir::TSPropertySignature *node) const { - (void)node; UNREACHABLE(); } @@ -372,49 +558,309 @@ checker::Type *ETSAnalyzer::Check(ir::AssignmentExpression *expr) const checker::Type *ETSAnalyzer::Check(ir::AwaitExpression *expr) const { - (void)expr; - UNREACHABLE(); + ETSChecker *checker = GetETSChecker(); + if (expr->TsType() != nullptr) { + return expr->TsType(); + } + + checker::Type *arg_type = expr->argument_->Check(checker); + // Check the argument type of await expression + if (!arg_type->IsETSObjectType() || + (arg_type->AsETSObjectType()->AssemblerName() != compiler::Signatures::BUILTIN_PROMISE)) { + checker->ThrowTypeError("'await' expressions require Promise object as argument.", expr->Argument()->Start()); + } + + expr->SetTsType(arg_type->AsETSObjectType()->TypeArguments().at(0)); + return expr->TsType(); } checker::Type *ETSAnalyzer::Check(ir::BinaryExpression *expr) const { - (void)expr; + ETSChecker *checker = GetETSChecker(); + if (expr->TsType() != nullptr) { + return expr->TsType(); + } + checker::Type *new_ts_type {nullptr}; + std::tie(new_ts_type, expr->operation_type_) = + checker->CheckBinaryOperator(expr->Left(), expr->Right(), expr, expr->OperatorType(), expr->Start()); + expr->SetTsType(new_ts_type); + return expr->TsType(); +} + +static checker::Type *InitAnonymousLambdaCallee(checker::ETSChecker *checker, ir::Expression *callee, + checker::Type *callee_type) +{ + auto *const arrow_func = callee->AsArrowFunctionExpression()->Function(); + auto orig_params = arrow_func->Params(); + auto *func_type = checker->Allocator()->New( + arrow_func->Scope()->AsFunctionScope()->ParamScope(), std::move(orig_params), nullptr, + arrow_func->ReturnTypeAnnotation(), ir::ScriptFunctionFlags::NONE); + auto *const func_iface = func_type->Check(checker); + checker->Relation()->SetNode(callee); + checker->Relation()->IsAssignableTo(callee_type, func_iface); + return func_iface; +} + +static checker::Signature *ResolveCallExtensionFunction(checker::ETSFunctionType *function_type, + checker::ETSChecker *checker, ir::CallExpression *expr) +{ + auto *member_expr = expr->Callee()->AsMemberExpression(); + expr->Arguments().insert(expr->Arguments().begin(), member_expr->Object()); + auto *signature = + checker->ResolveCallExpressionAndTrailingLambda(function_type->CallSignatures(), expr, expr->Start()); + if (!signature->Function()->IsExtensionMethod()) { + checker->ThrowTypeError({"Property '", member_expr->Property()->AsIdentifier()->Name(), + "' does not exist on type '", member_expr->ObjType()->Name(), "'"}, + member_expr->Property()->Start()); + } + expr->SetSignature(signature); + expr->SetCallee(member_expr->Property()); + member_expr->Property()->AsIdentifier()->SetParent(expr); + expr->Arguments()[0]->SetParent(expr); + checker->HandleUpdatedCallExpressionNode(expr); + // Set TsType for new Callee(original member expression's Object) + expr->Callee()->Check(checker); + return signature; +} + +static checker::Signature *ResolveCallForETSExtensionFuncHelperType(checker::ETSExtensionFuncHelperType *type, + checker::ETSChecker *checker, + ir::CallExpression *expr) +{ + checker::Signature *signature = checker->ResolveCallExpressionAndTrailingLambda( + type->ClassMethodType()->CallSignatures(), expr, expr->Start(), checker::TypeRelationFlag::NO_THROW); + + if (signature != nullptr) { + return signature; + } + + return ResolveCallExtensionFunction(type->ExtensionMethodType(), checker, expr); +} + +checker::Type *ETSAnalyzer::Check(ir::BlockExpression *st) const +{ + (void)st; UNREACHABLE(); } +ArenaVector &ChooseSignatures(checker::Type *callee_type, bool is_constructor_call, + bool is_functional_interface) +{ + if (is_constructor_call) { + return callee_type->AsETSObjectType()->ConstructSignatures(); + } + if (is_functional_interface) { + return callee_type->AsETSObjectType() + ->GetOwnProperty("invoke") + ->TsType() + ->AsETSFunctionType() + ->CallSignatures(); + } + return callee_type->AsETSFunctionType()->CallSignatures(); +} + +checker::ETSObjectType *ChooseCalleeObj(ETSChecker *checker, ir::CallExpression *expr, checker::Type *callee_type, + bool is_constructor_call) +{ + if (is_constructor_call) { + return callee_type->AsETSObjectType(); + } + if (expr->Callee()->IsIdentifier()) { + return checker->Context().ContainingClass(); + } + ASSERT(expr->Callee()->IsMemberExpression()); + return expr->Callee()->AsMemberExpression()->ObjType(); +} + +checker::Signature *ResolveSignature(ETSChecker *checker, ir::CallExpression *expr, checker::Type *callee_type, + bool is_constructor_call, bool is_functional_interface) +{ + bool extension_function_type = + expr->Callee()->IsMemberExpression() && checker->ExtensionETSFunctionType(callee_type); + + if (callee_type->IsETSExtensionFuncHelperType()) { + return ResolveCallForETSExtensionFuncHelperType(callee_type->AsETSExtensionFuncHelperType(), checker, expr); + } + if (extension_function_type) { + return ResolveCallExtensionFunction(callee_type->AsETSFunctionType(), checker, expr); + } + auto &signatures = ChooseSignatures(callee_type, is_constructor_call, is_functional_interface); + checker::Signature *signature = checker->ResolveCallExpressionAndTrailingLambda(signatures, expr, expr->Start()); + if (signature->Function()->IsExtensionMethod()) { + checker->ThrowTypeError({"No matching call signature"}, expr->Start()); + } + return signature; +} + +checker::Type *ETSAnalyzer::GetReturnType(ir::CallExpression *expr, checker::Type *callee_type) const +{ + ETSChecker *checker = GetETSChecker(); + bool is_constructor_call = expr->IsETSConstructorCall(); + bool is_functional_interface = callee_type->IsETSObjectType() && callee_type->AsETSObjectType()->HasObjectFlag( + checker::ETSObjectFlags::FUNCTIONAL_INTERFACE); + bool ets_extension_func_helper_type = callee_type->IsETSExtensionFuncHelperType(); + + if (expr->Callee()->IsArrowFunctionExpression()) { + callee_type = InitAnonymousLambdaCallee(checker, expr->Callee(), callee_type); + is_functional_interface = true; + } + + if (!is_functional_interface && !callee_type->IsETSFunctionType() && !is_constructor_call && + !ets_extension_func_helper_type) { + checker->ThrowTypeError("This expression is not callable.", expr->Start()); + } + + checker::Signature *signature = + ResolveSignature(checker, expr, callee_type, is_constructor_call, is_functional_interface); + + checker->CheckObjectLiteralArguments(signature, expr->Arguments()); + checker->AddUndefinedParamsForDefaultParams(signature, expr->Arguments(), checker); + + if (!is_functional_interface) { + checker::ETSObjectType *callee_obj = ChooseCalleeObj(checker, expr, callee_type, is_constructor_call); + checker->ValidateSignatureAccessibility(callee_obj, signature, expr->Start()); + } + + ASSERT(signature->Function() != nullptr); + if (signature->Function()->IsThrowing() || signature->Function()->IsRethrowing()) { + checker->CheckThrowingStatements(expr); + } + + if (signature->Function()->IsDynamic()) { + ASSERT(signature->Function()->IsDynamic()); + auto lang = signature->Function()->Language(); + expr->SetSignature(checker->ResolveDynamicCallExpression(expr->Callee(), signature->Params(), lang, false)); + } else { + ASSERT(!signature->Function()->IsDynamic()); + expr->SetSignature(signature); + } + + return signature->ReturnType(); +} + checker::Type *ETSAnalyzer::Check(ir::CallExpression *expr) const { - (void)expr; - UNREACHABLE(); + ETSChecker *checker = GetETSChecker(); + if (expr->TsType() != nullptr) { + return expr->TsType(); + } + auto *old_callee = expr->Callee(); + checker::Type *callee_type = expr->Callee()->Check(checker); + if (expr->Callee() != old_callee) { + // If it is a static invoke, the callee will be transformed from an identifier to a member expression + // Type check the callee again for member expression + callee_type = expr->Callee()->Check(checker); + } + if (!expr->IsOptional()) { + checker->CheckNonNullishType(callee_type, expr->Callee()->Start()); + } + checker::Type *return_type; + if (callee_type->IsETSDynamicType() && !callee_type->AsETSDynamicType()->HasDecl()) { + // Trailing lambda for js function call is not supported, check the correctness of `foo() {}` + checker->EnsureValidCurlyBrace(expr); + auto lang = callee_type->AsETSDynamicType()->Language(); + expr->SetSignature(checker->ResolveDynamicCallExpression(expr->Callee(), expr->Arguments(), lang, false)); + return_type = expr->Signature()->ReturnType(); + } else { + return_type = GetReturnType(expr, callee_type); + } + + if (expr->Signature()->RestVar() != nullptr) { + auto *const element_type = expr->Signature()->RestVar()->TsType()->AsETSArrayType()->ElementType(); + auto *const array_type = checker->CreateETSArrayType(element_type)->AsETSArrayType(); + checker->CreateBuiltinArraySignature(array_type, array_type->Rank()); + } + + if (expr->Signature()->HasSignatureFlag(checker::SignatureFlags::NEED_RETURN_TYPE)) { + expr->Signature()->OwnerVar()->Declaration()->Node()->Check(checker); + return_type = expr->Signature()->ReturnType(); + } + expr->SetOptionalType(return_type); + if (expr->IsOptional() && callee_type->IsNullishOrNullLike()) { + checker->Relation()->SetNode(expr); + return_type = checker->CreateOptionalResultType(return_type); + checker->Relation()->SetNode(nullptr); + } + expr->SetTsType(return_type); + return expr->TsType(); } -checker::Type *ETSAnalyzer::Check(ir::ChainExpression *expr) const +checker::Type *ETSAnalyzer::Check([[maybe_unused]] ir::ChainExpression *expr) const { - (void)expr; UNREACHABLE(); } -checker::Type *ETSAnalyzer::Check(ir::ClassExpression *expr) const +checker::Type *ETSAnalyzer::Check([[maybe_unused]] ir::ClassExpression *expr) const { - (void)expr; UNREACHABLE(); } checker::Type *ETSAnalyzer::Check(ir::ConditionalExpression *expr) const { - (void)expr; - UNREACHABLE(); + ETSChecker *checker = GetETSChecker(); + if (expr->TsType() != nullptr) { + return expr->TsType(); + } + + checker->CheckTruthinessOfType(expr->Test()); + + checker::Type *consequent_type = expr->consequent_->Check(checker); + checker::Type *alternate_type = expr->alternate_->Check(checker); + + auto *primitive_consequent_type = checker->ETSBuiltinTypeAsPrimitiveType(consequent_type); + auto *primitive_alter_type = checker->ETSBuiltinTypeAsPrimitiveType(alternate_type); + + if (primitive_consequent_type != nullptr && primitive_alter_type != nullptr) { + if (checker->IsTypeIdenticalTo(consequent_type, alternate_type)) { + expr->SetTsType(checker->GetNonConstantTypeFromPrimitiveType(consequent_type)); + } else if (checker->IsTypeIdenticalTo(primitive_consequent_type, primitive_alter_type)) { + checker->FlagExpressionWithUnboxing(expr->consequent_->TsType(), primitive_consequent_type, + expr->consequent_); + checker->FlagExpressionWithUnboxing(expr->alternate_->TsType(), primitive_alter_type, expr->alternate_); + + expr->SetTsType(primitive_consequent_type); + } else if (primitive_consequent_type->HasTypeFlag(checker::TypeFlag::ETS_NUMERIC) && + primitive_alter_type->HasTypeFlag(checker::TypeFlag::ETS_NUMERIC)) { + checker->FlagExpressionWithUnboxing(expr->consequent_->TsType(), primitive_consequent_type, + expr->consequent_); + checker->FlagExpressionWithUnboxing(expr->alternate_->TsType(), primitive_alter_type, expr->alternate_); + + expr->SetTsType( + checker->ApplyConditionalOperatorPromotion(checker, primitive_consequent_type, primitive_alter_type)); + } else { + checker->ThrowTypeError("Type error", expr->Range().start); + } + } else { + if (!(consequent_type->IsETSArrayType() || alternate_type->IsETSArrayType()) && + !(consequent_type->IsETSObjectType() && alternate_type->IsETSObjectType())) { + checker->ThrowTypeError("Type error", expr->Range().start); + } else { + checker->Relation()->SetNode(expr->consequent_); + auto builtin_conseq_type = checker->PrimitiveTypeAsETSBuiltinType(consequent_type); + auto builtin_alternate_type = checker->PrimitiveTypeAsETSBuiltinType(alternate_type); + + if (builtin_conseq_type == nullptr) { + builtin_conseq_type = consequent_type; + } + + if (builtin_alternate_type == nullptr) { + builtin_alternate_type = alternate_type; + } + + expr->SetTsType(checker->FindLeastUpperBound(builtin_conseq_type, builtin_alternate_type)); + } + } + + return expr->TsType(); } -checker::Type *ETSAnalyzer::Check(ir::DirectEvalExpression *expr) const +checker::Type *ETSAnalyzer::Check([[maybe_unused]] ir::DirectEvalExpression *expr) const { - (void)expr; UNREACHABLE(); } -checker::Type *ETSAnalyzer::Check(ir::FunctionExpression *expr) const +checker::Type *ETSAnalyzer::Check([[maybe_unused]] ir::FunctionExpression *expr) const { - (void)expr; UNREACHABLE(); } @@ -528,26 +974,47 @@ checker::Type *ETSAnalyzer::Check(ir::CharLiteral *expr) const checker::Type *ETSAnalyzer::Check(ir::NullLiteral *expr) const { - (void)expr; - UNREACHABLE(); + ETSChecker *checker = GetETSChecker(); + if (expr->TsType() == nullptr) { + expr->SetTsType(checker->GlobalETSNullType()); + } + return expr->TsType(); } checker::Type *ETSAnalyzer::Check(ir::NumberLiteral *expr) const { - (void)expr; - UNREACHABLE(); + ETSChecker *checker = GetETSChecker(); + if (expr->Number().IsInt()) { + expr->SetTsType(checker->CreateIntType(expr->Number().GetInt())); + return expr->TsType(); + } + + if (expr->Number().IsLong()) { + expr->SetTsType(checker->CreateLongType(expr->Number().GetLong())); + return expr->TsType(); + } + + if (expr->Number().IsFloat()) { + expr->SetTsType(checker->CreateFloatType(expr->Number().GetFloat())); + return expr->TsType(); + } + + expr->SetTsType(checker->CreateDoubleType(expr->Number().GetDouble())); + return expr->TsType(); } -checker::Type *ETSAnalyzer::Check(ir::RegExpLiteral *expr) const +checker::Type *ETSAnalyzer::Check([[maybe_unused]] ir::RegExpLiteral *expr) const { - (void)expr; UNREACHABLE(); } checker::Type *ETSAnalyzer::Check(ir::StringLiteral *expr) const { - (void)expr; - UNREACHABLE(); + ETSChecker *checker = GetETSChecker(); + if (expr->TsType() == nullptr) { + expr->SetTsType(checker->CreateETSStringLiteralType(expr->Str())); + } + return expr->TsType(); } checker::Type *ETSAnalyzer::Check(ir::UndefinedLiteral *expr) const @@ -557,51 +1024,123 @@ checker::Type *ETSAnalyzer::Check(ir::UndefinedLiteral *expr) const } // compile methods for MODULE-related nodes in alphabetical order -checker::Type *ETSAnalyzer::Check(ir::ExportAllDeclaration *st) const +checker::Type *ETSAnalyzer::Check([[maybe_unused]] ir::ExportAllDeclaration *st) const { - (void)st; UNREACHABLE(); } -checker::Type *ETSAnalyzer::Check(ir::ExportDefaultDeclaration *st) const +checker::Type *ETSAnalyzer::Check([[maybe_unused]] ir::ExportDefaultDeclaration *st) const { - (void)st; UNREACHABLE(); } -checker::Type *ETSAnalyzer::Check(ir::ExportNamedDeclaration *st) const +checker::Type *ETSAnalyzer::Check([[maybe_unused]] ir::ExportNamedDeclaration *st) const { - (void)st; UNREACHABLE(); } -checker::Type *ETSAnalyzer::Check(ir::ExportSpecifier *st) const +checker::Type *ETSAnalyzer::Check([[maybe_unused]] ir::ExportSpecifier *st) const { - (void)st; UNREACHABLE(); } checker::Type *ETSAnalyzer::Check(ir::ImportDeclaration *st) const { - (void)st; - UNREACHABLE(); + ETSChecker *checker = GetETSChecker(); + checker::Type *type = nullptr; + for (auto *spec : st->Specifiers()) { + if (spec->IsImportNamespaceSpecifier()) { + type = spec->AsImportNamespaceSpecifier()->Check(checker); + } + } + + return type; } -checker::Type *ETSAnalyzer::Check(ir::ImportDefaultSpecifier *st) const +checker::Type *ETSAnalyzer::Check([[maybe_unused]] ir::ImportDefaultSpecifier *st) const { - (void)st; UNREACHABLE(); } +checker::ETSObjectType *CreateSyntheticType(ETSChecker *checker, util::StringView const &synthetic_name, + checker::ETSObjectType *last_object_type, ir::Identifier *id) +{ + auto *synthetic_obj_type = checker->Allocator()->New( + checker->Allocator(), synthetic_name, synthetic_name, id, checker::ETSObjectFlags::NO_OPTS); + + auto *class_decl = checker->Allocator()->New(synthetic_name); + varbinder::LocalVariable *var = + checker->Allocator()->New(class_decl, varbinder::VariableFlags::CLASS); + var->SetTsType(synthetic_obj_type); + last_object_type->AddProperty(var); + synthetic_obj_type->SetEnclosingType(last_object_type); + return synthetic_obj_type; +} + checker::Type *ETSAnalyzer::Check(ir::ImportNamespaceSpecifier *st) const { - (void)st; - UNREACHABLE(); + ETSChecker *checker = GetETSChecker(); + if (st->Local()->Name().Empty()) { + return nullptr; + } + + if (st->Local()->AsIdentifier()->TsType() != nullptr) { + return st->Local()->TsType(); + } + + auto *import_decl = st->Parent()->AsETSImportDeclaration(); + auto import_path = import_decl->Source()->Str(); + + if (import_decl->IsPureDynamic()) { + auto *type = checker->GlobalBuiltinDynamicType(import_decl->Language()); + checker->SetrModuleObjectTsType(st->Local(), type); + return type; + } + + std::string package_name = + (import_decl->Module() == nullptr) ? import_path.Mutf8() : import_decl->Module()->Str().Mutf8(); + + std::replace(package_name.begin(), package_name.end(), '/', '.'); + util::UString package_path(package_name, checker->Allocator()); + std::vector synthetic_names = checker->GetNameForSynteticObjectType(package_path.View()); + + ASSERT(!synthetic_names.empty()); + + auto assembler_name = synthetic_names[0]; + if (import_decl->Module() != nullptr) { + assembler_name = util::UString(assembler_name.Mutf8().append(".").append(compiler::Signatures::ETS_GLOBAL), + checker->Allocator()) + .View(); + } + + auto *module_object_type = + checker->Allocator()->New(checker->Allocator(), synthetic_names[0], assembler_name, + st->Local()->AsIdentifier(), checker::ETSObjectFlags::CLASS); + + auto *root_decl = checker->Allocator()->New(synthetic_names[0]); + varbinder::LocalVariable *root_var = + checker->Allocator()->New(root_decl, varbinder::VariableFlags::NONE); + root_var->SetTsType(module_object_type); + + synthetic_names.erase(synthetic_names.begin()); + checker::ETSObjectType *last_object_type(module_object_type); + + for (const auto &synthetic_name : synthetic_names) { + last_object_type = CreateSyntheticType(checker, synthetic_name, last_object_type, st->Local()->AsIdentifier()); + } + + checker->SetPropertiesForModuleObject( + last_object_type, + (import_decl->Module() != nullptr) + ? util::UString(import_path.Mutf8() + import_decl->Module()->Str().Mutf8(), checker->Allocator()).View() + : import_path); + checker->SetrModuleObjectTsType(st->Local(), last_object_type); + + return module_object_type; } -checker::Type *ETSAnalyzer::Check(ir::ImportSpecifier *st) const +checker::Type *ETSAnalyzer::Check([[maybe_unused]] ir::ImportSpecifier *st) const { - (void)st; UNREACHABLE(); } // compile methods for STATEMENTS in alphabetical order @@ -625,74 +1164,182 @@ checker::Type *ETSAnalyzer::Check(ir::BreakStatement *st) const checker::Type *ETSAnalyzer::Check(ir::ClassDeclaration *st) const { - (void)st; - UNREACHABLE(); + ETSChecker *checker = GetETSChecker(); + st->Definition()->Check(checker); + return nullptr; } checker::Type *ETSAnalyzer::Check(ir::ContinueStatement *st) const { - (void)st; - UNREACHABLE(); + ETSChecker *checker = GetETSChecker(); + st->target_ = checker->FindJumpTarget(st->Type(), st, st->Ident()); + return nullptr; } -checker::Type *ETSAnalyzer::Check(ir::DebuggerStatement *st) const +checker::Type *ETSAnalyzer::Check([[maybe_unused]] ir::DebuggerStatement *st) const { - (void)st; UNREACHABLE(); } checker::Type *ETSAnalyzer::Check(ir::DoWhileStatement *st) const { - (void)st; - UNREACHABLE(); + ETSChecker *checker = GetETSChecker(); + checker::ScopeContext scope_ctx(checker, st->Scope()); + + checker->CheckTruthinessOfType(st->Test()); + st->Body()->Check(checker); + + return nullptr; } -checker::Type *ETSAnalyzer::Check(ir::EmptyStatement *st) const +checker::Type *ETSAnalyzer::Check([[maybe_unused]] ir::EmptyStatement *st) const { - (void)st; - UNREACHABLE(); + return nullptr; } checker::Type *ETSAnalyzer::Check(ir::ExpressionStatement *st) const { - (void)st; - UNREACHABLE(); + ETSChecker *checker = GetETSChecker(); + return st->GetExpression()->Check(checker); } -checker::Type *ETSAnalyzer::Check(ir::ForInStatement *st) const +checker::Type *ETSAnalyzer::Check([[maybe_unused]] ir::ForInStatement *st) const { - (void)st; UNREACHABLE(); } +// NOLINTBEGIN(modernize-avoid-c-arrays) +static constexpr char const INVALID_SOURCE_EXPR_TYPE[] = + "'For-of' statement source expression should be either a string or an array."; +static constexpr char const INVALID_CONST_ASSIGNMENT[] = "Cannot assign a value to a constant variable "; +static constexpr char const ITERATOR_TYPE_ABSENT[] = "Cannot obtain iterator type in 'for-of' statement."; +// NOLINTEND(modernize-avoid-c-arrays) + +checker::Type *GetIteratorType(ETSChecker *checker, checker::Type *elem_type, ir::AstNode *left) +{ + // Just to avoid extra nested level(s) + auto const get_iter_type = [checker, elem_type](ir::VariableDeclarator *const declarator) -> checker::Type * { + if (declarator->TsType() == nullptr) { + if (auto *resolved = checker->FindVariableInFunctionScope(declarator->Id()->AsIdentifier()->Name()); + resolved != nullptr) { + resolved->SetTsType(elem_type); + return elem_type; + } + } else { + return declarator->TsType(); + } + return nullptr; + }; + + checker::Type *iter_type = nullptr; + if (left->IsIdentifier()) { + if (auto *const variable = left->AsIdentifier()->Variable(); variable != nullptr) { + if (variable->Declaration()->IsConstDecl()) { + checker->ThrowTypeError({INVALID_CONST_ASSIGNMENT, variable->Name()}, + variable->Declaration()->Node()->Start()); + } + } + iter_type = left->AsIdentifier()->TsType(); + } else if (left->IsVariableDeclaration()) { + if (auto const &declarators = left->AsVariableDeclaration()->Declarators(); !declarators.empty()) { + iter_type = get_iter_type(declarators.front()); + } + } + + if (iter_type == nullptr) { + checker->ThrowTypeError(ITERATOR_TYPE_ABSENT, left->Start()); + } + return iter_type; +} + checker::Type *ETSAnalyzer::Check(ir::ForOfStatement *st) const { - (void)st; - UNREACHABLE(); + ETSChecker *checker = GetETSChecker(); + checker::ScopeContext scope_ctx(checker, st->Scope()); + + checker::Type *const expr_type = st->Right()->Check(checker); + checker::Type *elem_type; + + if (expr_type == nullptr || (!expr_type->IsETSArrayType() && !expr_type->IsETSStringType())) { + checker->ThrowTypeError(INVALID_SOURCE_EXPR_TYPE, st->Right()->Start()); + } else if (expr_type->IsETSStringType()) { + elem_type = checker->GetGlobalTypesHolder()->GlobalCharType(); + } else { + elem_type = expr_type->AsETSArrayType()->ElementType()->Instantiate(checker->Allocator(), checker->Relation(), + checker->GetGlobalTypesHolder()); + elem_type->RemoveTypeFlag(checker::TypeFlag::CONSTANT); + } + + st->Left()->Check(checker); + checker::Type *iter_type = GetIteratorType(checker, elem_type, st->Left()); + auto *const relation = checker->Relation(); + relation->SetFlags(checker::TypeRelationFlag::ASSIGNMENT_CONTEXT); + relation->SetNode(checker->AllocNode()); // Dummy node to avoid assertion! + + if (!relation->IsAssignableTo(elem_type, iter_type)) { + std::stringstream ss {}; + ss << "Source element type '"; + elem_type->ToString(ss); + ss << "' is not assignable to the loop iterator type '"; + iter_type->ToString(ss); + ss << "'."; + checker->ThrowTypeError(ss.str(), st->Start()); + } + + relation->SetNode(nullptr); + relation->SetFlags(checker::TypeRelationFlag::NONE); + + st->Body()->Check(checker); + + return nullptr; } checker::Type *ETSAnalyzer::Check(ir::ForUpdateStatement *st) const { - (void)st; - UNREACHABLE(); + ETSChecker *checker = GetETSChecker(); + checker::ScopeContext scope_ctx(checker, st->Scope()); + + if (st->Init() != nullptr) { + st->Init()->Check(checker); + } + + if (st->Test() != nullptr) { + checker->CheckTruthinessOfType(st->Test()); + } + + if (st->Update() != nullptr) { + st->Update()->Check(checker); + } + + st->Body()->Check(checker); + + return nullptr; } -checker::Type *ETSAnalyzer::Check(ir::FunctionDeclaration *st) const +checker::Type *ETSAnalyzer::Check([[maybe_unused]] ir::FunctionDeclaration *st) const { - (void)st; UNREACHABLE(); } checker::Type *ETSAnalyzer::Check(ir::IfStatement *st) const { - (void)st; - UNREACHABLE(); + ETSChecker *checker = GetETSChecker(); + checker->CheckTruthinessOfType(st->test_); + + st->consequent_->Check(checker); + + if (st->Alternate() != nullptr) { + st->alternate_->Check(checker); + } + + return nullptr; } checker::Type *ETSAnalyzer::Check(ir::LabelledStatement *st) const { - (void)st; - UNREACHABLE(); + ETSChecker *checker = GetETSChecker(); + st->body_->Check(checker); + return nullptr; } void CheckArgumentVoidType(checker::Type *&func_return_type, ETSChecker *checker, const std::string &name, @@ -831,7 +1478,6 @@ void ProcessReturnStatements(ETSChecker *checker, ir::ScriptFunction *containing "type(s).", st_argument->Start()); } - } else { checker->ThrowTypeError("Invalid return statement type(s).", st->Start()); } @@ -907,16 +1553,64 @@ checker::Type *ETSAnalyzer::Check(ir::ReturnStatement *st) const return nullptr; } -checker::Type *ETSAnalyzer::Check(ir::SwitchCaseStatement *st) const +checker::Type *ETSAnalyzer::Check([[maybe_unused]] ir::SwitchCaseStatement *st) const { - (void)st; UNREACHABLE(); } checker::Type *ETSAnalyzer::Check(ir::SwitchStatement *st) const { - (void)st; - UNREACHABLE(); + ETSChecker *checker = GetETSChecker(); + checker::ScopeContext scope_ctx(checker, st->scope_); + st->discriminant_->Check(checker); + checker::SavedTypeRelationFlagsContext saved_type_relation_flag_ctx(checker->Relation(), + checker::TypeRelationFlag::NONE); + // NOTE (user): check exhaustive Switch + checker->CheckSwitchDiscriminant(st->discriminant_); + auto *compared_expr_type = st->discriminant_->TsType(); + auto unboxed_disc_type = + (st->Discriminant()->GetBoxingUnboxingFlags() & ir::BoxingUnboxingFlags::UNBOXING_FLAG) != 0U + ? checker->ETSBuiltinTypeAsPrimitiveType(compared_expr_type) + : compared_expr_type; + + bool valid_case_type; + + for (auto *it : st->Cases()) { + if (it->Test() != nullptr) { + auto *case_type = it->Test()->Check(checker); + valid_case_type = true; + if (case_type->HasTypeFlag(checker::TypeFlag::CHAR)) { + valid_case_type = compared_expr_type->HasTypeFlag(checker::TypeFlag::ETS_INTEGRAL); + } else if (case_type->IsETSEnumType() && st->Discriminant()->TsType()->IsETSEnumType()) { + valid_case_type = + st->Discriminant()->TsType()->AsETSEnumType()->IsSameEnumType(case_type->AsETSEnumType()); + } else if (case_type->IsETSStringEnumType() && st->Discriminant()->TsType()->IsETSStringEnumType()) { + valid_case_type = st->Discriminant()->TsType()->AsETSStringEnumType()->IsSameEnumType( + case_type->AsETSStringEnumType()); + } else { + checker::AssignmentContext( + checker->Relation(), st->discriminant_, case_type, unboxed_disc_type, it->Test()->Start(), + {"Switch case type ", case_type, " is not comparable to discriminant type ", compared_expr_type}, + (compared_expr_type->IsETSObjectType() ? checker::TypeRelationFlag::NO_WIDENING + : checker::TypeRelationFlag::NO_UNBOXING) | + checker::TypeRelationFlag::NO_BOXING); + } + + if (!valid_case_type) { + checker->ThrowTypeError( + {"Switch case type ", case_type, " is not comparable to discriminant type ", compared_expr_type}, + it->Test()->Start()); + } + } + + for (auto *case_stmt : it->Consequent()) { + case_stmt->Check(checker); + } + } + + checker->CheckForSameSwitchCases(&st->cases_); + + return nullptr; } checker::Type *ETSAnalyzer::Check(ir::ThrowStatement *st) const @@ -949,9 +1643,8 @@ checker::Type *ETSAnalyzer::Check(ir::WhileStatement *st) const UNREACHABLE(); } // from ts folder -checker::Type *ETSAnalyzer::Check(ir::TSAnyKeyword *node) const +checker::Type *ETSAnalyzer::Check([[maybe_unused]] ir::TSAnyKeyword *node) const { - (void)node; UNREACHABLE(); } @@ -973,9 +1666,8 @@ checker::Type *ETSAnalyzer::Check(ir::TSBigintKeyword *node) const UNREACHABLE(); } -checker::Type *ETSAnalyzer::Check(ir::TSBooleanKeyword *node) const +checker::Type *ETSAnalyzer::Check([[maybe_unused]] ir::TSBooleanKeyword *node) const { - (void)node; UNREACHABLE(); } @@ -999,19 +1691,36 @@ checker::Type *ETSAnalyzer::Check(ir::TSConstructorType *node) const checker::Type *ETSAnalyzer::Check(ir::TSEnumDeclaration *st) const { - (void)st; - UNREACHABLE(); + ETSChecker *checker = GetETSChecker(); + varbinder::Variable *enum_var = st->Key()->Variable(); + ASSERT(enum_var != nullptr); + + if (enum_var->TsType() == nullptr) { + checker::Type *ets_enum_type; + if (auto *const item_init = st->Members().front()->AsTSEnumMember()->Init(); item_init->IsNumberLiteral()) { + ets_enum_type = checker->CreateETSEnumType(st); + } else if (item_init->IsStringLiteral()) { + ets_enum_type = checker->CreateETSStringEnumType(st); + } else { + checker->ThrowTypeError("Invalid enumeration value type.", st->Start()); + } + st->SetTsType(ets_enum_type); + ets_enum_type->SetVariable(enum_var); + enum_var->SetTsType(ets_enum_type); + } else if (st->TsType() == nullptr) { + st->SetTsType(enum_var->TsType()); + } + + return st->TsType(); } -checker::Type *ETSAnalyzer::Check(ir::TSEnumMember *st) const +checker::Type *ETSAnalyzer::Check([[maybe_unused]] ir::TSEnumMember *st) const { - (void)st; UNREACHABLE(); } -checker::Type *ETSAnalyzer::Check(ir::TSExternalModuleReference *expr) const +checker::Type *ETSAnalyzer::Check([[maybe_unused]] ir::TSExternalModuleReference *expr) const { - (void)expr; UNREACHABLE(); } @@ -1117,15 +1826,13 @@ checker::Type *ETSAnalyzer::Check(ir::TSNullKeyword *node) const UNREACHABLE(); } -checker::Type *ETSAnalyzer::Check(ir::TSNumberKeyword *node) const +checker::Type *ETSAnalyzer::Check([[maybe_unused]] ir::TSNumberKeyword *node) const { - (void)node; UNREACHABLE(); } -checker::Type *ETSAnalyzer::Check(ir::TSObjectKeyword *node) const +checker::Type *ETSAnalyzer::Check([[maybe_unused]] ir::TSObjectKeyword *node) const { - (void)node; UNREACHABLE(); } @@ -1147,9 +1854,8 @@ checker::Type *ETSAnalyzer::Check(ir::TSQualifiedName *expr) const UNREACHABLE(); } -checker::Type *ETSAnalyzer::Check(ir::TSStringKeyword *node) const +checker::Type *ETSAnalyzer::Check([[maybe_unused]] ir::TSStringKeyword *node) const { - (void)node; UNREACHABLE(); } @@ -1225,9 +1931,8 @@ checker::Type *ETSAnalyzer::Check(ir::TSTypeReference *node) const UNREACHABLE(); } -checker::Type *ETSAnalyzer::Check(ir::TSUndefinedKeyword *node) const +checker::Type *ETSAnalyzer::Check([[maybe_unused]] ir::TSUndefinedKeyword *node) const { - (void)node; UNREACHABLE(); } @@ -1237,15 +1942,13 @@ checker::Type *ETSAnalyzer::Check(ir::TSUnionType *node) const UNREACHABLE(); } -checker::Type *ETSAnalyzer::Check(ir::TSUnknownKeyword *node) const +checker::Type *ETSAnalyzer::Check([[maybe_unused]] ir::TSUnknownKeyword *node) const { - (void)node; UNREACHABLE(); } -checker::Type *ETSAnalyzer::Check(ir::TSVoidKeyword *node) const +checker::Type *ETSAnalyzer::Check([[maybe_unused]] ir::TSVoidKeyword *node) const { - (void)node; UNREACHABLE(); } diff --git a/ets2panda/checker/ETSAnalyzer.h b/ets2panda/checker/ETSAnalyzer.h index de2b57cc58f1221ba182913a895318b90abe91fd..ba76d31adaced2bab7242650536707b4db6e1c2e 100644 --- a/ets2panda/checker/ETSAnalyzer.h +++ b/ets2panda/checker/ETSAnalyzer.h @@ -37,6 +37,8 @@ public: private: ETSChecker *GetETSChecker() const; + void CheckMethodModifiers(ir::MethodDefinition *node) const; + checker::Type *GetReturnType(ir::CallExpression *expr, checker::Type *callee_type) const; }; } // namespace panda::es2panda::checker diff --git a/ets2panda/checker/ETSchecker.cpp b/ets2panda/checker/ETSchecker.cpp index 4d5cfde2fe2dcda1a6456896e5cbbdc5425bd7a1..4144da1ef35b883dced383245d7f619cea334c73 100644 --- a/ets2panda/checker/ETSchecker.cpp +++ b/ets2panda/checker/ETSchecker.cpp @@ -77,6 +77,11 @@ bool ETSChecker::StartChecker([[maybe_unused]] varbinder::VarBinder *varbinder, std::cout << Program()->Dump() << std::endl; } + if (options.op_dump_ast_only_silent) { + Program()->DumpSilent(); + return false; + } + if (options.parse_only) { return false; } diff --git a/ets2panda/checker/ETSchecker.h b/ets2panda/checker/ETSchecker.h index 756489ee872a2156d4fadd46a59b9bb5feaf14b7..0a35bc556a69d48ce367f9ae596ee7d2b0347680 100644 --- a/ets2panda/checker/ETSchecker.h +++ b/ets2panda/checker/ETSchecker.h @@ -124,6 +124,10 @@ public: Type *CheckTypeCached(ir::Expression *expr) override; void ResolveStructuredTypeMembers([[maybe_unused]] Type *type) override {} Type *GetTypeOfVariable([[maybe_unused]] varbinder::Variable *var) override; + bool IsETSChecker() override + { + return true; + } // Object ETSObjectType *BuildClassProperties(ir::ClassDefinition *class_def); @@ -257,7 +261,7 @@ public: bool TypeInference(Signature *signature, const ArenaVector &arguments, TypeRelationFlag flags = TypeRelationFlag::NONE); bool CheckLambdaAssignable(ir::Expression *param, ir::ScriptFunction *lambda); - bool IsCompatibleTypeArgument(Type *type_param, Type *type_argument); + bool IsCompatibleTypeArgument(Type *type_param, Type *type_argument, const Substitution *substitution); Substitution *NewSubstitution() { return Allocator()->New(Allocator()->Adapter()); @@ -266,8 +270,13 @@ public: { return Allocator()->New(*src); } + ArenaUnorderedSet *NewInstantiatedTypeParamsSet() + { + return Allocator()->New>(Allocator()->Adapter()); + } void EnhanceSubstitutionForType(const ArenaVector &type_params, Type *param_type, Type *argument_type, - Substitution *substitution); + Substitution *substitution, + ArenaUnorderedSet *instantiated_type_params); Signature *ValidateSignature(Signature *signature, const ir::TSTypeParameterInstantiation *type_arguments, const ArenaVector &arguments, const lexer::SourcePosition &pos, TypeRelationFlag initial_flags, const std::vector &arg_type_inference_required); @@ -280,11 +289,9 @@ public: const ArenaVector &arguments, const std::vector &arg_type_inference_required); Signature *ChooseMostSpecificSignature(ArenaVector &signatures, - const ArenaVector &arguments, const std::vector &arg_type_inference_required, const lexer::SourcePosition &pos, size_t arguments_size = ULONG_MAX); Signature *ChooseMostSpecificProxySignature(ArenaVector &signatures, - const ArenaVector &arguments, const std::vector &arg_type_inference_required, const lexer::SourcePosition &pos, size_t arguments_size); Signature *ResolveCallExpression(ArenaVector &signatures, @@ -397,6 +404,8 @@ public: bool IsNullLikeOrVoidExpression(const ir::Expression *expr) const; bool IsConstantExpression(ir::Expression *expr, Type *type); void ValidateUnaryOperatorOperand(varbinder::Variable *variable); + bool TestUnionType(Type *type, TypeFlag test); + bool CheckPossibilityPromotion(Type *left, Type *right, TypeFlag test); std::tuple ApplyBinaryOperatorPromotion(Type *left, Type *right, TypeFlag test, bool do_promotion = true); checker::Type *ApplyConditionalOperatorPromotion(checker::ETSChecker *checker, checker::Type *unboxed_l, @@ -470,6 +479,8 @@ public: bool CheckRethrowingParams(const ir::AstNode *ancestor_function, const ir::AstNode *node); void CheckThrowingStatements(ir::AstNode *node); bool CheckThrowingPlacement(ir::AstNode *node, const ir::AstNode *ancestor_function); + void CheckNumberOfTypeArguments(Type *type, ir::TSTypeParameterDeclaration *type_param_decl, + ir::TSTypeParameterInstantiation *type_args, const lexer::SourcePosition &pos); ir::BlockStatement *FindFinalizerOfTryStatement(ir::AstNode *start_from, const ir::AstNode *p); void CheckRethrowingFunction(ir::ScriptFunction *func); ETSObjectType *GetRelevantArgumentedTypeFromChild(ETSObjectType *child, ETSObjectType *target); @@ -543,6 +554,16 @@ private: using MethodBuilder = std::function *, ArenaVector *, Type **)>; + std::pair GetTargetIdentifierAndType(ir::Identifier *ident); + void ThrowError(ir::Identifier *ident); + void CheckEtsFunctionType(ir::Identifier *ident, ir::Identifier const *id, ir::TypeNode const *annotation); + void NotResolvedError(ir::Identifier *ident); + void ValidateCallExpressionIdentifier(ir::Identifier *ident, Type *type); + void ValidateNewClassInstanceIdentifier(ir::Identifier *ident, varbinder::Variable *resolved); + void ValidateMemberIdentifier(ir::Identifier *ident, varbinder::Variable *resolved, Type *type); + void ValidatePropertyOrDeclaratorIdentifier(ir::Identifier *ident, varbinder::Variable *resolved); + void ValidateAssignmentIdentifier(ir::Identifier *ident, varbinder::Variable *resolved, Type *type); + bool ValidateBinaryExpressionIdentifier(ir::Identifier *ident, Type *type); void BuildClass(util::StringView name, const ClassBuilder &builder); template std::conditional_t CreateClassInitializer( @@ -580,7 +601,14 @@ private: } ArenaVector CreateTypeForTypeParameters(ir::TSTypeParameterDeclaration *type_params); + Type *CreateTypeParameterType(ir::TSTypeParameter *param); + + using Type2TypeMap = std::unordered_map; + void CheckTypeParameterConstraint(ir::TSTypeParameter *param, Type2TypeMap &extends); + + void SetUpTypeParameterConstraint(ir::TSTypeParameter *param); + ETSObjectType *SetUpParameterType(ir::TSTypeParameter *param); ETSObjectType *CreateETSObjectTypeCheckBuiltins(util::StringView name, ir::AstNode *decl_node, ETSObjectFlags flags); void CheckProgram(parser::Program *program, bool run_analysis = false); @@ -595,6 +623,15 @@ private: typename TargetType::UType GetOperand(Type *type); ETSObjectType *AsETSObjectType(Type *(GlobalTypesHolder::*type_functor)()) const; + Signature *GetMostSpecificSignature(ArenaVector &compatible_signatures, + ArenaVector &proxy_signatures, + const ArenaVector &arguments, + std::vector &arg_type_inference_required, + const lexer::SourcePosition &pos, TypeRelationFlag resolve_flags); + std::pair, ArenaVector> CollectSignatures( + ArenaVector &signatures, const ir::TSTypeParameterInstantiation *type_arguments, + const ArenaVector &arguments, std::vector &arg_type_inference_required, + const lexer::SourcePosition &pos, TypeRelationFlag resolve_flags); // Trailing lambda void MoveTrailingBlockToEnclosingBlockStatement(ir::CallExpression *call_expr); diff --git a/ets2panda/checker/JSchecker.cpp b/ets2panda/checker/JSchecker.cpp index 5b72fec1c2e5b3e7fb44add5f59787d31a4f2457..a844137c2b0fc9cb747ab957909009e4d25a9060 100644 --- a/ets2panda/checker/JSchecker.cpp +++ b/ets2panda/checker/JSchecker.cpp @@ -29,6 +29,11 @@ bool JSChecker::StartChecker([[maybe_unused]] varbinder::VarBinder *varbinder, c std::cout << Program()->Dump() << std::endl; } + if (options.op_dump_ast_only_silent) { + Program()->DumpSilent(); + return false; + } + return !options.parse_only; } diff --git a/ets2panda/checker/TSAnalyzer.cpp b/ets2panda/checker/TSAnalyzer.cpp index d3e96e821ffd6bb149a2337acaa909ed200d7dca..49ebfde42f51c16072b57f36c933341a4aee7e70 100644 --- a/ets2panda/checker/TSAnalyzer.cpp +++ b/ets2panda/checker/TSAnalyzer.cpp @@ -17,7 +17,6 @@ #include "checker/TSchecker.h" #include "checker/ts/destructuringContext.h" -#include "util/helpers.h" namespace panda::es2panda::checker { @@ -78,27 +77,25 @@ checker::Type *TSAnalyzer::Check([[maybe_unused]] ir::Decorator *st) const UNREACHABLE(); } -checker::Type *TSAnalyzer::Check(ir::MetaProperty *expr) const +checker::Type *TSAnalyzer::Check([[maybe_unused]] ir::MetaProperty *expr) const { - (void)expr; - UNREACHABLE(); + TSChecker *checker = GetTSChecker(); + // NOTE: aszilagyi. + return checker->GlobalAnyType(); } -checker::Type *TSAnalyzer::Check(ir::MethodDefinition *node) const +checker::Type *TSAnalyzer::Check([[maybe_unused]] ir::MethodDefinition *node) const { - (void)node; UNREACHABLE(); } -checker::Type *TSAnalyzer::Check(ir::Property *expr) const +checker::Type *TSAnalyzer::Check([[maybe_unused]] ir::Property *expr) const { - (void)expr; UNREACHABLE(); } -checker::Type *TSAnalyzer::Check(ir::ScriptFunction *node) const +checker::Type *TSAnalyzer::Check([[maybe_unused]] ir::ScriptFunction *node) const { - (void)node; UNREACHABLE(); } @@ -108,28 +105,81 @@ checker::Type *TSAnalyzer::Check(ir::SpreadElement *expr) const UNREACHABLE(); } -checker::Type *TSAnalyzer::Check(ir::TemplateElement *expr) const +checker::Type *TSAnalyzer::Check([[maybe_unused]] ir::TemplateElement *expr) const { - (void)expr; UNREACHABLE(); } checker::Type *TSAnalyzer::Check(ir::TSIndexSignature *node) const { - (void)node; - UNREACHABLE(); + TSChecker *checker = GetTSChecker(); + if (node->TsType() != nullptr) { + return node->TsType(); + } + + const util::StringView ¶m_name = node->Param()->AsIdentifier()->Name(); + node->type_annotation_->Check(checker); + checker::Type *index_type = node->type_annotation_->GetType(checker); + checker::IndexInfo *info = + checker->Allocator()->New(index_type, param_name, node->Readonly(), node->Start()); + checker::ObjectDescriptor *desc = checker->Allocator()->New(checker->Allocator()); + checker::ObjectType *placeholder = checker->Allocator()->New(desc); + + if (node->Kind() == ir::TSIndexSignature::TSIndexSignatureKind::NUMBER) { + placeholder->Desc()->number_index_info = info; + } else { + placeholder->Desc()->string_index_info = info; + } + + node->SetTsType(placeholder); + return placeholder; } checker::Type *TSAnalyzer::Check(ir::TSMethodSignature *node) const { - (void)node; - UNREACHABLE(); + TSChecker *checker = GetTSChecker(); + if (node->Computed()) { + checker->CheckComputedPropertyName(node->Key()); + } + + checker::ScopeContext scope_ctx(checker, node->Scope()); + + auto *signature_info = checker->Allocator()->New(checker->Allocator()); + checker->CheckFunctionParameterDeclarations(node->Params(), signature_info); + + auto *call_signature = checker->Allocator()->New(signature_info, checker->GlobalAnyType()); + node->Variable()->SetTsType(checker->CreateFunctionTypeWithSignature(call_signature)); + + if (node->ReturnTypeAnnotation() == nullptr) { + checker->ThrowTypeError( + "Method signature, which lacks return-type annotation, implicitly has an 'any' return type.", + node->Start()); + } + + node->return_type_annotation_->Check(checker); + call_signature->SetReturnType(node->return_type_annotation_->GetType(checker)); + + return nullptr; } checker::Type *TSAnalyzer::Check(ir::TSPropertySignature *node) const { - (void)node; - UNREACHABLE(); + TSChecker *checker = GetTSChecker(); + if (node->TypeAnnotation() != nullptr) { + node->TypeAnnotation()->Check(checker); + } + + if (node->Computed()) { + checker->CheckComputedPropertyName(node->Key()); + } + + if (node->TypeAnnotation() != nullptr) { + node->Variable()->SetTsType(node->TypeAnnotation()->GetType(checker)); + return nullptr; + } + + checker->ThrowTypeError("Property implicitly has an 'any' type.", node->Start()); + return nullptr; } checker::Type *TSAnalyzer::Check(ir::TSSignatureDeclaration *node) const @@ -267,52 +317,163 @@ checker::Type *TSAnalyzer::Check(ir::AssignmentExpression *expr) const UNREACHABLE(); } -checker::Type *TSAnalyzer::Check(ir::AwaitExpression *expr) const +checker::Type *TSAnalyzer::Check([[maybe_unused]] ir::AwaitExpression *expr) const { - (void)expr; - UNREACHABLE(); + TSChecker *checker = GetTSChecker(); + // NOTE(aszilagyi) + return checker->GlobalAnyType(); } checker::Type *TSAnalyzer::Check(ir::BinaryExpression *expr) const { - (void)expr; + TSChecker *checker = GetTSChecker(); + auto *left_type = expr->Left()->Check(checker); + auto *right_type = expr->Right()->Check(checker); + + switch (expr->OperatorType()) { + case lexer::TokenType::PUNCTUATOR_MULTIPLY: + case lexer::TokenType::PUNCTUATOR_EXPONENTIATION: + case lexer::TokenType::PUNCTUATOR_DIVIDE: + case lexer::TokenType::PUNCTUATOR_MOD: + case lexer::TokenType::PUNCTUATOR_MINUS: + case lexer::TokenType::PUNCTUATOR_LEFT_SHIFT: + case lexer::TokenType::PUNCTUATOR_RIGHT_SHIFT: + case lexer::TokenType::PUNCTUATOR_UNSIGNED_RIGHT_SHIFT: + case lexer::TokenType::PUNCTUATOR_BITWISE_AND: + case lexer::TokenType::PUNCTUATOR_BITWISE_XOR: + case lexer::TokenType::PUNCTUATOR_BITWISE_OR: { + return checker->CheckBinaryOperator(left_type, right_type, expr->Left(), expr->Right(), expr, + expr->OperatorType()); + } + case lexer::TokenType::PUNCTUATOR_PLUS: { + return checker->CheckPlusOperator(left_type, right_type, expr->Left(), expr->Right(), expr, + expr->OperatorType()); + } + case lexer::TokenType::PUNCTUATOR_LESS_THAN: + case lexer::TokenType::PUNCTUATOR_GREATER_THAN: { + return checker->CheckCompareOperator(left_type, right_type, expr->Left(), expr->Right(), expr, + expr->OperatorType()); + } + case lexer::TokenType::PUNCTUATOR_EQUAL: + case lexer::TokenType::PUNCTUATOR_NOT_EQUAL: + case lexer::TokenType::PUNCTUATOR_STRICT_EQUAL: + case lexer::TokenType::PUNCTUATOR_NOT_STRICT_EQUAL: { + if (checker->IsTypeEqualityComparableTo(left_type, right_type) || + checker->IsTypeEqualityComparableTo(right_type, left_type)) { + return checker->GlobalBooleanType(); + } + + checker->ThrowBinaryLikeError(expr->OperatorType(), left_type, right_type, expr->Start()); + } + case lexer::TokenType::KEYW_INSTANCEOF: { + return checker->CheckInstanceofExpression(left_type, right_type, expr->Right(), expr); + } + case lexer::TokenType::KEYW_IN: { + return checker->CheckInExpression(left_type, right_type, expr->Left(), expr->Right(), expr); + } + case lexer::TokenType::PUNCTUATOR_LOGICAL_AND: { + return checker->CheckAndOperator(left_type, right_type, expr->Left()); + } + case lexer::TokenType::PUNCTUATOR_LOGICAL_OR: { + return checker->CheckOrOperator(left_type, right_type, expr->Left()); + } + case lexer::TokenType::PUNCTUATOR_NULLISH_COALESCING: { + // NOTE: Csaba Repasi. Implement checker for nullish coalescing + return checker->GlobalAnyType(); + } + case lexer::TokenType::PUNCTUATOR_SUBSTITUTION: { + checker->CheckAssignmentOperator(expr->OperatorType(), expr->Left(), left_type, right_type); + return right_type; + } + default: { + UNREACHABLE(); + break; + } + } + + return nullptr; +} + +checker::Type *TSAnalyzer::Check(ir::BlockExpression *st) const +{ + (void)st; UNREACHABLE(); } checker::Type *TSAnalyzer::Check(ir::CallExpression *expr) const { - (void)expr; - UNREACHABLE(); + TSChecker *checker = GetTSChecker(); + checker::Type *callee_type = expr->callee_->Check(checker); + + // NOTE: aszilagyi. handle optional chain + if (callee_type->IsObjectType()) { + checker::ObjectType *callee_obj = callee_type->AsObjectType(); + return checker->ResolveCallOrNewExpression(callee_obj->CallSignatures(), expr->Arguments(), expr->Start()); + } + + checker->ThrowTypeError("This expression is not callable.", expr->Start()); + return nullptr; } checker::Type *TSAnalyzer::Check(ir::ChainExpression *expr) const { - (void)expr; - UNREACHABLE(); + TSChecker *checker = GetTSChecker(); + return expr->expression_->Check(checker); } -checker::Type *TSAnalyzer::Check(ir::ClassExpression *expr) const +checker::Type *TSAnalyzer::Check([[maybe_unused]] ir::ClassExpression *expr) const { - (void)expr; UNREACHABLE(); } checker::Type *TSAnalyzer::Check(ir::ConditionalExpression *expr) const { - (void)expr; - UNREACHABLE(); + TSChecker *checker = GetTSChecker(); + checker::Type *test_type = expr->Test()->Check(checker); + + checker->CheckTruthinessOfType(test_type, expr->Test()->Start()); + checker->CheckTestingKnownTruthyCallableOrAwaitableType(expr->Test(), test_type, expr->consequent_); + + checker::Type *consequent_type = expr->consequent_->Check(checker); + checker::Type *alternate_type = expr->alternate_->Check(checker); + + return checker->CreateUnionType({consequent_type, alternate_type}); } -checker::Type *TSAnalyzer::Check(ir::DirectEvalExpression *expr) const +checker::Type *TSAnalyzer::Check([[maybe_unused]] ir::DirectEvalExpression *expr) const { - (void)expr; UNREACHABLE(); } checker::Type *TSAnalyzer::Check(ir::FunctionExpression *expr) const { - (void)expr; - UNREACHABLE(); + TSChecker *checker = GetTSChecker(); + varbinder::Variable *func_var = nullptr; + + if (expr->Function()->Parent()->Parent() != nullptr && + expr->Function()->Parent()->Parent()->IsVariableDeclarator() && + expr->Function()->Parent()->Parent()->AsVariableDeclarator()->Id()->IsIdentifier()) { + func_var = expr->Function()->Parent()->Parent()->AsVariableDeclarator()->Id()->AsIdentifier()->Variable(); + } + + checker::ScopeContext scope_ctx(checker, expr->Function()->Scope()); + + auto *signature_info = checker->Allocator()->New(checker->Allocator()); + checker->CheckFunctionParameterDeclarations(expr->Function()->Params(), signature_info); + + auto *signature = checker->Allocator()->New( + signature_info, checker->GlobalResolvingReturnType(), expr->Function()); + checker::Type *func_type = checker->CreateFunctionTypeWithSignature(signature); + + if (func_var != nullptr && func_var->TsType() == nullptr) { + func_var->SetTsType(func_type); + } + + signature->SetReturnType(checker->HandleFunctionReturn(expr->Function())); + + expr->Function()->Body()->Check(checker); + + return func_type; } checker::Type *TSAnalyzer::Check(ir::Identifier *expr) const @@ -423,28 +584,44 @@ checker::Type *TSAnalyzer::Check(ir::CharLiteral *expr) const UNREACHABLE(); } -checker::Type *TSAnalyzer::Check(ir::NullLiteral *expr) const +checker::Type *TSAnalyzer::Check([[maybe_unused]] ir::NullLiteral *expr) const { - (void)expr; - UNREACHABLE(); + TSChecker *checker = GetTSChecker(); + return checker->GlobalNullType(); } checker::Type *TSAnalyzer::Check(ir::NumberLiteral *expr) const { - (void)expr; - UNREACHABLE(); + TSChecker *checker = GetTSChecker(); + auto search = checker->NumberLiteralMap().find(expr->Number().GetDouble()); + if (search != checker->NumberLiteralMap().end()) { + return search->second; + } + + auto *new_num_literal_type = checker->Allocator()->New(expr->Number().GetDouble()); + checker->NumberLiteralMap().insert({expr->Number().GetDouble(), new_num_literal_type}); + return new_num_literal_type; } -checker::Type *TSAnalyzer::Check(ir::RegExpLiteral *expr) const +checker::Type *TSAnalyzer::Check([[maybe_unused]] ir::RegExpLiteral *expr) const { - (void)expr; - UNREACHABLE(); + TSChecker *checker = GetTSChecker(); + // NOTE: aszilagyi + return checker->GlobalAnyType(); } checker::Type *TSAnalyzer::Check(ir::StringLiteral *expr) const { - (void)expr; - UNREACHABLE(); + TSChecker *checker = GetTSChecker(); + auto search = checker->StringLiteralMap().find(expr->Str()); + if (search != checker->StringLiteralMap().end()) { + return search->second; + } + + auto *new_str_literal_type = checker->Allocator()->New(expr->Str()); + checker->StringLiteralMap().insert({expr->Str(), new_str_literal_type}); + + return new_str_literal_type; } checker::Type *TSAnalyzer::Check(ir::UndefinedLiteral *expr) const @@ -454,51 +631,43 @@ checker::Type *TSAnalyzer::Check(ir::UndefinedLiteral *expr) const } // compile methods for MODULE-related nodes in alphabetical order -checker::Type *TSAnalyzer::Check(ir::ExportAllDeclaration *st) const +checker::Type *TSAnalyzer::Check([[maybe_unused]] ir::ExportAllDeclaration *st) const { - (void)st; UNREACHABLE(); } -checker::Type *TSAnalyzer::Check(ir::ExportDefaultDeclaration *st) const +checker::Type *TSAnalyzer::Check([[maybe_unused]] ir::ExportDefaultDeclaration *st) const { - (void)st; UNREACHABLE(); } -checker::Type *TSAnalyzer::Check(ir::ExportNamedDeclaration *st) const +checker::Type *TSAnalyzer::Check([[maybe_unused]] ir::ExportNamedDeclaration *st) const { - (void)st; UNREACHABLE(); } -checker::Type *TSAnalyzer::Check(ir::ExportSpecifier *st) const +checker::Type *TSAnalyzer::Check([[maybe_unused]] ir::ExportSpecifier *st) const { - (void)st; UNREACHABLE(); } -checker::Type *TSAnalyzer::Check(ir::ImportDeclaration *st) const +checker::Type *TSAnalyzer::Check([[maybe_unused]] ir::ImportDeclaration *st) const { - (void)st; UNREACHABLE(); } -checker::Type *TSAnalyzer::Check(ir::ImportDefaultSpecifier *st) const +checker::Type *TSAnalyzer::Check([[maybe_unused]] ir::ImportDefaultSpecifier *st) const { - (void)st; UNREACHABLE(); } -checker::Type *TSAnalyzer::Check(ir::ImportNamespaceSpecifier *st) const +checker::Type *TSAnalyzer::Check([[maybe_unused]] ir::ImportNamespaceSpecifier *st) const { - (void)st; UNREACHABLE(); } -checker::Type *TSAnalyzer::Check(ir::ImportSpecifier *st) const +checker::Type *TSAnalyzer::Check([[maybe_unused]] ir::ImportSpecifier *st) const { - (void)st; UNREACHABLE(); } // compile methods for STATEMENTS in alphabetical order @@ -520,9 +689,8 @@ checker::Type *TSAnalyzer::Check(ir::BreakStatement *st) const UNREACHABLE(); } -checker::Type *TSAnalyzer::Check(ir::ClassDeclaration *st) const +checker::Type *TSAnalyzer::Check([[maybe_unused]] ir::ClassDeclaration *st) const { - (void)st; UNREACHABLE(); } @@ -532,63 +700,107 @@ checker::Type *TSAnalyzer::Check(ir::ContinueStatement *st) const UNREACHABLE(); } -checker::Type *TSAnalyzer::Check(ir::DebuggerStatement *st) const +checker::Type *TSAnalyzer::Check([[maybe_unused]] ir::DebuggerStatement *st) const { - (void)st; UNREACHABLE(); } checker::Type *TSAnalyzer::Check(ir::DoWhileStatement *st) const { - (void)st; - UNREACHABLE(); + TSChecker *checker = GetTSChecker(); + checker::ScopeContext scope_ctx(checker, st->Scope()); + + checker::Type *test_type = st->Test()->Check(checker); + checker->CheckTruthinessOfType(test_type, st->Test()->Start()); + st->Body()->Check(checker); + + return nullptr; } -checker::Type *TSAnalyzer::Check(ir::EmptyStatement *st) const +checker::Type *TSAnalyzer::Check([[maybe_unused]] ir::EmptyStatement *st) const { - (void)st; - UNREACHABLE(); + return nullptr; } checker::Type *TSAnalyzer::Check(ir::ExpressionStatement *st) const { - (void)st; - UNREACHABLE(); + TSChecker *checker = GetTSChecker(); + return st->GetExpression()->Check(checker); } -checker::Type *TSAnalyzer::Check(ir::ForInStatement *st) const +checker::Type *TSAnalyzer::Check([[maybe_unused]] ir::ForInStatement *st) const { - (void)st; UNREACHABLE(); } -checker::Type *TSAnalyzer::Check(ir::ForOfStatement *st) const +checker::Type *TSAnalyzer::Check([[maybe_unused]] ir::ForOfStatement *st) const { - (void)st; UNREACHABLE(); } checker::Type *TSAnalyzer::Check(ir::ForUpdateStatement *st) const { - (void)st; - UNREACHABLE(); + TSChecker *checker = GetTSChecker(); + checker::ScopeContext scope_ctx(checker, st->Scope()); + + if (st->Init() != nullptr) { + st->Init()->Check(checker); + } + + if (st->Test() != nullptr) { + checker::Type *test_type = st->Test()->Check(checker); + checker->CheckTruthinessOfType(test_type, st->Start()); + } + + if (st->Update() != nullptr) { + st->Update()->Check(checker); + } + + st->Body()->Check(checker); + + return nullptr; } checker::Type *TSAnalyzer::Check(ir::FunctionDeclaration *st) const { - (void)st; - UNREACHABLE(); + TSChecker *checker = GetTSChecker(); + if (st->Function()->IsOverload()) { + return nullptr; + } + + const util::StringView &func_name = st->Function()->Id()->Name(); + auto result = checker->Scope()->Find(func_name); + ASSERT(result.variable); + + checker::ScopeContext scope_ctx(checker, st->Function()->Scope()); + + if (result.variable->TsType() == nullptr) { + checker->InferFunctionDeclarationType(result.variable->Declaration()->AsFunctionDecl(), result.variable); + } + + st->Function()->Body()->Check(checker); + + return nullptr; } checker::Type *TSAnalyzer::Check(ir::IfStatement *st) const { - (void)st; - UNREACHABLE(); + TSChecker *checker = GetTSChecker(); + checker::Type *test_type = st->test_->Check(checker); + checker->CheckTruthinessOfType(test_type, st->Start()); + checker->CheckTestingKnownTruthyCallableOrAwaitableType(st->test_, test_type, st->consequent_); + + st->consequent_->Check(checker); + + if (st->Alternate() != nullptr) { + st->alternate_->Check(checker); + } + + return nullptr; } -checker::Type *TSAnalyzer::Check(ir::LabelledStatement *st) const +checker::Type *TSAnalyzer::Check([[maybe_unused]] ir::LabelledStatement *st) const { - (void)st; UNREACHABLE(); } @@ -623,16 +835,43 @@ checker::Type *TSAnalyzer::Check(ir::ReturnStatement *st) const return nullptr; } -checker::Type *TSAnalyzer::Check(ir::SwitchCaseStatement *st) const +checker::Type *TSAnalyzer::Check([[maybe_unused]] ir::SwitchCaseStatement *st) const { - (void)st; UNREACHABLE(); } checker::Type *TSAnalyzer::Check(ir::SwitchStatement *st) const { - (void)st; - UNREACHABLE(); + TSChecker *checker = GetTSChecker(); + checker::ScopeContext scope_ctx(checker, st->Scope()); + + checker::Type *expr_type = st->discriminant_->Check(checker); + bool expr_is_literal = checker::TSChecker::IsLiteralType(expr_type); + + for (auto *it : st->Cases()) { + if (it->Test() != nullptr) { + checker::Type *case_type = it->Test()->Check(checker); + bool case_is_literal = checker::TSChecker::IsLiteralType(case_type); + checker::Type *compared_expr_type = expr_type; + + if (!case_is_literal || !expr_is_literal) { + case_type = case_is_literal ? checker->GetBaseTypeOfLiteralType(case_type) : case_type; + compared_expr_type = checker->GetBaseTypeOfLiteralType(expr_type); + } + + if (!checker->IsTypeEqualityComparableTo(compared_expr_type, case_type) && + !checker->IsTypeComparableTo(case_type, compared_expr_type)) { + checker->ThrowTypeError({"Type ", case_type, " is not comparable to type ", compared_expr_type}, + it->Test()->Start()); + } + } + + for (auto *case_stmt : it->Consequent()) { + case_stmt->Check(checker); + } + } + + return nullptr; } checker::Type *TSAnalyzer::Check(ir::ThrowStatement *st) const @@ -665,10 +904,9 @@ checker::Type *TSAnalyzer::Check(ir::WhileStatement *st) const UNREACHABLE(); } // from ts folder -checker::Type *TSAnalyzer::Check(ir::TSAnyKeyword *node) const +checker::Type *TSAnalyzer::Check([[maybe_unused]] ir::TSAnyKeyword *node) const { - (void)node; - UNREACHABLE(); + return nullptr; } checker::Type *TSAnalyzer::Check(ir::TSArrayType *node) const @@ -689,10 +927,9 @@ checker::Type *TSAnalyzer::Check(ir::TSBigintKeyword *node) const UNREACHABLE(); } -checker::Type *TSAnalyzer::Check(ir::TSBooleanKeyword *node) const +checker::Type *TSAnalyzer::Check([[maybe_unused]] ir::TSBooleanKeyword *node) const { - (void)node; - UNREACHABLE(); + return nullptr; } checker::Type *TSAnalyzer::Check(ir::TSClassImplements *expr) const @@ -713,21 +950,343 @@ checker::Type *TSAnalyzer::Check(ir::TSConstructorType *node) const UNREACHABLE(); } +static varbinder::EnumMemberResult EvaluateIdentifier(checker::TSChecker *checker, varbinder::EnumVariable *enum_var, + const ir::Identifier *expr) +{ + if (expr->Name() == "NaN") { + return std::nan(""); + } + if (expr->Name() == "Infinity") { + return std::numeric_limits::infinity(); + } + + varbinder::Variable *enum_member = expr->AsIdentifier()->Variable(); + + if (enum_member == nullptr) { + checker->ThrowTypeError({"Cannot find name ", expr->AsIdentifier()->Name()}, + enum_var->Declaration()->Node()->Start()); + } + + if (enum_member->IsEnumVariable()) { + varbinder::EnumVariable *expr_enum_var = enum_member->AsEnumVariable(); + if (std::holds_alternative(expr_enum_var->Value())) { + checker->ThrowTypeError( + "A member initializer in a enum declaration cannot reference members declared after it, " + "including " + "members defined in other enums.", + enum_var->Declaration()->Node()->Start()); + } + + return expr_enum_var->Value(); + } + + return false; +} + +static int32_t ToInt(double num) +{ + if (num >= std::numeric_limits::min() && num <= std::numeric_limits::max()) { + return static_cast(num); + } + + // NOTE (aszilagyi): Perform ECMA defined toInt conversion + + return 0; +} + +static uint32_t ToUInt(double num) +{ + if (num >= std::numeric_limits::min() && num <= std::numeric_limits::max()) { + return static_cast(num); + } + + // NOTE (aszilagyi): Perform ECMA defined toInt conversion + + return 0; +} + +varbinder::EnumMemberResult GetOperationResulForDouble(lexer::TokenType type, varbinder::EnumMemberResult left, + varbinder::EnumMemberResult right) +{ + switch (type) { + case lexer::TokenType::PUNCTUATOR_BITWISE_OR: { + return static_cast(ToUInt(std::get(left)) | ToUInt(std::get(right))); + } + case lexer::TokenType::PUNCTUATOR_BITWISE_AND: { + return static_cast(ToUInt(std::get(left)) & ToUInt(std::get(right))); + } + case lexer::TokenType::PUNCTUATOR_BITWISE_XOR: { + return static_cast(ToUInt(std::get(left)) ^ ToUInt(std::get(right))); + } + case lexer::TokenType::PUNCTUATOR_LEFT_SHIFT: { // NOLINTNEXTLINE(hicpp-signed-bitwise) + return static_cast(ToInt(std::get(left)) << ToUInt(std::get(right))); + } + case lexer::TokenType::PUNCTUATOR_RIGHT_SHIFT: { // NOLINTNEXTLINE(hicpp-signed-bitwise) + return static_cast(ToInt(std::get(left)) >> ToUInt(std::get(right))); + } + case lexer::TokenType::PUNCTUATOR_UNSIGNED_RIGHT_SHIFT: { + return static_cast(ToUInt(std::get(left)) >> ToUInt(std::get(right))); + } + case lexer::TokenType::PUNCTUATOR_PLUS: { + return std::get(left) + std::get(right); + } + case lexer::TokenType::PUNCTUATOR_MINUS: { + return std::get(left) - std::get(right); + } + case lexer::TokenType::PUNCTUATOR_MULTIPLY: { + return std::get(left) * std::get(right); + } + case lexer::TokenType::PUNCTUATOR_DIVIDE: { + return std::get(left) / std::get(right); + } + case lexer::TokenType::PUNCTUATOR_MOD: { + return std::fmod(std::get(left), std::get(right)); + } + case lexer::TokenType::PUNCTUATOR_EXPONENTIATION: { + return std::pow(std::get(left), std::get(right)); + } + default: { + return false; + } + } +} + +varbinder::EnumMemberResult TSAnalyzer::EvaluateBinaryExpression(checker::TSChecker *checker, + varbinder::EnumVariable *enum_var, + const ir::BinaryExpression *expr) const +{ + varbinder::EnumMemberResult left = EvaluateEnumMember(checker, enum_var, expr->AsBinaryExpression()->Left()); + varbinder::EnumMemberResult right = EvaluateEnumMember(checker, enum_var, expr->AsBinaryExpression()->Right()); + if (std::holds_alternative(left) && std::holds_alternative(right)) { + GetOperationResulForDouble(expr->AsBinaryExpression()->OperatorType(), left, right); + } + + if (std::holds_alternative(left) && std::holds_alternative(right) && + expr->AsBinaryExpression()->OperatorType() == lexer::TokenType::PUNCTUATOR_PLUS) { + std::stringstream ss; + ss << std::get(left) << std::get(right); + + util::UString res(ss.str(), checker->Allocator()); + return res.View(); + } + + return false; +} + +varbinder::EnumMemberResult TSAnalyzer::EvaluateUnaryExpression(checker::TSChecker *checker, + varbinder::EnumVariable *enum_var, + const ir::UnaryExpression *expr) const +{ + varbinder::EnumMemberResult value = EvaluateEnumMember(checker, enum_var, expr->Argument()); + if (!std::holds_alternative(value)) { + return false; + } + + switch (expr->OperatorType()) { + case lexer::TokenType::PUNCTUATOR_PLUS: { + return std::get(value); + } + case lexer::TokenType::PUNCTUATOR_MINUS: { + return -std::get(value); + } + case lexer::TokenType::PUNCTUATOR_TILDE: { + return static_cast(~ToInt(std::get(value))); // NOLINT(hicpp-signed-bitwise) + } + default: { + break; + } + } + + return false; +} + +varbinder::EnumMemberResult TSAnalyzer::EvaluateEnumMember(checker::TSChecker *checker, + varbinder::EnumVariable *enum_var, + const ir::AstNode *expr) const +{ + switch (expr->Type()) { + case ir::AstNodeType::UNARY_EXPRESSION: { + return EvaluateUnaryExpression(checker, enum_var, expr->AsUnaryExpression()); + } + case ir::AstNodeType::BINARY_EXPRESSION: { + return EvaluateBinaryExpression(checker, enum_var, expr->AsBinaryExpression()); + } + case ir::AstNodeType::NUMBER_LITERAL: { + return expr->AsNumberLiteral()->Number().GetDouble(); + } + case ir::AstNodeType::STRING_LITERAL: { + return expr->AsStringLiteral()->Str(); + } + case ir::AstNodeType::IDENTIFIER: { + return EvaluateIdentifier(checker, enum_var, expr->AsIdentifier()); + } + case ir::AstNodeType::MEMBER_EXPRESSION: { + return EvaluateEnumMember(checker, enum_var, expr->AsMemberExpression()); + } + default: + break; + } + + return false; +} + +static bool IsComputedEnumMember(const ir::Expression *init) +{ + if (init->IsLiteral()) { + return !init->AsLiteral()->IsStringLiteral() && !init->AsLiteral()->IsNumberLiteral(); + } + + if (init->IsTemplateLiteral()) { + return !init->AsTemplateLiteral()->Quasis().empty(); + } + + return true; +} + +static void AddEnumValueDeclaration(checker::TSChecker *checker, double number, varbinder::EnumVariable *variable) +{ + variable->SetTsType(checker->GlobalNumberType()); + + util::StringView member_str = util::Helpers::ToStringView(checker->Allocator(), number); + + varbinder::LocalScope *enum_scope = checker->Scope()->AsLocalScope(); + varbinder::Variable *res = enum_scope->FindLocal(member_str, varbinder::ResolveBindingOptions::BINDINGS); + varbinder::EnumVariable *enum_var = nullptr; + + if (res == nullptr) { + auto *decl = checker->Allocator()->New(member_str); + decl->BindNode(variable->Declaration()->Node()); + enum_scope->AddDecl(checker->Allocator(), decl, ScriptExtension::TS); + res = enum_scope->FindLocal(member_str, varbinder::ResolveBindingOptions::BINDINGS); + ASSERT(res && res->IsEnumVariable()); + enum_var = res->AsEnumVariable(); + enum_var->AsEnumVariable()->SetBackReference(); + enum_var->SetTsType(checker->GlobalStringType()); + } else { + ASSERT(res->IsEnumVariable()); + enum_var = res->AsEnumVariable(); + auto *decl = checker->Allocator()->New(member_str); + decl->BindNode(variable->Declaration()->Node()); + enum_var->ResetDecl(decl); + } + + enum_var->SetValue(variable->Declaration()->Name()); +} + +// NOLINTBEGIN(modernize-avoid-c-arrays) +static constexpr char const INVALID_COMPUTED_WITH_STRING[] = + "Computed values are not permitted in an enum with string valued members."; +static constexpr char const INVALID_CONST_MEMBER[] = + "'const' enum member initializers can only contain literal values and other computed enum values."; +static constexpr char const INVALID_CONST_NAN[] = + "'const' enum member initializer was evaluated to disallowed value 'NaN'."; +static constexpr char const INVALID_CONST_INF[] = + "'const' enum member initializer was evaluated to a non-finite value."; +// NOLINTEND(modernize-avoid-c-arrays) + +void TSAnalyzer::InferEnumVariableType(varbinder::EnumVariable *variable, double *value, bool *init_next, + bool *is_literal_enum, bool is_const_enum) const +{ + TSChecker *checker = GetTSChecker(); + const ir::Expression *init = variable->Declaration()->Node()->AsTSEnumMember()->Init(); + + if (init == nullptr && *init_next) { + checker->ThrowTypeError("Enum member must have initializer.", variable->Declaration()->Node()->Start()); + } + + if (init == nullptr && !*init_next) { + variable->SetValue(++(*value)); + AddEnumValueDeclaration(checker, *value, variable); + return; + } + + ASSERT(init); + if (IsComputedEnumMember(init) && *is_literal_enum) { + checker->ThrowTypeError(INVALID_COMPUTED_WITH_STRING, init->Start()); + } + + varbinder::EnumMemberResult res = EvaluateEnumMember(checker, variable, init); + if (std::holds_alternative(res)) { + *is_literal_enum = true; + variable->SetTsType(checker->GlobalStringType()); + *init_next = true; + return; + } + + if (std::holds_alternative(res)) { + if (is_const_enum) { + checker->ThrowTypeError(INVALID_CONST_MEMBER, init->Start()); + } + + *init_next = true; + return; + } + + ASSERT(std::holds_alternative(res)); + variable->SetValue(res); + + *value = std::get(res); + if (is_const_enum && std::isnan(*value)) { + checker->ThrowTypeError(INVALID_CONST_NAN, init->Start()); + } + + if (is_const_enum && std::isinf(*value)) { + checker->ThrowTypeError(INVALID_CONST_INF, init->Start()); + } + + *init_next = false; + AddEnumValueDeclaration(checker, *value, variable); +} + +checker::Type *TSAnalyzer::InferType(checker::TSChecker *checker, bool is_const, ir::TSEnumDeclaration *st) const +{ + double value = -1.0; + + varbinder::LocalScope *enum_scope = checker->Scope()->AsLocalScope(); + + bool init_next = false; + bool is_literal_enum = false; + size_t locals_size = enum_scope->Decls().size(); + + for (size_t i = 0; i < locals_size; i++) { + const util::StringView ¤t_name = enum_scope->Decls()[i]->Name(); + varbinder::Variable *current_var = + enum_scope->FindLocal(current_name, varbinder::ResolveBindingOptions::BINDINGS); + ASSERT(current_var && current_var->IsEnumVariable()); + InferEnumVariableType(current_var->AsEnumVariable(), &value, &init_next, &is_literal_enum, is_const); + } + + checker::Type *enum_type = checker->Allocator()->New( + st->Key()->Name(), checker->Scope(), + is_literal_enum ? checker::EnumLiteralType::EnumLiteralTypeKind::LITERAL + : checker::EnumLiteralType::EnumLiteralTypeKind::NUMERIC); + + return enum_type; +} + checker::Type *TSAnalyzer::Check(ir::TSEnumDeclaration *st) const { - (void)st; - UNREACHABLE(); + TSChecker *checker = GetTSChecker(); + varbinder::Variable *enum_var = st->Key()->Variable(); + ASSERT(enum_var); + + if (enum_var->TsType() == nullptr) { + checker::ScopeContext scope_ctx(checker, st->Scope()); + checker::Type *enum_type = InferType(checker, st->IsConst(), st); + enum_type->SetVariable(enum_var); + enum_var->SetTsType(enum_type); + } + + return nullptr; } -checker::Type *TSAnalyzer::Check(ir::TSEnumMember *st) const +checker::Type *TSAnalyzer::Check([[maybe_unused]] ir::TSEnumMember *st) const { - (void)st; UNREACHABLE(); } -checker::Type *TSAnalyzer::Check(ir::TSExternalModuleReference *expr) const +checker::Type *TSAnalyzer::Check([[maybe_unused]] ir::TSExternalModuleReference *expr) const { - (void)expr; UNREACHABLE(); } @@ -833,15 +1392,13 @@ checker::Type *TSAnalyzer::Check(ir::TSNullKeyword *node) const UNREACHABLE(); } -checker::Type *TSAnalyzer::Check(ir::TSNumberKeyword *node) const +checker::Type *TSAnalyzer::Check([[maybe_unused]] ir::TSNumberKeyword *node) const { - (void)node; - UNREACHABLE(); + return nullptr; } -checker::Type *TSAnalyzer::Check(ir::TSObjectKeyword *node) const +checker::Type *TSAnalyzer::Check([[maybe_unused]] ir::TSObjectKeyword *node) const { - (void)node; UNREACHABLE(); } @@ -863,10 +1420,9 @@ checker::Type *TSAnalyzer::Check(ir::TSQualifiedName *expr) const UNREACHABLE(); } -checker::Type *TSAnalyzer::Check(ir::TSStringKeyword *node) const +checker::Type *TSAnalyzer::Check([[maybe_unused]] ir::TSStringKeyword *node) const { - (void)node; - UNREACHABLE(); + return nullptr; } checker::Type *TSAnalyzer::Check(ir::TSThisType *node) const @@ -941,10 +1497,9 @@ checker::Type *TSAnalyzer::Check(ir::TSTypeReference *node) const UNREACHABLE(); } -checker::Type *TSAnalyzer::Check(ir::TSUndefinedKeyword *node) const +checker::Type *TSAnalyzer::Check([[maybe_unused]] ir::TSUndefinedKeyword *node) const { - (void)node; - UNREACHABLE(); + return nullptr; } checker::Type *TSAnalyzer::Check(ir::TSUnionType *node) const @@ -953,16 +1508,14 @@ checker::Type *TSAnalyzer::Check(ir::TSUnionType *node) const UNREACHABLE(); } -checker::Type *TSAnalyzer::Check(ir::TSUnknownKeyword *node) const +checker::Type *TSAnalyzer::Check([[maybe_unused]] ir::TSUnknownKeyword *node) const { - (void)node; - UNREACHABLE(); + return nullptr; } -checker::Type *TSAnalyzer::Check(ir::TSVoidKeyword *node) const +checker::Type *TSAnalyzer::Check([[maybe_unused]] ir::TSVoidKeyword *node) const { - (void)node; - UNREACHABLE(); + return nullptr; } } // namespace panda::es2panda::checker diff --git a/ets2panda/checker/TSAnalyzer.h b/ets2panda/checker/TSAnalyzer.h index eb23fa2fc5c919df6b4b822e49429c8c3775b349..1f5979d31cba03f7f01fc980e5ccff15156645dc 100644 --- a/ets2panda/checker/TSAnalyzer.h +++ b/ets2panda/checker/TSAnalyzer.h @@ -16,6 +16,7 @@ #define ES2PANDA_CHECKER_TSANALYZER_H #include "checker/SemanticAnalyzer.h" +#include "util/helpers.h" namespace panda::es2panda::checker { @@ -36,6 +37,16 @@ public: private: TSChecker *GetTSChecker() const; + + varbinder::EnumMemberResult EvaluateBinaryExpression(checker::TSChecker *checker, varbinder::EnumVariable *enum_var, + const ir::BinaryExpression *expr) const; + varbinder::EnumMemberResult EvaluateEnumMember(checker::TSChecker *checker, varbinder::EnumVariable *enum_var, + const ir::AstNode *expr) const; + varbinder::EnumMemberResult EvaluateUnaryExpression(checker::TSChecker *checker, varbinder::EnumVariable *enum_var, + const ir::UnaryExpression *expr) const; + void InferEnumVariableType(varbinder::EnumVariable *variable, double *value, bool *init_next, bool *is_literal_enum, + bool is_const_enum) const; + checker::Type *InferType(checker::TSChecker *checker, bool is_const, ir::TSEnumDeclaration *st) const; }; } // namespace panda::es2panda::checker diff --git a/ets2panda/checker/TSchecker.cpp b/ets2panda/checker/TSchecker.cpp index 6a9eb3977e56b87d2790f40def815bfd80dab5bc..2a910c8424d01f29e07cccb22a769a70dbeede3d 100644 --- a/ets2panda/checker/TSchecker.cpp +++ b/ets2panda/checker/TSchecker.cpp @@ -29,6 +29,11 @@ bool TSChecker::StartChecker([[maybe_unused]] varbinder::VarBinder *varbinder, c std::cout << Program()->Dump() << std::endl; } + if (options.op_dump_ast_only_silent) { + Program()->DumpSilent(); + return false; + } + if (options.parse_only) { return false; } diff --git a/ets2panda/checker/checker.h b/ets2panda/checker/checker.h index 9927c78589745ccaa56b973dd6495904e8a761e0..d411772aa97bf49a0118b174df0a6989f0b94de0 100644 --- a/ets2panda/checker/checker.h +++ b/ets2panda/checker/checker.h @@ -70,7 +70,7 @@ using ArgRange = std::pair; class Checker { public: explicit Checker(); - ~Checker() = default; + virtual ~Checker() = default; NO_COPY_SEMANTIC(Checker); NO_MOVE_SEMANTIC(Checker); @@ -139,6 +139,11 @@ public: return type_stack_; } + virtual bool IsETSChecker() + { + return false; + } + ETSChecker *AsETSChecker() { return reinterpret_cast(this); diff --git a/ets2panda/checker/ets/arithmetic.cpp b/ets2panda/checker/ets/arithmetic.cpp index c78ac64ba9fe7e3ef3070a9a058a2e7686fb89d1..de5372293cab0bdba6bb9bf061670bda96bc32d1 100644 --- a/ets2panda/checker/ets/arithmetic.cpp +++ b/ets2panda/checker/ets/arithmetic.cpp @@ -139,6 +139,10 @@ checker::Type *ETSChecker::CheckBinaryOperatorMulDivMod(ir::Expression *left, ir FlagExpressionWithUnboxing(left_type, unboxed_l, left); FlagExpressionWithUnboxing(right_type, unboxed_r, right); + if (left_type->IsETSUnionType() || right_type->IsETSUnionType()) { + ThrowTypeError("Bad operand type, unions are not allowed in binary expressions except equality.", pos); + } + if (promotedType == nullptr && !bothConst) { ThrowTypeError("Bad operand type, the types of the operands must be numeric type.", pos); } @@ -156,6 +160,10 @@ checker::Type *ETSChecker::CheckBinaryOperatorPlus(ir::Expression *left, ir::Exp bool is_equal_op, checker::Type *const left_type, checker::Type *const right_type, Type *unboxed_l, Type *unboxed_r) { + if (left_type->IsETSUnionType() || right_type->IsETSUnionType()) { + ThrowTypeError("Bad operand type, unions are not allowed in binary expressions except equality.", pos); + } + if (left_type->IsETSStringType() || right_type->IsETSStringType()) { return HandleStringConcatenation(left_type, right_type); } @@ -182,6 +190,10 @@ checker::Type *ETSChecker::CheckBinaryOperatorShift(ir::Expression *left, ir::Ex bool is_equal_op, checker::Type *const left_type, checker::Type *const right_type, Type *unboxed_l, Type *unboxed_r) { + if (left_type->IsETSUnionType() || right_type->IsETSUnionType()) { + ThrowTypeError("Bad operand type, unions are not allowed in binary expressions except equality.", pos); + } + auto promoted_left_type = ApplyUnaryOperatorPromotion(unboxed_l, false, !is_equal_op); auto promoted_right_type = ApplyUnaryOperatorPromotion(unboxed_r, false, !is_equal_op); @@ -225,6 +237,10 @@ checker::Type *ETSChecker::CheckBinaryOperatorBitwise(ir::Expression *left, ir:: bool is_equal_op, checker::Type *const left_type, checker::Type *const right_type, Type *unboxed_l, Type *unboxed_r) { + if (left_type->IsETSUnionType() || right_type->IsETSUnionType()) { + ThrowTypeError("Bad operand type, unions are not allowed in binary expressions except equality.", pos); + } + if (unboxed_l != nullptr && unboxed_l->HasTypeFlag(checker::TypeFlag::ETS_BOOLEAN) && unboxed_r != nullptr && unboxed_r->HasTypeFlag(checker::TypeFlag::ETS_BOOLEAN)) { FlagExpressionWithUnboxing(left_type, unboxed_l, left); @@ -253,6 +269,10 @@ checker::Type *ETSChecker::CheckBinaryOperatorLogical(ir::Expression *left, ir:: lexer::SourcePosition pos, checker::Type *const left_type, checker::Type *const right_type, Type *unboxed_l, Type *unboxed_r) { + if (left_type->IsETSUnionType() || right_type->IsETSUnionType()) { + ThrowTypeError("Bad operand type, unions are not allowed in binary expressions except equality.", pos); + } + if (unboxed_l == nullptr || !unboxed_l->IsConditionalExprType() || unboxed_r == nullptr || !unboxed_r->IsConditionalExprType()) { ThrowTypeError("Bad operand type, the types of the operands must be of possible condition type.", pos); @@ -278,8 +298,8 @@ std::tuple ETSChecker::CheckBinaryOperatorStrictEqual(ir::Expres checker::Type *const right_type) { checker::Type *ts_type {}; - if (!(left_type->HasTypeFlag(checker::TypeFlag::ETS_ARRAY_OR_OBJECT)) || - !(right_type->HasTypeFlag(checker::TypeFlag::ETS_ARRAY_OR_OBJECT))) { + if (!(left_type->HasTypeFlag(checker::TypeFlag::ETS_ARRAY_OR_OBJECT) || left_type->IsETSUnionType()) || + !(right_type->HasTypeFlag(checker::TypeFlag::ETS_ARRAY_OR_OBJECT) || right_type->IsETSUnionType())) { ThrowTypeError("Both operands have to be reference types", pos); } @@ -374,6 +394,12 @@ std::tuple ETSChecker::CheckBinaryOperatorLessGreater( ir::Expression *left, ir::Expression *right, lexer::TokenType operation_type, lexer::SourcePosition pos, bool is_equal_op, checker::Type *const left_type, checker::Type *const right_type, Type *unboxed_l, Type *unboxed_r) { + if ((left_type->IsETSUnionType() || right_type->IsETSUnionType()) && + operation_type != lexer::TokenType::PUNCTUATOR_EQUAL && + operation_type != lexer::TokenType::PUNCTUATOR_NOT_EQUAL) { + ThrowTypeError("Bad operand type, unions are not allowed in binary expressions except equality.", pos); + } + checker::Type *ts_type {}; auto [promotedType, bothConst] = ApplyBinaryOperatorPromotion(unboxed_l, unboxed_r, TypeFlag::ETS_NUMERIC, !is_equal_op); diff --git a/ets2panda/checker/ets/function.cpp b/ets2panda/checker/ets/function.cpp index 7e6538ad779804810f7a49a78c87889141bdb4fe..877aa2c46f4dd3317c812b50e2a51b3095e7a7dd 100644 --- a/ets2panda/checker/ets/function.cpp +++ b/ets2panda/checker/ets/function.cpp @@ -67,7 +67,7 @@ namespace panda::es2panda::checker { -bool ETSChecker::IsCompatibleTypeArgument(Type *type_param, Type *type_argument) +bool ETSChecker::IsCompatibleTypeArgument(Type *type_param, Type *type_argument, const Substitution *substitution) { ASSERT(type_param->IsETSObjectType() && type_param->AsETSObjectType()->HasObjectFlag(ETSObjectFlags::TYPE_PARAMETER)); @@ -78,13 +78,21 @@ bool ETSChecker::IsCompatibleTypeArgument(Type *type_param, Type *type_argument) return false; } auto *type_param_obj = type_param->AsETSObjectType(); - if (type_param_obj->SuperType() != nullptr) { - type_param_obj->SuperType()->IsSupertypeOf(Relation(), type_argument); + auto *type_param_obj_supertype = type_param_obj->SuperType(); + if (type_param_obj_supertype != nullptr) { + if (!type_param_obj_supertype->TypeArguments().empty()) { + type_param_obj_supertype = + type_param_obj_supertype->Substitute(this->Relation(), substitution)->AsETSObjectType(); + } + type_param_obj_supertype->IsSupertypeOf(Relation(), type_argument); if (!Relation()->IsTrue()) { return false; } } for (auto *itf : type_param_obj->Interfaces()) { + if (!itf->TypeArguments().empty()) { + itf = itf->Substitute(this->Relation(), substitution)->AsETSObjectType(); + } itf->IsSupertypeOf(Relation(), type_argument); if (!Relation()->IsTrue()) { return false; @@ -96,7 +104,8 @@ bool ETSChecker::IsCompatibleTypeArgument(Type *type_param, Type *type_argument) /* A very rough and imprecise partial type inference */ void ETSChecker::EnhanceSubstitutionForType(const ArenaVector &type_params, Type *param_type, - Type *argument_type, Substitution *substitution) + Type *argument_type, Substitution *substitution, + ArenaUnorderedSet *instantiated_type_params) { if (!param_type->IsETSObjectType()) { return; @@ -104,24 +113,47 @@ void ETSChecker::EnhanceSubstitutionForType(const ArenaVector &type_para auto *param_obj_type = param_type->AsETSObjectType(); if (param_obj_type->HasObjectFlag(ETSObjectFlags::TYPE_PARAMETER)) { auto *param_base = GetOriginalBaseType(param_obj_type); + if (instantiated_type_params->find(param_obj_type) != instantiated_type_params->end() && + substitution->at(param_base) != argument_type) { + ThrowTypeError({"Type parameter already instantiated with another type "}, + param_obj_type->GetDeclNode()->Start()); + } if (std::find(type_params.begin(), type_params.end(), param_base) != type_params.end() && substitution->count(param_base) == 0) { substitution->emplace(param_base, argument_type); + instantiated_type_params->insert(param_obj_type); return; } } - if (!argument_type->IsETSObjectType()) { + if (argument_type->IsETSObjectType()) { + auto *arg_obj_type = argument_type->AsETSObjectType(); + if (GetOriginalBaseType(arg_obj_type) != GetOriginalBaseType(param_obj_type)) { + return; // don't attempt anything fancy for now + } + ASSERT(arg_obj_type->TypeArguments().size() == param_obj_type->TypeArguments().size()); + for (size_t ix = 0; ix < arg_obj_type->TypeArguments().size(); ix++) { + EnhanceSubstitutionForType(type_params, param_obj_type->TypeArguments()[ix], + arg_obj_type->TypeArguments()[ix], substitution, instantiated_type_params); + } + } else if (argument_type->IsETSFunctionType() && + param_obj_type->HasObjectFlag(ETSObjectFlags::FUNCTIONAL_INTERFACE)) { + auto parameter_signatures = param_obj_type->GetOwnProperty("invoke") + ->TsType() + ->AsETSFunctionType() + ->CallSignatures(); + auto argument_signatures = argument_type->AsETSFunctionType()->CallSignatures(); + ASSERT(argument_signatures.size() == 1); + ASSERT(parameter_signatures.size() == 1); + for (size_t idx = 0; idx < argument_signatures[0]->GetSignatureInfo()->params.size(); idx++) { + EnhanceSubstitutionForType(type_params, parameter_signatures[0]->GetSignatureInfo()->params[idx]->TsType(), + argument_signatures[0]->GetSignatureInfo()->params[idx]->TsType(), substitution, + instantiated_type_params); + } + EnhanceSubstitutionForType(type_params, parameter_signatures[0]->ReturnType(), + argument_signatures[0]->ReturnType(), substitution, instantiated_type_params); + } else { return; } - auto *arg_obj_type = argument_type->AsETSObjectType(); - if (GetOriginalBaseType(arg_obj_type) != GetOriginalBaseType(param_obj_type)) { - return; // don't attempt anything fancy for now - } - ASSERT(arg_obj_type->TypeArguments().size() == param_obj_type->TypeArguments().size()); - for (size_t ix = 0; ix < arg_obj_type->TypeArguments().size(); ix++) { - EnhanceSubstitutionForType(type_params, param_obj_type->TypeArguments()[ix], arg_obj_type->TypeArguments()[ix], - substitution); - } } // NOLINTBEGIN(modernize-avoid-c-arrays) @@ -158,10 +190,9 @@ Signature *ETSChecker::ValidateSignature(Signature *signature, const ir::TSTypeP } } - if (substituted_sig->ReturnType()->IsETSObjectType() && signature->ReturnType()->IsETSObjectType() && - substituted_sig->ReturnType()->AsETSObjectType()->AssemblerName() != - signature->ReturnType()->AsETSObjectType()->AssemblerName()) { - substituted_sig->AddSignatureFlag(SignatureFlags::SUBSTITUTED_RETURN_TYPE); + if (substituted_sig->IsBaseReturnDiff() && substituted_sig->ReturnType()->IsETSArrayType()) { + CreateBuiltinArraySignature(substituted_sig->ReturnType()->AsETSArrayType(), + substituted_sig->ReturnType()->AsETSArrayType()->Rank()); } // Check all required formal parameter(s) first @@ -258,10 +289,12 @@ bool ETSChecker::ValidateProxySignature(Signature *const signature, return false; } - const auto num_non_default_params = - signature->Params().size() - signature->Function()->Body()->AsBlockStatement()->Statements().size(); + auto const *const proxy_param = signature->Function()->Params().back()->AsETSParameterExpression(); + if (!proxy_param->Ident()->Name().Is(ir::PROXY_PARAMETER_NAME)) { + return false; + } - if (arguments.size() < num_non_default_params) { + if (arguments.size() < proxy_param->GetRequiredParams()) { return false; } @@ -271,14 +304,12 @@ bool ETSChecker::ValidateProxySignature(Signature *const signature, arg_type_inference_required) != nullptr; } -Signature *ETSChecker::ValidateSignatures(ArenaVector &signatures, - const ir::TSTypeParameterInstantiation *type_arguments, - const ArenaVector &arguments, - const lexer::SourcePosition &pos, std::string_view signature_kind, - TypeRelationFlag resolve_flags) +std::pair, ArenaVector> ETSChecker::CollectSignatures( + ArenaVector &signatures, const ir::TSTypeParameterInstantiation *type_arguments, + const ArenaVector &arguments, std::vector &arg_type_inference_required, + const lexer::SourcePosition &pos, TypeRelationFlag resolve_flags) { ArenaVector compatible_signatures(Allocator()->Adapter()); - std::vector arg_type_inference_required = FindTypeInferenceArguments(arguments); ArenaVector proxy_signatures(Allocator()->Adapter()); for (auto *sig : signatures) { @@ -320,40 +351,68 @@ Signature *ETSChecker::ValidateSignatures(ArenaVector &signatures, } } } + return std::make_pair(compatible_signatures, proxy_signatures); +} - if (!compatible_signatures.empty()) { - Signature *most_specific_signature = - ChooseMostSpecificSignature(compatible_signatures, arguments, arg_type_inference_required, pos); +Signature *ETSChecker::GetMostSpecificSignature(ArenaVector &compatible_signatures, + ArenaVector &proxy_signatures, + const ArenaVector &arguments, + std::vector &arg_type_inference_required, + const lexer::SourcePosition &pos, TypeRelationFlag resolve_flags) +{ + Signature *most_specific_signature = + ChooseMostSpecificSignature(compatible_signatures, arg_type_inference_required, pos); - if (most_specific_signature == nullptr) { - ThrowTypeError({"Reference to ", compatible_signatures.front()->Function()->Id()->Name(), " is ambiguous"}, - pos); + if (most_specific_signature == nullptr) { + ThrowTypeError({"Reference to ", compatible_signatures.front()->Function()->Id()->Name(), " is ambiguous"}, + pos); + } + + if (!TypeInference(most_specific_signature, arguments, resolve_flags)) { + return nullptr; + } + + // Just to avoid extra nesting level + auto const check_ambiguous = [this, most_specific_signature, &pos](Signature const *const proxy_signature) -> void { + auto const *const proxy_param = proxy_signature->Function()->Params().back()->AsETSParameterExpression(); + if (!proxy_param->Ident()->Name().Is(ir::PROXY_PARAMETER_NAME)) { + ThrowTypeError({"Proxy parameter '", proxy_param->Ident()->Name(), "' has invalid name."}, pos); } - if (!TypeInference(most_specific_signature, arguments, resolve_flags)) { - return nullptr; + if (most_specific_signature->Params().size() == proxy_param->GetRequiredParams()) { + ThrowTypeError({"Reference to ", most_specific_signature->Function()->Id()->Name(), " is ambiguous"}, pos); } + }; - if (!proxy_signatures.empty()) { - auto *const proxy_signature = ChooseMostSpecificProxySignature( - proxy_signatures, arguments, arg_type_inference_required, pos, arguments.size()); - if (proxy_signature != nullptr) { - const size_t num_non_default_params = - proxy_signature->Params().size() - - proxy_signature->Function()->Body()->AsBlockStatement()->Statements().size(); - if (most_specific_signature->Params().size() == num_non_default_params) { - ThrowTypeError( - {"Reference to ", most_specific_signature->Function()->Id()->Name(), " is ambiguous"}, pos); - } - } + if (!proxy_signatures.empty()) { + auto *const proxy_signature = + ChooseMostSpecificProxySignature(proxy_signatures, arg_type_inference_required, pos, arguments.size()); + if (proxy_signature != nullptr) { + check_ambiguous(proxy_signature); } + } - return most_specific_signature; + return most_specific_signature; +} + +Signature *ETSChecker::ValidateSignatures(ArenaVector &signatures, + const ir::TSTypeParameterInstantiation *type_arguments, + const ArenaVector &arguments, + const lexer::SourcePosition &pos, std::string_view signature_kind, + TypeRelationFlag resolve_flags) +{ + std::vector arg_type_inference_required = FindTypeInferenceArguments(arguments); + auto [compatible_signatures, proxy_signatures] = + CollectSignatures(signatures, type_arguments, arguments, arg_type_inference_required, pos, resolve_flags); + + if (!compatible_signatures.empty()) { + return GetMostSpecificSignature(compatible_signatures, proxy_signatures, arguments, arg_type_inference_required, + pos, resolve_flags); } if (!proxy_signatures.empty()) { - auto *const proxy_signature = ChooseMostSpecificProxySignature( - proxy_signatures, arguments, arg_type_inference_required, pos, arguments.size()); + auto *const proxy_signature = + ChooseMostSpecificProxySignature(proxy_signatures, arg_type_inference_required, pos, arguments.size()); if (proxy_signature != nullptr) { return proxy_signature; } @@ -367,7 +426,6 @@ Signature *ETSChecker::ValidateSignatures(ArenaVector &signatures, } Signature *ETSChecker::ChooseMostSpecificSignature(ArenaVector &signatures, - const ArenaVector &arguments, const std::vector &arg_type_inference_required, const lexer::SourcePosition &pos, size_t arguments_size) { @@ -390,8 +448,8 @@ Signature *ETSChecker::ChooseMostSpecificSignature(ArenaVector &sig // Collect which signatures are most specific for each parameter. ArenaMultiMap best_signatures_for_parameter(Allocator()->Adapter()); - checker::SavedTypeRelationFlagsContext saved_type_relation_flag_ctx(Relation(), - TypeRelationFlag::ONLY_CHECK_WIDENING); + const checker::SavedTypeRelationFlagsContext saved_type_relation_flag_ctx(Relation(), + TypeRelationFlag::ONLY_CHECK_WIDENING); for (size_t i = 0; i < param_count; ++i) { if (arg_type_inference_required[i]) { @@ -402,51 +460,56 @@ Signature *ETSChecker::ChooseMostSpecificSignature(ArenaVector &sig } // 1st step: check which is the most specific parameter type for i. parameter. Type *most_specific_type = signatures.front()->Params().at(i)->TsType(); + Signature *prev_sig = signatures.front(); - for (auto it = ++signatures.begin(); it != signatures.end(); ++it) { - Signature *sig = *it; - // Each signature must have the same amount of parameters. - if (arguments_size == ULONG_MAX) { - ASSERT(sig->Params().size() == param_count); - } - - Type *sig_type = sig->Params().at(i)->TsType(); - - if (Relation()->IsIdenticalTo(sig_type, most_specific_type)) { - continue; + auto init_most_specific_type = [&most_specific_type, &prev_sig, i](Signature *sig) { + if (Type *sig_type = sig->Params().at(i)->TsType(); + sig_type->IsETSObjectType() && !sig_type->AsETSObjectType()->HasObjectFlag(ETSObjectFlags::INTERFACE)) { + most_specific_type = sig_type; + prev_sig = sig; + return true; } + return false; + }; + auto evaluate_result = [this, &most_specific_type, &prev_sig, pos](Signature *sig, Type *sig_type) { if (Relation()->IsAssignableTo(sig_type, most_specific_type)) { most_specific_type = sig_type; + prev_sig = sig; + } else if (sig_type->IsETSObjectType() && most_specific_type->IsETSObjectType() && + !Relation()->IsAssignableTo(most_specific_type, sig_type)) { + auto func_name = sig->Function()->Id()->Name(); + ThrowTypeError({"Call to `", func_name, "` is ambiguous as `2` versions of `", func_name, + "` are available: `", func_name, prev_sig, "` and `", func_name, sig, "`"}, + pos); } - } + }; - // 2nd step: collect which signatures fit to the i. most specific parameter type. - Type *prev_sig_type = nullptr; - Signature *prev_sig = nullptr; - Type *arg_type = arguments.at(i)->TsType(); - for (auto *sig : signatures) { + auto search_among_types = [this, &most_specific_type, arguments_size, param_count, i, + &evaluate_result](Signature *sig, const bool look_for_class_type) { + if (look_for_class_type && arguments_size == ULONG_MAX) { + [[maybe_unused]] const bool equal_param_size = sig->Params().size() == param_count; + ASSERT(equal_param_size); + } Type *sig_type = sig->Params().at(i)->TsType(); - if (arg_type->IsETSObjectType()) { - auto it = std::find(arg_type->AsETSObjectType()->Interfaces().begin(), - arg_type->AsETSObjectType()->Interfaces().end(), sig_type); - bool found_coincidence = it != arg_type->AsETSObjectType()->Interfaces().end() || - arg_type->AsETSObjectType()->SuperType() == sig_type; - if (found_coincidence && prev_sig_type != nullptr) { // Ambiguous call - bool is_assignable = - IsTypeAssignableTo(prev_sig_type, sig_type) || IsTypeAssignableTo(sig_type, prev_sig_type); - if (!is_assignable) { - auto func_name = sig->Function()->Id()->Name(); - ThrowTypeError({"Call to `", func_name, "` is ambiguous as `2` versions of `", func_name, - "` are available: `", func_name, prev_sig, "` and `", func_name, sig, "`"}, - pos); - } - } else if (found_coincidence && !arg_type->IsETSStringType()) { - prev_sig = sig; - prev_sig_type = sig_type; + const bool is_class_type = + sig_type->IsETSObjectType() && !sig_type->AsETSObjectType()->HasObjectFlag(ETSObjectFlags::INTERFACE); + if (is_class_type == look_for_class_type) { + if (Relation()->IsIdenticalTo(sig_type, most_specific_type)) { + return; } + evaluate_result(sig, sig_type); } + }; + std::any_of(signatures.begin(), signatures.end(), init_most_specific_type); + std::for_each(signatures.begin(), signatures.end(), + [&search_among_types](Signature *sig) mutable { search_among_types(sig, true); }); + std::for_each(signatures.begin(), signatures.end(), + [&search_among_types](Signature *sig) mutable { search_among_types(sig, false); }); + + for (auto *sig : signatures) { + Type *sig_type = sig->Params().at(i)->TsType(); if (Relation()->IsIdenticalTo(sig_type, most_specific_type)) { best_signatures_for_parameter.insert({i, sig}); } @@ -492,7 +555,6 @@ Signature *ETSChecker::ChooseMostSpecificSignature(ArenaVector &sig } Signature *ETSChecker::ChooseMostSpecificProxySignature(ArenaVector &signatures, - const ArenaVector &arguments, const std::vector &arg_type_inference_required, const lexer::SourcePosition &pos, size_t arguments_size) { @@ -501,7 +563,7 @@ Signature *ETSChecker::ChooseMostSpecificProxySignature(ArenaVector } const auto most_specific_signature = - ChooseMostSpecificSignature(signatures, arguments, arg_type_inference_required, pos, arguments_size); + ChooseMostSpecificSignature(signatures, arg_type_inference_required, pos, arguments_size); if (most_specific_signature == nullptr) { const auto str = signatures.front()->Function()->Id()->Name().Mutf8().substr( @@ -2494,21 +2556,21 @@ varbinder::FunctionParamScope *ETSChecker::CopyParams(const ArenaVector &out_params) { auto param_ctx = varbinder::LexicalScope(VarBinder()); + for (auto *const it : params) { - auto *const param_expr_ident = it->AsETSParameterExpression()->Ident(); - auto *const param_ident = Allocator()->New(param_expr_ident->Name(), Allocator()); + auto *const param_old = it->AsETSParameterExpression(); + auto *const param_new = param_old->Clone(Allocator(), param_old->Parent())->AsETSParameterExpression(); - auto *const param = Allocator()->New(param_ident, nullptr); - auto *const var = std::get<1>(VarBinder()->AddParamDecl(param)); - var->SetTsType(param_expr_ident->Variable()->TsType()); + auto *const var = std::get<1>(VarBinder()->AddParamDecl(param_new)); + var->SetTsType(param_old->Ident()->Variable()->TsType()); var->SetScope(param_ctx.GetScope()); - param->SetVariable(var); - param_ident->SetTsTypeAnnotation(param_expr_ident->TypeAnnotation()); - param->SetTsType(param_expr_ident->Variable()->TsType()); - param->SetParent(it->Parent()); - param_ident->SetParent(param_expr_ident->Parent()); - out_params.push_back(param); + param_new->SetVariable(var); + + param_new->SetTsType(param_old->TsType()); + + out_params.emplace_back(param_new); } + return param_ctx.GetScope(); } diff --git a/ets2panda/checker/ets/function_helpers.h b/ets2panda/checker/ets/function_helpers.h index c112c116f7f81819b5fe4e0e0577fe4ea70f5e10..a4b7e1d091fb53b079bf33bf55dfd1411c37e93b 100644 --- a/ets2panda/checker/ets/function_helpers.h +++ b/ets2panda/checker/ets/function_helpers.h @@ -86,6 +86,7 @@ static const Substitution *BuildImplicitSubstitutionForArguments(ETSChecker *che const ArenaVector &arguments) { Substitution *substitution = checker->NewSubstitution(); + auto *instantiated_type_params = checker->NewInstantiatedTypeParamsSet(); auto *sig_info = signature->GetSignatureInfo(); ArenaVector &type_params = sig_info->type_params; for (size_t ix = 0; ix < arguments.size(); ix++) { @@ -100,7 +101,7 @@ static const Substitution *BuildImplicitSubstitutionForArguments(ETSChecker *che if (param_type == nullptr) { continue; } - checker->EnhanceSubstitutionForType(type_params, param_type, arg_type, substitution); + checker->EnhanceSubstitutionForType(type_params, param_type, arg_type, substitution, instantiated_type_params); } return substitution; } @@ -111,6 +112,7 @@ static const Substitution *BuildExplicitSubstitutionForArguments(ETSChecker *che TypeRelationFlag flags) { auto *substitution = checker->NewSubstitution(); + auto *constraints_substitution = checker->NewSubstitution(); ArenaVector &type_params = signature->GetSignatureInfo()->type_params; ArenaVector type_arg_types {checker->Allocator()->Adapter()}; for (auto *ta_expr : type_arguments->Params()) { @@ -125,8 +127,11 @@ static const Substitution *BuildExplicitSubstitutionForArguments(ETSChecker *che } return nullptr; } + for (size_t ix = 0; ix < type_params.size(); ix++) { + constraints_substitution->emplace(type_params[ix], type_arg_types[ix]); + } for (size_t ix = 0; ix < type_arg_types.size(); ix++) { - if (!checker->IsCompatibleTypeArgument(type_params[ix], type_arg_types[ix])) { + if (!checker->IsCompatibleTypeArgument(type_params[ix], type_arg_types[ix], constraints_substitution)) { return nullptr; } substitution->emplace(type_params[ix], type_arg_types[ix]); diff --git a/ets2panda/checker/ets/helpers.cpp b/ets2panda/checker/ets/helpers.cpp index b1f99ba5be31df8752d5e681279a7fc6a67bfa98..ec7e32f122cce4a74b439fbbdbf6450e06b3ea0a 100644 --- a/ets2panda/checker/ets/helpers.cpp +++ b/ets2panda/checker/ets/helpers.cpp @@ -75,6 +75,10 @@ void ETSChecker::CheckTruthinessOfType(ir::Expression *expr) checker::Type *type = expr->Check(this); auto *unboxed_type = ETSBuiltinTypeAsConditionalType(type); + if (unboxed_type == GlobalBuiltinVoidType() || unboxed_type->IsETSVoidType()) { + ThrowTypeError("An expression of type 'void' cannot be tested for truthiness", expr->Start()); + } + if (unboxed_type != nullptr && !unboxed_type->IsConditionalExprType()) { ThrowTypeError("Condition must be of possible condition type", expr->Start()); } @@ -367,92 +371,171 @@ bool ETSChecker::IsVariableGetterSetter(const varbinder::Variable *var) const return var->TsType() != nullptr && var->TsType()->HasTypeFlag(TypeFlag::GETTER_SETTER); } -void ETSChecker::ValidateResolvedIdentifier(ir::Identifier *const ident, varbinder::Variable *const resolved) +void ETSChecker::ThrowError(ir::Identifier *const ident) { - const auto throw_error = [this, ident]() { - ThrowTypeError({"Unresolved reference ", ident->Name()}, ident->Start()); - }; + ThrowTypeError({"Unresolved reference ", ident->Name()}, ident->Start()); +} - // Just to avoid extra nested level - const auto check_ets_function_type = [this, &throw_error](ir::Identifier const *const id, - ir::TypeNode const *const annotation) -> void { - if (annotation == nullptr) { - ThrowTypeError( - {"Cannot infer type for ", id->Name(), " because method reference needs an explicit target type"}, - id->Start()); +void ETSChecker::CheckEtsFunctionType(ir::Identifier *const ident, ir::Identifier const *const id, + ir::TypeNode const *const annotation) +{ + if (annotation == nullptr) { + ThrowTypeError( + {"Cannot infer type for ", id->Name(), " because method reference needs an explicit target type"}, + id->Start()); + } + + const auto *const target_type = GetTypeOfVariable(id->Variable()); + ASSERT(target_type != nullptr); + + if (!target_type->IsETSObjectType() || !target_type->AsETSObjectType()->HasObjectFlag(ETSObjectFlags::FUNCTIONAL)) { + ThrowError(ident); + } +} + +void ETSChecker::NotResolvedError(ir::Identifier *const ident) +{ + const auto [class_var, class_type] = FindVariableInClassOrEnclosing(ident->Name(), Context().ContainingClass()); + if (class_var == nullptr) { + ThrowError(ident); + } + + if (IsVariableStatic(class_var)) { + ThrowTypeError( + {"Static property '", ident->Name(), "' must be accessed through it's class '", class_type->Name(), "'"}, + ident->Start()); + } else { + ThrowTypeError({"Property '", ident->Name(), "' must be accessed through 'this'"}, ident->Start()); + } +} + +void ETSChecker::ValidateCallExpressionIdentifier(ir::Identifier *const ident, Type *const type) +{ + if (ident->Parent()->AsCallExpression()->Callee() == ident && !type->IsETSFunctionType() && + !type->IsETSDynamicType() && + (!type->IsETSObjectType() || !type->AsETSObjectType()->HasObjectFlag(ETSObjectFlags::FUNCTIONAL)) && + !TryTransformingToStaticInvoke(ident, type)) { + ThrowError(ident); + } +} + +void ETSChecker::ValidateNewClassInstanceIdentifier(ir::Identifier *const ident, varbinder::Variable *const resolved) +{ + if (ident->Parent()->AsETSNewClassInstanceExpression()->GetTypeRef() == ident && + !resolved->HasFlag(varbinder::VariableFlags::CLASS_OR_INTERFACE)) { + ThrowError(ident); + } +} + +void ETSChecker::ValidateMemberIdentifier(ir::Identifier *const ident, varbinder::Variable *const resolved, + Type *const type) +{ + if (ident->Parent()->AsMemberExpression()->IsComputed()) { + if (!resolved->Declaration()->PossibleTDZ()) { + ThrowError(ident); } - const auto *const target_type = GetTypeOfVariable(id->Variable()); + return; + } + + if (!type->IsETSObjectType() && !type->IsETSArrayType() && !type->IsETSEnumType() && !type->IsETSStringEnumType() && + !type->IsETSUnionType() && !type->HasTypeFlag(TypeFlag::ETS_PRIMITIVE)) { + ThrowError(ident); + } +} + +std::pair ETSChecker::GetTargetIdentifierAndType(ir::Identifier *const ident) +{ + if (ident->Parent()->IsClassProperty()) { + const auto *const class_prop = ident->Parent()->AsClassProperty(); + ASSERT(class_prop->Value() && class_prop->Value() == ident); + return std::make_pair(class_prop->Key()->AsIdentifier(), class_prop->TypeAnnotation()); + } + const auto *const variable_decl = ident->Parent()->AsVariableDeclarator(); + ASSERT(variable_decl->Init() && variable_decl->Init() == ident); + return std::make_pair(variable_decl->Id()->AsIdentifier(), variable_decl->Id()->AsIdentifier()->TypeAnnotation()); +} + +void ETSChecker::ValidatePropertyOrDeclaratorIdentifier(ir::Identifier *const ident, + varbinder::Variable *const resolved) +{ + const auto [target_ident, type_annotation] = GetTargetIdentifierAndType(ident); + + if (resolved->TsType()->IsETSFunctionType()) { + CheckEtsFunctionType(ident, target_ident, type_annotation); + return; + } + + if (!resolved->Declaration()->PossibleTDZ()) { + ThrowError(ident); + } +} + +void ETSChecker::ValidateAssignmentIdentifier(ir::Identifier *const ident, varbinder::Variable *const resolved, + Type *const type) +{ + const auto *const assignment_expr = ident->Parent()->AsAssignmentExpression(); + if (assignment_expr->Left() == ident && !resolved->Declaration()->PossibleTDZ()) { + ThrowError(ident); + } + + if (assignment_expr->Right() == ident) { + const auto *const target_type = assignment_expr->Left()->TsType(); ASSERT(target_type != nullptr); - if (!target_type->IsETSObjectType() || - !target_type->AsETSObjectType()->HasObjectFlag(ETSObjectFlags::FUNCTIONAL)) { - throw_error(); + if (target_type->IsETSObjectType() && + target_type->AsETSObjectType()->HasObjectFlag(ETSObjectFlags::FUNCTIONAL)) { + if (!type->IsETSFunctionType() && + !(type->IsETSObjectType() && type->AsETSObjectType()->HasObjectFlag(ETSObjectFlags::FUNCTIONAL))) { + ThrowError(ident); + } + + return; } - }; - if (resolved == nullptr) { - const auto [class_var, class_type] = FindVariableInClassOrEnclosing(ident->Name(), Context().ContainingClass()); - if (class_var == nullptr) { - throw_error(); + if (!resolved->Declaration()->PossibleTDZ()) { + ThrowError(ident); } + } +} - if (IsVariableStatic(class_var)) { - ThrowTypeError({"Static property '", ident->Name(), "' must be accessed through it's class '", - class_type->Name(), "'"}, - ident->Start()); - } else { - ThrowTypeError({"Property '", ident->Name(), "' must be accessed through 'this'"}, ident->Start()); +bool ETSChecker::ValidateBinaryExpressionIdentifier(ir::Identifier *const ident, Type *const type) +{ + const auto *const binary_expr = ident->Parent()->AsBinaryExpression(); + bool is_finished = false; + if (binary_expr->OperatorType() == lexer::TokenType::KEYW_INSTANCEOF && binary_expr->Right() == ident) { + if (!type->IsETSObjectType()) { + ThrowError(ident); } + is_finished = true; + } + return is_finished; +} + +void ETSChecker::ValidateResolvedIdentifier(ir::Identifier *const ident, varbinder::Variable *const resolved) +{ + if (resolved == nullptr) { + NotResolvedError(ident); } auto *const resolved_type = GetTypeOfVariable(resolved); switch (ident->Parent()->Type()) { case ir::AstNodeType::CALL_EXPRESSION: { - if (ident->Parent()->AsCallExpression()->Callee() == ident && !resolved_type->IsETSFunctionType() && - !resolved_type->IsETSDynamicType() && - (!resolved_type->IsETSObjectType() || - !resolved_type->AsETSObjectType()->HasObjectFlag(ETSObjectFlags::FUNCTIONAL)) && - !TryTransformingToStaticInvoke(ident, resolved_type)) { - throw_error(); - } - + ValidateCallExpressionIdentifier(ident, resolved_type); break; } case ir::AstNodeType::ETS_NEW_CLASS_INSTANCE_EXPRESSION: { - if (ident->Parent()->AsETSNewClassInstanceExpression()->GetTypeRef() == ident && - !resolved->HasFlag(varbinder::VariableFlags::CLASS_OR_INTERFACE)) { - throw_error(); - } - + ValidateNewClassInstanceIdentifier(ident, resolved); break; } case ir::AstNodeType::MEMBER_EXPRESSION: { - if (ident->Parent()->AsMemberExpression()->IsComputed()) { - if (!resolved->Declaration()->PossibleTDZ()) { - throw_error(); - } - - break; - } - - if (!resolved_type->IsETSObjectType() && !resolved_type->IsETSArrayType() && - !resolved_type->IsETSEnumType() && !resolved_type->IsETSStringEnumType() && - !resolved_type->IsETSUnionType()) { - throw_error(); - } - + ValidateMemberIdentifier(ident, resolved, resolved_type); break; } case ir::AstNodeType::BINARY_EXPRESSION: { - const auto *const binary_expr = ident->Parent()->AsBinaryExpression(); - if (binary_expr->OperatorType() == lexer::TokenType::KEYW_INSTANCEOF && binary_expr->Right() == ident) { - if (!resolved_type->IsETSObjectType()) { - throw_error(); - } - - break; + if (ValidateBinaryExpressionIdentifier(ident, resolved_type)) { + return; } [[fallthrough]]; @@ -460,70 +543,23 @@ void ETSChecker::ValidateResolvedIdentifier(ir::Identifier *const ident, varbind case ir::AstNodeType::UPDATE_EXPRESSION: case ir::AstNodeType::UNARY_EXPRESSION: { if (!resolved->Declaration()->PossibleTDZ()) { - throw_error(); + ThrowError(ident); } - break; } case ir::AstNodeType::CLASS_PROPERTY: case ir::AstNodeType::VARIABLE_DECLARATOR: { - const auto [target_ident, type_annotation] = [ident]() { - if (ident->Parent()->IsClassProperty()) { - const auto *const class_prop = ident->Parent()->AsClassProperty(); - ASSERT(class_prop->Value() && class_prop->Value() == ident); - return std::make_pair(class_prop->Key()->AsIdentifier(), class_prop->TypeAnnotation()); - } - const auto *const variable_decl = ident->Parent()->AsVariableDeclarator(); - ASSERT(variable_decl->Init() && variable_decl->Init() == ident); - return std::make_pair(variable_decl->Id()->AsIdentifier(), - variable_decl->Id()->AsIdentifier()->TypeAnnotation()); - }(); - - if (resolved->TsType()->IsETSFunctionType()) { - check_ets_function_type(target_ident, type_annotation); - break; - } - - if (!resolved->Declaration()->PossibleTDZ()) { - throw_error(); - } - + ValidatePropertyOrDeclaratorIdentifier(ident, resolved); break; } case ir::AstNodeType::ASSIGNMENT_EXPRESSION: { - const auto *const assignment_expr = ident->Parent()->AsAssignmentExpression(); - - if (assignment_expr->Left() == ident && !resolved->Declaration()->PossibleTDZ()) { - throw_error(); - } - - if (assignment_expr->Right() == ident) { - const auto *const target_type = assignment_expr->Left()->TsType(); - ASSERT(target_type != nullptr); - - if (target_type->IsETSObjectType() && - target_type->AsETSObjectType()->HasObjectFlag(ETSObjectFlags::FUNCTIONAL)) { - if (!resolved_type->IsETSFunctionType() && - !(resolved_type->IsETSObjectType() && - resolved_type->AsETSObjectType()->HasObjectFlag(ETSObjectFlags::FUNCTIONAL))) { - throw_error(); - } - - break; - } - - if (!resolved->Declaration()->PossibleTDZ()) { - throw_error(); - } - } - + ValidateAssignmentIdentifier(ident, resolved, resolved_type); break; } default: { if (!resolved->Declaration()->PossibleTDZ() && !resolved_type->IsETSFunctionType()) { - throw_error(); + ThrowError(ident); } - break; } } @@ -750,8 +786,13 @@ Type *ETSChecker::HandleBooleanLogicalOperatorsExtended(Type *left_type, Type *r IsNullLikeOrVoidExpression(expr->Right()) ? std::make_tuple(true, false) : right_type->ResolveConditionExpr(); if (!resolve_left) { - // return the UNION type when it is implemented - return IsTypeIdenticalTo(left_type, right_type) ? left_type : GlobalETSBooleanType(); + if (IsTypeIdenticalTo(left_type, right_type)) { + return left_type; + } + ArenaVector types(Allocator()->Adapter()); + types.push_back(left_type); + types.push_back(right_type); + return CreateETSUnionType(std::move(types)); } switch (expr->OperatorType()) { @@ -1057,8 +1098,11 @@ void ETSChecker::SetPropertiesForModuleObject(checker::ETSObjectType *module_obj { auto *ets_binder = static_cast(VarBinder()); - auto res = ets_binder->GetGlobalRecordTable()->Program()->ExternalSources().find(import_path); - + auto ext_records = ets_binder->GetGlobalRecordTable()->Program()->ExternalSources(); + auto res = [ets_binder, ext_records, import_path]() { + auto r = ext_records.find(import_path); + return r != ext_records.end() ? r : ext_records.find(ets_binder->GetResolvedImportPath(import_path)); + }(); for (auto [_, var] : res->second.front()->GlobalClassScope()->StaticFieldScope()->Bindings()) { (void)_; if (var->AsLocalVariable()->Declaration()->Node()->IsExported()) { @@ -1446,18 +1490,6 @@ Type *ETSChecker::ETSBuiltinTypeAsConditionalType(Type *object_type) return nullptr; } - if (object_type->IsETSObjectType()) { - if (!object_type->AsETSObjectType()->HasObjectFlag(ETSObjectFlags::UNBOXABLE_TYPE)) { - return object_type; - } - auto saved_result = Relation()->IsTrue(); - Relation()->Result(false); - - UnboxingConverter converter = UnboxingConverter(AsETSChecker(), Relation(), object_type, object_type); - Relation()->Result(saved_result); - return converter.Result(); - } - return object_type; } @@ -1786,7 +1818,7 @@ void ETSChecker::CheckUnboxedTypesAssignable(TypeRelation *relation, Type *sourc void ETSChecker::CheckBoxedSourceTypeAssignable(TypeRelation *relation, Type *source, Type *target) { checker::SavedTypeRelationFlagsContext saved_type_relation_flag_ctx( - relation, TypeRelationFlag::ONLY_CHECK_WIDENING | + relation, (relation->ApplyWidening() ? TypeRelationFlag::WIDENING : TypeRelationFlag::NONE) | (relation->ApplyNarrowing() ? TypeRelationFlag::NARROWING : TypeRelationFlag::NONE)); auto *boxed_source_type = relation->GetChecker()->AsETSChecker()->PrimitiveTypeAsETSBuiltinType(source); if (boxed_source_type == nullptr) { @@ -1804,7 +1836,7 @@ void ETSChecker::CheckBoxedSourceTypeAssignable(TypeRelation *relation, Type *so if (unboxed_target_type == nullptr) { return; } - NarrowingConverter(this, relation, unboxed_target_type, source); + NarrowingWideningConverter(this, relation, unboxed_target_type, source); if (relation->IsTrue()) { AddBoxingFlagToPrimitiveType(relation, target); } @@ -2040,7 +2072,7 @@ Type *ETSChecker::GetTypeFromTypeAnnotation(ir::TypeNode *const type_annotation) return type; } - if (!type->HasTypeFlag(TypeFlag::ETS_ARRAY_OR_OBJECT)) { + if (!type->HasTypeFlag(TypeFlag::ETS_ARRAY_OR_OBJECT) && !type->HasTypeFlag(TypeFlag::ETS_UNION)) { ThrowTypeError("Non reference types cannot be nullish.", type_annotation->Start()); } @@ -2068,6 +2100,30 @@ void ETSChecker::CheckValidGenericTypeParameter(Type *const arg_type, const lexe ThrowTypeError("Type '" + ss.str() + "' is not valid for generic type arguments", pos); } +void ETSChecker::CheckNumberOfTypeArguments(Type *const type, ir::TSTypeParameterDeclaration *const type_param_decl, + ir::TSTypeParameterInstantiation *const type_args, + const lexer::SourcePosition &pos) +{ + if (type_param_decl != nullptr && type_args == nullptr) { + ThrowTypeError({"Type '", type, "' is generic but type argument were not provided."}, pos); + } + + if (type_param_decl == nullptr && type_args != nullptr) { + ThrowTypeError({"Type '", type, "' is not generic."}, pos); + } + + if (type_args == nullptr) { + return; + } + + ASSERT(type_param_decl != nullptr && type_args != nullptr); + if (type_param_decl->Params().size() != type_args->Params().size()) { + ThrowTypeError({"Type '", type, "' has ", type_param_decl->Params().size(), " number of type parameters, but ", + type_args->Params().size(), " type arguments were provided."}, + pos); + } +} + bool ETSChecker::NeedTypeInference(const ir::ScriptFunction *lambda) { if (lambda->ReturnTypeAnnotation() == nullptr) { @@ -2282,7 +2338,7 @@ bool ETSChecker::TryTransformingToStaticInvoke(ir::Identifier *const ident, cons parser::Program program(Allocator(), VarBinder()); es2panda::CompilerOptions options; auto parser = parser::ETSParser(&program, options, parser::ParserStatus::NO_OPTS); - auto *arg_expr = parser.CreateExpression(parser::ExpressionParseFlags::NO_OPTS, implicit_instantiate_argument); + auto *arg_expr = parser.CreateExpression(implicit_instantiate_argument); arg_expr->SetParent(call_expr); arg_expr->SetRange(ident->Range()); diff --git a/ets2panda/checker/ets/object.cpp b/ets2panda/checker/ets/object.cpp index 9ae05f1775df24d55457e41a6a45944c51e2b7c2..4dadde3e03d98673deed41440d30b285896bce28 100644 --- a/ets2panda/checker/ets/object.cpp +++ b/ets2panda/checker/ets/object.cpp @@ -1,5 +1,5 @@ /** - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-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 @@ -175,13 +175,57 @@ ArenaVector ETSChecker::CreateTypeForTypeParameters(ir::TSTypeParameterD ArenaVector result {Allocator()->Adapter()}; checker::ScopeContext scope_ctx(this, type_params->Scope()); + // Note: we have to run pure check loop first to avoid endless loop because of possible circular dependencies + Type2TypeMap extends {}; + for (auto *const type_param : type_params->Params()) { + if (auto *const constraint = type_param->Constraint(); + constraint != nullptr && constraint->IsETSTypeReference() && + constraint->AsETSTypeReference()->Part()->Name()->IsIdentifier()) { + CheckTypeParameterConstraint(type_param, extends); + } + } + + for (auto *const type_param : type_params->Params()) { + result.emplace_back(CreateTypeParameterType(type_param)); + } + + // The type parameter might be used in the constraint, like 'K extend Comparable', + // so we need to create their type first, then set up the constraint for (auto *const param : type_params->Params()) { - result.push_back(CreateTypeParameterType(param)); + SetUpTypeParameterConstraint(param); } return result; } +void ETSChecker::CheckTypeParameterConstraint(ir::TSTypeParameter *param, Type2TypeMap &extends) +{ + const auto type_param_name = param->Name()->Name().Utf8(); + const auto constraint_name = + param->Constraint()->AsETSTypeReference()->Part()->Name()->AsIdentifier()->Name().Utf8(); + if (type_param_name == constraint_name) { + ThrowTypeError({"Type parameter '", type_param_name, "' cannot extend/implement itself."}, + param->Constraint()->Start()); + } + + auto it = extends.find(type_param_name); + if (it != extends.cend()) { + ThrowTypeError({"Type parameter '", type_param_name, "' is duplicated in the list."}, + param->Constraint()->Start()); + } + + it = extends.find(constraint_name); + while (it != extends.cend()) { + if (it->second == type_param_name) { + ThrowTypeError({"Type parameter '", type_param_name, "' has circular constraint dependency."}, + param->Constraint()->Start()); + } + it = extends.find(it->second); + } + + extends.emplace(type_param_name, constraint_name); +} + Type *ETSChecker::CreateTypeParameterType(ir::TSTypeParameter *const param) { auto const instantiate_supertype = [this](TypeFlag nullish_flags) { @@ -189,31 +233,37 @@ Type *ETSChecker::CreateTypeParameterType(ir::TSTypeParameter *const param) ->AsETSObjectType(); }; - ETSObjectType *param_type = - CreateNewETSObjectType(param->Name()->Name(), param, GlobalETSObjectType()->ObjectFlags()); - param_type->SetAssemblerName(GlobalETSObjectType()->AssemblerName()); - param_type->AddTypeFlag(TypeFlag::GENERIC); - param_type->AddObjectFlag(ETSObjectFlags::TYPE_PARAMETER); - param_type->SetVariable(param->Variable()); + ETSObjectType *param_type = SetUpParameterType(param); + if (param->Constraint() == nullptr) { + // No constraint, so it's Object|null + param_type->SetSuperType(instantiate_supertype(TypeFlag::NULLISH)); + } - if (param->Constraint() != nullptr) { - if (param->Constraint()->IsETSTypeReference() && - param->Constraint()->AsETSTypeReference()->Part()->Name()->IsIdentifier() && - param->Name()->Name() == - param->Constraint()->AsETSTypeReference()->Part()->Name()->AsIdentifier()->Name()) { - ThrowTypeError({"Type variable '", param->Name()->Name(), "' cannot depend on itself"}, - param->Constraint()->Start()); - } + return param_type; +} + +void ETSChecker::SetUpTypeParameterConstraint(ir::TSTypeParameter *const param) +{ + auto const instantiate_supertype = [this](TypeFlag nullish_flags) { + return CreateNullishType(GlobalETSObjectType(), nullish_flags, Allocator(), Relation(), GetGlobalTypesHolder()) + ->AsETSObjectType(); + }; + ETSObjectType *param_type = nullptr; + if (param->Name()->Variable()->TsType() == nullptr) { + param_type = SetUpParameterType(param); + } else { + param_type = param->Name()->Variable()->TsType()->AsETSObjectType(); + } + if (param->Constraint() != nullptr) { if (param->Constraint()->IsETSTypeReference()) { const auto constraint_name = param->Constraint()->AsETSTypeReference()->Part()->Name()->AsIdentifier()->Name(); const auto *const type_param_scope = param->Parent()->AsTSTypeParameterDeclaration()->Scope(); - if (auto *const found_param = type_param_scope->FindLocal(constraint_name, varbinder::ResolveBindingOptions::BINDINGS); found_param != nullptr) { - CreateTypeParameterType(found_param->Declaration()->Node()->AsTSTypeParameter()); + SetUpTypeParameterConstraint(found_param->Declaration()->Node()->AsTSTypeParameter()); } } @@ -233,7 +283,16 @@ Type *ETSChecker::CreateTypeParameterType(ir::TSTypeParameter *const param) // No constraint, so it's Object|null|undefined param_type->SetSuperType(instantiate_supertype(TypeFlag::NULLISH)); } +} +ETSObjectType *ETSChecker::SetUpParameterType(ir::TSTypeParameter *const param) +{ + ETSObjectType *param_type = + CreateNewETSObjectType(param->Name()->Name(), param, GlobalETSObjectType()->ObjectFlags()); + param_type->SetAssemblerName(GlobalETSObjectType()->AssemblerName()); + param_type->AddTypeFlag(TypeFlag::GENERIC); + param_type->AddObjectFlag(ETSObjectFlags::TYPE_PARAMETER); + param_type->SetVariable(param->Variable()); SetTypeParameterType(param, param_type); return param_type; } diff --git a/ets2panda/checker/ets/typeCreation.cpp b/ets2panda/checker/ets/typeCreation.cpp index 03be8f6bda655f04b4c21ddc1fdb27d9c413541e..bd75518d922c69b2a3d709a03d875c158a023f12 100644 --- a/ets2panda/checker/ets/typeCreation.cpp +++ b/ets2panda/checker/ets/typeCreation.cpp @@ -143,6 +143,7 @@ Type *ETSChecker::CreateETSUnionType(ArenaVector &&constituent_types) } auto *new_union_type = Allocator()->New(std::move(new_constituent_types)); + new_union_type->SetLeastUpperBoundType(this); return ETSUnionType::HandleUnionType(new_union_type); } diff --git a/ets2panda/checker/ets/typeRelationContext.cpp b/ets2panda/checker/ets/typeRelationContext.cpp index ee23d08854063b5e52316957947e01388f42bee9..b89612f33a37925d9309f4b441c900b639d1bce8 100644 --- a/ets2panda/checker/ets/typeRelationContext.cpp +++ b/ets2panda/checker/ets/typeRelationContext.cpp @@ -39,30 +39,36 @@ bool InstantiationContext::ValidateTypeArguments(ETSObjectType *type, ir::TSType ir::TSTypeParameterInstantiation *type_args, const lexer::SourcePosition &pos) { - if (type_param_decl != nullptr && type_args == nullptr) { - checker_->ThrowTypeError({"Type '", type, "' is generic but type argument were not provided."}, pos); - } - - if (type_param_decl == nullptr && type_args != nullptr) { - checker_->ThrowTypeError({"Type '", type, "' is not generic."}, pos); - } + checker_->CheckNumberOfTypeArguments(type, type_param_decl, type_args, pos); if (type_args == nullptr) { result_ = type; return true; } - ASSERT(type_param_decl != nullptr && type_args != nullptr); - if (type_param_decl->Params().size() != type_args->Params().size()) { - checker_->ThrowTypeError({"Type '", type, "' has ", type_param_decl->Params().size(), - " number of type parameters, but ", type_args->Params().size(), - " type arguments were provided."}, - pos); + auto *substitution = checker_->NewSubstitution(); + /* + The first loop is to create a substitution of type_params & type_args. + so that we can replace the type_params in constaints by the right type. + e.g: + class X ,T> {} + function main(){ + const myCharClass = new X(); + } + In the case above, the constraints_substitution should store "K->Char" and "T->String". + And in the second loop, we use this substitution to replace type_params in constraints. + In this case, we will check "Comparable" with "Char", since "Char" doesn't + extends "Comparable", we will get an error here. + */ + for (size_t type_param_iter = 0; type_param_iter < type_param_decl->Params().size(); ++type_param_iter) { + auto *const type_arg_type = type_args->Params().at(type_param_iter)->GetType(checker_); + checker_->CheckValidGenericTypeParameter(type_arg_type, pos); + auto *const type_param_type = type->TypeArguments().at(type_param_iter); + substitution->emplace(type_param_type, type_arg_type); } for (size_t type_param_iter = 0; type_param_iter < type_param_decl->Params().size(); ++type_param_iter) { - auto *const param_type = type_args->Params().at(type_param_iter)->GetType(checker_); - checker_->CheckValidGenericTypeParameter(param_type, pos); + auto *const type_arg_type = type_args->Params().at(type_param_iter)->GetType(checker_); auto *const type_param_constraint = type_param_decl->Params().at(type_param_iter)->AsTSTypeParameter()->Constraint(); if (type_param_constraint == nullptr) { @@ -71,10 +77,15 @@ bool InstantiationContext::ValidateTypeArguments(ETSObjectType *type, ir::TSType bool assignable = false; auto *constraint_type = type_param_constraint->GetType(checker_); - if (constraint_type->IsETSObjectType() && param_type->IsETSObjectType()) { - assignable = ValidateTypeArg(constraint_type->AsETSObjectType(), param_type->AsETSObjectType()); - } else if (param_type->IsETSUnionType() && !constraint_type->IsETSUnionType()) { - auto constituent_types = param_type->AsETSUnionType()->ConstituentTypes(); + + if (!constraint_type->AsETSObjectType()->TypeArguments().empty()) { + constraint_type = constraint_type->Substitute(checker_->Relation(), substitution); + } + + if (constraint_type->IsETSObjectType() && type_arg_type->IsETSObjectType()) { + assignable = ValidateTypeArg(constraint_type->AsETSObjectType(), type_arg_type->AsETSObjectType()); + } else if (type_arg_type->IsETSUnionType() && !constraint_type->IsETSUnionType()) { + auto constituent_types = type_arg_type->AsETSUnionType()->ConstituentTypes(); assignable = std::all_of(constituent_types.begin(), constituent_types.end(), [this, constraint_type](Type *c_type) { return c_type->IsETSObjectType() && @@ -83,7 +94,7 @@ bool InstantiationContext::ValidateTypeArguments(ETSObjectType *type, ir::TSType } if (!assignable) { - checker_->ThrowTypeError({"Type '", param_type->AsETSObjectType(), + checker_->ThrowTypeError({"Type '", type_arg_type->AsETSObjectType(), "' is not assignable to constraint type '", constraint_type, "'."}, type_args->Params().at(type_param_iter)->Start()); } @@ -146,17 +157,23 @@ void InstantiationContext::InstantiateType(ETSObjectType *type, ArenaVectorNewSubstitution(); + auto *constraints_substitution = checker_->NewSubstitution(); + for (size_t ix = 0; ix < type_params.size(); ix++) { + constraints_substitution->emplace(type_params[ix], type_arg_types[ix]); + } for (size_t ix = 0; ix < type_params.size(); ix++) { auto *type_param = type_params[ix]; bool is_compatible_type_arg; if (type_arg_types[ix]->IsETSUnionType()) { auto union_constituent_types = type_arg_types[ix]->AsETSUnionType()->ConstituentTypes(); is_compatible_type_arg = std::all_of(union_constituent_types.begin(), union_constituent_types.end(), - [this, type_param](Type *type_arg) { - return checker_->IsCompatibleTypeArgument(type_param, type_arg); + [this, type_param, constraints_substitution](Type *type_arg) { + return checker_->IsCompatibleTypeArgument( + type_param, type_arg, constraints_substitution); }); } else { - is_compatible_type_arg = checker_->IsCompatibleTypeArgument(type_param, type_arg_types[ix]); + is_compatible_type_arg = + checker_->IsCompatibleTypeArgument(type_param, type_arg_types[ix], constraints_substitution); } if (!is_compatible_type_arg) { checker_->ThrowTypeError( diff --git a/ets2panda/checker/types/ets/etsEnumType.h b/ets2panda/checker/types/ets/etsEnumType.h index fb9cc0debb0d67eb05482c3e70aaa8cb8b3a9d14..094790cab810693b05b43465b02c8f352890d96a 100644 --- a/ets2panda/checker/types/ets/etsEnumType.h +++ b/ets2panda/checker/types/ets/etsEnumType.h @@ -138,6 +138,11 @@ public: from_int_method_ = method; } + std::tuple ResolveConditionExpr() const override + { + return {true, !GetMembers().empty()}; + } + private: const ir::TSEnumDeclaration *decl_; const UType ordinal_; diff --git a/ets2panda/checker/types/ets/etsFunctionType.cpp b/ets2panda/checker/types/ets/etsFunctionType.cpp index b67c53ca99d7394fc16a3659e7ed87f311f20174..9a62df6fc07588558a55afb6c5f870036ffa4a2c 100644 --- a/ets2panda/checker/types/ets/etsFunctionType.cpp +++ b/ets2panda/checker/types/ets/etsFunctionType.cpp @@ -70,21 +70,9 @@ bool ETSFunctionType::AssignmentSource(TypeRelation *relation, Type *target) return false; } -void ETSFunctionType::AssignmentTarget(TypeRelation *relation, Type *source) +static Signature *ProcessSignatures(TypeRelation *relation, Signature *target, ETSFunctionType *source_func_type) { - if (!source->IsETSFunctionType() && - (!source->IsETSObjectType() || !source->AsETSObjectType()->HasObjectFlag(ETSObjectFlags::FUNCTIONAL))) { - return; - } - - ASSERT(call_signatures_.size() == 1 && call_signatures_[0]->HasSignatureFlag(SignatureFlags::TYPE)); - - Signature *target = call_signatures_[0]; Signature *match {}; - bool source_is_functional = source->IsETSObjectType(); - auto *source_func_type = source_is_functional ? source->AsETSObjectType()->GetFunctionalInterfaceInvokeType() - : source->AsETSFunctionType(); - for (auto *it : source_func_type->CallSignatures()) { if (target->MinArgCount() != it->MinArgCount()) { continue; @@ -97,15 +85,16 @@ void ETSFunctionType::AssignmentTarget(TypeRelation *relation, Type *source) if (!it->GetSignatureInfo()->type_params.empty()) { auto *substitution = relation->GetChecker()->AsETSChecker()->NewSubstitution(); + auto *instantiated_type_params = relation->GetChecker()->AsETSChecker()->NewInstantiatedTypeParamsSet(); for (size_t ix = 0; ix < target->MinArgCount(); ix++) { relation->GetChecker()->AsETSChecker()->EnhanceSubstitutionForType( it->GetSignatureInfo()->type_params, it->GetSignatureInfo()->params[ix]->TsType(), - target->GetSignatureInfo()->params[ix]->TsType(), substitution); + target->GetSignatureInfo()->params[ix]->TsType(), substitution, instantiated_type_params); } if (target->RestVar() != nullptr) { relation->GetChecker()->AsETSChecker()->EnhanceSubstitutionForType( it->GetSignatureInfo()->type_params, it->RestVar()->TsType(), target->RestVar()->TsType(), - substitution); + substitution, instantiated_type_params); } it = it->Substitute(relation, substitution); } @@ -133,6 +122,23 @@ void ETSFunctionType::AssignmentTarget(TypeRelation *relation, Type *source) match = it; break; } + return match; +} + +void ETSFunctionType::AssignmentTarget(TypeRelation *relation, Type *source) +{ + if (!source->IsETSFunctionType() && + (!source->IsETSObjectType() || !source->AsETSObjectType()->HasObjectFlag(ETSObjectFlags::FUNCTIONAL))) { + return; + } + + ASSERT(call_signatures_.size() == 1 && call_signatures_[0]->HasSignatureFlag(SignatureFlags::TYPE)); + + Signature *target = call_signatures_[0]; + bool source_is_functional = source->IsETSObjectType(); + auto *source_func_type = source_is_functional ? source->AsETSObjectType()->GetFunctionalInterfaceInvokeType() + : source->AsETSFunctionType(); + Signature *match = ProcessSignatures(relation, target, source_func_type); if (match == nullptr) { relation->Result(false); diff --git a/ets2panda/checker/types/ets/etsObjectType.cpp b/ets2panda/checker/types/ets/etsObjectType.cpp index 7d060c93c57c08edf186bd7416ed5a972c78443b..6c6435e7ecf83b47ad4a82337e9bd7616fd17431 100644 --- a/ets2panda/checker/types/ets/etsObjectType.cpp +++ b/ets2panda/checker/types/ets/etsObjectType.cpp @@ -762,7 +762,6 @@ Type *ETSObjectType::Instantiate(ArenaAllocator *const allocator, TypeRelation * for (auto *const type_argument : TypeArguments()) { copied_type->TypeArguments().emplace_back(type_argument->Instantiate(allocator, relation, global_types)); } - copied_type->SetBaseType(this); copied_type->properties_instantiated_ = false; copied_type->relation_ = relation; diff --git a/ets2panda/checker/types/ets/etsObjectType.h b/ets2panda/checker/types/ets/etsObjectType.h index a083979f86ffc07384e9df0e89b9a2a70409e337..391f54588ce9e0207ca381430e9c5e70461a690b 100644 --- a/ets2panda/checker/types/ets/etsObjectType.h +++ b/ets2panda/checker/types/ets/etsObjectType.h @@ -512,11 +512,7 @@ public: std::tuple ResolveConditionExpr() const override { - if (IsNullish() || IsETSStringType()) { - return {false, false}; - } - - return {true, true}; + return {false, false}; } protected: diff --git a/ets2panda/checker/types/ets/etsUnionType.cpp b/ets2panda/checker/types/ets/etsUnionType.cpp index cca516221ff77316e6c1f90d04713203c8de2161..b3335689a18c33baa4b690a8167e8452716399ba 100644 --- a/ets2panda/checker/types/ets/etsUnionType.cpp +++ b/ets2panda/checker/types/ets/etsUnionType.cpp @@ -19,6 +19,7 @@ #include "checker/ets/conversion.h" #include "checker/types/globalTypesHolder.h" #include "checker/ETSchecker.h" +#include "ir/astNode.h" namespace panda::es2panda::checker { void ETSUnionType::ToString(std::stringstream &ss) const @@ -26,11 +27,16 @@ void ETSUnionType::ToString(std::stringstream &ss) const for (auto it = constituent_types_.begin(); it != constituent_types_.end(); it++) { (*it)->ToString(ss); if (std::next(it) != constituent_types_.end()) { - ss << " | "; + ss << "|"; } } } +void ETSUnionType::ToAssemblerType(std::stringstream &ss) const +{ + ss << compiler::Signatures::BUILTIN_OBJECT; +} + bool ETSUnionType::EachTypeRelatedToSomeType(TypeRelation *relation, ETSUnionType *source, ETSUnionType *target) { return std::all_of(source->constituent_types_.begin(), source->constituent_types_.end(), @@ -43,7 +49,7 @@ bool ETSUnionType::TypeRelatedToSomeType(TypeRelation *relation, Type *source, E [relation, source](auto *t) { return relation->IsIdenticalTo(source, t); }); } -Type *ETSUnionType::GetLeastUpperBoundType(ETSChecker *checker) +void ETSUnionType::SetLeastUpperBoundType(ETSChecker *checker) { ASSERT(constituent_types_.size() > 1); if (lub_type_ == nullptr) { @@ -51,12 +57,11 @@ Type *ETSUnionType::GetLeastUpperBoundType(ETSChecker *checker) for (auto *t : constituent_types_) { if (!t->HasTypeFlag(TypeFlag::ETS_ARRAY_OR_OBJECT)) { lub_type_ = checker->GetGlobalTypesHolder()->GlobalETSObjectType(); - return lub_type_; + return; } lub_type_ = checker->FindLeastUpperBound(lub_type_, t); } } - return lub_type_; } void ETSUnionType::Identical(TypeRelation *relation, Type *other) @@ -86,10 +91,21 @@ bool ETSUnionType::AssignmentSource(TypeRelation *relation, Type *target) void ETSUnionType::AssignmentTarget(TypeRelation *relation, Type *source) { - auto *const ref_source = source->HasTypeFlag(checker::TypeFlag::ETS_PRIMITIVE) - ? relation->GetChecker()->AsETSChecker()->PrimitiveTypeAsETSBuiltinType(source) - : source; - + auto *const checker = relation->GetChecker()->AsETSChecker(); + auto *const ref_source = + source->HasTypeFlag(TypeFlag::ETS_PRIMITIVE) ? checker->PrimitiveTypeAsETSBuiltinType(source) : source; + auto exact_type = std::find_if( + constituent_types_.begin(), constituent_types_.end(), [checker, relation, source, ref_source](Type *ct) { + if (ct == ref_source && source->HasTypeFlag(TypeFlag::ETS_PRIMITIVE) && ct->IsETSObjectType() && + ct->AsETSObjectType()->HasObjectFlag(ETSObjectFlags::UNBOXABLE_TYPE)) { + relation->GetNode()->SetBoxingUnboxingFlags(checker->GetBoxingFlag(ct)); + return relation->IsAssignableTo(ref_source, ct); + } + return false; + }); + if (exact_type != constituent_types_.end()) { + return; + } for (auto *it : constituent_types_) { if (relation->IsAssignableTo(ref_source, it)) { if (ref_source != source) { @@ -98,6 +114,18 @@ void ETSUnionType::AssignmentTarget(TypeRelation *relation, Type *source) } return; } + bool assign_primitive = it->IsETSObjectType() && + it->AsETSObjectType()->HasObjectFlag(ETSObjectFlags::UNBOXABLE_TYPE) && + source->HasTypeFlag(TypeFlag::ETS_PRIMITIVE); + if (assign_primitive && relation->IsAssignableTo(source, checker->ETSBuiltinTypeAsPrimitiveType(it))) { + Type *unboxed_it = checker->ETSBuiltinTypeAsPrimitiveType(it); + if (unboxed_it != source) { + relation->GetNode()->SetBoxingUnboxingFlags(checker->GetBoxingFlag(it)); + source->Cast(relation, unboxed_it); + ASSERT(relation->IsTrue()); + } + return; + } } } @@ -124,21 +152,32 @@ Type *ETSUnionType::Instantiate(ArenaAllocator *allocator, TypeRelation *relatio return copied_constituents[0]; } - Type *new_union_type = allocator->New(std::move(copied_constituents)); + auto *new_union_type = allocator->New(std::move(copied_constituents)); - lub_type_ = global_types->GlobalETSObjectType(); - return HandleUnionType(new_union_type->AsETSUnionType()); + new_union_type->SetLeastUpperBoundType(relation->GetChecker()->AsETSChecker()); + return HandleUnionType(new_union_type); } void ETSUnionType::Cast(TypeRelation *relation, Type *target) { - auto *const ref_target = target->HasTypeFlag(checker::TypeFlag::ETS_PRIMITIVE) - ? relation->GetChecker()->AsETSChecker()->PrimitiveTypeAsETSBuiltinType(target) - : target; - + auto *const checker = relation->GetChecker()->AsETSChecker(); + auto *const ref_target = + target->HasTypeFlag(checker::TypeFlag::ETS_PRIMITIVE) ? checker->PrimitiveTypeAsETSBuiltinType(target) : target; + auto exact_type = std::find_if(constituent_types_.begin(), constituent_types_.end(), + [this, checker, relation, ref_target](Type *src) { + if (src == ref_target && relation->IsCastableTo(src, ref_target)) { + GetLeastUpperBoundType(checker)->Cast(relation, ref_target); + ASSERT(relation->IsTrue()); + return true; + } + return false; + }); + if (exact_type != constituent_types_.end()) { + return; + } for (auto *source : constituent_types_) { if (relation->IsCastableTo(source, ref_target)) { - GetLeastUpperBoundType(relation->GetChecker()->AsETSChecker())->Cast(relation, ref_target); + GetLeastUpperBoundType(checker)->Cast(relation, ref_target); ASSERT(relation->IsTrue()); if (ref_target != target) { source->Cast(relation, target); @@ -147,6 +186,13 @@ void ETSUnionType::Cast(TypeRelation *relation, Type *target) } return; } + bool cast_primitive = source->IsETSObjectType() && + source->AsETSObjectType()->HasObjectFlag(ETSObjectFlags::UNBOXABLE_TYPE) && + target->HasTypeFlag(TypeFlag::ETS_PRIMITIVE); + if (cast_primitive && relation->IsCastableTo(checker->ETSBuiltinTypeAsPrimitiveType(source), target)) { + ASSERT(relation->IsTrue()); + return; + } } conversion::Forbidden(relation); @@ -241,9 +287,36 @@ Type *ETSUnionType::FindTypeIsCastableToSomeType(ir::Expression *node, TypeRelat return nullptr; } -void ETSUnionType::ToAssemblerType(std::stringstream &ss) const +Type *ETSUnionType::FindUnboxableType() const { - ss << compiler::Signatures::BUILTIN_OBJECT; + auto it = std::find_if(constituent_types_.begin(), constituent_types_.end(), + [](Type *t) { return t->AsETSObjectType()->HasObjectFlag(ETSObjectFlags::UNBOXABLE_TYPE); }); + if (it != constituent_types_.end()) { + return *it; + } + return nullptr; +} + +bool ETSUnionType::HasObjectType(ETSObjectFlags flag) const +{ + auto it = std::find_if(constituent_types_.begin(), constituent_types_.end(), + [flag](Type *t) { return t->AsETSObjectType()->HasObjectFlag(flag); }); + return it != constituent_types_.end(); +} + +Type *ETSUnionType::FindExactOrBoxedType(ETSChecker *checker, Type *const type) const +{ + auto it = std::find_if(constituent_types_.begin(), constituent_types_.end(), [checker, type](Type *ct) { + if (ct->IsETSObjectType() && ct->AsETSObjectType()->HasObjectFlag(ETSObjectFlags::UNBOXABLE_TYPE)) { + auto *const unboxed_ct = checker->ETSBuiltinTypeAsPrimitiveType(ct); + return unboxed_ct == type; + } + return ct == type; + }); + if (it != constituent_types_.end()) { + return *it; + } + return nullptr; } } // namespace panda::es2panda::checker diff --git a/ets2panda/checker/types/ets/etsUnionType.h b/ets2panda/checker/types/ets/etsUnionType.h index 728c05665b8f285a32825e73fbd3df81cc61080d..ce032fcef4712cb86bab8f42048c78a0057a698d 100644 --- a/ets2panda/checker/types/ets/etsUnionType.h +++ b/ets2panda/checker/types/ets/etsUnionType.h @@ -17,6 +17,7 @@ #define ES2PANDA_COMPILER_CHECKER_TYPES_ETS_UNION_TYPE_H #include "checker/types/type.h" +#include "checker/types/ets/etsObjectType.h" namespace panda::es2panda::checker { class GlobalTypesHolder; @@ -60,6 +61,7 @@ public: } void ToString(std::stringstream &ss) const override; + void ToAssemblerType(std::stringstream &ss) const override; void Identical(TypeRelation *relation, Type *other) override; void AssignmentTarget(TypeRelation *relation, Type *source) override; bool AssignmentSource(TypeRelation *relation, Type *target) override; @@ -68,10 +70,18 @@ public: void CastToThis(TypeRelation *relation, Type *source); Type *FindTypeIsCastableToThis(ir::Expression *node, TypeRelation *relation, Type *source) const; Type *FindTypeIsCastableToSomeType(ir::Expression *node, TypeRelation *relation, Type *target) const; + Type *FindUnboxableType() const; - void ToAssemblerType(std::stringstream &ss) const override; + void SetLeastUpperBoundType(ETSChecker *checker); - Type *GetLeastUpperBoundType(ETSChecker *checker); + Type *GetLeastUpperBoundType(ETSChecker *checker) + { + if (lub_type_ == nullptr) { + SetLeastUpperBoundType(checker); + } + ASSERT(lub_type_ != nullptr); + return lub_type_; + } Type *GetLeastUpperBoundType() const { @@ -79,8 +89,22 @@ public: return lub_type_; } + bool HasObjectType(ETSObjectFlags flag) const; + + Type *FindExactOrBoxedType(ETSChecker *checker, Type *type) const; + static Type *HandleUnionType(ETSUnionType *union_type); + std::tuple ResolveConditionExpr() const override + { + for (auto tp : ConstituentTypes()) { + if (!tp->IsConditionalExprType()) { + return {true, false}; + } + } + return {true, true}; + } + private: static bool EachTypeRelatedToSomeType(TypeRelation *relation, ETSUnionType *source, ETSUnionType *target); static bool TypeRelatedToSomeType(TypeRelation *relation, Type *source, ETSUnionType *target); diff --git a/ets2panda/checker/types/signature.cpp b/ets2panda/checker/types/signature.cpp index ab2188c6c0b438324f968af76af314a0ccda0cf7..8bb01344d60925b768eb5867d7d7b09097cdfe10 100644 --- a/ets2panda/checker/types/signature.cpp +++ b/ets2panda/checker/types/signature.cpp @@ -84,7 +84,7 @@ Signature *Signature::Substitute(TypeRelation *relation, const Substitution *sub if (!any_change) { return this; } - auto *result = allocator->New(new_sig_info, new_return_type); + auto *result = allocator->New(new_sig_info, new_return_type, this); result->func_ = func_; result->flags_ = flags_; result->internal_name_ = internal_name_; @@ -172,12 +172,44 @@ void Signature::ToString(std::stringstream &ss, const varbinder::Variable *varia return_type_->ToString(ss); } +namespace { +std::size_t GetToCheckParamCount(Signature *signature, bool is_ets) +{ + auto param_number = static_cast(signature->Params().size()); + if (!is_ets || signature->Function() == nullptr) { + return param_number; + } + for (auto i = param_number - 1; i >= 0; i--) { + if (!signature->Function()->Params()[i]->AsETSParameterExpression()->IsDefault()) { + return static_cast(i + 1); + } + } + return 0; +} +} // namespace + +bool Signature::IdenticalParameter(TypeRelation *relation, Type *type1, Type *type2) +{ + if (!CheckFunctionalInterfaces(relation, type1, type2)) { + relation->IsIdenticalTo(type1, type2); + } + return relation->IsTrue(); +} + void Signature::Identical(TypeRelation *relation, Signature *other) { - if ((this->MinArgCount() != other->MinArgCount() || this->Params().size() != other->Params().size()) && + bool is_ets = relation->GetChecker()->IsETSChecker(); + auto const this_to_check_parameters_number = GetToCheckParamCount(this, is_ets); + auto const other_to_check_parameters_number = GetToCheckParamCount(other, is_ets); + if ((this_to_check_parameters_number != other_to_check_parameters_number || + this->MinArgCount() != other->MinArgCount()) && this->RestVar() == nullptr && other->RestVar() == nullptr) { - relation->Result(false); - return; + // skip check for ets cases only when all parameters are mandatory + if (!is_ets || (this_to_check_parameters_number == this->Params().size() && + other_to_check_parameters_number == other->Params().size())) { + relation->Result(false); + return; + } } if (relation->NoReturnTypeCheck()) { @@ -187,51 +219,63 @@ void Signature::Identical(TypeRelation *relation, Signature *other) } if (relation->IsTrue()) { - // Lambda to check parameter types - auto const identical_parameters = [this, relation](checker::Type *const type1, - checker::Type *const type2) -> bool { - if (!CheckFunctionalInterfaces(relation, type1, type2)) { - relation->IsIdenticalTo(type1, type2); - } - return relation->IsTrue(); - }; - - auto const this_parameters_number = this->Params().size(); - auto const other_parameters_number = other->Params().size(); - auto const parameters_number = std::min(this_parameters_number, other_parameters_number); + /* In ETS, the functions "foo(a: int)" and "foo(a: int, b: int = 1)" should be considered as having an + equivalent signature. Hence, we only need to check if the mandatory parameters of the signature with + more mandatory parameters can match the parameters of the other signature (including the optional + parameter or rest parameters) here. + + XXX_to_check_parameters_number is calculated beforehand by counting mandatory parameters. + Signature::params() stores all parameters (mandatory and optional), excluding the rest parameter. + Signature::restVar() stores the rest parameters of the function. + + For example: + foo(a: int): params().size: 1, to_check_param_number: 1, restVar: nullptr + foo(a: int, b: int = 0): params().size: 2, to_check_param_number: 1, restVar: nullptr + foo(a: int, ...b: int[]): params().size: 1, to_check_param_number: 1, restVar: ...b: int[] + + Note that optional parameters always come after mandatory parameters, and signatures containing both + optional and rest parameters are not allowed. + + "to_check_parameters_number" is the number of parameters that need to be checked to ensure identical. + "parameters_number" is the number of parameters that can be checked in Signature::params(). + */ + auto const to_check_parameters_number = + std::max(this_to_check_parameters_number, other_to_check_parameters_number); + auto const parameters_number = + std::min({this->Params().size(), other->Params().size(), to_check_parameters_number}); std::size_t i = 0U; for (; i < parameters_number; ++i) { - auto *const this_sig_param_type = this->Params()[i]->TsType(); - auto *const other_sig_param_type = other->Params()[i]->TsType(); - if (!identical_parameters(this_sig_param_type, other_sig_param_type)) { + if (!IdenticalParameter(relation, this->Params()[i]->TsType(), other->Params()[i]->TsType())) { return; } } - // Lambda to check the rest parameters - auto const identical_rest_parameters = - [&i, &identical_parameters, relation](std::size_t const parameter_number, - ArenaVector const ¶meters, - varbinder::LocalVariable const *const rest_parameter) -> void { - if (rest_parameter != nullptr) { - auto *const other_sig_param_type = rest_parameter->TsType()->AsETSArrayType()->ElementType(); - - for (; i < parameter_number; ++i) { - auto *const this_sig_param_type = parameters[i]->TsType(); - if (!identical_parameters(this_sig_param_type, other_sig_param_type)) { - break; - } - } - } else { - relation->Result(false); + /* "i" could be one of the following three cases: + 1. == to_check_parameters_number, we have finished the checking and can directly return. + 2. == other->Params().size(), must be < this_to_check_parameters_number in this case since + xxx->Params().size() always >= xxx_to_check_parameters_number. We need to check the remaining + mandatory parameters of "this" against ths RestVar of "other". + 3. == this->Params().size(), must be < other_to_check_parameters_number as described in 2, and + we need to check the remaining mandatory parameters of "other" against the RestVar of "this". + */ + if (i == to_check_parameters_number) { + return; + } + bool is_other_mandatory_params_matched = i < this_to_check_parameters_number; + ArenaVector const ¶meters = + is_other_mandatory_params_matched ? this->Params() : other->Params(); + varbinder::LocalVariable const *rest_parameter = + is_other_mandatory_params_matched ? other->RestVar() : this->RestVar(); + if (rest_parameter == nullptr) { + relation->Result(false); + return; + } + auto *const rest_parameter_type = rest_parameter->TsType()->AsETSArrayType()->ElementType(); + for (; i < to_check_parameters_number; ++i) { + if (!IdenticalParameter(relation, parameters[i]->TsType(), rest_parameter_type)) { + return; } - }; - - if (i < this_parameters_number) { - identical_rest_parameters(this_parameters_number, this->Params(), other->RestVar()); - } else if (i < other_parameters_number) { - identical_rest_parameters(other_parameters_number, other->Params(), this->RestVar()); } } } @@ -298,4 +342,12 @@ void Signature::AssignmentTarget(TypeRelation *relation, Signature *source) relation->IsAssignableTo(source->RestVar()->TsType(), signature_info_->rest_var->TsType()); } } + +bool Signature::IsBaseReturnDiff() const +{ + if (base_sig_ == nullptr) { + return false; + } + return ReturnType()->ToAssemblerName().str() != base_sig_->ReturnType()->ToAssemblerName().str(); +} } // namespace panda::es2panda::checker diff --git a/ets2panda/checker/types/signature.h b/ets2panda/checker/types/signature.h index 2341dd57456f0972044b51d5a2a87dba7cce9f97..308640890203d300622899263794c8f6a6c1d539 100644 --- a/ets2panda/checker/types/signature.h +++ b/ets2panda/checker/types/signature.h @@ -79,7 +79,6 @@ enum class SignatureFlags : uint32_t { INTERNAL = 1U << 12U, NEED_RETURN_TYPE = 1U << 13U, INFERRED_RETURN_TYPE = 1U << 14U, - SUBSTITUTED_RETURN_TYPE = 1U << 15U, INTERNAL_PROTECTED = INTERNAL | PROTECTED, FUNCTIONAL_INTERFACE_SIGNATURE = VIRTUAL | ABSTRACT | CALL | PUBLIC | TYPE @@ -89,8 +88,8 @@ DEFINE_BITOPS(SignatureFlags) class Signature { public: - Signature(SignatureInfo *signature_info, Type *return_type) - : signature_info_(signature_info), return_type_(return_type) + Signature(SignatureInfo *signature_info, Type *return_type, Signature *base_sig = nullptr) + : signature_info_(signature_info), return_type_(return_type), base_sig_(base_sig) { } @@ -221,6 +220,8 @@ public: return (flags_ & flag) != 0U; } + bool IsBaseReturnDiff() const; + bool IsFinal() const noexcept { return HasSignatureFlag(SignatureFlags::FINAL); @@ -250,6 +251,7 @@ public: void AssignmentTarget(TypeRelation *relation, Signature *source); private: + bool IdenticalParameter(TypeRelation *relation, Type *type1, Type *type2); checker::SignatureInfo *signature_info_; Type *return_type_; ir::ScriptFunction *func_ {}; @@ -257,6 +259,7 @@ private: util::StringView internal_name_ {}; ETSObjectType *owner_obj_ {}; varbinder::Variable *owner_var_ {}; + const Signature *base_sig_ = nullptr; }; } // namespace panda::es2panda::checker diff --git a/ets2panda/checker/types/type.h b/ets2panda/checker/types/type.h index 83d97754ba41ffe9b830a5ca162594f77c9dc5f6..470524b486bae04ea4ddcad1f2f1bc4a2ec4b932 100644 --- a/ets2panda/checker/types/type.h +++ b/ets2panda/checker/types/type.h @@ -207,6 +207,13 @@ public: return util::UString(ss.str(), allocator).View(); } + std::stringstream ToAssemblerName() const + { + std::stringstream ss; + ToAssemblerType(ss); + return ss; + } + bool IsLambdaObject() const; virtual void ToString(std::stringstream &ss) const = 0; virtual void ToStringAsSrc(std::stringstream &ss) const; diff --git a/ets2panda/checker/types/typeFlag.h b/ets2panda/checker/types/typeFlag.h index 7a26628209dce4b89f47d4dae61efbe9f2ad3963..58c04f812f895b62dc8f44893f4577fea54021ad 100644 --- a/ets2panda/checker/types/typeFlag.h +++ b/ets2panda/checker/types/typeFlag.h @@ -128,8 +128,8 @@ enum class TypeFlag : uint64_t { VALID_ARITHMETIC_TYPE = ANY | NUMBER_LIKE | BIGINT_LIKE | ENUM, UNIT = LITERAL | UNIQUE_SYMBOL | NULLISH, GETTER_SETTER = GETTER | SETTER, - CONDITION_EXPRESSION_TYPE = - NULLISH | CONSTANT | ETS_OBJECT | BYTE | SHORT | INT | LONG | FLOAT | DOUBLE | ETS_BOOLEAN | ETS_ARRAY + CONDITION_EXPRESSION_TYPE = NULLISH | CONSTANT | ETS_OBJECT | BYTE | SHORT | INT | LONG | FLOAT | DOUBLE | + ETS_BOOLEAN | ETS_ARRAY | ETS_ENUM | ETS_STRING_ENUM }; DEFINE_BITOPS(TypeFlag) diff --git a/ets2panda/cmake/coverage.cmake b/ets2panda/cmake/coverage.cmake index 8464c0fed8fbdeca293eb8743038231b204035f7..794bf7a6e7c226cfde314cd6b60f41f524545d3b 100644 --- a/ets2panda/cmake/coverage.cmake +++ b/ets2panda/cmake/coverage.cmake @@ -17,9 +17,13 @@ include(${PANDA_ROOT}/cmake/toolchain/coverage/unit_tests_lcov.cmake) add_custom_target(es2panda_coverage DEPENDS etsstdlib es2panda verifier ark) +if (NOT DEFINED ES2PANDA_PATH) + set(ES2PANDA_PATH ${PANDA_ROOT}/tools/es2panda) +endif() + add_custom_command(TARGET es2panda_coverage POST_BUILD WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} - COMMAND bash ${PANDA_ROOT}/plugins/ecmascript/es2panda/scripts/es2panda_coverage.sh --binary-dir=${PANDA_BINARY_ROOT} --root-dir=${PANDA_ROOT} + COMMAND bash ${ES2PANDA_PATH}/scripts/es2panda_coverage.sh --binary-dir=${PANDA_BINARY_ROOT} --root-dir=${PANDA_ROOT} ) if(ENABLE_ES2PANDA_COVERAGE) diff --git a/ets2panda/compiler/base/condition.cpp b/ets2panda/compiler/base/condition.cpp index 0331d9342c7c84029588065ec0bf8aeb442ec5be..d2abcf956930a75c6c9c30f7dae2f79f52208806 100644 --- a/ets2panda/compiler/base/condition.cpp +++ b/ets2panda/compiler/base/condition.cpp @@ -126,6 +126,67 @@ Condition::Result Condition::CheckConstantExpr(ETSGen *etsg, const ir::Expressio return Result::UNKNOWN; } +void Condition::CompileLogicalOrExpr(ETSGen *etsg, const ir::BinaryExpression *bin_expr, Label *false_label) +{ + auto ttctx = TargetTypeContext(etsg, bin_expr->OperationType()); + RegScope rs(etsg); + VReg lhs = etsg->AllocReg(); + VReg rhs = etsg->AllocReg(); + auto *return_left_label = etsg->AllocLabel(); + auto *return_right_true_label = etsg->AllocLabel(); + auto *return_right_false_label = etsg->AllocLabel(); + + bin_expr->Left()->Compile(etsg); + etsg->ApplyConversionAndStoreAccumulator(bin_expr->Left(), lhs, bin_expr->OperationType()); + etsg->ResolveConditionalResultIfTrue(bin_expr->Left(), return_left_label); + etsg->BranchIfTrue(bin_expr, return_left_label); + + bin_expr->Right()->Compile(etsg); + etsg->ApplyConversionAndStoreAccumulator(bin_expr->Right(), rhs, bin_expr->OperationType()); + etsg->ResolveConditionalResultIfFalse(bin_expr->Right(), return_right_false_label); + etsg->BranchIfFalse(bin_expr, return_right_false_label); + etsg->LoadAccumulator(bin_expr, rhs); + etsg->Branch(bin_expr, return_right_true_label); + + etsg->SetLabel(bin_expr, return_right_false_label); + etsg->LoadAccumulator(bin_expr, rhs); + etsg->Branch(bin_expr, false_label); + etsg->SetLabel(bin_expr, return_left_label); + etsg->LoadAccumulator(bin_expr, lhs); + etsg->SetLabel(bin_expr, return_right_true_label); +} + +void Condition::CompileLogicalAndExpr(ETSGen *etsg, const ir::BinaryExpression *bin_expr, Label *false_label) +{ + auto ttctx = TargetTypeContext(etsg, bin_expr->OperationType()); + RegScope rs(etsg); + VReg lhs = etsg->AllocReg(); + VReg rhs = etsg->AllocReg(); + auto *return_left_label = etsg->AllocLabel(); + auto *return_right_true_label = etsg->AllocLabel(); + auto *return_right_false_label = etsg->AllocLabel(); + + bin_expr->Left()->Compile(etsg); + etsg->ApplyConversionAndStoreAccumulator(bin_expr->Left(), lhs, bin_expr->OperationType()); + etsg->ResolveConditionalResultIfFalse(bin_expr->Left(), return_left_label); + etsg->BranchIfFalse(bin_expr, return_left_label); + + bin_expr->Right()->Compile(etsg); + etsg->ApplyConversionAndStoreAccumulator(bin_expr->Right(), rhs, bin_expr->OperationType()); + etsg->ResolveConditionalResultIfFalse(bin_expr->Right(), return_right_false_label); + etsg->BranchIfFalse(bin_expr, return_right_false_label); + etsg->LoadAccumulator(bin_expr, rhs); + etsg->Branch(bin_expr, return_right_true_label); + + etsg->SetLabel(bin_expr, return_left_label); + etsg->LoadAccumulator(bin_expr, lhs); + etsg->Branch(bin_expr, false_label); + etsg->SetLabel(bin_expr, return_right_false_label); + etsg->LoadAccumulator(bin_expr, rhs); + etsg->Branch(bin_expr, false_label); + etsg->SetLabel(bin_expr, return_right_true_label); +} + bool Condition::CompileBinaryExpr(ETSGen *etsg, const ir::BinaryExpression *bin_expr, Label *false_label) { switch (bin_expr->OperatorType()) { @@ -149,30 +210,11 @@ bool Condition::CompileBinaryExpr(ETSGen *etsg, const ir::BinaryExpression *bin_ return true; } case lexer::TokenType::PUNCTUATOR_LOGICAL_AND: { - bin_expr->Left()->Compile(etsg); - etsg->ApplyConversion(bin_expr->Left(), bin_expr->OperationType()); - etsg->ResolveConditionalResultIfFalse(bin_expr->Left(), false_label); - etsg->BranchIfFalse(bin_expr, false_label); - - bin_expr->Right()->Compile(etsg); - etsg->ApplyConversion(bin_expr->Right(), bin_expr->OperationType()); - etsg->ResolveConditionalResultIfFalse(bin_expr->Right(), false_label); - etsg->BranchIfFalse(bin_expr, false_label); + CompileLogicalAndExpr(etsg, bin_expr, false_label); return true; } case lexer::TokenType::PUNCTUATOR_LOGICAL_OR: { - auto *end_label = etsg->AllocLabel(); - - bin_expr->Left()->Compile(etsg); - etsg->ApplyConversion(bin_expr->Left(), bin_expr->OperationType()); - etsg->ResolveConditionalResultIfTrue(bin_expr->Left(), end_label); - etsg->BranchIfTrue(bin_expr, end_label); - - bin_expr->Right()->Compile(etsg); - etsg->ApplyConversion(bin_expr->Right(), bin_expr->OperationType()); - etsg->ResolveConditionalResultIfFalse(bin_expr->Right(), false_label); - etsg->BranchIfFalse(bin_expr, false_label); - etsg->SetLabel(bin_expr, end_label); + CompileLogicalOrExpr(etsg, bin_expr, false_label); return true; } default: { diff --git a/ets2panda/compiler/base/condition.h b/ets2panda/compiler/base/condition.h index 11ed9e8670ccb054d15c950f11338de275f11aa9..6380ba538ea054cc711217737c042649cfcc5ba7 100644 --- a/ets2panda/compiler/base/condition.h +++ b/ets2panda/compiler/base/condition.h @@ -40,6 +40,8 @@ public: private: static bool CompileBinaryExpr(PandaGen *pg, const ir::BinaryExpression *bin_expr, Label *false_label); static bool CompileBinaryExpr(ETSGen *etsg, const ir::BinaryExpression *bin_expr, Label *false_label); + static void CompileLogicalAndExpr(ETSGen *etsg, const ir::BinaryExpression *bin_expr, Label *false_label); + static void CompileLogicalOrExpr(ETSGen *etsg, const ir::BinaryExpression *bin_expr, Label *false_label); }; } // namespace panda::es2panda::compiler diff --git a/ets2panda/compiler/core/ETSCompiler.cpp b/ets2panda/compiler/core/ETSCompiler.cpp index 46dd096ae82d9c812db8af28704dee330951bdcd..017fb37d608046bc0a8c45cc2d36d51cfd71c3be 100644 --- a/ets2panda/compiler/core/ETSCompiler.cpp +++ b/ets2panda/compiler/core/ETSCompiler.cpp @@ -19,6 +19,7 @@ #include "compiler/base/condition.h" #include "compiler/base/lreference.h" #include "compiler/core/ETSGen.h" +#include "compiler/core/switchBuilder.h" #include "compiler/function/functionBuilder.h" namespace panda::es2panda::compiler { @@ -86,27 +87,23 @@ void ETSCompiler::Compile([[maybe_unused]] const ir::Decorator *st) const UNREACHABLE(); } -void ETSCompiler::Compile(const ir::MetaProperty *expr) const +void ETSCompiler::Compile([[maybe_unused]] const ir::MetaProperty *expr) const { - (void)expr; UNREACHABLE(); } -void ETSCompiler::Compile(const ir::MethodDefinition *node) const +void ETSCompiler::Compile([[maybe_unused]] const ir::MethodDefinition *node) const { - (void)node; UNREACHABLE(); } -void ETSCompiler::Compile(const ir::Property *expr) const +void ETSCompiler::Compile([[maybe_unused]] const ir::Property *expr) const { - (void)expr; UNREACHABLE(); } -void ETSCompiler::Compile(const ir::ScriptFunction *node) const +void ETSCompiler::Compile([[maybe_unused]] const ir::ScriptFunction *node) const { - (void)node; UNREACHABLE(); } @@ -118,25 +115,22 @@ void ETSCompiler::Compile(const ir::SpreadElement *expr) const void ETSCompiler::Compile(const ir::TemplateElement *expr) const { - (void)expr; - UNREACHABLE(); + ETSGen *etsg = GetETSGen(); + etsg->LoadAccumulatorString(expr, expr->Raw()); } -void ETSCompiler::Compile(const ir::TSIndexSignature *node) const +void ETSCompiler::Compile([[maybe_unused]] const ir::TSIndexSignature *node) const { - (void)node; UNREACHABLE(); } -void ETSCompiler::Compile(const ir::TSMethodSignature *node) const +void ETSCompiler::Compile([[maybe_unused]] const ir::TSMethodSignature *node) const { - (void)node; UNREACHABLE(); } -void ETSCompiler::Compile(const ir::TSPropertySignature *node) const +void ETSCompiler::Compile([[maybe_unused]] const ir::TSPropertySignature *node) const { - (void)node; UNREACHABLE(); } @@ -270,49 +264,367 @@ void ETSCompiler::Compile(const ir::AssignmentExpression *expr) const void ETSCompiler::Compile(const ir::AwaitExpression *expr) const { - (void)expr; - UNREACHABLE(); + ETSGen *etsg = GetETSGen(); + static constexpr bool IS_UNCHECKED_CAST = false; + compiler::RegScope rs(etsg); + compiler::VReg argument_reg = etsg->AllocReg(); + expr->Argument()->Compile(etsg); + etsg->StoreAccumulator(expr, argument_reg); + etsg->CallThisVirtual0(expr->Argument(), argument_reg, compiler::Signatures::BUILTIN_PROMISE_AWAIT_RESOLUTION); + etsg->CastToArrayOrObject(expr->Argument(), expr->TsType(), IS_UNCHECKED_CAST); + etsg->SetAccumulatorType(expr->TsType()); +} + +static void CompileNullishCoalescing(compiler::ETSGen *etsg, ir::BinaryExpression const *const node) +{ + auto const compile_operand = [etsg, optype = node->OperationType()](ir::Expression const *expr) { + etsg->CompileAndCheck(expr); + etsg->ApplyConversion(expr, optype); + }; + + compile_operand(node->Left()); + + if (!node->Left()->TsType()->IsNullishOrNullLike()) { + // fallthrough + } else if (node->Left()->TsType()->IsETSNullLike()) { + compile_operand(node->Right()); + } else { + auto *if_left_nullish = etsg->AllocLabel(); + auto *end_label = etsg->AllocLabel(); + + etsg->BranchIfNullish(node, if_left_nullish); + + etsg->ConvertToNonNullish(node); + etsg->ApplyConversion(node->Left(), node->OperationType()); + etsg->JumpTo(node, end_label); + + etsg->SetLabel(node, if_left_nullish); + compile_operand(node->Right()); + + etsg->SetLabel(node, end_label); + } + etsg->SetAccumulatorType(node->TsType()); +} + +static void CompileLogical(compiler::ETSGen *etsg, const ir::BinaryExpression *expr) +{ + if (expr->OperatorType() == lexer::TokenType::PUNCTUATOR_NULLISH_COALESCING) { + CompileNullishCoalescing(etsg, expr); + return; + } + + ASSERT(expr->IsLogicalExtended()); + auto ttctx = compiler::TargetTypeContext(etsg, expr->OperationType()); + compiler::RegScope rs(etsg); + auto lhs = etsg->AllocReg(); + + expr->Left()->Compile(etsg); + etsg->ApplyConversionAndStoreAccumulator(expr->Left(), lhs, expr->OperationType()); + + auto *end_label = etsg->AllocLabel(); + + auto return_left_label = etsg->AllocLabel(); + if (expr->OperatorType() == lexer::TokenType::PUNCTUATOR_LOGICAL_AND) { + etsg->ResolveConditionalResultIfFalse(expr->Left(), return_left_label); + etsg->BranchIfFalse(expr, return_left_label); + + expr->Right()->Compile(etsg); + etsg->ApplyConversion(expr->Right(), expr->OperationType()); + etsg->Branch(expr, end_label); + + etsg->SetLabel(expr, return_left_label); + etsg->LoadAccumulator(expr, lhs); + } else { + etsg->ResolveConditionalResultIfTrue(expr->Left(), return_left_label); + etsg->BranchIfTrue(expr, return_left_label); + + expr->Right()->Compile(etsg); + etsg->ApplyConversion(expr->Right(), expr->OperationType()); + etsg->Branch(expr, end_label); + + etsg->SetLabel(expr, return_left_label); + etsg->LoadAccumulator(expr, lhs); + } + + etsg->SetLabel(expr, end_label); + etsg->SetAccumulatorType(expr->TsType()); } void ETSCompiler::Compile(const ir::BinaryExpression *expr) const +{ + ETSGen *etsg = GetETSGen(); + if (etsg->TryLoadConstantExpression(expr)) { + return; + } + + auto ttctx = compiler::TargetTypeContext(etsg, expr->OperationType()); + + if (expr->IsLogical()) { + CompileLogical(etsg, expr); + etsg->ApplyConversion(expr, expr->OperationType()); + return; + } + + compiler::RegScope rs(etsg); + compiler::VReg lhs = etsg->AllocReg(); + + if (expr->OperatorType() == lexer::TokenType::PUNCTUATOR_PLUS && + (expr->Left()->TsType()->IsETSStringType() || expr->Right()->TsType()->IsETSStringType())) { + etsg->BuildString(expr); + return; + } + + expr->Left()->Compile(etsg); + etsg->ApplyConversionAndStoreAccumulator(expr->Left(), lhs, expr->OperationType()); + expr->Right()->Compile(etsg); + etsg->ApplyConversion(expr->Right(), expr->OperationType()); + if (expr->OperatorType() >= lexer::TokenType::PUNCTUATOR_LEFT_SHIFT && + expr->OperatorType() <= lexer::TokenType::PUNCTUATOR_UNSIGNED_RIGHT_SHIFT) { + etsg->ApplyCast(expr->Right(), expr->OperationType()); + } + + etsg->Binary(expr, expr->OperatorType(), lhs); +} + +static void ConvertRestArguments(checker::ETSChecker *const checker, const ir::CallExpression *expr) +{ + if (expr->Signature()->RestVar() != nullptr) { + std::size_t const argument_count = expr->Arguments().size(); + std::size_t const parameter_count = expr->Signature()->MinArgCount(); + ASSERT(argument_count >= parameter_count); + + auto &arguments = const_cast &>(expr->Arguments()); + std::size_t i = parameter_count; + + if (i < argument_count && expr->Arguments()[i]->IsSpreadElement()) { + arguments[i] = expr->Arguments()[i]->AsSpreadElement()->Argument(); + } else { + ArenaVector elements(checker->Allocator()->Adapter()); + for (; i < argument_count; ++i) { + elements.emplace_back(expr->Arguments()[i]); + } + auto *array_expression = checker->AllocNode(std::move(elements), checker->Allocator()); + array_expression->SetParent(const_cast(expr)); + array_expression->SetTsType(expr->Signature()->RestVar()->TsType()); + arguments.erase(expr->Arguments().begin() + parameter_count, expr->Arguments().end()); + arguments.emplace_back(array_expression); + } + } +} + +void ETSCompiler::Compile(const ir::BlockExpression *expr) const { (void)expr; UNREACHABLE(); } +bool ETSCompiler::IsSucceedCompilationProxyMemberExpr(const ir::CallExpression *expr) const +{ + ETSGen *etsg = GetETSGen(); + auto *const callee_object = expr->callee_->AsMemberExpression()->Object(); + auto const *const enum_interface = [callee_type = callee_object->TsType()]() -> checker::ETSEnumInterface const * { + if (callee_type->IsETSEnumType()) { + return callee_type->AsETSEnumType(); + } + if (callee_type->IsETSStringEnumType()) { + return callee_type->AsETSStringEnumType(); + } + return nullptr; + }(); + + if (enum_interface != nullptr) { + ArenaVector arguments(etsg->Allocator()->Adapter()); + + checker::Signature *const signature = [expr, callee_object, enum_interface, &arguments]() { + const auto &member_proxy_method_name = expr->Signature()->InternalName(); + + if (member_proxy_method_name == checker::ETSEnumType::TO_STRING_METHOD_NAME) { + arguments.push_back(callee_object); + return enum_interface->ToStringMethod().global_signature; + } + if (member_proxy_method_name == checker::ETSEnumType::GET_VALUE_METHOD_NAME) { + arguments.push_back(callee_object); + return enum_interface->GetValueMethod().global_signature; + } + if (member_proxy_method_name == checker::ETSEnumType::GET_NAME_METHOD_NAME) { + arguments.push_back(callee_object); + return enum_interface->GetNameMethod().global_signature; + } + if (member_proxy_method_name == checker::ETSEnumType::VALUES_METHOD_NAME) { + return enum_interface->ValuesMethod().global_signature; + } + if (member_proxy_method_name == checker::ETSEnumType::VALUE_OF_METHOD_NAME) { + arguments.push_back(expr->Arguments().front()); + return enum_interface->ValueOfMethod().global_signature; + } + UNREACHABLE(); + }(); + + ASSERT(signature->ReturnType() == expr->Signature()->ReturnType()); + etsg->CallStatic(expr, signature, arguments); + etsg->SetAccumulatorType(expr->TsType()); + } + + return enum_interface != nullptr; +} + +void ETSCompiler::CompileDynamic(const ir::CallExpression *expr, compiler::VReg &callee_reg) const +{ + ETSGen *etsg = GetETSGen(); + compiler::VReg dyn_param2 = etsg->AllocReg(); + ir::Expression *obj = expr->callee_; + std::vector parts; + + while (obj->IsMemberExpression() && obj->AsMemberExpression()->ObjType()->IsETSDynamicType()) { + auto *mem_expr = obj->AsMemberExpression(); + obj = mem_expr->Object(); + parts.push_back(mem_expr->Property()->AsIdentifier()->Name()); + } + + if (!obj->IsMemberExpression() && obj->IsIdentifier()) { + auto *var = obj->AsIdentifier()->Variable(); + auto *data = etsg->VarBinder()->DynamicImportDataForVar(var); + if (data != nullptr) { + auto *import = data->import; + auto *specifier = data->specifier; + ASSERT(import->Language().IsDynamic()); + etsg->LoadAccumulatorDynamicModule(expr, import); + if (specifier->IsImportSpecifier()) { + parts.push_back(specifier->AsImportSpecifier()->Imported()->Name()); + } + } else { + obj->Compile(etsg); + } + } else { + obj->Compile(etsg); + } + + etsg->StoreAccumulator(expr, callee_reg); + + if (!parts.empty()) { + std::stringstream ss; + for_each(parts.rbegin(), parts.rend(), [&ss](util::StringView sv) { ss << "." << sv; }); + etsg->LoadAccumulatorString(expr, util::UString(ss.str(), etsg->Allocator()).View()); + } else { + auto lang = expr->Callee()->TsType()->IsETSDynamicFunctionType() + ? expr->Callee()->TsType()->AsETSDynamicFunctionType()->Language() + : expr->Callee()->TsType()->AsETSDynamicType()->Language(); + etsg->LoadUndefinedDynamic(expr, lang); + } + etsg->StoreAccumulator(expr, dyn_param2); + etsg->CallDynamic(expr, callee_reg, dyn_param2, expr->Signature(), expr->Arguments()); + etsg->SetAccumulatorType(expr->TsType()); + + if (expr->Signature()->ReturnType() != expr->TsType()) { + etsg->ApplyConversion(expr, expr->TsType()); + } +} + +// Helper function to avoid branching in non optional cases +void ETSCompiler::EmitCall(const ir::CallExpression *expr, compiler::VReg &callee_reg, bool is_static) const +{ + ETSGen *etsg = GetETSGen(); + if (expr->Callee()->GetBoxingUnboxingFlags() != ir::BoxingUnboxingFlags::NONE) { + etsg->ApplyConversionAndStoreAccumulator(expr->Callee(), callee_reg, nullptr); + } + if (is_static) { + etsg->CallStatic(expr, expr->Signature(), expr->Arguments()); + } else if (expr->Signature()->HasSignatureFlag(checker::SignatureFlags::PRIVATE) || expr->IsETSConstructorCall() || + (expr->Callee()->IsMemberExpression() && + expr->Callee()->AsMemberExpression()->Object()->IsSuperExpression())) { + etsg->CallThisStatic(expr, callee_reg, expr->Signature(), expr->Arguments()); + } else { + etsg->CallThisVirtual(expr, callee_reg, expr->Signature(), expr->Arguments()); + } + etsg->SetAccumulatorType(expr->TsType()); +} + void ETSCompiler::Compile(const ir::CallExpression *expr) const { - (void)expr; - UNREACHABLE(); + ETSGen *etsg = GetETSGen(); + compiler::RegScope rs(etsg); + compiler::VReg callee_reg = etsg->AllocReg(); + + const auto is_proxy = expr->Signature()->HasSignatureFlag(checker::SignatureFlags::PROXY); + if (is_proxy && expr->Callee()->IsMemberExpression()) { + if (IsSucceedCompilationProxyMemberExpr(expr)) { + return; + } + } + + bool is_static = expr->Signature()->HasSignatureFlag(checker::SignatureFlags::STATIC); + bool is_reference = expr->Signature()->HasSignatureFlag(checker::SignatureFlags::TYPE); + bool is_dynamic = expr->Callee()->TsType()->HasTypeFlag(checker::TypeFlag::ETS_DYNAMIC_FLAG); + + ConvertRestArguments(const_cast(etsg->Checker()->AsETSChecker()), expr); + + if (is_dynamic) { + CompileDynamic(expr, callee_reg); + } else if (!is_reference && expr->Callee()->IsIdentifier()) { + if (!is_static) { + etsg->LoadThis(expr); + etsg->StoreAccumulator(expr, callee_reg); + } + EmitCall(expr, callee_reg, is_static); + } else if (!is_reference && expr->Callee()->IsMemberExpression()) { + if (!is_static) { + expr->Callee()->AsMemberExpression()->Object()->Compile(etsg); + etsg->StoreAccumulator(expr, callee_reg); + } + EmitCall(expr, callee_reg, is_static); + } else if (expr->Callee()->IsSuperExpression() || expr->Callee()->IsThisExpression()) { + ASSERT(!is_reference && expr->IsETSConstructorCall()); + expr->Callee()->Compile(etsg); // ctor is not a value! + etsg->SetVRegType(callee_reg, etsg->GetAccumulatorType()); + EmitCall(expr, callee_reg, is_static); + } else { + ASSERT(is_reference); + etsg->CompileAndCheck(expr->Callee()); + etsg->StoreAccumulator(expr, callee_reg); + etsg->EmitMaybeOptional( + expr, [this, expr, is_static, &callee_reg]() { this->EmitCall(expr, callee_reg, is_static); }, + expr->IsOptional()); + } } -void ETSCompiler::Compile(const ir::ChainExpression *expr) const +void ETSCompiler::Compile([[maybe_unused]] const ir::ChainExpression *expr) const { - (void)expr; UNREACHABLE(); } -void ETSCompiler::Compile(const ir::ClassExpression *expr) const +void ETSCompiler::Compile([[maybe_unused]] const ir::ClassExpression *expr) const { - (void)expr; UNREACHABLE(); } void ETSCompiler::Compile(const ir::ConditionalExpression *expr) const { - (void)expr; - UNREACHABLE(); + ETSGen *etsg = GetETSGen(); + + auto *false_label = etsg->AllocLabel(); + auto *end_label = etsg->AllocLabel(); + + compiler::Condition::Compile(etsg, expr->Test(), false_label); + + auto ttctx = compiler::TargetTypeContext(etsg, expr->TsType()); + + expr->Consequent()->Compile(etsg); + etsg->ApplyConversion(expr->Consequent()); + etsg->Branch(expr, end_label); + etsg->SetLabel(expr, false_label); + expr->Alternate()->Compile(etsg); + etsg->ApplyConversion(expr->Alternate()); + etsg->SetLabel(expr, end_label); + etsg->SetAccumulatorType(expr->TsType()); } -void ETSCompiler::Compile(const ir::DirectEvalExpression *expr) const +void ETSCompiler::Compile([[maybe_unused]] const ir::DirectEvalExpression *expr) const { - (void)expr; UNREACHABLE(); } -void ETSCompiler::Compile(const ir::FunctionExpression *expr) const +void ETSCompiler::Compile([[maybe_unused]] const ir::FunctionExpression *expr) const { - (void)expr; UNREACHABLE(); } @@ -426,26 +738,54 @@ void ETSCompiler::Compile(const ir::CharLiteral *expr) const void ETSCompiler::Compile(const ir::NullLiteral *expr) const { - (void)expr; - UNREACHABLE(); + ETSGen *etsg = GetETSGen(); + etsg->LoadAccumulatorNull(expr, expr->TsType()); } void ETSCompiler::Compile(const ir::NumberLiteral *expr) const { - (void)expr; - UNREACHABLE(); + ETSGen *etsg = GetETSGen(); + auto ttctx = compiler::TargetTypeContext(etsg, expr->TsType()); + if (expr->Number().IsInt()) { + if (util::Helpers::IsTargetFitInSourceRange( + expr->Number().GetInt())) { + etsg->LoadAccumulatorByte(expr, static_cast(expr->Number().GetInt())); + return; + } + + if (util::Helpers::IsTargetFitInSourceRange( + expr->Number().GetInt())) { + etsg->LoadAccumulatorShort(expr, static_cast(expr->Number().GetInt())); + return; + } + + etsg->LoadAccumulatorInt(expr, static_cast(expr->Number().GetInt())); + return; + } + + if (expr->Number().IsLong()) { + etsg->LoadAccumulatorWideInt(expr, expr->Number().GetLong()); + return; + } + + if (expr->Number().IsFloat()) { + etsg->LoadAccumulatorFloat(expr, expr->Number().GetFloat()); + return; + } + + etsg->LoadAccumulatorDouble(expr, expr->Number().GetDouble()); } -void ETSCompiler::Compile(const ir::RegExpLiteral *expr) const +void ETSCompiler::Compile([[maybe_unused]] const ir::RegExpLiteral *expr) const { - (void)expr; UNREACHABLE(); } void ETSCompiler::Compile(const ir::StringLiteral *expr) const { - (void)expr; - UNREACHABLE(); + ETSGen *etsg = GetETSGen(); + etsg->LoadAccumulatorString(expr, expr->Str()); + etsg->SetAccumulatorType(expr->TsType()); } void ETSCompiler::Compile(const ir::UndefinedLiteral *expr) const @@ -455,51 +795,43 @@ void ETSCompiler::Compile(const ir::UndefinedLiteral *expr) const } // compile methods for MODULE-related nodes in alphabetical order -void ETSCompiler::Compile(const ir::ExportAllDeclaration *st) const +void ETSCompiler::Compile([[maybe_unused]] const ir::ExportAllDeclaration *st) const { - (void)st; UNREACHABLE(); } -void ETSCompiler::Compile(const ir::ExportDefaultDeclaration *st) const +void ETSCompiler::Compile([[maybe_unused]] const ir::ExportDefaultDeclaration *st) const { - (void)st; UNREACHABLE(); } -void ETSCompiler::Compile(const ir::ExportNamedDeclaration *st) const +void ETSCompiler::Compile([[maybe_unused]] const ir::ExportNamedDeclaration *st) const { - (void)st; UNREACHABLE(); } -void ETSCompiler::Compile(const ir::ExportSpecifier *st) const +void ETSCompiler::Compile([[maybe_unused]] const ir::ExportSpecifier *st) const { - (void)st; UNREACHABLE(); } -void ETSCompiler::Compile(const ir::ImportDeclaration *st) const +void ETSCompiler::Compile([[maybe_unused]] const ir::ImportDeclaration *st) const { - (void)st; UNREACHABLE(); } -void ETSCompiler::Compile(const ir::ImportDefaultSpecifier *st) const +void ETSCompiler::Compile([[maybe_unused]] const ir::ImportDefaultSpecifier *st) const { - (void)st; UNREACHABLE(); } -void ETSCompiler::Compile(const ir::ImportNamespaceSpecifier *st) const +void ETSCompiler::Compile([[maybe_unused]] const ir::ImportNamespaceSpecifier *st) const { - (void)st; UNREACHABLE(); } -void ETSCompiler::Compile(const ir::ImportSpecifier *st) const +void ETSCompiler::Compile([[maybe_unused]] const ir::ImportSpecifier *st) const { - (void)st; UNREACHABLE(); } // compile methods for STATEMENTS in alphabetical order @@ -521,76 +853,206 @@ void ETSCompiler::Compile(const ir::BreakStatement *st) const UNREACHABLE(); } -void ETSCompiler::Compile(const ir::ClassDeclaration *st) const +void ETSCompiler::Compile([[maybe_unused]] const ir::ClassDeclaration *st) const { - (void)st; UNREACHABLE(); } +static void CompileImpl(const ir::ContinueStatement *self, ETSGen *etsg) +{ + compiler::Label *target = etsg->ControlFlowChangeContinue(self->Ident()); + etsg->Branch(self, target); +} + void ETSCompiler::Compile(const ir::ContinueStatement *st) const { - (void)st; - UNREACHABLE(); + ETSGen *etsg = GetETSGen(); + if (etsg->ExtendWithFinalizer(st->parent_, st)) { + return; + } + CompileImpl(st, etsg); } -void ETSCompiler::Compile(const ir::DebuggerStatement *st) const +void ETSCompiler::Compile([[maybe_unused]] const ir::DebuggerStatement *st) const { - (void)st; UNREACHABLE(); } -void ETSCompiler::Compile(const ir::DoWhileStatement *st) const +void CompileImpl(const ir::DoWhileStatement *self, ETSGen *etsg) { - (void)st; - UNREACHABLE(); + auto *start_label = etsg->AllocLabel(); + compiler::LabelTarget label_target(etsg); + + etsg->SetLabel(self, start_label); + + { + compiler::LocalRegScope reg_scope(etsg, self->Scope()); + compiler::LabelContext label_ctx(etsg, label_target); + self->Body()->Compile(etsg); + } + + etsg->SetLabel(self, label_target.ContinueTarget()); + compiler::Condition::Compile(etsg, self->Test(), label_target.BreakTarget()); + + etsg->Branch(self, start_label); + etsg->SetLabel(self, label_target.BreakTarget()); } -void ETSCompiler::Compile(const ir::EmptyStatement *st) const +void ETSCompiler::Compile(const ir::DoWhileStatement *st) const { - (void)st; - UNREACHABLE(); + ETSGen *etsg = GetETSGen(); + CompileImpl(st, etsg); } +void ETSCompiler::Compile([[maybe_unused]] const ir::EmptyStatement *st) const {} + void ETSCompiler::Compile(const ir::ExpressionStatement *st) const { - (void)st; - UNREACHABLE(); + ETSGen *etsg = GetETSGen(); + st->GetExpression()->Compile(etsg); } -void ETSCompiler::Compile(const ir::ForInStatement *st) const +void ETSCompiler::Compile([[maybe_unused]] const ir::ForInStatement *st) const { - (void)st; UNREACHABLE(); } void ETSCompiler::Compile(const ir::ForOfStatement *st) const { - (void)st; - UNREACHABLE(); + ETSGen *etsg = GetETSGen(); + compiler::LocalRegScope decl_reg_scope(etsg, st->Scope()->DeclScope()->InitScope()); + + checker::Type const *const expr_type = st->Right()->TsType(); + ASSERT(expr_type->IsETSArrayType() || expr_type->IsETSStringType()); + + st->Right()->Compile(etsg); + compiler::VReg obj_reg = etsg->AllocReg(); + etsg->StoreAccumulator(st, obj_reg); + + if (expr_type->IsETSArrayType()) { + etsg->LoadArrayLength(st, obj_reg); + } else { + etsg->LoadStringLength(st); + } + + compiler::VReg size_reg = etsg->AllocReg(); + etsg->StoreAccumulator(st, size_reg); + + compiler::LabelTarget label_target(etsg); + auto label_ctx = compiler::LabelContext(etsg, label_target); + + etsg->BranchIfFalse(st, label_target.BreakTarget()); + + compiler::VReg count_reg = etsg->AllocReg(); + etsg->MoveImmediateToRegister(st, count_reg, checker::TypeFlag::INT, static_cast(0)); + etsg->LoadAccumulatorInt(st, static_cast(0)); + + auto *const start_label = etsg->AllocLabel(); + etsg->SetLabel(st, start_label); + + auto lref = compiler::ETSLReference::Create(etsg, st->Left(), false); + + if (st->Right()->TsType()->IsETSArrayType()) { + etsg->LoadArrayElement(st, obj_reg); + } else { + etsg->LoadStringChar(st, obj_reg, count_reg); + } + + lref.SetValue(); + st->Body()->Compile(etsg); + + etsg->SetLabel(st, label_target.ContinueTarget()); + + etsg->IncrementImmediateRegister(st, count_reg, checker::TypeFlag::INT, static_cast(1)); + etsg->LoadAccumulator(st, count_reg); + + etsg->JumpCompareRegister(st, size_reg, start_label); + etsg->SetLabel(st, label_target.BreakTarget()); } void ETSCompiler::Compile(const ir::ForUpdateStatement *st) const { - (void)st; - UNREACHABLE(); + ETSGen *etsg = GetETSGen(); + compiler::LocalRegScope decl_reg_scope(etsg, st->Scope()->DeclScope()->InitScope()); + + if (st->Init() != nullptr) { + ASSERT(st->Init()->IsVariableDeclaration() || st->Init()->IsExpression()); + st->Init()->Compile(etsg); + } + + auto *start_label = etsg->AllocLabel(); + compiler::LabelTarget label_target(etsg); + auto label_ctx = compiler::LabelContext(etsg, label_target); + etsg->SetLabel(st, start_label); + + { + compiler::LocalRegScope reg_scope(etsg, st->Scope()); + + if (st->Test() != nullptr) { + compiler::Condition::Compile(etsg, st->Test(), label_target.BreakTarget()); + } + + st->Body()->Compile(etsg); + etsg->SetLabel(st, label_target.ContinueTarget()); + } + + if (st->Update() != nullptr) { + st->Update()->Compile(etsg); + } + + etsg->Branch(st, start_label); + etsg->SetLabel(st, label_target.BreakTarget()); } -void ETSCompiler::Compile(const ir::FunctionDeclaration *st) const +void ETSCompiler::Compile([[maybe_unused]] const ir::FunctionDeclaration *st) const { - (void)st; UNREACHABLE(); } void ETSCompiler::Compile(const ir::IfStatement *st) const { - (void)st; - UNREACHABLE(); + ETSGen *etsg = GetETSGen(); + auto res = compiler::Condition::CheckConstantExpr(etsg, st->Test()); + if (res == compiler::Condition::Result::CONST_TRUE) { + st->Consequent()->Compile(etsg); + return; + } + + if (res == compiler::Condition::Result::CONST_FALSE) { + if (st->Alternate() != nullptr) { + st->Alternate()->Compile(etsg); + } + return; + } + + auto *consequent_end = etsg->AllocLabel(); + compiler::Label *statement_end = consequent_end; + + compiler::Condition::Compile(etsg, st->Test(), consequent_end); + + st->Consequent()->Compile(etsg); + + if (st->Alternate() != nullptr) { + statement_end = etsg->AllocLabel(); + etsg->Branch(etsg->Insns().back()->Node(), statement_end); + + etsg->SetLabel(st, consequent_end); + st->Alternate()->Compile(etsg); + } + + etsg->SetLabel(st, statement_end); +} + +void CompileImpl(const ir::LabelledStatement *self, ETSGen *cg) +{ + compiler::LabelContext label_ctx(cg, self); + self->Body()->Compile(cg); } void ETSCompiler::Compile(const ir::LabelledStatement *st) const { - (void)st; - UNREACHABLE(); + ETSGen *etsg = GetETSGen(); + CompileImpl(st, etsg); } void ETSCompiler::Compile(const ir::ReturnStatement *st) const @@ -636,16 +1098,47 @@ void ETSCompiler::Compile(const ir::ReturnStatement *st) const etsg->ReturnAcc(st); } -void ETSCompiler::Compile(const ir::SwitchCaseStatement *st) const +void ETSCompiler::Compile([[maybe_unused]] const ir::SwitchCaseStatement *st) const { - (void)st; UNREACHABLE(); } +static void CompileImpl(const ir::SwitchStatement *self, ETSGen *etsg) +{ + compiler::LocalRegScope lrs(etsg, self->Scope()); + compiler::SwitchBuilder builder(etsg, self); + compiler::VReg tag = etsg->AllocReg(); + + builder.CompileTagOfSwitch(tag); + uint32_t default_index = 0; + + for (size_t i = 0; i < self->Cases().size(); i++) { + const auto *clause = self->Cases()[i]; + + if (clause->Test() == nullptr) { + default_index = i; + continue; + } + + builder.JumpIfCase(tag, i); + } + + if (default_index > 0) { + builder.JumpToDefault(default_index); + } else { + builder.Break(); + } + + for (size_t i = 0; i < self->Cases().size(); i++) { + builder.SetCaseTarget(i); + builder.CompileCaseStatements(i); + } +} + void ETSCompiler::Compile(const ir::SwitchStatement *st) const { - (void)st; - UNREACHABLE(); + ETSGen *etsg = GetETSGen(); + CompileImpl(st, etsg); } void ETSCompiler::Compile(const ir::ThrowStatement *st) const @@ -678,9 +1171,8 @@ void ETSCompiler::Compile(const ir::WhileStatement *st) const UNREACHABLE(); } // from ts folder -void ETSCompiler::Compile(const ir::TSAnyKeyword *node) const +void ETSCompiler::Compile([[maybe_unused]] const ir::TSAnyKeyword *node) const { - (void)node; UNREACHABLE(); } @@ -702,9 +1194,8 @@ void ETSCompiler::Compile(const ir::TSBigintKeyword *node) const UNREACHABLE(); } -void ETSCompiler::Compile(const ir::TSBooleanKeyword *node) const +void ETSCompiler::Compile([[maybe_unused]] const ir::TSBooleanKeyword *node) const { - (void)node; UNREACHABLE(); } @@ -726,21 +1217,18 @@ void ETSCompiler::Compile(const ir::TSConstructorType *node) const UNREACHABLE(); } -void ETSCompiler::Compile(const ir::TSEnumDeclaration *st) const +void ETSCompiler::Compile([[maybe_unused]] const ir::TSEnumDeclaration *st) const { - (void)st; UNREACHABLE(); } -void ETSCompiler::Compile(const ir::TSEnumMember *st) const +void ETSCompiler::Compile([[maybe_unused]] const ir::TSEnumMember *st) const { - (void)st; UNREACHABLE(); } -void ETSCompiler::Compile(const ir::TSExternalModuleReference *expr) const +void ETSCompiler::Compile([[maybe_unused]] const ir::TSExternalModuleReference *expr) const { - (void)expr; UNREACHABLE(); } @@ -846,15 +1334,13 @@ void ETSCompiler::Compile(const ir::TSNullKeyword *node) const UNREACHABLE(); } -void ETSCompiler::Compile(const ir::TSNumberKeyword *node) const +void ETSCompiler::Compile([[maybe_unused]] const ir::TSNumberKeyword *node) const { - (void)node; UNREACHABLE(); } -void ETSCompiler::Compile(const ir::TSObjectKeyword *node) const +void ETSCompiler::Compile([[maybe_unused]] const ir::TSObjectKeyword *node) const { - (void)node; UNREACHABLE(); } @@ -876,9 +1362,8 @@ void ETSCompiler::Compile(const ir::TSQualifiedName *expr) const UNREACHABLE(); } -void ETSCompiler::Compile(const ir::TSStringKeyword *node) const +void ETSCompiler::Compile([[maybe_unused]] const ir::TSStringKeyword *node) const { - (void)node; UNREACHABLE(); } @@ -954,9 +1439,8 @@ void ETSCompiler::Compile(const ir::TSTypeReference *node) const UNREACHABLE(); } -void ETSCompiler::Compile(const ir::TSUndefinedKeyword *node) const +void ETSCompiler::Compile([[maybe_unused]] const ir::TSUndefinedKeyword *node) const { - (void)node; UNREACHABLE(); } @@ -966,16 +1450,14 @@ void ETSCompiler::Compile(const ir::TSUnionType *node) const UNREACHABLE(); } -void ETSCompiler::Compile(const ir::TSUnknownKeyword *node) const +void ETSCompiler::Compile([[maybe_unused]] const ir::TSUnknownKeyword *node) const { - (void)node; UNREACHABLE(); } -void ETSCompiler::Compile(const ir::TSVoidKeyword *node) const +void ETSCompiler::Compile([[maybe_unused]] const ir::TSVoidKeyword *node) const { - (void)node; UNREACHABLE(); } -} // namespace panda::es2panda::compiler \ No newline at end of file +} // namespace panda::es2panda::compiler diff --git a/ets2panda/compiler/core/ETSCompiler.h b/ets2panda/compiler/core/ETSCompiler.h index df72ed1699f577a79948cc5b408b0dd01789cb00..61447f878f5e2263cc1a0030068719d49e04d818 100644 --- a/ets2panda/compiler/core/ETSCompiler.h +++ b/ets2panda/compiler/core/ETSCompiler.h @@ -34,6 +34,10 @@ public: #undef DECLARE_ETSCOMPILER_COMPILE_METHOD private: + bool IsSucceedCompilationProxyMemberExpr(const ir::CallExpression *expr) const; + void CompileDynamic(const ir::CallExpression *expr, compiler::VReg &callee_reg) const; + void EmitCall(const ir::CallExpression *expr, compiler::VReg &callee_reg, bool is_static) const; + ETSGen *GetETSGen() const; }; diff --git a/ets2panda/compiler/core/ETSGen.cpp b/ets2panda/compiler/core/ETSGen.cpp index 30b85196537359b852c43094dea5fbb21599e6f6..32f0f7800ab042adcb8af32662d4a3988d3e9a8f 100644 --- a/ets2panda/compiler/core/ETSGen.cpp +++ b/ets2panda/compiler/core/ETSGen.cpp @@ -15,7 +15,6 @@ #include "ETSGen.h" -#include "checker/ets/boxingConverter.h" #include "ir/base/scriptFunction.h" #include "ir/base/classDefinition.h" #include "ir/statement.h" @@ -40,6 +39,7 @@ #include "checker/types/typeFlag.h" #include "checker/checker.h" #include "checker/ETSchecker.h" +#include "checker/ets/boxingConverter.h" #include "checker/types/ets/etsObjectType.h" #include "checker/types/ets/types.h" #include "parser/program/program.h" @@ -290,7 +290,7 @@ void ETSGen::LoadVar(const ir::AstNode *node, varbinder::Variable const *const v } case ReferenceKind::FIELD: { const auto full_name = FormClassPropReference(GetVRegType(GetThisReg())->AsETSObjectType(), var->Name()); - LoadProperty(node, var->TsType(), GetThisReg(), full_name); + LoadProperty(node, var->TsType(), false, GetThisReg(), full_name); break; } case ReferenceKind::METHOD: @@ -422,14 +422,17 @@ void ETSGen::StoreProperty(const ir::AstNode *const node, const checker::Type *p } } -void ETSGen::LoadProperty(const ir::AstNode *const node, const checker::Type *prop_type, const VReg obj_reg, - const util::StringView &full_name) +void ETSGen::LoadProperty(const ir::AstNode *const node, const checker::Type *prop_type, bool is_generic, + const VReg obj_reg, const util::StringView &full_name) { if (node->IsIdentifier() && node->AsIdentifier()->Variable()->HasFlag(varbinder::VariableFlags::BOXED)) { prop_type = Checker()->GlobalBuiltinBoxType(prop_type); } if (prop_type->HasTypeFlag(checker::TypeFlag::ETS_ARRAY_OR_OBJECT | checker::TypeFlag::ETS_UNION)) { Ra().Emit(node, obj_reg, full_name); + if (is_generic) { + EmitCheckCast(node, prop_type); + } } else if (prop_type->HasTypeFlag(checker::TypeFlag::ETS_WIDE_NUMERIC)) { Ra().Emit(node, obj_reg, full_name); } else { @@ -450,11 +453,14 @@ void ETSGen::StoreUnionProperty([[maybe_unused]] const ir::AstNode *node, [[mayb } void ETSGen::LoadUnionProperty([[maybe_unused]] const ir::AstNode *const node, - [[maybe_unused]] const checker::Type *prop_type, [[maybe_unused]] const VReg obj_reg, - [[maybe_unused]] const util::StringView &prop_name) + [[maybe_unused]] const checker::Type *prop_type, [[maybe_unused]] bool is_generic, + [[maybe_unused]] const VReg obj_reg, [[maybe_unused]] const util::StringView &prop_name) { #ifdef PANDA_WITH_ETS Ra().Emit(node, obj_reg, prop_name); + if (is_generic) { + EmitCheckCast(node, prop_type); + } SetAccumulatorType(prop_type); #else UNREACHABLE(); @@ -867,15 +873,35 @@ bool ETSGen::TryLoadConstantExpression(const ir::Expression *node) return true; } -// NOTE: vpukhov. lower (union_value) as (primitive_type) to be two as-nodes -static void ApplyUnboxingUnionPrimitive(ETSGen *etsg, const ir::AstNode *node) +void ETSGen::ApplyConversionCast(const ir::AstNode *node, const checker::Type *target_type) { - if (node->IsExpression() && node->Parent()->IsTSAsExpression()) { - auto const *from_type = node->AsExpression()->TsType(); - auto const *to_type = node->Parent()->AsTSAsExpression()->TsType(); - if (from_type->IsETSUnionType() && to_type->HasTypeFlag(checker::TypeFlag::ETS_PRIMITIVE)) { - etsg->EmitCheckedNarrowingReferenceConversion( - node, checker::BoxingConverter::ETSTypeFromSource(etsg->Checker(), to_type)); + switch (checker::ETSChecker::TypeKind(target_type)) { + case checker::TypeFlag::DOUBLE: { + CastToDouble(node); + break; + } + case checker::TypeFlag::FLOAT: { + CastToFloat(node); + break; + } + case checker::TypeFlag::LONG: { + CastToLong(node); + break; + } + case checker::TypeFlag::ETS_ARRAY: + [[fallthrough]]; + case checker::TypeFlag::ETS_OBJECT: { + if (GetAccumulatorType() != nullptr && GetAccumulatorType()->IsETSDynamicType()) { + CastDynamicToObject(node, target_type); + } + break; + } + case checker::TypeFlag::ETS_DYNAMIC_TYPE: { + CastToDynamic(node, target_type->AsETSDynamicType()); + break; + } + default: { + break; } } } @@ -897,7 +923,6 @@ void ETSGen::ApplyConversion(const ir::AstNode *node, const checker::Type *targe if (GetAccumulatorType()->IsNullishOrNullLike()) { // NOTE: vpukhov. should be a CTE EmitNullishGuardian(node); } - ApplyUnboxingUnionPrimitive(this, node); EmitUnboxingConversion(node); const auto unboxing_flags = static_cast(node->GetBoxingUnboxingFlags() & ir::BoxingUnboxingFlags::UNBOXING_FLAG); @@ -909,35 +934,12 @@ void ETSGen::ApplyConversion(const ir::AstNode *node, const checker::Type *targe return; } - switch (checker::ETSChecker::TypeKind(target_type)) { - case checker::TypeFlag::DOUBLE: { - CastToDouble(node); - break; - } - case checker::TypeFlag::FLOAT: { - CastToFloat(node); - break; - } - case checker::TypeFlag::LONG: { - CastToLong(node); - break; - } - case checker::TypeFlag::ETS_ARRAY: - [[fallthrough]]; - case checker::TypeFlag::ETS_OBJECT: { - if (GetAccumulatorType() != nullptr && GetAccumulatorType()->IsETSDynamicType()) { - CastDynamicToObject(node, target_type); - } - break; - } - case checker::TypeFlag::ETS_DYNAMIC_TYPE: { - CastToDynamic(node, target_type->AsETSDynamicType()); - break; - } - default: { - break; - } + if (target_type->IsETSUnionType()) { + SetAccumulatorType(target_type->AsETSUnionType()->GetLeastUpperBoundType()); + return; } + + ApplyConversionCast(node, target_type); } void ETSGen::ApplyCast(const ir::AstNode *node, const checker::Type *target_type) @@ -1158,7 +1160,7 @@ void ETSGen::EmitLocalBoxGet(ir::AstNode const *node, checker::Type const *conte break; default: Ra().Emit(node, Signatures::BUILTIN_BOX_GET, dummy_reg_, 0); - Ra().Emit(node, content_type->AsETSObjectType()->AssemblerName()); + EmitCheckCast(node, content_type); break; } SetAccumulatorType(content_type); @@ -1778,13 +1780,7 @@ void ETSGen::EmitCheckedNarrowingReferenceConversion(const ir::AstNode *const no ASSERT(target_type->HasTypeFlag(checker::TypeFlag::ETS_ARRAY_OR_OBJECT | checker::TypeFlag::ETS_UNION) && !target_type->IsETSNullLike()); - if (target_type->IsETSObjectType()) { - Sa().Emit(node, target_type->AsETSObjectType()->AssemblerName()); - } else { - std::stringstream ss; - target_type->AsETSArrayType()->ToAssemblerTypeWithRank(ss); - Sa().Emit(node, util::UString(ss.str(), Allocator()).View()); - } + Sa().Emit(node, ToCheckCastTypeView(target_type)); SetAccumulatorType(target_type); } @@ -2160,6 +2156,7 @@ void ETSGen::LogicalNot(const ir::AstNode *node) ASSERT(GetAccumulatorType()->IsConditionalExprType()); ResolveConditionalResultIfFalse(node); Sa().Emit(node, 1); + SetAccumulatorType(Checker()->GlobalETSBooleanType()); } void ETSGen::Unary(const ir::AstNode *node, lexer::TokenType op) @@ -2247,6 +2244,13 @@ void ETSGen::UnaryDollarDollar(const ir::AstNode *node) EmitThrow(node, exception); } +void ETSGen::InsertNeededCheckCast(const checker::Signature *signature, const ir::AstNode *node) +{ + if (signature->IsBaseReturnDiff()) { + EmitCheckCast(node, signature->ReturnType()); + } +} + void ETSGen::Update(const ir::AstNode *node, lexer::TokenType op) { switch (op) { @@ -2422,6 +2426,10 @@ void ETSGen::LoadArrayElement(const ir::AstNode *node, VReg object_reg) { auto *element_type = GetVRegType(object_reg)->AsETSArrayType()->ElementType(); + if (element_type->IsETSUnionType()) { + element_type = element_type->AsETSUnionType()->GetLeastUpperBoundType(); + } + switch (checker::ETSChecker::ETSType(element_type)) { case checker::TypeFlag::ETS_BOOLEAN: case checker::TypeFlag::BYTE: { @@ -2472,6 +2480,9 @@ void ETSGen::LoadArrayElement(const ir::AstNode *node, VReg object_reg) void ETSGen::StoreArrayElement(const ir::AstNode *node, VReg object_reg, VReg index, const checker::Type *element_type) { + if (element_type->IsETSUnionType()) { + element_type = element_type->AsETSUnionType()->GetLeastUpperBoundType(); + } switch (checker::ETSChecker::ETSType(element_type)) { case checker::TypeFlag::ETS_BOOLEAN: case checker::TypeFlag::BYTE: { @@ -2607,4 +2618,23 @@ bool ETSGen::ExtendWithFinalizer(ir::AstNode *node, const ir::AstNode *original_ return ExtendWithFinalizer(parent, original_node, prev_finnaly); } +util::StringView ETSGen::ToCheckCastTypeView(const es2panda::checker::Type *type) const +{ + auto asm_t = type; + if (type->IsETSUnionType()) { + asm_t = type->AsETSUnionType()->GetLeastUpperBoundType(); + } + std::stringstream ss; + asm_t->ToAssemblerTypeWithRank(ss); + return util::UString(ss.str(), Allocator()).View(); +} + +void ETSGen::EmitCheckCast(const ir::AstNode *node, const es2panda::checker::Type *type) +{ + if (type->IsETSArrayType()) { + return; // Since generic arrays allowed we can't add checkcast for them. + } + Ra().Emit(node, ToCheckCastTypeView(type)); +} + } // namespace panda::es2panda::compiler diff --git a/ets2panda/compiler/core/ETSGen.h b/ets2panda/compiler/core/ETSGen.h index 7ee98c5619fb31522e9ada5358b7e9b7f720d1c2..95aaa9528a2c0680881104be8bcdf62c2d3eee06 100644 --- a/ets2panda/compiler/core/ETSGen.h +++ b/ets2panda/compiler/core/ETSGen.h @@ -69,7 +69,7 @@ public: void StoreProperty(const ir::AstNode *node, const checker::Type *prop_type, VReg obj_reg, const util::StringView &name); - void LoadProperty(const ir::AstNode *node, const checker::Type *prop_type, VReg obj_reg, + void LoadProperty(const ir::AstNode *node, const checker::Type *prop_type, bool is_generic, VReg obj_reg, const util::StringView &full_name); void StorePropertyDynamic(const ir::AstNode *node, const checker::Type *prop_type, VReg obj_reg, const util::StringView &name, Language lang); @@ -80,7 +80,7 @@ public: void LoadElementDynamic(const ir::AstNode *node, VReg object_reg, Language lang); void StoreUnionProperty(const ir::AstNode *node, VReg obj_reg, const util::StringView &name); - void LoadUnionProperty(const ir::AstNode *node, const checker::Type *prop_type, VReg obj_reg, + void LoadUnionProperty(const ir::AstNode *node, const checker::Type *prop_type, bool is_generic, VReg obj_reg, const util::StringView &prop_name); void LoadUndefinedDynamic(const ir::AstNode *node, Language lang); @@ -102,10 +102,11 @@ public: bool TryLoadConstantExpression(const ir::Expression *node); void Condition(const ir::AstNode *node, lexer::TokenType op, VReg lhs, Label *if_false); - template - void ResolveConditionalResultFloat(const ir::AstNode *node, [[maybe_unused]] Label *if_false, Label *end) + template + void ResolveConditionalResultFloat(const ir::AstNode *node, Label *real_end_label) { - auto type = node->IsExpression() ? node->AsExpression()->TsType() : GetAccumulatorType(); + auto type = node->IsExpression() && !node->AsExpression()->IsUnaryExpression() ? node->AsExpression()->TsType() + : GetAccumulatorType(); VReg tmp_reg = AllocReg(); StoreAccumulator(node, tmp_reg); if (type->IsFloatType()) { @@ -113,17 +114,8 @@ public: } else { DoubleIsNaN(node); } - Sa().Emit(node, 1); - auto real_end_label = [](Label *end_label, Label *if_false_label, ETSGen *etsgn, bool use_false_label) { - if (use_false_label) { - return if_false_label; - } - if (end_label == nullptr) { - end_label = etsgn->AllocLabel(); - } - return end_label; - }(end, if_false, this, USE_FALSE_LABEL); + BranchIfFalse(node, real_end_label); LoadAccumulator(node, tmp_reg); VReg zero_reg = AllocReg(); @@ -138,39 +130,40 @@ public: } template - void ResolveConditionalResultNumeric(const ir::AstNode *node, [[maybe_unused]] Label *if_false, Label *end) + void ResolveConditionalResultNumeric(const ir::AstNode *node, [[maybe_unused]] Label *if_false, Label **end) { - auto type = node->IsExpression() ? node->AsExpression()->TsType() : GetAccumulatorType(); - switch (type->TypeFlags()) { - case checker::TypeFlag::LONG: { - CastToInt(node); - [[fallthrough]]; - } - case checker::TypeFlag::BYTE: - case checker::TypeFlag::CHAR: - case checker::TypeFlag::SHORT: - case checker::TypeFlag::INT: { - if constexpr (BEFORE_LOGICAL_NOT) { - Label *zero_primitive = AllocLabel(); - BranchIfFalse(node, zero_primitive); - ToBinaryResult(node, zero_primitive); - } - break; + auto type = node->IsExpression() && !node->AsExpression()->IsUnaryExpression() ? node->AsExpression()->TsType() + : GetAccumulatorType(); + + auto real_end_label = [end, if_false, this](bool use_false_label) { + if (use_false_label) { + return if_false; } - case checker::TypeFlag::DOUBLE: - case checker::TypeFlag::FLOAT: { - ResolveConditionalResultFloat(node, if_false, end); - break; + if ((*end) == nullptr) { + (*end) = AllocLabel(); } - default: - break; + return (*end); + }(USE_FALSE_LABEL); + if (type->IsDoubleType() || type->IsFloatType()) { + ResolveConditionalResultFloat(node, real_end_label); + } + if (type->IsLongType()) { + VReg zero_reg = AllocReg(); + MoveImmediateToRegister(node, zero_reg, checker::TypeFlag::LONG, 0); + BinaryNumberComparison(node, zero_reg, real_end_label); + } + if constexpr (BEFORE_LOGICAL_NOT) { + Label *zero_primitive = AllocLabel(); + BranchIfFalse(node, zero_primitive); + ToBinaryResult(node, zero_primitive); } } - template - void ResolveConditionalResultObject(const ir::AstNode *node, [[maybe_unused]] Label *if_false) + template + void ResolveConditionalResultObject(const ir::AstNode *node) { - auto type = node->IsExpression() ? node->AsExpression()->TsType() : GetAccumulatorType(); + auto type = node->IsExpression() && !node->AsExpression()->IsUnaryExpression() ? node->AsExpression()->TsType() + : GetAccumulatorType(); if (type->IsETSStringType()) { LoadStringLength(node); if constexpr (BEFORE_LOGICAL_NOT) { @@ -178,6 +171,27 @@ public: BranchIfFalse(node, zero_lenth); ToBinaryResult(node, zero_lenth); } + } else if (node->IsExpression() && node->AsExpression()->IsIdentifier() && + node->AsExpression()->AsIdentifier()->Variable()->HasFlag(varbinder::VariableFlags::VAR)) { + Label *is_string = AllocLabel(); + Label *end = AllocLabel(); + compiler::VReg obj_reg = AllocReg(); + StoreAccumulator(node, obj_reg); + + Sa().Emit(node, Checker()->GlobalBuiltinETSStringType()->AsETSStringType()->AssemblerName()); + BranchIfTrue(node, is_string); + Sa().Emit(node, 1); + Branch(node, end); + SetLabel(node, is_string); + LoadAccumulator(node, obj_reg); + CastToString(node); + LoadStringLength(node); + if constexpr (BEFORE_LOGICAL_NOT) { + Label *zero_lenth = AllocLabel(); + BranchIfFalse(node, zero_lenth); + ToBinaryResult(node, zero_lenth); + } + SetLabel(node, end); } else { Sa().Emit(node, 1); } @@ -200,11 +214,8 @@ public: template void ResolveConditionalResult(const ir::AstNode *node, [[maybe_unused]] Label *if_false) { - auto type = node->IsExpression() ? node->AsExpression()->TsType() : GetAccumulatorType(); - if (type->IsETSObjectType() && - type->AsETSObjectType()->HasObjectFlag(panda::es2panda::checker::ETSObjectFlags::UNBOXABLE_TYPE)) { - type = GetAccumulatorType(); - } + auto type = node->IsExpression() && !node->AsExpression()->IsUnaryExpression() ? node->AsExpression()->TsType() + : GetAccumulatorType(); if (type->IsETSBooleanType()) { return; } @@ -228,9 +239,9 @@ public: StoreAccumulator(node, obj_reg); LoadArrayLength(node, obj_reg); } else if (type->IsETSObjectType()) { - ResolveConditionalResultObject(node, if_false); + ResolveConditionalResultObject(node); } else { - ResolveConditionalResultNumeric(node, if_false, end); + ResolveConditionalResultNumeric(node, if_false, &end); } if (if_nullish != nullptr) { Branch(node, end); @@ -248,10 +259,10 @@ public: ResolveConditionalResult(node, if_false); } - template + template void ResolveConditionalResultIfTrue(const ir::AstNode *node, Label *if_false = nullptr) { - ResolveConditionalResult(node, if_false); + ResolveConditionalResult(node, if_false); } void BranchIfFalse(const ir::AstNode *node, Label *if_false) @@ -407,6 +418,7 @@ public: ApplyConversion(node, target_type_); } } + void ApplyConversionCast(const ir::AstNode *node, const checker::Type *target_type); void ApplyConversion(const ir::AstNode *node, const checker::Type *target_type); void ApplyCast(const ir::AstNode *node, const checker::Type *target_type); void EmitUnboxingConversion(const ir::AstNode *node); @@ -650,6 +662,12 @@ private: void UnaryTilde(const ir::AstNode *node); void UnaryDollarDollar(const ir::AstNode *node); + util::StringView ToCheckCastTypeView(const es2panda::checker::Type *type) const; + void EmitCheckCast(const ir::AstNode *node, const es2panda::checker::Type *type); + + // To avoid verifier error checkcast is needed + void InsertNeededCheckCast(const checker::Signature *signature, const ir::AstNode *node); + template void StoreValueIntoArray(const ir::AstNode *const node, const VReg arr, const VReg index) { @@ -950,10 +968,7 @@ private: } } - // To avoid verifier error checkcast is needed - if (signature->HasSignatureFlag(checker::SignatureFlags::SUBSTITUTED_RETURN_TYPE)) { - Ra().Emit(node, signature->ReturnType()->AsETSObjectType()->AssemblerName()); - } + InsertNeededCheckCast(signature, node); } template @@ -1009,10 +1024,7 @@ private: } } - // To avoid verifier error checkcast is needed - if (signature->HasSignatureFlag(checker::SignatureFlags::SUBSTITUTED_RETURN_TYPE)) { - Ra().Emit(node, signature->ReturnType()->AsETSObjectType()->AssemblerName()); - } + InsertNeededCheckCast(signature, node); } #undef COMPILE_ARG @@ -1067,10 +1079,7 @@ private: } } - // To avoid verifier error checkcast is needed - if (signature->HasSignatureFlag(checker::SignatureFlags::SUBSTITUTED_RETURN_TYPE)) { - Ra().Emit(node, signature->ReturnType()->AsETSObjectType()->AssemblerName()); - } + InsertNeededCheckCast(signature, node); } #undef COMPILE_ARG diff --git a/ets2panda/compiler/core/JSCompiler.cpp b/ets2panda/compiler/core/JSCompiler.cpp index 10a894d364243fe8b74d0bd55d96c5d90df2551c..090f5f4ec79163bae0faa14f87f884d41aa6d6dd 100644 --- a/ets2panda/compiler/core/JSCompiler.cpp +++ b/ets2panda/compiler/core/JSCompiler.cpp @@ -18,6 +18,7 @@ #include "compiler/base/condition.h" #include "compiler/base/lreference.h" #include "compiler/core/pandagen.h" +#include "compiler/core/switchBuilder.h" #include "compiler/function/functionBuilder.h" #include "util/helpers.h" @@ -409,25 +410,30 @@ void JSCompiler::Compile([[maybe_unused]] const ir::Decorator *st) const void JSCompiler::Compile(const ir::MetaProperty *expr) const { - (void)expr; - UNREACHABLE(); + PandaGen *pg = GetPandaGen(); + if (expr->Kind() == ir::MetaProperty::MetaPropertyKind::NEW_TARGET) { + pg->GetNewTarget(expr); + return; + } + + if (expr->Kind() == ir::MetaProperty::MetaPropertyKind::IMPORT_META) { + // NOTE + pg->Unimplemented(); + } } -void JSCompiler::Compile(const ir::MethodDefinition *node) const +void JSCompiler::Compile([[maybe_unused]] const ir::MethodDefinition *node) const { - (void)node; UNREACHABLE(); } -void JSCompiler::Compile(const ir::Property *expr) const +void JSCompiler::Compile([[maybe_unused]] const ir::Property *expr) const { - (void)expr; UNREACHABLE(); } -void JSCompiler::Compile(const ir::ScriptFunction *node) const +void JSCompiler::Compile([[maybe_unused]] const ir::ScriptFunction *node) const { - (void)node; UNREACHABLE(); } @@ -437,27 +443,23 @@ void JSCompiler::Compile(const ir::SpreadElement *expr) const UNREACHABLE(); } -void JSCompiler::Compile(const ir::TemplateElement *expr) const +void JSCompiler::Compile([[maybe_unused]] const ir::TemplateElement *expr) const { - (void)expr; UNREACHABLE(); } -void JSCompiler::Compile(const ir::TSIndexSignature *node) const +void JSCompiler::Compile([[maybe_unused]] const ir::TSIndexSignature *node) const { - (void)node; UNREACHABLE(); } -void JSCompiler::Compile(const ir::TSMethodSignature *node) const +void JSCompiler::Compile([[maybe_unused]] const ir::TSMethodSignature *node) const { - (void)node; UNREACHABLE(); } -void JSCompiler::Compile(const ir::TSPropertySignature *node) const +void JSCompiler::Compile([[maybe_unused]] const ir::TSPropertySignature *node) const { - (void)node; UNREACHABLE(); } @@ -572,50 +574,248 @@ void JSCompiler::Compile(const ir::AssignmentExpression *expr) const void JSCompiler::Compile(const ir::AwaitExpression *expr) const { - (void)expr; - UNREACHABLE(); + PandaGen *pg = GetPandaGen(); + compiler::RegScope rs(pg); + + if (expr->Argument() != nullptr) { + expr->Argument()->Compile(pg); + } else { + pg->LoadConst(expr, compiler::Constant::JS_UNDEFINED); + } + + pg->EmitAwait(expr); +} + +static void CompileLogical(compiler::PandaGen *pg, const ir::BinaryExpression *expr) +{ + compiler::RegScope rs(pg); + compiler::VReg lhs = pg->AllocReg(); + + ASSERT(expr->OperatorType() == lexer::TokenType::PUNCTUATOR_LOGICAL_AND || + expr->OperatorType() == lexer::TokenType::PUNCTUATOR_LOGICAL_OR || + expr->OperatorType() == lexer::TokenType::PUNCTUATOR_NULLISH_COALESCING); + + auto *skip_right = pg->AllocLabel(); + auto *end_label = pg->AllocLabel(); + + // left -> acc -> lhs -> toboolean -> acc -> bool_lhs + expr->Left()->Compile(pg); + pg->StoreAccumulator(expr, lhs); + + if (expr->OperatorType() == lexer::TokenType::PUNCTUATOR_LOGICAL_AND) { + pg->ToBoolean(expr); + pg->BranchIfFalse(expr, skip_right); + } else if (expr->OperatorType() == lexer::TokenType::PUNCTUATOR_LOGICAL_OR) { + pg->ToBoolean(expr); + pg->BranchIfTrue(expr, skip_right); + } else if (expr->OperatorType() == lexer::TokenType::PUNCTUATOR_NULLISH_COALESCING) { + pg->BranchIfCoercible(expr, skip_right); + } + + // left is true/false(and/or) then right -> acc + expr->Right()->Compile(pg); + pg->Branch(expr, end_label); + + // left is false/true(and/or) then lhs -> acc + pg->SetLabel(expr, skip_right); + pg->LoadAccumulator(expr, lhs); + pg->SetLabel(expr, end_label); } void JSCompiler::Compile(const ir::BinaryExpression *expr) const +{ + PandaGen *pg = GetPandaGen(); + if (expr->IsLogical()) { + CompileLogical(pg, expr); + return; + } + + if (expr->OperatorType() == lexer::TokenType::KEYW_IN && expr->Left()->IsIdentifier() && + expr->Left()->AsIdentifier()->IsPrivateIdent()) { + compiler::RegScope rs(pg); + compiler::VReg ctor = pg->AllocReg(); + const auto &name = expr->Left()->AsIdentifier()->Name(); + compiler::Function::LoadClassContexts(expr, pg, ctor, name); + expr->Right()->Compile(pg); + pg->ClassPrivateFieldIn(expr, ctor, name); + return; + } + + compiler::RegScope rs(pg); + compiler::VReg lhs = pg->AllocReg(); + + expr->Left()->Compile(pg); + pg->StoreAccumulator(expr, lhs); + expr->Right()->Compile(pg); + + pg->Binary(expr, expr->OperatorType(), lhs); +} + +static compiler::VReg CreateSpreadArguments(compiler::PandaGen *pg, const ir::CallExpression *expr) +{ + compiler::VReg args_obj = pg->AllocReg(); + pg->CreateArray(expr, expr->Arguments(), args_obj); + + return args_obj; +} + +void JSCompiler::Compile(const ir::BlockExpression *expr) const { (void)expr; UNREACHABLE(); } +void CompileSuperExprWithoutSpread(PandaGen *pg, const ir::CallExpression *expr) +{ + compiler::RegScope param_scope(pg); + compiler::VReg arg_start {}; + + if (expr->Arguments().empty()) { + arg_start = pg->AllocReg(); + pg->StoreConst(expr, arg_start, compiler::Constant::JS_UNDEFINED); + } else { + arg_start = pg->NextReg(); + } + + for (const auto *it : expr->Arguments()) { + compiler::VReg arg = pg->AllocReg(); + it->Compile(pg); + pg->StoreAccumulator(it, arg); + } + + pg->GetFunctionObject(expr); + pg->SuperCall(expr, arg_start, expr->Arguments().size()); +} + void JSCompiler::Compile(const ir::CallExpression *expr) const { - (void)expr; - UNREACHABLE(); + PandaGen *pg = GetPandaGen(); + compiler::RegScope rs(pg); + bool contains_spread = util::Helpers::ContainSpreadElement(expr->Arguments()); + + if (expr->Callee()->IsSuperExpression()) { + if (contains_spread) { + compiler::RegScope param_scope(pg); + compiler::VReg args_obj = CreateSpreadArguments(pg, expr); + + pg->GetFunctionObject(expr); + pg->SuperCallSpread(expr, args_obj); + } else { + CompileSuperExprWithoutSpread(pg, expr); + } + + compiler::VReg new_this = pg->AllocReg(); + pg->StoreAccumulator(expr, new_this); + + pg->GetThis(expr); + pg->ThrowIfSuperNotCorrectCall(expr, 1); + + pg->LoadAccumulator(expr, new_this); + pg->SetThis(expr); + + compiler::Function::CompileInstanceFields(pg, pg->RootNode()->AsScriptFunction()); + return; + } + + compiler::VReg callee = pg->AllocReg(); + compiler::VReg this_reg = compiler::VReg::Invalid(); + + if (expr->Callee()->IsMemberExpression()) { + this_reg = pg->AllocReg(); + + compiler::RegScope mrs(pg); + expr->Callee()->AsMemberExpression()->CompileToReg(pg, this_reg); + } else if (expr->Callee()->IsChainExpression()) { + this_reg = pg->AllocReg(); + + compiler::RegScope mrs(pg); + expr->Callee()->AsChainExpression()->CompileToReg(pg, this_reg); + } else { + expr->Callee()->Compile(pg); + } + + pg->StoreAccumulator(expr, callee); + pg->OptionalChainCheck(expr->IsOptional(), callee); + + if (contains_spread || expr->Arguments().size() >= compiler::PandaGen::MAX_RANGE_CALL_ARG) { + if (this_reg.IsInvalid()) { + this_reg = pg->AllocReg(); + pg->StoreConst(expr, this_reg, compiler::Constant::JS_UNDEFINED); + } + + compiler::VReg args_obj = CreateSpreadArguments(pg, expr); + pg->CallSpread(expr, callee, this_reg, args_obj); + } else { + pg->Call(expr, callee, this_reg, expr->Arguments()); + } } void JSCompiler::Compile(const ir::ChainExpression *expr) const { - (void)expr; - UNREACHABLE(); + PandaGen *pg = GetPandaGen(); + compiler::OptionalChain chain(pg, expr); + expr->GetExpression()->Compile(pg); } void JSCompiler::Compile(const ir::ClassExpression *expr) const { - (void)expr; - UNREACHABLE(); + PandaGen *pg = GetPandaGen(); + expr->Definition()->Compile(pg); +} + +template +static void CompileImpl(const ir::ConditionalExpression *self, CodeGen *cg) +{ + auto *false_label = cg->AllocLabel(); + auto *end_label = cg->AllocLabel(); + + compiler::Condition::Compile(cg, self->Test(), false_label); + self->Consequent()->Compile(cg); + cg->Branch(self, end_label); + cg->SetLabel(self, false_label); + self->Alternate()->Compile(cg); + cg->SetLabel(self, end_label); } void JSCompiler::Compile(const ir::ConditionalExpression *expr) const { - (void)expr; - UNREACHABLE(); + PandaGen *pg = GetPandaGen(); + CompileImpl(expr, pg); } void JSCompiler::Compile(const ir::DirectEvalExpression *expr) const { - (void)expr; - UNREACHABLE(); + PandaGen *pg = GetPandaGen(); + if (expr->Arguments().empty()) { + pg->LoadConst(expr, compiler::Constant::JS_UNDEFINED); + return; + } + + compiler::RegScope rs(pg); + bool contains_spread = util::Helpers::ContainSpreadElement(expr->Arguments()); + if (contains_spread) { + [[maybe_unused]] compiler::VReg args_obj = CreateSpreadArguments(pg, expr); + pg->LoadObjByIndex(expr, 0); + } else { + compiler::VReg arg0 = pg->AllocReg(); + auto iter = expr->Arguments().cbegin(); + (*iter++)->Compile(pg); + pg->StoreAccumulator(expr, arg0); + + while (iter != expr->Arguments().cend()) { + (*iter++)->Compile(pg); + } + + pg->LoadAccumulator(expr, arg0); + } + + pg->DirectEval(expr, expr->parser_status_); } void JSCompiler::Compile(const ir::FunctionExpression *expr) const { - (void)expr; - UNREACHABLE(); + PandaGen *pg = GetPandaGen(); + pg->DefineFunction(expr->Function(), expr->Function(), expr->Function()->Scope()->InternalName()); } void JSCompiler::Compile(const ir::Identifier *expr) const @@ -728,26 +928,34 @@ void JSCompiler::Compile(const ir::CharLiteral *expr) const void JSCompiler::Compile(const ir::NullLiteral *expr) const { - (void)expr; - UNREACHABLE(); + PandaGen *pg = GetPandaGen(); + pg->LoadConst(expr, compiler::Constant::JS_NULL); } void JSCompiler::Compile(const ir::NumberLiteral *expr) const { - (void)expr; - UNREACHABLE(); + PandaGen *pg = GetPandaGen(); + if (std::isnan(expr->Number().GetDouble())) { + pg->LoadConst(expr, compiler::Constant::JS_NAN); + } else if (!std::isfinite(expr->Number().GetDouble())) { + pg->LoadConst(expr, compiler::Constant::JS_INFINITY); + } else if (util::Helpers::IsInteger(expr->Number().GetDouble())) { + pg->LoadAccumulatorInt(expr, static_cast(expr->Number().GetDouble())); + } else { + pg->LoadAccumulatorDouble(expr, expr->Number().GetDouble()); + } } void JSCompiler::Compile(const ir::RegExpLiteral *expr) const { - (void)expr; - UNREACHABLE(); + PandaGen *pg = GetPandaGen(); + pg->CreateRegExpWithLiteral(expr, expr->Pattern(), static_cast(expr->Flags())); } void JSCompiler::Compile(const ir::StringLiteral *expr) const { - (void)expr; - UNREACHABLE(); + PandaGen *pg = GetPandaGen(); + pg->LoadAccumulatorString(expr, expr->Str()); } void JSCompiler::Compile(const ir::UndefinedLiteral *expr) const @@ -757,51 +965,44 @@ void JSCompiler::Compile(const ir::UndefinedLiteral *expr) const } // Compile methods for MODULE-related nodes in alphabetical order -void JSCompiler::Compile(const ir::ExportAllDeclaration *st) const -{ - (void)st; - UNREACHABLE(); -} +void JSCompiler::Compile([[maybe_unused]] const ir::ExportAllDeclaration *st) const {} void JSCompiler::Compile(const ir::ExportDefaultDeclaration *st) const { - (void)st; - UNREACHABLE(); + PandaGen *pg = GetPandaGen(); + st->Decl()->Compile(pg); + pg->StoreModuleVar(st, "default"); } void JSCompiler::Compile(const ir::ExportNamedDeclaration *st) const { - (void)st; - UNREACHABLE(); -} + PandaGen *pg = GetPandaGen(); + if (st->Decl() == nullptr) { + return; + } -void JSCompiler::Compile(const ir::ExportSpecifier *st) const -{ - (void)st; - UNREACHABLE(); + st->Decl()->Compile(pg); } -void JSCompiler::Compile(const ir::ImportDeclaration *st) const +void JSCompiler::Compile([[maybe_unused]] const ir::ExportSpecifier *st) const { - (void)st; UNREACHABLE(); } -void JSCompiler::Compile(const ir::ImportDefaultSpecifier *st) const +void JSCompiler::Compile([[maybe_unused]] const ir::ImportDeclaration *st) const {} + +void JSCompiler::Compile([[maybe_unused]] const ir::ImportDefaultSpecifier *st) const { - (void)st; UNREACHABLE(); } -void JSCompiler::Compile(const ir::ImportNamespaceSpecifier *st) const +void JSCompiler::Compile([[maybe_unused]] const ir::ImportNamespaceSpecifier *st) const { - (void)st; UNREACHABLE(); } -void JSCompiler::Compile(const ir::ImportSpecifier *st) const +void JSCompiler::Compile([[maybe_unused]] const ir::ImportSpecifier *st) const { - (void)st; UNREACHABLE(); } // Compile methods for STATEMENTS in alphabetical order @@ -825,74 +1026,202 @@ void JSCompiler::Compile(const ir::BreakStatement *st) const void JSCompiler::Compile(const ir::ClassDeclaration *st) const { - (void)st; - UNREACHABLE(); + PandaGen *pg = GetPandaGen(); + auto lref = compiler::JSLReference::Create(pg, st->Definition()->Ident(), true); + st->Definition()->Compile(pg); + lref.SetValue(); } -void JSCompiler::Compile(const ir::ContinueStatement *st) const +static void CompileImpl(const ir::ContinueStatement *self, PandaGen *cg) { - (void)st; - UNREACHABLE(); + compiler::Label *target = cg->ControlFlowChangeContinue(self->Ident()); + cg->Branch(self, target); } -void JSCompiler::Compile(const ir::DebuggerStatement *st) const +void JSCompiler::Compile(const ir::ContinueStatement *st) const { - (void)st; - UNREACHABLE(); + PandaGen *pg = GetPandaGen(); + CompileImpl(st, pg); } -void JSCompiler::Compile(const ir::DoWhileStatement *st) const +void JSCompiler::Compile([[maybe_unused]] const ir::DebuggerStatement *st) const {} + +static void CompileImpl(const ir::DoWhileStatement *self, PandaGen *cg) { - (void)st; - UNREACHABLE(); + auto *start_label = cg->AllocLabel(); + compiler::LabelTarget label_target(cg); + + cg->SetLabel(self, start_label); + + { + compiler::LocalRegScope reg_scope(cg, self->Scope()); + compiler::LabelContext label_ctx(cg, label_target); + self->Body()->Compile(cg); + } + + cg->SetLabel(self, label_target.ContinueTarget()); + compiler::Condition::Compile(cg, self->Test(), label_target.BreakTarget()); + + cg->Branch(self, start_label); + cg->SetLabel(self, label_target.BreakTarget()); } -void JSCompiler::Compile(const ir::EmptyStatement *st) const +void JSCompiler::Compile(const ir::DoWhileStatement *st) const { - (void)st; - UNREACHABLE(); + PandaGen *pg = GetPandaGen(); + CompileImpl(st, pg); } +void JSCompiler::Compile([[maybe_unused]] const ir::EmptyStatement *st) const {} + void JSCompiler::Compile(const ir::ExpressionStatement *st) const { - (void)st; - UNREACHABLE(); + PandaGen *pg = GetPandaGen(); + st->GetExpression()->Compile(pg); } void JSCompiler::Compile(const ir::ForInStatement *st) const { - (void)st; - UNREACHABLE(); + PandaGen *pg = GetPandaGen(); + compiler::LabelTarget label_target(pg); + + compiler::RegScope rs(pg); + compiler::VReg iter = pg->AllocReg(); + compiler::VReg prop_name = pg->AllocReg(); + + // create enumerator + st->Right()->Compile(pg); + pg->GetPropIterator(st); + pg->StoreAccumulator(st, iter); + + pg->SetLabel(st, label_target.ContinueTarget()); + + // get next prop of enumerator + pg->GetNextPropName(st, iter); + pg->StoreAccumulator(st, prop_name); + pg->BranchIfUndefined(st, label_target.BreakTarget()); + + compiler::LocalRegScope decl_reg_scope(pg, st->Scope()->DeclScope()->InitScope()); + auto lref = compiler::JSLReference::Create(pg, st->Left(), false); + pg->LoadAccumulator(st, prop_name); + lref.SetValue(); + + compiler::LoopEnvScope decl_env_scope(pg, st->Scope()->DeclScope()); + + { + compiler::LoopEnvScope env_scope(pg, st->Scope(), label_target); + st->Body()->Compile(pg); + } + + pg->Branch(st, label_target.ContinueTarget()); + pg->SetLabel(st, label_target.BreakTarget()); } void JSCompiler::Compile(const ir::ForOfStatement *st) const { - (void)st; - UNREACHABLE(); + PandaGen *pg = GetPandaGen(); + compiler::LocalRegScope decl_reg_scope(pg, st->Scope()->DeclScope()->InitScope()); + + st->Right()->Compile(pg); + + compiler::LabelTarget label_target(pg); + auto iterator_type = st->IsAwait() ? compiler::IteratorType::ASYNC : compiler::IteratorType::SYNC; + compiler::Iterator iterator(pg, st, iterator_type); + + pg->SetLabel(st, label_target.ContinueTarget()); + + iterator.Next(); + iterator.Complete(); + pg->BranchIfTrue(st, label_target.BreakTarget()); + + iterator.Value(); + pg->StoreAccumulator(st, iterator.NextResult()); + + auto lref = compiler::JSLReference::Create(pg, st->Left(), false); + + { + compiler::IteratorContext for_of_ctx(pg, iterator, label_target); + pg->LoadAccumulator(st, iterator.NextResult()); + lref.SetValue(); + + compiler::LoopEnvScope decl_env_scope(pg, st->Scope()->DeclScope()); + compiler::LoopEnvScope env_scope(pg, st->Scope(), {}); + st->Body()->Compile(pg); + } + + pg->Branch(st, label_target.ContinueTarget()); + pg->SetLabel(st, label_target.BreakTarget()); } void JSCompiler::Compile(const ir::ForUpdateStatement *st) const { - (void)st; - UNREACHABLE(); + PandaGen *pg = GetPandaGen(); + compiler::LocalRegScope decl_reg_scope(pg, st->Scope()->DeclScope()->InitScope()); + + if (st->Init() != nullptr) { + ASSERT(st->Init()->IsVariableDeclaration() || st->Init()->IsExpression()); + st->Init()->Compile(pg); + } + + auto *start_label = pg->AllocLabel(); + compiler::LabelTarget label_target(pg); + + compiler::LoopEnvScope decl_env_scope(pg, st->Scope()->DeclScope()); + compiler::LoopEnvScope env_scope(pg, label_target, st->Scope()); + pg->SetLabel(st, start_label); + + { + compiler::LocalRegScope reg_scope(pg, st->Scope()); + + if (st->Test() != nullptr) { + compiler::Condition::Compile(pg, st->Test(), label_target.BreakTarget()); + } + + st->Body()->Compile(pg); + pg->SetLabel(st, label_target.ContinueTarget()); + env_scope.CopyPetIterationCtx(); + } + + if (st->Update() != nullptr) { + st->Update()->Compile(pg); + } + + pg->Branch(st, start_label); + pg->SetLabel(st, label_target.BreakTarget()); } -void JSCompiler::Compile(const ir::FunctionDeclaration *st) const +void JSCompiler::Compile([[maybe_unused]] const ir::FunctionDeclaration *st) const {} + +void JSCompiler::Compile(const ir::IfStatement *st) const { - (void)st; - UNREACHABLE(); + PandaGen *pg = GetPandaGen(); + auto *consequent_end = pg->AllocLabel(); + compiler::Label *statement_end = consequent_end; + + compiler::Condition::Compile(pg, st->Test(), consequent_end); + st->Consequent()->Compile(pg); + + if (st->Alternate() != nullptr) { + statement_end = pg->AllocLabel(); + pg->Branch(pg->Insns().back()->Node(), statement_end); + + pg->SetLabel(st, consequent_end); + st->Alternate()->Compile(pg); + } + + pg->SetLabel(st, statement_end); } -void JSCompiler::Compile(const ir::IfStatement *st) const +void CompileImpl(const ir::LabelledStatement *self, PandaGen *cg) { - (void)st; - UNREACHABLE(); + compiler::LabelContext label_ctx(cg, self); + self->Body()->Compile(cg); } void JSCompiler::Compile(const ir::LabelledStatement *st) const { - (void)st; - UNREACHABLE(); + PandaGen *pg = GetPandaGen(); + CompileImpl(st, pg); } void JSCompiler::Compile(const ir::ReturnStatement *st) const @@ -921,16 +1250,47 @@ void JSCompiler::Compile(const ir::ReturnStatement *st) const } } -void JSCompiler::Compile(const ir::SwitchCaseStatement *st) const +void JSCompiler::Compile([[maybe_unused]] const ir::SwitchCaseStatement *st) const { - (void)st; UNREACHABLE(); } +static void CompileImpl(const ir::SwitchStatement *self, PandaGen *cg) +{ + compiler::LocalRegScope lrs(cg, self->Scope()); + compiler::SwitchBuilder builder(cg, self); + compiler::VReg tag = cg->AllocReg(); + + builder.CompileTagOfSwitch(tag); + uint32_t default_index = 0; + + for (size_t i = 0; i < self->Cases().size(); i++) { + const auto *clause = self->Cases()[i]; + + if (clause->Test() == nullptr) { + default_index = i; + continue; + } + + builder.JumpIfCase(tag, i); + } + + if (default_index > 0) { + builder.JumpToDefault(default_index); + } else { + builder.Break(); + } + + for (size_t i = 0; i < self->Cases().size(); i++) { + builder.SetCaseTarget(i); + builder.CompileCaseStatements(i); + } +} + void JSCompiler::Compile(const ir::SwitchStatement *st) const { - (void)st; - UNREACHABLE(); + PandaGen *pg = GetPandaGen(); + CompileImpl(st, pg); } void JSCompiler::Compile(const ir::ThrowStatement *st) const @@ -963,9 +1323,8 @@ void JSCompiler::Compile(const ir::WhileStatement *st) const UNREACHABLE(); } // from ts folder -void JSCompiler::Compile(const ir::TSAnyKeyword *node) const +void JSCompiler::Compile([[maybe_unused]] const ir::TSAnyKeyword *node) const { - (void)node; UNREACHABLE(); } @@ -987,9 +1346,8 @@ void JSCompiler::Compile(const ir::TSBigintKeyword *node) const UNREACHABLE(); } -void JSCompiler::Compile(const ir::TSBooleanKeyword *node) const +void JSCompiler::Compile([[maybe_unused]] const ir::TSBooleanKeyword *node) const { - (void)node; UNREACHABLE(); } @@ -1011,21 +1369,18 @@ void JSCompiler::Compile(const ir::TSConstructorType *node) const UNREACHABLE(); } -void JSCompiler::Compile(const ir::TSEnumDeclaration *st) const +void JSCompiler::Compile([[maybe_unused]] const ir::TSEnumDeclaration *st) const { - (void)st; UNREACHABLE(); } -void JSCompiler::Compile(const ir::TSEnumMember *st) const +void JSCompiler::Compile([[maybe_unused]] const ir::TSEnumMember *st) const { - (void)st; UNREACHABLE(); } -void JSCompiler::Compile(const ir::TSExternalModuleReference *expr) const +void JSCompiler::Compile([[maybe_unused]] const ir::TSExternalModuleReference *expr) const { - (void)expr; UNREACHABLE(); } @@ -1131,15 +1486,13 @@ void JSCompiler::Compile(const ir::TSNullKeyword *node) const UNREACHABLE(); } -void JSCompiler::Compile(const ir::TSNumberKeyword *node) const +void JSCompiler::Compile([[maybe_unused]] const ir::TSNumberKeyword *node) const { - (void)node; UNREACHABLE(); } -void JSCompiler::Compile(const ir::TSObjectKeyword *node) const +void JSCompiler::Compile([[maybe_unused]] const ir::TSObjectKeyword *node) const { - (void)node; UNREACHABLE(); } @@ -1161,9 +1514,8 @@ void JSCompiler::Compile(const ir::TSQualifiedName *expr) const UNREACHABLE(); } -void JSCompiler::Compile(const ir::TSStringKeyword *node) const +void JSCompiler::Compile([[maybe_unused]] const ir::TSStringKeyword *node) const { - (void)node; UNREACHABLE(); } @@ -1239,9 +1591,8 @@ void JSCompiler::Compile(const ir::TSTypeReference *node) const UNREACHABLE(); } -void JSCompiler::Compile(const ir::TSUndefinedKeyword *node) const +void JSCompiler::Compile([[maybe_unused]] const ir::TSUndefinedKeyword *node) const { - (void)node; UNREACHABLE(); } @@ -1251,16 +1602,13 @@ void JSCompiler::Compile(const ir::TSUnionType *node) const UNREACHABLE(); } -void JSCompiler::Compile(const ir::TSUnknownKeyword *node) const +void JSCompiler::Compile([[maybe_unused]] const ir::TSUnknownKeyword *node) const { - (void)node; UNREACHABLE(); } -void JSCompiler::Compile(const ir::TSVoidKeyword *node) const +void JSCompiler::Compile([[maybe_unused]] const ir::TSVoidKeyword *node) const { - (void)node; UNREACHABLE(); } - -} // namespace panda::es2panda::compiler \ No newline at end of file +} // namespace panda::es2panda::compiler diff --git a/ets2panda/compiler/core/compilerContext.h b/ets2panda/compiler/core/compilerContext.h index 420a9fb18bc3e2407b8a89b958dd07da2dfce6eb..96e7144d450cdf54b18000960397670e80c3850a 100644 --- a/ets2panda/compiler/core/compilerContext.h +++ b/ets2panda/compiler/core/compilerContext.h @@ -16,13 +16,11 @@ #ifndef ES2PANDA_COMPILER_CORE_COMPILER_CONTEXT_H #define ES2PANDA_COMPILER_CORE_COMPILER_CONTEXT_H -#include "macros.h" -#include "mem/arena_allocator.h" +#include + #include "es2panda.h" #include "compiler/base/literals.h" - -#include -#include +#include "parser/parserImpl.h" namespace panda::es2panda::varbinder { class VarBinder; @@ -41,7 +39,7 @@ class CodeGen; class ProgramElement; class AstCompiler; -class CompilerContext { +class CompilerContext final { public: using CodeGenCb = std::function; @@ -52,72 +50,83 @@ public: { } + CompilerContext() = delete; NO_COPY_SEMANTIC(CompilerContext); NO_MOVE_SEMANTIC(CompilerContext); ~CompilerContext() = default; - varbinder::VarBinder *VarBinder() const + [[nodiscard]] varbinder::VarBinder *VarBinder() const noexcept { return varbinder_; } - checker::Checker *Checker() const + [[nodiscard]] checker::Checker *Checker() const noexcept { return checker_; } - Emitter *GetEmitter() const + [[nodiscard]] parser::ParserImpl *GetParser() const noexcept + { + return parser_; + } + + void SetParser(parser::ParserImpl *const parser) noexcept + { + parser_ = parser; + } + + [[nodiscard]] Emitter *GetEmitter() const noexcept { return emitter_; } - void SetEmitter(Emitter *emitter) + void SetEmitter(Emitter *emitter) noexcept { emitter_ = emitter; } - const CodeGenCb &GetCodeGenCb() const + [[nodiscard]] const CodeGenCb &GetCodeGenCb() const noexcept { return code_gen_cb_; } - int32_t AddContextLiteral(LiteralBuffer &&literals) + [[nodiscard]] int32_t AddContextLiteral(LiteralBuffer &&literals) { buff_storage_.emplace_back(std::move(literals)); return buff_storage_.size() - 1; } - const std::vector &ContextLiterals() const + [[nodiscard]] const std::vector &ContextLiterals() const noexcept { return buff_storage_; } - const CompilerOptions *Options() const + [[nodiscard]] const CompilerOptions *Options() const noexcept { return &options_; } - bool IsDebug() const + [[nodiscard]] bool IsDebug() const noexcept { return options_.is_debug; } - bool DumpDebugInfo() const + [[nodiscard]] bool DumpDebugInfo() const noexcept { return options_.dump_debug_info; } - bool IsDirectEval() const + [[nodiscard]] bool IsDirectEval() const noexcept { return options_.is_direct_eval; } - bool IsFunctionEval() const + [[nodiscard]] bool IsFunctionEval() const noexcept { return options_.is_function_eval; } - bool IsEval() const + [[nodiscard]] bool IsEval() const noexcept { return options_.is_eval; } @@ -125,6 +134,7 @@ public: private: varbinder::VarBinder *varbinder_; checker::Checker *checker_; + parser::ParserImpl *parser_ = nullptr; Emitter *emitter_ {}; std::vector buff_storage_; CompilerOptions options_; diff --git a/ets2panda/compiler/core/compilerImpl.cpp b/ets2panda/compiler/core/compilerImpl.cpp index 14bc8b7fbdbde505a5043aef2087f4e2f417a36d..31f07dcbf9ed4c9d9456d4ecffe34ccea7b76813 100644 --- a/ets2panda/compiler/core/compilerImpl.cpp +++ b/ets2panda/compiler/core/compilerImpl.cpp @@ -15,6 +15,7 @@ #include "compilerImpl.h" +#include "es2panda.h" #include "compiler/core/compilerContext.h" #include "compiler/core/compileQueue.h" #include "compiler/core/compilerImpl.h" @@ -41,12 +42,9 @@ #include "checker/ETSchecker.h" #include "checker/ASchecker.h" #include "checker/JSchecker.h" -#include "es2panda.h" +#include "public/public.h" #include "util/declgenEts2Ts.h" -#include -#include - namespace panda::es2panda::compiler { void CompilerImpl::HandleContextLiterals(CompilerContext *context) @@ -89,13 +87,28 @@ static CompilerContext::CodeGenCb MakeCompileJob() }; } +static void SetupPublicContext(public_lib::Context *context, const SourceFile *source_file, ArenaAllocator *allocator, + CompileQueue *queue, std::vector const *plugins, + parser::ParserImpl *parser, CompilerContext *compiler_context) +{ + context->source_file = source_file; + context->allocator = allocator; + context->queue = queue; + context->plugins = plugins; + context->parser = parser; + context->checker = compiler_context->Checker(); + context->analyzer = context->checker->GetAnalyzer(); + context->compiler_context = compiler_context; + context->emitter = compiler_context->GetEmitter(); +} + using EmitCb = std::function; using PhaseListGetter = std::function()>; template static pandasm::Program *CreateCompiler(const CompilationUnit &unit, const PhaseListGetter &get_phases, - const EmitCb &emit_cb) + CompilerImpl *compiler_impl) { ArenaAllocator allocator(SpaceType::SPACE_TYPE_COMPILER, nullptr, true); auto program = parser::Program::NewProgram(&allocator); @@ -114,48 +127,54 @@ static pandasm::Program *CreateCompiler(const CompilationUnit &unit, const Phase auto emitter = Emitter(&context); context.SetEmitter(&emitter); + context.SetParser(&parser); - parser.ParseScript(unit.input, unit.options.compilation_mode == CompilationMode::GEN_STD_LIB); + public_lib::Context public_context; + SetupPublicContext(&public_context, &unit.input, &allocator, compiler_impl->Queue(), &compiler_impl->Plugins(), + &parser, &context); + parser.ParseScript(unit.input, unit.options.compilation_mode == CompilationMode::GEN_STD_LIB); + if constexpr (std::is_same_v && std::is_same_v) { + reinterpret_cast(varbinder)->FillResolvedImportPathes(parser.ResolvedParsedSourcesMap(), + &allocator); + } for (auto *phase : get_phases()) { - if (!phase->Apply(&context, &program)) { + if (!phase->Apply(&public_context, &program)) { return nullptr; } } emitter.GenAnnotation(); - return emit_cb(&context); + return compiler_impl->Emit(&context); } pandasm::Program *CompilerImpl::Compile(const CompilationUnit &unit) { - auto emit_cb = [this](CompilerContext *context) -> pandasm::Program * { return Emit(context); }; - switch (unit.ext) { case ScriptExtension::TS: { return CreateCompiler(unit, compiler::GetTrivialPhaseList, - emit_cb); + this); } case ScriptExtension::AS: { return CreateCompiler(unit, compiler::GetTrivialPhaseList, - emit_cb); + this); } case ScriptExtension::ETS: { return CreateCompiler(unit, compiler::GetETSPhaseList, - emit_cb); + this); } case ScriptExtension::JS: { return CreateCompiler(unit, compiler::GetTrivialPhaseList, - emit_cb); + this); } default: { UNREACHABLE(); diff --git a/ets2panda/compiler/core/compilerImpl.h b/ets2panda/compiler/core/compilerImpl.h index cee0090c005d3e6cede14ae5c38d18c58b436d61..9ed854e5394b837053315b4b2a1bb77fa81e52d8 100644 --- a/ets2panda/compiler/core/compilerImpl.h +++ b/ets2panda/compiler/core/compilerImpl.h @@ -49,20 +49,35 @@ public: class CompilerImpl { public: - explicit CompilerImpl(size_t thread_count) : queue_(thread_count) {} + explicit CompilerImpl(size_t thread_count, std::vector const *plugins) + : queue_(thread_count), plugins_(plugins) + { + } NO_COPY_SEMANTIC(CompilerImpl); NO_MOVE_SEMANTIC(CompilerImpl); ~CompilerImpl() = default; pandasm::Program *Compile(const CompilationUnit &unit); + std::vector const &Plugins() + { + return *plugins_; + } + static void DumpAsm(const panda::pandasm::Program *prog); -private: panda::pandasm::Program *Emit(CompilerContext *context); + + CompileQueue *Queue() + { + return &queue_; + } + +private: static void HandleContextLiterals(CompilerContext *context); CompileQueue queue_; + std::vector const *plugins_; }; } // namespace panda::es2panda::compiler diff --git a/ets2panda/compiler/core/emitter.cpp b/ets2panda/compiler/core/emitter.cpp index 42a9e1593868f1dfd6651a73876e1250091b5ac7..3e44eed810a18e1bb84164c7e68da7918404c67c 100644 --- a/ets2panda/compiler/core/emitter.cpp +++ b/ets2panda/compiler/core/emitter.cpp @@ -312,8 +312,10 @@ void FunctionEmitter::GenScopeVariableInfo(pandasm::Function *func, const varbin GenLocalVariableInfo(variable_debug, param, start, vars_length, cg_->TotalRegsNum(), extension); } } - - for (const auto &[_, variable] : scope->Bindings()) { + const auto &unsorted_bindings = scope->Bindings(); + std::map bindings(unsorted_bindings.begin(), + unsorted_bindings.end()); + for (const auto &[_, variable] : bindings) { (void)_; if (!variable->IsLocalVariable() || variable->LexicalBound() || variable->Declaration()->IsParameterDecl() || variable->Declaration()->IsTypeAliasDecl()) { @@ -347,7 +349,6 @@ void FunctionEmitter::GenVariablesDebugInfo(pandasm::Function *func) Emitter::Emitter(const CompilerContext *context) : context_(context) { prog_ = new pandasm::Program(); - prog_->function_table.reserve(context->VarBinder()->Functions().size()); } Emitter::~Emitter() diff --git a/ets2panda/compiler/lowering/checkerPhase.cpp b/ets2panda/compiler/lowering/checkerPhase.cpp index a6c865ca83bb8b1ae64008e1268c4d16c70e848c..9d9c74108751a71f1c2a22c1b528a50a259867ca 100644 --- a/ets2panda/compiler/lowering/checkerPhase.cpp +++ b/ets2panda/compiler/lowering/checkerPhase.cpp @@ -18,9 +18,9 @@ #include "compiler/core/compilerContext.h" namespace panda::es2panda::compiler { -bool CheckerPhase::Perform(CompilerContext *ctx, [[maybe_unused]] parser::Program *program) +bool CheckerPhase::Perform(public_lib::Context *ctx, [[maybe_unused]] parser::Program *program) { - return ctx->Checker()->StartChecker(ctx->VarBinder(), *ctx->Options()); + return ctx->checker->StartChecker(ctx->compiler_context->VarBinder(), *ctx->compiler_context->Options()); } } // namespace panda::es2panda::compiler diff --git a/ets2panda/compiler/lowering/checkerPhase.h b/ets2panda/compiler/lowering/checkerPhase.h index 86e0db579bd58b4821d836ed9c05005a55cc8748..ef42e7004bac3154dedd78a1dd44ece3f79e51a5 100644 --- a/ets2panda/compiler/lowering/checkerPhase.h +++ b/ets2panda/compiler/lowering/checkerPhase.h @@ -20,13 +20,12 @@ namespace panda::es2panda::compiler { class CheckerPhase : public Phase { - std::string const &Name() override + std::string_view Name() override { - static std::string const NAME = "checker"; - return NAME; + return "checker"; } - bool Perform(CompilerContext *ctx, parser::Program *program) override; + bool Perform(public_lib::Context *ctx, parser::Program *program) override; }; } // namespace panda::es2panda::compiler diff --git a/ets2panda/compiler/lowering/ets/generateDeclarations.cpp b/ets2panda/compiler/lowering/ets/generateDeclarations.cpp index 41393a607b8e170c7eab618830d4765d4e3e74cb..96472eae5015737399508c79f631274e485363d2 100644 --- a/ets2panda/compiler/lowering/ets/generateDeclarations.cpp +++ b/ets2panda/compiler/lowering/ets/generateDeclarations.cpp @@ -19,11 +19,12 @@ #include "util/declgenEts2Ts.h" namespace panda::es2panda::compiler { -bool GenerateTsDeclarationsPhase::Perform(CompilerContext *ctx, parser::Program *program) +bool GenerateTsDeclarationsPhase::Perform(public_lib::Context *ctx, parser::Program *program) { - auto *checker = ctx->Checker(); - return (ctx->Options()->ts_decl_out.empty() || - util::GenerateTsDeclarations(checker->AsETSChecker(), program, ctx->Options()->ts_decl_out)); + auto *checker = ctx->checker; + return ( + ctx->compiler_context->Options()->ts_decl_out.empty() || + util::GenerateTsDeclarations(checker->AsETSChecker(), program, ctx->compiler_context->Options()->ts_decl_out)); } } // namespace panda::es2panda::compiler diff --git a/ets2panda/compiler/lowering/ets/generateDeclarations.h b/ets2panda/compiler/lowering/ets/generateDeclarations.h index fb7fcea3fdf721a01dffa15195528d964a803449..15ab3c61ef11d7d8962e305089a076684093a707 100644 --- a/ets2panda/compiler/lowering/ets/generateDeclarations.h +++ b/ets2panda/compiler/lowering/ets/generateDeclarations.h @@ -22,12 +22,11 @@ namespace panda::es2panda::compiler { class GenerateTsDeclarationsPhase : public Phase { public: - std::string const &Name() override + std::string_view Name() override { - static std::string const NAME = "generate-ts-declarations"; - return NAME; + return "generate-ts-declarations"; } - bool Perform(CompilerContext *ctx, parser::Program *program) override; + bool Perform(public_lib::Context *ctx, parser::Program *program) override; }; } // namespace panda::es2panda::compiler diff --git a/ets2panda/compiler/lowering/ets/opAssignment.cpp b/ets2panda/compiler/lowering/ets/opAssignment.cpp index 03ecf30834638433b677dd8cf385f568d88f2c15..aaea5422ca853f2cbbced80e7ac76c031b466d9a 100644 --- a/ets2panda/compiler/lowering/ets/opAssignment.cpp +++ b/ets2panda/compiler/lowering/ets/opAssignment.cpp @@ -15,9 +15,6 @@ // // This is a sample lowering, of little value by itself. -// NOTE: gobabr. -// - temporary variables are inserted into the current scope without any accompanying definition -// construction; most likely, a proper AST checker would complain. // // desc: A compound assignment expression of the form E1 op= E2 is equivalent to E1 = // ((E1) op (E2)) as T, where T is the type of E1, except that E1 is evaluated only @@ -25,29 +22,24 @@ // #include "opAssignment.h" -#include "checker/types/typeFlag.h" -#include "varbinder/variableFlags.h" + +#include "parser/ETSparser.h" +#include "varbinder/ETSBinder.h" #include "checker/ETSchecker.h" -#include "compiler/core/compilerContext.h" #include "compiler/lowering/util.h" -#include "ir/astNode.h" -#include "ir/expression.h" #include "ir/opaqueTypeNode.h" #include "ir/expressions/assignmentExpression.h" -#include "ir/expressions/binaryExpression.h" #include "ir/expressions/identifier.h" #include "ir/expressions/memberExpression.h" -#include "ir/expressions/sequenceExpression.h" +#include "ir/expressions/blockExpression.h" #include "ir/statements/blockStatement.h" -#include "ir/ts/tsAsExpression.h" -#include "lexer/token/tokenType.h" +#include "ir/statements/expressionStatement.h" namespace panda::es2panda::compiler { -std::string const &OpAssignmentLowering::Name() +std::string_view OpAssignmentLowering::Name() { - static std::string const NAME = "op-assignment"; - return NAME; + return "op-assignment"; } struct Conversion { @@ -83,52 +75,6 @@ static lexer::TokenType OpEqualToOp(const lexer::TokenType op_equal) UNREACHABLE(); } -// This should probably be a virtual method of AstNode -static ir::AstNode *CloneNode(checker::ETSChecker *checker, ir::AstNode *ast) -{ - if (ast->IsIdentifier()) { - const auto *id = ast->AsIdentifier(); - auto *res = checker->AllocNode(id->Name(), id->TypeAnnotation(), checker->Allocator()); - res->SetVariable(id->Variable()); - res->SetOptional(id->IsOptional()); - res->SetReference(id->IsReference()); - - if (id->IsTdz()) { - res->SetTdz(); - } - - if (id->IsAccessor()) { - res->SetAccessor(); - } - - if (id->IsMutator()) { - res->SetMutator(); - } - - res->SetPrivate(id->IsPrivate()); - if (id->IsIgnoreBox()) { - res->SetIgnoreBox(); - } - - return res; - } - - ASSERT(ast->IsMemberExpression()); - - auto *me = ast->AsMemberExpression(); - auto *object = CloneNode(checker, me->Object())->AsExpression(); - auto *property = CloneNode(checker, me->Property())->AsExpression(); - - auto *res = - checker->AllocNode(object, property, me->Kind(), me->IsComputed(), me->IsOptional()); - res->SetPropVar(me->PropVar()); - if (me->IsIgnoreBox()) { - res->SetIgnoreBox(); - } - - return res; -} - void AdjustBoxingUnboxingFlags(ir::Expression *new_expr, const ir::Expression *old_expr) { // NOTE: gogabr. make sure that the checker never puts both a boxing and an unboxing flag on the same node. @@ -138,117 +84,133 @@ void AdjustBoxingUnboxingFlags(ir::Expression *new_expr, const ir::Expression *o const ir::BoxingUnboxingFlags old_unboxing_flag {old_expr->GetBoxingUnboxingFlags() & ir::BoxingUnboxingFlags::UNBOXING_FLAG}; - if (new_expr->TsType()->HasTypeFlag(checker::TypeFlag::ETS_PRIMITIVE) && - old_boxing_flag != ir::BoxingUnboxingFlags::NONE) { + if (new_expr->TsType()->HasTypeFlag(checker::TypeFlag::ETS_PRIMITIVE)) { new_expr->SetBoxingUnboxingFlags(old_boxing_flag); - } else if (new_expr->TsType()->IsETSObjectType() && old_unboxing_flag != ir::BoxingUnboxingFlags::NONE) { + } else if (new_expr->TsType()->IsETSObjectType()) { new_expr->SetBoxingUnboxingFlags(old_unboxing_flag); } } -ir::Expression *HandleOpAssignment(checker::ETSChecker *checker, ir::AssignmentExpression *assignment) +ir::Expression *HandleOpAssignment(checker::ETSChecker *checker, parser::ETSParser *parser, + ir::AssignmentExpression *assignment) { if (assignment->TsType() == nullptr) { // hasn't been through checker return assignment; } - checker::SavedCheckerContext scc {checker, checker::CheckerStatus::IGNORE_VISIBILITY}; + const auto op_equal = assignment->OperatorType(); + ASSERT(op_equal != lexer::TokenType::PUNCTUATOR_SUBSTITUTION); + ASSERT(parser != nullptr); - ir::Expression *tmp_assignment_for_obj = nullptr; - ir::Expression *tmp_assignment_for_prop = nullptr; - ir::Expression *left_adjusted = nullptr; + auto *const allocator = checker->Allocator(); - auto *left = assignment->Left(); - auto *right = assignment->Right(); + auto *const left = assignment->Left(); + auto *const right = assignment->Right(); + auto *const scope = NearestScope(assignment); - const auto op_equal = assignment->OperatorType(); - ASSERT(op_equal != lexer::TokenType::PUNCTUATOR_SUBSTITUTION); + std::string new_assignment_statements {}; - if (left->IsIdentifier() || (left->IsMemberExpression() && left->AsMemberExpression()->Object()->IsIdentifier() && - left->AsMemberExpression()->Property()->IsIdentifier())) { - left_adjusted = left->AsExpression(); - } else { - ASSERT(left->IsMemberExpression()); - - auto *left_memb = left->AsMemberExpression(); - auto *scope = NearestScope(assignment); - - auto *tmp_obj_var_id = Gensym(checker->Allocator()); - auto *tmp_obj_var = scope->AddDecl( - checker->Allocator(), tmp_obj_var_id->Name(), varbinder::VariableFlags::LOCAL); - tmp_obj_var->SetTsType(left_memb->Object()->TsType()); - tmp_obj_var_id->SetVariable(tmp_obj_var); - tmp_obj_var_id->SetTsType(tmp_obj_var->TsType()); - tmp_assignment_for_obj = checker->AllocNode( - tmp_obj_var_id, left_memb->Object(), lexer::TokenType::PUNCTUATOR_SUBSTITUTION); - - tmp_assignment_for_obj->SetTsType(tmp_obj_var->TsType()); - - auto *property = left_memb->Property(); - if (!property->IsIdentifier()) { - auto *tmp_prop_var_id = Gensym(checker->Allocator()); - auto *tmp_prop_var = scope->AddDecl( - checker->Allocator(), tmp_prop_var_id->Name(), varbinder::VariableFlags::LOCAL); - tmp_prop_var->SetTsType(left_memb->Property()->TsType()); - tmp_prop_var_id->SetVariable(tmp_prop_var); - tmp_prop_var_id->SetTsType(tmp_prop_var->TsType()); - - tmp_assignment_for_prop = checker->AllocNode( - tmp_prop_var_id, left_memb->Property(), lexer::TokenType::PUNCTUATOR_SUBSTITUTION); - tmp_assignment_for_prop->SetTsType(tmp_prop_var->TsType()); - property = tmp_prop_var_id; - } + ir::Identifier *ident1; + ir::Identifier *ident2 = nullptr; + ir::Expression *object = nullptr; + ir::Expression *property = nullptr; - left_adjusted = checker->AllocNode(tmp_obj_var_id, property, left_memb->Kind(), - left_memb->IsComputed(), left_memb->IsOptional()); - left_adjusted->AsMemberExpression()->SetPropVar(left_memb->PropVar()); - left_adjusted->AsMemberExpression()->SetObjectType(left_memb->ObjType()); - left_adjusted->SetTsType(left->TsType()); + checker::SavedCheckerContext scc {checker, checker::CheckerStatus::IGNORE_VISIBILITY}; - if (left_memb->IsIgnoreBox()) { - left_adjusted->AsMemberExpression()->SetIgnoreBox(); + // Create temporary variable(s) if left hand of assignment is not defined by simple identifier[s] + if (left->IsIdentifier()) { + ident1 = left->AsIdentifier(); + } else if (left->IsMemberExpression()) { + auto *const member_expression = left->AsMemberExpression(); + + if (object = member_expression->Object(); object->IsIdentifier()) { + ident1 = object->AsIdentifier(); + } else { + ident1 = Gensym(allocator); + new_assignment_statements = "let @@I1 = (@@E2); "; } - } - left_adjusted->SetBoxingUnboxingFlags(ir::BoxingUnboxingFlags::NONE); // to be recomputed - auto *left_cloned = CloneNode(checker, left_adjusted)->AsExpression(); - auto *new_right = checker->AllocNode(left_cloned, right, OpEqualToOp(op_equal)); - - auto *lc_type = left_cloned->Check(checker); + if (property = member_expression->Property(); property->IsIdentifier()) { + ident2 = property->AsIdentifier(); + } else { + ident2 = Gensym(allocator); + new_assignment_statements += "let @@I3 = (@@E4); "; + } + } else { + UNREACHABLE(); + } + // Create proxy TypeNode for left hand of assignment expression + auto *lc_type = left->TsType(); if (auto *lc_type_as_primitive = checker->ETSBuiltinTypeAsPrimitiveType(lc_type); lc_type_as_primitive != nullptr) { lc_type = lc_type_as_primitive; } - - auto *lc_type_node = checker->AllocNode(lc_type); - auto *new_right_converted = checker->AllocNode(new_right, lc_type_node, false); - auto *new_assignment = checker->AllocNode(left_adjusted, new_right_converted, - lexer::TokenType::PUNCTUATOR_SUBSTITUTION); - - ir::Expression *res = new_assignment; - if (tmp_assignment_for_obj != nullptr) { - ArenaVector seq_exprs {checker->Allocator()->Adapter()}; - seq_exprs.push_back(tmp_assignment_for_obj); - - if (tmp_assignment_for_prop != nullptr) { - seq_exprs.push_back(tmp_assignment_for_prop); + auto *expr_type = checker->AllocNode(lc_type); + + // Generate ArkTS code string for new lowered assignment expression: + std::string left_hand = "@@I5"; + std::string right_hand = "@@I7"; + + if (ident2 != nullptr) { + if (auto const kind = left->AsMemberExpression()->Kind(); kind == ir::MemberExpressionKind::PROPERTY_ACCESS) { + left_hand += ".@@I6"; + right_hand += ".@@I8"; + } else if (kind == ir::MemberExpressionKind::ELEMENT_ACCESS) { + left_hand += "[@@I6]"; + right_hand += "[@@I8]"; + } else { + UNREACHABLE(); } + } - seq_exprs.push_back(new_assignment); - auto *seq = checker->AllocNode(std::move(seq_exprs)); - res = seq; + new_assignment_statements += left_hand + " = (" + right_hand + ' ' + + std::string {lexer::TokenToString(OpEqualToOp(op_equal))} + " (@@E9)) as @@T10"; + // std::cout << "Lowering statements: " << new_assignment_statements << std::endl; + + // Parse ArkTS code string and create and process corresponding AST node(s) + auto expression_ctx = varbinder::LexicalScope::Enter(checker->VarBinder(), scope); + + auto *lowering_result = parser->CreateFormattedExpression( + new_assignment_statements, parser::DEFAULT_SOURCE_FILE, ident1, object, ident2, property, + ident1->Clone(allocator), ident2 != nullptr ? ident2->Clone(allocator) : nullptr, ident1->Clone(allocator), + ident2 != nullptr ? ident2->Clone(allocator) : nullptr, right, expr_type); + lowering_result->SetParent(assignment->Parent()); + + checker->VarBinder()->AsETSBinder()->ResolveReferencesForScope(lowering_result, scope); + lowering_result->Check(checker); + + // Adjust [un]boxing flag + ir::AssignmentExpression *new_assignment; + if (lowering_result->IsAssignmentExpression()) { + new_assignment = lowering_result->AsAssignmentExpression(); + } else if (lowering_result->IsBlockExpression() && !lowering_result->AsBlockExpression()->Statements().empty() && + lowering_result->AsBlockExpression()->Statements().back()->IsExpressionStatement() && + lowering_result->AsBlockExpression() + ->Statements() + .back() + ->AsExpressionStatement() + ->GetExpression() + ->IsAssignmentExpression()) { + new_assignment = lowering_result->AsBlockExpression() + ->Statements() + .back() + ->AsExpressionStatement() + ->GetExpression() + ->AsAssignmentExpression(); + } else { + UNREACHABLE(); } - res->SetParent(assignment->Parent()); - new_assignment->Check(checker); + // NOTE(gogabr): make sure that the checker never puts both a boxing and an unboxing flag on the same node. + // Then this code will become unnecessary. AdjustBoxingUnboxingFlags(new_assignment, assignment); - return res; + return lowering_result; } -bool OpAssignmentLowering::Perform(CompilerContext *ctx, parser::Program *program) +bool OpAssignmentLowering::Perform(public_lib::Context *ctx, parser::Program *program) { - if (ctx->Options()->compilation_mode == CompilationMode::GEN_STD_LIB) { + if (ctx->compiler_context->Options()->compilation_mode == CompilationMode::GEN_STD_LIB) { for (auto &[_, ext_programs] : program->ExternalSources()) { (void)_; for (auto *ext_prog : ext_programs) { @@ -257,12 +219,13 @@ bool OpAssignmentLowering::Perform(CompilerContext *ctx, parser::Program *progra } } - checker::ETSChecker *checker = ctx->Checker()->AsETSChecker(); + auto *const parser = ctx->parser->AsETSParser(); + checker::ETSChecker *checker = ctx->checker->AsETSChecker(); - program->Ast()->TransformChildrenRecursively([checker](ir::AstNode *ast) -> ir::AstNode * { + program->Ast()->TransformChildrenRecursively([checker, parser](ir::AstNode *ast) -> ir::AstNode * { if (ast->IsAssignmentExpression() && ast->AsAssignmentExpression()->OperatorType() != lexer::TokenType::PUNCTUATOR_SUBSTITUTION) { - return HandleOpAssignment(checker, ast->AsAssignmentExpression()); + return HandleOpAssignment(checker, parser, ast->AsAssignmentExpression()); } return ast; @@ -271,9 +234,9 @@ bool OpAssignmentLowering::Perform(CompilerContext *ctx, parser::Program *progra return true; } -bool OpAssignmentLowering::Postcondition(CompilerContext *ctx, const parser::Program *program) +bool OpAssignmentLowering::Postcondition(public_lib::Context *ctx, const parser::Program *program) { - if (ctx->Options()->compilation_mode == CompilationMode::GEN_STD_LIB) { + if (ctx->compiler_context->Options()->compilation_mode == CompilationMode::GEN_STD_LIB) { for (auto &[_, ext_programs] : program->ExternalSources()) { (void)_; for (auto *ext_prog : ext_programs) { diff --git a/ets2panda/compiler/lowering/ets/opAssignment.h b/ets2panda/compiler/lowering/ets/opAssignment.h index b3c8dbd789b419afdf7683eabd8f93629b426661..407d558a2e32051fa9ed61591cee17172df188d2 100644 --- a/ets2panda/compiler/lowering/ets/opAssignment.h +++ b/ets2panda/compiler/lowering/ets/opAssignment.h @@ -22,9 +22,9 @@ namespace panda::es2panda::compiler { class OpAssignmentLowering : public Phase { public: - std::string const &Name() override; - bool Perform(CompilerContext *ctx, parser::Program *program) override; - bool Postcondition(CompilerContext *ctx, const parser::Program *program) override; + std::string_view Name() override; + bool Perform(public_lib::Context *ctx, parser::Program *program) override; + bool Postcondition(public_lib::Context *ctx, const parser::Program *program) override; }; } // namespace panda::es2panda::compiler diff --git a/ets2panda/compiler/lowering/ets/unionLowering.cpp b/ets2panda/compiler/lowering/ets/unionLowering.cpp index f036bdab81d8125c6a4a86a88fdf445edff8c45f..c9e0335ac9f5fc194af8760a728ea24091d18b61 100644 --- a/ets2panda/compiler/lowering/ets/unionLowering.cpp +++ b/ets2panda/compiler/lowering/ets/unionLowering.cpp @@ -17,30 +17,29 @@ #include "varbinder/variableFlags.h" #include "varbinder/ETSBinder.h" #include "checker/ETSchecker.h" +#include "checker/ets/conversion.h" +#include "checker/ets/boxingConverter.h" #include "compiler/core/compilerContext.h" +#include "compiler/lowering/util.h" #include "ir/base/classDefinition.h" #include "ir/base/classProperty.h" #include "ir/astNode.h" #include "ir/expression.h" #include "ir/opaqueTypeNode.h" -#include "ir/ets/etsParameterExpression.h" -#include "ir/expressions/assignmentExpression.h" #include "ir/expressions/binaryExpression.h" #include "ir/expressions/identifier.h" -#include "ir/expressions/functionExpression.h" #include "ir/expressions/memberExpression.h" -#include "ir/expressions/sequenceExpression.h" #include "ir/statements/blockStatement.h" #include "ir/statements/classDeclaration.h" +#include "ir/statements/variableDeclaration.h" #include "ir/ts/tsAsExpression.h" #include "type_helper.h" namespace panda::es2panda::compiler { -std::string const &UnionLowering::Name() +std::string_view UnionLowering::Name() { - static std::string const NAME = "union-property-access"; - return NAME; + return "union-property-access"; } ir::ClassDefinition *GetUnionFieldClass(checker::ETSChecker *checker, varbinder::VarBinder *varbinder) @@ -115,47 +114,262 @@ void HandleUnionPropertyAccess(checker::ETSChecker *checker, varbinder::VarBinde ASSERT(expr->PropVar() != nullptr); } -ir::Expression *HandleBinaryExpressionWithUnion(checker::ETSChecker *checker, ir::BinaryExpression *expr) +ir::TSAsExpression *GenAsExpression(checker::ETSChecker *checker, checker::Type *const opaque_type, + ir::Expression *const node, ir::AstNode *const parent) { - auto *union_type = expr->OperationType()->AsETSUnionType(); - ir::Expression *union_node; - ir::Expression *other_union_node = nullptr; - checker::Type *other_node_type; - if (expr->Left()->TsType()->IsETSUnionType()) { - union_node = expr->Left(); - other_node_type = expr->Right()->TsType(); - if (other_node_type->IsETSUnionType()) { - other_union_node = expr->Right(); + auto *const type_node = checker->AllocNode(opaque_type); + auto *const as_expression = checker->AllocNode(node, type_node, false); + as_expression->SetParent(parent); + node->SetParent(as_expression); + as_expression->Check(checker); + return as_expression; +} + +/* + * Function that generates conversion from (union) to (primitive) type as to `as` expressions: + * (union) as (prim) => ((union) as (ref)) as (prim), + * where (ref) is some unboxable type from union constituent types. + * Finally, `(union) as (prim)` expression replaces union_node that came above. + */ +ir::TSAsExpression *UnionCastToPrimitive(checker::ETSChecker *checker, checker::ETSObjectType *unboxable_ref, + checker::Type *unboxed_prim, ir::Expression *union_node) +{ + auto *const union_as_ref_expression = GenAsExpression(checker, unboxable_ref, union_node, nullptr); + union_as_ref_expression->SetBoxingUnboxingFlags(checker->GetUnboxingFlag(unboxed_prim)); + union_node->SetParent(union_as_ref_expression); + + auto *const ref_as_prim_expression = + GenAsExpression(checker, unboxed_prim, union_as_ref_expression, union_node->Parent()); + union_as_ref_expression->SetParent(ref_as_prim_expression); + + return ref_as_prim_expression; +} + +ir::TSAsExpression *HandleUnionCastToPrimitive(checker::ETSChecker *checker, ir::TSAsExpression *expr) +{ + auto *const union_type = expr->Expr()->TsType()->AsETSUnionType(); + auto *source_type = union_type->FindExactOrBoxedType(checker, expr->TsType()); + if (source_type == nullptr) { + source_type = union_type->AsETSUnionType()->FindTypeIsCastableToSomeType(expr->Expr(), checker->Relation(), + expr->TsType()); + } + if (source_type != nullptr && expr->Expr()->GetBoxingUnboxingFlags() != ir::BoxingUnboxingFlags::NONE) { + if (expr->TsType()->HasTypeFlag(checker::TypeFlag::ETS_PRIMITIVE)) { + auto *const boxed_expr_type = checker::BoxingConverter::ETSTypeFromSource(checker, expr->TsType()); + auto *const as_expr = GenAsExpression(checker, boxed_expr_type, expr->Expr(), expr); + as_expr->SetBoxingUnboxingFlags(expr->Expr()->GetBoxingUnboxingFlags()); + expr->Expr()->SetBoxingUnboxingFlags(ir::BoxingUnboxingFlags::NONE); + expr->SetExpr(as_expr); } - } else { - union_node = expr->Right(); - other_node_type = expr->Left()->TsType(); + return expr; } - auto *source_type = - union_type->AsETSUnionType()->FindTypeIsCastableToSomeType(union_node, checker->Relation(), other_node_type); - if (source_type == nullptr) { - checker->ThrowTypeError("Bad operand type, some type of the union must be the same type as other expression.", - expr->Start()); - } - if ((union_node->GetBoxingUnboxingFlags() & ir::BoxingUnboxingFlags::BOXING_FLAG) != 0U && - source_type->HasTypeFlag(checker::TypeFlag::ETS_ARRAY_OR_OBJECT)) { - union_node->SetBoxingUnboxingFlags(ir::BoxingUnboxingFlags::NONE); - } - auto *union_type_node = checker->AllocNode(source_type); - auto *as_expression = checker->AllocNode(union_node, union_type_node, false); - as_expression->SetParent(expr); - expr->SetOperationType(source_type); - if (other_union_node != nullptr) { - auto *other_union_type_node = checker->AllocNode(other_node_type); - auto *other_as_expression = - checker->AllocNode(other_union_node, other_union_type_node, false); - other_as_expression->SetParent(expr); + auto *const unboxable_union_type = source_type != nullptr ? source_type : union_type->FindUnboxableType(); + auto *const unboxed_union_type = checker->ETSBuiltinTypeAsPrimitiveType(unboxable_union_type); + expr->SetExpr( + UnionCastToPrimitive(checker, unboxable_union_type->AsETSObjectType(), unboxed_union_type, expr->Expr())); + return expr; +} + +ir::BinaryExpression *GenInstanceofExpr(checker::ETSChecker *checker, ir::Expression *union_node, + checker::Type *constituent_type) +{ + auto *const lhs_expr = union_node->Clone(checker->Allocator())->AsExpression(); + lhs_expr->Check(checker); + lhs_expr->SetBoxingUnboxingFlags(union_node->GetBoxingUnboxingFlags()); + auto *rhs_type = constituent_type; + if (!constituent_type->HasTypeFlag(checker::TypeFlag::ETS_ARRAY_OR_OBJECT)) { + checker->Relation()->SetNode(union_node); + rhs_type = checker::conversion::Boxing(checker->Relation(), constituent_type); + checker->Relation()->SetNode(nullptr); } + auto *const rhs_expr = + checker->Allocator()->New(rhs_type->AsETSObjectType()->Name(), checker->Allocator()); + auto *const instanceof_expr = + checker->Allocator()->New(lhs_expr, rhs_expr, lexer::TokenType::KEYW_INSTANCEOF); + lhs_expr->SetParent(instanceof_expr); + rhs_expr->SetParent(instanceof_expr); + auto rhs_var = NearestScope(union_node)->Find(rhs_expr->Name()); + rhs_expr->SetVariable(rhs_var.variable); + rhs_expr->SetTsType(rhs_var.variable->TsType()); + instanceof_expr->SetOperationType(checker->GlobalETSObjectType()); + instanceof_expr->SetTsType(checker->GlobalETSBooleanType()); + return instanceof_expr; +} + +ir::VariableDeclaration *GenVariableDeclForBinaryExpr(checker::ETSChecker *checker, varbinder::Scope *scope, + ir::BinaryExpression *expr) +{ + ASSERT(expr->OperatorType() == lexer::TokenType::PUNCTUATOR_EQUAL || + expr->OperatorType() == lexer::TokenType::PUNCTUATOR_NOT_EQUAL); + auto *var_id = Gensym(checker->Allocator()); + auto *var = scope->AddDecl(checker->Allocator(), var_id->Name(), + varbinder::VariableFlags::LOCAL); + var->SetTsType(checker->GlobalETSBooleanType()); + var_id->SetVariable(var); + var_id->SetTsType(var->TsType()); + + auto declarator = checker->AllocNode(var_id); + ArenaVector declarators(checker->Allocator()->Adapter()); + declarators.push_back(declarator); + + auto var_kind = ir::VariableDeclaration::VariableDeclarationKind::LET; + auto *binary_var_decl = + checker->AllocNode(var_kind, checker->Allocator(), std::move(declarators), false); + binary_var_decl->SetRange({expr->Start(), expr->End()}); + return binary_var_decl; +} + +ir::ExpressionStatement *GenExpressionStmtWithAssignment(checker::ETSChecker *checker, ir::Identifier *var_decl_id, + ir::Expression *expr) +{ + auto *assignment_for_binary = + checker->AllocNode(var_decl_id, expr, lexer::TokenType::PUNCTUATOR_SUBSTITUTION); + assignment_for_binary->SetTsType(expr->TsType()); + return checker->AllocNode(assignment_for_binary); +} + +ir::BlockStatement *GenBlockStmtForAssignmentBinary(checker::ETSChecker *checker, ir::Identifier *var_decl_id, + ir::Expression *expr) +{ + auto local_ctx = varbinder::LexicalScope(checker->VarBinder()); + ArenaVector stmts(checker->Allocator()->Adapter()); + auto *stmt = GenExpressionStmtWithAssignment(checker, var_decl_id, expr); + stmts.push_back(stmt); + auto *const local_block_stmt = + checker->AllocNode(checker->Allocator(), local_ctx.GetScope(), std::move(stmts)); + stmt->SetParent(local_block_stmt); + local_block_stmt->SetRange(stmt->Range()); + local_ctx.GetScope()->BindNode(local_block_stmt); + return local_block_stmt; +} + +ir::Expression *SetBoxFlagOrGenAsExpression(checker::ETSChecker *checker, checker::Type *constituent_type, + ir::Expression *other_node) +{ + if (constituent_type->AsETSObjectType()->HasObjectFlag(checker::ETSObjectFlags::UNBOXABLE_TYPE) && + !other_node->IsETSUnionType() && other_node->TsType()->HasTypeFlag(checker::TypeFlag::ETS_PRIMITIVE)) { + auto *unboxed_constituent_type = checker->ETSBuiltinTypeAsPrimitiveType(constituent_type); + if (unboxed_constituent_type != other_node->TsType()) { + auto *const prim_as_expression = + GenAsExpression(checker, unboxed_constituent_type, other_node, other_node->Parent()); + prim_as_expression->SetBoxingUnboxingFlags(checker->GetBoxingFlag(constituent_type)); + return prim_as_expression; + } + return other_node; + } + if (other_node->TsType()->HasTypeFlag(checker::TypeFlag::ETS_PRIMITIVE)) { + other_node->SetBoxingUnboxingFlags( + checker->GetBoxingFlag(checker::BoxingConverter::ETSTypeFromSource(checker, other_node->TsType()))); + } + return other_node; +} + +ir::Expression *ProcessOperandsInBinaryExpr(checker::ETSChecker *checker, ir::BinaryExpression *expr, + checker::Type *constituent_type) +{ + ASSERT(expr->OperatorType() == lexer::TokenType::PUNCTUATOR_EQUAL || + expr->OperatorType() == lexer::TokenType::PUNCTUATOR_NOT_EQUAL); + bool is_lhs_union; + ir::Expression *union_node = + (is_lhs_union = expr->Left()->TsType()->IsETSUnionType()) ? expr->Left() : expr->Right(); + auto *const as_expression = GenAsExpression(checker, constituent_type, union_node, expr); + if (is_lhs_union) { + expr->SetLeft(as_expression); + expr->SetRight(SetBoxFlagOrGenAsExpression(checker, constituent_type, expr->Right())); + } else { + expr->SetRight(as_expression); + expr->SetLeft(SetBoxFlagOrGenAsExpression(checker, constituent_type, expr->Left())); + } + expr->SetOperationType(checker->GlobalETSObjectType()); expr->SetTsType(checker->GlobalETSBooleanType()); return expr; } -bool UnionLowering::Perform(CompilerContext *ctx, parser::Program *program) +ir::Statement *FindStatementFromNode(ir::Expression *expr) +{ + ir::AstNode *node = expr; + while (!node->IsStatement()) { + node = node->Parent(); + } + ASSERT(node->IsStatement()); + return node->AsStatement(); +} + +void InsertInstanceofTreeBeforeStmt(ir::Statement *stmt, ir::VariableDeclaration *binary_var_decl, + ir::Statement *instanceof_tree) +{ + if (stmt->IsVariableDeclarator()) { + ASSERT(stmt->Parent()->IsVariableDeclaration()); + stmt = stmt->Parent()->AsVariableDeclaration(); + } + ASSERT(stmt->Parent()->IsBlockStatement()); + auto *block = stmt->Parent()->AsBlockStatement(); + binary_var_decl->SetParent(block); + instanceof_tree->SetParent(block); + auto it_stmt = std::find(block->Statements().begin(), block->Statements().end(), stmt); + block->Statements().insert(it_stmt, {binary_var_decl, instanceof_tree}); +} + +ir::BlockStatement *ReplaceBinaryExprInStmt(checker::ETSChecker *checker, ir::Expression *union_node, + ir::BlockStatement *block, ir::BinaryExpression *expr) +{ + auto *stmt = FindStatementFromNode(expr); + ASSERT(stmt->IsVariableDeclarator() || block == stmt->Parent()); // statement with union + auto *const binary_var_decl = GenVariableDeclForBinaryExpr(checker, NearestScope(stmt), expr); + auto *const var_decl_id = binary_var_decl->Declarators().front()->Id(); // only one declarator was generated + ir::IfStatement *instanceof_tree = nullptr; + for (auto *u_type : union_node->TsType()->AsETSUnionType()->ConstituentTypes()) { + auto *const test = GenInstanceofExpr(checker, union_node, u_type); + auto *cloned_binary = expr->Clone(checker->Allocator(), expr->Parent())->AsBinaryExpression(); + cloned_binary->Check(checker); + auto *const consequent = GenBlockStmtForAssignmentBinary( + checker, var_decl_id->AsIdentifier(), ProcessOperandsInBinaryExpr(checker, cloned_binary, u_type)); + instanceof_tree = checker->Allocator()->New(test, consequent, instanceof_tree); + test->SetParent(instanceof_tree); + consequent->SetParent(instanceof_tree); + if (instanceof_tree->Alternate() != nullptr) { + instanceof_tree->Alternate()->SetParent(instanceof_tree); + } + } + ASSERT(instanceof_tree != nullptr); + // Replacing a binary expression with an identifier + // that was set in one of the branches of the `instanceof_tree` tree + stmt->TransformChildrenRecursively([var_decl_id](ir::AstNode *ast) -> ir::AstNode * { + if (ast->IsBinaryExpression() && ast->AsBinaryExpression()->OperationType() != nullptr && + ast->AsBinaryExpression()->OperationType()->IsETSUnionType()) { + return var_decl_id; + } + + return ast; + }); + InsertInstanceofTreeBeforeStmt(stmt, binary_var_decl, instanceof_tree); + return block; +} + +ir::BlockStatement *HandleBlockWithBinaryAndUnion(checker::ETSChecker *checker, ir::BlockStatement *block, + ir::BinaryExpression *bin_expr) +{ + if (bin_expr->OperatorType() != lexer::TokenType::PUNCTUATOR_EQUAL && + bin_expr->OperatorType() != lexer::TokenType::PUNCTUATOR_NOT_EQUAL) { + checker->ThrowTypeError("Bad operand type, unions are not allowed in binary expressions except equality.", + bin_expr->Start()); + } + ir::Expression *union_node = bin_expr->Left()->TsType()->IsETSUnionType() ? bin_expr->Left() : bin_expr->Right(); + return ReplaceBinaryExprInStmt(checker, union_node, block, bin_expr); +} + +ir::BlockStatement *HandleBlockWithBinaryAndUnions(checker::ETSChecker *checker, ir::BlockStatement *block, + const ir::NodePredicate &handle_binary) +{ + ir::BlockStatement *modified_ast_block = block; + while (modified_ast_block->IsAnyChild(handle_binary)) { + modified_ast_block = HandleBlockWithBinaryAndUnion( + checker, modified_ast_block, modified_ast_block->FindChild(handle_binary)->AsBinaryExpression()); + } + return modified_ast_block; +} + +bool UnionLowering::Perform(public_lib::Context *ctx, parser::Program *program) { for (auto &[_, ext_programs] : program->ExternalSources()) { (void)_; @@ -164,18 +378,28 @@ bool UnionLowering::Perform(CompilerContext *ctx, parser::Program *program) } } - checker::ETSChecker *checker = ctx->Checker()->AsETSChecker(); + checker::ETSChecker *checker = ctx->checker->AsETSChecker(); - program->Ast()->TransformChildrenRecursively([checker, ctx](ir::AstNode *ast) -> ir::AstNode * { + program->Ast()->TransformChildrenRecursively([checker](ir::AstNode *ast) -> ir::AstNode * { if (ast->IsMemberExpression() && ast->AsMemberExpression()->Object()->TsType() != nullptr && ast->AsMemberExpression()->Object()->TsType()->IsETSUnionType()) { - HandleUnionPropertyAccess(checker, ctx->VarBinder(), ast->AsMemberExpression()); + HandleUnionPropertyAccess(checker, checker->VarBinder(), ast->AsMemberExpression()); return ast; } - if (ast->IsBinaryExpression() && ast->AsBinaryExpression()->OperationType() != nullptr && - ast->AsBinaryExpression()->OperationType()->IsETSUnionType()) { - return HandleBinaryExpressionWithUnion(checker, ast->AsBinaryExpression()); + if (ast->IsTSAsExpression() && ast->AsTSAsExpression()->Expr()->TsType() != nullptr && + ast->AsTSAsExpression()->Expr()->TsType()->IsETSUnionType() && + ast->AsTSAsExpression()->TsType() != nullptr && + ast->AsTSAsExpression()->TsType()->HasTypeFlag(checker::TypeFlag::ETS_PRIMITIVE)) { + return HandleUnionCastToPrimitive(checker, ast->AsTSAsExpression()); + } + + auto handle_binary = [](const ir::AstNode *ast_node) { + return ast_node->IsBinaryExpression() && ast_node->AsBinaryExpression()->OperationType() != nullptr && + ast_node->AsBinaryExpression()->OperationType()->IsETSUnionType(); + }; + if (ast->IsBlockStatement() && ast->IsAnyChild(handle_binary)) { + return HandleBlockWithBinaryAndUnions(checker, ast->AsBlockStatement(), handle_binary); } return ast; @@ -184,14 +408,14 @@ bool UnionLowering::Perform(CompilerContext *ctx, parser::Program *program) return true; } -bool UnionLowering::Postcondition(CompilerContext *ctx, const parser::Program *program) +bool UnionLowering::Postcondition(public_lib::Context *ctx, const parser::Program *program) { bool current = !program->Ast()->IsAnyChild([](const ir::AstNode *ast) { return ast->IsMemberExpression() && ast->AsMemberExpression()->Object()->TsType() != nullptr && ast->AsMemberExpression()->Object()->TsType()->IsETSUnionType() && ast->AsMemberExpression()->PropVar() == nullptr; }); - if (!current || ctx->Options()->compilation_mode != CompilationMode::GEN_STD_LIB) { + if (!current || ctx->compiler_context->Options()->compilation_mode != CompilationMode::GEN_STD_LIB) { return current; } diff --git a/ets2panda/compiler/lowering/ets/unionLowering.h b/ets2panda/compiler/lowering/ets/unionLowering.h index c8a4b49a905835aa4776dd09d9d427178bf695a2..efc0bf6bff7470fb1a3f6a99719f4a0c2c5a9b15 100644 --- a/ets2panda/compiler/lowering/ets/unionLowering.h +++ b/ets2panda/compiler/lowering/ets/unionLowering.h @@ -22,9 +22,9 @@ namespace panda::es2panda::compiler { class UnionLowering : public Phase { public: - std::string const &Name() override; - bool Perform(CompilerContext *ctx, parser::Program *program) override; - bool Postcondition(CompilerContext *ctx, const parser::Program *program) override; + std::string_view Name() override; + bool Perform(public_lib::Context *ctx, parser::Program *program) override; + bool Postcondition(public_lib::Context *ctx, const parser::Program *program) override; }; } // namespace panda::es2panda::compiler diff --git a/ets2panda/compiler/lowering/phase.cpp b/ets2panda/compiler/lowering/phase.cpp index f3b2ff83a6ee0aba42f56ab2082eb0483dc834ac..19035aec00f28b0aa6daf67d5c65dfa20992a553 100644 --- a/ets2panda/compiler/lowering/phase.cpp +++ b/ets2panda/compiler/lowering/phase.cpp @@ -19,9 +19,11 @@ #include "compiler/core/compilerContext.h" #include "lexer/token/sourceLocation.h" #include "compiler/lowering/checkerPhase.h" +#include "compiler/lowering/plugin_phase.h" #include "compiler/lowering/ets/generateDeclarations.h" #include "compiler/lowering/ets/opAssignment.h" #include "compiler/lowering/ets/unionLowering.h" +#include "public/es2panda_lib.h" namespace panda::es2panda::compiler { @@ -37,25 +39,28 @@ std::vector GetTrivialPhaseList() static GenerateTsDeclarationsPhase GENERATE_TS_DECLARATIONS_PHASE; static OpAssignmentLowering OP_ASSIGNMENT_LOWERING; static UnionLowering UNION_LOWERING; +static PluginPhase PLUGINS_AFTER_PARSE {"plugins-after-parse", ES2PANDA_STATE_PARSED, &util::Plugin::AfterParse}; +static PluginPhase PLUGINS_AFTER_CHECK {"plugins-after-check", ES2PANDA_STATE_CHECKED, &util::Plugin::AfterCheck}; +static PluginPhase PLUGINS_AFTER_LOWERINGS {"plugins-after-lowering", ES2PANDA_STATE_LOWERED, + &util::Plugin::AfterLowerings}; std::vector GetETSPhaseList() { return std::vector { - &CHECKER_PHASE, - &GENERATE_TS_DECLARATIONS_PHASE, - &OP_ASSIGNMENT_LOWERING, - &UNION_LOWERING, + &PLUGINS_AFTER_PARSE, &CHECKER_PHASE, &PLUGINS_AFTER_CHECK, &GENERATE_TS_DECLARATIONS_PHASE, + &OP_ASSIGNMENT_LOWERING, &UNION_LOWERING, &PLUGINS_AFTER_LOWERINGS, }; } -bool Phase::Apply(CompilerContext *ctx, parser::Program *program) +bool Phase::Apply(public_lib::Context *ctx, parser::Program *program) { - const auto *options = ctx->Options(); - if (options->skip_phases.count(Name()) > 0) { + const auto *options = ctx->compiler_context->Options(); + const auto name = std::string {Name()}; + if (options->skip_phases.count(name) > 0) { return true; } - if (options->dump_before_phases.count(Name()) > 0) { + if (options->dump_before_phases.count(name) > 0) { std::cout << "Before phase " << Name() << ":" << std::endl; std::cout << program->Dump() << std::endl; } @@ -66,8 +71,8 @@ bool Phase::Apply(CompilerContext *ctx, parser::Program *program) // NOTE(tatiana): Add some error processing } if (!Precondition(ctx, program)) { - ctx->Checker()->ThrowTypeError({"Precondition check failed for ", util::StringView {Name()}}, - lexer::SourcePosition {}); + ctx->checker->ThrowTypeError({"Precondition check failed for ", util::StringView {Name()}}, + lexer::SourcePosition {}); } #endif @@ -75,7 +80,7 @@ bool Phase::Apply(CompilerContext *ctx, parser::Program *program) return false; } - if (options->dump_after_phases.count(Name()) > 0) { + if (options->dump_after_phases.count(name) > 0) { std::cout << "After phase " << Name() << ":" << std::endl; std::cout << program->Dump() << std::endl; } @@ -86,8 +91,8 @@ bool Phase::Apply(CompilerContext *ctx, parser::Program *program) // NOTE(tatiana): Add some error processing } if (!Postcondition(ctx, program)) { - ctx->Checker()->ThrowTypeError({"Postcondition check failed for ", util::StringView {Name()}}, - lexer::SourcePosition {}); + ctx->checker->ThrowTypeError({"Postcondition check failed for ", util::StringView {Name()}}, + lexer::SourcePosition {}); } #endif diff --git a/ets2panda/compiler/lowering/phase.h b/ets2panda/compiler/lowering/phase.h index 490c2fac13b5ac2ba47bf964e7ddff2a3fdb0259..d64ed04e4c321859203df0a6af00a26b81aa80f5 100644 --- a/ets2panda/compiler/lowering/phase.h +++ b/ets2panda/compiler/lowering/phase.h @@ -17,22 +17,25 @@ #define ES2PANDA_COMPILER_LOWERING_PHASE_H #include "parser/program/program.h" +#include "public/public.h" namespace panda::es2panda::compiler { class Phase { public: /* If Apply returns false, processing is stopped. */ - bool Apply(CompilerContext *ctx, parser::Program *program); + bool Apply(public_lib::Context *ctx, parser::Program *program); - virtual std::string const &Name() = 0; + virtual std::string_view Name() = 0; - virtual bool Precondition([[maybe_unused]] CompilerContext *ctx, [[maybe_unused]] const parser::Program *program) + virtual bool Precondition([[maybe_unused]] public_lib::Context *ctx, + [[maybe_unused]] const parser::Program *program) { return true; } - virtual bool Perform(CompilerContext *ctx, parser::Program *program) = 0; - virtual bool Postcondition([[maybe_unused]] CompilerContext *ctx, [[maybe_unused]] const parser::Program *program) + virtual bool Perform(public_lib::Context *ctx, parser::Program *program) = 0; + virtual bool Postcondition([[maybe_unused]] public_lib::Context *ctx, + [[maybe_unused]] const parser::Program *program) { return true; } diff --git a/ets2panda/compiler/lowering/plugin_phase.cpp b/ets2panda/compiler/lowering/plugin_phase.cpp new file mode 100644 index 0000000000000000000000000000000000000000..35fa31a61bdfb1b9b6ffc013d66e9349fa200e58 --- /dev/null +++ b/ets2panda/compiler/lowering/plugin_phase.cpp @@ -0,0 +1,38 @@ +/** + * 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 "plugin_phase.h" + +namespace panda::es2panda::compiler { + +bool PluginPhase::Perform(public_lib::Context *ctx, [[maybe_unused]] parser::Program *program) +{ + ctx->state = context_state_; + + if (ctx->plugins == nullptr) { + return true; + } + + for (auto &plugin : *(ctx->plugins)) { + (plugin.*method_call_)(reinterpret_cast(ctx)); + if (ctx->state == ES2PANDA_STATE_ERROR) { + ctx->checker->ThrowTypeError(ctx->error_message, ctx->error_pos); + } + } + + return true; +} + +} // namespace panda::es2panda::compiler diff --git a/ets2panda/compiler/lowering/plugin_phase.h b/ets2panda/compiler/lowering/plugin_phase.h new file mode 100644 index 0000000000000000000000000000000000000000..4cff33ec06cc614b88fc4b320843c51bb15c8145 --- /dev/null +++ b/ets2panda/compiler/lowering/plugin_phase.h @@ -0,0 +1,47 @@ +/** + * 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. + */ + +#ifndef ES2PANDA_COMPILER_PLUGIN_PHASE_H +#define ES2PANDA_COMPILER_PLUGIN_PHASE_H + +#include "compiler/lowering/phase.h" +#include "util/plugin.h" + +namespace panda::es2panda::compiler { + +class PluginPhase : public Phase { +public: + constexpr PluginPhase(char const *name, es2panda_ContextState context_state, + void (util::Plugin::*method_call)(es2panda_Context *) const) noexcept + : name_(name), context_state_(context_state), method_call_(method_call) + { + } + + std::string_view Name() override + { + return name_; + } + + bool Perform(public_lib::Context *ctx, parser::Program *program) override; + +private: + char const *name_; + es2panda_ContextState context_state_; + void (util::Plugin::*method_call_)(es2panda_Context *) const; +}; + +} // namespace panda::es2panda::compiler + +#endif diff --git a/ets2panda/compiler/lowering/util.cpp b/ets2panda/compiler/lowering/util.cpp index 247f182093c3aadccab01eb842fd1e022f4e33b9..faa56e75c08436c32e99670ba396d48b3ce873e8 100644 --- a/ets2panda/compiler/lowering/util.cpp +++ b/ets2panda/compiler/lowering/util.cpp @@ -23,6 +23,10 @@ namespace panda::es2panda::compiler { varbinder::Scope *NearestScope(const ir::AstNode *ast) { + if (ast == nullptr) { + return nullptr; + } + while (!ast->IsScopeBearer()) { ast = ast->Parent(); ASSERT(ast != nullptr); @@ -31,17 +35,18 @@ varbinder::Scope *NearestScope(const ir::AstNode *ast) return ast->Scope(); } -static size_t GENSYM_COUNTER = 0; +ir::Identifier *Gensym(ArenaAllocator *const allocator) +{ + util::UString const s = GenName(allocator); + return allocator->New(s.View(), allocator); +} -ir::Identifier *Gensym(ArenaAllocator *allocator) +util::UString GenName(ArenaAllocator *const allocator) { - std::stringstream ss; - ss << "gensym$" << (GENSYM_COUNTER++); - const ArenaString s {allocator->Adapter()}; - const auto str = ss.str(); - auto *arena_pointer = allocator->Alloc(str.size() + 1); - std::memmove(arena_pointer, reinterpret_cast(str.c_str()), str.size() + 1); - return allocator->New(util::StringView(reinterpret_cast(arena_pointer)), allocator); + static std::string const GENSYM_CORE = "gensym$_"; + static std::size_t gensym_counter = 0U; + + return util::UString {GENSYM_CORE + std::to_string(++gensym_counter), allocator}; } } // namespace panda::es2panda::compiler diff --git a/ets2panda/compiler/lowering/util.h b/ets2panda/compiler/lowering/util.h index ba3d290a136019a4dff8fdbb411b61a20e9401e4..d8344157b1c0e8cf4e255b63c1ebc06478103f12 100644 --- a/ets2panda/compiler/lowering/util.h +++ b/ets2panda/compiler/lowering/util.h @@ -16,14 +16,13 @@ #ifndef ES2PANDA_COMPILER_LOWERING_UTIL_H #define ES2PANDA_COMPILER_LOWERING_UTIL_H -#include "varbinder/scope.h" -#include "checker/types/ets/etsObjectType.h" #include "ir/astNode.h" namespace panda::es2panda::compiler { varbinder::Scope *NearestScope(const ir::AstNode *ast); ir::Identifier *Gensym(ArenaAllocator *allocator); +util::UString GenName(ArenaAllocator *allocator); } // namespace panda::es2panda::compiler diff --git a/ets2panda/es2panda.cpp b/ets2panda/es2panda.cpp index 458f00dd7b422b8a611d8d79e4f9c0ca49bf797c..4b7051f93dc6bd8f239cf935b5fa949e163d9989 100644 --- a/ets2panda/es2panda.cpp +++ b/ets2panda/es2panda.cpp @@ -16,6 +16,7 @@ #include "es2panda.h" #include "compiler/core/compilerImpl.h" +#include "util/options.h" #include #include @@ -56,10 +57,12 @@ SourceFile::SourceFile(std::string_view fn, std::string_view s, std::string_view { } -Compiler::Compiler(ScriptExtension ext) : Compiler(ext, DEFAULT_THREAD_COUNT) {} +Compiler::Compiler(ScriptExtension ext) : Compiler(ext, DEFAULT_THREAD_COUNT, {}) {} -Compiler::Compiler(ScriptExtension ext, size_t thread_count) - : compiler_(new compiler::CompilerImpl(thread_count)), ext_(ext) +Compiler::Compiler(ScriptExtension ext, size_t thread_count) : Compiler(ext, thread_count, {}) {} + +Compiler::Compiler(ScriptExtension ext, size_t thread_count, std::vector &&plugins) + : plugins_(std::move(plugins)), compiler_(new compiler::CompilerImpl(thread_count, &plugins_)), ext_(ext) { } diff --git a/ets2panda/es2panda.h b/ets2panda/es2panda.h index 40774251e567cf0ba3ed97295b1960267869cddd..78ccfc73c5f7155ba8b911355e4e9e34d9f4a2ec 100644 --- a/ets2panda/es2panda.h +++ b/ets2panda/es2panda.h @@ -18,6 +18,7 @@ #include "macros.h" #include "util/arktsconfig.h" +#include "util/plugin.h" #include "util/ustring.h" #include @@ -93,12 +94,14 @@ struct CompilerOptions { bool is_direct_eval {}; bool is_function_eval {}; bool dump_ast {}; + bool op_dump_ast_only_silent {}; bool dump_checked_ast {}; bool dump_asm {}; bool dump_debug_info {}; bool parse_only {}; std::string std_lib {}; std::string ts_decl_out {}; + std::vector plugins {}; std::unordered_set skip_phases {}; std::unordered_set dump_before_phases {}; std::unordered_set dump_after_phases {}; @@ -191,6 +194,7 @@ class Compiler { public: explicit Compiler(ScriptExtension ext); explicit Compiler(ScriptExtension ext, size_t thread_count); + explicit Compiler(ScriptExtension ext, size_t thread_count, std::vector &&plugins); ~Compiler(); NO_COPY_SEMANTIC(Compiler); NO_MOVE_SEMANTIC(Compiler); @@ -211,7 +215,13 @@ public: return error_; } + std::vector const &Plugins() + { + return plugins_; + } + private: + std::vector const plugins_; compiler::CompilerImpl *compiler_; Error error_; ScriptExtension ext_; diff --git a/ets2panda/ir/astNode.cpp b/ets2panda/ir/astNode.cpp index bceb87943b488f79aa83938d004a22ee54d1d161..4687db69022050d5086d038a32b3b74175fdb737 100644 --- a/ets2panda/ir/astNode.cpp +++ b/ets2panda/ir/astNode.cpp @@ -89,11 +89,25 @@ bool AstNode::IsAnyChild(const NodePredicate &cb) const return found; } -void AnnotatedAstNode::CloneTypeAnnotation(ArenaAllocator *const allocator) +void FindChildHelper(AstNode *&found, const NodePredicate &cb, AstNode *ast) { - if (auto *annotation = const_cast(TypeAnnotation()); annotation != nullptr) { - SetTsTypeAnnotation(annotation->Clone(allocator, this)->AsTypeNode()); + if (found != nullptr) { + return; + } + + if (cb(ast)) { + found = ast; + return; } + + ast->Iterate([&found, cb](AstNode *child) { FindChildHelper(found, cb, child); }); +} + +AstNode *AstNode::FindChild(const NodePredicate &cb) const +{ + AstNode *found = nullptr; + Iterate([&found, cb](AstNode *child) { FindChildHelper(found, cb, child); }); + return found; } std::string AstNode::DumpJSON() const diff --git a/ets2panda/ir/astNode.h b/ets2panda/ir/astNode.h index 950d346f6f7cd740eed5cb85242a15b16da29324..52ae35ba718fd0b4f9d12517448c610915e4a431 100644 --- a/ets2panda/ir/astNode.h +++ b/ets2panda/ir/astNode.h @@ -263,6 +263,12 @@ public: variable_ = variable; } + // When no decorators are allowed, we cannot return a reference to an empty vector. + virtual const ArenaVector *DecoratorsPtr() const + { + return nullptr; + } + virtual void AddDecorators([[maybe_unused]] ArenaVector &&decorators) { UNREACHABLE(); @@ -448,11 +454,19 @@ public: [[nodiscard]] ir::BlockStatement *GetTopStatement(); [[nodiscard]] const ir::BlockStatement *GetTopStatement() const; + // NOLINTNEXTLINE(google-default-arguments) + [[nodiscard]] virtual AstNode *Clone([[maybe_unused]] ArenaAllocator *const allocator, + [[maybe_unused]] AstNode *const parent = nullptr) + { + UNREACHABLE(); + } + virtual void TransformChildren(const NodeTransformer &cb) = 0; virtual void Iterate(const NodeTraverser &cb) const = 0; void TransformChildrenRecursively(const NodeTransformer &cb); void IterateRecursively(const NodeTraverser &cb) const; bool IsAnyChild(const NodePredicate &cb) const; + AstNode *FindChild(const NodePredicate &cb) const; std::string DumpJSON() const; @@ -576,8 +590,6 @@ public: NO_COPY_OPERATOR(AnnotatedAstNode); NO_MOVE_SEMANTIC(AnnotatedAstNode); - void CloneTypeAnnotation(ArenaAllocator *allocator); - protected: explicit AnnotatedAstNode(AstNodeType const type, TypeNode *const type_annotation) : Annotated(type, type_annotation) diff --git a/ets2panda/ir/astNodeMapping.h b/ets2panda/ir/astNodeMapping.h index 9b8099c6002ea06f40396c3c6ca3321c435bf49d..e05e9a9c2fe3cbcb6303983fc3fbe7aca42cdbb7 100644 --- a/ets2panda/ir/astNodeMapping.h +++ b/ets2panda/ir/astNodeMapping.h @@ -160,7 +160,8 @@ _(VARIABLE_DECLARATOR, VariableDeclarator) \ _(WHILE_STATEMENT, WhileStatement) \ _(YIELD_EXPRESSION, YieldExpression) \ - _(OPAQUE_TYPE_NODE, OpaqueTypeNode) + _(OPAQUE_TYPE_NODE, OpaqueTypeNode) \ + _(BLOCK_EXPRESSION, BlockExpression) #define AST_NODE_REINTERPRET_MAPPING(_) \ _(ARRAY_EXPRESSION, ARRAY_PATTERN, ArrayExpression, ArrayPattern) \ diff --git a/ets2panda/ir/base/classDefinition.cpp b/ets2panda/ir/base/classDefinition.cpp index 12e57a0dbcb10ad54bb56bc9a9365d5a8a68fb37..31520c1ffd1097eb9e0e568d5258279d52443180 100644 --- a/ets2panda/ir/base/classDefinition.cpp +++ b/ets2panda/ir/base/classDefinition.cpp @@ -1,5 +1,5 @@ /** - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021 - 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 diff --git a/ets2panda/ir/base/classDefinition.h b/ets2panda/ir/base/classDefinition.h index 7341aab83e5a2787b52579e2eb10a6256299f4bf..9b4fca1959ddd5cae2614724403048ccc1a5cdea 100644 --- a/ets2panda/ir/base/classDefinition.h +++ b/ets2panda/ir/base/classDefinition.h @@ -1,5 +1,5 @@ /** - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021 - 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 @@ -50,6 +50,12 @@ DEFINE_BITOPS(ClassDefinitionModifiers) class ClassDefinition : public TypedAstNode { public: + ClassDefinition() = delete; + ~ClassDefinition() override = default; + + NO_COPY_SEMANTIC(ClassDefinition); + NO_MOVE_SEMANTIC(ClassDefinition); + explicit ClassDefinition(varbinder::LocalScope *scope, const util::StringView &private_id, Identifier *ident, TSTypeParameterDeclaration *type_params, TSTypeParameterInstantiation *super_type_params, ArenaVector &&implements, MethodDefinition *ctor, @@ -104,82 +110,87 @@ public: return scope_; } - const Identifier *Ident() const + [[nodiscard]] const Identifier *Ident() const noexcept { return ident_; } - Identifier *Ident() + [[nodiscard]] Identifier *Ident() noexcept { return ident_; } - void SetIdent(ir::Identifier *ident) + void SetIdent(ir::Identifier *ident) noexcept { ident_ = ident; } - const util::StringView &PrivateId() const + [[nodiscard]] const util::StringView &PrivateId() const noexcept { return private_id_; } - const util::StringView &InternalName() const + [[nodiscard]] const util::StringView &InternalName() const noexcept { return private_id_; } - void SetInternalName(util::StringView internal_name) + void SetInternalName(util::StringView internal_name) noexcept { private_id_ = internal_name; } - Expression *Super() + [[nodiscard]] Expression *Super() noexcept { return super_class_; } - const Expression *Super() const + [[nodiscard]] const Expression *Super() const noexcept { return super_class_; } - bool IsGlobal() const + void SetSuper(Expression *super_class) + { + super_class_ = super_class; + } + + [[nodiscard]] bool IsGlobal() const noexcept { return (modifiers_ & ClassDefinitionModifiers::GLOBAL) != 0; } - bool IsExtern() const + [[nodiscard]] bool IsExtern() const noexcept { return (modifiers_ & ClassDefinitionModifiers::EXTERN) != 0; } - bool IsInner() const + [[nodiscard]] bool IsInner() const noexcept { return (modifiers_ & ClassDefinitionModifiers::INNER) != 0; } - bool IsGlobalInitialized() const + [[nodiscard]] bool IsGlobalInitialized() const noexcept { return (modifiers_ & ClassDefinitionModifiers::GLOBAL_INITIALIZED) != 0; } - es2panda::Language Language() const + [[nodiscard]] es2panda::Language Language() const noexcept { return lang_; } - void SetGlobalInitialized() + void SetGlobalInitialized() noexcept { modifiers_ |= ClassDefinitionModifiers::GLOBAL_INITIALIZED; } - void SetInnerModifier() + void SetInnerModifier() noexcept { modifiers_ |= ClassDefinitionModifiers::INNER; } - ClassDefinitionModifiers Modifiers() const + [[nodiscard]] ClassDefinitionModifiers Modifiers() const noexcept { return modifiers_; } @@ -193,41 +204,51 @@ public: body_.insert(body_.end(), body.begin(), body.end()); } - ArenaVector &Body() + [[nodiscard]] ArenaVector &Body() noexcept { return body_; } - const ArenaVector &Body() const + [[nodiscard]] const ArenaVector &Body() const noexcept { return body_; } - MethodDefinition *Ctor() + [[nodiscard]] MethodDefinition *Ctor() noexcept { return ctor_; } - ArenaVector &Implements() + void SetCtor(MethodDefinition *ctor) + { + ctor_ = ctor; + } + + [[nodiscard]] ArenaVector &Implements() noexcept { return implements_; } - const ArenaVector &Implements() const + [[nodiscard]] const ArenaVector &Implements() const noexcept { return implements_; } - const ir::TSTypeParameterDeclaration *TypeParams() const + [[nodiscard]] const ir::TSTypeParameterDeclaration *TypeParams() const noexcept { return type_params_; } - ir::TSTypeParameterDeclaration *TypeParams() + [[nodiscard]] ir::TSTypeParameterDeclaration *TypeParams() noexcept { return type_params_; } + void SetTypeParams(ir::TSTypeParameterDeclaration *type_params) + { + type_params_ = type_params; + } + const FunctionExpression *Ctor() const; bool HasPrivateMethod() const; bool HasComputedInstanceField() const; @@ -235,7 +256,9 @@ public: void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; + void Dump(ir::AstDumper *dumper) const override; + void Compile(compiler::PandaGen *pg) const override; void Compile(compiler::ETSGen *etsg) const override; checker::Type *Check(checker::TSChecker *checker) override; diff --git a/ets2panda/ir/base/classElement.cpp b/ets2panda/ir/base/classElement.cpp index 192aecf3038e85c9818b50e6e3161d8c24b5efe7..62b0ebb1003ff02519fe98bdc74c1bd7df759be1 100644 --- a/ets2panda/ir/base/classElement.cpp +++ b/ets2panda/ir/base/classElement.cpp @@ -20,17 +20,17 @@ namespace panda::es2panda::ir { -Identifier *ClassElement::Id() +Identifier *ClassElement::Id() noexcept { - return key_->AsIdentifier(); + return key_->IsIdentifier() ? key_->AsIdentifier() : nullptr; } -const Identifier *ClassElement::Id() const +const Identifier *ClassElement::Id() const noexcept { - return key_->AsIdentifier(); + return key_->IsIdentifier() ? key_->AsIdentifier() : nullptr; } -bool ClassElement::IsPrivateElement() const +bool ClassElement::IsPrivateElement() const noexcept { if (IsClassStaticBlock()) { return false; diff --git a/ets2panda/ir/base/classElement.h b/ets2panda/ir/base/classElement.h index ea99fb156653d56d229f50c4ff6972157bae7382..7589b3d40741a81c5c0ccb5aa695f4b02c9ed211 100644 --- a/ets2panda/ir/base/classElement.h +++ b/ets2panda/ir/base/classElement.h @@ -23,8 +23,14 @@ class Expression; class ClassElement : public TypedStatement { public: - explicit ClassElement(AstNodeType element_type, Expression *key, Expression *value, ModifierFlags modifiers, - ArenaAllocator *allocator, bool is_computed) + ClassElement() = delete; + ~ClassElement() override = default; + + NO_COPY_SEMANTIC(ClassElement); + NO_MOVE_SEMANTIC(ClassElement); + + explicit ClassElement(AstNodeType const element_type, Expression *const key, Expression *const value, + ModifierFlags const modifiers, ArenaAllocator *const allocator, bool const is_computed) : TypedStatement(element_type, modifiers), key_(key), value_(value), @@ -33,37 +39,43 @@ public: { } - Identifier *Id(); - const Identifier *Id() const; + [[nodiscard]] Identifier *Id() noexcept; + + [[nodiscard]] const Identifier *Id() const noexcept; - Expression *Key() + [[nodiscard]] Expression *Key() noexcept { return key_; } - const Expression *Key() const + [[nodiscard]] const Expression *Key() const noexcept { return key_; } - Expression *Value() + [[nodiscard]] Expression *Value() noexcept { return value_; } - const Expression *Value() const + [[nodiscard]] const Expression *Value() const noexcept { return value_; } - bool IsPrivateElement() const; + [[nodiscard]] bool IsPrivateElement() const noexcept; - const ArenaVector &Decorators() const + [[nodiscard]] const ArenaVector &Decorators() const noexcept { return decorators_; } - bool IsComputed() const + const ArenaVector *DecoratorsPtr() const override + { + return &Decorators(); + } + + [[nodiscard]] bool IsComputed() const noexcept { return is_computed_; } @@ -73,7 +85,19 @@ public: decorators_ = std::move(decorators); } - virtual PrivateFieldKind ToPrivateFieldKind(bool is_static) const = 0; + void AddDecorator(ir::Decorator *const decorator) + { + if (decorator != nullptr) { + decorators_.emplace_back(decorator); + } + } + + bool CanHaveDecorator([[maybe_unused]] bool in_ts) const override + { + return true; + } + + [[nodiscard]] virtual PrivateFieldKind ToPrivateFieldKind(bool is_static) const = 0; protected: // NOLINTBEGIN(misc-non-private-member-variables-in-classes) diff --git a/ets2panda/ir/base/classProperty.cpp b/ets2panda/ir/base/classProperty.cpp index 24bfd844c1b8dad6d7ee340955a11133a97a32bb..081a992abfc21948efc67dd5bda7052c2deb1e4d 100644 --- a/ets2panda/ir/base/classProperty.cpp +++ b/ets2panda/ir/base/classProperty.cpp @@ -1,5 +1,5 @@ /** - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021 - 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 @@ -26,9 +26,6 @@ #include "ir/expression.h" #include "ir/expressions/identifier.h" -#include -#include - namespace panda::es2panda::ir { void ClassProperty::TransformChildren(const NodeTransformer &cb) { @@ -100,4 +97,31 @@ checker::Type *ClassProperty::Check(checker::ETSChecker *checker) { return checker->GetAnalyzer()->Check(this); } + +// NOLINTNEXTLINE(google-default-arguments) +ClassProperty *ClassProperty::Clone(ArenaAllocator *const allocator, AstNode *const parent) +{ + auto *const key = key_->Clone(allocator)->AsExpression(); + auto *const value = value_->Clone(allocator)->AsExpression(); + auto *const type_annotation = type_annotation_->Clone(allocator, this); + + if (auto *const clone = allocator->New(key, value, type_annotation, flags_, allocator, is_computed_); + clone != nullptr) { + if (parent != nullptr) { + clone->SetParent(parent); + } + + key->SetParent(clone); + value->SetParent(clone); + type_annotation->SetParent(clone); + + for (auto *const decorator : decorators_) { + clone->AddDecorator(decorator->Clone(allocator, clone)); + } + + return clone; + } + + throw Error(ErrorType::GENERIC, "", CLONE_ALLOCATION_ERROR); +} } // namespace panda::es2panda::ir diff --git a/ets2panda/ir/base/classProperty.h b/ets2panda/ir/base/classProperty.h index 82738acdab8b41e04f7d507aeed1a87b0bf62344..fc9773fc0f74a130cd2e1ae1dc09b92f07268081 100644 --- a/ets2panda/ir/base/classProperty.h +++ b/ets2panda/ir/base/classProperty.h @@ -28,28 +28,37 @@ class TypeNode; class ClassProperty : public ClassElement { public: - explicit ClassProperty(Expression *key, Expression *value, TypeNode *type_annotation, ModifierFlags modifiers, - ArenaAllocator *allocator, bool is_computed) + ClassProperty() = delete; + ~ClassProperty() override = default; + + NO_COPY_SEMANTIC(ClassProperty); + NO_MOVE_SEMANTIC(ClassProperty); + + explicit ClassProperty(Expression *const key, Expression *const value, TypeNode *const type_annotation, + ModifierFlags const modifiers, ArenaAllocator *const allocator, bool const is_computed) : ClassElement(AstNodeType::CLASS_PROPERTY, key, value, modifiers, allocator, is_computed), type_annotation_(type_annotation) { } - // NOTE: csabahurton. friend relationship can be removed once there are getters for private fields - friend class checker::ETSAnalyzer; - TypeNode *TypeAnnotation() const + [[nodiscard]] TypeNode *TypeAnnotation() const noexcept { return type_annotation_; } - PrivateFieldKind ToPrivateFieldKind(bool is_static) const override + [[nodiscard]] PrivateFieldKind ToPrivateFieldKind(bool const is_static) const override { return is_static ? PrivateFieldKind::STATIC_FIELD : PrivateFieldKind::FIELD; } + // NOLINTNEXTLINE(google-default-arguments) + [[nodiscard]] ClassProperty *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; + void Dump(ir::AstDumper *dumper) const override; + void Compile(compiler::PandaGen *pg) const override; void Compile(compiler::ETSGen *etsg) const override; checker::Type *Check(checker::TSChecker *checker) override; diff --git a/ets2panda/ir/base/decorator.cpp b/ets2panda/ir/base/decorator.cpp index 3b9e5c419b8f49dbde292e01e9850584245f5ac7..beb884f79b09a942806568245b84a242d24ee780 100644 --- a/ets2panda/ir/base/decorator.cpp +++ b/ets2panda/ir/base/decorator.cpp @@ -60,9 +60,9 @@ checker::Type *Decorator::Check(checker::ETSChecker *checker) } // NOLINTNEXTLINE(google-default-arguments) -Statement *Decorator::Clone(ArenaAllocator *const allocator, AstNode *const parent) +Decorator *Decorator::Clone(ArenaAllocator *const allocator, AstNode *const parent) { - auto *const expr = expr_ != nullptr ? expr_->Clone(allocator) : nullptr; + auto *const expr = expr_ != nullptr ? expr_->Clone(allocator)->AsExpression() : nullptr; if (auto *const clone = allocator->New(expr); clone != nullptr) { if (expr != nullptr) { diff --git a/ets2panda/ir/base/decorator.h b/ets2panda/ir/base/decorator.h index aadfb87af2223e923ce9840dd9e4690d50bea5ef..e85858d4b34eb4a7533e340431a087bf6e8908a1 100644 --- a/ets2panda/ir/base/decorator.h +++ b/ets2panda/ir/base/decorator.h @@ -37,7 +37,7 @@ public: } // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] Statement *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + [[nodiscard]] Decorator *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; diff --git a/ets2panda/ir/base/metaProperty.cpp b/ets2panda/ir/base/metaProperty.cpp index f88b13cc03b88649618baabbb677af035f4dce63..ed43fa1e0c5019d3e1fdc6f123eb67d6f794de51 100644 --- a/ets2panda/ir/base/metaProperty.cpp +++ b/ets2panda/ir/base/metaProperty.cpp @@ -15,10 +15,9 @@ #include "metaProperty.h" -#include "es2panda.h" -#include "compiler/core/pandagen.h" #include "checker/TSchecker.h" -#include "ir/astDump.h" +#include "compiler/core/ETSGen.h" +#include "compiler/core/pandagen.h" namespace panda::es2panda::ir { void MetaProperty::TransformChildren([[maybe_unused]] const NodeTransformer &cb) {} @@ -45,32 +44,28 @@ void MetaProperty::Dump(ir::AstDumper *dumper) const dumper->Add({{"type", "MetaProperty"}, {"kind", kind}}); } -void MetaProperty::Compile([[maybe_unused]] compiler::PandaGen *pg) const +void MetaProperty::Compile(compiler::PandaGen *pg) const { - if (kind_ == ir::MetaProperty::MetaPropertyKind::NEW_TARGET) { - pg->GetNewTarget(this); - return; - } + pg->GetAstCompiler()->Compile(this); +} - if (kind_ == ir::MetaProperty::MetaPropertyKind::IMPORT_META) { - // NOTE - pg->Unimplemented(); - } +void MetaProperty::Compile(compiler::ETSGen *etsg) const +{ + etsg->GetAstCompiler()->Compile(this); } -checker::Type *MetaProperty::Check([[maybe_unused]] checker::TSChecker *checker) +checker::Type *MetaProperty::Check(checker::TSChecker *checker) { - // NOTE: aszilagyi. - return checker->GlobalAnyType(); + return checker->GetAnalyzer()->Check(this); } -checker::Type *MetaProperty::Check([[maybe_unused]] checker::ETSChecker *checker) +checker::Type *MetaProperty::Check(checker::ETSChecker *checker) { - return nullptr; + return checker->GetAnalyzer()->Check(this); } // NOLINTNEXTLINE(google-default-arguments) -Expression *MetaProperty::Clone(ArenaAllocator *const allocator, AstNode *const parent) +MetaProperty *MetaProperty::Clone(ArenaAllocator *const allocator, AstNode *const parent) { if (auto *const clone = allocator->New(kind_); clone != nullptr) { if (parent != nullptr) { diff --git a/ets2panda/ir/base/metaProperty.h b/ets2panda/ir/base/metaProperty.h index 7a3d4e7f1736685ee21cd162a22f70506a014073..0ec7e846045e5b81b8200bd268980519223a1bf4 100644 --- a/ets2panda/ir/base/metaProperty.h +++ b/ets2panda/ir/base/metaProperty.h @@ -44,13 +44,14 @@ public: void TransformChildren(const NodeTransformer &cb) override; // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] Expression *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + [[nodiscard]] MetaProperty *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; void Iterate(const NodeTraverser &cb) const override; void Dump(ir::AstDumper *dumper) const override; - void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; - checker::Type *Check([[maybe_unused]] checker::TSChecker *checker) override; - checker::Type *Check([[maybe_unused]] checker::ETSChecker *checker) override; + void Compile(compiler::PandaGen *pg) const override; + void Compile(compiler::ETSGen *etsg) const override; + checker::Type *Check(checker::TSChecker *checker) override; + checker::Type *Check(checker::ETSChecker *checker) override; private: MetaPropertyKind kind_; diff --git a/ets2panda/ir/base/methodDefinition.cpp b/ets2panda/ir/base/methodDefinition.cpp index cff3cf3c6bd661e08997ecfc465c3c3b6208bd3c..a74af0796a389dc140a37f467529595aa4cfb475 100644 --- a/ets2panda/ir/base/methodDefinition.cpp +++ b/ets2panda/ir/base/methodDefinition.cpp @@ -16,34 +16,23 @@ #include "methodDefinition.h" #include "varbinder/scope.h" -#include "ir/astDump.h" -#include "ir/base/decorator.h" -#include "ir/base/classDefinition.h" -#include "ir/base/scriptFunction.h" -#include "ir/expression.h" -#include "ir/expressions/functionExpression.h" -#include "ir/expressions/identifier.h" -#include "ir/statements/blockStatement.h" -#include "ir/statements/returnStatement.h" -#include "ir/ts/tsTypeParameter.h" -#include "ir/typeNode.h" -#include "checker/ETSchecker.h" - -#include +#include "checker/TSchecker.h" +#include "compiler/core/ETSGen.h" +#include "compiler/core/pandagen.h" namespace panda::es2panda::ir { ScriptFunction *MethodDefinition::Function() { - return value_->AsFunctionExpression()->Function(); + return value_->IsFunctionExpression() ? value_->AsFunctionExpression()->Function() : nullptr; } const ScriptFunction *MethodDefinition::Function() const { - return value_->AsFunctionExpression()->Function(); + return value_->IsFunctionExpression() ? value_->AsFunctionExpression()->Function() : nullptr; } -PrivateFieldKind MethodDefinition::ToPrivateFieldKind(bool is_static) const +PrivateFieldKind MethodDefinition::ToPrivateFieldKind(bool const is_static) const { switch (kind_) { case MethodDefinitionKind::METHOD: { @@ -131,204 +120,57 @@ void MethodDefinition::Dump(ir::AstDumper *dumper) const {"decorators", decorators_}}); } -void MethodDefinition::Compile([[maybe_unused]] compiler::PandaGen *pg) const {} - -void MethodDefinition::Compile([[maybe_unused]] compiler::ETSGen *etsg) const {} - -checker::Type *MethodDefinition::Check([[maybe_unused]] checker::TSChecker *checker) +void MethodDefinition::Compile(compiler::PandaGen *pg) const { - return nullptr; + pg->GetAstCompiler()->Compile(this); } -checker::Type *MethodDefinition::Check(checker::ETSChecker *checker) +void MethodDefinition::Compile(compiler::ETSGen *etsg) const { - auto *script_func = Function(); - - if (script_func->IsProxy()) { - return nullptr; - } - - // NOTE: aszilagyi. make it correctly check for open function not have body - if (!script_func->HasBody() && - !(IsAbstract() || IsNative() || IsDeclare() || checker->HasStatus(checker::CheckerStatus::IN_INTERFACE))) { - checker->ThrowTypeError("Only abstract or native methods can't have body.", script_func->Start()); - } - - if (script_func->ReturnTypeAnnotation() == nullptr && (IsNative() || (IsDeclare() && !IsConstructor()))) { - checker->ThrowTypeError("Native and Declare methods should have explicit return type.", script_func->Start()); - } - - if (TsType() == nullptr) { - SetTsType(checker->BuildMethodSignature(this)); - } - - CheckMethodModifiers(checker); - - if (IsNative() && script_func->ReturnTypeAnnotation() == nullptr) { - checker->ThrowTypeError("'Native' method should have explicit return type", script_func->Start()); - } - - if (IsNative() && (script_func->IsGetter() || script_func->IsSetter())) { - checker->ThrowTypeError("'Native' modifier is invalid for Accessors", script_func->Start()); - } - - if (script_func->HasBody() && (IsNative() || IsAbstract() || IsDeclare())) { - checker->ThrowTypeError("Native, Abstract and Declare methods cannot have body.", script_func->Body()->Start()); - } - - if (script_func->IsAsyncFunc()) { - auto *ret_type = static_cast(script_func->Signature()->ReturnType()); - if (ret_type->AssemblerName() != checker->GlobalBuiltinPromiseType()->AssemblerName()) { - checker->ThrowTypeError("Return type of async function must be 'Promise'.", script_func->Start()); - } - } else if (script_func->HasBody() && !script_func->IsExternal()) { - checker::ScopeContext scope_ctx(checker, script_func->Scope()); - checker::SavedCheckerContext saved_context(checker, checker->Context().Status(), - checker->Context().ContainingClass()); - checker->Context().SetContainingSignature(checker->GetSignatureFromMethodDefinition(this)); - - if (IsStatic() && !IsConstructor() && - !checker->Context().ContainingClass()->HasObjectFlag(checker::ETSObjectFlags::GLOBAL)) { - checker->AddStatus(checker::CheckerStatus::IN_STATIC_CONTEXT); - } - - if (IsConstructor()) { - checker->AddStatus(checker::CheckerStatus::IN_CONSTRUCTOR); - } - - if (IsExtensionMethod()) { - CheckExtensionMethod(checker, script_func); - } - - script_func->Body()->Check(checker); - - // In case of inferred function's return type set it forcedly to all return statements; - if (script_func->Signature()->HasSignatureFlag(checker::SignatureFlags::INFERRED_RETURN_TYPE) && - script_func->ReturnTypeAnnotation() == nullptr && script_func->Body() != nullptr && - script_func->Body()->IsStatement()) { - script_func->Body()->AsStatement()->SetReturnType(checker, script_func->Signature()->ReturnType()); - } - - checker->Context().SetContainingSignature(nullptr); - } - - if (script_func->IsSetter() && (script_func->Signature()->ReturnType() != checker->GlobalBuiltinVoidType())) { - checker->ThrowTypeError("Setter must have void return type", script_func->Start()); - } - - if (script_func->IsGetter() && (script_func->Signature()->ReturnType() == checker->GlobalBuiltinVoidType())) { - checker->ThrowTypeError("Getter must return a value", script_func->Start()); - } - - checker->CheckOverride(TsType()->AsETSFunctionType()->FindSignature(Function())); - - for (auto *it : overloads_) { - it->Check(checker); - } - - if (script_func->IsRethrowing()) { - checker->CheckRethrowingFunction(script_func); - } - - return TsType(); + etsg->GetAstCompiler()->Compile(this); } -void MethodDefinition::CheckExtensionMethod(checker::ETSChecker *checker, ScriptFunction *extension_func) +checker::Type *MethodDefinition::Check(checker::TSChecker *checker) { - auto *const class_type = extension_func->Signature()->Params()[0]->TsType(); - if (!class_type->IsETSObjectType() || - (!class_type->AsETSObjectType()->HasObjectFlag(checker::ETSObjectFlags::CLASS) && - !class_type->AsETSObjectType()->HasObjectFlag(checker::ETSObjectFlags::INTERFACE))) { - checker->ThrowTypeError("Extension function can only defined for class and interface type.", Start()); - } - - checker->AddStatus(checker::CheckerStatus::IN_INSTANCE_EXTENSION_METHOD); - - checker::SignatureInfo *original_extension_sig_info = checker->Allocator()->New( - extension_func->Signature()->GetSignatureInfo(), checker->Allocator()); - original_extension_sig_info->min_arg_count -= 1; - original_extension_sig_info->params.erase(original_extension_sig_info->params.begin()); - checker::Signature *original_extension_sigature = checker->CreateSignature( - original_extension_sig_info, extension_func->Signature()->ReturnType(), extension_func); - - CheckExtensionIsShadowedByMethod(checker, class_type->AsETSObjectType(), extension_func, - original_extension_sigature); + return checker->GetAnalyzer()->Check(this); } -void MethodDefinition::CheckExtensionIsShadowedByMethod(checker::ETSChecker *checker, checker::ETSObjectType *obj_type, - ScriptFunction *extension_func, checker::Signature *sigature) +checker::Type *MethodDefinition::Check(checker::ETSChecker *checker) { - if (obj_type == nullptr) { - return; - } - - CheckExtensionIsShadowedInCurrentClassOrInterface(checker, obj_type, extension_func, sigature); - - for (auto *interface : obj_type->Interfaces()) { - CheckExtensionIsShadowedByMethod(checker, interface, extension_func, sigature); - } - - CheckExtensionIsShadowedByMethod(checker, obj_type->SuperType(), extension_func, sigature); + return checker->GetAnalyzer()->Check(this); } -void MethodDefinition::CheckExtensionIsShadowedInCurrentClassOrInterface(checker::ETSChecker *checker, - checker::ETSObjectType *obj_type, - ScriptFunction *extension_func, - checker::Signature *sigature) +// NOLINTNEXTLINE(google-default-arguments) +MethodDefinition *MethodDefinition::Clone(ArenaAllocator *const allocator, AstNode *const parent) { - const auto method_name = extension_func->Id()->Name(); - // Only check if there are class and interfaces' instance methods which would shadow instance extension method - auto *const variable = obj_type->GetOwnProperty(method_name); - if (variable == nullptr) { - return; - } + auto *const key = key_ != nullptr ? key_->Clone(allocator)->AsExpression() : nullptr; + auto *const value = value_ != nullptr ? value_->Clone(allocator)->AsExpression() : nullptr; - const auto *const func_type = variable->TsType()->AsETSFunctionType(); - for (auto *func_signature : func_type->CallSignatures()) { - sigature->SetReturnType(func_signature->ReturnType()); - if (!checker->Relation()->IsIdenticalTo(sigature, func_signature)) { - continue; + if (auto *const clone = allocator->New(kind_, key, value, flags_, allocator, is_computed_); + clone != nullptr) { + if (parent != nullptr) { + clone->SetParent(parent); } - checker->ReportWarning({"extension is shadowed by a instance member function '", func_type->Name(), - func_signature, "' in class ", obj_type->Name()}, - extension_func->Body()->Start()); - return; - } -} - -void MethodDefinition::CheckMethodModifiers(checker::ETSChecker *checker) -{ - auto const not_valid_in_abstract = ir::ModifierFlags::NATIVE | ir::ModifierFlags::PRIVATE | - ir::ModifierFlags::OVERRIDE | ir::ModifierFlags::FINAL | - ir::ModifierFlags::STATIC; + if (key != nullptr) { + key->SetParent(clone); + } - if (IsAbstract() && (flags_ & not_valid_in_abstract) != 0U) { - checker->ThrowTypeError( - "Invalid method modifier(s): an abstract method can't have private, override, static, final or native " - "modifier.", - Start()); - } + if (value != nullptr) { + value->SetParent(clone); + } - if ((IsAbstract() || (!Function()->HasBody() && !IsNative() && !IsDeclare())) && - !(checker->HasStatus(checker::CheckerStatus::IN_ABSTRACT) || - checker->HasStatus(checker::CheckerStatus::IN_INTERFACE))) { - checker->ThrowTypeError("Non abstract class has abstract method.", Start()); - } + for (auto *const decorator : decorators_) { + clone->AddDecorator(decorator->Clone(allocator, clone)); + } - auto const not_valid_in_final = ir::ModifierFlags::ABSTRACT | ir::ModifierFlags::STATIC | ir::ModifierFlags::NATIVE; + for (auto *const overloads : overloads_) { + clone->AddOverload(overloads->Clone(allocator, clone)); + } - if (IsFinal() && (flags_ & not_valid_in_final) != 0U) { - checker->ThrowTypeError( - "Invalid method modifier(s): a final method can't have abstract, static or native modifier.", Start()); + return clone; } - auto const not_valid_in_static = - ir::ModifierFlags::ABSTRACT | ir::ModifierFlags::FINAL | ir::ModifierFlags::OVERRIDE; - - if (IsStatic() && (flags_ & not_valid_in_static) != 0U) { - checker->ThrowTypeError( - "Invalid method modifier(s): a static method can't have abstract, final or override modifier.", Start()); - } + throw Error(ErrorType::GENERIC, "", CLONE_ALLOCATION_ERROR); } } // namespace panda::es2panda::ir diff --git a/ets2panda/ir/base/methodDefinition.h b/ets2panda/ir/base/methodDefinition.h index 079bddf66cfa20019c67274a2b4b1579b4c0af61..059301a44d33c0e460c631458ecfdf277e1d3029 100644 --- a/ets2panda/ir/base/methodDefinition.h +++ b/ets2panda/ir/base/methodDefinition.h @@ -1,5 +1,5 @@ /** - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021 - 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 @@ -16,41 +16,64 @@ #ifndef ES2PANDA_PARSER_INCLUDE_AST_METHOD_DEFINITION_H #define ES2PANDA_PARSER_INCLUDE_AST_METHOD_DEFINITION_H -#include "checker/types/ets/etsObjectType.h" -#include "checker/types/signature.h" #include "ir/base/classElement.h" +namespace panda::es2panda::checker { +class ETSAnalyzer; +} // namespace panda::es2panda::checker + namespace panda::es2panda::ir { + class Expression; +class ScriptFunction; enum class MethodDefinitionKind { NONE, CONSTRUCTOR, METHOD, EXTENSION_METHOD, GET, SET }; class MethodDefinition : public ClassElement { public: - explicit MethodDefinition(MethodDefinitionKind kind, Expression *key, Expression *value, ModifierFlags modifiers, - ArenaAllocator *allocator, bool is_computed) + MethodDefinition() = delete; + ~MethodDefinition() override = default; + + NO_COPY_SEMANTIC(MethodDefinition); + NO_MOVE_SEMANTIC(MethodDefinition); + + explicit MethodDefinition(MethodDefinitionKind const kind, Expression *const key, Expression *const value, + ModifierFlags const modifiers, ArenaAllocator *const allocator, bool const is_computed) : ClassElement(AstNodeType::METHOD_DEFINITION, key, value, modifiers, allocator, is_computed), kind_(kind), overloads_(allocator->Adapter()) { } + // NOTE (csabahurton): these friend relationships can be removed once there are getters for private fields + friend class checker::ETSAnalyzer; + MethodDefinitionKind Kind() const { return kind_; } - bool IsConstructor() const + [[nodiscard]] bool IsConstructor() const noexcept { return kind_ == MethodDefinitionKind::CONSTRUCTOR; } - bool IsExtensionMethod() const + [[nodiscard]] bool IsExtensionMethod() const noexcept { return kind_ == MethodDefinitionKind::EXTENSION_METHOD; } - const ArenaVector &Overloads() const + Expression const *Key() const + { + return key_; + } + + Expression const *Value() const + { + return value_; + } + + [[nodiscard]] const ArenaVector &Overloads() const noexcept { return overloads_; } @@ -60,12 +83,12 @@ public: overloads_ = std::move(overloads); } - void AddOverload(MethodDefinition *overload) + void AddOverload(MethodDefinition *const overload) { - overloads_.push_back(overload); + overloads_.emplace_back(overload); } - bool HasOverload(MethodDefinition *overload) + [[nodiscard]] bool HasOverload(MethodDefinition *overload) noexcept { return std::find(overloads_.begin(), overloads_.end(), overload) != overloads_.end(); } @@ -73,22 +96,18 @@ public: ScriptFunction *Function(); const ScriptFunction *Function() const; PrivateFieldKind ToPrivateFieldKind(bool is_static) const override; - void CheckMethodModifiers(checker::ETSChecker *checker); - void CheckExtensionMethod(checker::ETSChecker *checker, ScriptFunction *extension_func); - void CheckExtensionIsShadowedByMethod(checker::ETSChecker *checker, checker::ETSObjectType *obj_type, - ScriptFunction *extension_func, checker::Signature *sigature); - void CheckExtensionIsShadowedInCurrentClassOrInterface(checker::ETSChecker *checker, - checker::ETSObjectType *obj_type, - ScriptFunction *extension_func, - checker::Signature *sigature); + + // NOLINTNEXTLINE(google-default-arguments) + [[nodiscard]] MethodDefinition *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; + void Dump(ir::AstDumper *dumper) const override; - void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; - void Compile([[maybe_unused]] compiler::ETSGen *etsg) const override; - checker::Type *Check([[maybe_unused]] checker::TSChecker *checker) override; - checker::Type *Check([[maybe_unused]] checker::ETSChecker *checker) override; + void Compile(compiler::PandaGen *pg) const override; + void Compile(compiler::ETSGen *etsg) const override; + checker::Type *Check(checker::TSChecker *checker) override; + checker::Type *Check(checker::ETSChecker *checker) override; private: MethodDefinitionKind kind_; diff --git a/ets2panda/ir/base/property.cpp b/ets2panda/ir/base/property.cpp index f607be57b12bc097976ea5ea62d080cc8809aac4..962be16443769caee63d58314ed3f6ee1164c249 100644 --- a/ets2panda/ir/base/property.cpp +++ b/ets2panda/ir/base/property.cpp @@ -16,29 +16,26 @@ #include "property.h" #include "es2panda.h" -#include "ir/astDump.h" -#include "ir/expression.h" -#include "ir/expressions/arrayExpression.h" -#include "ir/expressions/assignmentExpression.h" -#include "ir/expressions/objectExpression.h" -#include "ir/expressions/identifier.h" -#include "ir/expressions/literals/stringLiteral.h" -#include "ir/validationInfo.h" +#include "checker/TSchecker.h" +#include "compiler/core/ETSGen.h" +#include "compiler/core/pandagen.h" namespace panda::es2panda::ir { -Property::Property([[maybe_unused]] Tag const tag, Expression *const key, Expression *const value) : Property(*this) +Property::Property([[maybe_unused]] Tag const tag, Property const &other, Expression *const key, + Expression *const value) + : Property(other) { key_ = key; value_ = value; } // NOLINTNEXTLINE(google-default-arguments) -Expression *Property::Clone(ArenaAllocator *const allocator, AstNode *const parent) +Property *Property::Clone(ArenaAllocator *const allocator, AstNode *const parent) { - auto *const key = key_ != nullptr ? key_->Clone(allocator) : nullptr; - auto *const value = value_ != nullptr ? value_->Clone(allocator) : nullptr; + auto *const key = key_ != nullptr ? key_->Clone(allocator)->AsExpression() : nullptr; + auto *const value = value_ != nullptr ? value_->Clone(allocator)->AsExpression() : nullptr; - if (auto *const clone = allocator->New(Tag {}, key, value); clone != nullptr) { + if (auto *const clone = allocator->New(Tag {}, *this, key, value); clone != nullptr) { if (key != nullptr) { key->SetParent(clone); } @@ -170,15 +167,23 @@ void Property::Dump(ir::AstDumper *dumper) const {"kind", kind}}); } -void Property::Compile([[maybe_unused]] compiler::PandaGen *pg) const {} +void Property::Compile(compiler::PandaGen *pg) const +{ + pg->GetAstCompiler()->Compile(this); +} + +void Property::Compile(compiler::ETSGen *etsg) const +{ + etsg->GetAstCompiler()->Compile(this); +} -checker::Type *Property::Check([[maybe_unused]] checker::TSChecker *checker) +checker::Type *Property::Check(checker::TSChecker *checker) { - return nullptr; + return checker->GetAnalyzer()->Check(this); } -checker::Type *Property::Check([[maybe_unused]] checker::ETSChecker *checker) +checker::Type *Property::Check(checker::ETSChecker *checker) { - return nullptr; + return checker->GetAnalyzer()->Check(this); } } // namespace panda::es2panda::ir diff --git a/ets2panda/ir/base/property.h b/ets2panda/ir/base/property.h index 91d91512c44d69921b94b4698ef2043ae9be9982..22759a0aca8344b9d2fb8fc578c1855ddef8de5d 100644 --- a/ets2panda/ir/base/property.h +++ b/ets2panda/ir/base/property.h @@ -50,7 +50,7 @@ public: { } - explicit Property(Tag tag, Expression *key, Expression *value); + explicit Property(Tag tag, Property const &other, Expression *key, Expression *value); [[nodiscard]] Expression *Key() noexcept { @@ -103,7 +103,7 @@ public: } // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] Expression *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + [[nodiscard]] Property *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; bool ConvertibleToPatternProperty(); ValidationInfo ValidateExpression(); @@ -111,9 +111,10 @@ public: void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; void Dump(ir::AstDumper *dumper) const override; - void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; - checker::Type *Check([[maybe_unused]] checker::TSChecker *checker) override; - checker::Type *Check([[maybe_unused]] checker::ETSChecker *checker) override; + void Compile(compiler::PandaGen *pg) const override; + void Compile(compiler::ETSGen *etsg) const override; + checker::Type *Check(checker::TSChecker *checker) override; + checker::Type *Check(checker::ETSChecker *checker) override; protected: Property(Property const &other) : Expression(static_cast(other)) diff --git a/ets2panda/ir/base/scriptFunction.cpp b/ets2panda/ir/base/scriptFunction.cpp index d7477e92b5b7cd519c9d50af95313d86ef5ba972..a058ba9da1a18793844609699b2cdbb007b279c1 100644 --- a/ets2panda/ir/base/scriptFunction.cpp +++ b/ets2panda/ir/base/scriptFunction.cpp @@ -16,36 +16,22 @@ #include "scriptFunction.h" #include "varbinder/scope.h" +#include "checker/TSchecker.h" #include "compiler/core/ETSGen.h" -#include "ir/astDump.h" -#include "ir/expression.h" -#include "ir/typeNode.h" -#include "ir/expressions/identifier.h" -#include "ir/statements/blockStatement.h" -#include "ir/ts/tsTypeParameter.h" -#include "ir/ts/tsTypeParameterDeclaration.h" +#include "compiler/core/pandagen.h" namespace panda::es2panda::ir { -bool ScriptFunction::HasBody() const -{ - return body_ != nullptr; -} -ir::ScriptFunctionFlags ScriptFunction::Flags() const +std::size_t ScriptFunction::FormalParamsLength() const noexcept { - return func_flags_; -} - -size_t ScriptFunction::FormalParamsLength() const -{ - size_t length = 0; + std::size_t length = 0U; for (const auto *param : params_) { if (param->IsRestElement() || param->IsAssignmentPattern()) { break; } - length++; + ++length; } return length; @@ -117,19 +103,22 @@ void ScriptFunction::Dump(ir::AstDumper *dumper) const } } -void ScriptFunction::Compile([[maybe_unused]] compiler::PandaGen *pg) const {} -void ScriptFunction::Compile([[maybe_unused]] compiler::ETSGen *etsg) const +void ScriptFunction::Compile(compiler::PandaGen *pg) const +{ + pg->GetAstCompiler()->Compile(this); +} +void ScriptFunction::Compile(compiler::ETSGen *etsg) const { - UNREACHABLE(); + etsg->GetAstCompiler()->Compile(this); } -checker::Type *ScriptFunction::Check([[maybe_unused]] checker::TSChecker *checker) +checker::Type *ScriptFunction::Check(checker::TSChecker *checker) { - return nullptr; + return checker->GetAnalyzer()->Check(this); } -checker::Type *ScriptFunction::Check([[maybe_unused]] checker::ETSChecker *checker) +checker::Type *ScriptFunction::Check(checker::ETSChecker *checker) { - return nullptr; + return checker->GetAnalyzer()->Check(this); } } // namespace panda::es2panda::ir diff --git a/ets2panda/ir/base/scriptFunction.h b/ets2panda/ir/base/scriptFunction.h index 93e134422716eda3f0635a8ab6982427df2d6bea..653a085db5ba2ebf1ee8ee71b4eb318ed201a530 100644 --- a/ets2panda/ir/base/scriptFunction.h +++ b/ets2panda/ir/base/scriptFunction.h @@ -1,5 +1,5 @@ /** - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021 - 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 @@ -30,7 +30,14 @@ class TSTypeParameterDeclaration; class TypeNode; class ScriptFunction : public AstNode { +private: public: + ScriptFunction() = delete; + ~ScriptFunction() override = default; + + NO_COPY_SEMANTIC(ScriptFunction); + NO_MOVE_SEMANTIC(ScriptFunction); + explicit ScriptFunction(varbinder::FunctionScope *scope, ArenaVector &¶ms, TSTypeParameterDeclaration *type_params, AstNode *body, TypeNode *return_type_annotation, ir::ScriptFunctionFlags func_flags, bool declare, Language lang) @@ -61,164 +68,167 @@ public: { } - const Identifier *Id() const + [[nodiscard]] const Identifier *Id() const noexcept { return id_; } - Identifier *Id() + [[nodiscard]] Identifier *Id() noexcept { return id_; } - const checker::Signature *Signature() const + [[nodiscard]] const checker::Signature *Signature() const noexcept { return signature_; } - checker::Signature *Signature() + [[nodiscard]] checker::Signature *Signature() noexcept { return signature_; } - const ArenaVector &Params() const + [[nodiscard]] const ArenaVector &Params() const noexcept { return params_; } - ArenaVector &Params() + [[nodiscard]] ArenaVector &Params() noexcept { return params_; } - const TSTypeParameterDeclaration *TypeParams() const + [[nodiscard]] const TSTypeParameterDeclaration *TypeParams() const noexcept { return type_params_; } - TSTypeParameterDeclaration *TypeParams() + [[nodiscard]] TSTypeParameterDeclaration *TypeParams() noexcept { return type_params_; } - const AstNode *Body() const + [[nodiscard]] const AstNode *Body() const noexcept { return body_; } - AstNode *Body() + [[nodiscard]] AstNode *Body() noexcept { return body_; } - void SetBody(AstNode *body) + void SetBody(AstNode *body) noexcept { body_ = body; } - const TypeNode *ReturnTypeAnnotation() const + [[nodiscard]] const TypeNode *ReturnTypeAnnotation() const noexcept { return return_type_annotation_; } - TypeNode *ReturnTypeAnnotation() + [[nodiscard]] TypeNode *ReturnTypeAnnotation() noexcept { return return_type_annotation_; } - void SetReturnTypeAnnotation(TypeNode *node) + void SetReturnTypeAnnotation(TypeNode *node) noexcept { return_type_annotation_ = node; } - bool IsEntryPoint() const + [[nodiscard]] bool IsEntryPoint() const noexcept { return (func_flags_ & ir::ScriptFunctionFlags::ENTRY_POINT) != 0; } - bool IsGenerator() const + [[nodiscard]] bool IsGenerator() const noexcept { return (func_flags_ & ir::ScriptFunctionFlags::GENERATOR) != 0; } - bool IsAsyncFunc() const + [[nodiscard]] bool IsAsyncFunc() const noexcept { return (func_flags_ & ir::ScriptFunctionFlags::ASYNC) != 0; } - bool IsArrow() const + [[nodiscard]] bool IsArrow() const noexcept { return (func_flags_ & ir::ScriptFunctionFlags::ARROW) != 0; } - bool IsOverload() const + [[nodiscard]] bool IsOverload() const noexcept { return (func_flags_ & ir::ScriptFunctionFlags::OVERLOAD) != 0; } - bool IsConstructor() const + [[nodiscard]] bool IsConstructor() const noexcept { return (func_flags_ & ir::ScriptFunctionFlags::CONSTRUCTOR) != 0; } - bool IsGetter() const + [[nodiscard]] bool IsGetter() const noexcept { return (func_flags_ & ir::ScriptFunctionFlags::GETTER) != 0; } - bool IsSetter() const + [[nodiscard]] bool IsSetter() const noexcept { return (func_flags_ & ir::ScriptFunctionFlags::SETTER) != 0; } - bool IsMethod() const + [[nodiscard]] bool IsMethod() const noexcept { return (func_flags_ & ir::ScriptFunctionFlags::METHOD) != 0; } - bool IsProxy() const + [[nodiscard]] bool IsProxy() const noexcept { return (func_flags_ & ir::ScriptFunctionFlags::PROXY) != 0; } - bool IsStaticBlock() const + [[nodiscard]] bool IsStaticBlock() const noexcept { return (func_flags_ & ir::ScriptFunctionFlags::STATIC_BLOCK) != 0; } - bool IsEnum() const + [[nodiscard]] bool IsEnum() const noexcept { return (func_flags_ & ir::ScriptFunctionFlags::ENUM) != 0; } - bool IsHidden() const + [[nodiscard]] bool IsHidden() const noexcept { return (func_flags_ & ir::ScriptFunctionFlags::HIDDEN) != 0; } - bool IsExternal() const + [[nodiscard]] bool IsExternal() const noexcept { return (func_flags_ & ir::ScriptFunctionFlags::EXTERNAL) != 0; } - bool IsImplicitSuperCallNeeded() const + [[nodiscard]] bool IsImplicitSuperCallNeeded() const noexcept { return (func_flags_ & ir::ScriptFunctionFlags::IMPLICIT_SUPER_CALL_NEEDED) != 0; } - bool HasBody() const; + [[nodiscard]] bool HasBody() const noexcept + { + return body_ != nullptr; + } - bool IsThrowing() const + [[nodiscard]] bool IsThrowing() const noexcept { return (func_flags_ & ir::ScriptFunctionFlags::THROWS) != 0; } - bool IsRethrowing() const + [[nodiscard]] bool IsRethrowing() const noexcept { return (func_flags_ & ir::ScriptFunctionFlags::RETHROWS) != 0; } - bool IsDefaultParamProxy() const noexcept + [[nodiscard]] bool IsDefaultParamProxy() const noexcept { return (func_flags_ & ir::ScriptFunctionFlags::DEFAULT_PARAM_PROXY) != 0; } @@ -228,44 +238,47 @@ public: AddFlag(ir::ScriptFunctionFlags::DEFAULT_PARAM_PROXY); } - bool IsDynamic() const + [[nodiscard]] bool IsDynamic() const noexcept { return lang_.IsDynamic(); } - bool IsExtensionMethod() const + [[nodiscard]] bool IsExtensionMethod() const noexcept { return (func_flags_ & ir::ScriptFunctionFlags::INSTANCE_EXTENSION_METHOD) != 0; } - bool Declare() const + [[nodiscard]] bool Declare() const noexcept { return declare_; } - ir::ScriptFunctionFlags Flags() const; + [[nodiscard]] ir::ScriptFunctionFlags Flags() const noexcept + { + return func_flags_; + } - void SetIdent(Identifier *id) + void SetIdent(Identifier *id) noexcept { id_ = id; } - void SetSignature(checker::Signature *signature) + void SetSignature(checker::Signature *signature) noexcept { signature_ = signature; } - void AddFlag(ir::ScriptFunctionFlags flags) + void AddFlag(ir::ScriptFunctionFlags flags) noexcept { func_flags_ |= flags; } - void AddModifier(ir::ModifierFlags flags) + void AddModifier(ir::ModifierFlags flags) noexcept { flags_ |= flags; } - size_t FormalParamsLength() const; + [[nodiscard]] std::size_t FormalParamsLength() const noexcept; bool IsScopeBearer() const override { @@ -277,19 +290,19 @@ public: return scope_; } - void TransformChildren(const NodeTransformer &cb) override; - - es2panda::Language Language() const + [[nodiscard]] es2panda::Language Language() const { return lang_; } + void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; + void Dump(ir::AstDumper *dumper) const override; - void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; - void Compile([[maybe_unused]] compiler::ETSGen *etsg) const override; - checker::Type *Check([[maybe_unused]] checker::TSChecker *checker) override; - checker::Type *Check([[maybe_unused]] checker::ETSChecker *checker) override; + void Compile(compiler::PandaGen *pg) const override; + void Compile(compiler::ETSGen *etsg) const override; + checker::Type *Check(checker::TSChecker *checker) override; + checker::Type *Check(checker::ETSChecker *checker) override; private: varbinder::FunctionScope *scope_; diff --git a/ets2panda/ir/base/spreadElement.cpp b/ets2panda/ir/base/spreadElement.cpp index 1f995a1f1160a8f03d86f2b8c0199817629b6394..c6a722c3ad7a17e58e9e94ff6e11dd96478f1b4c 100644 --- a/ets2panda/ir/base/spreadElement.cpp +++ b/ets2panda/ir/base/spreadElement.cpp @@ -25,22 +25,21 @@ namespace panda::es2panda::ir { SpreadElement::SpreadElement([[maybe_unused]] Tag const tag, SpreadElement const &other, ArenaAllocator *const allocator) - : AnnotatedExpression(static_cast(other)), decorators_(allocator->Adapter()) + : AnnotatedExpression(static_cast(other), allocator), decorators_(allocator->Adapter()) { - CloneTypeAnnotation(allocator); optional_ = other.optional_; if (other.argument_ != nullptr) { - argument_ = other.argument_->Clone(allocator, this); + argument_ = other.argument_->Clone(allocator, this)->AsExpression(); } for (auto *decorator : other.decorators_) { - decorators_.emplace_back(decorator->Clone(allocator, this)->AsDecorator()); + decorators_.emplace_back(decorator->Clone(allocator, this)); } } // NOLINTNEXTLINE(google-default-arguments) -Expression *SpreadElement::Clone(ArenaAllocator *const allocator, AstNode *const parent) +SpreadElement *SpreadElement::Clone(ArenaAllocator *const allocator, AstNode *const parent) { if (auto *const clone = allocator->New(Tag {}, *this, allocator); clone != nullptr) { if (parent != nullptr) { diff --git a/ets2panda/ir/base/spreadElement.h b/ets2panda/ir/base/spreadElement.h index 037cc59ca40d90174d64c54e4380f659c96ae2b5..d3c047434e7a3c33eba06c9e031f4aeeb569fc86 100644 --- a/ets2panda/ir/base/spreadElement.h +++ b/ets2panda/ir/base/spreadElement.h @@ -58,18 +58,28 @@ public: return decorators_; } + const ArenaVector *DecoratorsPtr() const override + { + return &Decorators(); + } + void AddDecorators(ArenaVector &&decorators) override { decorators_ = std::move(decorators); } - void SetOptional(bool const optional) noexcept + bool CanHaveDecorator([[maybe_unused]] bool in_ts) const override + { + return true; + } + + void SetOptional(bool optional) noexcept { optional_ = optional; } // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] Expression *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + [[nodiscard]] SpreadElement *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; ValidationInfo ValidateExpression(); [[nodiscard]] bool ConvertibleToRest(bool is_declaration, bool allow_pattern = true); diff --git a/ets2panda/ir/base/templateElement.cpp b/ets2panda/ir/base/templateElement.cpp index 8a0e7d317ee2ca4c6cdd02508ea2490ef5eb7ca5..f77f0237072aa10032568825d48f6b597cb03ab9 100644 --- a/ets2panda/ir/base/templateElement.cpp +++ b/ets2panda/ir/base/templateElement.cpp @@ -15,10 +15,9 @@ #include "templateElement.h" -#include "es2panda.h" +#include "checker/TSchecker.h" #include "compiler/core/ETSGen.h" -#include "ir/astDump.h" -#include "util/ustring.h" +#include "compiler/core/pandagen.h" namespace panda::es2panda::ir { void TemplateElement::TransformChildren([[maybe_unused]] const NodeTransformer &cb) {} @@ -32,26 +31,28 @@ void TemplateElement::Dump(ir::AstDumper *dumper) const }); } -void TemplateElement::Compile([[maybe_unused]] compiler::PandaGen *pg) const {} +void TemplateElement::Compile(compiler::PandaGen *pg) const +{ + pg->GetAstCompiler()->Compile(this); +} -void TemplateElement::Compile([[maybe_unused]] compiler::ETSGen *etsg) const +void TemplateElement::Compile(compiler::ETSGen *etsg) const { - etsg->LoadAccumulatorString(this, raw_); + etsg->GetAstCompiler()->Compile(this); } -checker::Type *TemplateElement::Check([[maybe_unused]] checker::TSChecker *checker) +checker::Type *TemplateElement::Check(checker::TSChecker *checker) { - return nullptr; + return checker->GetAnalyzer()->Check(this); } -checker::Type *TemplateElement::Check([[maybe_unused]] checker::ETSChecker *checker) +checker::Type *TemplateElement::Check(checker::ETSChecker *checker) { - SetTsType(checker->CreateETSStringLiteralType(raw_)); - return TsType(); + return checker->GetAnalyzer()->Check(this); } // NOLINTNEXTLINE(google-default-arguments) -Expression *TemplateElement::Clone(ArenaAllocator *const allocator, AstNode *const parent) +TemplateElement *TemplateElement::Clone(ArenaAllocator *const allocator, AstNode *const parent) { if (auto *const clone = allocator->New(raw_, cooked_); clone != nullptr) { if (parent != nullptr) { diff --git a/ets2panda/ir/base/templateElement.h b/ets2panda/ir/base/templateElement.h index b373d7aff8cc660a598824361c10e65c2e93ef3c..0f9e6b7a90c3ebd0a1560e003eb8cb968cb8e79d 100644 --- a/ets2panda/ir/base/templateElement.h +++ b/ets2panda/ir/base/templateElement.h @@ -45,15 +45,15 @@ public: } // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] Expression *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + [[nodiscard]] TemplateElement *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; void Dump(ir::AstDumper *dumper) const override; - void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; - void Compile([[maybe_unused]] compiler::ETSGen *etsg) const override; - checker::Type *Check([[maybe_unused]] checker::TSChecker *checker) override; - checker::Type *Check([[maybe_unused]] checker::ETSChecker *checker) override; + void Compile(compiler::PandaGen *pg) const override; + void Compile(compiler::ETSGen *etsg) const override; + checker::Type *Check(checker::TSChecker *checker) override; + checker::Type *Check(checker::ETSChecker *checker) override; private: util::StringView raw_ {}; diff --git a/ets2panda/ir/base/tsIndexSignature.cpp b/ets2panda/ir/base/tsIndexSignature.cpp index 09598d5b2488039e1ebf0c31c6900265cb77e31a..2bea99f714334c9e2337bd36192b2f155d89129c 100644 --- a/ets2panda/ir/base/tsIndexSignature.cpp +++ b/ets2panda/ir/base/tsIndexSignature.cpp @@ -1,5 +1,5 @@ /** - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021 - 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 @@ -15,14 +15,12 @@ #include "tsIndexSignature.h" -#include "ir/astDump.h" -#include "ir/typeNode.h" -#include "ir/expressions/identifier.h" - #include "checker/TSchecker.h" +#include "compiler/core/ETSGen.h" +#include "compiler/core/pandagen.h" namespace panda::es2panda::ir { -TSIndexSignature::TSIndexSignatureKind TSIndexSignature::Kind() const +TSIndexSignature::TSIndexSignatureKind TSIndexSignature::Kind() const noexcept { return param_->AsIdentifier()->TypeAnnotation()->IsTSNumberKeyword() ? TSIndexSignatureKind::NUMBER : TSIndexSignatureKind::STRING; @@ -48,34 +46,43 @@ void TSIndexSignature::Dump(ir::AstDumper *dumper) const {"readonly", readonly_}}); } -void TSIndexSignature::Compile([[maybe_unused]] compiler::PandaGen *pg) const {} - -checker::Type *TSIndexSignature::Check([[maybe_unused]] checker::TSChecker *checker) +void TSIndexSignature::Compile(compiler::PandaGen *pg) const { - if (TsType() != nullptr) { - return TsType(); - } + pg->GetAstCompiler()->Compile(this); +} - const util::StringView ¶m_name = param_->AsIdentifier()->Name(); - type_annotation_->Check(checker); - checker::Type *index_type = type_annotation_->GetType(checker); - checker::IndexInfo *info = - checker->Allocator()->New(index_type, param_name, readonly_, this->Start()); - checker::ObjectDescriptor *desc = checker->Allocator()->New(checker->Allocator()); - checker::ObjectType *placeholder = checker->Allocator()->New(desc); +void TSIndexSignature::Compile(compiler::ETSGen *etsg) const +{ + etsg->GetAstCompiler()->Compile(this); +} - if (Kind() == ir::TSIndexSignature::TSIndexSignatureKind::NUMBER) { - placeholder->Desc()->number_index_info = info; - } else { - placeholder->Desc()->string_index_info = info; - } +checker::Type *TSIndexSignature::Check(checker::TSChecker *checker) +{ + return checker->GetAnalyzer()->Check(this); +} - SetTsType(placeholder); - return placeholder; +checker::Type *TSIndexSignature::Check(checker::ETSChecker *checker) +{ + return checker->GetAnalyzer()->Check(this); } -checker::Type *TSIndexSignature::Check([[maybe_unused]] checker::ETSChecker *checker) +// NOLINTNEXTLINE(google-default-arguments) +TSIndexSignature *TSIndexSignature::Clone(ArenaAllocator *const allocator, AstNode *const parent) { - return nullptr; + auto *const param = param_ != nullptr ? param_->Clone(allocator)->AsExpression() : nullptr; + auto *const type_annotation = type_annotation_->Clone(allocator); + + if (auto *const clone = allocator->New(param, type_annotation, readonly_); clone != nullptr) { + if (parent != nullptr) { + clone->SetParent(parent); + } + if (param != nullptr) { + param->SetParent(clone); + } + type_annotation->SetParent(clone); + return clone; + } + + throw Error(ErrorType::GENERIC, "", CLONE_ALLOCATION_ERROR); } } // namespace panda::es2panda::ir diff --git a/ets2panda/ir/base/tsIndexSignature.h b/ets2panda/ir/base/tsIndexSignature.h index db29746c9150d9f768b760e68477280096771d64..f7ed2de9f43d054ca3143c72b50d2e2309676410 100644 --- a/ets2panda/ir/base/tsIndexSignature.h +++ b/ets2panda/ir/base/tsIndexSignature.h @@ -1,5 +1,5 @@ /** - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021 - 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 @@ -16,44 +16,61 @@ #ifndef ES2PANDA_PARSER_INCLUDE_AST_TS_INDEX_SIGNATURE_H #define ES2PANDA_PARSER_INCLUDE_AST_TS_INDEX_SIGNATURE_H -#include "ir/statement.h" +#include "ir/typeNode.h" + +namespace panda::es2panda::checker { +class TSAnalyzer; +} // namespace panda::es2panda::checker namespace panda::es2panda::ir { class TSIndexSignature : public TypedAstNode { public: enum class TSIndexSignatureKind { NUMBER, STRING }; - explicit TSIndexSignature(Expression *param, TypeNode *type_annotation, bool readonly) + TSIndexSignature() = delete; + ~TSIndexSignature() override = default; + + NO_COPY_SEMANTIC(TSIndexSignature); + NO_MOVE_SEMANTIC(TSIndexSignature); + + explicit TSIndexSignature(Expression *const param, TypeNode *const type_annotation, bool const readonly) : TypedAstNode(AstNodeType::TS_INDEX_SIGNATURE), param_(param), type_annotation_(type_annotation), readonly_(readonly) { } + // NOTE (csabahurton): friend relationship can be removed once there are getters for private fields + friend class checker::TSAnalyzer; - const Expression *Param() const + [[nodiscard]] const Expression *Param() const noexcept { return param_; } - const TypeNode *TypeAnnotation() const + [[nodiscard]] const TypeNode *TypeAnnotation() const noexcept { return type_annotation_; } - bool Readonly() const + [[nodiscard]] bool Readonly() const noexcept { return readonly_; } - TSIndexSignatureKind Kind() const; + [[nodiscard]] TSIndexSignatureKind Kind() const noexcept; + + // NOLINTNEXTLINE(google-default-arguments) + [[nodiscard]] TSIndexSignature *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; + void Dump(ir::AstDumper *dumper) const override; - void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; - checker::Type *Check([[maybe_unused]] checker::TSChecker *checker) override; - checker::Type *Check([[maybe_unused]] checker::ETSChecker *checker) override; + void Compile(compiler::PandaGen *pg) const override; + void Compile(compiler::ETSGen *etsg) const override; + checker::Type *Check(checker::TSChecker *checker) override; + checker::Type *Check(checker::ETSChecker *checker) override; private: Expression *param_; diff --git a/ets2panda/ir/base/tsMethodSignature.cpp b/ets2panda/ir/base/tsMethodSignature.cpp index c6f203b24b91e353de82a43c3fc37a2cd96349f9..f94bde70c69bc998bdab28280a94daaea126b1ea 100644 --- a/ets2panda/ir/base/tsMethodSignature.cpp +++ b/ets2panda/ir/base/tsMethodSignature.cpp @@ -1,5 +1,5 @@ /** - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021 - 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 @@ -16,12 +16,9 @@ #include "tsMethodSignature.h" #include "varbinder/scope.h" -#include "ir/astDump.h" -#include "ir/typeNode.h" -#include "ir/ts/tsTypeParameter.h" -#include "ir/ts/tsTypeParameterDeclaration.h" - #include "checker/TSchecker.h" +#include "compiler/core/ETSGen.h" +#include "compiler/core/pandagen.h" namespace panda::es2panda::ir { void TSMethodSignature::TransformChildren(const NodeTransformer &cb) @@ -69,35 +66,23 @@ void TSMethodSignature::Dump(ir::AstDumper *dumper) const {"typeAnnotation", AstDumper::Optional(return_type_annotation_)}}); } -void TSMethodSignature::Compile([[maybe_unused]] compiler::PandaGen *pg) const {} - -checker::Type *TSMethodSignature::Check([[maybe_unused]] checker::TSChecker *checker) +void TSMethodSignature::Compile(compiler::PandaGen *pg) const { - if (computed_) { - checker->CheckComputedPropertyName(key_); - } - - checker::ScopeContext scope_ctx(checker, scope_); - - auto *signature_info = checker->Allocator()->New(checker->Allocator()); - checker->CheckFunctionParameterDeclarations(params_, signature_info); - - auto *call_signature = checker->Allocator()->New(signature_info, checker->GlobalAnyType()); - Variable()->SetTsType(checker->CreateFunctionTypeWithSignature(call_signature)); - - if (return_type_annotation_ == nullptr) { - checker->ThrowTypeError( - "Method signature, which lacks return-type annotation, implicitly has an 'any' return type.", Start()); - } + pg->GetAstCompiler()->Compile(this); +} - return_type_annotation_->Check(checker); - call_signature->SetReturnType(return_type_annotation_->GetType(checker)); +void TSMethodSignature::Compile(compiler::ETSGen *etsg) const +{ + etsg->GetAstCompiler()->Compile(this); +} - return nullptr; +checker::Type *TSMethodSignature::Check(checker::TSChecker *checker) +{ + return checker->GetAnalyzer()->Check(this); } -checker::Type *TSMethodSignature::Check([[maybe_unused]] checker::ETSChecker *checker) +checker::Type *TSMethodSignature::Check(checker::ETSChecker *checker) { - return nullptr; + return checker->GetAnalyzer()->Check(this); } } // namespace panda::es2panda::ir diff --git a/ets2panda/ir/base/tsMethodSignature.h b/ets2panda/ir/base/tsMethodSignature.h index ffa4dca38709fca21aa9ff37fc4382ca0e2e69cd..b0e66768a73660e930496d15a5cc6aec97a21fb4 100644 --- a/ets2panda/ir/base/tsMethodSignature.h +++ b/ets2panda/ir/base/tsMethodSignature.h @@ -1,5 +1,5 @@ /** - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021 - 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 @@ -16,13 +16,24 @@ #ifndef ES2PANDA_PARSER_INCLUDE_AST_TS_METHOD_SIGNATURE_H #define ES2PANDA_PARSER_INCLUDE_AST_TS_METHOD_SIGNATURE_H -#include "ir/statement.h" +#include "ir/typeNode.h" + +namespace panda::es2panda::checker { +class TSAnalyzer; +class ETSAnalyzer; +} // namespace panda::es2panda::checker namespace panda::es2panda::ir { class TSTypeParameterDeclaration; class TSMethodSignature : public AstNode { public: + TSMethodSignature() = delete; + ~TSMethodSignature() override = default; + + NO_COPY_SEMANTIC(TSMethodSignature); + NO_MOVE_SEMANTIC(TSMethodSignature); + explicit TSMethodSignature(varbinder::Scope *scope, Expression *key, TSTypeParameterDeclaration *type_params, ArenaVector &¶ms, TypeNode *return_type_annotation, bool computed, bool optional) @@ -37,6 +48,9 @@ public: { } + // NOTE (csabahurton): friend relationship can be removed once there are getters for private fields + friend class checker::TSAnalyzer; + bool IsScopeBearer() const override { return true; @@ -47,47 +61,49 @@ public: return scope_; } - const Expression *Key() const + [[nodiscard]] const Expression *Key() const noexcept { return key_; } - Expression *Key() + [[nodiscard]] Expression *Key() noexcept { return key_; } - const TSTypeParameterDeclaration *TypeParams() const + [[nodiscard]] const TSTypeParameterDeclaration *TypeParams() const noexcept { return type_params_; } - const ArenaVector &Params() const + [[nodiscard]] const ArenaVector &Params() const noexcept { return params_; } - const TypeNode *ReturnTypeAnnotation() const + [[nodiscard]] const TypeNode *ReturnTypeAnnotation() const noexcept { return return_type_annotation_; } - bool Computed() const + [[nodiscard]] bool Computed() const noexcept { return computed_; } - bool Optional() const + [[nodiscard]] bool Optional() const noexcept { return optional_; } void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; + void Dump(ir::AstDumper *dumper) const override; - void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; - checker::Type *Check([[maybe_unused]] checker::TSChecker *checker) override; - checker::Type *Check([[maybe_unused]] checker::ETSChecker *checker) override; + void Compile(compiler::PandaGen *pg) const override; + void Compile(compiler::ETSGen *etsg) const override; + checker::Type *Check(checker::TSChecker *checker) override; + checker::Type *Check(checker::ETSChecker *checker) override; private: varbinder::Scope *scope_; diff --git a/ets2panda/ir/base/tsPropertySignature.cpp b/ets2panda/ir/base/tsPropertySignature.cpp index 3cfddf1f7fa1cb06cf888cd07f5a517fa545388e..ee863b4b7c55c56b1d8f9cbd01cfef6206233a21 100644 --- a/ets2panda/ir/base/tsPropertySignature.cpp +++ b/ets2panda/ir/base/tsPropertySignature.cpp @@ -1,5 +1,5 @@ /** - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021 - 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 @@ -15,10 +15,9 @@ #include "tsPropertySignature.h" -#include "ir/astDump.h" -#include "ir/typeNode.h" - #include "checker/TSchecker.h" +#include "compiler/core/ETSGen.h" +#include "compiler/core/pandagen.h" namespace panda::es2panda::ir { void TSPropertySignature::TransformChildren(const NodeTransformer &cb) @@ -49,29 +48,44 @@ void TSPropertySignature::Dump(ir::AstDumper *dumper) const {"typeAnnotation", AstDumper::Optional(TypeAnnotation())}}); } -void TSPropertySignature::Compile([[maybe_unused]] compiler::PandaGen *pg) const {} - -checker::Type *TSPropertySignature::Check([[maybe_unused]] checker::TSChecker *checker) +void TSPropertySignature::Compile(compiler::PandaGen *pg) const { - if (TypeAnnotation() != nullptr) { - TypeAnnotation()->Check(checker); - } + pg->GetAstCompiler()->Compile(this); +} - if (computed_) { - checker->CheckComputedPropertyName(key_); - } +void TSPropertySignature::Compile(compiler::ETSGen *etsg) const +{ + etsg->GetAstCompiler()->Compile(this); +} - if (TypeAnnotation() != nullptr) { - Variable()->SetTsType(TypeAnnotation()->GetType(checker)); - return nullptr; - } +checker::Type *TSPropertySignature::Check(checker::TSChecker *checker) +{ + return checker->GetAnalyzer()->Check(this); +} - checker->ThrowTypeError("Property implicitly has an 'any' type.", Start()); - return nullptr; +checker::Type *TSPropertySignature::Check(checker::ETSChecker *checker) +{ + return checker->GetAnalyzer()->Check(this); } -checker::Type *TSPropertySignature::Check([[maybe_unused]] checker::ETSChecker *checker) +// NOLINTNEXTLINE(google-default-arguments) +TSPropertySignature *TSPropertySignature::Clone(ArenaAllocator *const allocator, AstNode *const parent) { - return nullptr; + auto *const key = key_ != nullptr ? key_->Clone(allocator)->AsExpression() : nullptr; + auto *const type_annotation = TypeAnnotation()->Clone(allocator); + + if (auto *const clone = allocator->New(key, type_annotation, computed_, optional_, readonly_); + clone != nullptr) { + if (parent != nullptr) { + clone->SetParent(parent); + } + if (key != nullptr) { + key->SetParent(clone); + } + type_annotation->SetParent(clone); + return clone; + } + + throw Error(ErrorType::GENERIC, "", CLONE_ALLOCATION_ERROR); } } // namespace panda::es2panda::ir diff --git a/ets2panda/ir/base/tsPropertySignature.h b/ets2panda/ir/base/tsPropertySignature.h index b39ebfdd0dc38b3e327f4905f11ab52012768d2f..929e74dc15b315b945c6dcbb5373bbdd946905e6 100644 --- a/ets2panda/ir/base/tsPropertySignature.h +++ b/ets2panda/ir/base/tsPropertySignature.h @@ -23,6 +23,12 @@ class TypeNode; class TSPropertySignature : public AnnotatedAstNode { public: + TSPropertySignature() = delete; + ~TSPropertySignature() override = default; + + NO_COPY_SEMANTIC(TSPropertySignature); + NO_MOVE_SEMANTIC(TSPropertySignature); + explicit TSPropertySignature(Expression *key, TypeNode *type_annotation, bool computed, bool optional, bool readonly) : AnnotatedAstNode(AstNodeType::TS_PROPERTY_SIGNATURE, type_annotation), @@ -33,37 +39,42 @@ public: { } - const Expression *Key() const + [[nodiscard]] const Expression *Key() const noexcept { return key_; } - Expression *Key() + [[nodiscard]] Expression *Key() noexcept { return key_; } - bool Computed() const + [[nodiscard]] bool Computed() const noexcept { return computed_; } - bool Optional() const + [[nodiscard]] bool Optional() const noexcept { return optional_; } - bool Readonly() const + [[nodiscard]] bool Readonly() const noexcept { return readonly_; } + // NOLINTNEXTLINE(google-default-arguments) + [[nodiscard]] TSPropertySignature *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; + void Dump(ir::AstDumper *dumper) const override; - void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; - checker::Type *Check([[maybe_unused]] checker::TSChecker *checker) override; - checker::Type *Check([[maybe_unused]] checker::ETSChecker *checker) override; + void Compile(compiler::PandaGen *pg) const override; + void Compile(compiler::ETSGen *etsg) const override; + checker::Type *Check(checker::TSChecker *checker) override; + checker::Type *Check(checker::ETSChecker *checker) override; private: Expression *key_; diff --git a/ets2panda/ir/base/tsSignatureDeclaration.cpp b/ets2panda/ir/base/tsSignatureDeclaration.cpp index 734c4613f9cdd7b80be713cadb2c229dd837689d..a36cf714a6a1d619871eb8b804e8240d92575d13 100644 --- a/ets2panda/ir/base/tsSignatureDeclaration.cpp +++ b/ets2panda/ir/base/tsSignatureDeclaration.cpp @@ -1,5 +1,5 @@ /** - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021 - 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 diff --git a/ets2panda/ir/base/tsSignatureDeclaration.h b/ets2panda/ir/base/tsSignatureDeclaration.h index bd89af7fa3b833cc3542d3b60d05ae871697f8e6..20028f3aa848702267ad4baf9d862a158343e16d 100644 --- a/ets2panda/ir/base/tsSignatureDeclaration.h +++ b/ets2panda/ir/base/tsSignatureDeclaration.h @@ -1,5 +1,5 @@ /** - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021 - 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 @@ -16,7 +16,7 @@ #ifndef ES2PANDA_PARSER_INCLUDE_AST_TS_SIGNATURE_DECLARATION_H #define ES2PANDA_PARSER_INCLUDE_AST_TS_SIGNATURE_DECLARATION_H -#include "ir/statement.h" +#include "ir/astNode.h" namespace panda::es2panda::ir { class TSTypeParameterDeclaration; @@ -25,9 +25,15 @@ class TSSignatureDeclaration : public TypedAstNode { public: enum class TSSignatureDeclarationKind { CALL_SIGNATURE, CONSTRUCT_SIGNATURE }; - explicit TSSignatureDeclaration(varbinder::Scope *scope, TSSignatureDeclarationKind kind, - TSTypeParameterDeclaration *type_params, ArenaVector &¶ms, - TypeNode *return_type_annotation) + TSSignatureDeclaration() = delete; + ~TSSignatureDeclaration() override = default; + + NO_COPY_SEMANTIC(TSSignatureDeclaration); + NO_MOVE_SEMANTIC(TSSignatureDeclaration); + + explicit TSSignatureDeclaration(varbinder::Scope *const scope, TSSignatureDeclarationKind const kind, + TSTypeParameterDeclaration *const type_params, ArenaVector &¶ms, + TypeNode *const return_type_annotation) : TypedAstNode(AstNodeType::TS_SIGNATURE_DECLARATION), scope_(scope), kind_(kind), @@ -47,29 +53,31 @@ public: return scope_; } - const TSTypeParameterDeclaration *TypeParams() const + [[nodiscard]] const TSTypeParameterDeclaration *TypeParams() const noexcept { return type_params_; } - const ArenaVector &Params() const + [[nodiscard]] const ArenaVector &Params() const noexcept { return params_; } - const TypeNode *ReturnTypeAnnotation() const + [[nodiscard]] const TypeNode *ReturnTypeAnnotation() const noexcept { return return_type_annotation_; } - TSSignatureDeclarationKind Kind() const + [[nodiscard]] TSSignatureDeclarationKind Kind() const noexcept { return kind_; } void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; + void Dump(ir::AstDumper *dumper) const override; + void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; checker::Type *Check([[maybe_unused]] checker::TSChecker *checker) override; checker::Type *Check([[maybe_unused]] checker::ETSChecker *checker) override; diff --git a/ets2panda/ir/ets/etsClassLiteral.cpp b/ets2panda/ir/ets/etsClassLiteral.cpp index 79c11f531ecd7fc26d5fb88e412abc91c73b012b..9d461309a1ecac09ea49b28c67e735499e41a92d 100644 --- a/ets2panda/ir/ets/etsClassLiteral.cpp +++ b/ets2panda/ir/ets/etsClassLiteral.cpp @@ -77,9 +77,9 @@ checker::Type *ETSClassLiteral::Check([[maybe_unused]] checker::ETSChecker *chec } // NOLINTNEXTLINE(google-default-arguments) -Expression *ETSClassLiteral::Clone(ArenaAllocator *const allocator, AstNode *const parent) +ETSClassLiteral *ETSClassLiteral::Clone(ArenaAllocator *const allocator, AstNode *const parent) { - auto *const expr = expr_ != nullptr ? expr_->Clone(allocator)->AsTypeNode() : nullptr; + auto *const expr = expr_ != nullptr ? expr_->Clone(allocator) : nullptr; if (auto *const clone = allocator->New(expr); clone != nullptr) { if (expr != nullptr) { diff --git a/ets2panda/ir/ets/etsClassLiteral.h b/ets2panda/ir/ets/etsClassLiteral.h index 64dadfd65bbfb304b5a993444ee73cbba8bbe36f..44fbf9c8ba0179b0caf85783579f81727f302c11 100644 --- a/ets2panda/ir/ets/etsClassLiteral.h +++ b/ets2panda/ir/ets/etsClassLiteral.h @@ -31,7 +31,7 @@ public: explicit ETSClassLiteral(ir::TypeNode *const expr) : Expression(AstNodeType::ETS_CLASS_LITERAL), expr_(expr) {} // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] Expression *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + [[nodiscard]] ETSClassLiteral *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; diff --git a/ets2panda/ir/ets/etsFunctionType.h b/ets2panda/ir/ets/etsFunctionType.h index 62c59ffd9fb30b2a00ef9ef17bfc878c4961f611..d8323848934eb12c044460249b056ae6bdb1ca1a 100644 --- a/ets2panda/ir/ets/etsFunctionType.h +++ b/ets2panda/ir/ets/etsFunctionType.h @@ -80,6 +80,11 @@ public: functional_interface_ = functional_interface; } + ir::ScriptFunctionFlags Flags() + { + return func_flags_; + } + bool IsThrowing() const { return (func_flags_ & ir::ScriptFunctionFlags::THROWS) != 0; diff --git a/ets2panda/ir/ets/etsLaunchExpression.cpp b/ets2panda/ir/ets/etsLaunchExpression.cpp index f5d880a47f87fba81be68b8bcdd7c9ea5d3983b0..280a1f05e2531d5bc58e42805d5a69a6ae531f7b 100644 --- a/ets2panda/ir/ets/etsLaunchExpression.cpp +++ b/ets2panda/ir/ets/etsLaunchExpression.cpp @@ -117,9 +117,9 @@ bool ETSLaunchExpression::IsStaticCall() const } // NOLINTNEXTLINE(google-default-arguments) -Expression *ETSLaunchExpression::Clone(ArenaAllocator *const allocator, AstNode *const parent) +ETSLaunchExpression *ETSLaunchExpression::Clone(ArenaAllocator *const allocator, AstNode *const parent) { - auto *const expr = expr_ != nullptr ? expr_->Clone(allocator)->AsCallExpression() : nullptr; + auto *const expr = expr_ != nullptr ? expr_->Clone(allocator) : nullptr; if (auto *const clone = allocator->New(expr); clone != nullptr) { if (expr != nullptr) { diff --git a/ets2panda/ir/ets/etsLaunchExpression.h b/ets2panda/ir/ets/etsLaunchExpression.h index db99d9e6a58b6fd1a65e0be5066bdb06cb764bed..2863db9948045ae9f94f5adba6606e7e2333e716 100644 --- a/ets2panda/ir/ets/etsLaunchExpression.h +++ b/ets2panda/ir/ets/etsLaunchExpression.h @@ -33,7 +33,7 @@ public: explicit ETSLaunchExpression(CallExpression *expr); // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] Expression *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + [[nodiscard]] ETSLaunchExpression *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; diff --git a/ets2panda/ir/ets/etsNewArrayInstanceExpression.cpp b/ets2panda/ir/ets/etsNewArrayInstanceExpression.cpp index bf3d63aafe6f8230f4e2f8cb39ebd7dc9b536ce3..b56d07341e770bf2117b4091904345c98e01cbfa 100644 --- a/ets2panda/ir/ets/etsNewArrayInstanceExpression.cpp +++ b/ets2panda/ir/ets/etsNewArrayInstanceExpression.cpp @@ -71,10 +71,11 @@ checker::Type *ETSNewArrayInstanceExpression::Check([[maybe_unused]] checker::ET } // NOLINTNEXTLINE(google-default-arguments) -Expression *ETSNewArrayInstanceExpression::Clone(ArenaAllocator *const allocator, AstNode *const parent) +ETSNewArrayInstanceExpression *ETSNewArrayInstanceExpression::Clone(ArenaAllocator *const allocator, + AstNode *const parent) { - auto *const type_ref = type_reference_ != nullptr ? type_reference_->Clone(allocator)->AsTypeNode() : nullptr; - auto *const dimension = dimension_ != nullptr ? dimension_->Clone(allocator) : nullptr; + auto *const type_ref = type_reference_ != nullptr ? type_reference_->Clone(allocator) : nullptr; + auto *const dimension = dimension_ != nullptr ? dimension_->Clone(allocator)->AsExpression() : nullptr; if (auto *const clone = allocator->New(type_ref, dimension); clone != nullptr) { if (type_ref != nullptr) { diff --git a/ets2panda/ir/ets/etsNewArrayInstanceExpression.h b/ets2panda/ir/ets/etsNewArrayInstanceExpression.h index 553bb75120377bf84d5ead2276bf5323fbf855b6..3528a7646afdb6c149fa8db7dcc2d7d5ec1db143 100644 --- a/ets2panda/ir/ets/etsNewArrayInstanceExpression.h +++ b/ets2panda/ir/ets/etsNewArrayInstanceExpression.h @@ -35,8 +35,28 @@ public: { } + ir::TypeNode *TypeReference() + { + return type_reference_; + } + + ir::TypeNode const *TypeReference() const + { + return type_reference_; + } + + ir::Expression *Dimension() + { + return dimension_; + } + + ir::Expression const *Dimension() const + { + return dimension_; + } + // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] Expression *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + [[nodiscard]] ETSNewArrayInstanceExpression *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; diff --git a/ets2panda/ir/ets/etsNewClassInstanceExpression.cpp b/ets2panda/ir/ets/etsNewClassInstanceExpression.cpp index 0e55a8ac981c704ab2e0c4719cf31b7094de37d2..f39597c1c670cd66b670a4125d64a644c651a9cc 100644 --- a/ets2panda/ir/ets/etsNewClassInstanceExpression.cpp +++ b/ets2panda/ir/ets/etsNewClassInstanceExpression.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 - 2023 Huawei Device Co., Ltd. + * Copyright (c) 2021-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 @@ -164,6 +164,8 @@ checker::Type *ETSNewClassInstanceExpression::Check([[maybe_unused]] checker::ET auto *signature = checker->ResolveConstructExpression(callee_obj, arguments_, Start()); checker->CheckObjectLiteralArguments(signature, arguments_); + checker->AddUndefinedParamsForDefaultParams(signature, arguments_, checker); + checker->ValidateSignatureAccessibility(callee_obj, signature, Start()); ASSERT(signature->Function() != nullptr); @@ -184,4 +186,30 @@ checker::Type *ETSNewClassInstanceExpression::Check([[maybe_unused]] checker::ET return TsType(); } + +ETSNewClassInstanceExpression::ETSNewClassInstanceExpression(ETSNewClassInstanceExpression const &other, + ArenaAllocator *const allocator) + : Expression(static_cast(other)), arguments_(allocator->Adapter()), signature_(other.signature_) +{ + type_reference_ = other.type_reference_->Clone(allocator, this)->AsExpression(); + class_def_ = other.class_def_->Clone(allocator, this)->AsClassDefinition(); + + for (auto *const argument : other.arguments_) { + arguments_.emplace_back(argument->Clone(allocator, this)->AsExpression()); + } +} + +// NOLINTNEXTLINE(google-default-arguments) +ETSNewClassInstanceExpression *ETSNewClassInstanceExpression::Clone(ArenaAllocator *const allocator, + AstNode *const parent) +{ + if (auto *const clone = allocator->New(*this, allocator); clone != nullptr) { + if (parent != nullptr) { + clone->SetParent(parent); + } + return clone; + } + + throw Error(ErrorType::GENERIC, "", CLONE_ALLOCATION_ERROR); +} } // namespace panda::es2panda::ir diff --git a/ets2panda/ir/ets/etsNewClassInstanceExpression.h b/ets2panda/ir/ets/etsNewClassInstanceExpression.h index ffed6e65cdd9747a1bde4c1841d2ce62757f987f..25cd7607ff939b0d2b1de559525514646d09be1c 100644 --- a/ets2panda/ir/ets/etsNewClassInstanceExpression.h +++ b/ets2panda/ir/ets/etsNewClassInstanceExpression.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 - 2023 Huawei Device Co., Ltd. + * Copyright (c) 2021-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 @@ -29,8 +29,15 @@ class ClassDefinition; class ETSNewClassInstanceExpression : public Expression { public: - explicit ETSNewClassInstanceExpression(ir::Expression *type_reference, ArenaVector &&arguments, - ir::ClassDefinition *class_definition) + ETSNewClassInstanceExpression() = delete; + ~ETSNewClassInstanceExpression() override = default; + + NO_COPY_SEMANTIC(ETSNewClassInstanceExpression); + NO_MOVE_SEMANTIC(ETSNewClassInstanceExpression); + + explicit ETSNewClassInstanceExpression(ir::Expression *const type_reference, + ArenaVector &&arguments, + ir::ClassDefinition *const class_definition) : Expression(AstNodeType::ETS_NEW_CLASS_INSTANCE_EXPRESSION), type_reference_(type_reference), arguments_(std::move(arguments)), @@ -38,22 +45,24 @@ public: { } - ir::ClassDefinition *ClassDefinition() + explicit ETSNewClassInstanceExpression(ETSNewClassInstanceExpression const &other, ArenaAllocator *allocator); + + [[nodiscard]] ir::ClassDefinition *ClassDefinition() noexcept { return class_def_; } - const ir::ClassDefinition *ClassDefinition() const + [[nodiscard]] const ir::ClassDefinition *ClassDefinition() const noexcept { return class_def_; } - ir::Expression *GetTypeRef() const + [[nodiscard]] ir::Expression *GetTypeRef() const noexcept { return type_reference_; } - ArenaVector GetArguments() const + [[nodiscard]] ArenaVector GetArguments() const noexcept { return arguments_; } @@ -67,9 +76,14 @@ public: ir::Expression *name, checker::Signature *signature, const ArenaVector &arguments); + // NOLINTNEXTLINE(google-default-arguments) + [[nodiscard]] ETSNewClassInstanceExpression *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; + void Dump(ir::AstDumper *dumper) const override; + void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; void Compile([[maybe_unused]] compiler::ETSGen *etsg) const override; checker::Type *Check([[maybe_unused]] checker::TSChecker *checker) override; diff --git a/ets2panda/ir/ets/etsNewMultiDimArrayInstanceExpression.cpp b/ets2panda/ir/ets/etsNewMultiDimArrayInstanceExpression.cpp index 3671c96b28d60c2b1e9c1f9b1465aea951eb4738..73a9fafa1f10cac753fe217a3b28092a44d9a4c7 100644 --- a/ets2panda/ir/ets/etsNewMultiDimArrayInstanceExpression.cpp +++ b/ets2panda/ir/ets/etsNewMultiDimArrayInstanceExpression.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 - 2023 Huawei Device Co., Ltd. + * Copyright (c) 2021-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 @@ -71,4 +71,31 @@ checker::Type *ETSNewMultiDimArrayInstanceExpression::Check([[maybe_unused]] che signature_ = checker->CreateBuiltinArraySignature(element_type->AsETSArrayType(), dimensions_.size()); return TsType(); } + +ETSNewMultiDimArrayInstanceExpression::ETSNewMultiDimArrayInstanceExpression( + ETSNewMultiDimArrayInstanceExpression const &other, ArenaAllocator *const allocator) + : Expression(static_cast(other)), + dimensions_(allocator->Adapter()), + signature_(other.signature_) +{ + type_reference_ = other.type_reference_->Clone(allocator, this); + + for (auto *const dimension : other.dimensions_) { + dimensions_.emplace_back(dimension->Clone(allocator, this)->AsExpression()); + } +} + +// NOLINTNEXTLINE(google-default-arguments) +ETSNewMultiDimArrayInstanceExpression *ETSNewMultiDimArrayInstanceExpression::Clone(ArenaAllocator *const allocator, + AstNode *const parent) +{ + if (auto *const clone = allocator->New(*this, allocator); clone != nullptr) { + if (parent != nullptr) { + clone->SetParent(parent); + } + return clone; + } + + throw Error(ErrorType::GENERIC, "", CLONE_ALLOCATION_ERROR); +} } // namespace panda::es2panda::ir diff --git a/ets2panda/ir/ets/etsNewMultiDimArrayInstanceExpression.h b/ets2panda/ir/ets/etsNewMultiDimArrayInstanceExpression.h index 1cf38efa643435cccf347872aed8957b3912a35d..d758b3427d4d8de283e1ad165380fc17c883c649 100644 --- a/ets2panda/ir/ets/etsNewMultiDimArrayInstanceExpression.h +++ b/ets2panda/ir/ets/etsNewMultiDimArrayInstanceExpression.h @@ -1,5 +1,5 @@ /** - * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * Copyright (c) 2021-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 @@ -26,7 +26,13 @@ namespace panda::es2panda::ir { class ETSNewMultiDimArrayInstanceExpression : public Expression { public: - explicit ETSNewMultiDimArrayInstanceExpression(ir::TypeNode *type_reference, + ETSNewMultiDimArrayInstanceExpression() = delete; + ~ETSNewMultiDimArrayInstanceExpression() override = default; + + NO_COPY_SEMANTIC(ETSNewMultiDimArrayInstanceExpression); + NO_MOVE_SEMANTIC(ETSNewMultiDimArrayInstanceExpression); + + explicit ETSNewMultiDimArrayInstanceExpression(ir::TypeNode *const type_reference, ArenaVector &&dimensions) : Expression(AstNodeType::ETS_NEW_MULTI_DIM_ARRAY_INSTANCE_EXPRESSION), type_reference_(type_reference), @@ -34,19 +40,48 @@ public: { } - checker::Signature *Signature() + explicit ETSNewMultiDimArrayInstanceExpression(ETSNewMultiDimArrayInstanceExpression const &other, + ArenaAllocator *allocator); + + ir::TypeNode *TypeReference() + { + return type_reference_; + } + + ir::TypeNode const *TypeReference() const + { + return type_reference_; + } + + ArenaVector &Dimensions() + { + return dimensions_; + } + + ArenaVector const &Dimension() const + { + return dimensions_; + } + + [[nodiscard]] checker::Signature *Signature() noexcept { return signature_; } - const checker::Signature *Signature() const + [[nodiscard]] const checker::Signature *Signature() const noexcept { return signature_; } + // NOLINTNEXTLINE(google-default-arguments) + [[nodiscard]] ETSNewMultiDimArrayInstanceExpression *Clone(ArenaAllocator *allocator, + AstNode *parent = nullptr) override; + void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; + void Dump(ir::AstDumper *dumper) const override; + void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; void Compile([[maybe_unused]] compiler::ETSGen *etsg) const override; checker::Type *Check([[maybe_unused]] checker::TSChecker *checker) override; diff --git a/ets2panda/ir/ets/etsPackageDeclaration.cpp b/ets2panda/ir/ets/etsPackageDeclaration.cpp index b31ed8e71ba451b99890227ca2d99567b4091c56..d78bc70007436b6924d85215c7adc11893d39c97 100644 --- a/ets2panda/ir/ets/etsPackageDeclaration.cpp +++ b/ets2panda/ir/ets/etsPackageDeclaration.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 - 2023 Huawei Device Co., Ltd. + * Copyright (c) 2021-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 @@ -50,4 +50,21 @@ checker::Type *ETSPackageDeclaration::Check([[maybe_unused]] checker::ETSChecker { return nullptr; } + +// NOLINTNEXTLINE(google-default-arguments) +ETSPackageDeclaration *ETSPackageDeclaration::Clone(ArenaAllocator *const allocator, AstNode *const parent) +{ + auto const name = name_ != nullptr ? name_->Clone(allocator, this)->AsExpression() : nullptr; + if (auto *const clone = allocator->New(name); clone != nullptr) { + if (name != nullptr) { + name->SetParent(clone); + } + if (parent != nullptr) { + clone->SetParent(parent); + } + return clone; + } + + throw Error(ErrorType::GENERIC, "", CLONE_ALLOCATION_ERROR); +} } // namespace panda::es2panda::ir diff --git a/ets2panda/ir/ets/etsPackageDeclaration.h b/ets2panda/ir/ets/etsPackageDeclaration.h index 8ca20442d3d93240c979767e8aae6325cd873180..50249d8c681dcf6dad4c8d05bda130833c8b1a85 100644 --- a/ets2panda/ir/ets/etsPackageDeclaration.h +++ b/ets2panda/ir/ets/etsPackageDeclaration.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 - 2023 Huawei Device Co., Ltd. + * Copyright (c) 2021-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 @@ -22,13 +22,25 @@ namespace panda::es2panda::ir { class ETSPackageDeclaration : public Statement { public: - explicit ETSPackageDeclaration(ir::Expression *name) : Statement(AstNodeType::ETS_PACKAGE_DECLARATION), name_(name) + ETSPackageDeclaration() = delete; + ~ETSPackageDeclaration() override = default; + + NO_COPY_SEMANTIC(ETSPackageDeclaration); + NO_MOVE_SEMANTIC(ETSPackageDeclaration); + + explicit ETSPackageDeclaration(ir::Expression *const name) + : Statement(AstNodeType::ETS_PACKAGE_DECLARATION), name_(name) { } + // NOLINTNEXTLINE(google-default-arguments) + [[nodiscard]] ETSPackageDeclaration *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; + void Dump(ir::AstDumper *dumper) const override; + void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; void Compile([[maybe_unused]] compiler::ETSGen *etsg) const override; checker::Type *Check([[maybe_unused]] checker::TSChecker *checker) override; diff --git a/ets2panda/ir/ets/etsParameterExpression.cpp b/ets2panda/ir/ets/etsParameterExpression.cpp index bb0172b423fb8709b45b962774c37a9c49063fb6..6065a8a5cea82dab8d4fe67c7e2991ec623d709b 100644 --- a/ets2panda/ir/ets/etsParameterExpression.cpp +++ b/ets2panda/ir/ets/etsParameterExpression.cpp @@ -39,6 +39,7 @@ ETSParameterExpression::ETSParameterExpression(AnnotatedExpression *const ident_ spread_ = ident_or_spread->AsRestElement(); ASSERT(spread_->Argument()->IsIdentifier()); ident_ = spread_->Argument()->AsIdentifier(); + ident_->SetParent(spread_); initializer_ = nullptr; // Just in case! } else { UNREACHABLE(); @@ -163,20 +164,24 @@ checker::Type *ETSParameterExpression::Check(checker::ETSChecker *const checker) } // NOLINTNEXTLINE(google-default-arguments) -Expression *ETSParameterExpression::Clone(ArenaAllocator *const allocator, AstNode *const parent) +ETSParameterExpression *ETSParameterExpression::Clone(ArenaAllocator *const allocator, AstNode *const parent) { auto *const ident_or_spread = spread_ != nullptr ? spread_->Clone(allocator)->AsAnnotatedExpression() : ident_->Clone(allocator)->AsAnnotatedExpression(); - auto *const initializer = initializer_ != nullptr ? initializer_->Clone(allocator) : nullptr; + auto *const initializer = initializer_ != nullptr ? initializer_->Clone(allocator)->AsExpression() : nullptr; if (auto *const clone = allocator->New(ident_or_spread, initializer); clone != nullptr) { ident_or_spread->SetParent(clone); + if (initializer != nullptr) { initializer->SetParent(clone); } + if (parent != nullptr) { clone->SetParent(parent); } + + clone->SetRequiredParams(extra_value_); return clone; } diff --git a/ets2panda/ir/ets/etsParameterExpression.h b/ets2panda/ir/ets/etsParameterExpression.h index 4ea4ed1e32ad11db3db905048e24868de9c89732..64af2b177868a115c2d00efe1a7b2781e18888eb 100644 --- a/ets2panda/ir/ets/etsParameterExpression.h +++ b/ets2panda/ir/ets/etsParameterExpression.h @@ -23,6 +23,10 @@ class ETSAnalyzer; } // namespace panda::es2panda::checker namespace panda::es2panda::ir { +// NOLINTBEGIN(modernize-avoid-c-arrays) +inline constexpr char const PROXY_PARAMETER_NAME[] = "$proxy_mask$"; +// NOLINTEND(modernize-avoid-c-arrays) + class ETSParameterExpression final : public Expression { public: ETSParameterExpression() = delete; @@ -64,8 +68,18 @@ public: return spread_ != nullptr; } + [[nodiscard]] std::size_t GetRequiredParams() const noexcept + { + return extra_value_; + } + + void SetRequiredParams(std::size_t const value) noexcept + { + extra_value_ = value; + } + // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] Expression *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + [[nodiscard]] ETSParameterExpression *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; void Iterate(const NodeTraverser &cb) const override; void TransformChildren(const NodeTransformer &cb) override; @@ -80,6 +94,7 @@ private: Expression *initializer_; SpreadElement *spread_ = nullptr; util::StringView saved_lexer_ = ""; + std::size_t extra_value_ = 0U; }; } // namespace panda::es2panda::ir diff --git a/ets2panda/ir/ets/etsStructDeclaration.cpp b/ets2panda/ir/ets/etsStructDeclaration.cpp index 8bd7ed765a9957726b5a8c9f231372d41af095e9..14f7101ad09c6d056deac938079fd3ada3aa2508 100644 --- a/ets2panda/ir/ets/etsStructDeclaration.cpp +++ b/ets2panda/ir/ets/etsStructDeclaration.cpp @@ -68,4 +68,27 @@ checker::Type *ETSStructDeclaration::Check(checker::ETSChecker *checker) { return checker->GetAnalyzer()->Check(this); } + +// NOLINTNEXTLINE(google-default-arguments) +ETSStructDeclaration *ETSStructDeclaration::Clone(ArenaAllocator *const allocator, AstNode *const parent) +{ + auto *const def = def_ != nullptr ? def_->Clone(allocator, this)->AsClassDefinition() : nullptr; + + if (auto *const clone = allocator->New(def, allocator); clone != nullptr) { + for (auto *const decorator : decorators_) { + clone->AddDecorator(decorator->Clone(allocator, clone)); + } + + if (def != nullptr) { + def->SetParent(clone); + } + + if (parent != nullptr) { + clone->SetParent(parent); + } + return clone; + } + + throw Error(ErrorType::GENERIC, "", CLONE_ALLOCATION_ERROR); +} } // namespace panda::es2panda::ir diff --git a/ets2panda/ir/ets/etsStructDeclaration.h b/ets2panda/ir/ets/etsStructDeclaration.h index 90a448f581dfdf1ad83d074484be39a8ffb47acb..5824d5a4c7e3ccf0f5f4bf3bac0e979fd9f7c37a 100644 --- a/ets2panda/ir/ets/etsStructDeclaration.h +++ b/ets2panda/ir/ets/etsStructDeclaration.h @@ -21,39 +21,60 @@ namespace panda::es2panda::ir { class ETSStructDeclaration : public Statement { public: - explicit ETSStructDeclaration(ClassDefinition *def, ArenaAllocator *allocator) + ETSStructDeclaration() = delete; + ~ETSStructDeclaration() override = default; + + NO_COPY_SEMANTIC(ETSStructDeclaration); + NO_MOVE_SEMANTIC(ETSStructDeclaration); + + explicit ETSStructDeclaration(ClassDefinition *const def, ArenaAllocator *const allocator) : Statement(AstNodeType::STRUCT_DECLARATION), def_(def), decorators_(allocator->Adapter()) { } - ClassDefinition *Definition() + [[nodiscard]] ClassDefinition *Definition() noexcept { return def_; } - const ClassDefinition *Definition() const + [[nodiscard]] const ClassDefinition *Definition() const noexcept { return def_; } - const ArenaVector &Decorators() const + [[nodiscard]] const ArenaVector &Decorators() const noexcept { return decorators_; } + const ArenaVector *DecoratorsPtr() const override + { + return &Decorators(); + } + void AddDecorators(ArenaVector &&decorators) override { decorators_ = std::move(decorators); } + void AddDecorator(Decorator *const decorator) + { + decorators_.emplace_back(decorator); + } + bool CanHaveDecorator([[maybe_unused]] bool in_ts) const override { return true; } + // NOLINTNEXTLINE(google-default-arguments) + [[nodiscard]] ETSStructDeclaration *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; + void Dump(ir::AstDumper *dumper) const override; + void Compile(compiler::PandaGen *pg) const override; void Compile(compiler::ETSGen *etsg) const override; diff --git a/ets2panda/ir/ets/etsTypeReferencePart.cpp b/ets2panda/ir/ets/etsTypeReferencePart.cpp index ca7207a6f0227fe0102187d16dcc86d02a07d258..add1f500347c2dbfbe2ecd874f1a9de2ea0dfc1f 100644 --- a/ets2panda/ir/ets/etsTypeReferencePart.cpp +++ b/ets2panda/ir/ets/etsTypeReferencePart.cpp @@ -81,6 +81,7 @@ checker::Type *ETSTypeReferencePart::GetType(checker::ETSChecker *checker) if (prev_ == nullptr) { checker::Type *base_type = checker->GetReferencedTypeBase(name_); + ASSERT(base_type != nullptr); if (base_type->IsETSObjectType()) { checker::InstantiationContext ctx(checker, base_type->AsETSObjectType(), type_params_, Start()); return ctx.Result(); diff --git a/ets2panda/ir/expression.cpp b/ets2panda/ir/expression.cpp index 6d117c469e9c17a316e203beb5ab5dbcd4c70df4..88100c8f316f6716a505558fbc770d8e6e5cc64e 100644 --- a/ets2panda/ir/expression.cpp +++ b/ets2panda/ir/expression.cpp @@ -18,9 +18,10 @@ namespace panda::es2panda::ir { -void AnnotatedExpression::CloneTypeAnnotation(ArenaAllocator *const allocator) +AnnotatedExpression::AnnotatedExpression(AnnotatedExpression const &other, ArenaAllocator *const allocator) + : Annotated(static_cast const &>(other)) { - if (auto *annotation = const_cast(TypeAnnotation()); annotation != nullptr) { + if (auto *const annotation = other.TypeAnnotation(); annotation != nullptr) { SetTsTypeAnnotation(annotation->Clone(allocator, this)->AsTypeNode()); } } diff --git a/ets2panda/ir/expression.h b/ets2panda/ir/expression.h index 833fa1589022a98d75abb71694b7a8f4066b86fe..e42d12c5a5fabd6756c1206dfce606589cdffb3b 100644 --- a/ets2panda/ir/expression.h +++ b/ets2panda/ir/expression.h @@ -97,14 +97,6 @@ public: return reinterpret_cast(this); } - // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] virtual Expression *Clone([[maybe_unused]] ArenaAllocator *const allocator, - [[maybe_unused]] AstNode *const parent = nullptr) - { - UNREACHABLE(); - return nullptr; - } - protected: explicit Expression(AstNodeType const type) : TypedAstNode(type) {} explicit Expression(AstNodeType const type, ModifierFlags const flags) : TypedAstNode(type, flags) {} @@ -123,7 +115,7 @@ public: AnnotatedExpression() = delete; ~AnnotatedExpression() override = default; - NO_COPY_OPERATOR(AnnotatedExpression); + NO_COPY_SEMANTIC(AnnotatedExpression); NO_MOVE_SEMANTIC(AnnotatedExpression); [[nodiscard]] bool IsAnnotatedExpression() const noexcept override @@ -138,12 +130,7 @@ protected: } explicit AnnotatedExpression(AstNodeType const type) : Annotated(type) {} - AnnotatedExpression(AnnotatedExpression const &other) - : Annotated(static_cast const &>(other)) - { - } - - void CloneTypeAnnotation(ArenaAllocator *allocator); + explicit AnnotatedExpression(AnnotatedExpression const &other, ArenaAllocator *allocator); }; class MaybeOptionalExpression : public Expression { diff --git a/ets2panda/ir/expressions/arrayExpression.cpp b/ets2panda/ir/expressions/arrayExpression.cpp index c3c36bef08d178a73a9bc23e6ce871535cb73f3e..a29a2de739e4ffe7f6e56282530f24668e08c445 100644 --- a/ets2panda/ir/expressions/arrayExpression.cpp +++ b/ets2panda/ir/expressions/arrayExpression.cpp @@ -34,28 +34,26 @@ namespace panda::es2panda::ir { ArrayExpression::ArrayExpression([[maybe_unused]] Tag const tag, ArrayExpression const &other, ArenaAllocator *const allocator) - : AnnotatedExpression(static_cast(other)), + : AnnotatedExpression(static_cast(other), allocator), decorators_(allocator->Adapter()), elements_(allocator->Adapter()) { - CloneTypeAnnotation(allocator); - preferred_type_ = other.preferred_type_; is_declaration_ = other.is_declaration_; trailing_comma_ = other.trailing_comma_; optional_ = other.optional_; for (auto *element : other.elements_) { - elements_.emplace_back(element->Clone(allocator, this)); + elements_.emplace_back(element->Clone(allocator, this)->AsExpression()); } for (auto *decorator : other.decorators_) { - decorators_.emplace_back(decorator->Clone(allocator, this)->AsDecorator()); + decorators_.emplace_back(decorator->Clone(allocator, this)); } } // NOLINTNEXTLINE(google-default-arguments) -Expression *ArrayExpression::Clone(ArenaAllocator *const allocator, AstNode *const parent) +ArrayExpression *ArrayExpression::Clone(ArenaAllocator *const allocator, AstNode *const parent) { if (auto *const clone = allocator->New(Tag {}, *this, allocator); clone != nullptr) { if (parent != nullptr) { diff --git a/ets2panda/ir/expressions/arrayExpression.h b/ets2panda/ir/expressions/arrayExpression.h index 5848b480b54f641968a51e5abaddad04fa2a09ed..85a3fedbf0adf3b29f5021ea492a9d19d9926d72 100644 --- a/ets2panda/ir/expressions/arrayExpression.h +++ b/ets2panda/ir/expressions/arrayExpression.h @@ -93,17 +93,26 @@ public: return decorators_; } + const ArenaVector *DecoratorsPtr() const override + { + return &Decorators(); + } + void AddDecorators([[maybe_unused]] ArenaVector &&decorators) override { decorators_ = std::move(decorators); } + bool CanHaveDecorator([[maybe_unused]] bool in_ts) const override + { + return true; + } + // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] Expression *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + [[nodiscard]] ArrayExpression *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; [[nodiscard]] bool ConvertibleToArrayPattern(); [[nodiscard]] ValidationInfo ValidateExpression(); - void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; void Dump(ir::AstDumper *dumper) const override; diff --git a/ets2panda/ir/expressions/arrowFunctionExpression.cpp b/ets2panda/ir/expressions/arrowFunctionExpression.cpp index 0cb1b3b65fda36d2382bd984c471d1ff3110e718..c07a110c37a3952c267fa4028396b2a7cf2ff257 100644 --- a/ets2panda/ir/expressions/arrowFunctionExpression.cpp +++ b/ets2panda/ir/expressions/arrowFunctionExpression.cpp @@ -1,5 +1,5 @@ /** - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021 - 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 @@ -61,4 +61,33 @@ checker::Type *ArrowFunctionExpression::Check(checker::ETSChecker *checker) { return checker->GetAnalyzer()->Check(this); } + +ArrowFunctionExpression::ArrowFunctionExpression(ArrowFunctionExpression const &other, ArenaAllocator *const allocator) + : Expression(static_cast(other)), + captured_vars_(allocator->Adapter()), + propagate_this_(other.propagate_this_) +{ + func_ = other.func_->Clone(allocator, this)->AsScriptFunction(); + + for (auto *const variable : other.captured_vars_) { + captured_vars_.emplace_back(variable); + } + + if (other.resolved_lambda_ != nullptr) { + resolved_lambda_ = other.resolved_lambda_->Clone(allocator, this)->AsClassDefinition(); + } +} + +// NOLINTNEXTLINE(google-default-arguments) +ArrowFunctionExpression *ArrowFunctionExpression::Clone(ArenaAllocator *const allocator, AstNode *const parent) +{ + if (auto *const clone = allocator->New(*this, allocator); clone != nullptr) { + if (parent != nullptr) { + clone->SetParent(parent); + } + return clone; + } + + throw Error(ErrorType::GENERIC, "", CLONE_ALLOCATION_ERROR); +} } // namespace panda::es2panda::ir diff --git a/ets2panda/ir/expressions/arrowFunctionExpression.h b/ets2panda/ir/expressions/arrowFunctionExpression.h index 2d78a104125f5e3f2f1d7ff3e10f53e32ae864f9..0cc830afadcb529bd436b6ec84c39eb381f6bd05 100644 --- a/ets2panda/ir/expressions/arrowFunctionExpression.h +++ b/ets2panda/ir/expressions/arrowFunctionExpression.h @@ -1,5 +1,5 @@ /** - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021 - 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 @@ -27,53 +27,65 @@ class ScriptFunction; class ArrowFunctionExpression : public Expression { public: - explicit ArrowFunctionExpression(ArenaAllocator *allocator, ScriptFunction *func) + ArrowFunctionExpression() = delete; + ~ArrowFunctionExpression() override = default; + + NO_COPY_SEMANTIC(ArrowFunctionExpression); + NO_MOVE_SEMANTIC(ArrowFunctionExpression); + + explicit ArrowFunctionExpression(ArenaAllocator *const allocator, ScriptFunction *const func) : Expression(AstNodeType::ARROW_FUNCTION_EXPRESSION), func_(func), captured_vars_(allocator->Adapter()) { } + + explicit ArrowFunctionExpression(ArrowFunctionExpression const &other, ArenaAllocator *allocator); + // NOTE (csabahurton): friend relationship can be removed once there are getters for private fields friend class compiler::ETSCompiler; - const ScriptFunction *Function() const + [[nodiscard]] const ScriptFunction *Function() const noexcept { return func_; } - ScriptFunction *Function() + [[nodiscard]] ScriptFunction *Function() noexcept { return func_; } - const ClassDefinition *ResolvedLambda() const + [[nodiscard]] const ClassDefinition *ResolvedLambda() const noexcept { return resolved_lambda_; } - ClassDefinition *ResolvedLambda() + [[nodiscard]] ClassDefinition *ResolvedLambda() noexcept { return resolved_lambda_; } - ArenaVector &CapturedVars() + [[nodiscard]] ArenaVector &CapturedVars() noexcept { return captured_vars_; } - const ArenaVector &CapturedVars() const + [[nodiscard]] const ArenaVector &CapturedVars() const noexcept { return captured_vars_; } - void SetResolvedLambda(ClassDefinition *lambda) + void SetResolvedLambda(ClassDefinition *const lambda) noexcept { resolved_lambda_ = lambda; } - void SetPropagateThis() + void SetPropagateThis() noexcept { propagate_this_ = true; } + // NOLINTNEXTLINE(google-default-arguments) + [[nodiscard]] ArrowFunctionExpression *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; void Dump(ir::AstDumper *dumper) const override; diff --git a/ets2panda/ir/expressions/assignmentExpression.cpp b/ets2panda/ir/expressions/assignmentExpression.cpp index a6ba7d6ee0528ee4b948d9be668fe3a275f21027..4c3d14510fcfa13de7075c78b778596fc9d5fa17 100644 --- a/ets2panda/ir/expressions/assignmentExpression.cpp +++ b/ets2panda/ir/expressions/assignmentExpression.cpp @@ -322,10 +322,10 @@ AssignmentExpression::AssignmentExpression([[maybe_unused]] Tag const tag, Assig } // NOLINTNEXTLINE(google-default-arguments) -Expression *AssignmentExpression::Clone(ArenaAllocator *const allocator, AstNode *const parent) +AssignmentExpression *AssignmentExpression::Clone(ArenaAllocator *const allocator, AstNode *const parent) { - auto *const left = left_ != nullptr ? left_->Clone(allocator) : nullptr; - auto *const right = right_ != nullptr ? right_->Clone(allocator) : nullptr; + auto *const left = left_ != nullptr ? left_->Clone(allocator)->AsExpression() : nullptr; + auto *const right = right_ != nullptr ? right_->Clone(allocator)->AsExpression() : nullptr; if (auto *const clone = allocator->New(Tag {}, *this, left, right); clone != nullptr) { if (parent != nullptr) { diff --git a/ets2panda/ir/expressions/assignmentExpression.h b/ets2panda/ir/expressions/assignmentExpression.h index 5f14a1c1cff1321beae8fb22326bc89d9c25353a..dc1542c4b4322c808cea071419d5c3f0c4a03213 100644 --- a/ets2panda/ir/expressions/assignmentExpression.h +++ b/ets2panda/ir/expressions/assignmentExpression.h @@ -80,7 +80,7 @@ public: return operator_; } - [[nodiscard]] lexer::TokenType SetOperatorType(lexer::TokenType token_type) noexcept + lexer::TokenType SetOperatorType(lexer::TokenType token_type) noexcept { return operator_ = token_type; } @@ -108,7 +108,7 @@ public: } // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] Expression *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + [[nodiscard]] AssignmentExpression *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; [[nodiscard]] bool ConvertibleToAssignmentPattern(bool must_be_pattern = true); diff --git a/ets2panda/ir/expressions/awaitExpression.cpp b/ets2panda/ir/expressions/awaitExpression.cpp index 636a7e5bc25ab705db10bbefabee403e2d0fc139..f0fac3d9b4137445cdb5c17883b24b020d4cd30c 100644 --- a/ets2panda/ir/expressions/awaitExpression.cpp +++ b/ets2panda/ir/expressions/awaitExpression.cpp @@ -15,15 +15,10 @@ #include "awaitExpression.h" +#include "checker/TSchecker.h" #include "compiler/core/pandagen.h" #include "compiler/core/ETSGen.h" -#include "compiler/core/regScope.h" -#include "checker/TSchecker.h" -#include "checker/ETSchecker.h" #include "ir/astDump.h" -#include "ir/base/methodDefinition.h" -#include "ir/base/scriptFunction.h" -#include "ir/expressions/arrowFunctionExpression.h" namespace panda::es2panda::ir { void AwaitExpression::TransformChildren(const NodeTransformer &cb) @@ -47,56 +42,28 @@ void AwaitExpression::Dump(ir::AstDumper *dumper) const void AwaitExpression::Compile(compiler::PandaGen *pg) const { - compiler::RegScope rs(pg); - - if (argument_ != nullptr) { - argument_->Compile(pg); - } else { - pg->LoadConst(this, compiler::Constant::JS_UNDEFINED); - } - - pg->EmitAwait(this); + pg->GetAstCompiler()->Compile(this); } void AwaitExpression::Compile(compiler::ETSGen *etsg) const { - static constexpr bool IS_UNCHECKED_CAST = false; - compiler::RegScope rs(etsg); - compiler::VReg argument_reg = etsg->AllocReg(); - argument_->Compile(etsg); - etsg->StoreAccumulator(this, argument_reg); - etsg->CallThisVirtual0(argument_, argument_reg, compiler::Signatures::BUILTIN_PROMISE_AWAIT_RESOLUTION); - etsg->CastToArrayOrObject(argument_, TsType(), IS_UNCHECKED_CAST); - etsg->SetAccumulatorType(TsType()); + etsg->GetAstCompiler()->Compile(this); } -checker::Type *AwaitExpression::Check([[maybe_unused]] checker::TSChecker *checker) +checker::Type *AwaitExpression::Check(checker::TSChecker *checker) { - // NOTE: aszilagyi - return checker->GlobalAnyType(); + return checker->GetAnalyzer()->Check(this); } checker::Type *AwaitExpression::Check(checker::ETSChecker *checker) { - if (TsType() != nullptr) { - return TsType(); - } - - checker::Type *arg_type = argument_->Check(checker); - // Check the argument type of await expression - if (!arg_type->IsETSObjectType() || - (arg_type->AsETSObjectType()->AssemblerName() != compiler::Signatures::BUILTIN_PROMISE)) { - checker->ThrowTypeError("'await' expressions require Promise object as argument.", argument_->Start()); - } - - SetTsType(arg_type->AsETSObjectType()->TypeArguments().at(0)); - return TsType(); + return checker->GetAnalyzer()->Check(this); } // NOLINTNEXTLINE(google-default-arguments) -Expression *AwaitExpression::Clone(ArenaAllocator *const allocator, AstNode *const parent) +AwaitExpression *AwaitExpression::Clone(ArenaAllocator *const allocator, AstNode *const parent) { - auto *const argument = argument_ != nullptr ? argument_->Clone(allocator) : nullptr; + auto *const argument = argument_ != nullptr ? argument_->Clone(allocator)->AsExpression() : nullptr; if (auto *const clone = allocator->New(argument); clone != nullptr) { if (argument != nullptr) { diff --git a/ets2panda/ir/expressions/awaitExpression.h b/ets2panda/ir/expressions/awaitExpression.h index 17240df98c3efcdf6ca7e22e01545aa4a293e8f9..cc1f3f9415bb4a5dec79f5b00ea7fa1eae6f0dc4 100644 --- a/ets2panda/ir/expressions/awaitExpression.h +++ b/ets2panda/ir/expressions/awaitExpression.h @@ -18,6 +18,10 @@ #include "ir/expression.h" +namespace panda::es2panda::checker { +class ETSAnalyzer; +} // namespace panda::es2panda::checker + namespace panda::es2panda::ir { class AwaitExpression : public Expression { public: @@ -29,13 +33,16 @@ public: explicit AwaitExpression(Expression *argument) : Expression(AstNodeType::AWAIT_EXPRESSION), argument_(argument) {} + // NOTE (csabahurton): friend relationship can be removed once there are getters for private fields + friend class checker::ETSAnalyzer; + [[nodiscard]] const Expression *Argument() const noexcept { return argument_; } // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] Expression *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + [[nodiscard]] AwaitExpression *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; @@ -43,7 +50,7 @@ public: void Compile(compiler::PandaGen *pg) const override; void Compile(compiler::ETSGen *etsg) const override; checker::Type *Check(checker::TSChecker *checker) override; - checker::Type *Check([[maybe_unused]] checker::ETSChecker *checker) override; + checker::Type *Check(checker::ETSChecker *checker) override; private: Expression *argument_; diff --git a/ets2panda/ir/expressions/binaryExpression.cpp b/ets2panda/ir/expressions/binaryExpression.cpp index 440afa17f2d760db3d417e9bc88304214c0a7f85..4da4ae6df90367cfee6b8b20a34fbc287ffe06bf 100644 --- a/ets2panda/ir/expressions/binaryExpression.cpp +++ b/ets2panda/ir/expressions/binaryExpression.cpp @@ -15,14 +15,9 @@ #include "binaryExpression.h" -#include "varbinder/variable.h" -#include "compiler/core/function.h" #include "compiler/core/pandagen.h" #include "compiler/core/ETSGen.h" -#include "compiler/core/regScope.h" #include "checker/TSchecker.h" -#include "ir/astDump.h" -#include "ir/expressions/identifier.h" namespace panda::es2panda::ir { void BinaryExpression::TransformChildren(const NodeTransformer &cb) @@ -45,261 +40,31 @@ void BinaryExpression::Dump(ir::AstDumper *dumper) const {"right", right_}}); } -void BinaryExpression::CompileLogical(compiler::PandaGen *pg) const -{ - compiler::RegScope rs(pg); - compiler::VReg lhs = pg->AllocReg(); - - ASSERT(operator_ == lexer::TokenType::PUNCTUATOR_LOGICAL_AND || - operator_ == lexer::TokenType::PUNCTUATOR_LOGICAL_OR || - operator_ == lexer::TokenType::PUNCTUATOR_NULLISH_COALESCING); - - auto *skip_right = pg->AllocLabel(); - auto *end_label = pg->AllocLabel(); - - // left -> acc -> lhs -> toboolean -> acc -> bool_lhs - left_->Compile(pg); - pg->StoreAccumulator(this, lhs); - - if (operator_ == lexer::TokenType::PUNCTUATOR_LOGICAL_AND) { - pg->ToBoolean(this); - pg->BranchIfFalse(this, skip_right); - } else if (operator_ == lexer::TokenType::PUNCTUATOR_LOGICAL_OR) { - pg->ToBoolean(this); - pg->BranchIfTrue(this, skip_right); - } else if (operator_ == lexer::TokenType::PUNCTUATOR_NULLISH_COALESCING) { - pg->BranchIfCoercible(this, skip_right); - } - - // left is true/false(and/or) then right -> acc - right_->Compile(pg); - pg->Branch(this, end_label); - - // left is false/true(and/or) then lhs -> acc - pg->SetLabel(this, skip_right); - pg->LoadAccumulator(this, lhs); - pg->SetLabel(this, end_label); -} - void BinaryExpression::Compile(compiler::PandaGen *pg) const { - if (IsLogical()) { - CompileLogical(pg); - return; - } - - if (operator_ == lexer::TokenType::KEYW_IN && left_->IsIdentifier() && left_->AsIdentifier()->IsPrivateIdent()) { - compiler::RegScope rs(pg); - compiler::VReg ctor = pg->AllocReg(); - const auto &name = left_->AsIdentifier()->Name(); - compiler::Function::LoadClassContexts(this, pg, ctor, name); - right_->Compile(pg); - pg->ClassPrivateFieldIn(this, ctor, name); - return; - } - - compiler::RegScope rs(pg); - compiler::VReg lhs = pg->AllocReg(); - - left_->Compile(pg); - pg->StoreAccumulator(this, lhs); - right_->Compile(pg); - - pg->Binary(this, operator_, lhs); + pg->GetAstCompiler()->Compile(this); } void BinaryExpression::Compile(compiler::ETSGen *etsg) const { - if (etsg->TryLoadConstantExpression(this)) { - return; - } - - auto ttctx = compiler::TargetTypeContext(etsg, operation_type_); - - if (IsLogical()) { - CompileLogical(etsg); - etsg->ApplyConversion(this, operation_type_); - return; - } - - compiler::RegScope rs(etsg); - compiler::VReg lhs = etsg->AllocReg(); - - if (operator_ == lexer::TokenType::PUNCTUATOR_PLUS && - (left_->TsType()->IsETSStringType() || right_->TsType()->IsETSStringType())) { - etsg->BuildString(this); - return; - } - - left_->Compile(etsg); - etsg->ApplyConversionAndStoreAccumulator(left_, lhs, operation_type_); - right_->Compile(etsg); - etsg->ApplyConversion(right_, operation_type_); - if (operator_ >= lexer::TokenType::PUNCTUATOR_LEFT_SHIFT && - operator_ <= lexer::TokenType::PUNCTUATOR_UNSIGNED_RIGHT_SHIFT) { - etsg->ApplyCast(right_, operation_type_); - } - - etsg->Binary(this, operator_, lhs); -} - -static void CompileNullishCoalescing(BinaryExpression const *const node, compiler::ETSGen *etsg) -{ - auto const compile_operand = [etsg, optype = node->OperationType()](ir::Expression const *expr) { - etsg->CompileAndCheck(expr); - etsg->ApplyConversion(expr, optype); - }; - - compile_operand(node->Left()); - - if (!node->Left()->TsType()->IsNullishOrNullLike()) { - // fallthrough - } else if (node->Left()->TsType()->IsETSNullLike()) { - compile_operand(node->Right()); - } else { - auto *if_left_nullish = etsg->AllocLabel(); - auto *end_label = etsg->AllocLabel(); - - etsg->BranchIfNullish(node, if_left_nullish); - - etsg->ConvertToNonNullish(node); - etsg->ApplyConversion(node->Left(), node->OperationType()); - etsg->JumpTo(node, end_label); - - etsg->SetLabel(node, if_left_nullish); - compile_operand(node->Right()); - - etsg->SetLabel(node, end_label); - } - etsg->SetAccumulatorType(node->TsType()); -} - -void BinaryExpression::CompileLogical(compiler::ETSGen *etsg) const -{ - if (operator_ == lexer::TokenType::PUNCTUATOR_NULLISH_COALESCING) { - CompileNullishCoalescing(this, etsg); - return; - } - - ASSERT(IsLogicalExtended()); - auto ttctx = compiler::TargetTypeContext(etsg, OperationType()); - compiler::RegScope rs(etsg); - auto lhs = etsg->AllocReg(); - auto rhs = etsg->AllocReg(); - left_->Compile(etsg); - etsg->ApplyConversionAndStoreAccumulator(left_, lhs, OperationType()); - - auto *end_label = etsg->AllocLabel(); - - auto left_false_label = etsg->AllocLabel(); - if (operator_ == lexer::TokenType::PUNCTUATOR_LOGICAL_AND) { - etsg->ResolveConditionalResultIfFalse(left_, left_false_label); - etsg->BranchIfFalse(this, left_false_label); - - right_->Compile(etsg); - etsg->ApplyConversionAndStoreAccumulator(right_, rhs, OperationType()); - etsg->Branch(this, end_label); - - etsg->SetLabel(this, left_false_label); - etsg->LoadAccumulator(this, lhs); - } else { - etsg->ResolveConditionalResultIfFalse(left_, left_false_label); - etsg->BranchIfFalse(this, left_false_label); - - etsg->LoadAccumulator(this, lhs); - etsg->Branch(this, end_label); - - etsg->SetLabel(this, left_false_label); - right_->Compile(etsg); - etsg->ApplyConversionAndStoreAccumulator(right_, rhs, OperationType()); - } - - etsg->SetLabel(this, end_label); - etsg->SetAccumulatorType(TsType()); + etsg->GetAstCompiler()->Compile(this); } checker::Type *BinaryExpression::Check(checker::TSChecker *checker) { - auto *left_type = left_->Check(checker); - auto *right_type = right_->Check(checker); - - switch (operator_) { - case lexer::TokenType::PUNCTUATOR_MULTIPLY: - case lexer::TokenType::PUNCTUATOR_EXPONENTIATION: - case lexer::TokenType::PUNCTUATOR_DIVIDE: - case lexer::TokenType::PUNCTUATOR_MOD: - case lexer::TokenType::PUNCTUATOR_MINUS: - case lexer::TokenType::PUNCTUATOR_LEFT_SHIFT: - case lexer::TokenType::PUNCTUATOR_RIGHT_SHIFT: - case lexer::TokenType::PUNCTUATOR_UNSIGNED_RIGHT_SHIFT: - case lexer::TokenType::PUNCTUATOR_BITWISE_AND: - case lexer::TokenType::PUNCTUATOR_BITWISE_XOR: - case lexer::TokenType::PUNCTUATOR_BITWISE_OR: { - return checker->CheckBinaryOperator(left_type, right_type, left_, right_, this, operator_); - } - case lexer::TokenType::PUNCTUATOR_PLUS: { - return checker->CheckPlusOperator(left_type, right_type, left_, right_, this, operator_); - } - case lexer::TokenType::PUNCTUATOR_LESS_THAN: - case lexer::TokenType::PUNCTUATOR_GREATER_THAN: { - return checker->CheckCompareOperator(left_type, right_type, left_, right_, this, operator_); - } - case lexer::TokenType::PUNCTUATOR_EQUAL: - case lexer::TokenType::PUNCTUATOR_NOT_EQUAL: - case lexer::TokenType::PUNCTUATOR_STRICT_EQUAL: - case lexer::TokenType::PUNCTUATOR_NOT_STRICT_EQUAL: { - if (checker->IsTypeEqualityComparableTo(left_type, right_type) || - checker->IsTypeEqualityComparableTo(right_type, left_type)) { - return checker->GlobalBooleanType(); - } - - checker->ThrowBinaryLikeError(operator_, left_type, right_type, Start()); - } - case lexer::TokenType::KEYW_INSTANCEOF: { - return checker->CheckInstanceofExpression(left_type, right_type, right_, this); - } - case lexer::TokenType::KEYW_IN: { - return checker->CheckInExpression(left_type, right_type, left_, right_, this); - } - case lexer::TokenType::PUNCTUATOR_LOGICAL_AND: { - return checker->CheckAndOperator(left_type, right_type, left_); - } - case lexer::TokenType::PUNCTUATOR_LOGICAL_OR: { - return checker->CheckOrOperator(left_type, right_type, left_); - } - case lexer::TokenType::PUNCTUATOR_NULLISH_COALESCING: { - // NOTE: Csaba Repasi. Implement checker for nullish coalescing - return checker->GlobalAnyType(); - } - case lexer::TokenType::PUNCTUATOR_SUBSTITUTION: { - checker->CheckAssignmentOperator(operator_, left_, left_type, right_type); - return right_type; - } - default: { - UNREACHABLE(); - break; - } - } - - return nullptr; + return checker->GetAnalyzer()->Check(this); } checker::Type *BinaryExpression::Check(checker::ETSChecker *checker) { - if (TsType() != nullptr) { - return TsType(); - } - checker::Type *new_ts_type {nullptr}; - std::tie(new_ts_type, operation_type_) = checker->CheckBinaryOperator(left_, right_, this, operator_, Start()); - SetTsType(new_ts_type); - return TsType(); + return checker->GetAnalyzer()->Check(this); } // NOLINTNEXTLINE(google-default-arguments) -Expression *BinaryExpression::Clone(ArenaAllocator *const allocator, AstNode *const parent) +BinaryExpression *BinaryExpression::Clone(ArenaAllocator *const allocator, AstNode *const parent) { - auto *const left = left_ != nullptr ? left_->Clone(allocator) : nullptr; - auto *const right = right_ != nullptr ? right_->Clone(allocator) : nullptr; + auto *const left = left_ != nullptr ? left_->Clone(allocator)->AsExpression() : nullptr; + auto *const right = right_ != nullptr ? right_->Clone(allocator)->AsExpression() : nullptr; if (auto *const clone = allocator->New(left, right, operator_); clone != nullptr) { if (operation_type_ != nullptr) { diff --git a/ets2panda/ir/expressions/binaryExpression.h b/ets2panda/ir/expressions/binaryExpression.h index c2a1a47bbbc2943a56b1b2822cfa2227ecd71963..69bdfa92f80f1e02c5bbc025e2a116dd4ad525af 100644 --- a/ets2panda/ir/expressions/binaryExpression.h +++ b/ets2panda/ir/expressions/binaryExpression.h @@ -19,6 +19,10 @@ #include "ir/expression.h" #include "lexer/token/tokenType.h" +namespace panda::es2panda::checker { +class ETSAnalyzer; +} // namespace panda::es2panda::checker + namespace panda::es2panda::ir { class BinaryExpression : public Expression { public: @@ -33,6 +37,9 @@ public: { } + // NOTE (csabahurton): friend relationship can be removed once there are getters for private fields + friend class checker::ETSAnalyzer; + [[nodiscard]] const Expression *Left() const noexcept { return left_; @@ -85,6 +92,12 @@ public: SetStart(left_->Start()); } + void SetRight(Expression *expr) noexcept + { + right_ = expr; + SetEnd(right_->End()); + } + void SetResult(Expression *expr) noexcept { left_ = expr; @@ -113,17 +126,15 @@ public: } // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] Expression *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + [[nodiscard]] BinaryExpression *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; void Dump(ir::AstDumper *dumper) const override; void Compile(compiler::PandaGen *pg) const override; void Compile(compiler::ETSGen *etsg) const override; - void CompileLogical(compiler::PandaGen *pg) const; - void CompileLogical(compiler::ETSGen *etsg) const; checker::Type *Check(checker::TSChecker *checker) override; - checker::Type *Check([[maybe_unused]] checker::ETSChecker *checker) override; + checker::Type *Check(checker::ETSChecker *checker) override; private: Expression *left_ = nullptr; diff --git a/ets2panda/ir/expressions/blockExpression.cpp b/ets2panda/ir/expressions/blockExpression.cpp new file mode 100644 index 0000000000000000000000000000000000000000..02e3ff477e246e528a8228340ac990ac50948f50 --- /dev/null +++ b/ets2panda/ir/expressions/blockExpression.cpp @@ -0,0 +1,101 @@ +/** + * 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 "blockExpression.h" + +#include "ir/astDump.h" +#include "compiler/core/ETSGen.h" +#include "checker/ETSchecker.h" +#include "ir/astNode.h" + +namespace panda::es2panda::ir { + +BlockExpression::BlockExpression(ArenaVector &&statements) + : Expression(AstNodeType::BLOCK_EXPRESSION), statements_(std::move(statements)) +{ + for (auto *const node : statements_) { + node->SetParent(this); + } +} + +BlockExpression::BlockExpression([[maybe_unused]] Tag const tag, BlockExpression const &other, + ArenaAllocator *const allocator) + : Expression(static_cast(other)), statements_(allocator->Adapter()) +{ + for (auto *const node : other.statements_) { + statements_.emplace_back(node->Clone(allocator, this)->AsStatement()); + } +} + +// NOLINTNEXTLINE(google-default-arguments) +BlockExpression *BlockExpression::Clone(ArenaAllocator *const allocator, AstNode *const parent) +{ + if (auto *const clone = allocator->New(Tag {}, *this, allocator); clone != nullptr) { + if (parent != nullptr) { + clone->SetParent(parent); + } + return clone; + } + throw Error(ErrorType::GENERIC, "", CLONE_ALLOCATION_ERROR); +} + +void BlockExpression::TransformChildren(const NodeTransformer &cb) +{ + for (auto *&node : statements_) { + node = cb(node)->AsStatement(); + } +} + +void BlockExpression::Iterate(const NodeTraverser &cb) const +{ + for (auto *const node : statements_) { + cb(node); + } +} + +void BlockExpression::Dump(ir::AstDumper *dumper) const +{ + dumper->Add({{"type", "BlockExpression"}, {"statements", statements_}}); +} + +void BlockExpression::Compile([[maybe_unused]] compiler::PandaGen *pg) const +{ + UNREACHABLE(); +} + +void BlockExpression::Compile(compiler::ETSGen *etsg) const +{ + for (auto const *const node : statements_) { + node->Compile(etsg); + } +} + +checker::Type *BlockExpression::Check([[maybe_unused]] checker::TSChecker *checker) +{ + UNREACHABLE(); +} + +checker::Type *BlockExpression::Check(checker::ETSChecker *checker) +{ + if (TsType() == nullptr) { + for (auto *const node : statements_) { + if (auto *const expr_type = node->Check(checker); expr_type != nullptr) { + SetTsType(expr_type); + } + } + } + return TsType(); +} +} // namespace panda::es2panda::ir diff --git a/ets2panda/ir/expressions/blockExpression.h b/ets2panda/ir/expressions/blockExpression.h new file mode 100644 index 0000000000000000000000000000000000000000..ef4f0b8b58dc9d0876ca3bc6bcba49a137dec549 --- /dev/null +++ b/ets2panda/ir/expressions/blockExpression.h @@ -0,0 +1,60 @@ +/** + * 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. + */ + +#ifndef ES2PANDA_IR_EXPRESSION_BLOCK_EXPRESSION_H +#define ES2PANDA_IR_EXPRESSION_BLOCK_EXPRESSION_H + +#include "ir/astNode.h" +#include "ir/expression.h" +#include "ir/statement.h" + +namespace panda::es2panda::ir { + +class BlockExpression : public Expression { +private: + struct Tag {}; + +public: + BlockExpression() = delete; + ~BlockExpression() override = default; + + NO_COPY_SEMANTIC(BlockExpression); + NO_MOVE_SEMANTIC(BlockExpression); + + explicit BlockExpression(ArenaVector &&statements); + explicit BlockExpression(Tag tag, BlockExpression const &other, ArenaAllocator *allocator); + + [[nodiscard]] ArenaVector const &Statements() const noexcept + { + return statements_; + } + + // NOLINTNEXTLINE(google-default-arguments) + [[nodiscard]] BlockExpression *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + + void TransformChildren(const NodeTransformer &cb) override; + void Iterate(const NodeTraverser &cb) const override; + void Dump(ir::AstDumper *dumper) const override; + void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; + void Compile([[maybe_unused]] compiler::ETSGen *etsg) const override; + checker::Type *Check([[maybe_unused]] checker::TSChecker *checker) override; + checker::Type *Check([[maybe_unused]] checker::ETSChecker *checker) override; + +private: + ArenaVector statements_; +}; +} // namespace panda::es2panda::ir + +#endif diff --git a/ets2panda/ir/expressions/callExpression.cpp b/ets2panda/ir/expressions/callExpression.cpp index b74f16794da9ce5f8877d48db9208e8a2afb4f3b..ede576373ea70522612a61638b02c15583b846f2 100644 --- a/ets2panda/ir/expressions/callExpression.cpp +++ b/ets2panda/ir/expressions/callExpression.cpp @@ -1,5 +1,5 @@ /** - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021 - 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 @@ -15,29 +15,9 @@ #include "callExpression.h" -#include "util/helpers.h" -#include "compiler/core/function.h" -#include "compiler/core/pandagen.h" -#include "compiler/core/ETSGen.h" -#include "compiler/core/regScope.h" #include "checker/TSchecker.h" -#include "checker/ETSchecker.h" -#include "checker/types/ets/etsDynamicFunctionType.h" -#include "checker/types/ts/objectType.h" -#include "checker/types/signature.h" -#include "ir/astDump.h" -#include "ir/base/scriptFunction.h" -#include "ir/base/spreadElement.h" -#include "ir/ets/etsFunctionType.h" -#include "ir/expressions/arrayExpression.h" -#include "ir/expressions/chainExpression.h" -#include "ir/expressions/identifier.h" -#include "ir/expressions/memberExpression.h" -#include "ir/expressions/arrowFunctionExpression.h" -#include "ir/expressions/literals/numberLiteral.h" -#include "ir/statements/blockStatement.h" -#include "ir/ts/tsTypeParameterInstantiation.h" -#include "ir/ts/tsEnumMember.h" +#include "compiler/core/ETSGen.h" +#include "compiler/core/pandagen.h" namespace panda::es2panda::ir { void CallExpression::TransformChildren(const NodeTransformer &cb) @@ -79,287 +59,19 @@ void CallExpression::Dump(ir::AstDumper *dumper) const {"typeParameters", AstDumper::Optional(type_params_)}}); } -compiler::VReg CallExpression::CreateSpreadArguments(compiler::PandaGen *pg) const -{ - compiler::VReg args_obj = pg->AllocReg(); - pg->CreateArray(this, arguments_, args_obj); - - return args_obj; -} - -void CallExpression::ConvertRestArguments(checker::ETSChecker *const checker) const -{ - if (signature_->RestVar() != nullptr) { - std::size_t const argument_count = arguments_.size(); - std::size_t const parameter_count = signature_->MinArgCount(); - ASSERT(argument_count >= parameter_count); - - auto &arguments = const_cast &>(arguments_); - std::size_t i = parameter_count; - - if (i < argument_count && arguments_[i]->IsSpreadElement()) { - arguments[i] = arguments_[i]->AsSpreadElement()->Argument(); - } else { - ArenaVector elements(checker->Allocator()->Adapter()); - for (; i < argument_count; ++i) { - elements.emplace_back(arguments_[i]); - } - auto *array_expression = checker->AllocNode(std::move(elements), checker->Allocator()); - array_expression->SetParent(const_cast(this)); - array_expression->SetTsType(signature_->RestVar()->TsType()); - arguments.erase(arguments_.begin() + parameter_count, arguments_.end()); - arguments.emplace_back(array_expression); - } - } -} - void CallExpression::Compile(compiler::PandaGen *pg) const { - compiler::RegScope rs(pg); - bool contains_spread = util::Helpers::ContainSpreadElement(arguments_); - - if (callee_->IsSuperExpression()) { - if (contains_spread) { - compiler::RegScope param_scope(pg); - compiler::VReg args_obj = CreateSpreadArguments(pg); - - pg->GetFunctionObject(this); - pg->SuperCallSpread(this, args_obj); - } else { - compiler::RegScope param_scope(pg); - compiler::VReg arg_start {}; - - if (arguments_.empty()) { - arg_start = pg->AllocReg(); - pg->StoreConst(this, arg_start, compiler::Constant::JS_UNDEFINED); - } else { - arg_start = pg->NextReg(); - } - - for (const auto *it : arguments_) { - compiler::VReg arg = pg->AllocReg(); - it->Compile(pg); - pg->StoreAccumulator(it, arg); - } - - pg->GetFunctionObject(this); - pg->SuperCall(this, arg_start, arguments_.size()); - } - - compiler::VReg new_this = pg->AllocReg(); - pg->StoreAccumulator(this, new_this); - - pg->GetThis(this); - pg->ThrowIfSuperNotCorrectCall(this, 1); - - pg->LoadAccumulator(this, new_this); - pg->SetThis(this); - - compiler::Function::CompileInstanceFields(pg, pg->RootNode()->AsScriptFunction()); - return; - } - - compiler::VReg callee = pg->AllocReg(); - compiler::VReg this_reg = compiler::VReg::Invalid(); - - if (callee_->IsMemberExpression()) { - this_reg = pg->AllocReg(); - - compiler::RegScope mrs(pg); - callee_->AsMemberExpression()->CompileToReg(pg, this_reg); - } else if (callee_->IsChainExpression()) { - this_reg = pg->AllocReg(); - - compiler::RegScope mrs(pg); - callee_->AsChainExpression()->CompileToReg(pg, this_reg); - } else { - callee_->Compile(pg); - } - - pg->StoreAccumulator(this, callee); - pg->OptionalChainCheck(IsOptional(), callee); - - if (contains_spread || arguments_.size() >= compiler::PandaGen::MAX_RANGE_CALL_ARG) { - if (this_reg.IsInvalid()) { - this_reg = pg->AllocReg(); - pg->StoreConst(this, this_reg, compiler::Constant::JS_UNDEFINED); - } - - compiler::VReg args_obj = CreateSpreadArguments(pg); - pg->CallSpread(this, callee, this_reg, args_obj); - } else { - pg->Call(this, callee, this_reg, arguments_); - } + pg->GetAstCompiler()->Compile(this); } void CallExpression::Compile(compiler::ETSGen *etsg) const { - compiler::RegScope rs(etsg); - compiler::VReg callee_reg = etsg->AllocReg(); - - const auto is_proxy = signature_->HasSignatureFlag(checker::SignatureFlags::PROXY); - - if (is_proxy && callee_->IsMemberExpression()) { - auto *const callee_object = callee_->AsMemberExpression()->Object(); - - auto const *const enum_interface = [callee_type = - callee_object->TsType()]() -> checker::ETSEnumInterface const * { - if (callee_type->IsETSEnumType()) { - return callee_type->AsETSEnumType(); - } - if (callee_type->IsETSStringEnumType()) { - return callee_type->AsETSStringEnumType(); - } - return nullptr; - }(); - - if (enum_interface != nullptr) { - ArenaVector arguments(etsg->Allocator()->Adapter()); - - checker::Signature *const signature = [this, callee_object, enum_interface, &arguments]() { - const auto &member_proxy_method_name = signature_->InternalName(); - - if (member_proxy_method_name == checker::ETSEnumType::TO_STRING_METHOD_NAME) { - arguments.push_back(callee_object); - return enum_interface->ToStringMethod().global_signature; - } - if (member_proxy_method_name == checker::ETSEnumType::GET_VALUE_METHOD_NAME) { - arguments.push_back(callee_object); - return enum_interface->GetValueMethod().global_signature; - } - if (member_proxy_method_name == checker::ETSEnumType::GET_NAME_METHOD_NAME) { - arguments.push_back(callee_object); - return enum_interface->GetNameMethod().global_signature; - } - if (member_proxy_method_name == checker::ETSEnumType::VALUES_METHOD_NAME) { - return enum_interface->ValuesMethod().global_signature; - } - if (member_proxy_method_name == checker::ETSEnumType::VALUE_OF_METHOD_NAME) { - arguments.push_back(arguments_.front()); - return enum_interface->ValueOfMethod().global_signature; - } - UNREACHABLE(); - }(); - - ASSERT(signature->ReturnType() == signature_->ReturnType()); - etsg->CallStatic(this, signature, arguments); - etsg->SetAccumulatorType(TsType()); - return; - } - } - - bool is_static = signature_->HasSignatureFlag(checker::SignatureFlags::STATIC); - bool is_reference = signature_->HasSignatureFlag(checker::SignatureFlags::TYPE); - bool is_dynamic = callee_->TsType()->HasTypeFlag(checker::TypeFlag::ETS_DYNAMIC_FLAG); - - ConvertRestArguments(const_cast(etsg->Checker()->AsETSChecker())); - - compiler::VReg dyn_param2; - - // Helper function to avoid branching in non optional cases - auto emit_call = [this, etsg, is_static, is_dynamic, &callee_reg, &dyn_param2]() { - if (is_dynamic) { - etsg->CallDynamic(this, callee_reg, dyn_param2, signature_, arguments_); - } else if (is_static) { - etsg->CallStatic(this, signature_, arguments_); - } else if (signature_->HasSignatureFlag(checker::SignatureFlags::PRIVATE) || IsETSConstructorCall() || - (callee_->IsMemberExpression() && callee_->AsMemberExpression()->Object()->IsSuperExpression())) { - etsg->CallThisStatic(this, callee_reg, signature_, arguments_); - } else { - etsg->CallThisVirtual(this, callee_reg, signature_, arguments_); - } - etsg->SetAccumulatorType(TsType()); - }; - - if (is_dynamic) { - dyn_param2 = etsg->AllocReg(); - - ir::Expression *obj = callee_; - std::vector parts; - - while (obj->IsMemberExpression() && obj->AsMemberExpression()->ObjType()->IsETSDynamicType()) { - auto *mem_expr = obj->AsMemberExpression(); - obj = mem_expr->Object(); - parts.push_back(mem_expr->Property()->AsIdentifier()->Name()); - } - - if (!obj->IsMemberExpression() && obj->IsIdentifier()) { - auto *var = obj->AsIdentifier()->Variable(); - auto *data = etsg->VarBinder()->DynamicImportDataForVar(var); - if (data != nullptr) { - auto *import = data->import; - auto *specifier = data->specifier; - ASSERT(import->Language().IsDynamic()); - etsg->LoadAccumulatorDynamicModule(this, import); - if (specifier->IsImportSpecifier()) { - parts.push_back(specifier->AsImportSpecifier()->Imported()->Name()); - } - } else { - obj->Compile(etsg); - } - } else { - obj->Compile(etsg); - } - - etsg->StoreAccumulator(this, callee_reg); - - if (!parts.empty()) { - std::stringstream ss; - for_each(parts.rbegin(), parts.rend(), [&ss](util::StringView sv) { ss << "." << sv; }); - - etsg->LoadAccumulatorString(this, util::UString(ss.str(), etsg->Allocator()).View()); - } else { - auto lang = callee_->TsType()->IsETSDynamicFunctionType() - ? callee_->TsType()->AsETSDynamicFunctionType()->Language() - : callee_->TsType()->AsETSDynamicType()->Language(); - - etsg->LoadUndefinedDynamic(this, lang); - } - - etsg->StoreAccumulator(this, dyn_param2); - - emit_call(); - - if (signature_->ReturnType() != TsType()) { - etsg->ApplyConversion(this, TsType()); - } - } else if (!is_reference && callee_->IsIdentifier()) { - if (!is_static) { - etsg->LoadThis(this); - etsg->StoreAccumulator(this, callee_reg); - } - emit_call(); - } else if (!is_reference && callee_->IsMemberExpression()) { - if (!is_static) { - callee_->AsMemberExpression()->Object()->Compile(etsg); - etsg->StoreAccumulator(this, callee_reg); - } - emit_call(); - } else if (callee_->IsSuperExpression() || callee_->IsThisExpression()) { - ASSERT(!is_reference && IsETSConstructorCall()); - callee_->Compile(etsg); // ctor is not a value! - etsg->SetVRegType(callee_reg, etsg->GetAccumulatorType()); - emit_call(); - } else { - ASSERT(is_reference); - etsg->CompileAndCheck(callee_); - etsg->StoreAccumulator(this, callee_reg); - etsg->EmitMaybeOptional(this, emit_call, IsOptional()); - } + etsg->GetAstCompiler()->Compile(this); } checker::Type *CallExpression::Check(checker::TSChecker *checker) { - checker::Type *callee_type = callee_->Check(checker); - - // NOTE: aszilagyi. handle optional chain - if (callee_type->IsObjectType()) { - checker::ObjectType *callee_obj = callee_type->AsObjectType(); - return checker->ResolveCallOrNewExpression(callee_obj->CallSignatures(), arguments_, Start()); - } - - checker->ThrowTypeError("This expression is not callable.", Start()); - return nullptr; + return checker->GetAnalyzer()->Check(this); } bool CallExpression::IsETSConstructorCall() const @@ -367,170 +79,40 @@ bool CallExpression::IsETSConstructorCall() const return callee_->IsThisExpression() || callee_->IsSuperExpression(); } -checker::Signature *CallExpression::ResolveCallExtensionFunction(checker::ETSFunctionType *function_type, - checker::ETSChecker *checker) +checker::Type *CallExpression::Check(checker::ETSChecker *checker) { - auto *member_expr = callee_->AsMemberExpression(); - arguments_.insert(arguments_.begin(), member_expr->Object()); - auto *signature = checker->ResolveCallExpressionAndTrailingLambda(function_type->CallSignatures(), this, Start()); - if (!signature->Function()->IsExtensionMethod()) { - checker->ThrowTypeError({"Property '", member_expr->Property()->AsIdentifier()->Name(), - "' does not exist on type '", member_expr->ObjType()->Name(), "'"}, - member_expr->Property()->Start()); - } - this->SetSignature(signature); - this->SetCallee(member_expr->Property()); - member_expr->Property()->AsIdentifier()->SetParent(this); - this->Arguments()[0]->SetParent(this); - checker->HandleUpdatedCallExpressionNode(this); - // Set TsType for new Callee(original member expression's Object) - this->Callee()->Check(checker); - return signature; + return checker->GetAnalyzer()->Check(this); } -checker::Signature *CallExpression::ResolveCallForETSExtensionFuncHelperType(checker::ETSExtensionFuncHelperType *type, - checker::ETSChecker *checker) +CallExpression::CallExpression(CallExpression const &other, ArenaAllocator *const allocator) + : MaybeOptionalExpression(static_cast(other)), + arguments_(allocator->Adapter()), + signature_(other.signature_), + trailing_comma_(other.trailing_comma_), + is_trailing_block_in_new_line_(other.is_trailing_block_in_new_line_) { - checker::Signature *signature = checker->ResolveCallExpressionAndTrailingLambda( - type->ClassMethodType()->CallSignatures(), this, Start(), checker::TypeRelationFlag::NO_THROW); + callee_ = other.callee_->Clone(allocator, this)->AsExpression(); + type_params_ = other.type_params_->Clone(allocator, this); - if (signature != nullptr) { - return signature; + for (auto *const argument : other.arguments_) { + arguments_.emplace_back(argument->Clone(allocator, this)->AsExpression()); } - return ResolveCallExtensionFunction(type->ExtensionMethodType(), checker); + if (other.trailing_block_ != nullptr) { + trailing_block_ = other.trailing_block_->Clone(allocator, this)->AsBlockStatement(); + } } -checker::Type *CallExpression::Check(checker::ETSChecker *checker) +// NOLINTNEXTLINE(google-default-arguments) +CallExpression *CallExpression::Clone(ArenaAllocator *const allocator, AstNode *const parent) { - if (TsType() != nullptr) { - return TsType(); - } - auto *old_callee = callee_; - checker::Type *callee_type = callee_->Check(checker); - if (callee_ != old_callee) { - // If it is a static invoke, the callee will be transformed from an identifier to a member expression - // Type check the callee again for member expression - callee_type = callee_->Check(checker); - } - if (!IsOptional()) { - checker->CheckNonNullishType(callee_type, callee_->Start()); - } - checker::Type *return_type; - if (callee_type->IsETSDynamicType() && !callee_type->AsETSDynamicType()->HasDecl()) { - // Trailing lambda for js function call is not supported, check the correctness of `foo() {}` - checker->EnsureValidCurlyBrace(this); - auto lang = callee_type->AsETSDynamicType()->Language(); - signature_ = checker->ResolveDynamicCallExpression(callee_, arguments_, lang, false); - return_type = signature_->ReturnType(); - } else { - bool constructor_call = IsETSConstructorCall(); - bool functional_interface = - callee_type->IsETSObjectType() && - callee_type->AsETSObjectType()->HasObjectFlag(checker::ETSObjectFlags::FUNCTIONAL_INTERFACE); - bool ets_extension_func_helper_type = callee_type->IsETSExtensionFuncHelperType(); - bool extension_function_type = callee_->IsMemberExpression() && checker->ExtensionETSFunctionType(callee_type); - - if (callee_->IsArrowFunctionExpression()) { - callee_type = InitAnonymousLambdaCallee(checker, callee_, callee_type); - functional_interface = true; - } - - if (!functional_interface && !callee_type->IsETSFunctionType() && !constructor_call && - !ets_extension_func_helper_type) { - checker->ThrowTypeError("This expression is not callable.", Start()); - } - - checker::Signature *signature = nullptr; - - if (ets_extension_func_helper_type) { - signature = ResolveCallForETSExtensionFuncHelperType(callee_type->AsETSExtensionFuncHelperType(), checker); - } else { - if (extension_function_type) { - signature = ResolveCallExtensionFunction(callee_type->AsETSFunctionType(), checker); - } else { - auto &signatures = constructor_call ? callee_type->AsETSObjectType()->ConstructSignatures() - : functional_interface - ? callee_type->AsETSObjectType() - ->GetOwnProperty("invoke") - ->TsType() - ->AsETSFunctionType() - ->CallSignatures() - : callee_type->AsETSFunctionType()->CallSignatures(); - signature = checker->ResolveCallExpressionAndTrailingLambda(signatures, this, Start()); - if (signature->Function()->IsExtensionMethod()) { - checker->ThrowTypeError({"No matching call signature"}, Start()); - } - } + if (auto *const clone = allocator->New(*this, allocator); clone != nullptr) { + if (parent != nullptr) { + clone->SetParent(parent); } - - checker->CheckObjectLiteralArguments(signature, arguments_); - - checker->AddUndefinedParamsForDefaultParams(signature, arguments_, checker); - - if (!functional_interface) { - checker::ETSObjectType *callee_obj {}; - if (constructor_call) { - callee_obj = callee_type->AsETSObjectType(); - } else if (callee_->IsIdentifier()) { - callee_obj = checker->Context().ContainingClass(); - } else { - ASSERT(callee_->IsMemberExpression()); - callee_obj = callee_->AsMemberExpression()->ObjType(); - } - - checker->ValidateSignatureAccessibility(callee_obj, signature, Start()); - } - - ASSERT(signature->Function() != nullptr); - - if (signature->Function()->IsThrowing() || signature->Function()->IsRethrowing()) { - checker->CheckThrowingStatements(this); - } - - if (signature->Function()->IsDynamic()) { - ASSERT(signature->Function()->IsDynamic()); - auto lang = signature->Function()->Language(); - signature_ = checker->ResolveDynamicCallExpression(callee_, signature->Params(), lang, false); - } else { - ASSERT(!signature->Function()->IsDynamic()); - signature_ = signature; - } - - return_type = signature->ReturnType(); - } - - if (signature_->RestVar() != nullptr) { - auto *const element_type = signature_->RestVar()->TsType()->AsETSArrayType()->ElementType(); - auto *const array_type = checker->CreateETSArrayType(element_type)->AsETSArrayType(); - checker->CreateBuiltinArraySignature(array_type, array_type->Rank()); - } - - if (signature_->HasSignatureFlag(checker::SignatureFlags::NEED_RETURN_TYPE)) { - signature_->OwnerVar()->Declaration()->Node()->Check(checker); - return_type = signature_->ReturnType(); + return clone; } - SetOptionalType(return_type); - if (IsOptional() && callee_type->IsNullishOrNullLike()) { - checker->Relation()->SetNode(this); - return_type = checker->CreateOptionalResultType(return_type); - checker->Relation()->SetNode(nullptr); - } - SetTsType(return_type); - return TsType(); -} -checker::Type *CallExpression::InitAnonymousLambdaCallee(checker::ETSChecker *checker, Expression *callee, - checker::Type *callee_type) -{ - auto *const arrow_func = callee->AsArrowFunctionExpression()->Function(); - auto orig_params = arrow_func->Params(); - auto *func_type = checker->Allocator()->New( - arrow_func->Scope()->AsFunctionScope()->ParamScope(), std::move(orig_params), nullptr, - arrow_func->ReturnTypeAnnotation(), ir::ScriptFunctionFlags::NONE); - auto *const func_iface = func_type->Check(checker); - checker->Relation()->SetNode(callee); - checker->Relation()->IsAssignableTo(callee_type, func_iface); - return func_iface; + throw Error(ErrorType::GENERIC, "", CLONE_ALLOCATION_ERROR); } } // namespace panda::es2panda::ir diff --git a/ets2panda/ir/expressions/callExpression.h b/ets2panda/ir/expressions/callExpression.h index d68ca9daca725252c798de103c0eac2180193eca..1bdf683c065408420b8eaf3c186f94a9327eca2d 100644 --- a/ets2panda/ir/expressions/callExpression.h +++ b/ets2panda/ir/expressions/callExpression.h @@ -1,5 +1,5 @@ /** - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021 - 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 @@ -21,16 +21,30 @@ #include "ir/expression.h" namespace panda::es2panda::checker { +class ETSAnalyzer; +class TSAnalyzer; class Signature; } // namespace panda::es2panda::checker +namespace panda::es2panda::compiler { +class JSCompiler; +class ETSCompiler; +} // namespace panda::es2panda::compiler + namespace panda::es2panda::ir { class TSTypeParameterInstantiation; class CallExpression : public MaybeOptionalExpression { public: - explicit CallExpression(Expression *callee, ArenaVector &&arguments, - TSTypeParameterInstantiation *type_params, bool optional, bool trailing_comma = false) + CallExpression() = delete; + ~CallExpression() override = default; + + NO_COPY_SEMANTIC(CallExpression); + NO_MOVE_SEMANTIC(CallExpression); + + explicit CallExpression(Expression *const callee, ArenaVector &&arguments, + TSTypeParameterInstantiation *const type_params, bool const optional, + bool const trailing_comma = false) : MaybeOptionalExpression(AstNodeType::CALL_EXPRESSION, optional), callee_(callee), arguments_(std::move(arguments)), @@ -39,101 +53,107 @@ public: { } + explicit CallExpression(CallExpression const &other, ArenaAllocator *allocator); + + // NOTE (csabahurton): these friend relationships can be removed once there are getters for private fields + friend class checker::TSAnalyzer; + friend class checker::ETSAnalyzer; + friend class compiler::JSCompiler; + friend class compiler::ETSCompiler; + const Expression *Callee() const { return callee_; } - Expression *Callee() + [[nodiscard]] Expression *Callee() noexcept { return callee_; } - void SetCallee(Expression *callee) + void SetCallee(Expression *callee) noexcept { callee_ = callee; } - const TSTypeParameterInstantiation *TypeParams() const + [[nodiscard]] const TSTypeParameterInstantiation *TypeParams() const noexcept { return type_params_; } - TSTypeParameterInstantiation *TypeParams() + [[nodiscard]] TSTypeParameterInstantiation *TypeParams() noexcept { return type_params_; } - const ArenaVector &Arguments() const + [[nodiscard]] const ArenaVector &Arguments() const noexcept { return arguments_; } - ArenaVector &Arguments() + [[nodiscard]] ArenaVector &Arguments() noexcept { return arguments_; } - bool HasTrailingComma() const + [[nodiscard]] bool HasTrailingComma() const noexcept { return trailing_comma_; } - checker::Signature *Signature() + [[nodiscard]] checker::Signature *Signature() noexcept { return signature_; } - checker::Signature *Signature() const + [[nodiscard]] checker::Signature *Signature() const noexcept { return signature_; } - void SetSignature(checker::Signature *signature) + void SetSignature(checker::Signature *const signature) noexcept { signature_ = signature; } - void SetTypeParams(TSTypeParameterInstantiation *type_params) + void SetTypeParams(TSTypeParameterInstantiation *const type_params) noexcept { type_params_ = type_params; } - void SetTrailingBlock(ir::BlockStatement *block) + void SetTrailingBlock(ir::BlockStatement *const block) noexcept { trailing_block_ = block; } - ir::BlockStatement *TrailingBlock() const + [[nodiscard]] ir::BlockStatement *TrailingBlock() const noexcept { return trailing_block_; } - void SetIsTrailingBlockInNewLine(bool is_new_line) + void SetIsTrailingBlockInNewLine(bool const is_new_line) noexcept { is_trailing_block_in_new_line_ = is_new_line; } - bool IsTrailingBlockInNewLine() const + [[nodiscard]] bool IsTrailingBlockInNewLine() const noexcept { return is_trailing_block_in_new_line_; } + // NOLINTNEXTLINE(google-default-arguments) + [[nodiscard]] CallExpression *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; + void Dump(ir::AstDumper *dumper) const override; - void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; - void Compile([[maybe_unused]] compiler::ETSGen *etsg) const override; - checker::Type *Check([[maybe_unused]] checker::TSChecker *checker) override; - checker::Type *Check([[maybe_unused]] checker::ETSChecker *checker) override; - checker::Signature *ResolveCallExtensionFunction(checker::ETSFunctionType *function_type, - checker::ETSChecker *checker); - checker::Signature *ResolveCallForETSExtensionFuncHelperType(checker::ETSExtensionFuncHelperType *type, - checker::ETSChecker *checker); + void Compile(compiler::PandaGen *pg) const override; + void Compile(compiler::ETSGen *etsg) const override; + checker::Type *Check(checker::TSChecker *checker) override; + checker::Type *Check(checker::ETSChecker *checker) override; protected: - compiler::VReg CreateSpreadArguments(compiler::PandaGen *pg) const; - // NOLINTBEGIN(misc-non-private-member-variables-in-classes) Expression *callee_; ArenaVector arguments_; @@ -149,7 +169,6 @@ private: bool IsETSConstructorCall() const; checker::Type *InitAnonymousLambdaCallee(checker::ETSChecker *checker, Expression *callee, checker::Type *callee_type); - void ConvertRestArguments(checker::ETSChecker *checker) const; }; } // namespace panda::es2panda::ir diff --git a/ets2panda/ir/expressions/chainExpression.cpp b/ets2panda/ir/expressions/chainExpression.cpp index ce71eac838816b664bcb6cbfc04018e05cfb1b23..c7bddde72b0cdfb24d548f66af60e3e756b21a62 100644 --- a/ets2panda/ir/expressions/chainExpression.cpp +++ b/ets2panda/ir/expressions/chainExpression.cpp @@ -15,12 +15,11 @@ #include "chainExpression.h" -#include "ir/expressions/callExpression.h" -#include "ir/expressions/memberExpression.h" -#include "compiler/base/optionalChain.h" -#include "compiler/core/regScope.h" +#include "checker/TSchecker.h" +#include "compiler/core/ETSGen.h" #include "compiler/core/pandagen.h" #include "ir/astDump.h" +#include "ir/expressions/memberExpression.h" namespace panda::es2panda::ir { void ChainExpression::TransformChildren(const NodeTransformer &cb) @@ -38,10 +37,9 @@ void ChainExpression::Dump(ir::AstDumper *dumper) const dumper->Add({{"type", "ChainExpression"}, {"expression", expression_}}); } -void ChainExpression::Compile([[maybe_unused]] compiler::PandaGen *pg) const +void ChainExpression::Compile(compiler::PandaGen *pg) const { - compiler::OptionalChain chain(pg, this); - expression_->Compile(pg); + pg->GetAstCompiler()->Compile(this); } void ChainExpression::CompileToReg(compiler::PandaGen *pg, compiler::VReg &obj_reg) const @@ -57,20 +55,25 @@ void ChainExpression::CompileToReg(compiler::PandaGen *pg, compiler::VReg &obj_r } } -checker::Type *ChainExpression::Check([[maybe_unused]] checker::TSChecker *checker) +void ChainExpression::Compile(compiler::ETSGen *etsg) const +{ + etsg->GetAstCompiler()->Compile(this); +} + +checker::Type *ChainExpression::Check(checker::TSChecker *checker) { - return expression_->Check(checker); + return checker->GetAnalyzer()->Check(this); } -checker::Type *ChainExpression::Check([[maybe_unused]] checker::ETSChecker *checker) +checker::Type *ChainExpression::Check(checker::ETSChecker *checker) { - return nullptr; + return checker->GetAnalyzer()->Check(this); } // NOLINTNEXTLINE(google-default-arguments) -Expression *ChainExpression::Clone(ArenaAllocator *const allocator, AstNode *const parent) +ChainExpression *ChainExpression::Clone(ArenaAllocator *const allocator, AstNode *const parent) { - auto *const expression = expression_ != nullptr ? expression_->Clone(allocator) : nullptr; + auto *const expression = expression_ != nullptr ? expression_->Clone(allocator)->AsExpression() : nullptr; if (auto *const clone = allocator->New(expression); clone != nullptr) { if (expression != nullptr) { diff --git a/ets2panda/ir/expressions/chainExpression.h b/ets2panda/ir/expressions/chainExpression.h index 252ece9500b899c32839e359942a82ab5d196360..6aa823aeae17686e707e455a872ef0e38c297a08 100644 --- a/ets2panda/ir/expressions/chainExpression.h +++ b/ets2panda/ir/expressions/chainExpression.h @@ -19,6 +19,10 @@ #include "ir/expression.h" #include "ir/irnode.h" +namespace panda::es2panda::checker { +class TSAnalyzer; +} // namespace panda::es2panda::checker + namespace panda::es2panda::ir { class ChainExpression : public Expression { public: @@ -33,21 +37,25 @@ public: { } + // NOTE (csabahurton): friend relationship can be removed once there are getters for private fields + friend class checker::TSAnalyzer; + const Expression *GetExpression() const noexcept { return expression_; } // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] Expression *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + [[nodiscard]] ChainExpression *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; void Dump(ir::AstDumper *dumper) const override; - void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; + void Compile(compiler::PandaGen *pg) const override; + void Compile(compiler::ETSGen *etsg) const override; void CompileToReg(compiler::PandaGen *pg, compiler::VReg &obj_reg) const; - checker::Type *Check([[maybe_unused]] checker::TSChecker *checker) override; - checker::Type *Check([[maybe_unused]] checker::ETSChecker *checker) override; + checker::Type *Check(checker::TSChecker *checker) override; + checker::Type *Check(checker::ETSChecker *checker) override; private: Expression *expression_; diff --git a/ets2panda/ir/expressions/classExpression.cpp b/ets2panda/ir/expressions/classExpression.cpp index ecefc3a8faa98819a7af97b4a76a6d32be7280c2..b2fb7234fb02998b0509564d21397749e2fe10b0 100644 --- a/ets2panda/ir/expressions/classExpression.cpp +++ b/ets2panda/ir/expressions/classExpression.cpp @@ -1,5 +1,5 @@ /** - * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * Copyright (c) 2021-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 @@ -15,8 +15,10 @@ #include "classExpression.h" +#include "checker/TSchecker.h" +#include "compiler/core/ETSGen.h" +#include "compiler/core/pandagen.h" #include "ir/astDump.h" -#include "ir/base/classDefinition.h" namespace panda::es2panda::ir { void ClassExpression::TransformChildren(const NodeTransformer &cb) @@ -34,18 +36,41 @@ void ClassExpression::Dump(ir::AstDumper *dumper) const dumper->Add({{"type", "ClassExpression"}, {"definition", def_}}); } -void ClassExpression::Compile([[maybe_unused]] compiler::PandaGen *pg) const +void ClassExpression::Compile(compiler::PandaGen *pg) const { - def_->Compile(pg); + pg->GetAstCompiler()->Compile(this); } -checker::Type *ClassExpression::Check([[maybe_unused]] checker::TSChecker *checker) +void ClassExpression::Compile(compiler::ETSGen *etsg) const { - return nullptr; + etsg->GetAstCompiler()->Compile(this); } -checker::Type *ClassExpression::Check([[maybe_unused]] checker::ETSChecker *checker) +checker::Type *ClassExpression::Check(checker::TSChecker *checker) { - return nullptr; + return checker->GetAnalyzer()->Check(this); +} + +checker::Type *ClassExpression::Check(checker::ETSChecker *checker) +{ + return checker->GetAnalyzer()->Check(this); +} + +// NOLINTNEXTLINE(google-default-arguments) +ClassExpression *ClassExpression::Clone(ArenaAllocator *const allocator, AstNode *const parent) +{ + auto *const def = def_ != nullptr ? def_->Clone(allocator)->AsClassDefinition() : nullptr; + + if (auto *const clone = allocator->New(def); clone != nullptr) { + if (parent != nullptr) { + clone->SetParent(parent); + } + if (def != nullptr) { + def->SetParent(clone); + } + return clone; + } + + throw Error(ErrorType::GENERIC, "", CLONE_ALLOCATION_ERROR); } } // namespace panda::es2panda::ir diff --git a/ets2panda/ir/expressions/classExpression.h b/ets2panda/ir/expressions/classExpression.h index 1ab8e4a09cef41e69b7982dadee50bf1f4d269bb..0d2ca9b101617bb19f523c3c0d0c58ed97a07b2c 100644 --- a/ets2panda/ir/expressions/classExpression.h +++ b/ets2panda/ir/expressions/classExpression.h @@ -1,5 +1,5 @@ /** - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021 - 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 @@ -23,19 +23,30 @@ class ClassDefinition; class ClassExpression : public Expression { public: - explicit ClassExpression(ClassDefinition *def) : Expression(AstNodeType::CLASS_EXPRESSION), def_(def) {} + ClassExpression() = delete; + ~ClassExpression() override = default; - const ClassDefinition *Definition() const + NO_COPY_SEMANTIC(ClassExpression); + NO_MOVE_SEMANTIC(ClassExpression); + + explicit ClassExpression(ClassDefinition *const def) : Expression(AstNodeType::CLASS_EXPRESSION), def_(def) {} + + [[nodiscard]] const ClassDefinition *Definition() const noexcept { return def_; } + // NOLINTNEXTLINE(google-default-arguments) + [[nodiscard]] ClassExpression *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; + void Dump(ir::AstDumper *dumper) const override; - void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; - checker::Type *Check([[maybe_unused]] checker::TSChecker *checker) override; - checker::Type *Check([[maybe_unused]] checker::ETSChecker *checker) override; + void Compile(compiler::PandaGen *pg) const override; + void Compile(compiler::ETSGen *etsg) const override; + checker::Type *Check(checker::TSChecker *checker) override; + checker::Type *Check(checker::ETSChecker *checker) override; private: ClassDefinition *def_; diff --git a/ets2panda/ir/expressions/conditionalExpression.cpp b/ets2panda/ir/expressions/conditionalExpression.cpp index b60d48679a534d877a6043bcf2a4da23c1f8b8d2..7c6c572c9f5beb283c48e87899eb7e5068f3cfcd 100644 --- a/ets2panda/ir/expressions/conditionalExpression.cpp +++ b/ets2panda/ir/expressions/conditionalExpression.cpp @@ -15,11 +15,9 @@ #include "conditionalExpression.h" -#include "compiler/base/condition.h" +#include "checker/TSchecker.h" #include "compiler/core/pandagen.h" #include "compiler/core/ETSGen.h" -#include "checker/TSchecker.h" -#include "ir/astDump.h" namespace panda::es2panda::ir { void ConditionalExpression::TransformChildren(const NodeTransformer &cb) @@ -42,119 +40,32 @@ void ConditionalExpression::Dump(ir::AstDumper *dumper) const {{"type", "ConditionalExpression"}, {"test", test_}, {"consequent", consequent_}, {"alternate", alternate_}}); } -template -void CompileImpl(const ConditionalExpression *self, CodeGen *cg) -{ - auto *false_label = cg->AllocLabel(); - auto *end_label = cg->AllocLabel(); - - compiler::Condition::Compile(cg, self->Test(), false_label); - self->Consequent()->Compile(cg); - cg->Branch(self, end_label); - cg->SetLabel(self, false_label); - self->Alternate()->Compile(cg); - cg->SetLabel(self, end_label); -} - void ConditionalExpression::Compile(compiler::PandaGen *pg) const { - CompileImpl(this, pg); + pg->GetAstCompiler()->Compile(this); } void ConditionalExpression::Compile(compiler::ETSGen *etsg) const { - auto *false_label = etsg->AllocLabel(); - auto *end_label = etsg->AllocLabel(); - - compiler::Condition::Compile(etsg, Test(), false_label); - - auto ttctx = compiler::TargetTypeContext(etsg, TsType()); - - Consequent()->Compile(etsg); - etsg->ApplyConversion(Consequent()); - etsg->Branch(this, end_label); - etsg->SetLabel(this, false_label); - Alternate()->Compile(etsg); - etsg->ApplyConversion(Alternate()); - etsg->SetLabel(this, end_label); - etsg->SetAccumulatorType(TsType()); + etsg->GetAstCompiler()->Compile(this); } checker::Type *ConditionalExpression::Check(checker::TSChecker *checker) { - checker::Type *test_type = test_->Check(checker); - - checker->CheckTruthinessOfType(test_type, test_->Start()); - checker->CheckTestingKnownTruthyCallableOrAwaitableType(test_, test_type, consequent_); - - checker::Type *consequent_type = consequent_->Check(checker); - checker::Type *alternate_type = alternate_->Check(checker); - - return checker->CreateUnionType({consequent_type, alternate_type}); + return checker->GetAnalyzer()->Check(this); } checker::Type *ConditionalExpression::Check(checker::ETSChecker *checker) { - if (TsType() != nullptr) { - return TsType(); - } - - checker->CheckTruthinessOfType(test_); - - checker::Type *consequent_type = consequent_->Check(checker); - checker::Type *alternate_type = alternate_->Check(checker); - - auto *primitive_consequent_type = checker->ETSBuiltinTypeAsPrimitiveType(consequent_type); - auto *primitive_alter_type = checker->ETSBuiltinTypeAsPrimitiveType(alternate_type); - - if (primitive_consequent_type != nullptr && primitive_alter_type != nullptr) { - if (checker->IsTypeIdenticalTo(consequent_type, alternate_type)) { - SetTsType(checker->GetNonConstantTypeFromPrimitiveType(consequent_type)); - } else if (checker->IsTypeIdenticalTo(primitive_consequent_type, primitive_alter_type)) { - checker->FlagExpressionWithUnboxing(consequent_->TsType(), primitive_consequent_type, consequent_); - checker->FlagExpressionWithUnboxing(alternate_->TsType(), primitive_alter_type, alternate_); - - SetTsType(primitive_consequent_type); - } else if (primitive_consequent_type->HasTypeFlag(checker::TypeFlag::ETS_NUMERIC) && - primitive_alter_type->HasTypeFlag(checker::TypeFlag::ETS_NUMERIC)) { - checker->FlagExpressionWithUnboxing(consequent_->TsType(), primitive_consequent_type, consequent_); - checker->FlagExpressionWithUnboxing(alternate_->TsType(), primitive_alter_type, alternate_); - - SetTsType( - checker->ApplyConditionalOperatorPromotion(checker, primitive_consequent_type, primitive_alter_type)); - } else { - checker->ThrowTypeError("Type error", this->range_.start); - } - } else { - if (!(consequent_type->IsETSArrayType() || alternate_type->IsETSArrayType()) && - !(consequent_type->IsETSObjectType() && alternate_type->IsETSObjectType())) { - checker->ThrowTypeError("Type error", this->range_.start); - } else { - checker->Relation()->SetNode(consequent_); - auto builtin_conseq_type = checker->PrimitiveTypeAsETSBuiltinType(consequent_type); - auto builtin_alternate_type = checker->PrimitiveTypeAsETSBuiltinType(alternate_type); - - if (builtin_conseq_type == nullptr) { - builtin_conseq_type = consequent_type; - } - - if (builtin_alternate_type == nullptr) { - builtin_alternate_type = alternate_type; - } - - SetTsType(checker->FindLeastUpperBound(builtin_conseq_type, builtin_alternate_type)); - } - } - - return TsType(); + return checker->GetAnalyzer()->Check(this); } // NOLINTNEXTLINE(google-default-arguments) -Expression *ConditionalExpression::Clone(ArenaAllocator *const allocator, AstNode *const parent) +ConditionalExpression *ConditionalExpression::Clone(ArenaAllocator *const allocator, AstNode *const parent) { - auto *const test = test_ != nullptr ? test_->Clone(allocator) : nullptr; - auto *const consequent = consequent_ != nullptr ? consequent_->Clone(allocator) : nullptr; - auto *const alternate = alternate_ != nullptr ? alternate_->Clone(allocator) : nullptr; + auto *const test = test_ != nullptr ? test_->Clone(allocator)->AsExpression() : nullptr; + auto *const consequent = consequent_ != nullptr ? consequent_->Clone(allocator)->AsExpression() : nullptr; + auto *const alternate = alternate_ != nullptr ? alternate_->Clone(allocator)->AsExpression() : nullptr; if (auto *const clone = allocator->New(test, consequent, alternate); clone != nullptr) { if (test != nullptr) { diff --git a/ets2panda/ir/expressions/conditionalExpression.h b/ets2panda/ir/expressions/conditionalExpression.h index 8e0e7a10d8f05320189fb05223dedd18f2d73dea..e15219d556a5de372ce90e99c2c596a681e6cdb5 100644 --- a/ets2panda/ir/expressions/conditionalExpression.h +++ b/ets2panda/ir/expressions/conditionalExpression.h @@ -18,6 +18,11 @@ #include "ir/expression.h" +namespace panda::es2panda::checker { +class TSAnalyzer; +class ETSAnalyzer; +} // namespace panda::es2panda::checker + namespace panda::es2panda::ir { class ConditionalExpression : public Expression { public: @@ -32,6 +37,10 @@ public: { } + // NOTE (csabahurton): these friend relationships can be removed once there are getters for private fields + friend class checker::TSAnalyzer; + friend class checker::ETSAnalyzer; + [[nodiscard]] const Expression *Test() const noexcept { return test_; @@ -58,7 +67,7 @@ public: } // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] Expression *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + [[nodiscard]] ConditionalExpression *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; diff --git a/ets2panda/ir/expressions/directEvalExpression.cpp b/ets2panda/ir/expressions/directEvalExpression.cpp index 356301fb15468c40b02608ae59669c30bd649465..95cb09e36775f8723343bdc0e58c9e2184637a57 100644 --- a/ets2panda/ir/expressions/directEvalExpression.cpp +++ b/ets2panda/ir/expressions/directEvalExpression.cpp @@ -17,36 +17,29 @@ #include "directEvalExpression.h" -#include "util/helpers.h" +#include "checker/TSchecker.h" +#include "compiler/core/ETSGen.h" #include "compiler/core/pandagen.h" -#include "compiler/core/regScope.h" namespace panda::es2panda::ir { void DirectEvalExpression::Compile(compiler::PandaGen *pg) const { - if (arguments_.empty()) { - pg->LoadConst(this, compiler::Constant::JS_UNDEFINED); - return; - } - - compiler::RegScope rs(pg); - bool contains_spread = util::Helpers::ContainSpreadElement(arguments_); - if (contains_spread) { - [[maybe_unused]] compiler::VReg args_obj = CreateSpreadArguments(pg); - pg->LoadObjByIndex(this, 0); - } else { - compiler::VReg arg0 = pg->AllocReg(); - auto iter = arguments_.cbegin(); - (*iter++)->Compile(pg); - pg->StoreAccumulator(this, arg0); - - while (iter != arguments_.cend()) { - (*iter++)->Compile(pg); - } - - pg->LoadAccumulator(this, arg0); - } - - pg->DirectEval(this, parser_status_); + pg->GetAstCompiler()->Compile(this); } + +void DirectEvalExpression::Compile(compiler::ETSGen *etsg) const +{ + etsg->GetAstCompiler()->Compile(this); +} + +checker::Type *DirectEvalExpression::Check(checker::TSChecker *checker) +{ + return checker->GetAnalyzer()->Check(this); +} + +checker::Type *DirectEvalExpression::Check(checker::ETSChecker *checker) +{ + return checker->GetAnalyzer()->Check(this); +} + } // namespace panda::es2panda::ir diff --git a/ets2panda/ir/expressions/directEvalExpression.h b/ets2panda/ir/expressions/directEvalExpression.h index eca191333919c1ad2372095147cc0326165dbdca..3ee2b05badd356fe2ac6ba59dfb6a9a6ef3d003f 100644 --- a/ets2panda/ir/expressions/directEvalExpression.h +++ b/ets2panda/ir/expressions/directEvalExpression.h @@ -16,6 +16,10 @@ #ifndef ES2PANDA_IR_EXPRESSION_DIRECT_EVAL_H #define ES2PANDA_IR_EXPRESSION_DIRECT_EVAL_H +namespace panda::es2panda::compiler { +class JSCompiler; +} // namespace panda::es2panda::compiler + #include "ir/expressions/callExpression.h" namespace panda::es2panda::ir { @@ -28,7 +32,13 @@ public: type_ = AstNodeType::DIRECT_EVAL; } - void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; + // NOTE (csabahurton): friend relationship can be removed once there are getters for private fields + friend class compiler::JSCompiler; + + void Compile(compiler::PandaGen *pg) const override; + void Compile(compiler::ETSGen *etsg) const override; + checker::Type *Check(checker::TSChecker *checker) override; + checker::Type *Check(checker::ETSChecker *checker) override; private: uint32_t parser_status_ {}; diff --git a/ets2panda/ir/expressions/functionExpression.cpp b/ets2panda/ir/expressions/functionExpression.cpp index 7f9c194231c0aed7c6c2b7a3d46b99df5c074fff..f8add6e7234e48c6f4a74b28da9f7b43106c9fdc 100644 --- a/ets2panda/ir/expressions/functionExpression.cpp +++ b/ets2panda/ir/expressions/functionExpression.cpp @@ -1,5 +1,5 @@ /** - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021 - 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 @@ -15,13 +15,10 @@ #include "functionExpression.h" -#include "compiler/core/pandagen.h" -#include "compiler/core/ETSGen.h" #include "checker/TSchecker.h" +#include "compiler/core/ETSGen.h" +#include "compiler/core/pandagen.h" #include "ir/astDump.h" -#include "ir/base/scriptFunction.h" -#include "ir/expressions/identifier.h" -#include "ir/statements/variableDeclarator.h" namespace panda::es2panda::ir { void FunctionExpression::TransformChildren(const NodeTransformer &cb) @@ -41,45 +38,37 @@ void FunctionExpression::Dump(ir::AstDumper *dumper) const void FunctionExpression::Compile(compiler::PandaGen *pg) const { - pg->DefineFunction(func_, func_, func_->Scope()->InternalName()); + pg->GetAstCompiler()->Compile(this); } -void FunctionExpression::Compile([[maybe_unused]] compiler::ETSGen *etsg) const +void FunctionExpression::Compile(compiler::ETSGen *etsg) const { - UNREACHABLE(); + etsg->GetAstCompiler()->Compile(this); } checker::Type *FunctionExpression::Check(checker::TSChecker *checker) { - varbinder::Variable *func_var = nullptr; - - if (func_->Parent()->Parent() != nullptr && func_->Parent()->Parent()->IsVariableDeclarator() && - func_->Parent()->Parent()->AsVariableDeclarator()->Id()->IsIdentifier()) { - func_var = func_->Parent()->Parent()->AsVariableDeclarator()->Id()->AsIdentifier()->Variable(); - } - - checker::ScopeContext scope_ctx(checker, func_->Scope()); - - auto *signature_info = checker->Allocator()->New(checker->Allocator()); - checker->CheckFunctionParameterDeclarations(func_->Params(), signature_info); - - auto *signature = - checker->Allocator()->New(signature_info, checker->GlobalResolvingReturnType(), func_); - checker::Type *func_type = checker->CreateFunctionTypeWithSignature(signature); - - if (func_var != nullptr && func_var->TsType() == nullptr) { - func_var->SetTsType(func_type); - } - - signature->SetReturnType(checker->HandleFunctionReturn(func_)); - - func_->Body()->Check(checker); - - return func_type; + return checker->GetAnalyzer()->Check(this); } checker::Type *FunctionExpression::Check([[maybe_unused]] checker::ETSChecker *checker) { - return nullptr; + return checker->GetAnalyzer()->Check(this); +} + +// NOLINTNEXTLINE(google-default-arguments) +FunctionExpression *FunctionExpression::Clone(ArenaAllocator *const allocator, AstNode *const parent) +{ + auto *const func = func_->Clone(allocator)->AsScriptFunction(); + + if (auto *const clone = allocator->New(func); clone != nullptr) { + func->SetParent(clone); + if (parent != nullptr) { + clone->SetParent(parent); + } + return clone; + } + + throw Error(ErrorType::GENERIC, "", CLONE_ALLOCATION_ERROR); } } // namespace panda::es2panda::ir diff --git a/ets2panda/ir/expressions/functionExpression.h b/ets2panda/ir/expressions/functionExpression.h index 4b2191857876d40e841c41400d5ce63f5f3de283..52f716d6f8fe28cbac2cc2c16ec6762faca413b3 100644 --- a/ets2panda/ir/expressions/functionExpression.h +++ b/ets2panda/ir/expressions/functionExpression.h @@ -1,5 +1,5 @@ /** - * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * Copyright (c) 2021-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 @@ -23,25 +23,37 @@ class ScriptFunction; class FunctionExpression : public Expression { public: - explicit FunctionExpression(ScriptFunction *func) : Expression(AstNodeType::FUNCTION_EXPRESSION), func_(func) {} + FunctionExpression() = delete; + ~FunctionExpression() override = default; - const ScriptFunction *Function() const + NO_COPY_SEMANTIC(FunctionExpression); + NO_MOVE_SEMANTIC(FunctionExpression); + + explicit FunctionExpression(ScriptFunction *const func) : Expression(AstNodeType::FUNCTION_EXPRESSION), func_(func) + { + } + + [[nodiscard]] const ScriptFunction *Function() const noexcept { return func_; } - ScriptFunction *Function() + [[nodiscard]] ScriptFunction *Function() noexcept { return func_; } + // NOLINTNEXTLINE(google-default-arguments) + [[nodiscard]] FunctionExpression *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; + void Dump(ir::AstDumper *dumper) const override; - void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; + void Compile(compiler::PandaGen *pg) const override; void Compile(compiler::ETSGen *etsg) const override; - checker::Type *Check([[maybe_unused]] checker::TSChecker *checker) override; - checker::Type *Check([[maybe_unused]] checker::ETSChecker *checker) override; + checker::Type *Check(checker::TSChecker *checker) override; + checker::Type *Check(checker::ETSChecker *checker) override; private: ScriptFunction *func_; diff --git a/ets2panda/ir/expressions/identifier.cpp b/ets2panda/ir/expressions/identifier.cpp index e1f2b3cd2a574197000bf42a07baec92d04bfec7..34f5fff812b1b6d319846bd8caa1a144b01a75cd 100644 --- a/ets2panda/ir/expressions/identifier.cpp +++ b/ets2panda/ir/expressions/identifier.cpp @@ -27,20 +27,19 @@ namespace panda::es2panda::ir { Identifier::Identifier([[maybe_unused]] Tag const tag, Identifier const &other, ArenaAllocator *const allocator) - : AnnotatedExpression(static_cast(other)), decorators_(allocator->Adapter()) + : AnnotatedExpression(static_cast(other), allocator), decorators_(allocator->Adapter()) { - CloneTypeAnnotation(allocator); name_ = other.name_; flags_ = other.flags_; variable_ = other.variable_; for (auto *decorator : other.decorators_) { - decorators_.emplace_back(decorator->Clone(allocator, this)->AsDecorator()); + decorators_.emplace_back(decorator->Clone(allocator, this)); } } // NOLINTNEXTLINE(google-default-arguments) -Expression *Identifier::Clone(ArenaAllocator *const allocator, AstNode *const parent) +Identifier *Identifier::Clone(ArenaAllocator *const allocator, AstNode *const parent) { if (auto *const clone = allocator->New(Tag {}, *this, allocator); clone != nullptr) { if (parent != nullptr) { diff --git a/ets2panda/ir/expressions/identifier.h b/ets2panda/ir/expressions/identifier.h index a6ee3dd78ef7aaa4e9400a3bb702c9cd6a3ddc0b..2d3e4394a840cf497f1cc4d493ad07a2a6f027d1 100644 --- a/ets2panda/ir/expressions/identifier.h +++ b/ets2panda/ir/expressions/identifier.h @@ -83,6 +83,11 @@ public: return decorators_; } + const ArenaVector *DecoratorsPtr() const override + { + return &Decorators(); + } + [[nodiscard]] bool IsOptional() const noexcept { return (flags_ & IdentifierFlags::OPTIONAL) != 0; @@ -186,7 +191,12 @@ public: } // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] Expression *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + [[nodiscard]] Identifier *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + + bool CanHaveDecorator([[maybe_unused]] bool in_ts) const override + { + return true; + } [[nodiscard]] ValidationInfo ValidateExpression(); diff --git a/ets2panda/ir/expressions/importExpression.cpp b/ets2panda/ir/expressions/importExpression.cpp index e812123c13e5fbc49ccd6910fa2868d0bbde7c13..d9b39dcd391d6028b91e9e4243710f49e5bce488 100644 --- a/ets2panda/ir/expressions/importExpression.cpp +++ b/ets2panda/ir/expressions/importExpression.cpp @@ -50,9 +50,9 @@ checker::Type *ImportExpression::Check([[maybe_unused]] checker::ETSChecker *che } // NOLINTNEXTLINE(google-default-arguments) -Expression *ImportExpression::Clone(ArenaAllocator *const allocator, AstNode *const parent) +ImportExpression *ImportExpression::Clone(ArenaAllocator *const allocator, AstNode *const parent) { - auto *const source = source_ != nullptr ? source_->Clone(allocator) : nullptr; + auto *const source = source_ != nullptr ? source_->Clone(allocator)->AsExpression() : nullptr; if (auto *const clone = allocator->New(source); clone != nullptr) { if (source != nullptr) { diff --git a/ets2panda/ir/expressions/importExpression.h b/ets2panda/ir/expressions/importExpression.h index d275dd9a9a4e87384f2455bf2f8a0fa934ec7ca4..5b37ae04ee7bf7422d017674f5b2e7efe4ec24ee 100644 --- a/ets2panda/ir/expressions/importExpression.h +++ b/ets2panda/ir/expressions/importExpression.h @@ -29,8 +29,13 @@ public: explicit ImportExpression(Expression *source) : Expression(AstNodeType::IMPORT_EXPRESSION), source_(source) {} + Expression *Source() + { + return source_; + } + // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] Expression *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + [[nodiscard]] ImportExpression *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; diff --git a/ets2panda/ir/expressions/literals/bigIntLiteral.cpp b/ets2panda/ir/expressions/literals/bigIntLiteral.cpp index b59d2f83c9ae771c68c70ca915af97c031505b6d..5887c20cd73cb0fc8aebd1a34de9e631d1e5d146 100644 --- a/ets2panda/ir/expressions/literals/bigIntLiteral.cpp +++ b/ets2panda/ir/expressions/literals/bigIntLiteral.cpp @@ -51,7 +51,7 @@ checker::Type *BigIntLiteral::Check([[maybe_unused]] checker::ETSChecker *checke } // NOLINTNEXTLINE(google-default-arguments) -Expression *BigIntLiteral::Clone(ArenaAllocator *const allocator, AstNode *const parent) +BigIntLiteral *BigIntLiteral::Clone(ArenaAllocator *const allocator, AstNode *const parent) { if (auto *const clone = allocator->New(src_); clone != nullptr) { if (parent != nullptr) { diff --git a/ets2panda/ir/expressions/literals/bigIntLiteral.h b/ets2panda/ir/expressions/literals/bigIntLiteral.h index a017c4912ac80e3d975aa02b7b965edbae1793a1..32d4c40d30351f22165c52ebadbaa4c55e770d4e 100644 --- a/ets2panda/ir/expressions/literals/bigIntLiteral.h +++ b/ets2panda/ir/expressions/literals/bigIntLiteral.h @@ -36,7 +36,7 @@ public: } // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] Expression *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + [[nodiscard]] BigIntLiteral *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; diff --git a/ets2panda/ir/expressions/literals/booleanLiteral.cpp b/ets2panda/ir/expressions/literals/booleanLiteral.cpp index 81fc1cb14718f2c6e99534c32beca2b02f6e38fb..d73eed1c05f8c58868b7de42bc5e2e452b273e1e 100644 --- a/ets2panda/ir/expressions/literals/booleanLiteral.cpp +++ b/ets2panda/ir/expressions/literals/booleanLiteral.cpp @@ -54,7 +54,7 @@ checker::Type *BooleanLiteral::Check([[maybe_unused]] checker::ETSChecker *check } // NOLINTNEXTLINE(google-default-arguments) -Expression *BooleanLiteral::Clone(ArenaAllocator *const allocator, AstNode *const parent) +BooleanLiteral *BooleanLiteral::Clone(ArenaAllocator *const allocator, AstNode *const parent) { if (auto *const clone = allocator->New(boolean_); clone != nullptr) { if (parent != nullptr) { diff --git a/ets2panda/ir/expressions/literals/booleanLiteral.h b/ets2panda/ir/expressions/literals/booleanLiteral.h index 8643f5b573c262cff61edab9c12c9e406e5c1fb7..e2a69e617e72b01de88b1323c0ae24dea309540c 100644 --- a/ets2panda/ir/expressions/literals/booleanLiteral.h +++ b/ets2panda/ir/expressions/literals/booleanLiteral.h @@ -35,7 +35,7 @@ public: } // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] Expression *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + [[nodiscard]] BooleanLiteral *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; diff --git a/ets2panda/ir/expressions/literals/charLiteral.cpp b/ets2panda/ir/expressions/literals/charLiteral.cpp index 6596de257711f061e06f4395377b7ac1fea59ac0..4f333ee45fda52941941b61b3ec75a9600bee506 100644 --- a/ets2panda/ir/expressions/literals/charLiteral.cpp +++ b/ets2panda/ir/expressions/literals/charLiteral.cpp @@ -52,7 +52,7 @@ checker::Type *CharLiteral::Check([[maybe_unused]] checker::ETSChecker *checker) } // NOLINTNEXTLINE(google-default-arguments) -Expression *CharLiteral::Clone(ArenaAllocator *const allocator, AstNode *const parent) +CharLiteral *CharLiteral::Clone(ArenaAllocator *const allocator, AstNode *const parent) { if (auto *const clone = allocator->New(char_); clone != nullptr) { if (parent != nullptr) { diff --git a/ets2panda/ir/expressions/literals/charLiteral.h b/ets2panda/ir/expressions/literals/charLiteral.h index 048d73884fd2e5dad47d59ef47e11306d7af5867..f1bf1e8f105e8268c35cb28b040c8fe46dadc36d 100644 --- a/ets2panda/ir/expressions/literals/charLiteral.h +++ b/ets2panda/ir/expressions/literals/charLiteral.h @@ -41,7 +41,7 @@ public: } // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] Expression *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + [[nodiscard]] CharLiteral *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; diff --git a/ets2panda/ir/expressions/literals/nullLiteral.cpp b/ets2panda/ir/expressions/literals/nullLiteral.cpp index 10868ce8325bb18e32378cdc0cce05e2578a7ede..f04d88b766385a9e260d2f7cc285ff2736a5938d 100644 --- a/ets2panda/ir/expressions/literals/nullLiteral.cpp +++ b/ets2panda/ir/expressions/literals/nullLiteral.cpp @@ -15,11 +15,9 @@ #include "nullLiteral.h" -#include "compiler/core/pandagen.h" -#include "compiler/core/ETSGen.h" #include "checker/TSchecker.h" -#include "checker/ETSchecker.h" -#include "ir/astDump.h" +#include "compiler/core/ETSGen.h" +#include "compiler/core/pandagen.h" namespace panda::es2panda::ir { void NullLiteral::TransformChildren([[maybe_unused]] const NodeTransformer &cb) {} @@ -32,29 +30,26 @@ void NullLiteral::Dump(ir::AstDumper *dumper) const void NullLiteral::Compile(compiler::PandaGen *pg) const { - pg->LoadConst(this, compiler::Constant::JS_NULL); + pg->GetAstCompiler()->Compile(this); } void NullLiteral::Compile(compiler::ETSGen *etsg) const { - etsg->LoadAccumulatorNull(this, TsType()); + etsg->GetAstCompiler()->Compile(this); } checker::Type *NullLiteral::Check(checker::TSChecker *checker) { - return checker->GlobalNullType(); + return checker->GetAnalyzer()->Check(this); } -checker::Type *NullLiteral::Check([[maybe_unused]] checker::ETSChecker *checker) +checker::Type *NullLiteral::Check(checker::ETSChecker *checker) { - if (TsType() == nullptr) { - SetTsType(checker->GlobalETSNullType()); - } - return TsType(); + return checker->GetAnalyzer()->Check(this); } // NOLINTNEXTLINE(google-default-arguments) -Expression *NullLiteral::Clone(ArenaAllocator *const allocator, AstNode *const parent) +NullLiteral *NullLiteral::Clone(ArenaAllocator *const allocator, AstNode *const parent) { if (auto *const clone = allocator->New(); clone != nullptr) { if (parent != nullptr) { diff --git a/ets2panda/ir/expressions/literals/nullLiteral.h b/ets2panda/ir/expressions/literals/nullLiteral.h index 1fa60a74f0fa783d1d44d8106f99a51ea01d32c5..1fd823acca97cb1848e56d4cd3018b2621e06738 100644 --- a/ets2panda/ir/expressions/literals/nullLiteral.h +++ b/ets2panda/ir/expressions/literals/nullLiteral.h @@ -29,7 +29,7 @@ public: explicit NullLiteral() : Literal(AstNodeType::NULL_LITERAL) {} // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] Expression *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + [[nodiscard]] NullLiteral *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; @@ -37,7 +37,7 @@ public: void Compile(compiler::PandaGen *pg) const override; void Compile(compiler::ETSGen *etsg) const override; checker::Type *Check(checker::TSChecker *checker) override; - checker::Type *Check([[maybe_unused]] checker::ETSChecker *checker) override; + checker::Type *Check(checker::ETSChecker *checker) override; }; } // namespace panda::es2panda::ir diff --git a/ets2panda/ir/expressions/literals/numberLiteral.cpp b/ets2panda/ir/expressions/literals/numberLiteral.cpp index d411de92385590e1760a15ad0e1145ef357cb244..af42b4f5124cb49f114ad9383fa0336e0685bf90 100644 --- a/ets2panda/ir/expressions/literals/numberLiteral.cpp +++ b/ets2panda/ir/expressions/literals/numberLiteral.cpp @@ -15,12 +15,9 @@ #include "numberLiteral.h" -#include "util/helpers.h" -#include "compiler/core/pandagen.h" -#include "compiler/core/ETSGen.h" #include "checker/TSchecker.h" -#include "checker/ETSchecker.h" -#include "ir/astDump.h" +#include "compiler/core/ETSGen.h" +#include "compiler/core/pandagen.h" namespace panda::es2panda::ir { void NumberLiteral::TransformChildren([[maybe_unused]] const NodeTransformer &cb) {} @@ -33,85 +30,26 @@ void NumberLiteral::Dump(ir::AstDumper *dumper) const void NumberLiteral::Compile(compiler::PandaGen *pg) const { - if (std::isnan(number_.GetDouble())) { - pg->LoadConst(this, compiler::Constant::JS_NAN); - } else if (!std::isfinite(number_.GetDouble())) { - pg->LoadConst(this, compiler::Constant::JS_INFINITY); - } else if (util::Helpers::IsInteger(number_.GetDouble())) { - pg->LoadAccumulatorInt(this, static_cast(number_.GetDouble())); - } else { - pg->LoadAccumulatorDouble(this, number_.GetDouble()); - } + pg->GetAstCompiler()->Compile(this); } void NumberLiteral::Compile(compiler::ETSGen *etsg) const { - auto ttctx = compiler::TargetTypeContext(etsg, TsType()); - if (number_.IsInt()) { - if (util::Helpers::IsTargetFitInSourceRange( - number_.GetInt())) { - etsg->LoadAccumulatorByte(this, static_cast(number_.GetInt())); - return; - } - - if (util::Helpers::IsTargetFitInSourceRange( - number_.GetInt())) { - etsg->LoadAccumulatorShort(this, static_cast(number_.GetInt())); - return; - } - - etsg->LoadAccumulatorInt(this, static_cast(number_.GetInt())); - return; - } - - if (number_.IsLong()) { - etsg->LoadAccumulatorWideInt(this, number_.GetLong()); - return; - } - - if (number_.IsFloat()) { - etsg->LoadAccumulatorFloat(this, number_.GetFloat()); - return; - } - - etsg->LoadAccumulatorDouble(this, number_.GetDouble()); + etsg->GetAstCompiler()->Compile(this); } checker::Type *NumberLiteral::Check(checker::TSChecker *checker) { - auto search = checker->NumberLiteralMap().find(number_.GetDouble()); - if (search != checker->NumberLiteralMap().end()) { - return search->second; - } - - auto *new_num_literal_type = checker->Allocator()->New(number_.GetDouble()); - checker->NumberLiteralMap().insert({number_.GetDouble(), new_num_literal_type}); - return new_num_literal_type; + return checker->GetAnalyzer()->Check(this); } -checker::Type *NumberLiteral::Check([[maybe_unused]] checker::ETSChecker *checker) +checker::Type *NumberLiteral::Check(checker::ETSChecker *checker) { - if (number_.IsInt()) { - SetTsType(checker->CreateIntType(number_.GetInt())); - return TsType(); - } - - if (number_.IsLong()) { - SetTsType(checker->CreateLongType(number_.GetLong())); - return TsType(); - } - - if (number_.IsFloat()) { - SetTsType(checker->CreateFloatType(number_.GetFloat())); - return TsType(); - } - - SetTsType(checker->CreateDoubleType(number_.GetDouble())); - return TsType(); + return checker->GetAnalyzer()->Check(this); } // NOLINTNEXTLINE(google-default-arguments) -Expression *NumberLiteral::Clone(ArenaAllocator *const allocator, AstNode *const parent) +NumberLiteral *NumberLiteral::Clone(ArenaAllocator *const allocator, AstNode *const parent) { if (auto *const clone = allocator->New(number_); clone != nullptr) { if (parent != nullptr) { diff --git a/ets2panda/ir/expressions/literals/numberLiteral.h b/ets2panda/ir/expressions/literals/numberLiteral.h index e7391b8e40398b77f86ecd401c3e64d6517acdfa..00b97c52583aa580f2faa537b1c9c9106f0ad260 100644 --- a/ets2panda/ir/expressions/literals/numberLiteral.h +++ b/ets2panda/ir/expressions/literals/numberLiteral.h @@ -50,7 +50,7 @@ public: [[nodiscard]] bool HasFloatingPoint() const; // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] Expression *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + [[nodiscard]] NumberLiteral *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; @@ -58,7 +58,7 @@ public: void Compile(compiler::PandaGen *pg) const override; void Compile(compiler::ETSGen *etsg) const override; checker::Type *Check(checker::TSChecker *checker) override; - checker::Type *Check([[maybe_unused]] checker::ETSChecker *checker) override; + checker::Type *Check(checker::ETSChecker *checker) override; private: lexer::Number number_; diff --git a/ets2panda/ir/expressions/literals/regExpLiteral.cpp b/ets2panda/ir/expressions/literals/regExpLiteral.cpp index d278513f9fe09ca26e43472a2f48dc2ec46a2fbd..353d8fabb251a080ece8fdfb2bce87b42201acf2 100644 --- a/ets2panda/ir/expressions/literals/regExpLiteral.cpp +++ b/ets2panda/ir/expressions/literals/regExpLiteral.cpp @@ -19,7 +19,7 @@ #include "compiler/core/pandagen.h" #include "compiler/core/regScope.h" #include "checker/TSchecker.h" -#include "ir/astDump.h" +#include "compiler/core/ETSGen.h" namespace panda::es2panda::ir { void RegExpLiteral::TransformChildren([[maybe_unused]] const NodeTransformer &cb) {} @@ -32,21 +32,26 @@ void RegExpLiteral::Dump(ir::AstDumper *dumper) const void RegExpLiteral::Compile(compiler::PandaGen *pg) const { - pg->CreateRegExpWithLiteral(this, pattern_, static_cast(flags_)); + pg->GetAstCompiler()->Compile(this); +} + +void RegExpLiteral::Compile(compiler::ETSGen *etsg) const +{ + etsg->GetAstCompiler()->Compile(this); } checker::Type *RegExpLiteral::Check(checker::TSChecker *checker) { - return checker->GlobalAnyType(); + return checker->GetAnalyzer()->Check(this); } -checker::Type *RegExpLiteral::Check([[maybe_unused]] checker::ETSChecker *checker) +checker::Type *RegExpLiteral::Check(checker::ETSChecker *checker) { - return nullptr; + return checker->GetAnalyzer()->Check(this); } // NOLINTNEXTLINE(google-default-arguments) -Expression *RegExpLiteral::Clone(ArenaAllocator *const allocator, AstNode *const parent) +RegExpLiteral *RegExpLiteral::Clone(ArenaAllocator *const allocator, AstNode *const parent) { if (auto *const clone = allocator->New(pattern_, flags_, flags_str_); clone != nullptr) { if (parent != nullptr) { diff --git a/ets2panda/ir/expressions/literals/regExpLiteral.h b/ets2panda/ir/expressions/literals/regExpLiteral.h index 8ee1c453e535964d0a1c483a91f7f276a99d7e85..61ffde4bc4a96415c9f61aa9278dca433306683b 100644 --- a/ets2panda/ir/expressions/literals/regExpLiteral.h +++ b/ets2panda/ir/expressions/literals/regExpLiteral.h @@ -45,14 +45,15 @@ public: } // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] Expression *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + [[nodiscard]] RegExpLiteral *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; void Dump(ir::AstDumper *dumper) const override; void Compile(compiler::PandaGen *pg) const override; + void Compile(compiler::ETSGen *etsg) const override; checker::Type *Check(checker::TSChecker *checker) override; - checker::Type *Check([[maybe_unused]] checker::ETSChecker *checker) override; + checker::Type *Check(checker::ETSChecker *checker) override; private: util::StringView pattern_; diff --git a/ets2panda/ir/expressions/literals/stringLiteral.cpp b/ets2panda/ir/expressions/literals/stringLiteral.cpp index 2c45cb252ecda5adb8c4d5b410bef4345cf508af..1406de9d88d2740d1acc685cfea6bdffbb35e3da 100644 --- a/ets2panda/ir/expressions/literals/stringLiteral.cpp +++ b/ets2panda/ir/expressions/literals/stringLiteral.cpp @@ -15,11 +15,9 @@ #include "stringLiteral.h" -#include "compiler/core/pandagen.h" -#include "compiler/core/ETSGen.h" #include "checker/TSchecker.h" -#include "checker/ETSchecker.h" -#include "ir/astDump.h" +#include "compiler/core/ETSGen.h" +#include "compiler/core/pandagen.h" namespace panda::es2panda::ir { void StringLiteral::TransformChildren([[maybe_unused]] const NodeTransformer &cb) {} @@ -32,38 +30,26 @@ void StringLiteral::Dump(ir::AstDumper *dumper) const void StringLiteral::Compile(compiler::PandaGen *pg) const { - pg->LoadAccumulatorString(this, str_); + pg->GetAstCompiler()->Compile(this); } void StringLiteral::Compile(compiler::ETSGen *etsg) const { - etsg->LoadAccumulatorString(this, str_); - etsg->SetAccumulatorType(TsType()); + etsg->GetAstCompiler()->Compile(this); } checker::Type *StringLiteral::Check(checker::TSChecker *checker) { - auto search = checker->StringLiteralMap().find(str_); - if (search != checker->StringLiteralMap().end()) { - return search->second; - } - - auto *new_str_literal_type = checker->Allocator()->New(str_); - checker->StringLiteralMap().insert({str_, new_str_literal_type}); - - return new_str_literal_type; + return checker->GetAnalyzer()->Check(this); } -checker::Type *StringLiteral::Check([[maybe_unused]] checker::ETSChecker *checker) +checker::Type *StringLiteral::Check(checker::ETSChecker *checker) { - if (TsType() == nullptr) { - SetTsType(checker->CreateETSStringLiteralType(str_)); - } - return TsType(); + return checker->GetAnalyzer()->Check(this); } // NOLINTNEXTLINE(google-default-arguments) -Expression *StringLiteral::Clone(ArenaAllocator *const allocator, AstNode *const parent) +StringLiteral *StringLiteral::Clone(ArenaAllocator *const allocator, AstNode *const parent) { if (auto *const clone = allocator->New(str_); clone != nullptr) { if (parent != nullptr) { diff --git a/ets2panda/ir/expressions/literals/stringLiteral.h b/ets2panda/ir/expressions/literals/stringLiteral.h index da7f22fdadbab4187e7988f6e37c7e7fcf8041fb..a6191f8c641cffaeda2ff56f8b2620a2c8a685bd 100644 --- a/ets2panda/ir/expressions/literals/stringLiteral.h +++ b/ets2panda/ir/expressions/literals/stringLiteral.h @@ -42,7 +42,7 @@ public: } // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] Expression *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + [[nodiscard]] StringLiteral *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; @@ -50,7 +50,7 @@ public: void Compile(compiler::PandaGen *pg) const override; void Compile(compiler::ETSGen *etsg) const override; checker::Type *Check(checker::TSChecker *checker) override; - checker::Type *Check([[maybe_unused]] checker::ETSChecker *checker) override; + checker::Type *Check(checker::ETSChecker *checker) override; private: util::StringView str_; diff --git a/ets2panda/ir/expressions/memberExpression.cpp b/ets2panda/ir/expressions/memberExpression.cpp index 44936411def8039ca48d27983c70f5b50f85269e..c1e1349b8c9de0c9e036c48c9ee43c707164716b 100644 --- a/ets2panda/ir/expressions/memberExpression.cpp +++ b/ets2panda/ir/expressions/memberExpression.cpp @@ -15,28 +15,14 @@ #include "memberExpression.h" -#include "checker/types/typeRelation.h" #include "compiler/core/pandagen.h" #include "compiler/core/ETSGen.h" -#include "compiler/core/function.h" #include "checker/TSchecker.h" -#include "checker/ETSchecker.h" -#include "checker/types/ets/etsExtensionFuncHelperType.h" -#include "checker/types/ets/etsFunctionType.h" -#include "checker/types/signature.h" -#include "ir/astDump.h" -#include "ir/base/methodDefinition.h" -#include "ir/base/scriptFunction.h" -#include "ir/expressions/callExpression.h" -#include "ir/expressions/identifier.h" -#include "ir/expressions/literals/numberLiteral.h" -#include "ir/expressions/literals/stringLiteral.h" -#include "ir/ts/tsEnumMember.h" -#include "util/helpers.h" namespace panda::es2panda::ir { -MemberExpression::MemberExpression([[maybe_unused]] Tag const tag, Expression *const object, Expression *const property) - : MemberExpression(*this) +MemberExpression::MemberExpression([[maybe_unused]] Tag const tag, MemberExpression const &other, + Expression *const object, Expression *const property) + : MemberExpression(other) { object_ = object; if (object_ != nullptr) { @@ -240,10 +226,10 @@ void MemberExpression::Compile(compiler::ETSGen *etsg) const auto lang = object_type->AsETSDynamicType()->Language(); etsg->LoadPropertyDynamic(this, OptionalType(), obj_reg, prop_name, lang); } else if (object_type->IsETSUnionType()) { - etsg->LoadUnionProperty(this, OptionalType(), obj_reg, prop_name); + etsg->LoadUnionProperty(this, OptionalType(), IsGenericField(), obj_reg, prop_name); } else { const auto full_name = etsg->FormClassPropReference(object_type->AsETSObjectType(), prop_name); - etsg->LoadProperty(this, OptionalType(), obj_reg, full_name); + etsg->LoadProperty(this, OptionalType(), IsGenericField(), obj_reg, full_name); } }; @@ -465,16 +451,33 @@ checker::Type *MemberExpression::Check(checker::ETSChecker *checker) return AdjustOptional(checker, CheckUnionMember(checker, base_type)); } + if (base_type->HasTypeFlag(checker::TypeFlag::ETS_PRIMITIVE)) { + checker->Relation()->SetNode(this); + SetObjectType(checker->PrimitiveTypeAsETSBuiltinType(base_type)->AsETSObjectType()); + checker->AddBoxingUnboxingFlagToNode(this, obj_type_); + auto [res_type, res_var] = ResolveObjectMember(checker); + SetPropVar(res_var); + return AdjustOptional(checker, res_type); + } + checker->ThrowTypeError({"Cannot access property of non-object or non-enum type"}, object_->Start()); } // NOLINTNEXTLINE(google-default-arguments) -Expression *MemberExpression::Clone(ArenaAllocator *const allocator, AstNode *const parent) +MemberExpression *MemberExpression::Clone(ArenaAllocator *const allocator, AstNode *const parent) { - auto *const object = object_ != nullptr ? object_->Clone(allocator) : nullptr; - auto *const property = property_ != nullptr ? property_->Clone(allocator) : nullptr; - - if (auto *const clone = allocator->New(Tag {}, object, property); clone != nullptr) { + auto *const object = object_ != nullptr ? object_->Clone(allocator)->AsExpression() : nullptr; + auto *const property = property_ != nullptr ? property_->Clone(allocator)->AsExpression() : nullptr; + + if (auto *const clone = + allocator->New(object, property, kind_, computed_, MaybeOptionalExpression::IsOptional()); + clone != nullptr) { + if (object != nullptr) { + object->SetParent(clone); + } + if (property != nullptr) { + property->SetParent(clone); + } if (parent != nullptr) { clone->SetParent(parent); } @@ -483,4 +486,22 @@ Expression *MemberExpression::Clone(ArenaAllocator *const allocator, AstNode *co throw Error(ErrorType::GENERIC, "", CLONE_ALLOCATION_ERROR); } + +bool MemberExpression::IsGenericField() const +{ + const auto obj_t = object_->TsType(); + if (!obj_t->IsETSObjectType()) { + return false; + } + auto base_class_t = obj_t->AsETSObjectType()->GetBaseType(); + if (base_class_t == nullptr) { + return false; + } + const auto &prop_name = property_->AsIdentifier()->Name(); + auto base_prop = base_class_t->GetProperty(prop_name, checker::PropertySearchFlags::SEARCH_FIELD); + if (base_prop == nullptr || base_prop->TsType() == nullptr) { + return false; + } + return TsType()->ToAssemblerName().str() != base_prop->TsType()->ToAssemblerName().str(); +} } // namespace panda::es2panda::ir diff --git a/ets2panda/ir/expressions/memberExpression.h b/ets2panda/ir/expressions/memberExpression.h index 47c172e843045b4e1361a60898a1fbd5630f39b7..5deeabfe476ed3ad950d92cdf5b541477c1aa019 100644 --- a/ets2panda/ir/expressions/memberExpression.h +++ b/ets2panda/ir/expressions/memberExpression.h @@ -57,7 +57,7 @@ public: { } - explicit MemberExpression(Tag tag, Expression *object, Expression *property); + explicit MemberExpression(Tag tag, MemberExpression const &other, Expression *object, Expression *property); [[nodiscard]] Expression *Object() noexcept { @@ -142,7 +142,7 @@ public: [[nodiscard]] bool IsPrivateReference() const noexcept; // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] Expression *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + [[nodiscard]] MemberExpression *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; @@ -176,6 +176,8 @@ private: checker::Type *CheckUnionMember(checker::ETSChecker *checker, checker::Type *base_type); void LoadRhs(compiler::PandaGen *pg) const; + bool IsGenericField() const; + Expression *object_ = nullptr; Expression *property_ = nullptr; MemberExpressionKind kind_; diff --git a/ets2panda/ir/expressions/newExpression.cpp b/ets2panda/ir/expressions/newExpression.cpp index 565ba8caa42aac382506643a66d32de7706a6e23..ada998946446ca1934c1292feb440c4929caadf4 100644 --- a/ets2panda/ir/expressions/newExpression.cpp +++ b/ets2panda/ir/expressions/newExpression.cpp @@ -28,16 +28,16 @@ NewExpression::NewExpression([[maybe_unused]] Tag const tag, NewExpression const : Expression(static_cast(other)), arguments_(allocator->Adapter()) { if (other.callee_ != nullptr) { - callee_ = other.callee_->Clone(allocator, this); + callee_ = other.callee_->Clone(allocator, this)->AsExpression(); } for (auto *argument : other.arguments_) { - arguments_.emplace_back(argument->Clone(allocator, this)); + arguments_.emplace_back(argument->Clone(allocator, this)->AsExpression()); } } // NOLINTNEXTLINE(google-default-arguments) -Expression *NewExpression::Clone(ArenaAllocator *const allocator, AstNode *const parent) +NewExpression *NewExpression::Clone(ArenaAllocator *const allocator, AstNode *const parent) { if (auto *const clone = allocator->New(Tag {}, *this, allocator); clone != nullptr) { if (parent != nullptr) { diff --git a/ets2panda/ir/expressions/newExpression.h b/ets2panda/ir/expressions/newExpression.h index 2cefd3ce6d746341f26e6e2d26aca857bb0219c0..6fc447c38150639e107c1602e038233d3b586182 100644 --- a/ets2panda/ir/expressions/newExpression.h +++ b/ets2panda/ir/expressions/newExpression.h @@ -48,7 +48,7 @@ public: } // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] Expression *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + [[nodiscard]] NewExpression *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; diff --git a/ets2panda/ir/expressions/objectExpression.cpp b/ets2panda/ir/expressions/objectExpression.cpp index f3b4b4ebff09da14eb37d8fd2e2cedca2209ae1e..d39f3695ac9c118d2561341b11552ec063070a18 100644 --- a/ets2panda/ir/expressions/objectExpression.cpp +++ b/ets2panda/ir/expressions/objectExpression.cpp @@ -46,28 +46,26 @@ namespace panda::es2panda::ir { ObjectExpression::ObjectExpression([[maybe_unused]] Tag const tag, ObjectExpression const &other, ArenaAllocator *const allocator) - : AnnotatedExpression(static_cast(other)), + : AnnotatedExpression(static_cast(other), allocator), decorators_(allocator->Adapter()), properties_(allocator->Adapter()) { - CloneTypeAnnotation(allocator); - preferred_type_ = other.preferred_type_; is_declaration_ = other.is_declaration_; trailing_comma_ = other.trailing_comma_; optional_ = other.optional_; for (auto *property : other.properties_) { - properties_.emplace_back(property->Clone(allocator, this)); + properties_.emplace_back(property->Clone(allocator, this)->AsExpression()); } for (auto *decorator : other.decorators_) { - decorators_.emplace_back(decorator->Clone(allocator, this)->AsDecorator()); + decorators_.emplace_back(decorator->Clone(allocator, this)); } } // NOLINTNEXTLINE(google-default-arguments) -Expression *ObjectExpression::Clone(ArenaAllocator *const allocator, AstNode *const parent) +ObjectExpression *ObjectExpression::Clone(ArenaAllocator *const allocator, AstNode *const parent) { if (auto *const clone = allocator->New(Tag {}, *this, allocator); clone != nullptr) { if (parent != nullptr) { diff --git a/ets2panda/ir/expressions/objectExpression.h b/ets2panda/ir/expressions/objectExpression.h index b258313d0b93de38a1d3b55eab3cae03dfbc5123..3499814cca3c61b1c81f50e55ea9ade5a66f1ade 100644 --- a/ets2panda/ir/expressions/objectExpression.h +++ b/ets2panda/ir/expressions/objectExpression.h @@ -77,17 +77,26 @@ public: return decorators_; } + const ArenaVector *DecoratorsPtr() const override + { + return &Decorators(); + } + void AddDecorators([[maybe_unused]] ArenaVector &&decorators) override { decorators_ = std::move(decorators); } + bool CanHaveDecorator([[maybe_unused]] bool in_ts) const override + { + return true; + } + // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] Expression *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + [[nodiscard]] ObjectExpression *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; [[nodiscard]] ValidationInfo ValidateExpression(); [[nodiscard]] bool ConvertibleToObjectPattern(); - void SetDeclaration(); void SetOptional(bool optional); void TransformChildren(const NodeTransformer &cb) override; diff --git a/ets2panda/ir/expressions/omittedExpression.cpp b/ets2panda/ir/expressions/omittedExpression.cpp index b24ea45bebab63c11dc55a32528f0a71ea030e1e..ab2a356ac6b9b8ee39d989fc697c0cf6c348091b 100644 --- a/ets2panda/ir/expressions/omittedExpression.cpp +++ b/ets2panda/ir/expressions/omittedExpression.cpp @@ -40,7 +40,7 @@ checker::Type *OmittedExpression::Check([[maybe_unused]] checker::ETSChecker *ch } // NOLINTNEXTLINE(google-default-arguments) -Expression *OmittedExpression::Clone(ArenaAllocator *const allocator, AstNode *const parent) +OmittedExpression *OmittedExpression::Clone(ArenaAllocator *const allocator, AstNode *const parent) { if (auto *const clone = allocator->New(); clone != nullptr) { if (parent != nullptr) { diff --git a/ets2panda/ir/expressions/omittedExpression.h b/ets2panda/ir/expressions/omittedExpression.h index ee722bf0c336ee9e36d8d58fc9d017e7f02ca9db..20f7f5ead9e959abb84db7903320aebd3a0c81c7 100644 --- a/ets2panda/ir/expressions/omittedExpression.h +++ b/ets2panda/ir/expressions/omittedExpression.h @@ -31,7 +31,7 @@ public: void TransformChildren(const NodeTransformer &cb) override; // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] Expression *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + [[nodiscard]] OmittedExpression *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; void Iterate(const NodeTraverser &cb) const override; void Dump(ir::AstDumper *dumper) const override; diff --git a/ets2panda/ir/expressions/sequenceExpression.cpp b/ets2panda/ir/expressions/sequenceExpression.cpp index cde77a042f784b3d3574295e4c64f03e31ef02f6..f855c5826d318cf7049e68b19dce7948dc290a28 100644 --- a/ets2panda/ir/expressions/sequenceExpression.cpp +++ b/ets2panda/ir/expressions/sequenceExpression.cpp @@ -24,12 +24,12 @@ SequenceExpression::SequenceExpression([[maybe_unused]] Tag const tag, SequenceE : Expression(static_cast(other)), sequence_(allocator->Adapter()) { for (auto *sequence : other.sequence_) { - sequence_.emplace_back(sequence->Clone(allocator, this)); + sequence_.emplace_back(sequence->Clone(allocator, this)->AsExpression()); } } // NOLINTNEXTLINE(google-default-arguments) -Expression *SequenceExpression::Clone(ArenaAllocator *const allocator, AstNode *const parent) +SequenceExpression *SequenceExpression::Clone(ArenaAllocator *const allocator, AstNode *const parent) { if (auto *const clone = allocator->New(Tag {}, *this, allocator); clone != nullptr) { if (parent != nullptr) { diff --git a/ets2panda/ir/expressions/sequenceExpression.h b/ets2panda/ir/expressions/sequenceExpression.h index 29a1fd2aec43f64f48f98152123afb97c7f8a0d6..79e9974db8d061a6b10ca30193b9eea37c4cf63a 100644 --- a/ets2panda/ir/expressions/sequenceExpression.h +++ b/ets2panda/ir/expressions/sequenceExpression.h @@ -48,7 +48,7 @@ public: } // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] Expression *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + [[nodiscard]] SequenceExpression *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; diff --git a/ets2panda/ir/expressions/superExpression.cpp b/ets2panda/ir/expressions/superExpression.cpp index 8858bffbc9e4ff10e2b72a72c26d99b24b8b8f17..b7d291a57f39b93f74a0cd3b4f45b3c238fd4904 100644 --- a/ets2panda/ir/expressions/superExpression.cpp +++ b/ets2panda/ir/expressions/superExpression.cpp @@ -65,7 +65,7 @@ checker::Type *SuperExpression::Check([[maybe_unused]] checker::ETSChecker *chec } // NOLINTNEXTLINE(google-default-arguments) -Expression *SuperExpression::Clone(ArenaAllocator *const allocator, AstNode *const parent) +SuperExpression *SuperExpression::Clone(ArenaAllocator *const allocator, AstNode *const parent) { if (auto *const clone = allocator->New(); clone != nullptr) { if (parent != nullptr) { diff --git a/ets2panda/ir/expressions/superExpression.h b/ets2panda/ir/expressions/superExpression.h index 31b2835975906406105493339f80923749dc2e28..27d45416083710a98f04330679c5a7f43f2bcb7b 100644 --- a/ets2panda/ir/expressions/superExpression.h +++ b/ets2panda/ir/expressions/superExpression.h @@ -29,7 +29,7 @@ public: explicit SuperExpression() : Expression(AstNodeType::SUPER_EXPRESSION) {} // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] Expression *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + [[nodiscard]] SuperExpression *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; diff --git a/ets2panda/ir/expressions/taggedTemplateExpression.cpp b/ets2panda/ir/expressions/taggedTemplateExpression.cpp index 3960c0d1c3ee7c915b032ecb59f765e754cdf4d2..b68a413ab31afb6b1ea12d6e08e51467ae94f2bf 100644 --- a/ets2panda/ir/expressions/taggedTemplateExpression.cpp +++ b/ets2panda/ir/expressions/taggedTemplateExpression.cpp @@ -83,12 +83,11 @@ checker::Type *TaggedTemplateExpression::Check([[maybe_unused]] checker::ETSChec } // NOLINTNEXTLINE(google-default-arguments) -Expression *TaggedTemplateExpression::Clone(ArenaAllocator *const allocator, AstNode *const parent) +TaggedTemplateExpression *TaggedTemplateExpression::Clone(ArenaAllocator *const allocator, AstNode *const parent) { - auto *const tag = tag_ != nullptr ? tag_->Clone(allocator) : nullptr; - auto *const quasi = quasi_ != nullptr ? quasi_->Clone(allocator)->AsTemplateLiteral() : nullptr; - auto *const type_params = - type_params_ != nullptr ? type_params_->Clone(allocator)->AsTSTypeParameterInstantiation() : nullptr; + auto *const tag = tag_ != nullptr ? tag_->Clone(allocator)->AsExpression() : nullptr; + auto *const quasi = quasi_ != nullptr ? quasi_->Clone(allocator) : nullptr; + auto *const type_params = type_params_ != nullptr ? type_params_->Clone(allocator) : nullptr; if (auto *const clone = allocator->New(tag, quasi, type_params); clone != nullptr) { if (tag != nullptr) { diff --git a/ets2panda/ir/expressions/taggedTemplateExpression.h b/ets2panda/ir/expressions/taggedTemplateExpression.h index 194571cf79c12eda61595a57a64efd753b6d948c..6aeabf80f7bcebc9d807cfe829c990ec7c1e40d2 100644 --- a/ets2panda/ir/expressions/taggedTemplateExpression.h +++ b/ets2panda/ir/expressions/taggedTemplateExpression.h @@ -52,7 +52,7 @@ public: } // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] Expression *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + [[nodiscard]] TaggedTemplateExpression *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; diff --git a/ets2panda/ir/expressions/templateLiteral.cpp b/ets2panda/ir/expressions/templateLiteral.cpp index 82a52458f67c586989cd81b76cccedc736d56c51..61c58acd1ee21815bdafb39788b142d871287703 100644 --- a/ets2panda/ir/expressions/templateLiteral.cpp +++ b/ets2panda/ir/expressions/templateLiteral.cpp @@ -30,16 +30,16 @@ TemplateLiteral::TemplateLiteral([[maybe_unused]] Tag const tag, TemplateLiteral expressions_(allocator->Adapter()) { for (auto *quasy : other.quasis_) { - quasis_.emplace_back(quasy->Clone(allocator, this)->AsTemplateElement()); + quasis_.emplace_back(quasy->Clone(allocator, this)); } for (auto *expression : other.expressions_) { - expressions_.emplace_back(expression->Clone(allocator, this)); + expressions_.emplace_back(expression->Clone(allocator, this)->AsExpression()); } } // NOLINTNEXTLINE(google-default-arguments) -Expression *TemplateLiteral::Clone(ArenaAllocator *const allocator, AstNode *const parent) +TemplateLiteral *TemplateLiteral::Clone(ArenaAllocator *const allocator, AstNode *const parent) { if (auto *const clone = allocator->New(Tag {}, *this, allocator); clone != nullptr) { if (parent != nullptr) { diff --git a/ets2panda/ir/expressions/templateLiteral.h b/ets2panda/ir/expressions/templateLiteral.h index 3ec24e8007cc43548ee7074e6060b0ff1d30bc3c..bc2d31666dcfc2116ad025c3b5c2a9af7b73d47f 100644 --- a/ets2panda/ir/expressions/templateLiteral.h +++ b/ets2panda/ir/expressions/templateLiteral.h @@ -49,7 +49,7 @@ public: } // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] Expression *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + [[nodiscard]] TemplateLiteral *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; diff --git a/ets2panda/ir/expressions/thisExpression.cpp b/ets2panda/ir/expressions/thisExpression.cpp index 4bfd27544111932efed650ee506898500715312c..0c91e916486119c26058cbf27f381ee4c87ace5a 100644 --- a/ets2panda/ir/expressions/thisExpression.cpp +++ b/ets2panda/ir/expressions/thisExpression.cpp @@ -109,7 +109,7 @@ checker::Type *ThisExpression::Check(checker::ETSChecker *checker) } // NOLINTNEXTLINE(google-default-arguments) -Expression *ThisExpression::Clone(ArenaAllocator *const allocator, AstNode *const parent) +ThisExpression *ThisExpression::Clone(ArenaAllocator *const allocator, AstNode *const parent) { if (auto *const clone = allocator->New(); clone != nullptr) { if (parent != nullptr) { diff --git a/ets2panda/ir/expressions/thisExpression.h b/ets2panda/ir/expressions/thisExpression.h index a98f7f39df074533882dbf48b0053b24524724f1..6ffa359d07232aedc724f3e53b009f4f6d9fe493 100644 --- a/ets2panda/ir/expressions/thisExpression.h +++ b/ets2panda/ir/expressions/thisExpression.h @@ -29,7 +29,7 @@ public: explicit ThisExpression() : Expression(AstNodeType::THIS_EXPRESSION) {} // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] Expression *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + [[nodiscard]] ThisExpression *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; diff --git a/ets2panda/ir/expressions/unaryExpression.cpp b/ets2panda/ir/expressions/unaryExpression.cpp index 2f6ced1150f5be10b5062bbd0193e929d5722955..b9e2579f6586d106b32a2d6c45ce53ac3ee82c64 100644 --- a/ets2panda/ir/expressions/unaryExpression.cpp +++ b/ets2panda/ir/expressions/unaryExpression.cpp @@ -283,7 +283,7 @@ checker::Type *UnaryExpression::Check(checker::ETSChecker *checker) break; } - SetTsType(operand_type); + SetTsType(checker->GlobalETSBooleanType()); break; } case lexer::TokenType::PUNCTUATOR_DOLLAR_DOLLAR: { @@ -305,9 +305,9 @@ checker::Type *UnaryExpression::Check(checker::ETSChecker *checker) } // NOLINTNEXTLINE(google-default-arguments) -Expression *UnaryExpression::Clone(ArenaAllocator *const allocator, AstNode *const parent) +UnaryExpression *UnaryExpression::Clone(ArenaAllocator *const allocator, AstNode *const parent) { - auto *const argument = argument_ != nullptr ? argument_->Clone(allocator) : nullptr; + auto *const argument = argument_ != nullptr ? argument_->Clone(allocator)->AsExpression() : nullptr; if (auto *const clone = allocator->New(argument, operator_); clone != nullptr) { if (argument != nullptr) { diff --git a/ets2panda/ir/expressions/unaryExpression.h b/ets2panda/ir/expressions/unaryExpression.h index 1e2fb24c0b3e260332e46efe3022f22b27dd2987..ade78126852b73f78907de3db4bc4954627ca53e 100644 --- a/ets2panda/ir/expressions/unaryExpression.h +++ b/ets2panda/ir/expressions/unaryExpression.h @@ -54,7 +54,7 @@ public: } // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] Expression *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + [[nodiscard]] UnaryExpression *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; diff --git a/ets2panda/ir/expressions/updateExpression.cpp b/ets2panda/ir/expressions/updateExpression.cpp index e72ca193e8daeafe42af10f01d419cdbdc17b9f4..ae49e98ae65b35975ade9f7f3a03571012e813f3 100644 --- a/ets2panda/ir/expressions/updateExpression.cpp +++ b/ets2panda/ir/expressions/updateExpression.cpp @@ -149,9 +149,9 @@ checker::Type *UpdateExpression::Check(checker::ETSChecker *checker) } // NOLINTNEXTLINE(google-default-arguments) -Expression *UpdateExpression::Clone(ArenaAllocator *const allocator, AstNode *const parent) +UpdateExpression *UpdateExpression::Clone(ArenaAllocator *const allocator, AstNode *const parent) { - auto *const argument = argument_ != nullptr ? argument_->Clone(allocator) : nullptr; + auto *const argument = argument_ != nullptr ? argument_->Clone(allocator)->AsExpression() : nullptr; if (auto *const clone = allocator->New(argument, operator_, prefix_); clone != nullptr) { if (argument != nullptr) { diff --git a/ets2panda/ir/expressions/updateExpression.h b/ets2panda/ir/expressions/updateExpression.h index 34901b1845bbf46306de88a9c286b86845db85dd..494fbaf2981e13e3c443338068176a4fb929d465 100644 --- a/ets2panda/ir/expressions/updateExpression.h +++ b/ets2panda/ir/expressions/updateExpression.h @@ -54,7 +54,7 @@ public: } // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] Expression *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + [[nodiscard]] UpdateExpression *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; diff --git a/ets2panda/ir/expressions/yieldExpression.cpp b/ets2panda/ir/expressions/yieldExpression.cpp index 4aadc7a54582364feea1d450fdf0c06c3361bad6..465498c428b001ee02f60fd2e9cabb698570705b 100644 --- a/ets2panda/ir/expressions/yieldExpression.cpp +++ b/ets2panda/ir/expressions/yieldExpression.cpp @@ -70,9 +70,9 @@ checker::Type *YieldExpression::Check([[maybe_unused]] checker::ETSChecker *chec } // NOLINTNEXTLINE(google-default-arguments) -Expression *YieldExpression::Clone(ArenaAllocator *const allocator, AstNode *const parent) +YieldExpression *YieldExpression::Clone(ArenaAllocator *const allocator, AstNode *const parent) { - auto *const argument = argument_ != nullptr ? argument_->Clone(allocator) : nullptr; + auto *const argument = argument_ != nullptr ? argument_->Clone(allocator)->AsExpression() : nullptr; if (auto *const clone = allocator->New(argument, delegate_); clone != nullptr) { if (argument != nullptr) { diff --git a/ets2panda/ir/expressions/yieldExpression.h b/ets2panda/ir/expressions/yieldExpression.h index 9e8e85608b77f19cfcdf8a788394cb66af1fa9de..3c2f5282e2fc6549926d84443e13f0e9a8e1fc23 100644 --- a/ets2panda/ir/expressions/yieldExpression.h +++ b/ets2panda/ir/expressions/yieldExpression.h @@ -47,7 +47,7 @@ public: } // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] Expression *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + [[nodiscard]] YieldExpression *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; diff --git a/ets2panda/ir/module/exportAllDeclaration.cpp b/ets2panda/ir/module/exportAllDeclaration.cpp index 9867f99848a1b6bac1430a33d5f7a758011eb814..c34cb356e49c57204f7920e1862daed02a77ec6d 100644 --- a/ets2panda/ir/module/exportAllDeclaration.cpp +++ b/ets2panda/ir/module/exportAllDeclaration.cpp @@ -15,9 +15,9 @@ #include "exportAllDeclaration.h" -#include "ir/astDump.h" -#include "ir/expressions/identifier.h" -#include "ir/expressions/literals/stringLiteral.h" +#include "checker/TSchecker.h" +#include "compiler/core/ETSGen.h" +#include "compiler/core/pandagen.h" namespace panda::es2panda::ir { void ExportAllDeclaration::TransformChildren(const NodeTransformer &cb) @@ -43,15 +43,23 @@ void ExportAllDeclaration::Dump(ir::AstDumper *dumper) const dumper->Add({{"type", "ExportAllDeclaration"}, {"source", source_}, {"exported", AstDumper::Nullish(exported_)}}); } -void ExportAllDeclaration::Compile([[maybe_unused]] compiler::PandaGen *pg) const {} +void ExportAllDeclaration::Compile(compiler::PandaGen *pg) const +{ + pg->GetAstCompiler()->Compile(this); +} + +void ExportAllDeclaration::Compile(compiler::ETSGen *etsg) const +{ + etsg->GetAstCompiler()->Compile(this); +} -checker::Type *ExportAllDeclaration::Check([[maybe_unused]] checker::TSChecker *checker) +checker::Type *ExportAllDeclaration::Check(checker::TSChecker *checker) { - return nullptr; + return checker->GetAnalyzer()->Check(this); } -checker::Type *ExportAllDeclaration::Check([[maybe_unused]] checker::ETSChecker *checker) +checker::Type *ExportAllDeclaration::Check(checker::ETSChecker *checker) { - return nullptr; + return checker->GetAnalyzer()->Check(this); } } // namespace panda::es2panda::ir diff --git a/ets2panda/ir/module/exportAllDeclaration.h b/ets2panda/ir/module/exportAllDeclaration.h index afcdea02dc0642a422c4a88e6935da6cfaafb38e..89926b4ec8ba4af0a07361fcf324be8611a1eedb 100644 --- a/ets2panda/ir/module/exportAllDeclaration.h +++ b/ets2panda/ir/module/exportAllDeclaration.h @@ -42,9 +42,10 @@ public: void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; void Dump(ir::AstDumper *dumper) const override; - void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; - checker::Type *Check([[maybe_unused]] checker::TSChecker *checker) override; - checker::Type *Check([[maybe_unused]] checker::ETSChecker *checker) override; + void Compile(compiler::PandaGen *pg) const override; + void Compile(compiler::ETSGen *etsg) const override; + checker::Type *Check(checker::TSChecker *checker) override; + checker::Type *Check(checker::ETSChecker *checker) override; private: StringLiteral *source_; diff --git a/ets2panda/ir/module/exportDefaultDeclaration.cpp b/ets2panda/ir/module/exportDefaultDeclaration.cpp index 657179005ad193df5ed6ec2b95386b1f2c72077f..82e090025be581f9ea29b24ed39d83d1c7bc210f 100644 --- a/ets2panda/ir/module/exportDefaultDeclaration.cpp +++ b/ets2panda/ir/module/exportDefaultDeclaration.cpp @@ -15,8 +15,9 @@ #include "exportDefaultDeclaration.h" +#include "checker/TSchecker.h" +#include "compiler/core/ETSGen.h" #include "compiler/core/pandagen.h" -#include "ir/astDump.h" namespace panda::es2panda::ir { void ExportDefaultDeclaration::TransformChildren(const NodeTransformer &cb) @@ -35,19 +36,23 @@ void ExportDefaultDeclaration::Dump(ir::AstDumper *dumper) const {{"type", IsExportEquals() ? "TSExportAssignment" : "ExportDefaultDeclaration"}, {"declaration", decl_}}); } -void ExportDefaultDeclaration::Compile([[maybe_unused]] compiler::PandaGen *pg) const +void ExportDefaultDeclaration::Compile(compiler::PandaGen *pg) const { - decl_->Compile(pg); - pg->StoreModuleVar(this, "default"); + pg->GetAstCompiler()->Compile(this); } -checker::Type *ExportDefaultDeclaration::Check([[maybe_unused]] checker::TSChecker *checker) +void ExportDefaultDeclaration::Compile(compiler::ETSGen *etsg) const { - return nullptr; + etsg->GetAstCompiler()->Compile(this); } -checker::Type *ExportDefaultDeclaration::Check([[maybe_unused]] checker::ETSChecker *checker) +checker::Type *ExportDefaultDeclaration::Check(checker::TSChecker *checker) { - return nullptr; + return checker->GetAnalyzer()->Check(this); +} + +checker::Type *ExportDefaultDeclaration::Check(checker::ETSChecker *checker) +{ + return checker->GetAnalyzer()->Check(this); } } // namespace panda::es2panda::ir diff --git a/ets2panda/ir/module/exportDefaultDeclaration.h b/ets2panda/ir/module/exportDefaultDeclaration.h index 38af658d5fd2109cc40f22b083b4cf0526b5b33a..6d32882db58427972a6495ba267d3c04cb356173 100644 --- a/ets2panda/ir/module/exportDefaultDeclaration.h +++ b/ets2panda/ir/module/exportDefaultDeclaration.h @@ -44,9 +44,10 @@ public: void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; void Dump(ir::AstDumper *dumper) const override; - void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; - checker::Type *Check([[maybe_unused]] checker::TSChecker *checker) override; - checker::Type *Check([[maybe_unused]] checker::ETSChecker *checker) override; + void Compile(compiler::PandaGen *pg) const override; + void Compile(compiler::ETSGen *etsg) const override; + checker::Type *Check(checker::TSChecker *checker) override; + checker::Type *Check(checker::ETSChecker *checker) override; private: AstNode *decl_; diff --git a/ets2panda/ir/module/exportNamedDeclaration.cpp b/ets2panda/ir/module/exportNamedDeclaration.cpp index 5bbd501593ea5ebbc42befcf2b5d8808ecb93f0d..ff886326fd879b9e8fe06e74fdf6dde74a11d3d6 100644 --- a/ets2panda/ir/module/exportNamedDeclaration.cpp +++ b/ets2panda/ir/module/exportNamedDeclaration.cpp @@ -15,12 +15,9 @@ #include "exportNamedDeclaration.h" -#include "compiler/core/pandagen.h" +#include "checker/TSchecker.h" #include "compiler/core/ETSGen.h" -#include "ir/astDump.h" -#include "ir/base/decorator.h" -#include "ir/expressions/literals/stringLiteral.h" -#include "ir/module/exportSpecifier.h" +#include "compiler/core/pandagen.h" namespace panda::es2panda::ir { void ExportNamedDeclaration::TransformChildren(const NodeTransformer &cb) @@ -70,27 +67,23 @@ void ExportNamedDeclaration::Dump(ir::AstDumper *dumper) const {"specifiers", specifiers_}}); } -void ExportNamedDeclaration::Compile([[maybe_unused]] compiler::PandaGen *pg) const +void ExportNamedDeclaration::Compile(compiler::PandaGen *pg) const { - if (decl_ == nullptr) { - return; - } - - decl_->Compile(pg); + pg->GetAstCompiler()->Compile(this); } -void ExportNamedDeclaration::Compile([[maybe_unused]] compiler::ETSGen *etsg) const +void ExportNamedDeclaration::Compile(compiler::ETSGen *etsg) const { - UNREACHABLE(); + etsg->GetAstCompiler()->Compile(this); } -checker::Type *ExportNamedDeclaration::Check([[maybe_unused]] checker::TSChecker *checker) +checker::Type *ExportNamedDeclaration::Check(checker::TSChecker *checker) { - return nullptr; + return checker->GetAnalyzer()->Check(this); } -checker::Type *ExportNamedDeclaration::Check([[maybe_unused]] checker::ETSChecker *checker) +checker::Type *ExportNamedDeclaration::Check(checker::ETSChecker *checker) { - return nullptr; + return checker->GetAnalyzer()->Check(this); } } // namespace panda::es2panda::ir diff --git a/ets2panda/ir/module/exportNamedDeclaration.h b/ets2panda/ir/module/exportNamedDeclaration.h index e794931975cb496b4ff75af645ee64f51e014fb2..f455b8985e6a3c51e15f4bd2832950257da1806c 100644 --- a/ets2panda/ir/module/exportNamedDeclaration.h +++ b/ets2panda/ir/module/exportNamedDeclaration.h @@ -78,10 +78,10 @@ public: void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; void Dump(ir::AstDumper *dumper) const override; - void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; - void Compile([[maybe_unused]] compiler::ETSGen *etsg) const override; - checker::Type *Check([[maybe_unused]] checker::TSChecker *checker) override; - checker::Type *Check([[maybe_unused]] checker::ETSChecker *checker) override; + void Compile(compiler::PandaGen *pg) const override; + void Compile(compiler::ETSGen *etsg) const override; + checker::Type *Check(checker::TSChecker *checker) override; + checker::Type *Check(checker::ETSChecker *checker) override; private: ArenaVector decorators_; diff --git a/ets2panda/ir/module/exportSpecifier.cpp b/ets2panda/ir/module/exportSpecifier.cpp index e308dd2b06e10d8ac06045377dea3290fad64075..2aa19dee82c77cf7cb630552fde92cc83c183f9c 100644 --- a/ets2panda/ir/module/exportSpecifier.cpp +++ b/ets2panda/ir/module/exportSpecifier.cpp @@ -15,8 +15,9 @@ #include "exportSpecifier.h" -#include "ir/astDump.h" -#include "ir/expressions/identifier.h" +#include "checker/TSchecker.h" +#include "compiler/core/ETSGen.h" +#include "compiler/core/pandagen.h" namespace panda::es2panda::ir { void ExportSpecifier::TransformChildren(const NodeTransformer &cb) @@ -36,15 +37,23 @@ void ExportSpecifier::Dump(ir::AstDumper *dumper) const dumper->Add({{"type", "ExportSpecifier"}, {"local", local_}, {"exported", exported_}}); } -void ExportSpecifier::Compile([[maybe_unused]] compiler::PandaGen *pg) const {} +void ExportSpecifier::Compile(compiler::PandaGen *pg) const +{ + pg->GetAstCompiler()->Compile(this); +} + +void ExportSpecifier::Compile(compiler::ETSGen *etsg) const +{ + etsg->GetAstCompiler()->Compile(this); +} -checker::Type *ExportSpecifier::Check([[maybe_unused]] checker::TSChecker *checker) +checker::Type *ExportSpecifier::Check(checker::TSChecker *checker) { - return nullptr; + return checker->GetAnalyzer()->Check(this); } -checker::Type *ExportSpecifier::Check([[maybe_unused]] checker::ETSChecker *checker) +checker::Type *ExportSpecifier::Check(checker::ETSChecker *checker) { - return nullptr; + return checker->GetAnalyzer()->Check(this); } } // namespace panda::es2panda::ir diff --git a/ets2panda/ir/module/exportSpecifier.h b/ets2panda/ir/module/exportSpecifier.h index f6bfefbd9f576fc633d063ff5ac4fa8df07eba16..d50d2bee59f714f3f87dc48258fd4c268bfe6a74 100644 --- a/ets2panda/ir/module/exportSpecifier.h +++ b/ets2panda/ir/module/exportSpecifier.h @@ -41,9 +41,10 @@ public: void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; void Dump(ir::AstDumper *dumper) const override; - void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; - checker::Type *Check([[maybe_unused]] checker::TSChecker *checker) override; - checker::Type *Check([[maybe_unused]] checker::ETSChecker *checker) override; + void Compile(compiler::PandaGen *pg) const override; + void Compile(compiler::ETSGen *etsg) const override; + checker::Type *Check(checker::TSChecker *checker) override; + checker::Type *Check(checker::ETSChecker *checker) override; private: Identifier *local_; diff --git a/ets2panda/ir/module/importDeclaration.cpp b/ets2panda/ir/module/importDeclaration.cpp index b946fbd1b679d90f467435cc458cbd68d79a3dbe..e1208b0d02a56bb3b2eb6ba72753ec14817a2ede 100644 --- a/ets2panda/ir/module/importDeclaration.cpp +++ b/ets2panda/ir/module/importDeclaration.cpp @@ -15,11 +15,9 @@ #include "importDeclaration.h" +#include "checker/TSchecker.h" #include "compiler/core/ETSGen.h" -#include "ir/astDump.h" -#include "ir/expressions/literals/stringLiteral.h" -#include "ir/module/importNamespaceSpecifier.h" -#include "ir/module/importSpecifier.h" +#include "compiler/core/pandagen.h" namespace panda::es2panda::ir { void ImportDeclaration::TransformChildren(const NodeTransformer &cb) @@ -45,27 +43,23 @@ void ImportDeclaration::Dump(ir::AstDumper *dumper) const dumper->Add({{"type", "ImportDeclaration"}, {"source", source_}, {"specifiers", specifiers_}}); } -void ImportDeclaration::Compile([[maybe_unused]] compiler::PandaGen *pg) const {} - -void ImportDeclaration::Compile([[maybe_unused]] compiler::ETSGen *etsg) const +void ImportDeclaration::Compile(compiler::PandaGen *pg) const { - UNREACHABLE(); + pg->GetAstCompiler()->Compile(this); } -checker::Type *ImportDeclaration::Check([[maybe_unused]] checker::TSChecker *checker) +void ImportDeclaration::Compile(compiler::ETSGen *etsg) const { - return nullptr; + etsg->GetAstCompiler()->Compile(this); } -checker::Type *ImportDeclaration::Check([[maybe_unused]] checker::ETSChecker *checker) +checker::Type *ImportDeclaration::Check(checker::TSChecker *checker) { - checker::Type *type = nullptr; - for (auto *spec : specifiers_) { - if (spec->IsImportNamespaceSpecifier()) { - type = spec->AsImportNamespaceSpecifier()->Check(checker); - } - } + return checker->GetAnalyzer()->Check(this); +} - return type; +checker::Type *ImportDeclaration::Check(checker::ETSChecker *checker) +{ + return checker->GetAnalyzer()->Check(this); } } // namespace panda::es2panda::ir diff --git a/ets2panda/ir/module/importDeclaration.h b/ets2panda/ir/module/importDeclaration.h index 18594b35e398f98c9fe13b2b31e26f42c2272922..fc8e923882bad9d6d0b209670f82e88cf8a5f284 100644 --- a/ets2panda/ir/module/importDeclaration.h +++ b/ets2panda/ir/module/importDeclaration.h @@ -47,10 +47,10 @@ public: void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; void Dump(ir::AstDumper *dumper) const override; - void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; - void Compile([[maybe_unused]] compiler::ETSGen *etsg) const override; - checker::Type *Check([[maybe_unused]] checker::TSChecker *checker) override; - checker::Type *Check([[maybe_unused]] checker::ETSChecker *checker) override; + void Compile(compiler::PandaGen *pg) const override; + void Compile(compiler::ETSGen *etsg) const override; + checker::Type *Check(checker::TSChecker *checker) override; + checker::Type *Check(checker::ETSChecker *checker) override; private: StringLiteral *source_; diff --git a/ets2panda/ir/module/importDefaultSpecifier.cpp b/ets2panda/ir/module/importDefaultSpecifier.cpp index 2413efb897afcfa10a9ee7636f5f788fa027f7a9..ea4a43b93e199df6aa0178d0fbca81eb82e89459 100644 --- a/ets2panda/ir/module/importDefaultSpecifier.cpp +++ b/ets2panda/ir/module/importDefaultSpecifier.cpp @@ -15,11 +15,9 @@ #include "importDefaultSpecifier.h" -#include "checker/ETSchecker.h" -#include "ir/astDump.h" -#include "ir/expressions/identifier.h" -#include "ir/module/importDeclaration.h" -#include "ir/expressions/literals/stringLiteral.h" +#include "checker/TSchecker.h" +#include "compiler/core/ETSGen.h" +#include "compiler/core/pandagen.h" namespace panda::es2panda::ir { void ImportDefaultSpecifier::TransformChildren(const NodeTransformer &cb) @@ -37,15 +35,23 @@ void ImportDefaultSpecifier::Dump(ir::AstDumper *dumper) const dumper->Add({{"type", "ImportDefaultSpecifier"}, {"local", local_}}); } -void ImportDefaultSpecifier::Compile([[maybe_unused]] compiler::PandaGen *pg) const {} +void ImportDefaultSpecifier::Compile(compiler::PandaGen *pg) const +{ + pg->GetAstCompiler()->Compile(this); +} + +void ImportDefaultSpecifier::Compile(compiler::ETSGen *etsg) const +{ + etsg->GetAstCompiler()->Compile(this); +} -checker::Type *ImportDefaultSpecifier::Check([[maybe_unused]] checker::TSChecker *checker) +checker::Type *ImportDefaultSpecifier::Check(checker::TSChecker *checker) { - return nullptr; + return checker->GetAnalyzer()->Check(this); } -checker::Type *ImportDefaultSpecifier::Check([[maybe_unused]] checker::ETSChecker *checker) +checker::Type *ImportDefaultSpecifier::Check(checker::ETSChecker *checker) { - return nullptr; + return checker->GetAnalyzer()->Check(this); } } // namespace panda::es2panda::ir diff --git a/ets2panda/ir/module/importDefaultSpecifier.h b/ets2panda/ir/module/importDefaultSpecifier.h index 7d39425a088c59f202e41c07c2acbc619f0478d3..0ad73508467408f9477946cf9ec2a776aac1a244 100644 --- a/ets2panda/ir/module/importDefaultSpecifier.h +++ b/ets2panda/ir/module/importDefaultSpecifier.h @@ -35,9 +35,10 @@ public: void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; void Dump(ir::AstDumper *dumper) const override; - void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; - checker::Type *Check([[maybe_unused]] checker::TSChecker *checker) override; - checker::Type *Check([[maybe_unused]] checker::ETSChecker *checker) override; + void Compile(compiler::PandaGen *pg) const override; + void Compile(compiler::ETSGen *etsg) const override; + checker::Type *Check(checker::TSChecker *checker) override; + checker::Type *Check(checker::ETSChecker *checker) override; private: Identifier *local_; diff --git a/ets2panda/ir/module/importNamespaceSpecifier.cpp b/ets2panda/ir/module/importNamespaceSpecifier.cpp index 9607da9ba6a098627b7b78b4c0d9d03a15096575..44660316c6ed0e0860617c2d976c7e8f2a24316b 100644 --- a/ets2panda/ir/module/importNamespaceSpecifier.cpp +++ b/ets2panda/ir/module/importNamespaceSpecifier.cpp @@ -15,12 +15,10 @@ #include "importNamespaceSpecifier.h" -#include "checker/ETSchecker.h" #include "varbinder/ETSBinder.h" -#include "ir/astDump.h" -#include "ir/expressions/identifier.h" -#include "ir/module/importDeclaration.h" -#include "ir/expressions/literals/stringLiteral.h" +#include "checker/TSchecker.h" +#include "compiler/core/ETSGen.h" +#include "compiler/core/pandagen.h" namespace panda::es2panda::ir { void ImportNamespaceSpecifier::TransformChildren(const NodeTransformer &cb) @@ -38,81 +36,23 @@ void ImportNamespaceSpecifier::Dump(ir::AstDumper *dumper) const dumper->Add({{"type", "ImportNamespaceSpecifier"}, {"local", local_}}); } -void ImportNamespaceSpecifier::Compile([[maybe_unused]] compiler::PandaGen *pg) const {} - -checker::Type *ImportNamespaceSpecifier::Check([[maybe_unused]] checker::TSChecker *checker) +void ImportNamespaceSpecifier::Compile(compiler::PandaGen *pg) const { - return nullptr; + pg->GetAstCompiler()->Compile(this); } -checker::Type *ImportNamespaceSpecifier::Check([[maybe_unused]] checker::ETSChecker *checker) +void ImportNamespaceSpecifier::Compile(compiler::ETSGen *etsg) const { - if (Local()->Name().Empty()) { - return nullptr; - } - - if (Local()->AsIdentifier()->TsType() != nullptr) { - return local_->TsType(); - } - - auto *import_decl = Parent()->AsETSImportDeclaration(); - auto import_path = import_decl->Source()->Str(); - - if (import_decl->IsPureDynamic()) { - auto *type = checker->GlobalBuiltinDynamicType(import_decl->Language()); - checker->SetrModuleObjectTsType(local_, type); - return type; - } - - std::string package_name = - (import_decl->Module() == nullptr) ? import_path.Mutf8() : import_decl->Module()->Str().Mutf8(); - - std::replace(package_name.begin(), package_name.end(), '/', '.'); - util::UString package_path(package_name, checker->Allocator()); - std::vector synthetic_names = checker->GetNameForSynteticObjectType(package_path.View()); - - ASSERT(!synthetic_names.empty()); - - auto assembler_name = synthetic_names[0]; - if (import_decl->Module() != nullptr) { - assembler_name = util::UString(assembler_name.Mutf8().append(".").append(compiler::Signatures::ETS_GLOBAL), - checker->Allocator()) - .View(); - } - - auto *module_object_type = - checker->Allocator()->New(checker->Allocator(), synthetic_names[0], assembler_name, - local_->AsIdentifier(), checker::ETSObjectFlags::CLASS); - - auto *root_decl = checker->Allocator()->New(synthetic_names[0]); - varbinder::LocalVariable *root_var = - checker->Allocator()->New(root_decl, varbinder::VariableFlags::NONE); - root_var->SetTsType(module_object_type); - - synthetic_names.erase(synthetic_names.begin()); - checker::ETSObjectType *last_object_type(module_object_type); - - for (const auto &synthetic_name : synthetic_names) { - auto *synthetic_obj_type = - checker->Allocator()->New(checker->Allocator(), synthetic_name, synthetic_name, - local_->AsIdentifier(), checker::ETSObjectFlags::NO_OPTS); - - auto *class_decl = checker->Allocator()->New(synthetic_name); - varbinder::LocalVariable *var = - checker->Allocator()->New(class_decl, varbinder::VariableFlags::CLASS); - var->SetTsType(synthetic_obj_type); - last_object_type->AddProperty(var); - synthetic_obj_type->SetEnclosingType(last_object_type); - last_object_type = synthetic_obj_type; - } + etsg->GetAstCompiler()->Compile(this); +} - checker->SetPropertiesForModuleObject( - last_object_type, - (import_decl->Module() != nullptr) - ? util::UString(import_path.Mutf8() + import_decl->Module()->Str().Mutf8(), checker->Allocator()).View() - : import_path); - checker->SetrModuleObjectTsType(local_, last_object_type); +checker::Type *ImportNamespaceSpecifier::Check(checker::TSChecker *checker) +{ + return checker->GetAnalyzer()->Check(this); +} - return module_object_type; +checker::Type *ImportNamespaceSpecifier::Check(checker::ETSChecker *checker) +{ + return checker->GetAnalyzer()->Check(this); } } // namespace panda::es2panda::ir diff --git a/ets2panda/ir/module/importNamespaceSpecifier.h b/ets2panda/ir/module/importNamespaceSpecifier.h index 0af20262ba57e28274a7974262ef5ca60a22978a..e725cce1aef38761c90498c64939d19eeabf2c45 100644 --- a/ets2panda/ir/module/importNamespaceSpecifier.h +++ b/ets2panda/ir/module/importNamespaceSpecifier.h @@ -41,9 +41,10 @@ public: void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; void Dump(ir::AstDumper *dumper) const override; - void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; - checker::Type *Check([[maybe_unused]] checker::TSChecker *checker) override; - checker::Type *Check([[maybe_unused]] checker::ETSChecker *checker) override; + void Compile(compiler::PandaGen *pg) const override; + void Compile(compiler::ETSGen *etsg) const override; + checker::Type *Check(checker::TSChecker *checker) override; + checker::Type *Check(checker::ETSChecker *checker) override; private: Identifier *local_; diff --git a/ets2panda/ir/module/importSpecifier.cpp b/ets2panda/ir/module/importSpecifier.cpp index 343614347e2e30cb5af932d939965a43cac4ba45..984e4137d5861c8b746bb2fc0bbe2a63f02e5559 100644 --- a/ets2panda/ir/module/importSpecifier.cpp +++ b/ets2panda/ir/module/importSpecifier.cpp @@ -15,11 +15,9 @@ #include "importSpecifier.h" +#include "checker/TSchecker.h" #include "compiler/core/ETSGen.h" -#include "ir/astDump.h" -#include "ir/expressions/identifier.h" -#include "ir/expressions/literals/stringLiteral.h" -#include "ir/module/importDeclaration.h" +#include "compiler/core/pandagen.h" namespace panda::es2panda::ir { void ImportSpecifier::TransformChildren(const NodeTransformer &cb) @@ -43,19 +41,22 @@ void ImportSpecifier::Dump(ir::AstDumper *dumper) const dumper->Add({{"type", "ImportSpecifier"}, {"local", ir::AstDumper::Optional(local_)}, {"imported", imported_}}); } -void ImportSpecifier::Compile([[maybe_unused]] compiler::PandaGen *pg) const {} -void ImportSpecifier::Compile([[maybe_unused]] compiler::ETSGen *etsg) const +void ImportSpecifier::Compile(compiler::PandaGen *pg) const { - UNREACHABLE(); + pg->GetAstCompiler()->Compile(this); +} +void ImportSpecifier::Compile(compiler::ETSGen *etsg) const +{ + etsg->GetAstCompiler()->Compile(this); } -checker::Type *ImportSpecifier::Check([[maybe_unused]] checker::TSChecker *checker) +checker::Type *ImportSpecifier::Check(checker::TSChecker *checker) { - return nullptr; + return checker->GetAnalyzer()->Check(this); } -checker::Type *ImportSpecifier::Check([[maybe_unused]] checker::ETSChecker *checker) +checker::Type *ImportSpecifier::Check(checker::ETSChecker *checker) { - return nullptr; + return checker->GetAnalyzer()->Check(this); } } // namespace panda::es2panda::ir diff --git a/ets2panda/ir/module/importSpecifier.h b/ets2panda/ir/module/importSpecifier.h index 9a0c1311abb9eee8973fb19ac1479b050cfabe99..c59fba3bed65f9dadc3658fc27678a920357a5c9 100644 --- a/ets2panda/ir/module/importSpecifier.h +++ b/ets2panda/ir/module/importSpecifier.h @@ -51,10 +51,10 @@ public: void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; void Dump(ir::AstDumper *dumper) const override; - void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; - void Compile([[maybe_unused]] compiler::ETSGen *etsg) const override; - checker::Type *Check([[maybe_unused]] checker::TSChecker *checker) override; - checker::Type *Check([[maybe_unused]] checker::ETSChecker *checker) override; + void Compile(compiler::PandaGen *pg) const override; + void Compile(compiler::ETSGen *etsg) const override; + checker::Type *Check(checker::TSChecker *checker) override; + checker::Type *Check(checker::ETSChecker *checker) override; private: Identifier *imported_; diff --git a/ets2panda/ir/statement.cpp b/ets2panda/ir/statement.cpp index 8eb886a24eab5ca13ccc2fd3120d1c20620b2d7c..6fcc6723374f857d2dd6bb20db2f3522ded344be 100644 --- a/ets2panda/ir/statement.cpp +++ b/ets2panda/ir/statement.cpp @@ -17,11 +17,4 @@ #include "typeNode.h" namespace panda::es2panda::ir { -void AnnotatedStatement::CloneTypeAnnotation(ArenaAllocator *const allocator) -{ - if (auto *annotation = const_cast(TypeAnnotation()); annotation != nullptr) { - SetTsTypeAnnotation(annotation->Clone(allocator, this)->AsTypeNode()); - } -} - } // namespace panda::es2panda::ir diff --git a/ets2panda/ir/statement.h b/ets2panda/ir/statement.h index 76e05d1d4bf3c4b6365e58329741e29455b92e6a..bc98848eaac97e4ad1756cccb6b58a9143735c77 100644 --- a/ets2panda/ir/statement.h +++ b/ets2panda/ir/statement.h @@ -36,14 +36,6 @@ public: virtual void SetReturnType([[maybe_unused]] checker::ETSChecker *checker, [[maybe_unused]] checker::Type *type) {} - // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] virtual Statement *Clone([[maybe_unused]] ArenaAllocator *const allocator, - [[maybe_unused]] AstNode *const parent = nullptr) - { - UNREACHABLE(); - return nullptr; - } - protected: explicit Statement(AstNodeType type) : AstNode(type) {} explicit Statement(AstNodeType type, ModifierFlags flags) : AstNode(type, flags) {} @@ -88,8 +80,6 @@ protected: : Annotated(static_cast const &>(other)) { } - - void CloneTypeAnnotation(ArenaAllocator *allocator); }; } // namespace panda::es2panda::ir diff --git a/ets2panda/ir/statements/classDeclaration.cpp b/ets2panda/ir/statements/classDeclaration.cpp index 6c0822d5f27188bd9be8fa96bf140895ef367ece..627e9bece0a42037e8d65b33e331a28d9073671d 100644 --- a/ets2panda/ir/statements/classDeclaration.cpp +++ b/ets2panda/ir/statements/classDeclaration.cpp @@ -15,13 +15,9 @@ #include "classDeclaration.h" -#include "compiler/base/lreference.h" -#include "compiler/core/pandagen.h" +#include "checker/TSchecker.h" #include "compiler/core/ETSGen.h" -#include "ir/astDump.h" -#include "ir/base/classDefinition.h" -#include "ir/base/decorator.h" -#include "ir/expressions/identifier.h" +#include "compiler/core/pandagen.h" namespace panda::es2panda::ir { void ClassDeclaration::TransformChildren(const NodeTransformer &cb) @@ -47,26 +43,23 @@ void ClassDeclaration::Dump(ir::AstDumper *dumper) const dumper->Add({{"type", "ClassDeclaration"}, {"definition", def_}, {"decorators", AstDumper::Optional(decorators_)}}); } -void ClassDeclaration::Compile([[maybe_unused]] compiler::PandaGen *pg) const +void ClassDeclaration::Compile(compiler::PandaGen *pg) const { - auto lref = compiler::JSLReference::Create(pg, def_->Ident(), true); - def_->Compile(pg); - lref.SetValue(); + pg->GetAstCompiler()->Compile(this); } -void ClassDeclaration::Compile([[maybe_unused]] compiler::ETSGen *etsg) const +void ClassDeclaration::Compile(compiler::ETSGen *etsg) const { - UNREACHABLE(); + etsg->GetAstCompiler()->Compile(this); } -checker::Type *ClassDeclaration::Check([[maybe_unused]] checker::TSChecker *checker) +checker::Type *ClassDeclaration::Check(checker::TSChecker *checker) { - return nullptr; + return checker->GetAnalyzer()->Check(this); } checker::Type *ClassDeclaration::Check(checker::ETSChecker *checker) { - def_->Check(checker); - return nullptr; + return checker->GetAnalyzer()->Check(this); } } // namespace panda::es2panda::ir diff --git a/ets2panda/ir/statements/classDeclaration.h b/ets2panda/ir/statements/classDeclaration.h index c2e535c0740205f0be808f6d4e772d51b8f8e7b1..41d4bb4f6c83d64fa03a480f34ab393a74e595ff 100644 --- a/ets2panda/ir/statements/classDeclaration.h +++ b/ets2panda/ir/statements/classDeclaration.h @@ -41,6 +41,11 @@ public: return decorators_; } + const ArenaVector *DecoratorsPtr() const override + { + return &Decorators(); + } + void AddDecorators(ArenaVector &&decorators) override { decorators_ = std::move(decorators); @@ -54,11 +59,11 @@ public: void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; void Dump(ir::AstDumper *dumper) const override; - void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; - void Compile([[maybe_unused]] compiler::ETSGen *etsg) const override; + void Compile(compiler::PandaGen *pg) const override; + void Compile(compiler::ETSGen *etsg) const override; - checker::Type *Check([[maybe_unused]] checker::TSChecker *checker) override; - checker::Type *Check([[maybe_unused]] checker::ETSChecker *checker) override; + checker::Type *Check(checker::TSChecker *checker) override; + checker::Type *Check(checker::ETSChecker *checker) override; private: ClassDefinition *def_; diff --git a/ets2panda/ir/statements/continueStatement.cpp b/ets2panda/ir/statements/continueStatement.cpp index 74536dc361990216d18cc453b69cb7bc40b21b77..da58f870ae1043602b4e21bcb8460c06f4742262 100644 --- a/ets2panda/ir/statements/continueStatement.cpp +++ b/ets2panda/ir/statements/continueStatement.cpp @@ -15,10 +15,9 @@ #include "continueStatement.h" -#include "compiler/core/pandagen.h" +#include "checker/TSchecker.h" #include "compiler/core/ETSGen.h" -#include "ir/astDump.h" -#include "checker/ETSchecker.h" +#include "compiler/core/pandagen.h" namespace panda::es2panda::ir { void ContinueStatement::TransformChildren(const NodeTransformer &cb) @@ -40,34 +39,23 @@ void ContinueStatement::Dump(ir::AstDumper *dumper) const dumper->Add({{"type", "ContinueStatement"}, {"label", AstDumper::Nullish(ident_)}}); } -template -void CompileImpl(const ContinueStatement *self, [[maybe_unused]] CodeGen *cg) -{ - compiler::Label *target = cg->ControlFlowChangeContinue(self->Ident()); - cg->Branch(self, target); -} - -void ContinueStatement::Compile([[maybe_unused]] compiler::PandaGen *pg) const +void ContinueStatement::Compile(compiler::PandaGen *pg) const { - CompileImpl(this, pg); + pg->GetAstCompiler()->Compile(this); } -void ContinueStatement::Compile([[maybe_unused]] compiler::ETSGen *etsg) const +void ContinueStatement::Compile(compiler::ETSGen *etsg) const { - if (etsg->ExtendWithFinalizer(parent_, this)) { - return; - } - CompileImpl(this, etsg); + etsg->GetAstCompiler()->Compile(this); } -checker::Type *ContinueStatement::Check([[maybe_unused]] checker::TSChecker *checker) +checker::Type *ContinueStatement::Check(checker::TSChecker *checker) { - return nullptr; + return checker->GetAnalyzer()->Check(this); } checker::Type *ContinueStatement::Check(checker::ETSChecker *checker) { - target_ = checker->FindJumpTarget(Type(), this, ident_); - return nullptr; + return checker->GetAnalyzer()->Check(this); } } // namespace panda::es2panda::ir diff --git a/ets2panda/ir/statements/continueStatement.h b/ets2panda/ir/statements/continueStatement.h index 2eead3db014edee313f4d7df437480dc734736f2..4468f9e76b0e8d51d521619c0951a482f7225535 100644 --- a/ets2panda/ir/statements/continueStatement.h +++ b/ets2panda/ir/statements/continueStatement.h @@ -19,12 +19,24 @@ #include "ir/statement.h" #include "ir/expressions/identifier.h" +namespace panda::es2panda::checker { +class ETSAnalyzer; +} // namespace panda::es2panda::checker + +namespace panda::es2panda::compiler { +class ETSCompiler; +} // namespace panda::es2panda::compiler + namespace panda::es2panda::ir { class ContinueStatement : public Statement { public: explicit ContinueStatement() : Statement(AstNodeType::CONTINUE_STATEMENT) {} explicit ContinueStatement(Identifier *ident) : Statement(AstNodeType::CONTINUE_STATEMENT), ident_(ident) {} + // NOTE (csabahurton): these friend relationships can be removed once there are getters for private fields + friend class checker::ETSAnalyzer; + friend class compiler::ETSCompiler; + const Identifier *Ident() const { return ident_; @@ -38,10 +50,10 @@ public: void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; void Dump(ir::AstDumper *dumper) const override; - void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; - void Compile([[maybe_unused]] compiler::ETSGen *etsg) const override; - checker::Type *Check([[maybe_unused]] checker::TSChecker *checker) override; - checker::Type *Check([[maybe_unused]] checker::ETSChecker *checker) override; + void Compile(compiler::PandaGen *pg) const override; + void Compile(compiler::ETSGen *etsg) const override; + checker::Type *Check(checker::TSChecker *checker) override; + checker::Type *Check(checker::ETSChecker *checker) override; private: Identifier *ident_ {}; diff --git a/ets2panda/ir/statements/debuggerStatement.cpp b/ets2panda/ir/statements/debuggerStatement.cpp index 506daf50ae480818324ae2a6532fa1dc2cd1ba5b..b0bb23faadd70a585650ec54cd7d21c5988d5c0f 100644 --- a/ets2panda/ir/statements/debuggerStatement.cpp +++ b/ets2panda/ir/statements/debuggerStatement.cpp @@ -15,7 +15,9 @@ #include "debuggerStatement.h" -#include "ir/astDump.h" +#include "checker/TSchecker.h" +#include "compiler/core/ETSGen.h" +#include "compiler/core/pandagen.h" namespace panda::es2panda::ir { void DebuggerStatement::TransformChildren([[maybe_unused]] const NodeTransformer &cb) {} @@ -26,15 +28,23 @@ void DebuggerStatement::Dump(ir::AstDumper *dumper) const dumper->Add({{"type", "DebuggerStatement"}}); } -void DebuggerStatement::Compile([[maybe_unused]] compiler::PandaGen *pg) const {} +void DebuggerStatement::Compile(compiler::PandaGen *pg) const +{ + pg->GetAstCompiler()->Compile(this); +} + +void DebuggerStatement::Compile(compiler::ETSGen *etsg) const +{ + etsg->GetAstCompiler()->Compile(this); +} -checker::Type *DebuggerStatement::Check([[maybe_unused]] checker::TSChecker *checker) +checker::Type *DebuggerStatement::Check(checker::TSChecker *checker) { - return nullptr; + return checker->GetAnalyzer()->Check(this); } -checker::Type *DebuggerStatement::Check([[maybe_unused]] checker::ETSChecker *checker) +checker::Type *DebuggerStatement::Check(checker::ETSChecker *checker) { - return nullptr; + return checker->GetAnalyzer()->Check(this); } } // namespace panda::es2panda::ir diff --git a/ets2panda/ir/statements/debuggerStatement.h b/ets2panda/ir/statements/debuggerStatement.h index d9858dbfd48308a8c4f381539a0c05f9936ab209..792af73b967f1e99bf3c29aa1a3b22ffe6e35131 100644 --- a/ets2panda/ir/statements/debuggerStatement.h +++ b/ets2panda/ir/statements/debuggerStatement.h @@ -26,9 +26,10 @@ public: void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; void Dump(ir::AstDumper *dumper) const override; - void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; - checker::Type *Check([[maybe_unused]] checker::TSChecker *checker) override; - checker::Type *Check([[maybe_unused]] checker::ETSChecker *checker) override; + void Compile(compiler::PandaGen *pg) const override; + void Compile(compiler::ETSGen *etsg) const override; + checker::Type *Check(checker::TSChecker *checker) override; + checker::Type *Check(checker::ETSChecker *checker) override; private: }; diff --git a/ets2panda/ir/statements/doWhileStatement.cpp b/ets2panda/ir/statements/doWhileStatement.cpp index e36442c438d676836f8e153234cd403a5ea8ac23..93d2a413e6a8e2efabe04fa0d386c38083230573 100644 --- a/ets2panda/ir/statements/doWhileStatement.cpp +++ b/ets2panda/ir/statements/doWhileStatement.cpp @@ -21,8 +21,6 @@ #include "compiler/core/pandagen.h" #include "compiler/core/ETSGen.h" #include "checker/TSchecker.h" -#include "ir/astDump.h" -#include "ir/expression.h" namespace panda::es2panda::ir { void DoWhileStatement::TransformChildren(const NodeTransformer &cb) @@ -42,55 +40,23 @@ void DoWhileStatement::Dump(ir::AstDumper *dumper) const dumper->Add({{"type", "DoWhileStatement"}, {"body", body_}, {"test", test_}}); } -template -void CompileImpl(const DoWhileStatement *self, [[maybe_unused]] CodeGen *cg) +void DoWhileStatement::Compile(compiler::PandaGen *pg) const { - auto *start_label = cg->AllocLabel(); - compiler::LabelTarget label_target(cg); - - cg->SetLabel(self, start_label); - - { - compiler::LocalRegScope reg_scope(cg, self->Scope()); - compiler::LabelContext label_ctx(cg, label_target); - self->Body()->Compile(cg); - } - - cg->SetLabel(self, label_target.ContinueTarget()); - compiler::Condition::Compile(cg, self->Test(), label_target.BreakTarget()); - - cg->Branch(self, start_label); - cg->SetLabel(self, label_target.BreakTarget()); + pg->GetAstCompiler()->Compile(this); } -void DoWhileStatement::Compile([[maybe_unused]] compiler::PandaGen *pg) const +void DoWhileStatement::Compile(compiler::ETSGen *etsg) const { - CompileImpl(this, pg); + etsg->GetAstCompiler()->Compile(this); } -void DoWhileStatement::Compile([[maybe_unused]] compiler::ETSGen *etsg) const +checker::Type *DoWhileStatement::Check(checker::TSChecker *checker) { - CompileImpl(this, etsg); + return checker->GetAnalyzer()->Check(this); } -checker::Type *DoWhileStatement::Check([[maybe_unused]] checker::TSChecker *checker) +checker::Type *DoWhileStatement::Check(checker::ETSChecker *checker) { - checker::ScopeContext scope_ctx(checker, Scope()); - - checker::Type *test_type = Test()->Check(checker); - checker->CheckTruthinessOfType(test_type, Test()->Start()); - Body()->Check(checker); - - return nullptr; -} - -checker::Type *DoWhileStatement::Check([[maybe_unused]] checker::ETSChecker *checker) -{ - checker::ScopeContext scope_ctx(checker, Scope()); - - checker->CheckTruthinessOfType(Test()); - Body()->Check(checker); - - return nullptr; + return checker->GetAnalyzer()->Check(this); } } // namespace panda::es2panda::ir diff --git a/ets2panda/ir/statements/doWhileStatement.h b/ets2panda/ir/statements/doWhileStatement.h index 58b970bfdcecebd33c19ab6b66e1d7fcb69ce851..bc811edca2c361e570539a30fa61467242c010c3 100644 --- a/ets2panda/ir/statements/doWhileStatement.h +++ b/ets2panda/ir/statements/doWhileStatement.h @@ -62,10 +62,10 @@ public: void Iterate(const NodeTraverser &cb) const override; void Dump(ir::AstDumper *dumper) const override; - void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; - void Compile([[maybe_unused]] compiler::ETSGen *etsg) const override; - checker::Type *Check([[maybe_unused]] checker::TSChecker *checker) override; - checker::Type *Check([[maybe_unused]] checker::ETSChecker *checker) override; + void Compile(compiler::PandaGen *pg) const override; + void Compile(compiler::ETSGen *etsg) const override; + checker::Type *Check(checker::TSChecker *checker) override; + checker::Type *Check(checker::ETSChecker *checker) override; private: Statement *body_; diff --git a/ets2panda/ir/statements/emptyStatement.cpp b/ets2panda/ir/statements/emptyStatement.cpp index 5da09fdd2284bad2b67f115767bb55cd0e163517..4c00f2a89ee6f42aea577b5c9121229994a54b11 100644 --- a/ets2panda/ir/statements/emptyStatement.cpp +++ b/ets2panda/ir/statements/emptyStatement.cpp @@ -15,7 +15,9 @@ #include "emptyStatement.h" -#include "ir/astDump.h" +#include "checker/TSchecker.h" +#include "compiler/core/ETSGen.h" +#include "compiler/core/pandagen.h" namespace panda::es2panda::ir { void EmptyStatement::TransformChildren([[maybe_unused]] const NodeTransformer &cb) {} @@ -26,15 +28,23 @@ void EmptyStatement::Dump(ir::AstDumper *dumper) const dumper->Add({{"type", "EmptyStatement"}}); } -void EmptyStatement::Compile([[maybe_unused]] compiler::PandaGen *pg) const {} +void EmptyStatement::Compile(compiler::PandaGen *pg) const +{ + pg->GetAstCompiler()->Compile(this); +} + +void EmptyStatement::Compile(compiler::ETSGen *etsg) const +{ + etsg->GetAstCompiler()->Compile(this); +} -checker::Type *EmptyStatement::Check([[maybe_unused]] checker::TSChecker *checker) +checker::Type *EmptyStatement::Check(checker::TSChecker *checker) { - return nullptr; + return checker->GetAnalyzer()->Check(this); } -checker::Type *EmptyStatement::Check([[maybe_unused]] checker::ETSChecker *checker) +checker::Type *EmptyStatement::Check(checker::ETSChecker *checker) { - return nullptr; + return checker->GetAnalyzer()->Check(this); } } // namespace panda::es2panda::ir diff --git a/ets2panda/ir/statements/emptyStatement.h b/ets2panda/ir/statements/emptyStatement.h index 44c82b2fba26420907ff6388cb687a08da889b22..a815449fbadf23621f73dfd5ba1ba21070799c57 100644 --- a/ets2panda/ir/statements/emptyStatement.h +++ b/ets2panda/ir/statements/emptyStatement.h @@ -26,9 +26,10 @@ public: void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; void Dump(ir::AstDumper *dumper) const override; - void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; - checker::Type *Check([[maybe_unused]] checker::TSChecker *checker) override; - checker::Type *Check([[maybe_unused]] checker::ETSChecker *checker) override; + void Compile(compiler::PandaGen *pg) const override; + void Compile(compiler::ETSGen *etsg) const override; + checker::Type *Check(checker::TSChecker *checker) override; + checker::Type *Check(checker::ETSChecker *checker) override; private: }; diff --git a/ets2panda/ir/statements/expressionStatement.cpp b/ets2panda/ir/statements/expressionStatement.cpp index 61ebaca008147e8c817413c5420f97726aaa5de2..d4750832be8cdad6688db5c3f34f4f80185336df 100644 --- a/ets2panda/ir/statements/expressionStatement.cpp +++ b/ets2panda/ir/statements/expressionStatement.cpp @@ -15,8 +15,9 @@ #include "expressionStatement.h" -#include "ir/astDump.h" -#include "ir/expression.h" +#include "checker/TSchecker.h" +#include "compiler/core/ETSGen.h" +#include "compiler/core/pandagen.h" namespace panda::es2panda::ir { void ExpressionStatement::TransformChildren(const NodeTransformer &cb) @@ -34,23 +35,23 @@ void ExpressionStatement::Dump(ir::AstDumper *dumper) const dumper->Add({{"type", "ExpressionStatement"}, {"expression", expression_}}); } -void ExpressionStatement::Compile([[maybe_unused]] compiler::PandaGen *pg) const +void ExpressionStatement::Compile(compiler::PandaGen *pg) const { - expression_->Compile(pg); + pg->GetAstCompiler()->Compile(this); } -void ExpressionStatement::Compile([[maybe_unused]] compiler::ETSGen *etsg) const +void ExpressionStatement::Compile(compiler::ETSGen *etsg) const { - expression_->Compile(etsg); + etsg->GetAstCompiler()->Compile(this); } -checker::Type *ExpressionStatement::Check([[maybe_unused]] checker::TSChecker *checker) +checker::Type *ExpressionStatement::Check(checker::TSChecker *checker) { - return expression_->Check(checker); + return checker->GetAnalyzer()->Check(this); } -checker::Type *ExpressionStatement::Check([[maybe_unused]] checker::ETSChecker *checker) +checker::Type *ExpressionStatement::Check(checker::ETSChecker *checker) { - return expression_->Check(checker); + return checker->GetAnalyzer()->Check(this); } } // namespace panda::es2panda::ir diff --git a/ets2panda/ir/statements/expressionStatement.h b/ets2panda/ir/statements/expressionStatement.h index 2f80d87221946a812a42877339724d51be7cad30..56ea20363273428ddb7a53d833ecd72818830d1f 100644 --- a/ets2panda/ir/statements/expressionStatement.h +++ b/ets2panda/ir/statements/expressionStatement.h @@ -38,10 +38,10 @@ public: void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; void Dump(ir::AstDumper *dumper) const override; - void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; - void Compile([[maybe_unused]] compiler::ETSGen *etsg) const override; - checker::Type *Check([[maybe_unused]] checker::TSChecker *checker) override; - checker::Type *Check([[maybe_unused]] checker::ETSChecker *checker) override; + void Compile(compiler::PandaGen *pg) const override; + void Compile(compiler::ETSGen *etsg) const override; + checker::Type *Check(checker::TSChecker *checker) override; + checker::Type *Check(checker::ETSChecker *checker) override; private: Expression *expression_; diff --git a/ets2panda/ir/statements/forInStatement.cpp b/ets2panda/ir/statements/forInStatement.cpp index b21b387e5d819c361781df5ef246153ef6dd3d6d..331be2f2fff94081c1ae8d4b1b8527e784c91c1a 100644 --- a/ets2panda/ir/statements/forInStatement.cpp +++ b/ets2panda/ir/statements/forInStatement.cpp @@ -20,9 +20,7 @@ #include "compiler/core/labelTarget.h" #include "compiler/core/pandagen.h" #include "checker/TSchecker.h" - -#include "ir/astDump.h" -#include "ir/expression.h" +#include "compiler/core/ETSGen.h" namespace panda::es2panda::ir { void ForInStatement::TransformChildren(const NodeTransformer &cb) @@ -44,49 +42,23 @@ void ForInStatement::Dump(ir::AstDumper *dumper) const dumper->Add({{"type", "ForInStatement"}, {"left", left_}, {"right", right_}, {"body", body_}}); } -void ForInStatement::Compile([[maybe_unused]] compiler::PandaGen *pg) const +void ForInStatement::Compile(compiler::PandaGen *pg) const { - compiler::LabelTarget label_target(pg); - - compiler::RegScope rs(pg); - compiler::VReg iter = pg->AllocReg(); - compiler::VReg prop_name = pg->AllocReg(); - - // create enumerator - right_->Compile(pg); - pg->GetPropIterator(this); - pg->StoreAccumulator(this, iter); - - pg->SetLabel(this, label_target.ContinueTarget()); - - // get next prop of enumerator - pg->GetNextPropName(this, iter); - pg->StoreAccumulator(this, prop_name); - pg->BranchIfUndefined(this, label_target.BreakTarget()); - - compiler::LocalRegScope decl_reg_scope(pg, Scope()->DeclScope()->InitScope()); - auto lref = compiler::JSLReference::Create(pg, left_, false); - pg->LoadAccumulator(this, prop_name); - lref.SetValue(); - - compiler::LoopEnvScope decl_env_scope(pg, Scope()->DeclScope()); - - { - compiler::LoopEnvScope env_scope(pg, Scope(), label_target); - body_->Compile(pg); - } + pg->GetAstCompiler()->Compile(this); +} - pg->Branch(this, label_target.ContinueTarget()); - pg->SetLabel(this, label_target.BreakTarget()); +void ForInStatement::Compile(compiler::ETSGen *etsg) const +{ + etsg->GetAstCompiler()->Compile(this); } -checker::Type *ForInStatement::Check([[maybe_unused]] checker::TSChecker *checker) +checker::Type *ForInStatement::Check(checker::TSChecker *checker) { - return nullptr; + return checker->GetAnalyzer()->Check(this); } -checker::Type *ForInStatement::Check([[maybe_unused]] checker::ETSChecker *checker) +checker::Type *ForInStatement::Check(checker::ETSChecker *checker) { - return nullptr; + return checker->GetAnalyzer()->Check(this); } } // namespace panda::es2panda::ir diff --git a/ets2panda/ir/statements/forInStatement.h b/ets2panda/ir/statements/forInStatement.h index 1089e3ffa4875d5b9040c3d74c90e07c7c9dc9f0..78d482e827d98b8884b84ddea5abec50275b01ef 100644 --- a/ets2panda/ir/statements/forInStatement.h +++ b/ets2panda/ir/statements/forInStatement.h @@ -72,9 +72,10 @@ public: void Iterate(const NodeTraverser &cb) const override; void Dump(ir::AstDumper *dumper) const override; - void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; - checker::Type *Check([[maybe_unused]] checker::TSChecker *checker) override; - checker::Type *Check([[maybe_unused]] checker::ETSChecker *checker) override; + void Compile(compiler::PandaGen *pg) const override; + void Compile(compiler::ETSGen *etsg) const override; + checker::Type *Check(checker::TSChecker *checker) override; + checker::Type *Check(checker::ETSChecker *checker) override; private: AstNode *left_; diff --git a/ets2panda/ir/statements/forOfStatement.cpp b/ets2panda/ir/statements/forOfStatement.cpp index 1b7ae5a7cc17222bc20fb1a1eda01b3978f74d1f..50cb1e9d1c9e63c719ed6236d68ed35d2f2d12e8 100644 --- a/ets2panda/ir/statements/forOfStatement.cpp +++ b/ets2panda/ir/statements/forOfStatement.cpp @@ -19,14 +19,9 @@ #include "compiler/base/iterators.h" #include "compiler/base/lreference.h" #include "compiler/core/labelTarget.h" +#include "checker/TSchecker.h" #include "compiler/core/pandagen.h" #include "compiler/core/ETSGen.h" -#include "ir/astDump.h" -#include "ir/expression.h" -#include "ir/expressions/identifier.h" -#include "ir/expressions/superExpression.h" -#include "ir/statements/variableDeclarator.h" -#include "ir/statements/variableDeclaration.h" namespace panda::es2panda::ir { void ForOfStatement::TransformChildren(const NodeTransformer &cb) @@ -49,176 +44,23 @@ void ForOfStatement::Dump(ir::AstDumper *dumper) const {{"type", "ForOfStatement"}, {"await", is_await_}, {"left", left_}, {"right", right_}, {"body", body_}}); } -void ForOfStatement::Compile([[maybe_unused]] compiler::PandaGen *pg) const +void ForOfStatement::Compile(compiler::PandaGen *pg) const { - compiler::LocalRegScope decl_reg_scope(pg, Scope()->DeclScope()->InitScope()); - - right_->Compile(pg); - - compiler::LabelTarget label_target(pg); - auto iterator_type = is_await_ ? compiler::IteratorType::ASYNC : compiler::IteratorType::SYNC; - compiler::Iterator iterator(pg, this, iterator_type); - - pg->SetLabel(this, label_target.ContinueTarget()); - - iterator.Next(); - iterator.Complete(); - pg->BranchIfTrue(this, label_target.BreakTarget()); - - iterator.Value(); - pg->StoreAccumulator(this, iterator.NextResult()); - - auto lref = compiler::JSLReference::Create(pg, left_, false); - - { - compiler::IteratorContext for_of_ctx(pg, iterator, label_target); - pg->LoadAccumulator(this, iterator.NextResult()); - lref.SetValue(); - - compiler::LoopEnvScope decl_env_scope(pg, Scope()->DeclScope()); - compiler::LoopEnvScope env_scope(pg, Scope(), {}); - body_->Compile(pg); - } - - pg->Branch(this, label_target.ContinueTarget()); - pg->SetLabel(this, label_target.BreakTarget()); + pg->GetAstCompiler()->Compile(this); } void ForOfStatement::Compile(compiler::ETSGen *etsg) const { - compiler::LocalRegScope decl_reg_scope(etsg, Scope()->DeclScope()->InitScope()); - - checker::Type const *const expr_type = right_->TsType(); - ASSERT(expr_type->IsETSArrayType() || expr_type->IsETSStringType()); - - right_->Compile(etsg); - compiler::VReg obj_reg = etsg->AllocReg(); - etsg->StoreAccumulator(this, obj_reg); - - if (expr_type->IsETSArrayType()) { - etsg->LoadArrayLength(this, obj_reg); - } else { - etsg->LoadStringLength(this); - } - - compiler::VReg size_reg = etsg->AllocReg(); - etsg->StoreAccumulator(this, size_reg); - - compiler::LabelTarget label_target(etsg); - auto label_ctx = compiler::LabelContext(etsg, label_target); - - etsg->BranchIfFalse(this, label_target.BreakTarget()); - - compiler::VReg count_reg = etsg->AllocReg(); - etsg->MoveImmediateToRegister(this, count_reg, checker::TypeFlag::INT, static_cast(0)); - etsg->LoadAccumulatorInt(this, static_cast(0)); - - auto *const start_label = etsg->AllocLabel(); - etsg->SetLabel(this, start_label); - - auto lref = compiler::ETSLReference::Create(etsg, left_, false); - - if (right_->TsType()->IsETSArrayType()) { - etsg->LoadArrayElement(this, obj_reg); - } else { - etsg->LoadStringChar(this, obj_reg, count_reg); - } - - lref.SetValue(); - body_->Compile(etsg); - - etsg->SetLabel(this, label_target.ContinueTarget()); - - etsg->IncrementImmediateRegister(this, count_reg, checker::TypeFlag::INT, static_cast(1)); - etsg->LoadAccumulator(this, count_reg); - - etsg->JumpCompareRegister(this, size_reg, start_label); - etsg->SetLabel(this, label_target.BreakTarget()); + etsg->GetAstCompiler()->Compile(this); } -checker::Type *ForOfStatement::Check([[maybe_unused]] checker::TSChecker *checker) +checker::Type *ForOfStatement::Check(checker::TSChecker *checker) { - return nullptr; + return checker->GetAnalyzer()->Check(this); } -// NOLINTBEGIN(modernize-avoid-c-arrays) -static constexpr char const INVALID_SOURCE_EXPR_TYPE[] = - "'For-of' statement source expression should be either a string or an array."; -static constexpr char const INVALID_CONST_ASSIGNMENT[] = "Cannot assign a value to a constant variable "; -static constexpr char const ITERATOR_TYPE_ABSENT[] = "Cannot obtain iterator type in 'for-of' statement."; -// NOLINTEND(modernize-avoid-c-arrays) - checker::Type *ForOfStatement::Check(checker::ETSChecker *checker) { - checker::ScopeContext scope_ctx(checker, Scope()); - - checker::Type *const expr_type = right_->Check(checker); - checker::Type *elem_type; - - if (expr_type == nullptr || (!expr_type->IsETSArrayType() && !expr_type->IsETSStringType())) { - checker->ThrowTypeError(INVALID_SOURCE_EXPR_TYPE, right_->Start()); - } else if (expr_type->IsETSStringType()) { - elem_type = checker->GetGlobalTypesHolder()->GlobalCharType(); - } else { - elem_type = expr_type->AsETSArrayType()->ElementType()->Instantiate(checker->Allocator(), checker->Relation(), - checker->GetGlobalTypesHolder()); - elem_type->RemoveTypeFlag(checker::TypeFlag::CONSTANT); - } - - left_->Check(checker); - checker::Type *iter_type = nullptr; - - // Just to avoid extra nested level(s) - auto const get_iter_type = [checker, elem_type](ir::VariableDeclarator *const declarator) -> checker::Type * { - if (declarator->TsType() == nullptr) { - if (auto *resolved = checker->FindVariableInFunctionScope(declarator->Id()->AsIdentifier()->Name()); - resolved != nullptr) { - resolved->SetTsType(elem_type); - return elem_type; - } - } else { - return declarator->TsType(); - } - return nullptr; - }; - - if (left_->IsIdentifier()) { - if (auto *const variable = left_->AsIdentifier()->Variable(); variable != nullptr) { - if (variable->Declaration()->IsConstDecl()) { - checker->ThrowTypeError({INVALID_CONST_ASSIGNMENT, variable->Name()}, - variable->Declaration()->Node()->Start()); - } - } - iter_type = left_->AsIdentifier()->TsType(); - } else if (left_->IsVariableDeclaration()) { - if (auto const &declarators = left_->AsVariableDeclaration()->Declarators(); !declarators.empty()) { - iter_type = get_iter_type(declarators.front()); - } - } - - if (iter_type == nullptr) { - checker->ThrowTypeError(ITERATOR_TYPE_ABSENT, left_->Start()); - } - - auto *const relation = checker->Relation(); - relation->SetFlags(checker::TypeRelationFlag::ASSIGNMENT_CONTEXT); - relation->SetNode(checker->AllocNode()); // Dummy node to avoid assertion! - - if (!relation->IsAssignableTo(elem_type, iter_type)) { - std::stringstream ss {}; - ss << "Source element type '"; - elem_type->ToString(ss); - ss << "' is not assignable to the loop iterator type '"; - iter_type->ToString(ss); - ss << "'."; - checker->ThrowTypeError(ss.str(), Start()); - } - - relation->SetNode(nullptr); - relation->SetFlags(checker::TypeRelationFlag::NONE); - - body_->Check(checker); - - return nullptr; + return checker->GetAnalyzer()->Check(this); } } // namespace panda::es2panda::ir diff --git a/ets2panda/ir/statements/forOfStatement.h b/ets2panda/ir/statements/forOfStatement.h index 51a99573c8ca30a73b4e6e2a4bb42a9a3e27ea36..0043c78a7c6e7e4d3b3244df1bf12b8251bc3a39 100644 --- a/ets2panda/ir/statements/forOfStatement.h +++ b/ets2panda/ir/statements/forOfStatement.h @@ -82,10 +82,10 @@ public: void Iterate(const NodeTraverser &cb) const override; void Dump(ir::AstDumper *dumper) const override; - void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; - void Compile([[maybe_unused]] compiler::ETSGen *etsg) const override; - checker::Type *Check([[maybe_unused]] checker::TSChecker *checker) override; - checker::Type *Check([[maybe_unused]] checker::ETSChecker *checker) override; + void Compile(compiler::PandaGen *pg) const override; + void Compile(compiler::ETSGen *etsg) const override; + checker::Type *Check(checker::TSChecker *checker) override; + checker::Type *Check(checker::ETSChecker *checker) override; private: AstNode *left_; diff --git a/ets2panda/ir/statements/forUpdateStatement.cpp b/ets2panda/ir/statements/forUpdateStatement.cpp index 378dbcf36dc89fad9af9431ff94c135a8e04c791..09ccc206027021f9ecad28e5c682212f9ad238f8 100644 --- a/ets2panda/ir/statements/forUpdateStatement.cpp +++ b/ets2panda/ir/statements/forUpdateStatement.cpp @@ -23,8 +23,6 @@ #include "compiler/core/ETSGen.h" #include "compiler/core/dynamicContext.h" #include "checker/TSchecker.h" -#include "ir/astDump.h" -#include "ir/expression.h" namespace panda::es2panda::ir { void ForUpdateStatement::TransformChildren(const NodeTransformer &cb) @@ -68,115 +66,23 @@ void ForUpdateStatement::Dump(ir::AstDumper *dumper) const {"body", body_}}); } -void ForUpdateStatement::Compile([[maybe_unused]] compiler::PandaGen *pg) const +void ForUpdateStatement::Compile(compiler::PandaGen *pg) const { - compiler::LocalRegScope decl_reg_scope(pg, Scope()->DeclScope()->InitScope()); - - if (init_ != nullptr) { - ASSERT(init_->IsVariableDeclaration() || init_->IsExpression()); - init_->Compile(pg); - } - - auto *start_label = pg->AllocLabel(); - compiler::LabelTarget label_target(pg); - - compiler::LoopEnvScope decl_env_scope(pg, Scope()->DeclScope()); - compiler::LoopEnvScope env_scope(pg, label_target, Scope()); - pg->SetLabel(this, start_label); - - { - compiler::LocalRegScope reg_scope(pg, Scope()); - - if (test_ != nullptr) { - compiler::Condition::Compile(pg, test_, label_target.BreakTarget()); - } - - body_->Compile(pg); - pg->SetLabel(this, label_target.ContinueTarget()); - env_scope.CopyPetIterationCtx(); - } - - if (update_ != nullptr) { - update_->Compile(pg); - } - - pg->Branch(this, start_label); - pg->SetLabel(this, label_target.BreakTarget()); + pg->GetAstCompiler()->Compile(this); } -void ForUpdateStatement::Compile([[maybe_unused]] compiler::ETSGen *etsg) const +void ForUpdateStatement::Compile(compiler::ETSGen *etsg) const { - compiler::LocalRegScope decl_reg_scope(etsg, Scope()->DeclScope()->InitScope()); - - if (init_ != nullptr) { - ASSERT(init_->IsVariableDeclaration() || init_->IsExpression()); - init_->Compile(etsg); - } - - auto *start_label = etsg->AllocLabel(); - compiler::LabelTarget label_target(etsg); - auto label_ctx = compiler::LabelContext(etsg, label_target); - etsg->SetLabel(this, start_label); - - { - compiler::LocalRegScope reg_scope(etsg, Scope()); - - if (test_ != nullptr) { - compiler::Condition::Compile(etsg, test_, label_target.BreakTarget()); - } - - body_->Compile(etsg); - etsg->SetLabel(this, label_target.ContinueTarget()); - } - - if (update_ != nullptr) { - update_->Compile(etsg); - } - - etsg->Branch(this, start_label); - etsg->SetLabel(this, label_target.BreakTarget()); + etsg->GetAstCompiler()->Compile(this); } -checker::Type *ForUpdateStatement::Check([[maybe_unused]] checker::TSChecker *checker) +checker::Type *ForUpdateStatement::Check(checker::TSChecker *checker) { - checker::ScopeContext scope_ctx(checker, Scope()); - - if (init_ != nullptr) { - init_->Check(checker); - } - - if (test_ != nullptr) { - checker::Type *test_type = test_->Check(checker); - checker->CheckTruthinessOfType(test_type, Start()); - } - - if (update_ != nullptr) { - update_->Check(checker); - } - - body_->Check(checker); - - return nullptr; + return checker->GetAnalyzer()->Check(this); } -checker::Type *ForUpdateStatement::Check([[maybe_unused]] checker::ETSChecker *checker) +checker::Type *ForUpdateStatement::Check(checker::ETSChecker *checker) { - checker::ScopeContext scope_ctx(checker, Scope()); - - if (init_ != nullptr) { - init_->Check(checker); - } - - if (test_ != nullptr) { - checker->CheckTruthinessOfType(test_); - } - - if (update_ != nullptr) { - update_->Check(checker); - } - - body_->Check(checker); - - return nullptr; + return checker->GetAnalyzer()->Check(this); } } // namespace panda::es2panda::ir diff --git a/ets2panda/ir/statements/forUpdateStatement.h b/ets2panda/ir/statements/forUpdateStatement.h index f79166695e3efc93d0e6fa272d6def0f8de14a68..9e39b8b0d47c7b71e5201107ac0999ceab72d3ae 100644 --- a/ets2panda/ir/statements/forUpdateStatement.h +++ b/ets2panda/ir/statements/forUpdateStatement.h @@ -87,10 +87,10 @@ public: void Iterate(const NodeTraverser &cb) const override; void Dump(ir::AstDumper *dumper) const override; - void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; - void Compile([[maybe_unused]] compiler::ETSGen *etsg) const override; - checker::Type *Check([[maybe_unused]] checker::TSChecker *checker) override; - checker::Type *Check([[maybe_unused]] checker::ETSChecker *checker) override; + void Compile(compiler::PandaGen *pg) const override; + void Compile(compiler::ETSGen *etsg) const override; + checker::Type *Check(checker::TSChecker *checker) override; + checker::Type *Check(checker::ETSChecker *checker) override; private: AstNode *init_; diff --git a/ets2panda/ir/statements/functionDeclaration.cpp b/ets2panda/ir/statements/functionDeclaration.cpp index 578a8b1e7883d21a2eeafba08f3a00431f5c3245..a5c9e3a6148b417654cc2360ad5ad0b80fc3934d 100644 --- a/ets2panda/ir/statements/functionDeclaration.cpp +++ b/ets2panda/ir/statements/functionDeclaration.cpp @@ -19,14 +19,7 @@ #include "varbinder/scope.h" #include "compiler/core/ETSGen.h" #include "checker/TSchecker.h" -#include "checker/ETSchecker.h" -#include "checker/types/ets/etsFunctionType.h" -#include "ir/astDump.h" -#include "ir/typeNode.h" -#include "ir/base/spreadElement.h" -#include "ir/base/decorator.h" -#include "ir/base/scriptFunction.h" -#include "ir/expressions/identifier.h" +#include "compiler/core/pandagen.h" namespace panda::es2panda::ir { void FunctionDeclaration::TransformChildren(const NodeTransformer &cb) @@ -54,37 +47,23 @@ void FunctionDeclaration::Dump(ir::AstDumper *dumper) const {"function", func_}}); } -void FunctionDeclaration::Compile([[maybe_unused]] compiler::PandaGen *pg) const {} - -void FunctionDeclaration::Compile([[maybe_unused]] compiler::ETSGen *etsg) const +void FunctionDeclaration::Compile(compiler::PandaGen *pg) const { - UNREACHABLE(); + pg->GetAstCompiler()->Compile(this); } -checker::Type *FunctionDeclaration::Check([[maybe_unused]] checker::TSChecker *checker) +void FunctionDeclaration::Compile(compiler::ETSGen *etsg) const { - if (func_->IsOverload()) { - return nullptr; - } - - const util::StringView &func_name = func_->Id()->Name(); - auto result = checker->Scope()->Find(func_name); - ASSERT(result.variable); - - checker::ScopeContext scope_ctx(checker, func_->Scope()); - - if (result.variable->TsType() == nullptr) { - checker->InferFunctionDeclarationType(result.variable->Declaration()->AsFunctionDecl(), result.variable); - } - - func_->Body()->Check(checker); + etsg->GetAstCompiler()->Compile(this); +} - return nullptr; +checker::Type *FunctionDeclaration::Check(checker::TSChecker *checker) +{ + return checker->GetAnalyzer()->Check(this); } -checker::Type *FunctionDeclaration::Check([[maybe_unused]] checker::ETSChecker *checker) +checker::Type *FunctionDeclaration::Check(checker::ETSChecker *checker) { - UNREACHABLE(); - return nullptr; + return checker->GetAnalyzer()->Check(this); } } // namespace panda::es2panda::ir diff --git a/ets2panda/ir/statements/functionDeclaration.h b/ets2panda/ir/statements/functionDeclaration.h index 0c00928b77c77239586cc8f93347ddc1cd002ad2..26bed64a5df7b0c8b4a5d95c192dfe669bbd3c75 100644 --- a/ets2panda/ir/statements/functionDeclaration.h +++ b/ets2panda/ir/statements/functionDeclaration.h @@ -51,10 +51,10 @@ public: void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; void Dump(ir::AstDumper *dumper) const override; - void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; - void Compile([[maybe_unused]] compiler::ETSGen *etsg) const override; - checker::Type *Check([[maybe_unused]] checker::TSChecker *checker) override; - checker::Type *Check([[maybe_unused]] checker::ETSChecker *checker) override; + void Compile(compiler::PandaGen *pg) const override; + void Compile(compiler::ETSGen *etsg) const override; + checker::Type *Check(checker::TSChecker *checker) override; + checker::Type *Check(checker::ETSChecker *checker) override; private: ArenaVector decorators_; diff --git a/ets2panda/ir/statements/ifStatement.cpp b/ets2panda/ir/statements/ifStatement.cpp index 02d9091d064a664cdc3999ec5e4de66e24c09bef..05b30ac4114a462e1148d45887c8a54fea6758d4 100644 --- a/ets2panda/ir/statements/ifStatement.cpp +++ b/ets2panda/ir/statements/ifStatement.cpp @@ -15,12 +15,9 @@ #include "ifStatement.h" -#include "compiler/base/condition.h" -#include "compiler/core/pandagen.h" -#include "compiler/core/ETSGen.h" #include "checker/TSchecker.h" -#include "ir/astDump.h" -#include "ir/expression.h" +#include "compiler/core/ETSGen.h" +#include "compiler/core/pandagen.h" namespace panda::es2panda::ir { void IfStatement::TransformChildren(const NodeTransformer &cb) @@ -51,84 +48,23 @@ void IfStatement::Dump(ir::AstDumper *dumper) const {"alternate", AstDumper::Nullish(alternate_)}}); } -void IfStatement::Compile([[maybe_unused]] compiler::PandaGen *pg) const +void IfStatement::Compile(compiler::PandaGen *pg) const { - auto *consequent_end = pg->AllocLabel(); - compiler::Label *statement_end = consequent_end; - - compiler::Condition::Compile(pg, test_, consequent_end); - consequent_->Compile(pg); - - if (alternate_ != nullptr) { - statement_end = pg->AllocLabel(); - pg->Branch(pg->Insns().back()->Node(), statement_end); - - pg->SetLabel(this, consequent_end); - alternate_->Compile(pg); - } - - pg->SetLabel(this, statement_end); + pg->GetAstCompiler()->Compile(this); } -void IfStatement::Compile([[maybe_unused]] compiler::ETSGen *etsg) const +void IfStatement::Compile(compiler::ETSGen *etsg) const { - auto res = compiler::Condition::CheckConstantExpr(etsg, test_); - - if (res == compiler::Condition::Result::CONST_TRUE) { - consequent_->Compile(etsg); - return; - } - - if (res == compiler::Condition::Result::CONST_FALSE) { - if (alternate_ != nullptr) { - alternate_->Compile(etsg); - } - return; - } - - auto *consequent_end = etsg->AllocLabel(); - compiler::Label *statement_end = consequent_end; - - compiler::Condition::Compile(etsg, test_, consequent_end); - - consequent_->Compile(etsg); - - if (alternate_ != nullptr) { - statement_end = etsg->AllocLabel(); - etsg->Branch(etsg->Insns().back()->Node(), statement_end); - - etsg->SetLabel(this, consequent_end); - alternate_->Compile(etsg); - } - - etsg->SetLabel(this, statement_end); + etsg->GetAstCompiler()->Compile(this); } checker::Type *IfStatement::Check([[maybe_unused]] checker::TSChecker *checker) { - checker::Type *test_type = test_->Check(checker); - checker->CheckTruthinessOfType(test_type, Start()); - checker->CheckTestingKnownTruthyCallableOrAwaitableType(test_, test_type, consequent_); - - consequent_->Check(checker); - - if (alternate_ != nullptr) { - alternate_->Check(checker); - } - - return nullptr; + return checker->GetAnalyzer()->Check(this); } checker::Type *IfStatement::Check([[maybe_unused]] checker::ETSChecker *checker) { - checker->CheckTruthinessOfType(test_); - - consequent_->Check(checker); - - if (alternate_ != nullptr) { - alternate_->Check(checker); - } - - return nullptr; + return checker->GetAnalyzer()->Check(this); } } // namespace panda::es2panda::ir diff --git a/ets2panda/ir/statements/ifStatement.h b/ets2panda/ir/statements/ifStatement.h index b2596d77bc4043995a8fca37e3c52555433dac39..57755853e4591303e6ed7855348c27a5d40cd579 100644 --- a/ets2panda/ir/statements/ifStatement.h +++ b/ets2panda/ir/statements/ifStatement.h @@ -18,6 +18,11 @@ #include "ir/statement.h" +namespace panda::es2panda::checker { +class TSAnalyzer; +class ETSAnalyzer; +} // namespace panda::es2panda::checker + namespace panda::es2panda::ir { class Expression; @@ -28,6 +33,10 @@ public: { } + // NOTE (csabahurton): these friend relationships can be removed once there are getters for private fields + friend class checker::ETSAnalyzer; + friend class checker::TSAnalyzer; + const Expression *Test() const { return test_; @@ -38,6 +47,11 @@ public: return consequent_; } + Statement *Alternate() + { + return alternate_; + } + const Statement *Alternate() const { return alternate_; @@ -56,10 +70,10 @@ public: void Iterate(const NodeTraverser &cb) const override; void Dump(ir::AstDumper *dumper) const override; - void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; - void Compile([[maybe_unused]] compiler::ETSGen *etsg) const override; - checker::Type *Check([[maybe_unused]] checker::TSChecker *checker) override; - checker::Type *Check([[maybe_unused]] checker::ETSChecker *checker) override; + void Compile(compiler::PandaGen *pg) const override; + void Compile(compiler::ETSGen *etsg) const override; + checker::Type *Check(checker::TSChecker *checker) override; + checker::Type *Check(checker::ETSChecker *checker) override; private: Expression *test_; diff --git a/ets2panda/ir/statements/labelledStatement.cpp b/ets2panda/ir/statements/labelledStatement.cpp index be77a04fdcb42c826352d2467bebf1c37e54b8bc..c43d30ebf809b61b750156899434574fa474ec94 100644 --- a/ets2panda/ir/statements/labelledStatement.cpp +++ b/ets2panda/ir/statements/labelledStatement.cpp @@ -15,11 +15,9 @@ #include "labelledStatement.h" -#include "compiler/core/pandagen.h" +#include "checker/TSchecker.h" #include "compiler/core/ETSGen.h" -#include "compiler/core/labelTarget.h" -#include "ir/astDump.h" -#include "ir/expressions/identifier.h" +#include "compiler/core/pandagen.h" namespace panda::es2panda::ir { void LabelledStatement::TransformChildren(const NodeTransformer &cb) @@ -39,13 +37,6 @@ void LabelledStatement::Dump(ir::AstDumper *dumper) const dumper->Add({{"type", "LabelledStatement"}, {"label", ident_}, {"body", body_}}); } -template -void CompileImpl(const LabelledStatement *self, CodeGen *cg) -{ - compiler::LabelContext label_ctx(cg, self); - self->Body()->Compile(cg); -} - const ir::AstNode *LabelledStatement::GetReferencedStatement() const { const auto *iter = body_; @@ -67,24 +58,23 @@ const ir::AstNode *LabelledStatement::GetReferencedStatement() const } } -void LabelledStatement::Compile([[maybe_unused]] compiler::PandaGen *pg) const +void LabelledStatement::Compile(compiler::PandaGen *pg) const { - CompileImpl(this, pg); + pg->GetAstCompiler()->Compile(this); } -void LabelledStatement::Compile([[maybe_unused]] compiler::ETSGen *etsg) const +void LabelledStatement::Compile(compiler::ETSGen *etsg) const { - CompileImpl(this, etsg); + etsg->GetAstCompiler()->Compile(this); } -checker::Type *LabelledStatement::Check([[maybe_unused]] checker::TSChecker *checker) +checker::Type *LabelledStatement::Check(checker::TSChecker *checker) { - return nullptr; + return checker->GetAnalyzer()->Check(this); } -checker::Type *LabelledStatement::Check([[maybe_unused]] checker::ETSChecker *checker) +checker::Type *LabelledStatement::Check(checker::ETSChecker *checker) { - body_->Check(checker); - return nullptr; + return checker->GetAnalyzer()->Check(this); } } // namespace panda::es2panda::ir diff --git a/ets2panda/ir/statements/labelledStatement.h b/ets2panda/ir/statements/labelledStatement.h index 7a5779bd3febc3c7c20a37847e7b76a2f3191d3b..1daa79ce46f6f97127a54bf2c43e727a0bd50ab4 100644 --- a/ets2panda/ir/statements/labelledStatement.h +++ b/ets2panda/ir/statements/labelledStatement.h @@ -19,6 +19,10 @@ #include "ir/statement.h" #include "util/ustring.h" +namespace panda::es2panda::checker { +class ETSAnalyzer; +} // namespace panda::es2panda::checker + namespace panda::es2panda::ir { class Identifier; @@ -29,6 +33,9 @@ public: { } + // NOTE (csabahurton): these friend relationships can be removed once there are getters for private fields + friend class checker::ETSAnalyzer; + const Statement *Body() const { return body_; @@ -51,10 +58,10 @@ public: void Iterate(const NodeTraverser &cb) const override; void Dump(ir::AstDumper *dumper) const override; - void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; - void Compile([[maybe_unused]] compiler::ETSGen *etsg) const override; - checker::Type *Check([[maybe_unused]] checker::TSChecker *checker) override; - checker::Type *Check([[maybe_unused]] checker::ETSChecker *checker) override; + void Compile(compiler::PandaGen *pg) const override; + void Compile(compiler::ETSGen *etsg) const override; + checker::Type *Check(checker::TSChecker *checker) override; + checker::Type *Check(checker::ETSChecker *checker) override; private: Identifier *ident_; diff --git a/ets2panda/ir/statements/returnStatement.h b/ets2panda/ir/statements/returnStatement.h index cacaf713a77d7b33281721073dea6680f01c6cff..2e2efaf8da232a47c16cb0ef0863994fb0032546 100644 --- a/ets2panda/ir/statements/returnStatement.h +++ b/ets2panda/ir/statements/returnStatement.h @@ -61,10 +61,10 @@ public: void Iterate(const NodeTraverser &cb) const override; void Dump(ir::AstDumper *dumper) const override; - void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; - void Compile([[maybe_unused]] compiler::ETSGen *etsg) const override; - checker::Type *Check([[maybe_unused]] checker::TSChecker *checker) override; - checker::Type *Check([[maybe_unused]] checker::ETSChecker *checker) override; + void Compile(compiler::PandaGen *pg) const override; + void Compile(compiler::ETSGen *etsg) const override; + checker::Type *Check(checker::TSChecker *checker) override; + checker::Type *Check(checker::ETSChecker *checker) override; private: Expression *argument_ {}; diff --git a/ets2panda/ir/statements/switchCaseStatement.cpp b/ets2panda/ir/statements/switchCaseStatement.cpp index d3b4ab31eaa9d4bfcabffbf0afb8081c0d07ad80..3830c777c6445b27e21d45b8b7069cbdda0e9a73 100644 --- a/ets2panda/ir/statements/switchCaseStatement.cpp +++ b/ets2panda/ir/statements/switchCaseStatement.cpp @@ -15,8 +15,9 @@ #include "switchCaseStatement.h" -#include "ir/astDump.h" -#include "ir/expression.h" +#include "checker/TSchecker.h" +#include "compiler/core/ETSGen.h" +#include "compiler/core/pandagen.h" namespace panda::es2panda::ir { void SwitchCaseStatement::TransformChildren(const NodeTransformer &cb) @@ -46,15 +47,23 @@ void SwitchCaseStatement::Dump(ir::AstDumper *dumper) const dumper->Add({{"type", "SwitchCase"}, {"test", AstDumper::Nullish(test_)}, {"consequent", consequent_}}); } -void SwitchCaseStatement::Compile([[maybe_unused]] compiler::PandaGen *pg) const {} +void SwitchCaseStatement::Compile(compiler::PandaGen *pg) const +{ + pg->GetAstCompiler()->Compile(this); +} + +void SwitchCaseStatement::Compile(compiler::ETSGen *etsg) const +{ + etsg->GetAstCompiler()->Compile(this); +} -checker::Type *SwitchCaseStatement::Check([[maybe_unused]] checker::TSChecker *checker) +checker::Type *SwitchCaseStatement::Check(checker::TSChecker *checker) { - return nullptr; + return checker->GetAnalyzer()->Check(this); } -checker::Type *SwitchCaseStatement::Check([[maybe_unused]] checker::ETSChecker *checker) +checker::Type *SwitchCaseStatement::Check(checker::ETSChecker *checker) { - return nullptr; + return checker->GetAnalyzer()->Check(this); } } // namespace panda::es2panda::ir diff --git a/ets2panda/ir/statements/switchCaseStatement.h b/ets2panda/ir/statements/switchCaseStatement.h index 0ed32b85facd23ca10301372f9e6c2616dd9e74e..886520a6f719792a1a9835481d2750439f97e1ee 100644 --- a/ets2panda/ir/statements/switchCaseStatement.h +++ b/ets2panda/ir/statements/switchCaseStatement.h @@ -55,9 +55,10 @@ public: void Iterate(const NodeTraverser &cb) const override; void Dump(ir::AstDumper *dumper) const override; - void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; - checker::Type *Check([[maybe_unused]] checker::TSChecker *checker) override; - checker::Type *Check([[maybe_unused]] checker::ETSChecker *checker) override; + void Compile(compiler::PandaGen *pg) const override; + void Compile(compiler::ETSGen *etsg) const override; + checker::Type *Check(checker::TSChecker *checker) override; + checker::Type *Check(checker::ETSChecker *checker) override; private: Expression *test_; diff --git a/ets2panda/ir/statements/switchStatement.cpp b/ets2panda/ir/statements/switchStatement.cpp index 4bc685e3b2ba20fc3c0f25c67c3d0a36e1eb8300..c7d908bd2d4ec163e47ee390b1a21ce49cb6b864 100644 --- a/ets2panda/ir/statements/switchStatement.cpp +++ b/ets2panda/ir/statements/switchStatement.cpp @@ -21,12 +21,6 @@ #include "compiler/core/pandagen.h" #include "compiler/core/ETSGen.h" #include "checker/TSchecker.h" -#include "checker/ets/typeRelationContext.h" -#include "ir/astDump.h" -#include "ir/expression.h" -#include "ir/expressions/identifier.h" -#include "ir/expressions/memberExpression.h" -#include "ir/statements/switchCaseStatement.h" namespace panda::es2panda::ir { void SwitchStatement::TransformChildren(const NodeTransformer &cb) @@ -52,132 +46,24 @@ void SwitchStatement::Dump(ir::AstDumper *dumper) const dumper->Add({{"type", "SwitchStatement"}, {"discriminant", discriminant_}, {"cases", cases_}}); } -template -void CompileImpl(const SwitchStatement *self, CodeGen *cg) +void SwitchStatement::Compile(compiler::PandaGen *pg) const { - compiler::LocalRegScope lrs(cg, self->Scope()); - compiler::SwitchBuilder builder(cg, self); - compiler::VReg tag = cg->AllocReg(); - - builder.CompileTagOfSwitch(tag); - uint32_t default_index = 0; - - for (size_t i = 0; i < self->Cases().size(); i++) { - const auto *clause = self->Cases()[i]; - - if (clause->Test() == nullptr) { - default_index = i; - continue; - } - - builder.JumpIfCase(tag, i); - } - - if (default_index > 0) { - builder.JumpToDefault(default_index); - } else { - builder.Break(); - } - - for (size_t i = 0; i < self->Cases().size(); i++) { - builder.SetCaseTarget(i); - builder.CompileCaseStatements(i); - } + pg->GetAstCompiler()->Compile(this); } -void SwitchStatement::Compile([[maybe_unused]] compiler::PandaGen *pg) const +void SwitchStatement::Compile(compiler::ETSGen *etsg) const { - CompileImpl(this, pg); + etsg->GetAstCompiler()->Compile(this); } -void SwitchStatement::Compile([[maybe_unused]] compiler::ETSGen *etsg) const +checker::Type *SwitchStatement::Check(checker::TSChecker *checker) { - CompileImpl(this, etsg); -} - -checker::Type *SwitchStatement::Check([[maybe_unused]] checker::TSChecker *checker) -{ - checker::ScopeContext scope_ctx(checker, scope_); - - checker::Type *expr_type = discriminant_->Check(checker); - bool expr_is_literal = checker::TSChecker::IsLiteralType(expr_type); - - for (auto *it : cases_) { - if (it->Test() != nullptr) { - checker::Type *case_type = it->Test()->Check(checker); - bool case_is_literal = checker::TSChecker::IsLiteralType(case_type); - checker::Type *compared_expr_type = expr_type; - - if (!case_is_literal || !expr_is_literal) { - case_type = case_is_literal ? checker->GetBaseTypeOfLiteralType(case_type) : case_type; - compared_expr_type = checker->GetBaseTypeOfLiteralType(expr_type); - } - - if (!checker->IsTypeEqualityComparableTo(compared_expr_type, case_type) && - !checker->IsTypeComparableTo(case_type, compared_expr_type)) { - checker->ThrowTypeError({"Type ", case_type, " is not comparable to type ", compared_expr_type}, - it->Test()->Start()); - } - } - - for (auto *case_stmt : it->Consequent()) { - case_stmt->Check(checker); - } - } - - return nullptr; + return checker->GetAnalyzer()->Check(this); } checker::Type *SwitchStatement::Check(checker::ETSChecker *const checker) { - checker::ScopeContext scope_ctx(checker, scope_); - discriminant_->Check(checker); - checker::SavedTypeRelationFlagsContext saved_type_relation_flag_ctx(checker->Relation(), - checker::TypeRelationFlag::NONE); - // NOTE: check exhaustive Switch - checker->CheckSwitchDiscriminant(discriminant_); - auto *compared_expr_type = discriminant_->TsType(); - auto unboxed_disc_type = (Discriminant()->GetBoxingUnboxingFlags() & ir::BoxingUnboxingFlags::UNBOXING_FLAG) != 0U - ? checker->ETSBuiltinTypeAsPrimitiveType(compared_expr_type) - : compared_expr_type; - - bool valid_case_type; - - for (auto *it : cases_) { - if (it->Test() != nullptr) { - auto *case_type = it->Test()->Check(checker); - valid_case_type = true; - if (case_type->HasTypeFlag(checker::TypeFlag::CHAR)) { - valid_case_type = compared_expr_type->HasTypeFlag(checker::TypeFlag::ETS_INTEGRAL); - } else if (case_type->IsETSEnumType() && discriminant_->TsType()->IsETSEnumType()) { - valid_case_type = discriminant_->TsType()->AsETSEnumType()->IsSameEnumType(case_type->AsETSEnumType()); - } else if (case_type->IsETSStringEnumType() && discriminant_->TsType()->IsETSStringEnumType()) { - valid_case_type = - discriminant_->TsType()->AsETSStringEnumType()->IsSameEnumType(case_type->AsETSStringEnumType()); - } else { - checker::AssignmentContext( - checker->Relation(), discriminant_, case_type, unboxed_disc_type, it->Test()->Start(), - {"Switch case type ", case_type, " is not comparable to discriminant type ", compared_expr_type}, - (compared_expr_type->IsETSObjectType() ? checker::TypeRelationFlag::NO_WIDENING - : checker::TypeRelationFlag::NO_UNBOXING) | - checker::TypeRelationFlag::NO_BOXING); - } - - if (!valid_case_type) { - checker->ThrowTypeError( - {"Switch case type ", case_type, " is not comparable to discriminant type ", compared_expr_type}, - it->Test()->Start()); - } - } - - for (auto *case_stmt : it->Consequent()) { - case_stmt->Check(checker); - } - } - - checker->CheckForSameSwitchCases(&cases_); - - return nullptr; + return checker->GetAnalyzer()->Check(this); } void SwitchStatement::SetReturnType(checker::ETSChecker *checker, checker::Type *type) diff --git a/ets2panda/ir/statements/switchStatement.h b/ets2panda/ir/statements/switchStatement.h index 70a0fab7466e5818c6861ecb5897de991b770dc2..a18b646ac3dd6d5c2197ec6512bc606e943b9f98 100644 --- a/ets2panda/ir/statements/switchStatement.h +++ b/ets2panda/ir/statements/switchStatement.h @@ -19,6 +19,11 @@ #include "varbinder/scope.h" #include "ir/statement.h" +namespace panda::es2panda::checker { +class TSAnalyzer; +class ETSAnalyzer; +} // namespace panda::es2panda::checker + namespace panda::es2panda::ir { class Expression; class SwitchCaseStatement; @@ -31,6 +36,10 @@ public: { } + // NOTE (csabahurton): these friend relationships can be removed once there are getters for private fields + friend class checker::ETSAnalyzer; + friend class checker::TSAnalyzer; + const Expression *Discriminant() const { return discriminant_; @@ -56,10 +65,10 @@ public: void Iterate(const NodeTraverser &cb) const override; void Dump(ir::AstDumper *dumper) const override; - void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; - void Compile([[maybe_unused]] compiler::ETSGen *etsg) const override; - checker::Type *Check([[maybe_unused]] checker::TSChecker *checker) override; - checker::Type *Check([[maybe_unused]] checker::ETSChecker *checker) override; + void Compile(compiler::PandaGen *pg) const override; + void Compile(compiler::ETSGen *etsg) const override; + checker::Type *Check(checker::TSChecker *checker) override; + checker::Type *Check(checker::ETSChecker *checker) override; private: varbinder::LocalScope *scope_; diff --git a/ets2panda/ir/statements/variableDeclaration.h b/ets2panda/ir/statements/variableDeclaration.h index 601170366b6d7bc04feb7395bc72542d65953875..fac991570d54d21800e1fcdf469654a2c48fbd11 100644 --- a/ets2panda/ir/statements/variableDeclaration.h +++ b/ets2panda/ir/statements/variableDeclaration.h @@ -55,6 +55,11 @@ public: return decorators_; } + const ArenaVector *DecoratorsPtr() const override + { + return &Decorators(); + } + void AddDecorators([[maybe_unused]] ArenaVector &&decorators) override { decorators_ = std::move(decorators); diff --git a/ets2panda/ir/ts/tsAnyKeyword.cpp b/ets2panda/ir/ts/tsAnyKeyword.cpp index 170d086c834e06131469232c55c42778705bb7a6..c82f0274154bba1664f4055ba3082a96504a8266 100644 --- a/ets2panda/ir/ts/tsAnyKeyword.cpp +++ b/ets2panda/ir/ts/tsAnyKeyword.cpp @@ -15,8 +15,9 @@ #include "tsAnyKeyword.h" -#include "ir/astDump.h" #include "checker/TSchecker.h" +#include "compiler/core/ETSGen.h" +#include "compiler/core/pandagen.h" namespace panda::es2panda::ir { void TSAnyKeyword::TransformChildren([[maybe_unused]] const NodeTransformer &cb) {} @@ -27,11 +28,19 @@ void TSAnyKeyword::Dump(ir::AstDumper *dumper) const dumper->Add({{"type", "TSAnyKeyword"}}); } -void TSAnyKeyword::Compile([[maybe_unused]] compiler::PandaGen *pg) const {} +void TSAnyKeyword::Compile(compiler::PandaGen *pg) const +{ + pg->GetAstCompiler()->Compile(this); +} + +void TSAnyKeyword::Compile(compiler::ETSGen *etsg) const +{ + etsg->GetAstCompiler()->Compile(this); +} -checker::Type *TSAnyKeyword::Check([[maybe_unused]] checker::TSChecker *checker) +checker::Type *TSAnyKeyword::Check(checker::TSChecker *checker) { - return nullptr; + return checker->GetAnalyzer()->Check(this); } checker::Type *TSAnyKeyword::GetType([[maybe_unused]] checker::TSChecker *checker) @@ -39,8 +48,8 @@ checker::Type *TSAnyKeyword::GetType([[maybe_unused]] checker::TSChecker *checke return checker->GlobalAnyType(); } -checker::Type *TSAnyKeyword::Check([[maybe_unused]] checker::ETSChecker *checker) +checker::Type *TSAnyKeyword::Check(checker::ETSChecker *checker) { - return nullptr; + return checker->GetAnalyzer()->Check(this); } } // namespace panda::es2panda::ir diff --git a/ets2panda/ir/ts/tsAnyKeyword.h b/ets2panda/ir/ts/tsAnyKeyword.h index 5719a54c0a73cc95b06679d6190b869ba21910f6..e6f2d21e62f1ad86135cddb12d10f5ad84a36c92 100644 --- a/ets2panda/ir/ts/tsAnyKeyword.h +++ b/ets2panda/ir/ts/tsAnyKeyword.h @@ -26,10 +26,11 @@ public: void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; void Dump(ir::AstDumper *dumper) const override; - void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; - checker::Type *Check([[maybe_unused]] checker::TSChecker *checker) override; + void Compile(compiler::PandaGen *pg) const override; + void Compile(compiler::ETSGen *etsg) const override; + checker::Type *Check(checker::TSChecker *checker) override; checker::Type *GetType([[maybe_unused]] checker::TSChecker *checker) override; - checker::Type *Check([[maybe_unused]] checker::ETSChecker *checker) override; + checker::Type *Check(checker::ETSChecker *checker) override; }; } // namespace panda::es2panda::ir diff --git a/ets2panda/ir/ts/tsBooleanKeyword.cpp b/ets2panda/ir/ts/tsBooleanKeyword.cpp index f5759ccf7f82246b477557cff9dcbc2e04714c1b..7cc031e8a91543cfcef2b0a1a680ad182a2c90bc 100644 --- a/ets2panda/ir/ts/tsBooleanKeyword.cpp +++ b/ets2panda/ir/ts/tsBooleanKeyword.cpp @@ -15,8 +15,9 @@ #include "tsBooleanKeyword.h" -#include "ir/astDump.h" #include "checker/TSchecker.h" +#include "compiler/core/ETSGen.h" +#include "compiler/core/pandagen.h" namespace panda::es2panda::ir { void TSBooleanKeyword::TransformChildren([[maybe_unused]] const NodeTransformer &cb) {} @@ -27,11 +28,19 @@ void TSBooleanKeyword::Dump(ir::AstDumper *dumper) const dumper->Add({{"type", "TSBooleanKeyword"}}); } -void TSBooleanKeyword::Compile([[maybe_unused]] compiler::PandaGen *pg) const {} +void TSBooleanKeyword::Compile(compiler::PandaGen *pg) const +{ + pg->GetAstCompiler()->Compile(this); +} + +void TSBooleanKeyword::Compile(compiler::ETSGen *etsg) const +{ + etsg->GetAstCompiler()->Compile(this); +} -checker::Type *TSBooleanKeyword::Check([[maybe_unused]] checker::TSChecker *checker) +checker::Type *TSBooleanKeyword::Check(checker::TSChecker *checker) { - return nullptr; + return checker->GetAnalyzer()->Check(this); } checker::Type *TSBooleanKeyword::GetType([[maybe_unused]] checker::TSChecker *checker) @@ -39,8 +48,8 @@ checker::Type *TSBooleanKeyword::GetType([[maybe_unused]] checker::TSChecker *ch return checker->GlobalBooleanType(); } -checker::Type *TSBooleanKeyword::Check([[maybe_unused]] checker::ETSChecker *checker) +checker::Type *TSBooleanKeyword::Check(checker::ETSChecker *checker) { - return nullptr; + return checker->GetAnalyzer()->Check(this); } } // namespace panda::es2panda::ir diff --git a/ets2panda/ir/ts/tsBooleanKeyword.h b/ets2panda/ir/ts/tsBooleanKeyword.h index a4936f1cecadf7e928448c41e891ebc3dcfd8eeb..c796b0e41c04d70a67e045d3b3fb3fd359fe1832 100644 --- a/ets2panda/ir/ts/tsBooleanKeyword.h +++ b/ets2panda/ir/ts/tsBooleanKeyword.h @@ -26,10 +26,11 @@ public: void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; void Dump(ir::AstDumper *dumper) const override; - void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; - checker::Type *Check([[maybe_unused]] checker::TSChecker *checker) override; + void Compile(compiler::PandaGen *pg) const override; + void Compile(compiler::ETSGen *etsg) const override; + checker::Type *Check(checker::TSChecker *checker) override; checker::Type *GetType([[maybe_unused]] checker::TSChecker *checker) override; - checker::Type *Check([[maybe_unused]] checker::ETSChecker *checker) override; + checker::Type *Check(checker::ETSChecker *checker) override; }; } // namespace panda::es2panda::ir diff --git a/ets2panda/ir/ts/tsEnumDeclaration.cpp b/ets2panda/ir/ts/tsEnumDeclaration.cpp index c1bb84f23b05aace5810caed65fa8ba22a0ed144..b0f73788e5517e4142ff969721f057e92825a6e0 100644 --- a/ets2panda/ir/ts/tsEnumDeclaration.cpp +++ b/ets2panda/ir/ts/tsEnumDeclaration.cpp @@ -15,22 +15,11 @@ #include "tsEnumDeclaration.h" +#include "checker/TSchecker.h" +#include "compiler/core/ETSGen.h" +#include "compiler/core/pandagen.h" #include "varbinder/scope.h" #include "util/helpers.h" -#include "ir/astDump.h" -#include "ir/base/decorator.h" -#include "ir/base/scriptFunction.h" -#include "ir/expressions/identifier.h" -#include "ir/base/methodDefinition.h" -#include "ir/expressions/memberExpression.h" -#include "ir/expressions/unaryExpression.h" -#include "ir/expressions/binaryExpression.h" -#include "ir/expressions/templateLiteral.h" -#include "ir/expressions/literals/stringLiteral.h" -#include "ir/expressions/literals/numberLiteral.h" -#include "ir/ts/tsEnumMember.h" -#include "checker/TSchecker.h" -#include "checker/ETSchecker.h" namespace panda::es2panda::ir { void TSEnumDeclaration::TransformChildren(const NodeTransformer &cb) @@ -68,89 +57,7 @@ void TSEnumDeclaration::Dump(ir::AstDumper *dumper) const {"const", is_const_}}); } -void TSEnumDeclaration::Compile([[maybe_unused]] compiler::PandaGen *pg) const {} - -int32_t ToInt(double num) -{ - if (num >= std::numeric_limits::min() && num <= std::numeric_limits::max()) { - return static_cast(num); - } - - // NOTE: aszilagyi. Perform ECMA defined toInt conversion - - return 0; -} - -uint32_t ToUInt(double num) -{ - if (num >= std::numeric_limits::min() && num <= std::numeric_limits::max()) { - return static_cast(num); - } - - // NOTE: aszilagyi. Perform ECMA defined toInt conversion - - return 0; -} - -varbinder::EnumMemberResult EvaluateIdentifier(checker::TSChecker *checker, varbinder::EnumVariable *enum_var, - const ir::Identifier *expr) -{ - if (expr->Name() == "NaN") { - return std::nan(""); - } - if (expr->Name() == "Infinity") { - return std::numeric_limits::infinity(); - } - - varbinder::Variable *enum_member = expr->AsIdentifier()->Variable(); - - if (enum_member == nullptr) { - checker->ThrowTypeError({"Cannot find name ", expr->AsIdentifier()->Name()}, - enum_var->Declaration()->Node()->Start()); - } - - if (enum_member->IsEnumVariable()) { - varbinder::EnumVariable *expr_enum_var = enum_member->AsEnumVariable(); - if (std::holds_alternative(expr_enum_var->Value())) { - checker->ThrowTypeError( - "A member initializer in a enum declaration cannot reference members declared after it, " - "including " - "members defined in other enums.", - enum_var->Declaration()->Node()->Start()); - } - - return expr_enum_var->Value(); - } - - return false; -} - -varbinder::EnumMemberResult EvaluateUnaryExpression(checker::TSChecker *checker, varbinder::EnumVariable *enum_var, - const ir::UnaryExpression *expr) -{ - varbinder::EnumMemberResult value = TSEnumDeclaration::EvaluateEnumMember(checker, enum_var, expr->Argument()); - if (!std::holds_alternative(value)) { - return false; - } - - switch (expr->OperatorType()) { - case lexer::TokenType::PUNCTUATOR_PLUS: { - return std::get(value); - } - case lexer::TokenType::PUNCTUATOR_MINUS: { - return -std::get(value); - } - case lexer::TokenType::PUNCTUATOR_TILDE: { - return static_cast(~ToInt(std::get(value))); // NOLINT(hicpp-signed-bitwise) - } - default: { - break; - } - } - - return false; -} - +// NOTE (csabahurton): this method has not been moved to TSAnalyizer.cpp, because it is not used. varbinder::EnumMemberResult EvaluateMemberExpression(checker::TSChecker *checker, [[maybe_unused]] varbinder::EnumVariable *enum_var, ir::MemberExpression *expr) @@ -172,280 +79,23 @@ varbinder::EnumMemberResult EvaluateMemberExpression(checker::TSChecker *checker return false; } -varbinder::EnumMemberResult EvaluateBinaryExpression(checker::TSChecker *checker, varbinder::EnumVariable *enum_var, - const ir::BinaryExpression *expr) +void TSEnumDeclaration::Compile(compiler::PandaGen *pg) const { - varbinder::EnumMemberResult left = - TSEnumDeclaration::EvaluateEnumMember(checker, enum_var, expr->AsBinaryExpression()->Left()); - varbinder::EnumMemberResult right = - TSEnumDeclaration::EvaluateEnumMember(checker, enum_var, expr->AsBinaryExpression()->Right()); - if (std::holds_alternative(left) && std::holds_alternative(right)) { - switch (expr->AsBinaryExpression()->OperatorType()) { - case lexer::TokenType::PUNCTUATOR_BITWISE_OR: { - return static_cast(ToUInt(std::get(left)) | ToUInt(std::get(right))); - } - case lexer::TokenType::PUNCTUATOR_BITWISE_AND: { - return static_cast(ToUInt(std::get(left)) & ToUInt(std::get(right))); - } - case lexer::TokenType::PUNCTUATOR_BITWISE_XOR: { - return static_cast(ToUInt(std::get(left)) ^ ToUInt(std::get(right))); - } - case lexer::TokenType::PUNCTUATOR_LEFT_SHIFT: { // NOLINTNEXTLINE(hicpp-signed-bitwise) - return static_cast(ToInt(std::get(left)) << ToUInt(std::get(right))); - } - case lexer::TokenType::PUNCTUATOR_RIGHT_SHIFT: { // NOLINTNEXTLINE(hicpp-signed-bitwise) - return static_cast(ToInt(std::get(left)) >> ToUInt(std::get(right))); - } - case lexer::TokenType::PUNCTUATOR_UNSIGNED_RIGHT_SHIFT: { - return static_cast(ToUInt(std::get(left)) >> ToUInt(std::get(right))); - } - case lexer::TokenType::PUNCTUATOR_PLUS: { - return std::get(left) + std::get(right); - } - case lexer::TokenType::PUNCTUATOR_MINUS: { - return std::get(left) - std::get(right); - } - case lexer::TokenType::PUNCTUATOR_MULTIPLY: { - return std::get(left) * std::get(right); - } - case lexer::TokenType::PUNCTUATOR_DIVIDE: { - return std::get(left) / std::get(right); - } - case lexer::TokenType::PUNCTUATOR_MOD: { - return std::fmod(std::get(left), std::get(right)); - } - case lexer::TokenType::PUNCTUATOR_EXPONENTIATION: { - return std::pow(std::get(left), std::get(right)); - } - default: { - break; - } - } - - return false; - } - - if (std::holds_alternative(left) && std::holds_alternative(right) && - expr->AsBinaryExpression()->OperatorType() == lexer::TokenType::PUNCTUATOR_PLUS) { - std::stringstream ss; - ss << std::get(left) << std::get(right); - - util::UString res(ss.str(), checker->Allocator()); - return res.View(); - } - - return false; + pg->GetAstCompiler()->Compile(this); } -varbinder::EnumMemberResult TSEnumDeclaration::EvaluateEnumMember(checker::TSChecker *checker, - varbinder::EnumVariable *enum_var, - const ir::AstNode *expr) +void TSEnumDeclaration::Compile(compiler::ETSGen *etsg) const { - switch (expr->Type()) { - case ir::AstNodeType::UNARY_EXPRESSION: { - return EvaluateUnaryExpression(checker, enum_var, expr->AsUnaryExpression()); - } - case ir::AstNodeType::BINARY_EXPRESSION: { - return EvaluateBinaryExpression(checker, enum_var, expr->AsBinaryExpression()); - } - case ir::AstNodeType::NUMBER_LITERAL: { - return expr->AsNumberLiteral()->Number().GetDouble(); - } - case ir::AstNodeType::STRING_LITERAL: { - return expr->AsStringLiteral()->Str(); - } - case ir::AstNodeType::IDENTIFIER: { - return EvaluateIdentifier(checker, enum_var, expr->AsIdentifier()); - } - case ir::AstNodeType::MEMBER_EXPRESSION: { - return EvaluateEnumMember(checker, enum_var, expr->AsMemberExpression()); - } - default: - break; - } - - return false; -} - -bool IsComputedEnumMember(const ir::Expression *init) -{ - if (init->IsLiteral()) { - return !init->AsLiteral()->IsStringLiteral() && !init->AsLiteral()->IsNumberLiteral(); - } - - if (init->IsTemplateLiteral()) { - return !init->AsTemplateLiteral()->Quasis().empty(); - } - - return true; -} - -void AddEnumValueDeclaration(checker::TSChecker *checker, double number, varbinder::EnumVariable *variable) -{ - variable->SetTsType(checker->GlobalNumberType()); - - util::StringView member_str = util::Helpers::ToStringView(checker->Allocator(), number); - - varbinder::LocalScope *enum_scope = checker->Scope()->AsLocalScope(); - varbinder::Variable *res = enum_scope->FindLocal(member_str, varbinder::ResolveBindingOptions::BINDINGS); - varbinder::EnumVariable *enum_var = nullptr; - - if (res == nullptr) { - auto *decl = checker->Allocator()->New(member_str); - decl->BindNode(variable->Declaration()->Node()); - enum_scope->AddDecl(checker->Allocator(), decl, ScriptExtension::TS); - res = enum_scope->FindLocal(member_str, varbinder::ResolveBindingOptions::BINDINGS); - ASSERT(res && res->IsEnumVariable()); - enum_var = res->AsEnumVariable(); - enum_var->AsEnumVariable()->SetBackReference(); - enum_var->SetTsType(checker->GlobalStringType()); - } else { - ASSERT(res->IsEnumVariable()); - enum_var = res->AsEnumVariable(); - auto *decl = checker->Allocator()->New(member_str); - decl->BindNode(variable->Declaration()->Node()); - enum_var->ResetDecl(decl); - } - - enum_var->SetValue(variable->Declaration()->Name()); -} - -void InferEnumVariableType(checker::TSChecker *checker, varbinder::EnumVariable *variable, double *value, - bool *init_next, bool *is_literal_enum, bool is_const_enum, - const ir::Expression *computed_expr) -{ - const ir::Expression *init = variable->Declaration()->Node()->AsTSEnumMember()->Init(); - - if (init == nullptr && *init_next) { - checker->ThrowTypeError("Enum member must have initializer.", variable->Declaration()->Node()->Start()); - } - - if (init == nullptr && !*init_next) { - variable->SetValue(++(*value)); - AddEnumValueDeclaration(checker, *value, variable); - return; - } - - ASSERT(init); - - if (IsComputedEnumMember(init)) { - if (*is_literal_enum) { - checker->ThrowTypeError("Computed values are not permitted in an enum with string valued members.", - init->Start()); - } - - computed_expr = init; - } - - varbinder::EnumMemberResult res = TSEnumDeclaration::EvaluateEnumMember(checker, variable, init); - if (std::holds_alternative(res)) { - if (computed_expr != nullptr) { - checker->ThrowTypeError("Computed values are not permitted in an enum with string valued members.", - computed_expr->Start()); - } - - *is_literal_enum = true; - variable->SetTsType(checker->GlobalStringType()); - *init_next = true; - return; - } - - if (std::holds_alternative(res)) { - if (is_const_enum) { - checker->ThrowTypeError( - "const enum member initializers can only contain literal values and other computed enum " - "values.", - init->Start()); - } - - *init_next = true; - return; - } - - ASSERT(std::holds_alternative(res)); - variable->SetValue(res); - - *value = std::get(res); - if (is_const_enum) { - if (std::isnan(*value)) { - checker->ThrowTypeError("'const' enum member initializer was evaluated to disallowed value 'NaN'.", - init->Start()); - } - - if (std::isinf(*value)) { - checker->ThrowTypeError("'const' enum member initializer was evaluated to a non-finite value.", - init->Start()); - } - } - - *init_next = false; - AddEnumValueDeclaration(checker, *value, variable); + etsg->GetAstCompiler()->Compile(this); } -checker::Type *TSEnumDeclaration::InferType(checker::TSChecker *checker, bool is_const) const +checker::Type *TSEnumDeclaration::Check(checker::TSChecker *checker) { - double value = -1.0; - - varbinder::LocalScope *enum_scope = checker->Scope()->AsLocalScope(); - - bool init_next = false; - bool is_literal_enum = false; - const ir::Expression *computed_expr = nullptr; - size_t locals_size = enum_scope->Decls().size(); - - for (size_t i = 0; i < locals_size; i++) { - const util::StringView ¤t_name = enum_scope->Decls()[i]->Name(); - varbinder::Variable *current_var = - enum_scope->FindLocal(current_name, varbinder::ResolveBindingOptions::BINDINGS); - ASSERT(current_var && current_var->IsEnumVariable()); - InferEnumVariableType(checker, current_var->AsEnumVariable(), &value, &init_next, &is_literal_enum, is_const, - computed_expr); - } - - checker::Type *enum_type = checker->Allocator()->New( - key_->Name(), checker->Scope(), - is_literal_enum ? checker::EnumLiteralType::EnumLiteralTypeKind::LITERAL - : checker::EnumLiteralType::EnumLiteralTypeKind::NUMERIC); - - return enum_type; -} - -checker::Type *TSEnumDeclaration::Check([[maybe_unused]] checker::TSChecker *checker) -{ - varbinder::Variable *enum_var = key_->Variable(); - ASSERT(enum_var); - - if (enum_var->TsType() == nullptr) { - checker::ScopeContext scope_ctx(checker, scope_); - checker::Type *enum_type = InferType(checker, is_const_); - enum_type->SetVariable(enum_var); - enum_var->SetTsType(enum_type); - } - - return nullptr; + return checker->GetAnalyzer()->Check(this); } checker::Type *TSEnumDeclaration::Check(checker::ETSChecker *const checker) { - varbinder::Variable *enum_var = key_->Variable(); - ASSERT(enum_var != nullptr); - - if (enum_var->TsType() == nullptr) { - checker::Type *ets_enum_type; - if (auto *const item_init = members_.front()->AsTSEnumMember()->Init(); item_init->IsNumberLiteral()) { - ets_enum_type = checker->CreateETSEnumType(this); - } else if (item_init->IsStringLiteral()) { - ets_enum_type = checker->CreateETSStringEnumType(this); - } else { - checker->ThrowTypeError("Invalid enumeration value type.", Start()); - } - SetTsType(ets_enum_type); - ets_enum_type->SetVariable(enum_var); - enum_var->SetTsType(ets_enum_type); - } else if (TsType() == nullptr) { - SetTsType(enum_var->TsType()); - } - - return TsType(); + return checker->GetAnalyzer()->Check(this); } } // namespace panda::es2panda::ir diff --git a/ets2panda/ir/ts/tsEnumDeclaration.h b/ets2panda/ir/ts/tsEnumDeclaration.h index 72a6d0870e70927c208743b2179173baf897b3e6..3380a13e4a12b39c1fddab666ba80bdc2b77d9a2 100644 --- a/ets2panda/ir/ts/tsEnumDeclaration.h +++ b/ets2panda/ir/ts/tsEnumDeclaration.h @@ -89,6 +89,11 @@ public: return decorators_; } + const ArenaVector *DecoratorsPtr() const override + { + return &Decorators(); + } + void AddDecorators([[maybe_unused]] ArenaVector &&decorators) override { decorators_ = std::move(decorators); @@ -101,14 +106,13 @@ public: static varbinder::EnumMemberResult EvaluateEnumMember(checker::TSChecker *checker, varbinder::EnumVariable *enum_var, const ir::AstNode *expr); - checker::Type *InferType(checker::TSChecker *checker, bool is_const) const; - void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; void Dump(ir::AstDumper *dumper) const override; - void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; - checker::Type *Check([[maybe_unused]] checker::TSChecker *checker) override; - checker::Type *Check([[maybe_unused]] checker::ETSChecker *checker) override; + void Compile(compiler::PandaGen *pg) const override; + void Compile(compiler::ETSGen *etsg) const override; + checker::Type *Check(checker::TSChecker *checker) override; + checker::Type *Check(checker::ETSChecker *checker) override; private: varbinder::LocalScope *scope_; diff --git a/ets2panda/ir/ts/tsEnumMember.cpp b/ets2panda/ir/ts/tsEnumMember.cpp index d0cb459a00ee3e5d787bc70aacf7b6c7f14c48cc..adb6873dd8b5ffb09e1c3451e10afe28b93c95ba 100644 --- a/ets2panda/ir/ts/tsEnumMember.cpp +++ b/ets2panda/ir/ts/tsEnumMember.cpp @@ -15,9 +15,9 @@ #include "tsEnumMember.h" -#include "ir/astDump.h" -#include "ir/expression.h" -#include "ir/expressions/identifier.h" +#include "checker/TSchecker.h" +#include "compiler/core/ETSGen.h" +#include "compiler/core/pandagen.h" namespace panda::es2panda::ir { void TSEnumMember::TransformChildren(const NodeTransformer &cb) @@ -49,15 +49,23 @@ util::StringView TSEnumMember::Name() const return key_->AsIdentifier()->Name(); } -void TSEnumMember::Compile([[maybe_unused]] compiler::PandaGen *pg) const {} +void TSEnumMember::Compile(compiler::PandaGen *pg) const +{ + pg->GetAstCompiler()->Compile(this); +} + +void TSEnumMember::Compile(compiler::ETSGen *etsg) const +{ + etsg->GetAstCompiler()->Compile(this); +} -checker::Type *TSEnumMember::Check([[maybe_unused]] checker::TSChecker *checker) +checker::Type *TSEnumMember::Check(checker::TSChecker *checker) { - return nullptr; + return checker->GetAnalyzer()->Check(this); } -checker::Type *TSEnumMember::Check([[maybe_unused]] checker::ETSChecker *checker) +checker::Type *TSEnumMember::Check(checker::ETSChecker *checker) { - return nullptr; + return checker->GetAnalyzer()->Check(this); } } // namespace panda::es2panda::ir diff --git a/ets2panda/ir/ts/tsEnumMember.h b/ets2panda/ir/ts/tsEnumMember.h index 52918aee6035283dfd9502090324f2035ba06f66..c169a782db2bbe14f6bcd09d903471fd837df8a1 100644 --- a/ets2panda/ir/ts/tsEnumMember.h +++ b/ets2panda/ir/ts/tsEnumMember.h @@ -43,9 +43,10 @@ public: void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; void Dump(ir::AstDumper *dumper) const override; - void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; - checker::Type *Check([[maybe_unused]] checker::TSChecker *checker) override; - checker::Type *Check([[maybe_unused]] checker::ETSChecker *checker) override; + void Compile(compiler::PandaGen *pg) const override; + void Compile(compiler::ETSGen *etsg) const override; + checker::Type *Check(checker::TSChecker *checker) override; + checker::Type *Check(checker::ETSChecker *checker) override; private: Expression *key_; diff --git a/ets2panda/ir/ts/tsExternalModuleReference.cpp b/ets2panda/ir/ts/tsExternalModuleReference.cpp index 5e9aa155d8e9903772b48181c504ae15de8bb758..601c235a021631515e75a58bcc15a6f566762db8 100644 --- a/ets2panda/ir/ts/tsExternalModuleReference.cpp +++ b/ets2panda/ir/ts/tsExternalModuleReference.cpp @@ -15,7 +15,9 @@ #include "tsExternalModuleReference.h" -#include "ir/astDump.h" +#include "checker/TSchecker.h" +#include "compiler/core/ETSGen.h" +#include "compiler/core/pandagen.h" namespace panda::es2panda::ir { void TSExternalModuleReference::TransformChildren(const NodeTransformer &cb) @@ -33,15 +35,23 @@ void TSExternalModuleReference::Dump(ir::AstDumper *dumper) const dumper->Add({{"type", "TSExternalModuleReference"}, {"expression", expr_}}); } -void TSExternalModuleReference::Compile([[maybe_unused]] compiler::PandaGen *pg) const {} +void TSExternalModuleReference::Compile(compiler::PandaGen *pg) const +{ + pg->GetAstCompiler()->Compile(this); +} + +void TSExternalModuleReference::Compile(compiler::ETSGen *etsg) const +{ + etsg->GetAstCompiler()->Compile(this); +} -checker::Type *TSExternalModuleReference::Check([[maybe_unused]] checker::TSChecker *checker) +checker::Type *TSExternalModuleReference::Check(checker::TSChecker *checker) { - return nullptr; + return checker->GetAnalyzer()->Check(this); } -checker::Type *TSExternalModuleReference::Check([[maybe_unused]] checker::ETSChecker *checker) +checker::Type *TSExternalModuleReference::Check(checker::ETSChecker *checker) { - return nullptr; + return checker->GetAnalyzer()->Check(this); } } // namespace panda::es2panda::ir diff --git a/ets2panda/ir/ts/tsExternalModuleReference.h b/ets2panda/ir/ts/tsExternalModuleReference.h index 2ab4685a25524fa460de66ddb231c6ffd88a94bd..00ec35da541200445121e4b99bbaf29834a6ec67 100644 --- a/ets2panda/ir/ts/tsExternalModuleReference.h +++ b/ets2panda/ir/ts/tsExternalModuleReference.h @@ -34,9 +34,10 @@ public: void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; void Dump(ir::AstDumper *dumper) const override; - void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; - checker::Type *Check([[maybe_unused]] checker::TSChecker *checker) override; - checker::Type *Check([[maybe_unused]] checker::ETSChecker *checker) override; + void Compile(compiler::PandaGen *pg) const override; + void Compile(compiler::ETSGen *etsg) const override; + checker::Type *Check(checker::TSChecker *checker) override; + checker::Type *Check(checker::ETSChecker *checker) override; private: Expression *expr_; diff --git a/ets2panda/ir/ts/tsInterfaceDeclaration.h b/ets2panda/ir/ts/tsInterfaceDeclaration.h index e209324087ebff6e72b4d94dd77acfee8c52eb2d..9ede275089e2f6b24cf5570e0da0f9de83682d62 100644 --- a/ets2panda/ir/ts/tsInterfaceDeclaration.h +++ b/ets2panda/ir/ts/tsInterfaceDeclaration.h @@ -120,6 +120,11 @@ public: return decorators_; } + const ArenaVector *DecoratorsPtr() const override + { + return &Decorators(); + } + void AddDecorators([[maybe_unused]] ArenaVector &&decorators) override { decorators_ = std::move(decorators); diff --git a/ets2panda/ir/ts/tsNumberKeyword.cpp b/ets2panda/ir/ts/tsNumberKeyword.cpp index 294e15b549f5c62458c1e8322542441823f881ad..13aca3172f286fb496bf7b9cbaecaacd2f6cdb43 100644 --- a/ets2panda/ir/ts/tsNumberKeyword.cpp +++ b/ets2panda/ir/ts/tsNumberKeyword.cpp @@ -15,8 +15,9 @@ #include "tsNumberKeyword.h" -#include "ir/astDump.h" #include "checker/TSchecker.h" +#include "compiler/core/ETSGen.h" +#include "compiler/core/pandagen.h" namespace panda::es2panda::ir { void TSNumberKeyword::TransformChildren([[maybe_unused]] const NodeTransformer &cb) {} @@ -27,11 +28,19 @@ void TSNumberKeyword::Dump(ir::AstDumper *dumper) const dumper->Add({{"type", "TSNumberKeyword"}}); } -void TSNumberKeyword::Compile([[maybe_unused]] compiler::PandaGen *pg) const {} +void TSNumberKeyword::Compile(compiler::PandaGen *pg) const +{ + pg->GetAstCompiler()->Compile(this); +} + +void TSNumberKeyword::Compile(compiler::ETSGen *etsg) const +{ + etsg->GetAstCompiler()->Compile(this); +} -checker::Type *TSNumberKeyword::Check([[maybe_unused]] checker::TSChecker *checker) +checker::Type *TSNumberKeyword::Check(checker::TSChecker *checker) { - return nullptr; + return checker->GetAnalyzer()->Check(this); } checker::Type *TSNumberKeyword::GetType([[maybe_unused]] checker::TSChecker *checker) @@ -39,8 +48,8 @@ checker::Type *TSNumberKeyword::GetType([[maybe_unused]] checker::TSChecker *che return checker->GlobalNumberType(); } -checker::Type *TSNumberKeyword::Check([[maybe_unused]] checker::ETSChecker *checker) +checker::Type *TSNumberKeyword::Check(checker::ETSChecker *checker) { - return nullptr; + return checker->GetAnalyzer()->Check(this); } } // namespace panda::es2panda::ir diff --git a/ets2panda/ir/ts/tsNumberKeyword.h b/ets2panda/ir/ts/tsNumberKeyword.h index f9012741687d4613e41392c7af9b026847ad9e0a..5debdb8a4a114c28859cc24b147b06321b57eeb1 100644 --- a/ets2panda/ir/ts/tsNumberKeyword.h +++ b/ets2panda/ir/ts/tsNumberKeyword.h @@ -26,10 +26,11 @@ public: void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; void Dump(ir::AstDumper *dumper) const override; - void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; - checker::Type *Check([[maybe_unused]] checker::TSChecker *checker) override; + void Compile(compiler::PandaGen *pg) const override; + void Compile(compiler::ETSGen *etsg) const override; + checker::Type *Check(checker::TSChecker *checker) override; checker::Type *GetType([[maybe_unused]] checker::TSChecker *checker) override; - checker::Type *Check([[maybe_unused]] checker::ETSChecker *checker) override; + checker::Type *Check(checker::ETSChecker *checker) override; }; } // namespace panda::es2panda::ir diff --git a/ets2panda/ir/ts/tsObjectKeyword.cpp b/ets2panda/ir/ts/tsObjectKeyword.cpp index eb471e9d7b1502b6ba6895968a7fc19c2d77e7c8..da0fea006153b8aca88c0a39aecb43b9f7db034f 100644 --- a/ets2panda/ir/ts/tsObjectKeyword.cpp +++ b/ets2panda/ir/ts/tsObjectKeyword.cpp @@ -15,8 +15,9 @@ #include "tsObjectKeyword.h" -#include "ir/astDump.h" #include "checker/TSchecker.h" +#include "compiler/core/ETSGen.h" +#include "compiler/core/pandagen.h" namespace panda::es2panda::ir { void TSObjectKeyword::TransformChildren([[maybe_unused]] const NodeTransformer &cb) {} @@ -27,11 +28,19 @@ void TSObjectKeyword::Dump(ir::AstDumper *dumper) const dumper->Add({{"type", "TSObjectKeyword"}}); } -void TSObjectKeyword::Compile([[maybe_unused]] compiler::PandaGen *pg) const {} +void TSObjectKeyword::Compile([[maybe_unused]] compiler::PandaGen *pg) const +{ + pg->GetAstCompiler()->Compile(this); +} + +void TSObjectKeyword::Compile([[maybe_unused]] compiler::ETSGen *etsg) const +{ + etsg->GetAstCompiler()->Compile(this); +} checker::Type *TSObjectKeyword::Check([[maybe_unused]] checker::TSChecker *checker) { - return nullptr; + return checker->GetAnalyzer()->Check(this); } checker::Type *TSObjectKeyword::GetType([[maybe_unused]] checker::TSChecker *checker) @@ -41,6 +50,6 @@ checker::Type *TSObjectKeyword::GetType([[maybe_unused]] checker::TSChecker *che checker::Type *TSObjectKeyword::Check([[maybe_unused]] checker::ETSChecker *checker) { - return nullptr; + return checker->GetAnalyzer()->Check(this); } } // namespace panda::es2panda::ir diff --git a/ets2panda/ir/ts/tsObjectKeyword.h b/ets2panda/ir/ts/tsObjectKeyword.h index d06a36dde29392f550497276e762ee1a3272e4aa..ecbb83c4518d66c430daa21e2884b04c653c30f8 100644 --- a/ets2panda/ir/ts/tsObjectKeyword.h +++ b/ets2panda/ir/ts/tsObjectKeyword.h @@ -26,10 +26,11 @@ public: void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; void Dump(ir::AstDumper *dumper) const override; - void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; - checker::Type *Check([[maybe_unused]] checker::TSChecker *checker) override; + void Compile(compiler::PandaGen *pg) const override; + void Compile(compiler::ETSGen *etsg) const override; + checker::Type *Check(checker::TSChecker *checker) override; checker::Type *GetType([[maybe_unused]] checker::TSChecker *checker) override; - checker::Type *Check([[maybe_unused]] checker::ETSChecker *checker) override; + checker::Type *Check(checker::ETSChecker *checker) override; }; } // namespace panda::es2panda::ir diff --git a/ets2panda/ir/ts/tsStringKeyword.cpp b/ets2panda/ir/ts/tsStringKeyword.cpp index 3374b8bb51d9eccd2a48ca08990eab939e65a420..11caf9ca5a439ab380ae10e48c43135243033167 100644 --- a/ets2panda/ir/ts/tsStringKeyword.cpp +++ b/ets2panda/ir/ts/tsStringKeyword.cpp @@ -15,8 +15,9 @@ #include "tsStringKeyword.h" -#include "ir/astDump.h" #include "checker/TSchecker.h" +#include "compiler/core/ETSGen.h" +#include "compiler/core/pandagen.h" namespace panda::es2panda::ir { void TSStringKeyword::TransformChildren([[maybe_unused]] const NodeTransformer &cb) {} @@ -27,11 +28,19 @@ void TSStringKeyword::Dump(ir::AstDumper *dumper) const dumper->Add({{"type", "TSStringKeyword"}}); } -void TSStringKeyword::Compile([[maybe_unused]] compiler::PandaGen *pg) const {} +void TSStringKeyword::Compile(compiler::PandaGen *pg) const +{ + pg->GetAstCompiler()->Compile(this); +} + +void TSStringKeyword::Compile(compiler::ETSGen *etsg) const +{ + etsg->GetAstCompiler()->Compile(this); +} -checker::Type *TSStringKeyword::Check([[maybe_unused]] checker::TSChecker *checker) +checker::Type *TSStringKeyword::Check(checker::TSChecker *checker) { - return nullptr; + return checker->GetAnalyzer()->Check(this); } checker::Type *TSStringKeyword::GetType([[maybe_unused]] checker::TSChecker *checker) @@ -39,8 +48,8 @@ checker::Type *TSStringKeyword::GetType([[maybe_unused]] checker::TSChecker *che return checker->GlobalStringType(); } -checker::Type *TSStringKeyword::Check([[maybe_unused]] checker::ETSChecker *checker) +checker::Type *TSStringKeyword::Check(checker::ETSChecker *checker) { - return nullptr; + return checker->GetAnalyzer()->Check(this); } } // namespace panda::es2panda::ir diff --git a/ets2panda/ir/ts/tsStringKeyword.h b/ets2panda/ir/ts/tsStringKeyword.h index 14b8cf390d545b080368bce3979fa6622077265e..611c2a70f90643775d63d26876d10b9c4cb40998 100644 --- a/ets2panda/ir/ts/tsStringKeyword.h +++ b/ets2panda/ir/ts/tsStringKeyword.h @@ -26,10 +26,11 @@ public: void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; void Dump(ir::AstDumper *dumper) const override; - void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; - checker::Type *Check([[maybe_unused]] checker::TSChecker *checker) override; + void Compile(compiler::PandaGen *pg) const override; + void Compile(compiler::ETSGen *etsg) const override; + checker::Type *Check(checker::TSChecker *checker) override; checker::Type *GetType([[maybe_unused]] checker::TSChecker *checker) override; - checker::Type *Check([[maybe_unused]] checker::ETSChecker *checker) override; + checker::Type *Check(checker::ETSChecker *checker) override; }; } // namespace panda::es2panda::ir diff --git a/ets2panda/ir/ts/tsTypeAliasDeclaration.h b/ets2panda/ir/ts/tsTypeAliasDeclaration.h index 5dc000528a098a4fca951d7e7431644d01f39082..77061cb11274a031479d4f0c9e89fef551171035 100644 --- a/ets2panda/ir/ts/tsTypeAliasDeclaration.h +++ b/ets2panda/ir/ts/tsTypeAliasDeclaration.h @@ -72,6 +72,11 @@ public: return decorators_; } + const ArenaVector *DecoratorsPtr() const override + { + return &Decorators(); + } + void AddTypeParameters(ir::TSTypeParameterDeclaration *type_params) { type_params_ = type_params; diff --git a/ets2panda/ir/ts/tsTypeParameterDeclaration.h b/ets2panda/ir/ts/tsTypeParameterDeclaration.h index 6e203679adc7e041816cf6af1c97fc13b9de56f3..0d9b263ebab82dc22b4a58ea8853f394322fe39b 100644 --- a/ets2panda/ir/ts/tsTypeParameterDeclaration.h +++ b/ets2panda/ir/ts/tsTypeParameterDeclaration.h @@ -18,9 +18,9 @@ #include "varbinder/scope.h" #include "ir/expression.h" +#include "ir/ts/tsTypeParameter.h" namespace panda::es2panda::ir { -class TSTypeParameter; class TSTypeParameterDeclaration : public Expression { public: @@ -48,6 +48,14 @@ public: return params_; } + void AddParam(TSTypeParameter *param) + { + if (required_params_ == params_.size() && param->DefaultType() == nullptr) { + required_params_++; + } + params_.push_back(param); + } + size_t RequiredParams() const { return required_params_; diff --git a/ets2panda/ir/ts/tsTypeParameterInstantiation.cpp b/ets2panda/ir/ts/tsTypeParameterInstantiation.cpp index 614e9798df1fab0d259a248af6eb144a817379d9..f9906355134f706cc9f02bc68efa1eebce3c9ef6 100644 --- a/ets2panda/ir/ts/tsTypeParameterInstantiation.cpp +++ b/ets2panda/ir/ts/tsTypeParameterInstantiation.cpp @@ -27,12 +27,13 @@ TSTypeParameterInstantiation::TSTypeParameterInstantiation([[maybe_unused]] Tag : Expression(static_cast(other)), params_(allocator->Adapter()) { for (auto *param : other.params_) { - params_.emplace_back(param->Clone(allocator, this)->AsTypeNode()); + params_.emplace_back(param->Clone(allocator, this)); } } // NOLINTNEXTLINE(google-default-arguments) -Expression *TSTypeParameterInstantiation::Clone(ArenaAllocator *const allocator, AstNode *const parent) +TSTypeParameterInstantiation *TSTypeParameterInstantiation::Clone(ArenaAllocator *const allocator, + AstNode *const parent) { if (auto *const clone = allocator->New(Tag {}, *this, allocator); clone != nullptr) { if (parent != nullptr) { diff --git a/ets2panda/ir/ts/tsTypeParameterInstantiation.h b/ets2panda/ir/ts/tsTypeParameterInstantiation.h index 727e08911e51a4b2b7e2b7195e298efe543c6f08..09db9a4b1df80ee993004e47adeab28c5347e851 100644 --- a/ets2panda/ir/ts/tsTypeParameterInstantiation.h +++ b/ets2panda/ir/ts/tsTypeParameterInstantiation.h @@ -43,7 +43,7 @@ public: } // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] Expression *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + [[nodiscard]] TSTypeParameterInstantiation *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; diff --git a/ets2panda/ir/ts/tsUndefinedKeyword.cpp b/ets2panda/ir/ts/tsUndefinedKeyword.cpp index 6d889996c82dab60fced9a83fd9230db62ce8c4d..ba59f6f222104216981d9d0947bfec593be26db7 100644 --- a/ets2panda/ir/ts/tsUndefinedKeyword.cpp +++ b/ets2panda/ir/ts/tsUndefinedKeyword.cpp @@ -15,8 +15,9 @@ #include "tsUndefinedKeyword.h" -#include "ir/astDump.h" #include "checker/TSchecker.h" +#include "compiler/core/ETSGen.h" +#include "compiler/core/pandagen.h" namespace panda::es2panda::ir { void TSUndefinedKeyword::TransformChildren([[maybe_unused]] const NodeTransformer &cb) {} @@ -27,11 +28,19 @@ void TSUndefinedKeyword::Dump(ir::AstDumper *dumper) const dumper->Add({{"type", "TSUndefinedKeyword"}}); } -void TSUndefinedKeyword::Compile([[maybe_unused]] compiler::PandaGen *pg) const {} +void TSUndefinedKeyword::Compile(compiler::PandaGen *pg) const +{ + pg->GetAstCompiler()->Compile(this); +} + +void TSUndefinedKeyword::Compile(compiler::ETSGen *etsg) const +{ + etsg->GetAstCompiler()->Compile(this); +} -checker::Type *TSUndefinedKeyword::Check([[maybe_unused]] checker::TSChecker *checker) +checker::Type *TSUndefinedKeyword::Check(checker::TSChecker *checker) { - return nullptr; + return checker->GetAnalyzer()->Check(this); } checker::Type *TSUndefinedKeyword::GetType([[maybe_unused]] checker::TSChecker *checker) @@ -39,8 +48,8 @@ checker::Type *TSUndefinedKeyword::GetType([[maybe_unused]] checker::TSChecker * return checker->GlobalUndefinedType(); } -checker::Type *TSUndefinedKeyword::Check([[maybe_unused]] checker::ETSChecker *checker) +checker::Type *TSUndefinedKeyword::Check(checker::ETSChecker *checker) { - return nullptr; + return checker->GetAnalyzer()->Check(this); } } // namespace panda::es2panda::ir diff --git a/ets2panda/ir/ts/tsUndefinedKeyword.h b/ets2panda/ir/ts/tsUndefinedKeyword.h index 1dcc42d743a2803f468a43a8c3b008a09752eca3..1bbf96fcfdea6d51a220218457fc74afa8ab5703 100644 --- a/ets2panda/ir/ts/tsUndefinedKeyword.h +++ b/ets2panda/ir/ts/tsUndefinedKeyword.h @@ -26,10 +26,11 @@ public: void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; void Dump(ir::AstDumper *dumper) const override; - void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; - checker::Type *Check([[maybe_unused]] checker::TSChecker *checker) override; + void Compile(compiler::PandaGen *pg) const override; + void Compile(compiler::ETSGen *etsg) const override; + checker::Type *Check(checker::TSChecker *checker) override; checker::Type *GetType([[maybe_unused]] checker::TSChecker *checker) override; - checker::Type *Check([[maybe_unused]] checker::ETSChecker *checker) override; + checker::Type *Check(checker::ETSChecker *checker) override; }; } // namespace panda::es2panda::ir diff --git a/ets2panda/ir/ts/tsUnknownKeyword.cpp b/ets2panda/ir/ts/tsUnknownKeyword.cpp index 3799e4b62b1b288094101bfeda5d8b18558db5b7..d8e35bf46a3b69854a8209cb66f10adb66a48b21 100644 --- a/ets2panda/ir/ts/tsUnknownKeyword.cpp +++ b/ets2panda/ir/ts/tsUnknownKeyword.cpp @@ -15,8 +15,9 @@ #include "tsUnknownKeyword.h" -#include "ir/astDump.h" #include "checker/TSchecker.h" +#include "compiler/core/ETSGen.h" +#include "compiler/core/pandagen.h" namespace panda::es2panda::ir { void TSUnknownKeyword::TransformChildren([[maybe_unused]] const NodeTransformer &cb) {} @@ -27,11 +28,19 @@ void TSUnknownKeyword::Dump(ir::AstDumper *dumper) const dumper->Add({{"type", "TSUnknownKeyword"}}); } -void TSUnknownKeyword::Compile([[maybe_unused]] compiler::PandaGen *pg) const {} +void TSUnknownKeyword::Compile(compiler::PandaGen *pg) const +{ + pg->GetAstCompiler()->Compile(this); +} + +void TSUnknownKeyword::Compile(compiler::ETSGen *etsg) const +{ + etsg->GetAstCompiler()->Compile(this); +} -checker::Type *TSUnknownKeyword::Check([[maybe_unused]] checker::TSChecker *checker) +checker::Type *TSUnknownKeyword::Check(checker::TSChecker *checker) { - return nullptr; + return checker->GetAnalyzer()->Check(this); } checker::Type *TSUnknownKeyword::GetType([[maybe_unused]] checker::TSChecker *checker) @@ -39,8 +48,8 @@ checker::Type *TSUnknownKeyword::GetType([[maybe_unused]] checker::TSChecker *ch return checker->GlobalUnknownType(); } -checker::Type *TSUnknownKeyword::Check([[maybe_unused]] checker::ETSChecker *checker) +checker::Type *TSUnknownKeyword::Check(checker::ETSChecker *checker) { - return nullptr; + return checker->GetAnalyzer()->Check(this); } } // namespace panda::es2panda::ir diff --git a/ets2panda/ir/ts/tsUnknownKeyword.h b/ets2panda/ir/ts/tsUnknownKeyword.h index 0e912ca124800fd68f94ae4bf3a615cfadfdaec2..642f239a53d7f929e544c44b1b2e63a0c4cd5299 100644 --- a/ets2panda/ir/ts/tsUnknownKeyword.h +++ b/ets2panda/ir/ts/tsUnknownKeyword.h @@ -26,10 +26,11 @@ public: void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; void Dump(ir::AstDumper *dumper) const override; - void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; - checker::Type *Check([[maybe_unused]] checker::TSChecker *checker) override; + void Compile(compiler::PandaGen *pg) const override; + void Compile(compiler::ETSGen *etsg) const override; + checker::Type *Check(checker::TSChecker *checker) override; checker::Type *GetType([[maybe_unused]] checker::TSChecker *checker) override; - checker::Type *Check([[maybe_unused]] checker::ETSChecker *checker) override; + checker::Type *Check(checker::ETSChecker *checker) override; }; } // namespace panda::es2panda::ir diff --git a/ets2panda/ir/ts/tsVoidKeyword.cpp b/ets2panda/ir/ts/tsVoidKeyword.cpp index 43417ff96ac18a52f86f0ea68ce7fded722ac217..47502deb375b1b5088bd99d2837c606d2f93b6d4 100644 --- a/ets2panda/ir/ts/tsVoidKeyword.cpp +++ b/ets2panda/ir/ts/tsVoidKeyword.cpp @@ -15,8 +15,9 @@ #include "tsVoidKeyword.h" -#include "ir/astDump.h" #include "checker/TSchecker.h" +#include "compiler/core/ETSGen.h" +#include "compiler/core/pandagen.h" namespace panda::es2panda::ir { void TSVoidKeyword::TransformChildren([[maybe_unused]] const NodeTransformer &cb) {} @@ -27,11 +28,19 @@ void TSVoidKeyword::Dump(ir::AstDumper *dumper) const dumper->Add({{"type", "TSVoidKeyword"}}); } -void TSVoidKeyword::Compile([[maybe_unused]] compiler::PandaGen *pg) const {} +void TSVoidKeyword::Compile(compiler::PandaGen *pg) const +{ + pg->GetAstCompiler()->Compile(this); +} + +void TSVoidKeyword::Compile(compiler::ETSGen *etsg) const +{ + etsg->GetAstCompiler()->Compile(this); +} -checker::Type *TSVoidKeyword::Check([[maybe_unused]] checker::TSChecker *checker) +checker::Type *TSVoidKeyword::Check(checker::TSChecker *checker) { - return nullptr; + return checker->GetAnalyzer()->Check(this); } checker::Type *TSVoidKeyword::GetType([[maybe_unused]] checker::TSChecker *checker) @@ -39,8 +48,8 @@ checker::Type *TSVoidKeyword::GetType([[maybe_unused]] checker::TSChecker *check return checker->GlobalVoidType(); } -checker::Type *TSVoidKeyword::Check([[maybe_unused]] checker::ETSChecker *checker) +checker::Type *TSVoidKeyword::Check(checker::ETSChecker *checker) { - return nullptr; + return checker->GetAnalyzer()->Check(this); } } // namespace panda::es2panda::ir diff --git a/ets2panda/ir/ts/tsVoidKeyword.h b/ets2panda/ir/ts/tsVoidKeyword.h index 6a1d20d35d712a7631f8c1e483d6ae377c68048d..d1869ab617e16b767aaf296e818456b3d6d91067 100644 --- a/ets2panda/ir/ts/tsVoidKeyword.h +++ b/ets2panda/ir/ts/tsVoidKeyword.h @@ -26,10 +26,11 @@ public: void TransformChildren(const NodeTransformer &cb) override; void Iterate(const NodeTraverser &cb) const override; void Dump(ir::AstDumper *dumper) const override; - void Compile([[maybe_unused]] compiler::PandaGen *pg) const override; - checker::Type *Check([[maybe_unused]] checker::TSChecker *checker) override; + void Compile(compiler::PandaGen *pg) const override; + void Compile(compiler::ETSGen *etsg) const override; + checker::Type *Check(checker::TSChecker *checker) override; checker::Type *GetType([[maybe_unused]] checker::TSChecker *checker) override; - checker::Type *Check([[maybe_unused]] checker::ETSChecker *checker) override; + checker::Type *Check(checker::ETSChecker *checker) override; }; } // namespace panda::es2panda::ir diff --git a/ets2panda/ir/typeNode.cpp b/ets2panda/ir/typeNode.cpp index 991f0a7d9549324e03af7194c032c78265f17765..be22e10ee704a4131e7b904c37bcbe46245b34a3 100644 --- a/ets2panda/ir/typeNode.cpp +++ b/ets2panda/ir/typeNode.cpp @@ -14,13 +14,14 @@ */ #include "typeNode.h" +#include "astNode.h" #include "opaqueTypeNode.h" #include "es2panda.h" namespace panda::es2panda::ir { // NOLINTNEXTLINE(google-default-arguments) -Expression *TypeNode::Clone(ArenaAllocator *const allocator, AstNode *const parent) +TypeNode *TypeNode::Clone(ArenaAllocator *const allocator, AstNode *const parent) { if (auto *const type = TsType(); type != nullptr) { if (auto *const clone = allocator->New(type); clone != nullptr) { diff --git a/ets2panda/ir/typeNode.h b/ets2panda/ir/typeNode.h index c92340a3a1fb3512ce77ef4a6f345f4a901154e4..7933f9b5e407daaa0898bc2b39b20c5107b542c4 100644 --- a/ets2panda/ir/typeNode.h +++ b/ets2panda/ir/typeNode.h @@ -48,7 +48,7 @@ public: } // NOLINTNEXTLINE(google-default-arguments) - [[nodiscard]] Expression *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; + [[nodiscard]] TypeNode *Clone(ArenaAllocator *allocator, AstNode *parent = nullptr) override; protected: explicit TypeNode(AstNodeType const type) : Expression(type) {} diff --git a/ets2panda/lexer/lexer.cpp b/ets2panda/lexer/lexer.cpp index 0b26a83a572ab5f91fd822575265418f1b88cc2b..dba2f94d63d0f02821d977264f6a2c63c89ba75a 100644 --- a/ets2panda/lexer/lexer.cpp +++ b/ets2panda/lexer/lexer.cpp @@ -779,6 +779,16 @@ void Lexer::ScanAmpersandPunctuator() } } +void Lexer::ScanAtPunctuator() +{ + GetToken().type_ = TokenType::PUNCTUATOR_AT; + + if (Iterator().Peek() == LEX_CHAR_AT) { + GetToken().type_ = TokenType::PUNCTUATOR_FORMAT; + Iterator().Forward(1U); + } +} + void Lexer::ScanVLinePunctuator() { GetToken().type_ = TokenType::PUNCTUATOR_BITWISE_OR; @@ -1360,7 +1370,7 @@ void Lexer::NextToken(Keywords *kws) break; } case LEX_CHAR_AT: { - GetToken().type_ = TokenType::PUNCTUATOR_AT; + ScanAtPunctuator(); break; } case LEX_CHAR_DOLLAR_SIGN: { diff --git a/ets2panda/lexer/lexer.h b/ets2panda/lexer/lexer.h index 2a36059a2b794a8adc91a9e1157818af3cdaa925..4f8cd73a1c419a0fb8f80c11bb5d906afc8a9bbb 100644 --- a/ets2panda/lexer/lexer.h +++ b/ets2panda/lexer/lexer.h @@ -230,6 +230,7 @@ protected: void ScanDotPunctuator(); void ScanColonPunctuator(); virtual bool ScanDollarPunctuator(); + void ScanAtPunctuator(); virtual void SkipMultiLineComment(); virtual void ScanHashMark(); diff --git a/ets2panda/lexer/token/token.cpp b/ets2panda/lexer/token/token.cpp index a6bb09dfb07aecbb655dc95c9f7f5ed36c03021f..885adaa546e630541797b437148728de124496b7 100644 --- a/ets2panda/lexer/token/token.cpp +++ b/ets2panda/lexer/token/token.cpp @@ -226,6 +226,8 @@ const char *TokenToString(TokenType type) // NOLINT(readability-function-size) return "?."; case TokenType::PUNCTUATOR_AT: return "@"; + case TokenType::PUNCTUATOR_FORMAT: + return "@@"; case TokenType::PUNCTUATOR_RIGHT_PARENTHESIS: return ")"; case TokenType::PUNCTUATOR_LEFT_PARENTHESIS: diff --git a/ets2panda/lexer/token/tokenType.h b/ets2panda/lexer/token/tokenType.h index 7872cd90d76aa93d05d2378891c5308c25306e53..5f6b4df393764e869320bfe0d29b3622c13ee530 100644 --- a/ets2panda/lexer/token/tokenType.h +++ b/ets2panda/lexer/token/tokenType.h @@ -94,6 +94,7 @@ enum class TokenType { PUNCTUATOR_BACK_TICK, PUNCTUATOR_HASH_MARK, PUNCTUATOR_AT, + PUNCTUATOR_FORMAT, PUNCTUATOR_DOLLAR_DOLLAR, /* contextual keywords */ diff --git a/ets2panda/linter-4.2/cookbook_convertor/src/cookbook_convertor.ts b/ets2panda/linter-4.2/cookbook_convertor/src/cookbook_convertor.ts index 65279a304b149cf2bebff17f664eddb54044ca57..d6e672ebff585f03aa6bcaf4354dae59e10eaf46 100644 --- a/ets2panda/linter-4.2/cookbook_convertor/src/cookbook_convertor.ts +++ b/ets2panda/linter-4.2/cookbook_convertor/src/cookbook_convertor.ts @@ -102,8 +102,6 @@ console.log(" NUMBER: " + ruleNum) } if( doc_lines[ _line ].startsWith( CB_R ) ) { let line = doc_lines[ _line ].split( CB_R )[1]; - //let tegNumStr = line.split(':')[0]; - //let ruleNum = Number(tegNumStr.split('#')[1]); ruleNames[ ruleNum ] = line; //line.split(':')[1]; _line++; needHeader(); @@ -146,7 +144,6 @@ function translateLine( s: string ) : string { let line = s; line = line.replace( CB_BAD, "TypeScript"); line = line.replace( CB_OK, "ArkTS"); - //line = line.replace( "|CB_R|", "Recipe"); //.. |CB_RULE| replace:: Rule line = line.replace( CB_ERROR, "**Severity: error**" ); line = line.replace( CB_WARNING, "**Severity: warning**" ); @@ -300,7 +297,6 @@ console.error(">>>BODY 3 HDR>>>: " + + _line + " -> " + doc_lines[_line]); } //_line++; while( !isHeader() || doc_lines[ _line ].startsWith( CB_ERROR ) || doc_lines[ _line ].startsWith( CB_WARNING ) ) { - //skipEmptyLines(); let s = translateLine( doc_lines[_line] ); mdText.push(s); @@ -337,7 +333,6 @@ console.error(">>>makeBAD HDR>>>: " + doc_lines[_line]); mdText.push(""); while( _line < doc_lines.length && !isHeader() ) { - //skipEmptyLines(); let s = translateLine( doc_lines[_line] ); mdText.push( s ); @@ -382,7 +377,6 @@ console.error( ">>>makeOK HDR>>>: " + doc_lines[ _line ] ); mdText.push(""); while( _line < doc_lines.length && !isHeader() ) { - //skipEmptyLines(); let s = translateLine( doc_lines[ _line ] ); mdText.push( s ); @@ -417,8 +411,6 @@ console.error( ">>>makeOK HDR>>>: " + doc_lines[ _line ] ); function makeSee( ): string { - //mdText.push("## See also"); - //mdText.push(""); const RECIPE = "Recipe "; console.error(">>> #" + recNum + " PASSED: " + doc_lines[_line]); while( _line < doc_lines.length && !doc_lines[ _line ].startsWith( ".." ) ) { @@ -461,10 +453,7 @@ if( commandLineArgs[0] == '-md') { MAKE_MD = true; } let inFileName = commandLineArgs[0]; -//console.error(inFileName); console.log(COPYRIGHT_HEADER); -//console.log("export const cookBookMsg: string[] = []; \n"); -//console.log("export const cookBookTag: string[] = []; \n"); console.log( CODE_PROLOGUE ); syncReadFile( inFileName); diff --git a/ets2panda/linter-4.2/src/Autofixer.ts b/ets2panda/linter-4.2/src/Autofixer.ts index 940ad3b1ae7f09a990b856f6b8ae0a5d7b86b537..d082f5ade8234e5feb0f20069176f9e16bd2b751 100644 --- a/ets2panda/linter-4.2/src/Autofixer.ts +++ b/ets2panda/linter-4.2/src/Autofixer.ts @@ -45,7 +45,9 @@ export class AutofixInfoSet { public shouldAutofix(node: ts.Node, faultID: FaultID): boolean { if (UNSAFE_FIXES.includes(faultID)) return false; if (this.autofixInfo.length === 0) return false; - if (this.autofixInfo.length === 1 && this.autofixInfo[0] == AUTOFIX_ALL) return true; + if (this.autofixInfo.length === 1 && this.autofixInfo[0] === AUTOFIX_ALL) { + return true; + } return this.autofixInfo.findIndex( value => value.start === node.getStart() && value.end === node.getEnd() && value.problemID === FaultID[faultID] ) !== -1; @@ -56,7 +58,7 @@ export function fixLiteralAsPropertyName(node: ts.Node): Autofix[] | undefined { if (ts.isPropertyDeclaration(node) || ts.isPropertyAssignment(node)) { let propName = (node as (ts.PropertyDeclaration | ts.PropertyAssignment)).name; let identName = propertyName2IdentifierName(propName); - if (identName) + if (identName) return [{ replacementText: identName, start: propName.getStart(), end: propName.getEnd() }]; } return undefined; @@ -66,21 +68,21 @@ export function fixPropertyAccessByIndex(node: ts.Node): Autofix[] | undefined { if (ts.isElementAccessExpression(node)) { let elemAccess = node as ts.ElementAccessExpression; let identifierName = indexExpr2IdentifierName(elemAccess.argumentExpression); - if (identifierName) - return [{ - replacementText: elemAccess.expression.getText() + '.' + identifierName, - start: elemAccess.getStart(), end: elemAccess.getEnd() + if (identifierName) + return [{ + replacementText: elemAccess.expression.getText() + '.' + identifierName, + start: elemAccess.getStart(), end: elemAccess.getEnd() }]; } return undefined; } -export function fixFunctionExpression(funcExpr: ts.FunctionExpression, - params: ts.NodeArray = funcExpr.parameters, +export function fixFunctionExpression(funcExpr: ts.FunctionExpression, + params: ts.NodeArray = funcExpr.parameters, retType: ts.TypeNode | undefined = funcExpr.type, modifiers: readonly ts.Modifier[] | undefined): Autofix { let arrowFunc: ts.Expression = ts.factory.createArrowFunction( - modifiers, undefined, params, retType, ts.factory.createToken(ts.SyntaxKind.EqualsGreaterThanToken), + modifiers, undefined, params, retType, ts.factory.createToken(ts.SyntaxKind.EqualsGreaterThanToken), funcExpr.body ); if (needsParentheses(funcExpr)) { @@ -118,7 +120,7 @@ export function dropTypeOnlyFlag( return { start: impExpNode.getStart(), end: impExpNode.getEnd(), replacementText: text }; } -export function fixDefaultImport(importClause: ts.ImportClause, +export function fixDefaultImport(importClause: ts.ImportClause, defaultSpec: ts.ImportSpecifier, nonDefaultSpecs: ts.ImportSpecifier[]): Autofix { let nameBindings = nonDefaultSpecs.length > 0 ? ts.factory.createNamedImports(nonDefaultSpecs) : undefined; let newImportClause = ts.factory.createImportClause(importClause.isTypeOnly, defaultSpec.name, nameBindings); @@ -144,22 +146,22 @@ function stringLiteral2IdentifierName(str: ts.StringLiteral) { } function propertyName2IdentifierName(name: ts.PropertyName): string { - if (name.kind === ts.SyntaxKind.NumericLiteral) + if (name.kind === ts.SyntaxKind.NumericLiteral) return numericLiteral2IdentifierName(name as ts.NumericLiteral); - if (name.kind === ts.SyntaxKind.StringLiteral) + if (name.kind === ts.SyntaxKind.StringLiteral) return stringLiteral2IdentifierName(name as ts.StringLiteral); - + return ''; } function indexExpr2IdentifierName(index: ts.Expression) { - if (index.kind === ts.SyntaxKind.NumericLiteral) + if (index.kind === ts.SyntaxKind.NumericLiteral) return numericLiteral2IdentifierName(index as ts.NumericLiteral); - if (index.kind === ts.SyntaxKind.StringLiteral) + if (index.kind === ts.SyntaxKind.StringLiteral) return stringLiteral2IdentifierName(index as ts.StringLiteral); - + return ''; } @@ -171,7 +173,7 @@ function getReturnTypePosition(funcLikeDecl: ts.FunctionLikeDeclaration): number let postParametersPosition = ts.isArrowFunction(funcLikeDecl) ? funcLikeDecl.equalsGreaterThanToken.getStart() : funcLikeDecl.body.getStart(); - + const children = funcLikeDecl.getChildren(); for (let i = children.length - 1; i >= 0; i--) { const child = children[i]; diff --git a/ets2panda/linter-4.2/src/LibraryTypeCallDiagnosticChecker.ts b/ets2panda/linter-4.2/src/LibraryTypeCallDiagnosticChecker.ts index f34e4f8617d2a39249b77db763618a0ef2a39d2e..e80b4025a56a37011308d42eb0727c3687e73210 100644 --- a/ets2panda/linter-4.2/src/LibraryTypeCallDiagnosticChecker.ts +++ b/ets2panda/linter-4.2/src/LibraryTypeCallDiagnosticChecker.ts @@ -36,7 +36,7 @@ export class LibraryTypeCallDiagnosticChecker implements DiagnosticChecker { this.filteredDiagnosticMessages = filteredDiagnosticMessages; } - configure(inLibCall: boolean, diagnosticMessages: Array) { + configure(inLibCall: boolean, diagnosticMessages: Array): void { this.inLibCall = inLibCall; this.diagnosticMessages = diagnosticMessages; } @@ -65,9 +65,9 @@ export class LibraryTypeCallDiagnosticChecker implements DiagnosticChecker { } } return chain.next === undefined ? true : this.checkMessageChain(chain.next[0]); - }; + } - checkFilteredDiagnosticMessages(msgText: ts.DiagnosticMessageChain | string) { + checkFilteredDiagnosticMessages(msgText: ts.DiagnosticMessageChain | string): boolean { if (this.filteredDiagnosticMessages.size === 0) { return true; } @@ -91,11 +91,11 @@ export class LibraryTypeCallDiagnosticChecker implements DiagnosticChecker { return true; } - if (curMsg.code != curFilteredMsg.code) { + if (curMsg.code !== curFilteredMsg.code) { return true; } - if (curMsg.messageText != curFilteredMsg.messageText) { + if (curMsg.messageText !== curFilteredMsg.messageText) { return true; } @@ -117,7 +117,7 @@ export class LibraryTypeCallDiagnosticChecker implements DiagnosticChecker { return false; } - if (typeof msgText == 'string') { + if (typeof msgText === 'string') { return this.checkMessageText(msgText); } diff --git a/ets2panda/linter-4.2/src/LinterRunner.ts b/ets2panda/linter-4.2/src/LinterRunner.ts index dca4d3dfd12e26a528c7aa837877b358d2b5471b..466e245285f03a5ef0f951940c25006a7820c2ed 100644 --- a/ets2panda/linter-4.2/src/LinterRunner.ts +++ b/ets2panda/linter-4.2/src/LinterRunner.ts @@ -156,7 +156,7 @@ function getTscDiagnostics( const strictDiagnostics = new Map(); sourceFiles.forEach(file => { const diagnostics = tscDiagnosticsLinter.getStrictDiagnostics(file.fileName); - if (diagnostics.length != 0) { + if (diagnostics.length !== 0) { strictDiagnostics.set(path.normalize(file.fileName), diagnostics); } }); @@ -174,7 +174,7 @@ function transformTscDiagnostics( } function countProblemFiles( - nodeCounters: number[], filesNumber: number, tsSrcFile: ts.SourceFile, + nodeCounters: number[], filesNumber: number, tsSrcFile: ts.SourceFile, fileNodes: number, fileErrorLines: number, fileWarningLines: number, linter: TypeScriptLinter, ) { let errorNodes = 0, warningNodes = 0; @@ -212,7 +212,7 @@ function logProblemsPercentageByFeatures(linter: TypeScriptLinter) { // if Strict mode - count all cases if (!linter.strictMode && faultsAttrs[i].migratable) continue; - + let nodes = linter.nodeCounters[i]; let lines = linter.lineCounters[i]; let pecentage = ((nodes / linter.totalVisitedNodes) * 100).toFixed(2).padEnd(7, ' '); diff --git a/ets2panda/linter-4.2/src/TypeScriptLinter.ts b/ets2panda/linter-4.2/src/TypeScriptLinter.ts index 1eab4f9d62346078fd0f4ddb9ba6d5b0c0ab47d5..7e11b132f41355e168af9ffa09d4a8438d1d1fae 100644 --- a/ets2panda/linter-4.2/src/TypeScriptLinter.ts +++ b/ets2panda/linter-4.2/src/TypeScriptLinter.ts @@ -215,12 +215,12 @@ export class TypeScriptLinter { this.lineCounters[faultId]++; if (faultsAttrs[faultId].warning) { - if (line != this.currentWarningLine) { + if (line !== this.currentWarningLine) { this.currentWarningLine = line; ++this.totalWarningLines; this.warningLineNumbersString += line + ", "; } - } else if (line != this.currentErrorLine) { + } else if (line !== this.currentErrorLine) { this.currentErrorLine = line; ++this.totalErrorLines; this.errorLineNumbersString += line + ", "; @@ -474,7 +474,7 @@ export class TypeScriptLinter { p.name, (decl as ts.PropertyDeclaration).type ); - } else if (decl.kind == ts.SyntaxKind.PropertySignature) { + } else if (decl.kind === ts.SyntaxKind.PropertySignature) { this.countInterfaceExtendsDifferentPropertyTypes( node, prop2type, @@ -710,7 +710,7 @@ export class TypeScriptLinter { if (!isRecordObjectInitializer && !isDynamicLiteralInitializer) { let autofix: Autofix[] | undefined = Autofixer.fixLiteralAsPropertyName(node); - let autofixable = autofix != undefined; + let autofixable = autofix !== undefined; if ( !this.autofixesInfo.shouldAutofix(node, FaultID.LiteralAsPropertyName) ) { @@ -1253,7 +1253,7 @@ export class TypeScriptLinter { } } - private handleEsObjectAssignment(node: ts.Node, nodeDeclType: ts.TypeNode | undefined, initializer: ts.Node) { + private handleEsObjectAssignment(node: ts.Node, nodeDeclType: ts.TypeNode | undefined, initializer: ts.Node): void { const isTypeAnnotated = !!nodeDeclType; const isDeclaredESObject = !!nodeDeclType && this.tsUtils.isEsObjectType(nodeDeclType); const initalizerTypeNode = this.tsUtils.getVariableDeclarationTypeNode(initializer); @@ -1305,7 +1305,7 @@ export class TypeScriptLinter { const visitHClause = (hClause: ts.HeritageClause) => { for (const tsTypeExpr of hClause.types) { const tsExprType = this.tsTypeChecker.getTypeAtLocation(tsTypeExpr.expression); - if (tsExprType.isClass() && hClause.token == ts.SyntaxKind.ImplementsKeyword) { + if (tsExprType.isClass() && hClause.token === ts.SyntaxKind.ImplementsKeyword) { this.incrementCounters(tsTypeExpr, FaultID.ImplementsClass); } } @@ -1470,7 +1470,7 @@ export class TypeScriptLinter { TsUtils.FUNCTION_HAS_NO_RETURN_ERROR_CODE); } - private handleMethodSignature(node: ts.MethodSignature) { + private handleMethodSignature(node: ts.MethodSignature): void { const tsMethodSign = node as ts.MethodSignature; if (!tsMethodSign.type) { this.handleMissingReturnType(tsMethodSign); @@ -1503,13 +1503,13 @@ export class TypeScriptLinter { if (ts.isPropertyAssignment(ctx.parent) && ts.isObjectLiteralExpression(ctx.parent.parent)) { ctx = ctx.parent.parent; } - if (ts.isArrowFunction(ctx.parent) && ctx.parent.body == ctx) { + if (ts.isArrowFunction(ctx.parent) && ctx.parent.body === ctx) { ctx = ctx.parent; } if (ts.isCallExpression(ctx.parent) || ts.isNewExpression(ctx.parent)) { let callee = ctx.parent.expression; - if (callee != ctx && this.tsUtils.hasLibraryType(callee)) { + if (callee !== ctx && this.tsUtils.hasLibraryType(callee)) { return true; } } @@ -1521,18 +1521,18 @@ export class TypeScriptLinter { // If module name is duplicated by another declaration, this increases the possibility // of finding a lot of false positives. Thus, do not check further in that case. - if ((tsIdentSym.flags & ts.SymbolFlags.ValueModule) != 0) { + if ((tsIdentSym.flags & ts.SymbolFlags.ValueModule) !== 0) { if (!!tsIdentSym && this.tsUtils.symbolHasDuplicateName(tsIdentSym, ts.SyntaxKind.ModuleDeclaration)) { return; } } - if ((tsIdentSym.flags & illegalValues) == 0 || this.tsUtils.isStruct(tsIdentSym) || + if ((tsIdentSym.flags & illegalValues) === 0 || this.tsUtils.isStruct(tsIdentSym) || !this.identiferUseInValueContext(tsIdentifier, tsIdentSym)) { return; } - if ((tsIdentSym.flags & ts.SymbolFlags.Class) != 0) { + if ((tsIdentSym.flags & ts.SymbolFlags.Class) !== 0) { if (this.isAllowedClassValueContext(tsIdentifier, tsIdentSym)) { return; } @@ -1560,8 +1560,8 @@ export class TypeScriptLinter { // treat TypeQuery as valid because it's already forbidden (FaultID.TypeQuery) (ts.isTypeNode(parent) && !ts.isTypeOfExpression(parent)) || // ElementAccess is allowed for enum types - (ts.isElementAccessExpression(parent) - && (parent as ts.ElementAccessExpression).expression == ident && (tsSym.flags & ts.SymbolFlags.Enum)) || + (ts.isElementAccessExpression(parent) && + (parent as ts.ElementAccessExpression).expression === ident && (tsSym.flags & ts.SymbolFlags.Enum)) || ts.isExpressionWithTypeArguments(parent) || ts.isExportAssignment(parent) || ts.isExportSpecifier(parent) || @@ -1601,15 +1601,6 @@ export class TypeScriptLinter { const checkThisOrSuper = this.tsUtils.isThisOrSuperExpr(tsElementAccessExpr.expression) && !this.tsUtils.isDerivedFrom(tsElemAccessBaseExprType, CheckType.Array); - // if (this.tsUtils.isEnumType(tsElemAccessBaseExprType)) { - // implement argument expression type check - // let argType = this.tsTypeChecker.getTypeAtLocation(tsElementAccessExpr.argumentExpression); - // if (argType.aliasSymbol == this.tsUtils.trueSymbolAtLocation(tsElementAccessExpr.expression)) { - // return; - // } - // check if constant EnumMember inferred ... - // this.incrementCounters(node, FaultID.PropertyAccessByIndex, autofixable, autofix); - // } if ( !this.tsUtils.isLibraryType(tsElemAccessBaseExprType) && !this.tsUtils.isTypedArray(tsElemAccessBaseExprTypeNode) && @@ -1617,7 +1608,7 @@ export class TypeScriptLinter { this.tsUtils.isObjectLiteralType(tsElemAccessBaseExprType) || checkThisOrSuper) ) { let autofix = Autofixer.fixPropertyAccessByIndex(node); - const autofixable = autofix != undefined; + const autofixable = autofix !== undefined; if ( !this.autofixesInfo.shouldAutofix(node, FaultID.PropertyAccessByIndex) ) @@ -1721,7 +1712,6 @@ export class TypeScriptLinter { private handleImportCall(tsCallExpr: ts.CallExpression) { if (tsCallExpr.expression.kind === ts.SyntaxKind.ImportKeyword) { // relax rule#133 "arkts-no-runtime-import" - // this.incrementCounters(tsCallExpr, FaultID.DynamicImport); const tsArgs = tsCallExpr.arguments; if (tsArgs.length > 1 && ts.isObjectLiteralExpression(tsArgs[1])) { let objLitExpr = tsArgs[1] as ts.ObjectLiteralExpression; @@ -1824,7 +1814,7 @@ export class TypeScriptLinter { } } - private checkLimitedStdLib(node: ts.Node, symbol: ts.Symbol) { + private checkLimitedStdLib(node: ts.Node, symbol: ts.Symbol): void { const parName = this.tsUtils.getParentSymbolName(symbol); const res = parName ? TsUtils.LIMITED_STD_API.get(parName) : undefined; if (res && res.arr.includes(symbol.name)) { @@ -1853,7 +1843,7 @@ export class TypeScriptLinter { return result; } - private handleLibraryTypeCall(callExpr: ts.CallExpression, calleeType: ts.Type) { + private handleLibraryTypeCall(callExpr: ts.CallExpression, calleeType: ts.Type): void { let inLibCall = this.tsUtils.isLibraryType(calleeType); const diagnosticMessages: Array = []; this.libraryTypeCallDiagnosticChecker.configure(inLibCall, diagnosticMessages); @@ -1946,7 +1936,7 @@ export class TypeScriptLinter { private handleMetaProperty(node: ts.Node) { let tsMetaProperty = node as ts.MetaProperty; - if (tsMetaProperty.name.text === "target") { + if (tsMetaProperty.name.text === 'target') { this.incrementCounters(node, FaultID.NewTarget); } } @@ -2172,7 +2162,7 @@ export class TypeScriptLinter { | ts.PropertyDeclaration | ts.ParameterDeclaration ): void { - if (type.aliasSymbol != undefined) { + if (type.aliasSymbol !== undefined) { return; } const isObject = type.flags & ts.TypeFlags.Object; diff --git a/ets2panda/linter-4.2/src/Utils.ts b/ets2panda/linter-4.2/src/Utils.ts index ba940b1e7754523a8befc0d60861bb142d9ba18c..fa383a3e68e71573ba75e0e221a1ab69aa9eaff3 100644 --- a/ets2panda/linter-4.2/src/Utils.ts +++ b/ets2panda/linter-4.2/src/Utils.ts @@ -63,15 +63,15 @@ export function getNodeOrLineEnd( } export function mergeArrayMaps(lhs: Map, rhs: Map): Map { - if (lhs.size == 0) { + if (lhs.size === 0) { return rhs; } - if (rhs.size == 0) { + if (rhs.size === 0) { return lhs; } rhs.forEach((values, key) => { - if (values.length != 0) { + if (values.length !== 0) { if (lhs.has(key)) { lhs.get(key)!.push(...values); } else { @@ -314,7 +314,7 @@ export class TsUtils { if (tsType === undefined || !ts.isTypeReferenceNode(tsType)) { return false; } - return this.entityNameToString(tsType.typeName) == checkType; + return this.entityNameToString(tsType.typeName) === checkType; } public entityNameToString(name: ts.EntityName): string { @@ -421,7 +421,7 @@ export class TsUtils { } public isEnumType(tsType: ts.Type): boolean { - // Note: For some reason, test (tsType.flags & ts.TypeFlags.Enum) != 0 doesn't work here. + // Note: For some reason, test (tsType.flags & ts.TypeFlags.Enum) !== 0 doesn't work here. // Must use SymbolFlags to figure out if this is an enum type. return tsType.symbol && (tsType.symbol.flags & ts.SymbolFlags.Enum) !== 0; } @@ -517,17 +517,17 @@ export class TsUtils { public isReferenceType(tsType: ts.Type): boolean { const f = tsType.getFlags(); return ( - (f & ts.TypeFlags.InstantiableNonPrimitive) != 0 || (f & ts.TypeFlags.Object) != 0 || - (f & ts.TypeFlags.Boolean) != 0 || (f & ts.TypeFlags.Enum) != 0 || (f & ts.TypeFlags.NonPrimitive) != 0 || - (f & ts.TypeFlags.Number) != 0 || (f & ts.TypeFlags.String) != 0 + (f & ts.TypeFlags.InstantiableNonPrimitive) !== 0 || (f & ts.TypeFlags.Object) !== 0 || + (f & ts.TypeFlags.Boolean) !== 0 || (f & ts.TypeFlags.Enum) !== 0 || (f & ts.TypeFlags.NonPrimitive) !== 0 || + (f & ts.TypeFlags.Number) !== 0 || (f & ts.TypeFlags.String) !== 0 ); } public isPrimitiveType(type: ts.Type): boolean { const f = type.getFlags(); return ( - (f & ts.TypeFlags.Boolean) != 0 || (f & ts.TypeFlags.BooleanLiteral) != 0 || - (f & ts.TypeFlags.Number) != 0 || (f & ts.TypeFlags.NumberLiteral) != 0 + (f & ts.TypeFlags.Boolean) !== 0 || (f & ts.TypeFlags.BooleanLiteral) !== 0 || + (f & ts.TypeFlags.Number) !== 0 || (f & ts.TypeFlags.NumberLiteral) !== 0 // In ArkTS 'string' is not a primitive type. So for the common subset 'string' // should be considered as a reference type. That is why next line is commented out. //(f & ts.TypeFlags.String) != 0 || (f & ts.TypeFlags.StringLiteral) != 0 @@ -554,9 +554,9 @@ export class TsUtils { if (this.isTypeReference(tsType) && tsType.target !== tsType) tsType = tsType.target; const tsTypeNode = this.tsTypeChecker.typeToTypeNode(tsType, undefined, ts.NodeBuilderFlags.None); - if (checkType == CheckType.Array && (this.isGenericArrayType(tsType) || this.isTypedArray(tsTypeNode))) + if (checkType === CheckType.Array && (this.isGenericArrayType(tsType) || this.isTypedArray(tsTypeNode))) return true; - if (checkType != CheckType.Array && this.isType(tsTypeNode, checkType.toString())) + if (checkType !== CheckType.Array && this.isType(tsTypeNode, checkType.toString())) return true; if (!tsType.symbol || !tsType.symbol.declarations) return false; @@ -585,7 +585,7 @@ export class TsUtils { } public isThisOrSuperExpr(tsExpr: ts.Expression): boolean { - return (tsExpr.kind == ts.SyntaxKind.ThisKeyword || tsExpr.kind == ts.SyntaxKind.SuperKeyword); + return (tsExpr.kind === ts.SyntaxKind.ThisKeyword || tsExpr.kind === ts.SyntaxKind.SuperKeyword); } public isPrototypeSymbol(symbol: ts.Symbol | undefined): boolean { @@ -800,7 +800,7 @@ export class TsUtils { !typeADecl.heritageClauses ) continue; for (let heritageClause of typeADecl.heritageClauses) { - let processInterfaces = typeA.isClass() ? (heritageClause.token != ts.SyntaxKind.ExtendsKeyword) : true; + let processInterfaces = typeA.isClass() ? (heritageClause.token !== ts.SyntaxKind.ExtendsKeyword) : true; if (this.processParentTypes(heritageClause.types, typeB, processInterfaces)) return true; } } @@ -867,7 +867,9 @@ export class TsUtils { for (let baseTypeExpr of parentTypes) { let baseType = this.tsTypeChecker.getTypeAtLocation(baseTypeExpr); if (this.isTypeReference(baseType) && baseType.target !== baseType) baseType = baseType.target; - if (baseType && (baseType.isClass() != processInterfaces) && this.relatedByInheritanceOrIdentical(baseType, typeB)) return true; + if (baseType && (baseType.isClass() !== processInterfaces) && this.relatedByInheritanceOrIdentical(baseType, typeB)) { + return true; + } } return false; } @@ -889,7 +891,7 @@ export class TsUtils { return true; } let node = this.tsTypeChecker.typeToTypeNode(tsType, undefined, undefined); - return node != undefined && node.kind === ts.SyntaxKind.ObjectKeyword; + return node !== undefined && node.kind === ts.SyntaxKind.ObjectKeyword; } public isCallToFunctionWithOmittedReturnType(tsExpr: ts.Expression): boolean { @@ -1003,7 +1005,7 @@ export class TsUtils { return true; } - private getNonNullableType(t: ts.Type) { + private getNonNullableType(t: ts.Type): ts.Type { if (this.isNullableUnionType(t)) { return t.getNonNullableType(); } @@ -1482,7 +1484,7 @@ export class TsUtils { public isEsObjectType(typeNode: ts.TypeNode): boolean { return ts.isTypeReferenceNode(typeNode) && ts.isIdentifier(typeNode.typeName) && - typeNode.typeName.text == TsUtils.ES_OBJECT; + typeNode.typeName.text === TsUtils.ES_OBJECT; } public isInsideBlock(node: ts.Node): boolean { @@ -1536,8 +1538,8 @@ export class TsUtils { public isEsObjectSymbol(sym: ts.Symbol): boolean { let decl = this.getDeclaration(sym); - return !!decl && ts.isTypeAliasDeclaration(decl) && decl.name.escapedText == TsUtils.ES_OBJECT && - decl.type.kind == ts.SyntaxKind.AnyKeyword; + return !!decl && ts.isTypeAliasDeclaration(decl) && decl.name.escapedText === TsUtils.ES_OBJECT && + decl.type.kind === ts.SyntaxKind.AnyKeyword; } public isAnonymousType(type: ts.Type): boolean { @@ -1565,9 +1567,9 @@ export class TsUtils { // has to be re-implemented with local loop detection public typeIsRecursive(topType: ts.Type, type: ts.Type | undefined = undefined): boolean { - if (type == undefined) { + if (type === undefined) { type = topType; - } else if (type == topType) { + } else if (type === topType) { return true; } else if (type.aliasSymbol) { return false; diff --git a/ets2panda/linter-4.2/test/limited_stdlib_api.ts b/ets2panda/linter-4.2/test/limited_stdlib_api.ts index 0cc445fe759022f5cd6bcd7850aa3f018cf33849..b7f800683008fab4164c535332ab894927002c27 100644 --- a/ets2panda/linter-4.2/test/limited_stdlib_api.ts +++ b/ets2panda/linter-4.2/test/limited_stdlib_api.ts @@ -35,16 +35,10 @@ class C {} let c = new C(); /// Object -//Object.__proto__(), -//Object.__defineGetter__(), -//Object.__defineSetter__(); -//Object.__lookupGetter__(); -//Object.__lookupSetter__(); Object.assign(c, c); Object.create(c); Object.defineProperties(c, {}); Object.defineProperty(c, 'p', c); -// Object.entries([]); Object.freeze(() => {}); Object.fromEntries([]); Object.getOwnPropertyDescriptor(c, 'p'); diff --git a/ets2panda/linter-4.2/test/object_literals_2.ts b/ets2panda/linter-4.2/test/object_literals_2.ts index 2a78eaa7fffe292882a3fefeddf5a820326d37f8..b8e6f2dd50243d453649327948f25dec4bc1d890 100644 --- a/ets2panda/linter-4.2/test/object_literals_2.ts +++ b/ets2panda/linter-4.2/test/object_literals_2.ts @@ -77,7 +77,6 @@ class C3 { public s: string = ''; } -//let c6: C3 = {n: 42, s: 'foo'}; // CTE in TypeScript, CTE in ArkTS class C4 { readonly n: number = 0; @@ -118,7 +117,6 @@ class C7 { n: number = 0; s: string = ''; } -//let c10: C7 = {n: 42, s: '', extra: true}; // TS: CTE, ArtTS: CTE let o1: Object = {s: '', n: 42} // OK in TS, CTE in ArkTS: no fields 'n' and 's' in Object let o2: object = {n: 42, s: ''} // OK in TS, CTE in ArkTS: no fields 'n' and 's' in object diff --git a/ets2panda/parser/ETSparser.cpp b/ets2panda/parser/ETSparser.cpp index e86b81930b53cae8faaf2f62b2477e5529ca52c7..5d2da9eaafa61605feee038dbb1a7260cfcfc392 100644 --- a/ets2panda/parser/ETSparser.cpp +++ b/ets2panda/parser/ETSparser.cpp @@ -14,6 +14,7 @@ */ #include "ETSparser.h" +#include #include "parser/parserFlags.h" #include "util/arktsconfig.h" @@ -46,6 +47,7 @@ #include "ir/expressions/assignmentExpression.h" #include "ir/expressions/sequenceExpression.h" #include "ir/expressions/callExpression.h" +#include "ir/expressions/blockExpression.h" #include "ir/expressions/thisExpression.h" #include "ir/expressions/superExpression.h" #include "ir/expressions/newExpression.h" @@ -171,11 +173,21 @@ void ETSParser::ParseETSGlobalScript(lexer::SourcePosition start_loc, ArenaVecto // remove external sources from paths because already parsed them paths.erase(remove_if(begin(paths), end(paths), [this](auto x) { - return find(begin(parsed_sources_), end(parsed_sources_), x) != end(parsed_sources_); + auto resolved = ResolveImportPath(x); + auto path_iter = + std::find_if(resolved_parsed_sources_.begin(), resolved_parsed_sources_.end(), + [resolved](const auto &p) { return p.second == resolved; }); + auto found = path_iter != resolved_parsed_sources_.end(); + if (found) { + resolved_parsed_sources_.emplace(x, resolved); + } + return found; }), end(paths)); - parsed_sources_.insert(parsed_sources_.end(), paths.begin(), paths.end()); + for (const auto &path : paths) { + parsed_sources_.push_back(ResolveImportPath(path)); + } ParseSources(paths, false); ParseTopLevelDeclaration(statements); @@ -229,9 +241,12 @@ ArenaVector ETSParser::PrepareExternalGlobalClass([[maybe_unuse if (!statements.empty()) { res = ext_sources.find(name); } else { - const util::UString source_file_path( - GetProgram()->SourceFilePath().Mutf8() + GetProgram()->GetPackageName().Mutf8(), Allocator()); - GetProgram()->SetSource(GetProgram()->SourceCode(), GetProgram()->SourceFile(), source_file_path.View()); + auto path = GetProgram()->SourceFilePath().Mutf8() + panda::os::file::File::GetPathDelim().at(0) + + GetProgram()->GetPackageName().Mutf8(); + auto resolved = ResolveImportPath(path); + resolved_parsed_sources_.emplace(path, resolved); + GetProgram()->SetSource(GetProgram()->SourceCode(), GetProgram()->SourceFile(), + util::UString(resolved, Allocator()).View()); } if (res == ext_sources.end()) { @@ -342,14 +357,30 @@ ETSParser::ImportData ETSParser::GetImportData(const std::string &path) return {ToLanguage(Extension()), path, true}; } +std::string ETSParser::ResolveFullPathFromRelative(const std::string &path) +{ + char path_delimiter = panda::os::file::File::GetPathDelim().at(0); + auto resolved_fp = GetProgram()->ResolvedFilePath().Mutf8(); + auto source_fp = GetProgram()->SourceFilePath().Mutf8(); + if (resolved_fp.empty()) { + auto fp = source_fp + path_delimiter + path; + return util::Helpers::IsRealPath(fp) ? fp : path; + } + auto fp = resolved_fp + path_delimiter + path; + if (util::Helpers::IsRealPath(fp)) { + return fp; + } + if (path.find(source_fp) == 0) { + return resolved_fp + path_delimiter + path.substr(source_fp.size()); + } + return path; +} + std::string ETSParser::ResolveImportPath(const std::string &path) { char path_delimiter = panda::os::file::File::GetPathDelim().at(0); if (util::Helpers::IsRelativePath(path)) { - if (GetProgram()->ResolvedFilePath().Mutf8().empty()) { - return GetProgram()->SourceFilePath().Mutf8() + path_delimiter + path; - } - return GetProgram()->ResolvedFilePath().Mutf8() + path_delimiter + path; + return util::Helpers::GetAbsPath(ResolveFullPathFromRelative(path)); } std::string base_url; @@ -393,11 +424,29 @@ std::string ETSParser::ResolveImportPath(const std::string &path) return base_url; } +std::tuple ETSParser::GetSourceRegularPath(const std::string &path, const std::string &resolved_path) +{ + if (!panda::os::file::File::IsRegularFile(resolved_path)) { + std::string import_extension = ".ets"; + + if (!panda::os::file::File::IsRegularFile(resolved_path + import_extension)) { + import_extension = ".ts"; + + if (!panda::os::file::File::IsRegularFile(resolved_path + import_extension)) { + ThrowSyntaxError("Incorrect path: " + resolved_path); + } + } + return {path + import_extension, true}; + } + return {path, false}; +} + std::tuple, bool> ETSParser::CollectUserSources(const std::string &path) { std::vector user_paths; const std::string resolved_path = ResolveImportPath(path); + resolved_parsed_sources_.emplace(path, resolved_path); const auto data = GetImportData(resolved_path); if (!data.has_decl) { @@ -405,23 +454,11 @@ std::tuple, bool> ETSParser::CollectUserSources(const s } if (!panda::os::file::File::IsDirectory(resolved_path)) { - if (!panda::os::file::File::IsRegularFile(resolved_path)) { - std::string import_extension = ".ets"; - - if (!panda::os::file::File::IsRegularFile(resolved_path + import_extension)) { - import_extension = ".ts"; - - if (!panda::os::file::File::IsRegularFile(resolved_path + import_extension)) { - ThrowSyntaxError("Incorrect path: " + resolved_path); - } - } - - user_paths.emplace_back(path + import_extension); - return {user_paths, true}; - } - - user_paths.emplace_back(path); - return {user_paths, false}; + std::string regular_path; + bool is_module = false; + std::tie(regular_path, is_module) = GetSourceRegularPath(path, resolved_path); + user_paths.emplace_back(regular_path); + return {user_paths, is_module}; } #ifdef USE_UNIX_SYSCALL @@ -477,6 +514,8 @@ void ETSParser::ParseSources(const std::vector &paths, bool is_exte const std::size_t path_count = paths.size(); for (std::size_t idx = 0; idx < path_count; idx++) { std::string resolved_path = ResolveImportPath(paths[idx]); + resolved_parsed_sources_.emplace(paths[idx], resolved_path); + const auto data = GetImportData(resolved_path); if (!data.has_decl) { @@ -669,7 +708,7 @@ ArenaVector ETSParser::ParseTopLevelStatements(ArenaVector::Enter( VarBinder(), GetProgram()->GlobalClassScope()); - ParseClassFieldDefiniton(member_name, member_modifiers, &global_properties, init_function); + ParseClassFieldDefiniton(member_name, member_modifiers, &global_properties, init_function, &start_loc); break; } case lexer::TokenType::KEYW_ASYNC: @@ -1253,8 +1292,11 @@ ir::ModifierFlags ETSParser::ParseClassMethodModifiers(bool seen_static) // NOLINTNEXTLINE(google-default-arguments) void ETSParser::ParseClassFieldDefiniton(ir::Identifier *field_name, ir::ModifierFlags modifiers, - ArenaVector *declarations, ir::ScriptFunction *init_function) + ArenaVector *declarations, ir::ScriptFunction *init_function, + lexer::SourcePosition *let_loc) { + lexer::SourcePosition start_loc = let_loc != nullptr ? *let_loc : Lexer()->GetToken().Start(); + lexer::SourcePosition end_loc = start_loc; ir::TypeNode *type_annotation = nullptr; TypeAnnotationParsingOptions options = TypeAnnotationParsingOptions::THROW_ERROR; @@ -1283,9 +1325,16 @@ void ETSParser::ParseClassFieldDefiniton(ir::Identifier *field_name, ir::Modifie auto *assignment_expression = AllocNode(ident, initializer, lexer::TokenType::PUNCTUATOR_SUBSTITUTION); + end_loc = initializer->End(); + assignment_expression->SetRange({field_name->Start(), end_loc}); assignment_expression->SetParent(func_body); - func_body->AsBlockStatement()->Statements().emplace_back( - AllocNode(assignment_expression)); + + auto expression_statement = AllocNode(assignment_expression); + if (Lexer()->GetToken().Type() == lexer::TokenType::PUNCTUATOR_SEMI_COLON) { + end_loc = Lexer()->GetToken().End(); + } + expression_statement->SetRange({start_loc, end_loc}); + func_body->AsBlockStatement()->Statements().emplace_back(expression_statement); if (type_annotation != nullptr && !type_annotation->IsETSFunctionType()) { initializer = nullptr; @@ -1300,6 +1349,13 @@ void ETSParser::ParseClassFieldDefiniton(ir::Identifier *field_name, ir::Modifie } auto *field = AllocNode(field_name, initializer, type_annotation, modifiers, Allocator(), false); + start_loc = field_name->Start(); + if (initializer != nullptr) { + end_loc = initializer->End(); + } else { + end_loc = type_annotation != nullptr ? type_annotation->End() : field_name->End(); + } + field->SetRange({start_loc, end_loc}); if ((modifiers & ir::ModifierFlags::CONST) != 0) { ASSERT(VarBinder()->GetScope()->Parent() != nullptr); @@ -2149,13 +2205,15 @@ void ETSParser::CreateClassFunctionDeclaration(ir::MethodDefinition *method) method->Function()->AddFlag(ir::ScriptFunctionFlags::OVERLOAD); } -bool ETSParser::HasDefaultParam(const ir::ScriptFunction *const function) +std::pair ETSParser::CheckDefaultParameters(const ir::ScriptFunction *const function) const { bool has_default_parameter = false; bool has_rest_parameter = false; + std::size_t required_parameters_number = 0U; for (auto *const it : function->Params()) { auto const *const param = it->AsETSParameterExpression(); + if (param->IsRestParameter()) { has_rest_parameter = true; continue; @@ -2173,23 +2231,58 @@ bool ETSParser::HasDefaultParam(const ir::ScriptFunction *const function) if (has_default_parameter) { ThrowSyntaxError("Required parameter follows default parameter(s).", param->Start()); } - } - if (!has_default_parameter) { - return false; + ++required_parameters_number; } - if (has_rest_parameter) { + if (has_default_parameter && has_rest_parameter) { ThrowSyntaxError("Both optional and rest parameters are not allowed in function's parameter list.", function->Start()); } - return true; + return std::make_pair(has_default_parameter, required_parameters_number); +} + +ir::MethodDefinition *ETSParser::CreateProxyConstructorDefinition(ir::MethodDefinition const *const method) +{ + ASSERT(method->IsConstructor()); + + const auto *const function = method->Function(); + std::string proxy_method = function->Id()->Name().Mutf8() + '('; + + for (const auto *const it : function->Params()) { + auto const *const param = it->AsETSParameterExpression(); + proxy_method += param->Ident()->Name().Mutf8() + ": " + GetNameForTypeNode(param->TypeAnnotation()) + ", "; + } + + proxy_method += ir::PROXY_PARAMETER_NAME; + proxy_method += ": int) { this("; + + auto const parameters_number = function->Params().size(); + for (size_t i = 0U; i < parameters_number; ++i) { + if (auto const *const param = function->Params()[i]->AsETSParameterExpression(); param->IsDefault()) { + std::string proxy_if = "(((" + std::string {ir::PROXY_PARAMETER_NAME} + " >> " + std::to_string(i) + + ") & 0x1) == 0) ? " + param->Ident()->Name().Mutf8() + " : (" + + param->LexerSaved().Mutf8() + "), "; + proxy_method += proxy_if; + } else { + proxy_method += function->Params()[i]->AsETSParameterExpression()->Ident()->Name().Mutf8() + ", "; + } + } + + proxy_method.pop_back(); // Note: at least one parameter always should present! + proxy_method.pop_back(); + proxy_method += ") }"; + + return CreateConstructorDefinition(method->Modifiers(), proxy_method, DEFAULT_PROXY_FILE); } -std::string ETSParser::CreateProxyMethodName(const ir::ScriptFunction *const function, ir::MethodDefinition *method, - ir::Identifier *ident_node, varbinder::ClassScope *const cls_scope) +ir::MethodDefinition *ETSParser::CreateProxyMethodDefinition(ir::MethodDefinition const *const method, + ir::Identifier const *const ident_node) { + ASSERT(!method->IsConstructor()); + + const auto *const function = method->Function(); std::string proxy_method = function->Id()->Name().Mutf8() + "_proxy("; for (const auto *const it : function->Params()) { @@ -2197,32 +2290,42 @@ std::string ETSParser::CreateProxyMethodName(const ir::ScriptFunction *const fun proxy_method += param->Ident()->Name().Mutf8() + ": " + GetNameForTypeNode(param->TypeAnnotation()) + ", "; } - const bool has_function_return_type = method->Function()->ReturnTypeAnnotation() != nullptr; + const bool has_function_return_type = function->ReturnTypeAnnotation() != nullptr; const std::string return_type = - has_function_return_type ? GetNameForTypeNode(method->Function()->ReturnTypeAnnotation()) : ""; + has_function_return_type ? GetNameForTypeNode(function->ReturnTypeAnnotation()) : ""; - proxy_method += has_function_return_type ? "proxy_int:int):" + return_type + "{" : "proxy_int:int) {"; + proxy_method += ir::PROXY_PARAMETER_NAME; + proxy_method += ": int)"; + if (has_function_return_type) { + proxy_method += ": " + return_type; + } + proxy_method += " { "; auto const parameters_number = function->Params().size(); - for (size_t i = 0U; i < parameters_number; i++) { + for (size_t i = 0U; i < parameters_number; ++i) { if (auto const *const param = function->Params()[i]->AsETSParameterExpression(); param->IsDefault()) { - std::string proxy_if = "if (((proxy_int >> " + std::to_string(i) + ") & 0x1) == 1) { " + - param->Ident()->Name().Mutf8() + " = " + param->LexerSaved().Mutf8() + " }"; + std::string proxy_if = "if (((" + std::string {ir::PROXY_PARAMETER_NAME} + " >> " + std::to_string(i) + + ") & 0x1) == 1) { " + param->Ident()->Name().Mutf8() + " = " + + param->LexerSaved().Mutf8() + " } "; proxy_method += proxy_if; } } + proxy_method += ' '; if (return_type != "void") { - if (cls_scope->Parent()->IsGlobalScope()) { + if (auto *const cls_scope = VarBinder()->GetScope()->AsClassScope(); cls_scope->Parent()->IsGlobalScope()) { proxy_method += "return "; } else if (method->IsStatic()) { + ASSERT(ident_node != nullptr); proxy_method += "return " + ident_node->Name().Mutf8() + "."; } else { proxy_method += "return this."; } } - proxy_method += function->Id()->Name().Mutf8() + "("; + proxy_method += function->Id()->Name().Mutf8(); + proxy_method += '('; + for (const auto *const it : function->Params()) { proxy_method += it->AsETSParameterExpression()->Ident()->Name().Mutf8() + ", "; } @@ -2230,39 +2333,34 @@ std::string ETSParser::CreateProxyMethodName(const ir::ScriptFunction *const fun proxy_method.pop_back(); proxy_method += ") }"; - return proxy_method; + return CreateMethodDefinition(method->Modifiers(), proxy_method, DEFAULT_PROXY_FILE); } void ETSParser::AddProxyOverloadToMethodWithDefaultParams(ir::MethodDefinition *method, ir::Identifier *ident_node) { - if (method->IsConstructor()) { - return; // TODO(szd): Fix constructors not working with default params - } - - const auto *const function = method->Function(); + if (auto const [has_default_parameters, required_parameters] = CheckDefaultParameters(method->Function()); + has_default_parameters) { + if (ir::MethodDefinition *proxy_method_def = !method->IsConstructor() + ? CreateProxyMethodDefinition(method, ident_node) + : CreateProxyConstructorDefinition(method); + proxy_method_def != nullptr) { + auto *const proxy_param = proxy_method_def->Function()->Params().back()->AsETSParameterExpression(); + proxy_param->SetRequiredParams(required_parameters); - if (!HasDefaultParam(function)) { - return; - } + proxy_method_def->Function()->SetDefaultParamProxy(); + proxy_method_def->Function()->AddFlag(ir::ScriptFunctionFlags::OVERLOAD); - auto *const cls_scope = VarBinder()->GetScope()->AsClassScope(); - varbinder::LocalScope *target_scope = - method->IsStatic() ? cls_scope->StaticMethodScope() : cls_scope->InstanceMethodScope(); - auto *const found = target_scope->FindLocal(method->Id()->Name(), varbinder::ResolveBindingOptions::BINDINGS); + auto *const var = method->Id()->Variable(); + auto *const current_node = var->Declaration()->Node(); - std::string proxy_method = CreateProxyMethodName(function, method, ident_node, cls_scope); - - auto class_ctx = - varbinder::LexicalScope::Enter(VarBinder(), GetProgram()->GlobalClassScope()); + proxy_method_def->Id()->SetVariable(var); + proxy_method_def->SetParent(current_node); - auto *const proxy_method_def = CreateMethodDefinition(method->Modifiers(), proxy_method, ".ets"); - proxy_method_def->Function()->SetDefaultParamProxy(); - - auto *const current_node = found->Declaration()->Node(); - current_node->AsMethodDefinition()->AddOverload(proxy_method_def); - proxy_method_def->Id()->SetVariable(found); - proxy_method_def->SetParent(current_node); - proxy_method_def->Function()->AddFlag(ir::ScriptFunctionFlags::OVERLOAD); + if (!method->IsConstructor()) { + current_node->AsMethodDefinition()->AddOverload(proxy_method_def); + } + } + } } std::string ETSParser::PrimitiveTypeToName(ir::PrimitiveType type) @@ -2291,7 +2389,7 @@ std::string ETSParser::PrimitiveTypeToName(ir::PrimitiveType type) } } -std::string ETSParser::GetNameForTypeNode(const ir::TypeNode *type_annotation) +std::string ETSParser::GetNameForTypeNode(const ir::TypeNode *type_annotation) const { if ((type_annotation->IsNullAssignable() || type_annotation->IsUndefinedAssignable()) && type_annotation->IsETSUnionType()) { @@ -2616,10 +2714,10 @@ ir::TypeNode *ETSParser::ParseFunctionType() return func_type; } -ir::TypeNode *ETSParser::ParseTypeAnnotation(TypeAnnotationParsingOptions *options) +// Just to reduce the size of ParseTypeAnnotation(...) method +std::pair ETSParser::GetTypeAnnotationFromToken(TypeAnnotationParsingOptions *options) { ir::TypeNode *type_annotation = nullptr; - bool throw_error = ((*options) & TypeAnnotationParsingOptions::THROW_ERROR) != 0; switch (Lexer()->GetToken().Type()) { case lexer::TokenType::LITERAL_IDENT: { @@ -2632,7 +2730,7 @@ ir::TypeNode *ETSParser::ParseTypeAnnotation(TypeAnnotationParsingOptions *optio if (((*options) & TypeAnnotationParsingOptions::POTENTIAL_CLASS_LITERAL) != 0 && (Lexer()->GetToken().Type() == lexer::TokenType::KEYW_CLASS || IsStructKeyword())) { - return type_annotation; + return std::make_pair(type_annotation, false); } break; } @@ -2678,14 +2776,14 @@ ir::TypeNode *ETSParser::ParseTypeAnnotation(TypeAnnotationParsingOptions *optio Lexer()->Lookahead() == lexer::LEX_CHAR_COLON)) { type_annotation = ParseFunctionType(); type_annotation->SetStart(start_loc); - return type_annotation; + return std::make_pair(type_annotation, false); } type_annotation = ParseTypeAnnotation(options); type_annotation->SetStart(start_loc); if (Lexer()->GetToken().Type() != lexer::TokenType::PUNCTUATOR_RIGHT_PARENTHESIS) { - if (throw_error) { + if (((*options) & TypeAnnotationParsingOptions::THROW_ERROR) != 0) { ThrowExpectedToken(lexer::TokenType::PUNCTUATOR_RIGHT_PARENTHESIS); } @@ -2697,25 +2795,44 @@ ir::TypeNode *ETSParser::ParseTypeAnnotation(TypeAnnotationParsingOptions *optio break; } + case lexer::TokenType::PUNCTUATOR_FORMAT: { + type_annotation = ParseTypeFormatPlaceholder(); + break; + } default: { break; } } + return std::make_pair(type_annotation, true); +} + +ir::TypeNode *ETSParser::ParseTypeAnnotation(TypeAnnotationParsingOptions *options) +{ + bool const throw_error = ((*options) & TypeAnnotationParsingOptions::THROW_ERROR) != 0; + + auto [type_annotation, need_further_processing] = GetTypeAnnotationFromToken(options); + if (type_annotation == nullptr) { if (throw_error) { ThrowSyntaxError("Invalid Type"); } - return nullptr; } + if (!need_further_processing) { + return type_annotation; + } + const lexer::SourcePosition &start_pos = Lexer()->GetToken().Start(); if (((*options) & TypeAnnotationParsingOptions::ALLOW_INTERSECTION) != 0 && Lexer()->GetToken().Type() == lexer::TokenType::PUNCTUATOR_BITWISE_AND) { if (type_annotation->IsETSPrimitiveType()) { - ThrowSyntaxError("Invalid intersection type."); + if (throw_error) { + ThrowSyntaxError("Invalid intersection type."); + } + return nullptr; } return ParseIntersectionType(type_annotation); @@ -2728,7 +2845,6 @@ ir::TypeNode *ETSParser::ParseTypeAnnotation(TypeAnnotationParsingOptions *optio if (throw_error) { ThrowExpectedToken(lexer::TokenType::PUNCTUATOR_RIGHT_SQUARE_BRACKET); } - return nullptr; } @@ -2825,6 +2941,7 @@ std::tuple> ETSParser::ParseFromCla bool is_module = false; auto import_path = Lexer()->GetToken().Ident(); auto resolved_import_path = ResolveImportPath(import_path.Mutf8()); + resolved_parsed_sources_.emplace(import_path.Mutf8(), resolved_import_path); ir::StringLiteral *resolved_source; if (*import_path.Bytes() == '/') { @@ -3653,6 +3770,9 @@ ir::Expression *ETSParser::ParsePrimaryExpression(ExpressionParseFlags flags) case lexer::TokenType::KEYW_TYPE: { ThrowSyntaxError("Type alias is allowed only as top-level declaration"); } + case lexer::TokenType::PUNCTUATOR_FORMAT: { + return ParseExpressionFormatPlaceholder(); + } default: { return ParseDefaultPrimaryExpression(flags); } @@ -3847,6 +3967,9 @@ ir::Expression *ETSParser::ParsePostPrimaryExpression(ir::Expression *primary_ex continue; } + case lexer::TokenType::PUNCTUATOR_FORMAT: { + ThrowUnexpectedToken(lexer::TokenType::PUNCTUATOR_FORMAT); + } default: { break; } @@ -3861,11 +3984,12 @@ ir::Expression *ETSParser::ParsePostPrimaryExpression(ir::Expression *primary_ex ir::Expression *ETSParser::ParsePotentialAsExpression(ir::Expression *primary_expr) { ASSERT(Lexer()->GetToken().Type() == lexer::TokenType::KEYW_AS); + Lexer()->NextToken(); TypeAnnotationParsingOptions options = TypeAnnotationParsingOptions::THROW_ERROR | TypeAnnotationParsingOptions::ALLOW_INTERSECTION; - Lexer()->NextToken(); ir::TypeNode *type = ParseTypeAnnotation(&options); + auto *as_expression = AllocNode(primary_expr, type, false); as_expression->SetRange(primary_expr->Range()); return as_expression; @@ -4119,23 +4243,16 @@ ir::TSEnumDeclaration *ETSParser::ParseEnumMembers(ir::Identifier *const key, co void ETSParser::ParseNumberEnum(ArenaVector &members) { - std::unordered_set enum_values {}; checker::ETSEnumType::ValueType current_value {}; // Lambda to parse enum member (maybe with initializer) - auto const parse_member = [this, &members, &enum_values, ¤t_value]() { + auto const parse_member = [this, &members, ¤t_value]() { auto *const ident = ExpectIdentifier(); auto [decl, var] = VarBinder()->NewVarDecl(ident->Start(), ident->Name()); var->SetScope(VarBinder()->GetScope()); var->AddFlag(varbinder::VariableFlags::STATIC); ident->SetVariable(var); - auto const add_value = [this, &enum_values](checker::ETSEnumType::ValueType const new_value) { - if (auto const rc = enum_values.emplace(new_value); !rc.second) { - ThrowSyntaxError(DUPLICATE_ENUM_VALUE + std::to_string(new_value)); - } - }; - ir::NumberLiteral *ordinal; lexer::SourcePosition end_loc; @@ -4164,14 +4281,12 @@ void ETSParser::ParseNumberEnum(ArenaVector &members) } current_value = ordinal->Number().GetValue(); - add_value(current_value); end_loc = ordinal->End(); } else { // Default enumeration constant value. Equal to 0 for the first item and = previous_value + 1 for all the // others. - add_value(current_value); ordinal = AllocNode(lexer::Number(current_value)); end_loc = ident->End(); @@ -4204,10 +4319,8 @@ void ETSParser::ParseNumberEnum(ArenaVector &members) void ETSParser::ParseStringEnum(ArenaVector &members) { - std::unordered_set enum_values {}; - // Lambda to parse enum member (maybe with initializer) - auto const parse_member = [this, &members, &enum_values]() { + auto const parse_member = [this, &members]() { auto *const ident = ExpectIdentifier(); auto [decl, var] = VarBinder()->NewVarDecl(ident->Start(), ident->Name()); var->SetScope(VarBinder()->GetScope()); @@ -4225,9 +4338,6 @@ void ETSParser::ParseStringEnum(ArenaVector &members) } item_value = ParseStringLiteral(); - if (auto const rc = enum_values.emplace(item_value->Str()); !rc.second) { - ThrowSyntaxError(DUPLICATE_ENUM_VALUE + '\'' + std::string {item_value->Str()} + '\''); - } } else { // Default item value is not allowed for string type enumerations! ThrowSyntaxError("All items of string-type enumeration should be explicitly initialized."); @@ -4468,6 +4578,148 @@ void ETSParser::CheckDeclare() // Methods to create AST node(s) from the specified string (part of valid ETS-code!) //================================================================================================// +// NOLINTBEGIN(modernize-avoid-c-arrays) +static constexpr char const INVALID_NUMBER_NODE[] = "Invalid node number in format expression."; +static constexpr char const INVALID_FORMAT_NODE[] = "Invalid node type in format expression."; +static constexpr char const INSERT_NODE_ABSENT[] = "There is no any node to insert at the placeholder position."; +static constexpr char const INVALID_INSERT_NODE[] = + "Inserting node type differs from that required by format specification."; +// NOLINTEND(modernize-avoid-c-arrays) + +ParserImpl::NodeFormatType ETSParser::GetFormatPlaceholderIdent() const +{ + ASSERT(Lexer()->GetToken().Type() == lexer::TokenType::PUNCTUATOR_FORMAT); + Lexer()->NextToken(); + ASSERT(Lexer()->GetToken().Type() == lexer::TokenType::LITERAL_IDENT); + + char const *const ident_data = Lexer()->GetToken().Ident().Bytes(); + + // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic, cert-err34-c) + auto ident_number = std::atoi(ident_data + 1U); + if (ident_number <= 0) { + ThrowSyntaxError(INVALID_NUMBER_NODE, Lexer()->GetToken().Start()); + } + + return {*ident_data, static_cast().second)>(ident_number - 1)}; +} + +ir::AstNode *ETSParser::ParseFormatPlaceholder() +{ + if (inserting_nodes_.empty()) { + ThrowSyntaxError(INSERT_NODE_ABSENT, Lexer()->GetToken().Start()); + } + + if (auto node_format = GetFormatPlaceholderIdent(); node_format.first == EXPRESSION_FORMAT_NODE) { + return ParseExpressionFormatPlaceholder(std::make_optional(node_format)); + } else if (node_format.first == IDENTIFIER_FORMAT_NODE) { // NOLINT(readability-else-after-return) + return ParseIdentifierFormatPlaceholder(std::make_optional(node_format)); + } else if (node_format.first == TYPE_FORMAT_NODE) { // NOLINT(readability-else-after-return) + return ParseTypeFormatPlaceholder(std::make_optional(node_format)); + } else if (node_format.first == STATEMENT_FORMAT_NODE) { // NOLINT(readability-else-after-return) + return ParseStatementFormatPlaceholder(std::make_optional(node_format)); + } + + ThrowSyntaxError(INVALID_FORMAT_NODE, Lexer()->GetToken().Start()); +} + +ir::Expression *ETSParser::ParseExpressionFormatPlaceholder(std::optional node_format) +{ + if (!node_format.has_value()) { + if (inserting_nodes_.empty()) { + ThrowSyntaxError(INSERT_NODE_ABSENT, Lexer()->GetToken().Start()); + } + + if (node_format = GetFormatPlaceholderIdent(); node_format->first == TYPE_FORMAT_NODE) { + return ParseTypeFormatPlaceholder(std::move(node_format)); + } else if (node_format->first == IDENTIFIER_FORMAT_NODE) { // NOLINT(readability-else-after-return) + return ParseIdentifierFormatPlaceholder(std::move(node_format)); + } else if (node_format->first != EXPRESSION_FORMAT_NODE) { // NOLINT(readability-else-after-return) + ThrowSyntaxError(INVALID_FORMAT_NODE, Lexer()->GetToken().Start()); + } + } + + auto *const inserting_node = + node_format->second < inserting_nodes_.size() ? inserting_nodes_[node_format->second] : nullptr; + if (inserting_node == nullptr || !inserting_node->IsExpression()) { + ThrowSyntaxError(INVALID_INSERT_NODE, Lexer()->GetToken().Start()); + } + + auto *const insert_expression = inserting_node->AsExpression(); + Lexer()->NextToken(); + return insert_expression; +} + +ir::TypeNode *ETSParser::ParseTypeFormatPlaceholder(std::optional node_format) +{ + if (!node_format.has_value()) { + if (inserting_nodes_.empty()) { + ThrowSyntaxError(INSERT_NODE_ABSENT, Lexer()->GetToken().Start()); + } + + if (node_format = GetFormatPlaceholderIdent(); node_format->first != TYPE_FORMAT_NODE) { + ThrowSyntaxError(INVALID_FORMAT_NODE, Lexer()->GetToken().Start()); + } + } + + auto *const inserting_node = + node_format->second < inserting_nodes_.size() ? inserting_nodes_[node_format->second] : nullptr; + if (inserting_node == nullptr || !inserting_node->IsExpression() || !inserting_node->AsExpression()->IsTypeNode()) { + ThrowSyntaxError(INVALID_INSERT_NODE, Lexer()->GetToken().Start()); + } + + auto *const insert_type = inserting_node->AsExpression()->AsTypeNode(); + Lexer()->NextToken(); + return insert_type; +} + +// NOLINTNEXTLINE(google-default-arguments) +ir::Identifier *ETSParser::ParseIdentifierFormatPlaceholder(std::optional node_format) +{ + if (!node_format.has_value()) { + if (inserting_nodes_.empty()) { + ThrowSyntaxError(INSERT_NODE_ABSENT, Lexer()->GetToken().Start()); + } + + if (node_format = GetFormatPlaceholderIdent(); node_format->first != IDENTIFIER_FORMAT_NODE) { + ThrowSyntaxError(INVALID_FORMAT_NODE, Lexer()->GetToken().Start()); + } + } + + auto *const inserting_node = + node_format->second < inserting_nodes_.size() ? inserting_nodes_[node_format->second] : nullptr; + if (inserting_node == nullptr || !inserting_node->IsExpression() || + !inserting_node->AsExpression()->IsIdentifier()) { + ThrowSyntaxError(INVALID_INSERT_NODE, Lexer()->GetToken().Start()); + } + + auto *const insert_identifier = inserting_node->AsExpression()->AsIdentifier(); + Lexer()->NextToken(); + return insert_identifier; +} + +ir::Statement *ETSParser::ParseStatementFormatPlaceholder(std::optional node_format) +{ + if (!node_format.has_value()) { + if (inserting_nodes_.empty()) { + ThrowSyntaxError(INSERT_NODE_ABSENT, Lexer()->GetToken().Start()); + } + + if (node_format = GetFormatPlaceholderIdent(); node_format->first != STATEMENT_FORMAT_NODE) { + ThrowSyntaxError(INVALID_FORMAT_NODE, Lexer()->GetToken().Start()); + } + } + + auto *const inserting_node = + node_format->second < inserting_nodes_.size() ? inserting_nodes_[node_format->second] : nullptr; + if (inserting_node == nullptr || !inserting_node->IsStatement()) { + ThrowSyntaxError(INVALID_INSERT_NODE, Lexer()->GetToken().Start()); + } + + auto *const insert_statement = inserting_node->AsStatement(); + Lexer()->NextToken(); + return insert_statement; +} + ir::Statement *ETSParser::CreateStatement(std::string_view const source_code, std::string_view const file_name) { util::UString source {source_code, Allocator()}; @@ -4498,6 +4750,16 @@ ir::Statement *ETSParser::CreateStatement(std::string_view const source_code, st return block_stmt; } +ir::Statement *ETSParser::CreateFormattedStatement(std::string_view const source_code, + std::vector &inserting_nodes, + std::string_view const file_name) +{ + inserting_nodes_.swap(inserting_nodes); + auto const statement = CreateStatement(source_code, file_name); + inserting_nodes_.swap(inserting_nodes); + return statement; +} + ArenaVector ETSParser::CreateStatements(std::string_view const source_code, std::string_view const file_name) { @@ -4509,6 +4771,16 @@ ArenaVector ETSParser::CreateStatements(std::string_view const return ParseStatementList(StatementParsingFlags::STMT_GLOBAL_LEXICAL); } +ArenaVector ETSParser::CreateFormattedStatements(std::string_view const source_code, + std::vector &inserting_nodes, + std::string_view const file_name) +{ + inserting_nodes_.swap(inserting_nodes); + auto statements = CreateStatements(source_code, file_name); + inserting_nodes_.swap(inserting_nodes); + return statements; +} + ir::MethodDefinition *ETSParser::CreateMethodDefinition(ir::ModifierFlags modifiers, std::string_view const source_code, std::string_view const file_name) { @@ -4535,15 +4807,71 @@ ir::MethodDefinition *ETSParser::CreateMethodDefinition(ir::ModifierFlags modifi return method_definition; } -ir::Expression *ETSParser::CreateExpression(ExpressionParseFlags const flags, std::string_view const source_code, +ir::MethodDefinition *ETSParser::CreateConstructorDefinition(ir::ModifierFlags modifiers, + std::string_view const source_code, + std::string_view const file_name) +{ + util::UString source {source_code, Allocator()}; + auto const isp = InnerSourceParser(this); + auto const lexer = InitLexer({file_name, source.View().Utf8()}); + + auto const start_loc = Lexer()->GetToken().Start(); + Lexer()->NextToken(); + + if (IsClassMethodModifier(Lexer()->GetToken().Type())) { + modifiers |= ParseClassMethodModifiers(false); + } + + if (Lexer()->GetToken().Type() != lexer::TokenType::KEYW_CONSTRUCTOR) { + ThrowSyntaxError({"Unexpected token. 'Constructor' keyword is expected."}); + } + + if ((modifiers & ir::ModifierFlags::ASYNC) != 0) { + ThrowSyntaxError({"Constructor should not be async."}); + } + + auto *member_name = AllocNode(Lexer()->GetToken().Ident(), Allocator()); + modifiers |= ir::ModifierFlags::CONSTRUCTOR; + Lexer()->NextToken(); + + auto *const method_definition = ParseClassMethodDefinition(member_name, modifiers); + method_definition->SetStart(start_loc); + + return method_definition; +} + +ir::Expression *ETSParser::CreateExpression(std::string_view const source_code, ExpressionParseFlags const flags, std::string_view const file_name) { util::UString source {source_code, Allocator()}; auto const isp = InnerSourceParser(this); auto const lexer = InitLexer({file_name, source.View().Utf8()}); + lexer::SourcePosition const start_loc = lexer->GetToken().Start(); lexer->NextToken(); - return ParseExpression(flags); + + ir::Expression *return_expression = ParseExpression(flags); + return_expression->SetRange({start_loc, lexer->GetToken().End()}); + + return return_expression; +} + +ir::Expression *ETSParser::CreateFormattedExpression(std::string_view const source_code, + std::vector &inserting_nodes, + std::string_view const file_name) +{ + ir::Expression *return_expression; + inserting_nodes_.swap(inserting_nodes); + + if (auto statements = CreateStatements(source_code, file_name); + statements.size() == 1U && statements.back()->IsExpressionStatement()) { + return_expression = statements.back()->AsExpressionStatement()->GetExpression(); + } else { + return_expression = AllocNode(std::move(statements)); + } + + inserting_nodes_.swap(inserting_nodes); + return return_expression; } ir::TypeNode *ETSParser::CreateTypeAnnotation(TypeAnnotationParsingOptions *options, std::string_view const source_code, diff --git a/ets2panda/parser/ETSparser.h b/ets2panda/parser/ETSparser.h index ba8e78e3598ff4a5968eafceb990cbf6237273d0..e75558299cabb6bcf0f1fccb21b98a4e95f2d496 100644 --- a/ets2panda/parser/ETSparser.h +++ b/ets2panda/parser/ETSparser.h @@ -16,6 +16,7 @@ #ifndef ES2PANDA_PARSER_CORE_ETS_PARSER_H #define ES2PANDA_PARSER_CORE_ETS_PARSER_H +#include #include "util/arktsconfig.h" #include "TypedParser.h" #include "ir/ets/etsParameterExpression.h" @@ -27,21 +28,74 @@ enum class PrimitiveType; } // namespace panda::es2panda::ir namespace panda::es2panda::parser { + +// NOLINTBEGIN(modernize-avoid-c-arrays) +inline constexpr char const FORMAT_SIGNATURE = '@'; +inline constexpr char const TYPE_FORMAT_NODE = 'T'; +inline constexpr char const STATEMENT_FORMAT_NODE = 'S'; +inline constexpr char const EXPRESSION_FORMAT_NODE = 'E'; +inline constexpr char const IDENTIFIER_FORMAT_NODE = 'I'; +inline constexpr char const DEFAULT_SOURCE_FILE[] = ".ets"; +// NOLINTEND(modernize-avoid-c-arrays) + class ETSParser final : public TypedParser { public: ETSParser(Program *program, const CompilerOptions &options, ParserStatus status = ParserStatus::NO_OPTS) - : TypedParser(program, options, status), global_program_(GetProgram()), parsed_sources_({}) + : TypedParser(program, options, status), + global_program_(GetProgram()), + parsed_sources_({}), + resolved_parsed_sources_({}) { } + ETSParser() = delete; NO_COPY_SEMANTIC(ETSParser); NO_MOVE_SEMANTIC(ETSParser); - ~ETSParser() = default; + ~ETSParser() final = default; + + [[nodiscard]] bool IsETSParser() const noexcept override + { + return true; + } + + // Methods to create AST node(s) from the specified string (part of valid ETS-code!) + // NOTE: the correct initial scope should be entered BEFORE calling any of these methods, + // and correct parent and, probably, variable set to the node(s) after obtaining - ir::Expression *CreateExpression(ExpressionParseFlags flags, std::string_view source_code, + ir::Expression *CreateExpression(std::string_view source_code, + ExpressionParseFlags flags = ExpressionParseFlags::NO_OPTS, std::string_view file_name = DEFAULT_SOURCE_FILE); + ir::Expression *CreateFormattedExpression(std::string_view source_code, std::vector &inserting_nodes, + std::string_view file_name = DEFAULT_SOURCE_FILE); + + template + ir::Expression *CreateFormattedExpression(std::string_view const source_code, std::string_view const file_name, + Args &&...args) + { + std::vector inserting_nodes {}; + inserting_nodes.reserve(sizeof...(Args)); + (inserting_nodes.emplace_back(std::forward(args)), ...); + return CreateFormattedExpression(source_code, inserting_nodes, file_name); + } + + ArenaVector CreateStatements(std::string_view source_code, + std::string_view file_name = DEFAULT_SOURCE_FILE); + + ArenaVector CreateFormattedStatements(std::string_view source_code, + std::vector &inserting_nodes, + std::string_view file_name = DEFAULT_SOURCE_FILE); + + template + ArenaVector CreateFormattedStatements(std::string_view const source_code, + std::string_view const file_name, Args &&...args) + { + std::vector inserting_nodes {}; + (inserting_nodes.emplace(std::forward(args)), ...); + return CreateFormattedStatements(source_code, inserting_nodes, file_name); + } + private: struct ImportData { Language lang; @@ -59,8 +113,10 @@ private: void ParseTopLevelDeclaration(ArenaVector &statements); void CollectDefaultSources(); std::string ResolveImportPath(const std::string &path); + std::string ResolveFullPathFromRelative(const std::string &path); ImportData GetImportData(const std::string &path); std::tuple, bool> CollectUserSources(const std::string &path); + std::tuple GetSourceRegularPath(const std::string &path, const std::string &resolved_path); void ParseSources(const std::vector &paths, bool is_external = true); std::tuple> ParseFromClause(bool require_from); void ParseNamedImportSpecifiers(ArenaVector *specifiers); @@ -103,8 +159,8 @@ private: // NOLINTNEXTLINE(google-default-arguments) void ParseClassFieldDefiniton(ir::Identifier *field_name, ir::ModifierFlags modifiers, - ArenaVector *declarations, - ir::ScriptFunction *init_function = nullptr); + ArenaVector *declarations, ir::ScriptFunction *init_function = nullptr, + lexer::SourcePosition *let_loc = nullptr); std::tuple ParseTypeReferencePart( TypeAnnotationParsingOptions *options); ir::TypeNode *ParseTypeReference(TypeAnnotationParsingOptions *options); @@ -115,17 +171,19 @@ private: ir::TypeNode *ParseWildcardType(TypeAnnotationParsingOptions *options); ir::TypeNode *ParseFunctionType(); void CreateClassFunctionDeclaration(ir::MethodDefinition *method); - bool HasDefaultParam(const ir::ScriptFunction *function); - std::string CreateProxyMethodName(const ir::ScriptFunction *function, ir::MethodDefinition *method, - ir::Identifier *ident_node, varbinder::ClassScope *cls_scope); + std::pair CheckDefaultParameters(const ir::ScriptFunction *function) const; + ir::MethodDefinition *CreateProxyMethodDefinition(ir::MethodDefinition const *method, + ir::Identifier const *ident_node); + ir::MethodDefinition *CreateProxyConstructorDefinition(ir::MethodDefinition const *method); void AddProxyOverloadToMethodWithDefaultParams(ir::MethodDefinition *method, ir::Identifier *ident_node = nullptr); static std::string PrimitiveTypeToName(ir::PrimitiveType type); - std::string GetNameForTypeNode(const ir::TypeNode *type_annotation); + std::string GetNameForTypeNode(const ir::TypeNode *type_annotation) const; ir::TSInterfaceDeclaration *ParseInterfaceBody(ir::Identifier *name, bool is_static); bool IsArrowFunctionExpressionStart(); ir::ArrowFunctionExpression *ParseArrowFunctionExpression(); void ThrowIfVarDeclaration(VariableParsingFlags flags) override; + std::pair GetTypeAnnotationFromToken(TypeAnnotationParsingOptions *options); ir::TypeNode *ParseTypeAnnotation(TypeAnnotationParsingOptions *options) override; ir::TSTypeAliasDeclaration *ParseTypeAliasDeclaration() override; @@ -179,6 +237,14 @@ private: ir::Expression *ParseAwaitExpression(); ir::TSTypeParameter *ParseTypeParameter(TypeAnnotationParsingOptions *options) override; + NodeFormatType GetFormatPlaceholderIdent() const; + ir::AstNode *ParseFormatPlaceholder(); + ir::Statement *ParseStatementFormatPlaceholder(std::optional node_format = std::nullopt); + ir::Expression *ParseExpressionFormatPlaceholder(std::optional node_format = std::nullopt); + // NOLINTNEXTLINE(google-default-arguments) + ir::Identifier *ParseIdentifierFormatPlaceholder(std::optional node_format = std::nullopt) override; + ir::TypeNode *ParseTypeFormatPlaceholder(std::optional node_format = std::nullopt); + ir::TSEnumDeclaration *ParseEnumMembers(ir::Identifier *key, const lexer::SourcePosition &enum_start, bool is_const, bool is_static) override; void ParseNumberEnum(ArenaVector &members); @@ -243,27 +309,48 @@ private: void CheckDeclare(); - // Methods to create AST node(s) from the specified string (part of valid ETS-code!) - // NOTE: the correct initial scope should be entered BEFORE calling any of these methods, - // and correct parent and, probably, variable set to the node(s) after obtaining - // NOLINTNEXTLINE(modernize-avoid-c-arrays) + // Methods to create AST node(s) from the specified string (part of valid ETS-code!) + // NOTE: the correct initial scope should be entered BEFORE calling any of these methods, + // and correct parent and, probably, variable set to the node(s) after obtaining + // NOLINTBEGIN(modernize-avoid-c-arrays) inline static constexpr char const DEFAULT_SOURCE_FILE[] = ".ets"; + inline static constexpr char const DEFAULT_PROXY_FILE[] = ".ets"; + // NOLINTEND(modernize-avoid-c-arrays) // NOLINTBEGIN(google-default-arguments) ir::Statement *CreateStatement(std::string_view source_code, std::string_view file_name = DEFAULT_SOURCE_FILE); - ArenaVector CreateStatements(std::string_view source_code, - std::string_view file_name = DEFAULT_SOURCE_FILE); + ir::Statement *CreateFormattedStatement(std::string_view source_code, std::vector &inserting_nodes, + std::string_view file_name = DEFAULT_SOURCE_FILE); + + template + ir::Statement *CreateFormattedStatement(std::string_view const source_code, std::string_view const file_name, + Args &&...args) + { + std::vector inserting_nodes {}; + (inserting_nodes.emplace(std::forward(args)), ...); + return CreateFormattedStatement(source_code, inserting_nodes, file_name); + } + ir::MethodDefinition *CreateMethodDefinition(ir::ModifierFlags modifiers, std::string_view source_code, std::string_view file_name = DEFAULT_SOURCE_FILE); + ir::MethodDefinition *CreateConstructorDefinition(ir::ModifierFlags modifiers, std::string_view source_code, + std::string_view file_name = DEFAULT_SOURCE_FILE); ir::TypeNode *CreateTypeAnnotation(TypeAnnotationParsingOptions *options, std::string_view source_code, std::string_view file_name = DEFAULT_SOURCE_FILE); - // NOLINTEND(google-default-arguments) friend class ExternalSourceParser; friend class InnerSourceParser; +public: + const std::unordered_map &ResolvedParsedSourcesMap() const + { + return resolved_parsed_sources_; + } + private: parser::Program *global_program_; std::vector parsed_sources_; + std::vector inserting_nodes_ {}; + std::unordered_map resolved_parsed_sources_; }; class ExternalSourceParser { diff --git a/ets2panda/parser/TypedParser.cpp b/ets2panda/parser/TypedParser.cpp index b2955aec9cc1fcf896d25686c5f5ed74a7658eed..9167b18adebe2b1516b23e9d88eab812501c3d46 100644 --- a/ets2panda/parser/TypedParser.cpp +++ b/ets2panda/parser/TypedParser.cpp @@ -1,5 +1,5 @@ /** - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021 - 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 @@ -1274,6 +1274,8 @@ ir::Expression *TypedParser::ParseQualifiedReference(ir::Expression *type_name, Lexer()->GetToken().Type() == lexer::TokenType::PUNCTUATOR_MULTIPLY) { Lexer()->NextToken(); // eat '*' prop_name = AllocNode(varbinder::VarBinder::STAR_IMPORT, Allocator()); + } else if (Lexer()->GetToken().Type() == lexer::TokenType::PUNCTUATOR_FORMAT) { + prop_name = ParseIdentifierFormatPlaceholder(); } else if (Lexer()->GetToken().Type() != lexer::TokenType::LITERAL_IDENT) { if ((flags & ExpressionParseFlags::POTENTIAL_CLASS_LITERAL) != 0) { if (Lexer()->GetToken().Type() == lexer::TokenType::KEYW_CLASS) { diff --git a/ets2panda/parser/parserImpl.cpp b/ets2panda/parser/parserImpl.cpp index 13ef8c672976b2ef8786568abdee101277b7b224..4a19f8842780e4436933f767f7238451e440ca40 100644 --- a/ets2panda/parser/parserImpl.cpp +++ b/ets2panda/parser/parserImpl.cpp @@ -1137,6 +1137,10 @@ void ParserImpl::ThrowParameterModifierError(ir::ModifierFlags status) const ir::Identifier *ParserImpl::ExpectIdentifier(bool is_reference) { + if (lexer_->GetToken().Type() == lexer::TokenType::PUNCTUATOR_FORMAT) { + return ParseIdentifierFormatPlaceholder(); + } + if (lexer_->GetToken().Type() != lexer::TokenType::LITERAL_IDENT) { ThrowSyntaxError("Identifier expected."); } diff --git a/ets2panda/parser/parserImpl.h b/ets2panda/parser/parserImpl.h index 21c674b2e6d56b19aeb6cc03885a5bde0e9b866a..64a4b9b3f35df75a4cd4acf6e6a263ac56a5e0d4 100644 --- a/ets2panda/parser/parserImpl.h +++ b/ets2panda/parser/parserImpl.h @@ -1,5 +1,5 @@ /** - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021 - 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 @@ -101,6 +101,8 @@ enum class CatchClauseType; namespace panda::es2panda::parser { +class ETSParser; + using FunctionSignature = std::tuple, ir::TypeNode *, varbinder::FunctionParamScope *, panda::es2panda::ir::ScriptFunctionFlags>; @@ -175,12 +177,29 @@ public: explicit ParserImpl(Program *program, const CompilerOptions &options, ParserStatus status = ParserStatus::NO_OPTS); NO_COPY_SEMANTIC(ParserImpl); NO_MOVE_SEMANTIC(ParserImpl); - ~ParserImpl() = default; + virtual ~ParserImpl() = default; void ParseScript(const SourceFile &source_file, bool gen_std_lib); ScriptExtension Extension() const; + [[nodiscard]] virtual bool IsETSParser() const noexcept + { + return false; + } + + ETSParser *AsETSParser() + { + ASSERT(IsETSParser()); + return reinterpret_cast(this); + } + + const ETSParser *AsETSParser() const + { + ASSERT(IsETSParser()); + return reinterpret_cast(this); + } + protected: virtual void ParseProgram(ScriptKind kind); static ExpressionParseFlags CarryExpressionParserFlag(ExpressionParseFlags origin, ExpressionParseFlags carry); @@ -502,6 +521,14 @@ protected: return ir::ScriptFunctionFlags::NONE; } + using NodeFormatType = std::pair; + // NOLINTNEXTLINE(google-default-arguments) + virtual ir::Identifier *ParseIdentifierFormatPlaceholder( + [[maybe_unused]] std::optional node_format = std::nullopt) + { + ThrowSyntaxError("Identifier expected"); + } + virtual std::tuple ParseFunctionBody( const ArenaVector ¶ms, ParserStatus new_status, ParserStatus context_status, varbinder::FunctionScope *func_scope); @@ -797,7 +824,7 @@ protected: return varbinder_; } - varbinder::Scope::VariableMap SavedBindings() const + const varbinder::Scope::VariableMap &SavedBindings() const { return saved_bindings_; } diff --git a/ets2panda/parser/program/program.cpp b/ets2panda/parser/program/program.cpp index 1ab75d6854366725f90a248146a897c3e21f23bc..f0adf76b96dd02d554e45edfc50615c30af740a7 100644 --- a/ets2panda/parser/program/program.cpp +++ b/ets2panda/parser/program/program.cpp @@ -29,6 +29,12 @@ std::string Program::Dump() const return dumper.Str(); } +void Program::DumpSilent() const +{ + [[maybe_unused]] ir::AstDumper dumper {ast_, SourceCode()}; + ASSERT(!dumper.Str().empty()); +} + util::StringView Program::PackageClassName(util::StringView class_name) { if (package_name_.Empty()) { diff --git a/ets2panda/parser/program/program.h b/ets2panda/parser/program/program.h index c1331188946169e250b2d3e2192406ca41d8324a..88b3db982c0195f8e9ca327e4f5c57ab23c7dd96 100644 --- a/ets2panda/parser/program/program.h +++ b/ets2panda/parser/program/program.h @@ -217,6 +217,8 @@ public: std::string Dump() const; + void DumpSilent() const; + private: ArenaAllocator *allocator_ {}; varbinder::VarBinder *varbinder_ {}; diff --git a/ets2panda/public/es2panda_lib.cpp b/ets2panda/public/es2panda_lib.cpp index 6b6c6e5cf449bf91a56ad8835176fa9a9796107e..469b5348f1f805d6d7011cb5eaa8d7064a297f55 100644 --- a/ets2panda/public/es2panda_lib.cpp +++ b/ets2panda/public/es2panda_lib.cpp @@ -16,6 +16,10 @@ #include "es2panda_lib.h" #include +#include "varbinder/varbinder.h" +#include "varbinder/scope.h" +#include "varbinder/variable.h" +#include "public/public.h" #include "generated/signatures.h" #include "es2panda.h" #include "assembler/assembly-program.h" @@ -28,39 +32,221 @@ #include "compiler/core/ETSGen.h" #include "compiler/core/regSpiller.h" #include "compiler/lowering/phase.h" +#include "compiler/lowering/util.h" #include "ir/astNode.h" +#include "ir/expressions/arrowFunctionExpression.h" +#include "ir/ts/tsAsExpression.h" +#include "ir/expressions/assignmentExpression.h" +#include "ir/expressions/binaryExpression.h" +#include "ir/statements/blockStatement.h" +#include "ir/expressions/callExpression.h" +#include "ir/expressions/chainExpression.h" +#include "ir/statements/classDeclaration.h" +#include "ir/base/classDefinition.h" +#include "ir/base/classElement.h" +#include "ir/ts/tsClassImplements.h" +#include "ir/base/classProperty.h" +#include "ir/statements/expressionStatement.h" +#include "ir/statements/functionDeclaration.h" +#include "ir/expressions/functionExpression.h" +#include "ir/ets/etsFunctionType.h" #include "ir/expressions/identifier.h" +#include "ir/statements/ifStatement.h" +#include "ir/module/importDeclaration.h" +#include "ir/expressions/importExpression.h" +#include "ir/module/importSpecifier.h" +#include "ir/base/methodDefinition.h" +#include "ir/ets/etsNewClassInstanceExpression.h" +#include "ir/ets/etsNewArrayInstanceExpression.h" +#include "ir/ets/etsNewMultiDimArrayInstanceExpression.h" +#include "ir/expressions/thisExpression.h" +#include "ir/ts/tsTypeParameter.h" +#include "ir/ts/tsTypeParameterDeclaration.h" +#include "ir/ts/tsTypeParameterInstantiation.h" +#include "ir/statements/variableDeclaration.h" +#include "ir/statements/variableDeclarator.h" #include "parser/ETSparser.h" #include "parser/context/parserContext.h" #include "parser/program/program.h" #include "util/generateBin.h" +#include "util/language.h" #include "util/options.h" namespace panda::es2panda::public_lib { -struct ConfigImpl { - std::unique_ptr options; -}; -struct Context { - ConfigImpl *config = nullptr; - std::string source_file_name; - std::string input; - std::unique_ptr source_file; - std::unique_ptr allocator; - std::unique_ptr queue; - - std::unique_ptr parser_program; - std::unique_ptr parser; - std::unique_ptr checker; - std::unique_ptr analyzer; - std::unique_ptr compiler_context; - std::unique_ptr emitter; - std::unique_ptr program; - - es2panda_ContextState state = ES2PANDA_STATE_NEW; - std::string error_message; +struct TokenTypeToStr { + lexer::TokenType token; + char const *str; }; +static lexer::TokenType StrToToken(TokenTypeToStr const *table, char const *str) +{ + // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) + for (auto *tp = table; tp->str != nullptr; tp++) { + if (strcmp(str, tp->str) == 0) { + return tp->token; + } + } + UNREACHABLE(); +} + +static char const *TokenToStr(TokenTypeToStr const *table, lexer::TokenType token) +{ + // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) + for (auto *tp = table; tp->str != nullptr; tp++) { + if (tp->token == token) { + return tp->str; + } + } + UNREACHABLE(); +} + +static char const *StringViewToCString(ArenaAllocator *allocator, util::StringView const sv) +{ + // NOLINTBEGIN(cppcoreguidelines-pro-bounds-pointer-arithmetic, readability-simplify-subscript-expr) + std::string_view utf8 = sv.Utf8(); + if (utf8.data()[utf8.size()] == '\0') { + // Avoid superfluous allocation. + return utf8.data(); + } + char *res = reinterpret_cast(allocator->Alloc(utf8.size() + 1)); + memmove(res, utf8.cbegin(), utf8.size()); + res[utf8.size()] = '\0'; + return res; + // NOLINTEND(cppcoreguidelines-pro-bounds-pointer-arithmetic, readability-simplify-subscript-expr) +} + +static char const *ArenaStrdup(ArenaAllocator *allocator, char const *src) +{ + size_t len = strlen(src); + char *res = reinterpret_cast(allocator->Alloc(len + 1)); + memmove(res, src, len); + + // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) + res[len] = '\0'; + return res; +} + +// NOLINTNEXTLINE(cppcoreguidelines-macro-usage) +#define FOR_ALL_MODIFIER_FLAGS(_) \ + _(STATIC) \ + _(ASYNC) \ + _(PUBLIC) \ + _(PROTECTED) \ + _(PRIVATE) \ + _(DECLARE) \ + _(READONLY) \ + _(OPTIONAL) \ + _(DEFINITE) \ + _(ABSTRACT) \ + _(CONST) \ + _(FINAL) \ + _(NATIVE) \ + _(OVERRIDE) \ + _(CONSTRUCTOR) \ + _(SYNCHRONIZED) \ + _(FUNCTIONAL) \ + _(IN) \ + _(OUT) \ + _(INTERNAL) \ + _(NULL_ASSIGNABLE) \ + _(UNDEFINED_ASSIGNABLE) \ + _(EXPORT) \ + _(SETTER) \ + _(DEFAULT_EXPORT) + +static ir::ModifierFlags E2pToIrModifierFlags(es2panda_ModifierFlags e2p_flags) +{ + ir::ModifierFlags ir_flags {ir::ModifierFlags::NONE}; + +// NOLINTNEXTLINE(cppcoreguidelines-macro-usage) +#define DO_FLAG(FL) \ + if ((e2p_flags & ES2PANDA_MODIFIER_##FL) != 0) { \ + ir_flags |= ir::ModifierFlags::FL; \ + } + + FOR_ALL_MODIFIER_FLAGS(DO_FLAG) + +#undef DO_FLAG + + return ir_flags; +} + +static es2panda_ModifierFlags IrToE2pModifierFlags(ir::ModifierFlags ir_flags) +{ + es2panda_ModifierFlags e2p_flags {ES2PANDA_MODIFIER_NONE}; + +// NOLINTNEXTLINE(cppcoreguidelines-macro-usage) +#define DO_FLAG(FL) \ + if ((ir_flags & ir::ModifierFlags::FL) != 0) { \ + e2p_flags = static_cast(e2p_flags | ES2PANDA_MODIFIER_##FL); \ + } + + FOR_ALL_MODIFIER_FLAGS(DO_FLAG) + +#undef DO_FLAG + + return e2p_flags; +} + +// NOLINTNEXTLINE(cppcoreguidelines-macro-usage) +#define FOR_ALL_SCRIPT_FUNCTION_FLAGS(_) \ + _(GENERATOR) \ + _(ASYNC) \ + _(ARROW) \ + _(EXPRESSION) \ + _(OVERLOAD) \ + _(CONSTRUCTOR) \ + _(METHOD) \ + _(STATIC_BLOCK) \ + _(HIDDEN) \ + _(IMPLICIT_SUPER_CALL_NEEDED) \ + _(ENUM) \ + _(EXTERNAL) \ + _(PROXY) \ + _(THROWS) \ + _(RETHROWS) \ + _(GETTER) \ + _(SETTER) \ + _(DEFAULT_PARAM_PROXY) \ + _(ENTRY_POINT) \ + _(INSTANCE_EXTENSION_METHOD) \ + _(HAS_RETURN) + +static ir::ScriptFunctionFlags E2pToIrScriptFunctionFlags(es2panda_ScriptFunctionFlags e2p_flags) +{ + ir::ScriptFunctionFlags ir_flags {ir::ScriptFunctionFlags::NONE}; + +// NOLINTNEXTLINE(cppcoreguidelines-macro-usage) +#define DO_FLAG(FL) \ + if ((e2p_flags & ES2PANDA_SCRIPT_FUNCTION_##FL) != 0) { \ + ir_flags |= ir::ScriptFunctionFlags::FL; \ + } + + FOR_ALL_SCRIPT_FUNCTION_FLAGS(DO_FLAG) + +#undef DO_FLAG + + return ir_flags; +} + +static es2panda_ScriptFunctionFlags IrToE2pScriptFunctionFlags(ir::ScriptFunctionFlags ir_flags) +{ + es2panda_ScriptFunctionFlags e2p_flags {ES2PANDA_SCRIPT_FUNCTION_NONE}; + +// NOLINTNEXTLINE(cppcoreguidelines-macro-usage) +#define DO_FLAG(FL) \ + if ((ir_flags & ir::ScriptFunctionFlags::FL) != 0) { \ + e2p_flags = static_cast(e2p_flags | ES2PANDA_SCRIPT_FUNCTION_##FL); \ + } + + FOR_ALL_SCRIPT_FUNCTION_FLAGS(DO_FLAG) + +#undef DO_FLAG + + return e2p_flags; +} + extern "C" es2panda_Config *CreateConfig(int args, char const **argv) { constexpr auto COMPILER_SIZE = 256_MB; @@ -68,7 +254,7 @@ extern "C" es2panda_Config *CreateConfig(int args, char const **argv) mem::MemConfig::Initialize(0, 0, COMPILER_SIZE, 0, 0, 0); PoolManager::Initialize(PoolType::MMAP); - auto options = std::make_unique(); + auto *options = new util::Options(); if (!options->Parse(args, argv)) { // NOTE: gogabr. report option errors properly. std::cerr << options->ErrorMsg() << std::endl; @@ -79,7 +265,7 @@ extern "C" es2panda_Config *CreateConfig(int args, char const **argv) Logger::InitializeStdLogging(Logger::LevelFromString(options->LogLevel()), mask); auto *res = new ConfigImpl; - res->options = std::move(options); + res->options = options; return reinterpret_cast(res); } @@ -88,7 +274,10 @@ extern "C" void DestroyConfig(es2panda_Config *config) PoolManager::Finalize(); mem::MemConfig::Finalize(); - delete reinterpret_cast(config); + auto *cfg = reinterpret_cast(config); + + delete cfg->options; + delete cfg; } static void CompileJob(compiler::CompilerContext *context, varbinder::FunctionScope *scope, @@ -107,31 +296,33 @@ static es2panda_Context *CreateContext(es2panda_Config *config, std::string cons { auto *cfg = reinterpret_cast(config); auto *res = new Context; - res->config = cfg; res->input = source; res->source_file_name = file_name; try { - res->source_file = std::make_unique(res->source_file_name, res->input, cfg->options->ParseModule()); - res->allocator = std::make_unique(SpaceType::SPACE_TYPE_COMPILER, nullptr, true); - res->queue = std::make_unique(cfg->options->ThreadCount()); + res->source_file = new SourceFile(res->source_file_name, res->input, cfg->options->ParseModule()); + res->allocator = new ArenaAllocator(SpaceType::SPACE_TYPE_COMPILER, nullptr, true); + res->queue = new compiler::CompileQueue(cfg->options->ThreadCount()); - auto *varbinder = res->allocator->New(res->allocator.get()); - res->parser_program = std::make_unique(res->allocator.get(), varbinder); + auto *varbinder = res->allocator->New(res->allocator); + res->parser_program = new parser::Program(res->allocator, varbinder); res->parser_program->MarkEntry(); - res->parser = std::make_unique(res->parser_program.get(), cfg->options->CompilerOptions(), - parser::ParserStatus::NO_OPTS); - res->checker = std::make_unique(); - res->analyzer = std::make_unique(res->checker.get()); - res->checker->SetAnalyzer(res->analyzer.get()); - - varbinder->SetProgram(res->parser_program.get()); - - res->compiler_context = std::make_unique( - varbinder, res->checker.get(), cfg->options->CompilerOptions(), CompileJob); - varbinder->SetCompilerContext(res->compiler_context.get()); - res->emitter = std::make_unique(res->compiler_context.get()); - res->compiler_context->SetEmitter(res->emitter.get()); + res->parser = + new parser::ETSParser(res->parser_program, cfg->options->CompilerOptions(), parser::ParserStatus::NO_OPTS); + res->checker = new checker::ETSChecker(); + res->analyzer = new checker::ETSAnalyzer(res->checker); + res->checker->SetAnalyzer(res->analyzer); + + varbinder->SetProgram(res->parser_program); + + res->compiler_context = + new compiler::CompilerContext(varbinder, res->checker, cfg->options->CompilerOptions(), CompileJob); + varbinder->SetCompilerContext(res->compiler_context); + res->phases = compiler::GetETSPhaseList(); + res->current_phase = 0; + res->emitter = new compiler::ETSEmitter(res->compiler_context); + res->compiler_context->SetEmitter(res->emitter); + res->compiler_context->SetParser(res->parser); res->program = nullptr; res->state = ES2PANDA_STATE_NEW; } catch (Error &e) { @@ -151,7 +342,7 @@ extern "C" es2panda_Context *CreateContextFromFile(es2panda_Config *config, char auto *res = new Context; res->error_message = "Failed to open file: "; res->error_message.append(source_file_name); - return reinterpret_cast(res); + return reinterpret_cast(res); } std::stringstream ss; ss << input_stream.rdbuf(); @@ -159,7 +350,7 @@ extern "C" es2panda_Context *CreateContextFromFile(es2panda_Config *config, char auto *res = new Context; res->error_message = "Failed to read file: "; res->error_message.append(source_file_name); - return reinterpret_cast(res); + return reinterpret_cast(res); } return CreateContext(config, ss.str(), source_file_name); } @@ -178,8 +369,9 @@ static Context *Parse(Context *ctx) return ctx; } try { - ctx->parser->ParseScript(*ctx->source_file, ctx->config->options->CompilerOptions().compilation_mode == - CompilationMode::GEN_STD_LIB); + ctx->parser->ParseScript(*ctx->source_file, + ctx->compiler_context->Options()->compilation_mode == CompilationMode::GEN_STD_LIB); + ctx->parser_program = ctx->compiler_context->VarBinder()->Program(); ctx->state = ES2PANDA_STATE_PARSED; } catch (Error &e) { std::stringstream ss; @@ -204,8 +396,13 @@ static Context *Check(Context *ctx) ASSERT(ctx->state == ES2PANDA_STATE_PARSED); try { - ctx->compiler_context->Checker()->StartChecker(ctx->compiler_context->VarBinder(), - ctx->config->options->CompilerOptions()); + do { + if (ctx->current_phase >= ctx->phases.size()) { + break; + } + + ctx->phases[ctx->current_phase]->Apply(ctx, ctx->parser_program); + } while (ctx->phases[ctx->current_phase++]->Name() != "checker"); ctx->state = ES2PANDA_STATE_CHECKED; } catch (Error &e) { std::stringstream ss; @@ -229,8 +426,8 @@ static Context *Lower(Context *ctx) ASSERT(ctx->state == ES2PANDA_STATE_CHECKED); try { - for (auto *phase : compiler::GetETSPhaseList()) { - phase->Apply(ctx->compiler_context.get(), ctx->compiler_context->VarBinder()->Program()); + while (ctx->current_phase < ctx->phases.size()) { + ctx->phases[ctx->current_phase++]->Apply(ctx, ctx->parser_program); } ctx->state = ES2PANDA_STATE_LOWERED; @@ -269,13 +466,12 @@ static Context *GenerateAsm(Context *ctx) emitter->LiteralBufferIndex() += ctx->compiler_context->ContextLiterals().size(); /* Main thread can also be used instead of idling */ - ctx->queue->Schedule(ctx->compiler_context.get()); + ctx->queue->Schedule(ctx->compiler_context); ctx->queue->Consume(); ctx->queue->Wait( [emitter](compiler::CompileJob *job) { emitter->AddProgramElement(job->GetProgramElement()); }); ASSERT(ctx->program == nullptr); - ctx->program = std::unique_ptr { - emitter->Finalize(ctx->compiler_context->DumpDebugInfo(), compiler::Signatures::ETS_GLOBAL)}; + ctx->program = emitter->Finalize(ctx->compiler_context->DumpDebugInfo(), compiler::Signatures::ETS_GLOBAL); ctx->state = ES2PANDA_STATE_ASM_GENERATED; } catch (Error &e) { @@ -301,7 +497,7 @@ Context *GenerateBin(Context *ctx) try { ASSERT(ctx->program != nullptr); - util::GenerateProgram(ctx->program.get(), ctx->config->options.get(), + util::GenerateProgram(ctx->program, ctx->config->options, [ctx](const std::string &str) { ctx->error_message = str; }); ctx->state = ES2PANDA_STATE_BIN_GENERATED; @@ -345,8 +541,18 @@ extern "C" es2panda_Context *ProceedToState(es2panda_Context *context, es2panda_ extern "C" void DestroyContext(es2panda_Context *context) { - auto *s = reinterpret_cast(context); - delete s; + auto *ctx = reinterpret_cast(context); + delete ctx->program; + delete ctx->emitter; + delete ctx->compiler_context; + delete ctx->analyzer; + delete ctx->checker; + delete ctx->parser; + delete ctx->parser_program; + delete ctx->queue; + delete ctx->allocator; + delete ctx->source_file; + delete ctx; } extern "C" es2panda_ContextState ContextState(es2panda_Context *context) @@ -361,13 +567,1942 @@ extern "C" char const *ContextErrorMessage(es2panda_Context *context) return s->error_message.c_str(); } -es2panda_Impl IMPL = {ES2PANDA_LIB_VERSION, +extern "C" es2panda_Program *ContextProgram(es2panda_Context *context) +{ + auto *ctx = reinterpret_cast(context); + return reinterpret_cast(ctx->compiler_context->VarBinder()->Program()); +} + +extern "C" es2panda_AstNode *ProgramAst(es2panda_Program *program) +{ + auto *pgm = reinterpret_cast(program); + return reinterpret_cast(pgm->Ast()); +} + +using ExternalSourceEntry = std::pair *>; + +extern "C" es2panda_ExternalSource **ProgramExternalSources(es2panda_Program *program, size_t *len_p) +{ + auto *pgm = reinterpret_cast(program); + auto *allocator = pgm->VarBinder()->Allocator(); + auto *vec = allocator->New>(allocator->Adapter()); + + for (auto &[e_name, e_programs] : pgm->ExternalSources()) { + vec->push_back(allocator->New(StringViewToCString(allocator, e_name), &e_programs)); + } + + *len_p = vec->size(); + return reinterpret_cast(vec->data()); +} + +extern "C" char const *ExternalSourceName(es2panda_ExternalSource *e_source) +{ + auto *entry = reinterpret_cast(e_source); + return entry->first; +} + +extern "C" es2panda_Program **ExternalSourcePrograms(es2panda_ExternalSource *e_source, size_t *len_p) +{ + auto *entry = reinterpret_cast(e_source); + *len_p = entry->second->size(); + return reinterpret_cast(entry->second->data()); +} + +extern "C" es2panda_Type *AstNodeType(es2panda_AstNode *ast) +{ + auto *node = reinterpret_cast(ast); + // Need to work with other TypeAstNodes + if (node->IsExpression()) { + return reinterpret_cast(node->AsExpression()->TsType()); + } + return nullptr; +} + +extern "C" es2panda_AstNode *const *AstNodeDecorators(es2panda_AstNode *ast, size_t *size_p) +{ + auto *node = reinterpret_cast(ast); + if (node->CanHaveDecorator(false)) { + auto *decorators = node->DecoratorsPtr(); + *size_p = decorators->size(); + return reinterpret_cast(decorators->data()); + } + *size_p = 0; + return nullptr; +} + +extern "C" es2panda_ModifierFlags AstNodeModifierFlags(es2panda_AstNode *ast) +{ + auto *node = reinterpret_cast(ast); + return IrToE2pModifierFlags(node->Modifiers()); +} + +extern "C" void AstNodeSetDecorators(es2panda_Context *context, es2panda_AstNode *ast, es2panda_AstNode **decorators, + size_t n_decorators) +{ + auto *ctx = reinterpret_cast(context); + auto *allocator = ctx->allocator; + auto *node = reinterpret_cast(ast); + + ArenaVector decorators_vector {allocator->Adapter()}; + for (size_t i = 0; i < n_decorators; i++) { + // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) + decorators_vector.push_back(reinterpret_cast(decorators[i])->AsDecorator()); + } + node->AddDecorators(std::move(decorators_vector)); +} + +extern "C" void AstNodeSetType(es2panda_AstNode *ast, es2panda_Type *type) +{ + auto *node = reinterpret_cast(ast); + auto *tp = reinterpret_cast(type); + // Need to work with other TypedAstNodes + if (node->IsExpression()) { + node->AsExpression()->SetTsType(tp); + } else { + UNREACHABLE(); + } +} + +extern "C" void AstNodeForEach(es2panda_AstNode *ast, void (*func)(es2panda_AstNode *, void *), void *arg) +{ + auto *node = reinterpret_cast(ast); + func(ast, arg); + node->IterateRecursively([=](ir::AstNode *child) { func(reinterpret_cast(child), arg); }); +} + +// NOLINTNEXTLINE(cppcoreguidelines-macro-usage) +#define IS(public_name, e2p_name) \ + extern "C" bool Is##public_name(es2panda_AstNode *ast) \ + { \ + auto *node = reinterpret_cast(ast); \ + return node->Is##e2p_name(); \ + } + +IS(ArrowFunctionExpression, ArrowFunctionExpression) +IS(AsExpression, TSAsExpression) +IS(AssignmentExpression, AssignmentExpression) +IS(BinaryExpression, BinaryExpression) +IS(BlockStatement, BlockStatement) +IS(CallExpression, CallExpression) +IS(ChainExpression, ChainExpression) +IS(ClassDeclaration, ClassDeclaration) +IS(ClassDefinition, ClassDefinition) +IS(ClassImplementsClause, TSClassImplements) +IS(ClassProperty, ClassProperty) +IS(ExpressionStatement, ExpressionStatement) +IS(FunctionDeclaration, FunctionDeclaration) +IS(FunctionExpression, FunctionExpression) +IS(FunctionTypeNode, TSFunctionType) +IS(Identifier, Identifier) +IS(IfStatement, IfStatement) +IS(ImportDeclaration, ImportDeclaration) +IS(ImportExpression, ImportExpression) +IS(ImportSpecifier, ImportSpecifier) +IS(MemberExpression, MemberExpression) +IS(MethodDefinition, MethodDefinition) +IS(NewClassInstanceExpression, ETSNewClassInstanceExpression) +IS(NewArrayInstanceExpression, ETSNewArrayInstanceExpression) +IS(NewMultiDimArrayInstanceExpression, ETSNewMultiDimArrayInstanceExpression) +IS(NonNullExpression, TSNonNullExpression) +IS(NumberLiteral, NumberLiteral) +IS(ObjectExpression, ObjectExpression) +IS(ParameterDeclaration, ETSParameterExpression) +IS(PrimitiveTypeNode, ETSPrimitiveType) +IS(ReturnStatement, ReturnStatement) +IS(ScriptFunction, ScriptFunction) +IS(StringLiteral, StringLiteral) +IS(ThisExpression, ThisExpression) +IS(TypeParameter, TSTypeParameter) +IS(TypeParameterDeclaration, TSTypeParameterDeclaration) +IS(TypeParameterInstantiation, TSTypeParameterInstantiation) +IS(TypeReferenceNode, ETSTypeReference) +IS(TypeReferencePart, ETSTypeReferencePart) +IS(UnionTypeNode, TSUnionType) +IS(VariableDeclaration, VariableDeclaration) +IS(VariableDeclarator, VariableDeclarator) + +#undef IS + +extern "C" es2panda_AstNode *CreateArrowFunctionExpression(es2panda_Context *context, es2panda_AstNode *script_function) +{ + auto *ctx = reinterpret_cast(context); + auto *func = reinterpret_cast(script_function)->AsScriptFunction(); + auto *allocator = ctx->allocator; + + return reinterpret_cast(allocator->New(allocator, func)); +} + +extern "C" es2panda_AstNode *ArrowFunctionExpressionScriptFunction(es2panda_AstNode *ast) +{ + auto *node = reinterpret_cast(ast)->AsArrowFunctionExpression(); + return reinterpret_cast(node->Function()); +} + +extern "C" es2panda_AstNode *CreateAsExpression(es2panda_Context *context, es2panda_AstNode *expr, + es2panda_AstNode *type_annotation, bool is_const) +{ + auto *ctx = reinterpret_cast(context); + auto *left_expr = reinterpret_cast(expr)->AsExpression(); + auto *tp = reinterpret_cast(type_annotation)->AsExpression()->AsTypeNode(); + auto *allocator = ctx->allocator; + + return reinterpret_cast(allocator->New(left_expr, tp, is_const)); +} + +extern "C" es2panda_AstNode *AsExpressionExpr(es2panda_AstNode *ast) +{ + auto *node = reinterpret_cast(ast)->AsTSAsExpression(); + return reinterpret_cast(node->Expr()); +} + +extern "C" es2panda_AstNode *AsExpressionTypeAnnotation(es2panda_AstNode *ast) +{ + auto *node = reinterpret_cast(ast)->AsTSAsExpression(); + return reinterpret_cast(node->Type()); +} + +extern "C" bool AsExpressionIsConst(es2panda_AstNode *ast) +{ + auto *node = reinterpret_cast(ast)->AsTSAsExpression(); + return node->IsConst(); +} + +extern "C" void AsExpressionSetExpr(es2panda_AstNode *ast, es2panda_AstNode *expr) +{ + auto *node = reinterpret_cast(ast)->AsTSAsExpression(); + auto *new_expr = reinterpret_cast(expr)->AsExpression(); + node->SetExpr(new_expr); +} + +extern "C" void AsExpressionSetTypeAnnotation(es2panda_AstNode *ast, es2panda_AstNode *type_annotation) +{ + auto *node = reinterpret_cast(ast)->AsTSAsExpression(); + auto *tp = reinterpret_cast(type_annotation)->AsExpression()->AsTypeNode(); + node->SetTsTypeAnnotation(tp); +} + +static constexpr std::array ASSIGNMENT_TOKEN_TYPES { + {{lexer::TokenType::PUNCTUATOR_SUBSTITUTION, "="}, + {lexer::TokenType::PUNCTUATOR_UNSIGNED_RIGHT_SHIFT_EQUAL, ">>>="}, + {lexer::TokenType::PUNCTUATOR_RIGHT_SHIFT_EQUAL, ">>="}, + {lexer::TokenType::PUNCTUATOR_LEFT_SHIFT_EQUAL, "<<="}, + {lexer::TokenType::PUNCTUATOR_PLUS_EQUAL, "+="}, + {lexer::TokenType::PUNCTUATOR_MINUS_EQUAL, "-="}, + {lexer::TokenType::PUNCTUATOR_MULTIPLY_EQUAL, "*="}, + {lexer::TokenType::PUNCTUATOR_DIVIDE_EQUAL, "/="}, + {lexer::TokenType::PUNCTUATOR_MOD_EQUAL, "%="}, + {lexer::TokenType::PUNCTUATOR_BITWISE_AND_EQUAL, "&="}, + {lexer::TokenType::PUNCTUATOR_BITWISE_OR_EQUAL, "|="}, + {lexer::TokenType::PUNCTUATOR_BITWISE_XOR_EQUAL, "^="}, + {lexer::TokenType::PUNCTUATOR_LOGICAL_AND_EQUAL, "&&="}, + {lexer::TokenType::PUNCTUATOR_LOGICAL_OR_EQUAL, "||="}, + {lexer::TokenType::PUNCTUATOR_LOGICAL_NULLISH_EQUAL, "\?\?="}, + {lexer::TokenType::PUNCTUATOR_EXPONENTIATION_EQUAL, "**="}, + {lexer::TokenType::EOS, nullptr}}}; + +extern "C" es2panda_AstNode *CreateAssignmentExpression(es2panda_Context *context, es2panda_AstNode *left, + es2panda_AstNode *right, char const *operator_type) +{ + auto *ctx = reinterpret_cast(context); + auto *allocator = ctx->allocator; + auto *left_node = reinterpret_cast(left)->AsExpression(); + auto *right_node = reinterpret_cast(right)->AsExpression(); + lexer::TokenType tok = StrToToken(ASSIGNMENT_TOKEN_TYPES.data(), operator_type); + return reinterpret_cast(allocator->New(left_node, right_node, tok)); +} + +extern "C" es2panda_AstNode *AssignmentExpressionLeft(es2panda_AstNode *ast) +{ + auto *node = reinterpret_cast(ast)->AsAssignmentExpression(); + return reinterpret_cast(node->Left()); +} + +extern "C" es2panda_AstNode *AssignmentExpressionRight(es2panda_AstNode *ast) +{ + auto *node = reinterpret_cast(ast)->AsAssignmentExpression(); + return reinterpret_cast(node->Right()); +} + +extern "C" char const *AssignmentExpressionOperatorType(es2panda_AstNode *ast) +{ + auto *node = reinterpret_cast(ast)->AsAssignmentExpression(); + return TokenToStr(ASSIGNMENT_TOKEN_TYPES.data(), node->OperatorType()); +} + +extern "C" void AssignmentExpressionSetOperatorType(es2panda_AstNode *ast, char const *operator_type) +{ + auto *node = reinterpret_cast(ast)->AsAssignmentExpression(); + auto tok = StrToToken(ASSIGNMENT_TOKEN_TYPES.data(), operator_type); + node->SetOperatorType(tok); +} + +static constexpr std::array BINARY_OP_TOKEN_TYPES { + {{lexer::TokenType::PUNCTUATOR_UNSIGNED_RIGHT_SHIFT, ">>>"}, + {lexer::TokenType::PUNCTUATOR_RIGHT_SHIFT, ">>"}, + {lexer::TokenType::PUNCTUATOR_LEFT_SHIFT, "<<"}, + {lexer::TokenType::PUNCTUATOR_PLUS, "+"}, + {lexer::TokenType::PUNCTUATOR_MINUS, "-"}, + {lexer::TokenType::PUNCTUATOR_MULTIPLY, "*"}, + {lexer::TokenType::PUNCTUATOR_DIVIDE, "/"}, + {lexer::TokenType::PUNCTUATOR_MOD, "%"}, + {lexer::TokenType::PUNCTUATOR_BITWISE_AND, "&"}, + {lexer::TokenType::PUNCTUATOR_BITWISE_OR, "|"}, + {lexer::TokenType::PUNCTUATOR_BITWISE_XOR, "^"}, + {lexer::TokenType::PUNCTUATOR_LOGICAL_AND, "&&"}, + {lexer::TokenType::PUNCTUATOR_LOGICAL_OR, "||"}, + {lexer::TokenType::PUNCTUATOR_NULLISH_COALESCING, "??"}, + {lexer::TokenType::PUNCTUATOR_EXPONENTIATION, "**"}, + {lexer::TokenType::PUNCTUATOR_EQUAL, "=="}, + {lexer::TokenType::PUNCTUATOR_NOT_EQUAL, "/="}, + {lexer::TokenType::PUNCTUATOR_STRICT_EQUAL, "==="}, + {lexer::TokenType::PUNCTUATOR_NOT_STRICT_EQUAL, "/=="}, + {lexer::TokenType::PUNCTUATOR_LESS_THAN, "<"}, + {lexer::TokenType::PUNCTUATOR_LESS_THAN_EQUAL, "<="}, + {lexer::TokenType::PUNCTUATOR_GREATER_THAN, ">"}, + {lexer::TokenType::PUNCTUATOR_GREATER_THAN_EQUAL, ">="}, + {lexer::TokenType::KEYW_IN, "in"}, + {lexer::TokenType::KEYW_INSTANCEOF, "instanceof"}, + {lexer::TokenType::EOS, nullptr}}}; + +extern "C" es2panda_AstNode *CreateBinaryExpression(es2panda_Context *context, es2panda_AstNode *left, + es2panda_AstNode *right, char const *operator_type) +{ + auto *ctx = reinterpret_cast(context); + auto *allocator = ctx->allocator; + auto *left_expr = reinterpret_cast(left)->AsExpression(); + auto *right_expr = reinterpret_cast(right)->AsExpression(); + auto tok = StrToToken(BINARY_OP_TOKEN_TYPES.data(), operator_type); + + return reinterpret_cast(allocator->New(left_expr, right_expr, tok)); +} + +extern "C" es2panda_AstNode *BinaryExpressionLeft(es2panda_AstNode *ast) +{ + auto *node = reinterpret_cast(ast)->AsBinaryExpression(); + return reinterpret_cast(node->Left()); +} + +extern "C" es2panda_AstNode *BinaryExpressionRight(es2panda_AstNode *ast) +{ + auto *node = reinterpret_cast(ast)->AsBinaryExpression(); + return reinterpret_cast(node->Right()); +} + +extern "C" char const *BinaryExpressionOperator(es2panda_AstNode *ast) +{ + auto *node = reinterpret_cast(ast)->AsBinaryExpression(); + return TokenToStr(BINARY_OP_TOKEN_TYPES.data(), node->OperatorType()); +} + +extern "C" void BinaryExpressionSetOperator(es2panda_AstNode *ast, char const *operator_type) +{ + auto *node = reinterpret_cast(ast)->AsBinaryExpression(); + auto op = StrToToken(BINARY_OP_TOKEN_TYPES.data(), operator_type); + node->SetOperator(op); +} + +extern "C" es2panda_AstNode *CreateBlockStatement(es2panda_Context *context, es2panda_AstNode *in_scope_of) +{ + auto *ctx = reinterpret_cast(context); + auto *allocator = ctx->allocator; + auto *parent = reinterpret_cast(in_scope_of); + auto *parent_scope = compiler::NearestScope(parent); + + auto *scope = allocator->New(allocator, parent_scope); + ArenaVector stmts {allocator->Adapter()}; + return reinterpret_cast(allocator->New(allocator, scope, std::move(stmts))); +} + +extern "C" es2panda_AstNode **BlockStatementStatements(es2panda_AstNode *ast, size_t *size_p) +{ + auto *node = reinterpret_cast(ast)->AsBlockStatement(); + *size_p = node->Statements().size(); + return reinterpret_cast(node->Statements().data()); +} + +extern "C" void BlockStatementAddStatement(es2panda_AstNode *ast, es2panda_AstNode *statement) +{ + auto *node = reinterpret_cast(ast)->AsBlockStatement(); + auto *stmt = reinterpret_cast(statement)->AsBlockStatement(); + node->Statements().push_back(stmt); +} + +extern "C" es2panda_AstNode *CreateCallExpression(es2panda_Context *context, es2panda_AstNode *callee, + es2panda_AstNode *type_arguments, es2panda_AstNode **arguments, + size_t n_arguments, bool is_optional) +{ + auto *ctx = reinterpret_cast(context); + auto *allocator = ctx->allocator; + auto *callee_node = reinterpret_cast(callee)->AsExpression(); + + ir::TSTypeParameterInstantiation *type_args = nullptr; + if (type_arguments != nullptr) { + type_args = reinterpret_cast(type_arguments)->AsTSTypeParameterInstantiation(); + } + + ArenaVector args {allocator->Adapter()}; + for (size_t i = 0; i < n_arguments; i++) { + // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) + args.push_back(reinterpret_cast(arguments[i])->AsExpression()); + } + return reinterpret_cast( + allocator->New(callee_node, std::move(args), type_args, is_optional)); +} + +extern "C" es2panda_AstNode const *CallExpressionCallee(es2panda_AstNode *ast) +{ + auto *node = reinterpret_cast(ast)->AsCallExpression(); + return reinterpret_cast(node->Callee()); +} + +extern "C" es2panda_AstNode const *CallExpressionTypeArguments(es2panda_AstNode *ast) +{ + auto *node = reinterpret_cast(ast)->AsCallExpression(); + return reinterpret_cast(node->TypeParams()); +} + +extern "C" es2panda_AstNode **CallExpressionArguments(es2panda_AstNode *ast, size_t *size_p) +{ + auto *node = reinterpret_cast(ast)->AsCallExpression(); + *size_p = node->Arguments().size(); + return reinterpret_cast(node->Arguments().data()); +} + +extern "C" bool CallExpressionIsOptional(es2panda_AstNode *ast) +{ + auto *node = reinterpret_cast(ast)->AsCallExpression(); + return node->IsOptional(); +} + +extern "C" void CallExpressionSetTypeArguments(es2panda_AstNode *ast, es2panda_AstNode *type_arguments) +{ + auto *node = reinterpret_cast(ast)->AsCallExpression(); + auto *type_args = reinterpret_cast(type_arguments)->AsTSTypeParameterInstantiation(); + node->SetTypeParams(type_args); +} + +extern "C" es2panda_AstNode *CreateChainExpression(es2panda_Context *context, es2panda_AstNode *child) +{ + auto *ctx = reinterpret_cast(context); + auto *allocator = ctx->allocator; + auto *child_expr = reinterpret_cast(child)->AsExpression(); + + return reinterpret_cast(allocator->New(child_expr)); +} + +extern "C" es2panda_AstNode const *ChainExpressionChild(es2panda_AstNode *ast) +{ + auto *node = reinterpret_cast(ast)->AsChainExpression(); + return reinterpret_cast(node->GetExpression()); +} + +extern "C" es2panda_AstNode *CreateClassDeclaration(es2panda_Context *context, es2panda_AstNode *definition) +{ + auto *ctx = reinterpret_cast(context); + auto *allocator = ctx->allocator; + auto *dfn = reinterpret_cast(definition)->AsClassDefinition(); + + return reinterpret_cast(allocator->New(dfn, allocator)); +} + +extern "C" es2panda_AstNode *ClassDeclarationDefinition(es2panda_AstNode *ast) +{ + auto *node = reinterpret_cast(ast)->AsClassDeclaration(); + return reinterpret_cast(node->Definition()); +} + +extern "C" es2panda_AstNode *CreateClassDefinition(es2panda_Context *context, es2panda_AstNode *in_scope_of, + es2panda_AstNode *identifier, es2panda_ModifierFlags flags) +{ + auto *ctx = reinterpret_cast(context); + auto *allocator = ctx->allocator; + auto *parent = reinterpret_cast(in_scope_of); + auto *parent_scope = compiler::NearestScope(parent); + auto *id = reinterpret_cast(identifier)->AsIdentifier(); + + auto *scope = allocator->New(allocator, parent_scope); + return reinterpret_cast( + allocator->New(allocator, scope, id, ir::ClassDefinitionModifiers::NONE, + E2pToIrModifierFlags(flags), Language::FromString("ets").value())); +} + +extern "C" es2panda_AstNode *ClassDefinitionIdentifier(es2panda_AstNode *ast) +{ + auto *node = reinterpret_cast(ast)->AsClassDefinition(); + return reinterpret_cast(node->Ident()); +} + +extern "C" es2panda_AstNode *ClassDefinitionTypeParameters(es2panda_AstNode *ast) +{ + auto *node = reinterpret_cast(ast)->AsClassDefinition(); + return reinterpret_cast(node->TypeParams()); +} + +extern "C" es2panda_AstNode *ClassDefinitionSuperClass(es2panda_AstNode *ast) +{ + auto *node = reinterpret_cast(ast)->AsClassDefinition(); + return reinterpret_cast(node->Super()); +} + +extern "C" es2panda_AstNode **ClassDefinitionImplements(es2panda_AstNode *ast, size_t *size_p) +{ + auto *node = reinterpret_cast(ast)->AsClassDefinition(); + auto &impl_vec = node->Implements(); + *size_p = impl_vec.size(); + return reinterpret_cast(impl_vec.data()); +} + +extern "C" es2panda_AstNode *ClassDefinitionConstructor(es2panda_AstNode *ast) +{ + auto *node = reinterpret_cast(ast)->AsClassDefinition(); + return reinterpret_cast(node->Ctor()); +} + +extern "C" es2panda_AstNode **ClassDefinitionBody(es2panda_AstNode *ast, size_t *size_p) +{ + auto *node = reinterpret_cast(ast)->AsClassDefinition(); + auto &body_vec = node->Body(); + *size_p = body_vec.size(); + return reinterpret_cast(body_vec.data()); +} + +extern "C" void ClassDefinitionSetIdentifier(es2panda_AstNode *ast, es2panda_AstNode *identifier) +{ + auto *node = reinterpret_cast(ast)->AsClassDefinition(); + auto *id = reinterpret_cast(identifier)->AsIdentifier(); + node->SetIdent(id); +} + +extern "C" void ClassDefinitionSetTypeParameters(es2panda_AstNode *ast, es2panda_AstNode *type_params) +{ + auto *node = reinterpret_cast(ast)->AsClassDefinition(); + auto *tpd = reinterpret_cast(type_params)->AsTSTypeParameterDeclaration(); + node->SetTypeParams(tpd); +} - CreateConfig, DestroyConfig, +extern "C" void ClassDefinitionSetSuperClass(es2panda_AstNode *ast, es2panda_AstNode *super_class) +{ + auto *node = reinterpret_cast(ast)->AsClassDefinition(); + auto *super = reinterpret_cast(super_class)->AsExpression(); + node->SetSuper(super); +} - CreateContextFromFile, CreateContextFromString, ProceedToState, DestroyContext, +extern "C" void ClassDefinitionSetImplements(es2panda_AstNode *ast, es2panda_AstNode **implements, size_t n_implements) +{ + auto *node = reinterpret_cast(ast)->AsClassDefinition(); + auto &impl_vec = node->Implements(); + impl_vec.resize(0); + for (size_t i = 0; i < n_implements; i++) { + // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) + impl_vec.push_back(reinterpret_cast(implements[i])->AsTSClassImplements()); + } +} - ContextState, ContextErrorMessage}; +extern "C" void ClassDefinitionAddImplements(es2panda_AstNode *ast, es2panda_AstNode *implements) +{ + auto *node = reinterpret_cast(ast)->AsClassDefinition(); + auto &impl_vec = node->Implements(); + impl_vec.push_back(reinterpret_cast(implements)->AsTSClassImplements()); +} + +extern "C" void ClassDefinitionSetConstructor(es2panda_AstNode *ast, es2panda_AstNode *constructor) +{ + auto *node = reinterpret_cast(ast)->AsClassDefinition(); + auto *ctor = reinterpret_cast(constructor)->AsMethodDefinition(); + node->SetCtor(ctor); +} + +extern "C" void ClassDefinitionSetBody(es2panda_AstNode *ast, es2panda_AstNode **body, size_t n_elems) +{ + auto *node = reinterpret_cast(ast)->AsClassDefinition(); + auto &body_vec = node->Body(); + body_vec.resize(0); + for (size_t i = 0; i < n_elems; i++) { + // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) + body_vec.push_back(reinterpret_cast(body[i])); + } +} + +extern "C" void ClassDefinitionAddToBody(es2panda_AstNode *ast, es2panda_AstNode *body_elem) +{ + auto *node = reinterpret_cast(ast)->AsClassDefinition(); + auto *elem = reinterpret_cast(body_elem); + auto &body_vec = node->Body(); + body_vec.push_back(reinterpret_cast(elem)); +} + +extern "C" es2panda_AstNode *ClassElementKey(es2panda_AstNode *ast) +{ + auto *node = reinterpret_cast(ast)->AsClassElement(); + return reinterpret_cast(node->Key()); +} + +extern "C" es2panda_AstNode *ClassElementValue(es2panda_AstNode *ast) +{ + auto *node = reinterpret_cast(ast)->AsClassElement(); + return reinterpret_cast(node->Value()); +} + +extern "C" es2panda_AstNode *CreateClassImplementsClause(es2panda_Context *context, es2panda_AstNode *expression, + es2panda_AstNode *type_arguments) +{ + auto *ctx = reinterpret_cast(context); + auto *allocator = ctx->allocator; + auto *expr = reinterpret_cast(expression)->AsExpression(); + auto *targs = type_arguments == nullptr + ? nullptr + : reinterpret_cast(type_arguments)->AsTSTypeParameterInstantiation(); + + return reinterpret_cast(allocator->New(expr, targs)); +} + +extern "C" es2panda_AstNode *ClassImplementsClauseExpression(es2panda_AstNode *ast) +{ + auto *node = reinterpret_cast(ast)->AsTSClassImplements(); + return reinterpret_cast(node->Expr()); +} + +extern "C" es2panda_AstNode const *ClassImplementsClauseTypeArguments(es2panda_AstNode *ast) +{ + auto *node = reinterpret_cast(ast)->AsTSClassImplements(); + return reinterpret_cast(node->TypeParameters()); +} + +extern "C" es2panda_AstNode *CreateClassProperty(es2panda_Context *context, es2panda_AstNode *key, + es2panda_AstNode *value, es2panda_AstNode *type_annotation, + es2panda_ModifierFlags modifier_flags, bool is_computed) +{ + auto *ctx = reinterpret_cast(context); + auto *allocator = ctx->allocator; + auto *ekey = reinterpret_cast(key)->AsExpression(); + auto *evalue = value == nullptr ? nullptr : reinterpret_cast(value)->AsExpression(); + auto *tp_ann = type_annotation == nullptr + ? nullptr + : reinterpret_cast(type_annotation)->AsExpression()->AsTypeNode(); + auto modifiers = E2pToIrModifierFlags(modifier_flags); + + return reinterpret_cast( + allocator->New(ekey, evalue, tp_ann, modifiers, allocator, is_computed)); +} + +extern "C" es2panda_AstNode *ClassPropertyTypeAnnotation(es2panda_AstNode *ast) +{ + auto *node = reinterpret_cast(ast)->AsClassProperty(); + return reinterpret_cast(node->TypeAnnotation()); +} + +extern "C" es2panda_AstNode *CreateExpressionStatement(es2panda_Context *context, es2panda_AstNode *expression) +{ + auto *ctx = reinterpret_cast(context); + auto *allocator = ctx->allocator; + auto *expr = reinterpret_cast(expression)->AsExpression(); + + return reinterpret_cast(allocator->New(expr)); +} + +extern "C" es2panda_AstNode *ExpressionStatementExpression(es2panda_AstNode *ast) +{ + auto *node = reinterpret_cast(ast)->AsExpressionStatement(); + return reinterpret_cast(node->GetExpression()); +} + +extern "C" es2panda_AstNode *CreateFunctionDeclaration(es2panda_Context *context, es2panda_AstNode *function) +{ + auto *ctx = reinterpret_cast(context); + auto *allocator = ctx->allocator; + auto *func = reinterpret_cast(function)->AsScriptFunction(); + + return reinterpret_cast(allocator->New(allocator, func)); +} + +extern "C" es2panda_AstNode *FunctionDeclarationFunction(es2panda_AstNode *ast) +{ + auto *node = reinterpret_cast(ast)->AsFunctionDeclaration(); + return reinterpret_cast(node->Function()); +} + +extern "C" es2panda_AstNode *CreateFunctionExpression(es2panda_Context *context, es2panda_AstNode *function) +{ + auto *ctx = reinterpret_cast(context); + auto *allocator = ctx->allocator; + auto *func = reinterpret_cast(function)->AsScriptFunction(); + + return reinterpret_cast(allocator->New(func)); +} + +extern "C" es2panda_AstNode *FunctionExpressionFunction(es2panda_AstNode *ast) +{ + auto *node = reinterpret_cast(ast)->AsFunctionExpression(); + return reinterpret_cast(node->Function()); +} + +extern "C" es2panda_AstNode *CreateFunctionTypeNode(es2panda_Context *context, es2panda_AstNode *in_scope_of, + es2panda_AstNode *type_params, es2panda_AstNode **params, + size_t n_params, es2panda_AstNode *return_type, + es2panda_ScriptFunctionFlags func_flags) +{ + auto *ctx = reinterpret_cast(context); + auto *allocator = ctx->allocator; + auto *parent = reinterpret_cast(in_scope_of); + auto *parent_scope = compiler::NearestScope(parent); + auto *tpar = + type_params == nullptr ? nullptr : reinterpret_cast(type_params)->AsTSTypeParameterDeclaration(); + auto *tret = + return_type == nullptr ? nullptr : reinterpret_cast(return_type)->AsExpression()->AsTypeNode(); + auto flags = E2pToIrScriptFunctionFlags(func_flags); + + auto *scope = allocator->New(allocator, parent_scope); + + ArenaVector par {allocator->Adapter()}; + for (size_t i = 0; i < n_params; i++) { + // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) + par.push_back(reinterpret_cast(params[i])->AsExpression()); + } + + return reinterpret_cast( + allocator->New(scope, std::move(par), tpar, tret, flags)); +} + +extern "C" es2panda_AstNode const *FunctionTypeNodeTypeParams(es2panda_AstNode *ast) +{ + auto *node = reinterpret_cast(ast)->AsETSFunctionType(); + return reinterpret_cast(node->TypeParams()); +} + +extern "C" es2panda_AstNode *const *FunctionTypeNodeParams(es2panda_AstNode *ast, size_t *size_p) +{ + auto *node = reinterpret_cast(ast)->AsETSFunctionType(); + auto ¶ms = node->Params(); + *size_p = params.size(); + return reinterpret_cast(params.data()); +} + +extern "C" es2panda_AstNode *FunctionTypeNodeReturnType(es2panda_AstNode *ast) +{ + auto *node = reinterpret_cast(ast)->AsETSFunctionType(); + return reinterpret_cast(node->ReturnType()); +} + +extern "C" es2panda_ScriptFunctionFlags FunctionTypeNodeFlags(es2panda_AstNode *ast) +{ + auto *node = reinterpret_cast(ast)->AsETSFunctionType(); + return IrToE2pScriptFunctionFlags(node->Flags()); +} + +extern "C" es2panda_AstNode *CreateIdentifier(es2panda_Context *context, char const *name, + es2panda_AstNode *type_annotations) +{ + auto *ctx = reinterpret_cast(context); + auto *allocator = ctx->allocator; + auto *name_copy = ArenaStrdup(ctx->allocator, name); + auto *tp_ann = type_annotations == nullptr + ? nullptr + : reinterpret_cast(type_annotations)->AsExpression()->AsTypeNode(); + + auto *res = allocator->New(util::StringView {name_copy}, tp_ann, allocator); + + return reinterpret_cast(res); +} + +extern "C" char const *IdentifierName(es2panda_Context *context, es2panda_AstNode *identifier) +{ + auto *ctx = reinterpret_cast(context); + auto *id = reinterpret_cast(identifier); + ASSERT(id->IsIdentifier()); + + return StringViewToCString(ctx->allocator, id->AsIdentifier()->Name()); +} + +extern "C" es2panda_AstNode *IdentifierTypeAnnotation(es2panda_AstNode *identifier) +{ + auto *id = reinterpret_cast(identifier)->AsIdentifier(); + return reinterpret_cast(id->TypeAnnotation()); +} + +extern "C" es2panda_Variable *IdentifierVariable(es2panda_AstNode *identifier) +{ + auto *id = reinterpret_cast(identifier)->AsIdentifier(); + + return reinterpret_cast(id->Variable()); +} + +extern "C" void IdentifierSetVariable(es2panda_AstNode *identifier, es2panda_Variable *variable) +{ + auto *id = reinterpret_cast(identifier)->AsIdentifier(); + auto *var = reinterpret_cast(variable); + + id->SetVariable(var); +} + +extern "C" es2panda_AstNode *CreateIfStatement(es2panda_Context *context, es2panda_AstNode *test, + es2panda_AstNode *consequent, es2panda_AstNode *alternate) +{ + auto *ctx = reinterpret_cast(context); + auto *allocator = ctx->allocator; + auto *t = reinterpret_cast(test)->AsExpression(); + auto *conseq = reinterpret_cast(consequent)->AsStatement(); + auto *alt = reinterpret_cast(alternate)->AsStatement(); + + return reinterpret_cast(allocator->New(t, conseq, alt)); +} + +extern "C" es2panda_AstNode const *IfStatementTest(es2panda_AstNode *identifier) +{ + auto *if_stat = reinterpret_cast(identifier)->AsIfStatement(); + + return reinterpret_cast(if_stat->Test()); +} + +extern "C" es2panda_AstNode const *IfStatementConsequent(es2panda_AstNode *identifier) +{ + auto *if_stat = reinterpret_cast(identifier)->AsIfStatement(); + + return reinterpret_cast(if_stat->Consequent()); +} + +extern "C" es2panda_AstNode const *IfStatementAlternate(es2panda_AstNode *identifier) +{ + auto *if_stat = reinterpret_cast(identifier)->AsIfStatement(); + + return reinterpret_cast(if_stat->Alternate()); +} + +extern "C" es2panda_AstNode *CreateImportDeclaration(es2panda_Context *context, es2panda_AstNode *source, + es2panda_AstNode **specifiers, size_t n_specifiers) +{ + auto *ctx = reinterpret_cast(context); + auto *allocator = ctx->allocator; + auto *src = reinterpret_cast(source)->AsStringLiteral(); + + ArenaVector specs {allocator->Adapter()}; + for (size_t i = 0; i < n_specifiers; i++) { + // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) + specs.push_back(reinterpret_cast(specifiers[i])); + } + + return reinterpret_cast(allocator->New(src, std::move(specs))); +} + +extern "C" es2panda_AstNode const *ImportDeclarationSource(es2panda_AstNode *ast) +{ + auto *decl = reinterpret_cast(ast)->AsImportDeclaration(); + + return reinterpret_cast(decl->Source()); +} + +extern "C" es2panda_AstNode *const *ImportDeclarationSpecifiers(es2panda_AstNode *ast, size_t *size_p) +{ + auto *decl = reinterpret_cast(ast)->AsImportDeclaration(); + auto &specs = decl->Specifiers(); + + *size_p = specs.size(); + + return reinterpret_cast(specs.data()); +} + +extern "C" es2panda_AstNode *CreateImportExpression(es2panda_Context *context, es2panda_AstNode *source) +{ + auto *ctx = reinterpret_cast(context); + auto *allocator = ctx->allocator; + auto *src = reinterpret_cast(source)->AsExpression(); + + return reinterpret_cast(allocator->New(src)); +} + +extern "C" es2panda_AstNode *ImportExpressionSource(es2panda_AstNode *ast) +{ + auto *node = reinterpret_cast(ast)->AsImportExpression(); + return reinterpret_cast(node->Source()); +} + +extern "C" es2panda_AstNode *CreateImportSpecifier(es2panda_Context *context, es2panda_AstNode *imported, + es2panda_AstNode *local) +{ + auto *ctx = reinterpret_cast(context); + auto *allocator = ctx->allocator; + auto *ir_imported = reinterpret_cast(imported)->AsIdentifier(); + auto *ir_local = reinterpret_cast(local)->AsIdentifier(); + + return reinterpret_cast(allocator->New(ir_imported, ir_local)); +} + +extern "C" es2panda_AstNode *ImportSpecifierImported(es2panda_AstNode *ast) +{ + auto *node = reinterpret_cast(ast)->AsImportSpecifier(); + return reinterpret_cast(node->Imported()); +} + +extern "C" es2panda_AstNode *ImportSpecifierLocal(es2panda_AstNode *ast) +{ + auto *node = reinterpret_cast(ast)->AsImportSpecifier(); + return reinterpret_cast(node->Local()); +} + +// NOLINTNEXTLINE(cppcoreguidelines-macro-usage) +#define FOR_ALL_MEMBER_EXPRESSION_KINDS(_) \ + _(ELEMENT_ACCESS) \ + _(PROPERTY_ACCESS) \ + _(GETTER) \ + _(SETTER) + +static ir::MemberExpressionKind E2pToIrMemberExpressionKind(es2panda_MemberExpressionKind e2p_kind) +{ + ir::MemberExpressionKind ir_kind = ir::MemberExpressionKind::NONE; + +// NOLINTNEXTLINE(cppcoreguidelines-macro-usage) +#define DO_KIND(K) \ + if ((e2p_kind & ES2PANDA_MEMBER_EXPRESSION_KIND_##K) != 0) { \ + ir_kind |= ir::MemberExpressionKind::K; \ + } + + FOR_ALL_MEMBER_EXPRESSION_KINDS(DO_KIND) + +#undef DO_KIND + + return ir_kind; +} + +static es2panda_MemberExpressionKind IrToE2pMemberExpressionKind(ir::MemberExpressionKind ir_kind) +{ + es2panda_MemberExpressionKind e2p_kind = ES2PANDA_MEMBER_EXPRESSION_KIND_NONE; + +// NOLINTNEXTLINE(cppcoreguidelines-macro-usage) +#define DO_KIND(K) \ + if ((ir_kind & ir::MemberExpressionKind::K) != 0) { \ + e2p_kind = static_cast(e2p_kind | ES2PANDA_MEMBER_EXPRESSION_KIND_##K); \ + } + + FOR_ALL_MEMBER_EXPRESSION_KINDS(DO_KIND) + +#undef DO_KIND + + return e2p_kind; +} + +extern "C" es2panda_AstNode *CreateMemberExpression(es2panda_Context *context, es2panda_AstNode *object, + es2panda_AstNode *property, es2panda_MemberExpressionKind kind, + bool is_computed, bool is_optional) +{ + auto *ctx = reinterpret_cast(context); + auto *allocator = ctx->allocator; + auto ir_object = reinterpret_cast(object)->AsExpression(); + auto ir_property = reinterpret_cast(property)->AsExpression(); + auto ir_kind = E2pToIrMemberExpressionKind(kind); + + return reinterpret_cast( + allocator->New(ir_object, ir_property, ir_kind, is_computed, is_optional)); +} + +extern "C" es2panda_AstNode *MemberExpressionObject(es2panda_AstNode *ast) +{ + auto *node = reinterpret_cast(ast)->AsMemberExpression(); + return reinterpret_cast(node->Object()); +} + +extern "C" es2panda_AstNode *MemberExpressionProperty(es2panda_AstNode *ast) +{ + auto *node = reinterpret_cast(ast)->AsMemberExpression(); + return reinterpret_cast(node->Property()); +} + +extern "C" es2panda_MemberExpressionKind MemberExpressionKind(es2panda_AstNode *ast) +{ + auto *node = reinterpret_cast(ast)->AsMemberExpression(); + return IrToE2pMemberExpressionKind(node->Kind()); +} + +extern "C" bool MemberExpressionIsComputed(es2panda_AstNode *ast) +{ + auto *node = reinterpret_cast(ast)->AsMemberExpression(); + return node->IsComputed(); +} + +extern "C" bool MemberExpressionIsOptional(es2panda_AstNode *ast) +{ + auto *node = reinterpret_cast(ast)->AsMemberExpression(); + return node->IsOptional(); +} + +struct MethodDefinitionKindToStrStruct { + ir::MethodDefinitionKind kind; + char const *str; +}; + +static constexpr std::array METHOD_DEFINITION_KIND_TO_STR {{ + {ir::MethodDefinitionKind::CONSTRUCTOR, "constructor"}, + {ir::MethodDefinitionKind::METHOD, "method"}, + {ir::MethodDefinitionKind::EXTENSION_METHOD, "extension method"}, + {ir::MethodDefinitionKind::GET, "get"}, + {ir::MethodDefinitionKind::SET, "set"}, +}}; + +static ir::MethodDefinitionKind StrToMethodDefinitionKind(char const *str) +{ + for (auto &elem : METHOD_DEFINITION_KIND_TO_STR) { + if (strcmp(elem.str, str) == 0) { + return elem.kind; + } + } + return ir::MethodDefinitionKind::NONE; +} + +static char const *MethodDefinitionKindToStr(ir::MethodDefinitionKind kind) +{ + for (auto &elem : METHOD_DEFINITION_KIND_TO_STR) { + if (elem.kind == kind) { + return elem.str; + } + } + return "unknown"; +} + +extern "C" es2panda_AstNode *CreateMethodDefinition(es2panda_Context *context, char const *kind, es2panda_AstNode *key, + es2panda_AstNode *value, es2panda_ModifierFlags modifiers, + bool is_computed) +{ + auto *ctx = reinterpret_cast(context); + auto *allocator = ctx->allocator; + auto ir_kind = StrToMethodDefinitionKind(kind); + auto *ir_key = reinterpret_cast(key)->AsExpression(); + auto *ir_value = reinterpret_cast(value)->AsExpression(); + auto ir_flags = E2pToIrModifierFlags(modifiers); + + return reinterpret_cast( + allocator->New(ir_kind, ir_key, ir_value, ir_flags, allocator, is_computed)); +} + +extern "C" char const *MethodDefinitionKind(es2panda_AstNode *ast) +{ + auto *node = reinterpret_cast(ast)->AsMethodDefinition(); + return MethodDefinitionKindToStr(node->Kind()); +} + +extern "C" es2panda_AstNode const *MethodDefinitionKey(es2panda_AstNode *ast) +{ + auto *node = reinterpret_cast(ast)->AsMethodDefinition(); + return reinterpret_cast(node->Key()); +} + +extern "C" es2panda_AstNode const *MethodDefinitionValue(es2panda_AstNode *ast) +{ + auto *node = reinterpret_cast(ast)->AsMethodDefinition(); + return reinterpret_cast(node->Value()); +} + +extern "C" es2panda_ModifierFlags MethodDefinitionModifiers(es2panda_AstNode *ast) +{ + auto *node = reinterpret_cast(ast)->AsMethodDefinition(); + return IrToE2pModifierFlags(node->Modifiers()); +} + +extern "C" bool MethodDefinitionIsComputed(es2panda_AstNode *ast) +{ + auto *node = reinterpret_cast(ast)->AsMethodDefinition(); + return node->IsComputed(); +} + +extern "C" es2panda_AstNode *const *MethodDefinitionOverloads(es2panda_AstNode *ast, size_t *size_p) +{ + auto *node = reinterpret_cast(ast)->AsMethodDefinition(); + auto const &overloads = node->Overloads(); + *size_p = overloads.size(); + return reinterpret_cast(overloads.data()); +} + +extern "C" void MethodDefinitionSetOverloads(es2panda_AstNode *ast, es2panda_AstNode **overloads, size_t n_overloads) +{ + auto *node = reinterpret_cast(ast)->AsMethodDefinition(); + ArenaVector ir_overloads {node->Overloads().get_allocator()}; + ir_overloads.reserve(n_overloads); + for (size_t i = 0; i < n_overloads; i++) { + // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) + ir_overloads.push_back(reinterpret_cast(overloads[i])->AsMethodDefinition()); + } + node->SetOverloads(std::move(ir_overloads)); +} + +extern "C" void MethodDefinitionAddOverload(es2panda_AstNode *ast, es2panda_AstNode *overload) +{ + auto *node = reinterpret_cast(ast)->AsMethodDefinition(); + auto *ir_overload = reinterpret_cast(overload)->AsMethodDefinition(); + node->AddOverload(ir_overload); +} + +extern "C" es2panda_AstNode *CreateNewClassInstanceExpression(es2panda_Context *context, + es2panda_AstNode *type_reference, + es2panda_AstNode **arguments, size_t n_arguments, + es2panda_AstNode *class_definition) +{ + auto *ctx = reinterpret_cast(context); + auto *allocator = ctx->allocator; + auto *ir_typeref = reinterpret_cast(type_reference)->AsExpression(); + + ArenaVector args {allocator->Adapter()}; + for (size_t i = 0; i < n_arguments; i++) { + // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) + args.push_back(reinterpret_cast(arguments[i])->AsExpression()); + } + + auto *ir_classdef = + class_definition == nullptr ? nullptr : reinterpret_cast(class_definition)->AsClassDefinition(); + + return reinterpret_cast( + allocator->New(ir_typeref, std::move(args), ir_classdef)); +} + +extern "C" es2panda_AstNode *NewClassInstanceExpressionTypeReference(es2panda_AstNode *ast) +{ + auto *node = reinterpret_cast(ast)->AsETSNewClassInstanceExpression(); + return reinterpret_cast(node->GetTypeRef()); +} + +extern "C" es2panda_AstNode *const *NewClassInstanceExpressionArguments(es2panda_AstNode *ast, size_t *size_p) +{ + auto *node = reinterpret_cast(ast)->AsETSNewClassInstanceExpression(); + auto const &args = node->GetArguments(); + + *size_p = args.size(); + return reinterpret_cast(args.data()); +} + +extern "C" es2panda_AstNode *NewClassInstanceExpressionClassDefinition(es2panda_AstNode *ast) +{ + auto *node = reinterpret_cast(ast)->AsETSNewClassInstanceExpression(); + return reinterpret_cast(node->ClassDefinition()); +} + +extern "C" es2panda_AstNode *CreateNewArrayInstanceExpression(es2panda_Context *context, + es2panda_AstNode *type_reference, + es2panda_AstNode *dimension) +{ + auto *ctx = reinterpret_cast(context); + auto *allocator = ctx->allocator; + auto *ir_typeref = reinterpret_cast(type_reference)->AsExpression()->AsTypeNode(); + auto *ir_dim = reinterpret_cast(dimension)->AsExpression(); + + return reinterpret_cast(allocator->New(ir_typeref, ir_dim)); +} + +extern "C" es2panda_AstNode *NewArrayInstanceExpressionTypeReference(es2panda_AstNode *ast) +{ + auto *node = reinterpret_cast(ast)->AsETSNewArrayInstanceExpression(); + return reinterpret_cast(node->TypeReference()); +} + +extern "C" es2panda_AstNode *NewArrayInstanceExpressionDimension(es2panda_AstNode *ast) +{ + auto *node = reinterpret_cast(ast)->AsETSNewArrayInstanceExpression(); + return reinterpret_cast(node->Dimension()); +} + +extern "C" es2panda_AstNode *CreateNewMultiDimArrayInstanceExpression(es2panda_Context *context, + es2panda_AstNode *type_reference, + es2panda_AstNode **dimensions, + size_t n_dimensions) +{ + auto *ctx = reinterpret_cast(context); + auto *allocator = ctx->allocator; + auto *ir_typeref = reinterpret_cast(type_reference)->AsExpression()->AsTypeNode(); + + ArenaVector ir_dims {allocator->Adapter()}; + for (size_t i = 0; i < n_dimensions; i++) { + // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) + ir_dims.push_back(reinterpret_cast(dimensions[i])->AsExpression()); + } + + return reinterpret_cast( + allocator->New(ir_typeref, std::move(ir_dims))); +} + +extern "C" es2panda_AstNode *NewMultiDimArrayInstanceExpressionTypeReference(es2panda_AstNode *ast) +{ + auto *node = reinterpret_cast(ast)->AsETSNewMultiDimArrayInstanceExpression(); + return reinterpret_cast(node->TypeReference()); +} + +extern "C" es2panda_AstNode *const *NewMultiDimArrayInstanceExpressionDimensions(es2panda_AstNode *ast, size_t *size_p) +{ + auto *node = reinterpret_cast(ast)->AsETSNewMultiDimArrayInstanceExpression(); + auto const &dims = node->Dimensions(); + + *size_p = dims.size(); + return reinterpret_cast(dims.data()); +} + +extern "C" es2panda_AstNode *CreateParameterDeclaration(es2panda_Context *context, + es2panda_AstNode *identifier_or_spread, + es2panda_AstNode *initializer) +{ + auto *ctx = reinterpret_cast(context); + auto *allocator = ctx->allocator; + + auto *ir_ident_or_spread_raw = reinterpret_cast(identifier_or_spread)->AsExpression(); + ir::AnnotatedExpression *ir_ident_or_spread; + if (ir_ident_or_spread_raw->IsIdentifier()) { + ir_ident_or_spread = ir_ident_or_spread_raw->AsIdentifier(); + } else if (ir_ident_or_spread_raw->IsSpreadElement()) { + ir_ident_or_spread = ir_ident_or_spread_raw->AsSpreadElement(); + } else { + UNREACHABLE(); + } + + auto *ir_initializer = + initializer == nullptr ? nullptr : reinterpret_cast(initializer)->AsExpression(); + + return reinterpret_cast( + allocator->New(ir_ident_or_spread, ir_initializer)); +} + +extern "C" es2panda_AstNode *ParameterDeclarationIdentifierOrSpread(es2panda_AstNode *ast) +{ + auto *node = reinterpret_cast(ast)->AsETSParameterExpression(); + + ir::AstNode *res; + if (node->IsRestParameter()) { + res = node->RestParameter(); + } else { + res = node->Ident(); + } + return reinterpret_cast(res); +} + +extern "C" es2panda_AstNode *ParameterDeclarationInitializer(es2panda_AstNode *ast) +{ + auto *node = reinterpret_cast(ast)->AsETSParameterExpression(); + return reinterpret_cast(node->Initializer()); +} + +struct PrimitiveTypeToStrStruct { + ir::PrimitiveType type; + char const *str; +}; + +static constexpr std::array PRIMITIVE_TYPE_TO_STR {{ + {ir::PrimitiveType::BYTE, "byte"}, + {ir::PrimitiveType::INT, "int"}, + {ir::PrimitiveType::LONG, "long"}, + {ir::PrimitiveType::SHORT, "short"}, + {ir::PrimitiveType::FLOAT, "float"}, + {ir::PrimitiveType::DOUBLE, "double"}, + {ir::PrimitiveType::BOOLEAN, "boolean"}, + {ir::PrimitiveType::CHAR, "char"}, + {ir::PrimitiveType::VOID, "void"}, +}}; + +static ir::PrimitiveType StrToPrimitiveType(char const *str) +{ + for (auto &elem : PRIMITIVE_TYPE_TO_STR) { + if (strcmp(elem.str, str) == 0) { + return elem.type; + } + } + return ir::PrimitiveType::VOID; +} + +static char const *PrimitiveTypeToStr(ir::PrimitiveType type) +{ + for (auto &elem : PRIMITIVE_TYPE_TO_STR) { + if (elem.type == type) { + return elem.str; + } + } + return "unknown"; +} + +extern "C" es2panda_AstNode *CreatePrimitiveTypeNode(es2panda_Context *context, char const *type) +{ + auto *ctx = reinterpret_cast(context); + auto *allocator = ctx->allocator; + auto tp = StrToPrimitiveType(type); + + return reinterpret_cast(allocator->New(tp)); +} + +extern "C" char const *PrimitiveTypeNodeType(es2panda_AstNode *ast) +{ + auto *node = reinterpret_cast(ast)->AsETSPrimitiveType(); + return PrimitiveTypeToStr(node->GetPrimitiveType()); +} + +extern "C" es2panda_AstNode *CreateReturnStatement(es2panda_Context *context, es2panda_AstNode *argument) +{ + auto *ctx = reinterpret_cast(context); + auto *allocator = ctx->allocator; + auto *ir_arg = argument == nullptr ? nullptr : reinterpret_cast(argument)->AsExpression(); + + return reinterpret_cast(allocator->New(ir_arg)); +} + +extern "C" es2panda_AstNode *ReturnStatementArgument(es2panda_AstNode *ast) +{ + auto *node = reinterpret_cast(ast)->AsReturnStatement(); + return reinterpret_cast(node->Argument()); +} + +extern "C" es2panda_Type *ReturnStatementReturnType(es2panda_AstNode *ast) +{ + auto *node = reinterpret_cast(ast)->AsReturnStatement(); + return reinterpret_cast(node->ReturnType()); +} + +extern "C" es2panda_AstNode *CreateScriptFunction(es2panda_Context *context, es2panda_AstNode *type_params, + es2panda_AstNode **params, size_t n_params, + es2panda_AstNode *return_type_annotation, + es2panda_ScriptFunctionFlags function_flags, + es2panda_ModifierFlags modifier_flags, bool is_declare, + es2panda_AstNode *in_scope_of) +{ + auto *ctx = reinterpret_cast(context); + auto *allocator = ctx->allocator; + auto *ir_type_params = + type_params == nullptr ? nullptr : reinterpret_cast(type_params)->AsTSTypeParameterDeclaration(); + + // NOTE(gogabr): without explicit reference to scope, scopes within params will be broken + ArenaVector ir_params {allocator->Adapter()}; + for (size_t i = 0; i < n_params; i++) { + // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) + ir_params.push_back(reinterpret_cast(params[i])->AsExpression()); + } + + auto ir_return_type_annotation = + return_type_annotation == nullptr + ? nullptr + : reinterpret_cast(return_type_annotation)->AsExpression()->AsTypeNode(); + auto ir_function_flags = E2pToIrScriptFunctionFlags(function_flags); + auto ir_modifier_flags = E2pToIrModifierFlags(modifier_flags); + + auto *outer_scope = ir_type_params == nullptr ? compiler::NearestScope(reinterpret_cast(in_scope_of)) + : ir_type_params->Scope(); + auto *parameter_scope = allocator->New(allocator, outer_scope); + auto *body_scope = allocator->New(allocator, parameter_scope); + parameter_scope->BindFunctionScope(body_scope); + body_scope->BindParamScope(parameter_scope); + + return reinterpret_cast(allocator->New( + body_scope, std::move(ir_params), ir_type_params, nullptr, ir_return_type_annotation, ir_function_flags, + ir_modifier_flags, is_declare, Language::FromString("ets").value())); +} + +extern "C" es2panda_AstNode *ScriptFunctionTypeParams(es2panda_AstNode *ast) +{ + auto *node = reinterpret_cast(ast)->AsScriptFunction(); + return reinterpret_cast(node->TypeParams()); +} + +extern "C" es2panda_AstNode *const *ScriptFunctionParams(es2panda_AstNode *ast, size_t *size_p) +{ + auto *node = reinterpret_cast(ast)->AsScriptFunction(); + auto ¶ms = node->Params(); + + *size_p = params.size(); + return reinterpret_cast(params.data()); +} + +extern "C" es2panda_AstNode *ScriptFunctionReturnTypeAnnotation(es2panda_AstNode *ast) +{ + auto *node = reinterpret_cast(ast)->AsScriptFunction(); + return reinterpret_cast(node->ReturnTypeAnnotation()); +} + +extern "C" es2panda_ScriptFunctionFlags ScriptFunctionScriptFunctionFlags(es2panda_AstNode *ast) +{ + auto *node = reinterpret_cast(ast)->AsScriptFunction(); + return IrToE2pScriptFunctionFlags(node->Flags()); +} + +extern "C" bool ScriptFunctionIsDeclare(es2panda_AstNode *ast) +{ + auto *node = reinterpret_cast(ast)->AsScriptFunction(); + return node->Declare(); +} + +extern "C" es2panda_AstNode *ScriptFunctionIdentifier(es2panda_AstNode *ast) +{ + auto *node = reinterpret_cast(ast)->AsScriptFunction(); + return reinterpret_cast(node->Id()); +} + +extern "C" es2panda_AstNode *ScriptFunctionBody(es2panda_AstNode *ast) +{ + auto *node = reinterpret_cast(ast)->AsScriptFunction(); + return reinterpret_cast(node->Body()); +} + +extern "C" void ScriptFunctionSetIdentifier(es2panda_AstNode *ast, es2panda_AstNode *identifier) +{ + auto *node = reinterpret_cast(ast)->AsScriptFunction(); + auto *id = reinterpret_cast(identifier)->AsIdentifier(); + + node->SetIdent(id); +} + +extern "C" void ScriptFunctionSetBody(es2panda_AstNode *ast, es2panda_AstNode *body) +{ + auto *node = reinterpret_cast(ast)->AsScriptFunction(); + auto *ir_body = reinterpret_cast(body); + + node->SetBody(ir_body); +} + +extern "C" void ScriptFunctionSetParams(es2panda_AstNode *ast, es2panda_AstNode **params, size_t n_params) +{ + auto *node = reinterpret_cast(ast)->AsScriptFunction(); + auto &ir_params = node->Params(); + + ir_params.clear(); + for (size_t i = 0; i < n_params; i++) { + // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) + ir_params.push_back(reinterpret_cast(params[i])->AsExpression()); + } +} + +extern "C" void ScripFunctionAddParam(es2panda_AstNode *ast, es2panda_AstNode *param) +{ + auto *node = reinterpret_cast(ast)->AsScriptFunction(); + auto *ir_param = reinterpret_cast(param)->AsExpression(); + + node->Params().push_back(ir_param); +} + +extern "C" es2panda_AstNode *CreateStringLiteral(es2panda_Context *context, char const *string) +{ + auto *ctx = reinterpret_cast(context); + auto *allocator = ctx->allocator; + auto *str = ArenaStrdup(allocator, string); + + return reinterpret_cast(allocator->New(str)); +} + +extern "C" char const *StringLiteralString(es2panda_Context *context, es2panda_AstNode *ast) +{ + auto *ctx = reinterpret_cast(context); + auto *allocator = ctx->allocator; + auto *node = reinterpret_cast(ast)->AsStringLiteral(); + return StringViewToCString(allocator, node->Str()); +} + +extern "C" es2panda_AstNode *CreateThisExpression(es2panda_Context *context) +{ + auto *ctx = reinterpret_cast(context); + auto *allocator = ctx->allocator; + + return reinterpret_cast(allocator->New()); +} + +extern "C" es2panda_AstNode *CreateTypeParameter(es2panda_Context *context, es2panda_AstNode *name, + es2panda_AstNode *constraint, es2panda_AstNode *default_type) +{ + auto *ctx = reinterpret_cast(context); + auto *allocator = ctx->allocator; + auto *nm = reinterpret_cast(name)->AsIdentifier(); + auto *constr = + constraint == nullptr ? nullptr : reinterpret_cast(constraint)->AsExpression()->AsTypeNode(); + auto *dflt = + default_type == nullptr ? nullptr : reinterpret_cast(default_type)->AsExpression()->AsTypeNode(); + + return reinterpret_cast(allocator->New(nm, constr, dflt)); +} + +extern "C" es2panda_AstNode const *TypeParameterName(es2panda_AstNode *ast) +{ + auto *tp = reinterpret_cast(ast)->AsTSTypeParameter(); + return reinterpret_cast(tp->Name()); +} + +extern "C" es2panda_AstNode const *TypeParameterConstraint(es2panda_AstNode *ast) +{ + auto *tp = reinterpret_cast(ast)->AsTSTypeParameter(); + return reinterpret_cast(tp->Constraint()); +} + +extern "C" es2panda_AstNode const *TypeParameterDefaultType(es2panda_AstNode *ast) +{ + auto *tp = reinterpret_cast(ast)->AsTSTypeParameter(); + return reinterpret_cast(tp->DefaultType()); +} + +extern "C" es2panda_AstNode *CreateTypeParameterDeclaration(es2panda_Context *context, es2panda_AstNode *in_scope_of) +{ + auto *ctx = reinterpret_cast(context); + auto *allocator = ctx->allocator; + auto *parent = reinterpret_cast(in_scope_of); + auto *parent_scope = compiler::NearestScope(parent); + + auto *scope = allocator->New(allocator, parent_scope); + ArenaVector params {allocator->Adapter()}; + return reinterpret_cast( + allocator->New(scope, std::move(params), 0)); +} + +extern "C" void TypeParameterDeclarationAddTypeParameter(es2panda_AstNode *ast, es2panda_AstNode *type_parameter) +{ + auto *tpd = reinterpret_cast(ast)->AsTSTypeParameterDeclaration(); + auto *param = reinterpret_cast(type_parameter)->AsTSTypeParameter(); + + tpd->AddParam(param); +} + +extern "C" es2panda_AstNode *const *TypeParameterDeclarationTypeParameters(es2panda_AstNode *ast, size_t *size_p) +{ + auto *tpd = reinterpret_cast(ast)->AsTSTypeParameterDeclaration(); + auto const ¶ms = tpd->Params(); + *size_p = params.size(); + return reinterpret_cast(params.data()); +} + +extern "C" es2panda_AstNode *CreateTypeParameterInstantiation(es2panda_Context *context, + es2panda_AstNode **type_parameters, size_t n_params) +{ + auto *ctx = reinterpret_cast(context); + auto *allocator = ctx->allocator; + + ArenaVector params {allocator->Adapter()}; + for (size_t i = 0; i < n_params; i++) { + // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) + params.push_back(reinterpret_cast(type_parameters[i])->AsExpression()->AsTypeNode()); + } + return reinterpret_cast(allocator->New(std::move(params))); +} + +extern "C" es2panda_AstNode *const *TypeParameterInstantiationTypeParameters(es2panda_AstNode *ast, size_t *size_p) +{ + auto *tpi = reinterpret_cast(ast)->AsTSTypeParameterInstantiation(); + auto const ¶ms = tpi->Params(); + *size_p = params.size(); + return reinterpret_cast(params.data()); +} + +extern "C" es2panda_AstNode *CreateTypeReferenceNode(es2panda_Context *context, es2panda_AstNode *part) +{ + auto *ctx = reinterpret_cast(context); + auto *allocator = ctx->allocator; + auto *ir_part = reinterpret_cast(part)->AsETSTypeReferencePart(); + + return reinterpret_cast(allocator->New(ir_part)); +} + +extern "C" es2panda_AstNode *TypeReferenceNodePart(es2panda_AstNode *ast) +{ + auto *node = reinterpret_cast(ast)->AsETSTypeReference(); + return reinterpret_cast(node->Part()); +} + +extern "C" es2panda_AstNode *CreateTypeReferencePart(es2panda_Context *context, es2panda_AstNode *name, + es2panda_AstNode *type_arguments, es2panda_AstNode *previous) +{ + auto *ctx = reinterpret_cast(context); + auto *allocator = ctx->allocator; + auto *ir_name = reinterpret_cast(name)->AsExpression(); + auto *ir_type_args = type_arguments == nullptr + ? nullptr + : reinterpret_cast(type_arguments)->AsTSTypeParameterInstantiation(); + auto *ir_prev = previous == nullptr ? nullptr : reinterpret_cast(previous)->AsETSTypeReferencePart(); + + return reinterpret_cast( + allocator->New(ir_name, ir_type_args, ir_prev)); +} + +extern "C" es2panda_AstNode *TypeReferencePartName(es2panda_AstNode *ast) +{ + auto *node = reinterpret_cast(ast)->AsETSTypeReferencePart(); + return reinterpret_cast(node->Name()); +} + +extern "C" es2panda_AstNode *TypeReferencePartTypeArguments(es2panda_AstNode *ast) +{ + auto *node = reinterpret_cast(ast)->AsETSTypeReferencePart(); + return reinterpret_cast(node->TypeParams()); +} + +extern "C" es2panda_AstNode *TypeReferencePartPrevious(es2panda_AstNode *ast) +{ + auto *node = reinterpret_cast(ast)->AsETSTypeReferencePart(); + return reinterpret_cast(node->Previous()); +} + +extern "C" es2panda_AstNode *CreateUnionTypeNode(es2panda_Context *context, es2panda_AstNode **types, size_t n_types) +{ + auto *ctx = reinterpret_cast(context); + auto *allocator = ctx->allocator; + + ArenaVector ir_types {allocator->Adapter()}; + for (size_t i = 0; i < n_types; i++) { + // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) + ir_types.push_back(reinterpret_cast(types[i])->AsExpression()->AsTypeNode()); + } + + return reinterpret_cast(allocator->New(std::move(ir_types))); +} + +extern "C" es2panda_AstNode *const *UnionTypeNodeTypes(es2panda_AstNode *ast, size_t *size_p) +{ + auto *node = reinterpret_cast(ast)->AsTSUnionType(); + auto &ir_types = node->Types(); + + *size_p = ir_types.size(); + return reinterpret_cast(ir_types.data()); +} + +struct VariableDeclarationKindToStrStruct { + ir::VariableDeclaration::VariableDeclarationKind kind; + char const *str; +}; + +static constexpr std::array VARIABLE_DECLARATION_KIND_TO_STR {{ + {ir::VariableDeclaration::VariableDeclarationKind::CONST, "const"}, + {ir::VariableDeclaration::VariableDeclarationKind::LET, "let"}, + {ir::VariableDeclaration::VariableDeclarationKind::VAR, "var"}, +}}; + +static ir::VariableDeclaration::VariableDeclarationKind StrToVariableDeclarationKind(char const *str) +{ + for (auto &elem : VARIABLE_DECLARATION_KIND_TO_STR) { + if (strcmp(elem.str, str) == 0) { + return elem.kind; + } + } + + // NOTE(gogabr): handle errors + UNREACHABLE(); +} + +static char const *VariableDeclarationKindToStr(ir::VariableDeclaration::VariableDeclarationKind kind) +{ + for (auto &elem : VARIABLE_DECLARATION_KIND_TO_STR) { + if (elem.kind == kind) { + return elem.str; + } + } + return "unknown"; +} + +extern "C" es2panda_AstNode *CreateVariableDeclaration(es2panda_Context *context, char const *kind, + es2panda_AstNode **declarators, size_t n_declarators, + bool is_declare) +{ + auto *ctx = reinterpret_cast(context); + auto *allocator = ctx->allocator; + auto ir_kind = StrToVariableDeclarationKind(kind); + + ArenaVector ir_declarators {allocator->Adapter()}; + for (size_t i = 0; i < n_declarators; i++) { + // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) + ir_declarators.push_back(reinterpret_cast(declarators[i])->AsVariableDeclarator()); + } + + return reinterpret_cast( + allocator->New(ir_kind, allocator, std::move(ir_declarators), is_declare)); +} + +extern "C" char const *VariableDeclarationKind(es2panda_AstNode *ast) +{ + auto *node = reinterpret_cast(ast)->AsVariableDeclaration(); + return VariableDeclarationKindToStr(node->Kind()); +} + +extern "C" es2panda_AstNode *const *VariableDeclarationDeclarators(es2panda_AstNode *ast, size_t *size_p) +{ + auto *node = reinterpret_cast(ast)->AsVariableDeclaration(); + auto const &declarators = node->Declarators(); + *size_p = declarators.size(); + return reinterpret_cast(declarators.data()); +} + +extern "C" bool VariableDeclarationIsDeclare(es2panda_AstNode *ast) +{ + auto *node = reinterpret_cast(ast)->AsVariableDeclaration(); + return node->Declare(); +} + +extern "C" es2panda_AstNode *CreateVariableDeclarator(es2panda_Context *context, es2panda_AstNode *identifier, + es2panda_AstNode *initializer) +{ + auto *ctx = reinterpret_cast(context); + auto *allocator = ctx->allocator; + auto *ident = reinterpret_cast(identifier)->AsExpression(); + auto *init = initializer == nullptr ? nullptr : reinterpret_cast(initializer)->AsExpression(); + + return reinterpret_cast(allocator->New(ident, init)); +} + +extern "C" es2panda_AstNode *VariableDeclaratorIdentifier(es2panda_AstNode *ast) +{ + auto *node = reinterpret_cast(ast)->AsVariableDeclarator(); + return reinterpret_cast(node->Id()); +} + +extern "C" es2panda_AstNode *VariableDeclaratorInitializer(es2panda_AstNode *ast) +{ + auto *node = reinterpret_cast(ast)->AsVariableDeclarator(); + return reinterpret_cast(node->Init()); +} + +es2panda_Impl IMPL = { + ES2PANDA_LIB_VERSION, + + CreateConfig, + DestroyConfig, + + CreateContextFromFile, + CreateContextFromString, + ProceedToState, + DestroyContext, + + ContextState, + ContextErrorMessage, + + ContextProgram, + ProgramAst, + ProgramExternalSources, + ExternalSourceName, + ExternalSourcePrograms, + + AstNodeType, + AstNodeSetType, + + AstNodeDecorators, + AstNodeSetDecorators, + + AstNodeModifierFlags, + + AstNodeForEach, + + IsArrowFunctionExpression, + CreateArrowFunctionExpression, + ArrowFunctionExpressionScriptFunction, + + IsAsExpression, + CreateAsExpression, + AsExpressionExpr, + AsExpressionTypeAnnotation, + AsExpressionIsConst, + AsExpressionSetExpr, + AsExpressionSetTypeAnnotation, + + IsAssignmentExpression, + CreateAssignmentExpression, + AssignmentExpressionLeft, + AssignmentExpressionRight, + AssignmentExpressionOperatorType, + AssignmentExpressionSetOperatorType, + + IsBinaryExpression, + CreateBinaryExpression, + BinaryExpressionLeft, + BinaryExpressionRight, + BinaryExpressionOperator, + BinaryExpressionSetOperator, + + IsBlockStatement, + CreateBlockStatement, + BlockStatementStatements, + BlockStatementAddStatement, + + IsCallExpression, + CreateCallExpression, + CallExpressionCallee, + CallExpressionTypeArguments, + CallExpressionArguments, + CallExpressionIsOptional, + CallExpressionSetTypeArguments, + + IsChainExpression, + CreateChainExpression, + ChainExpressionChild, + + IsClassDeclaration, + CreateClassDeclaration, + ClassDeclarationDefinition, + + IsClassDefinition, + CreateClassDefinition, + ClassDefinitionIdentifier, + ClassDefinitionTypeParameters, + ClassDefinitionSuperClass, + ClassDefinitionImplements, + ClassDefinitionConstructor, + ClassDefinitionBody, + ClassDefinitionSetIdentifier, + ClassDefinitionSetTypeParameters, + ClassDefinitionSetSuperClass, + ClassDefinitionSetImplements, + ClassDefinitionAddImplements, + ClassDefinitionSetConstructor, + ClassDefinitionSetBody, + ClassDefinitionAddToBody, + + ClassElementKey, + ClassElementValue, + + IsClassImplementsClause, + CreateClassImplementsClause, + ClassImplementsClauseExpression, + ClassImplementsClauseTypeArguments, + + IsClassProperty, + CreateClassProperty, + ClassPropertyTypeAnnotation, + + IsExpressionStatement, + CreateExpressionStatement, + ExpressionStatementExpression, + + IsFunctionDeclaration, + CreateFunctionDeclaration, + FunctionDeclarationFunction, + + IsFunctionExpression, + CreateFunctionExpression, + FunctionExpressionFunction, + + IsFunctionTypeNode, + CreateFunctionTypeNode, + FunctionTypeNodeTypeParams, + FunctionTypeNodeParams, + FunctionTypeNodeReturnType, + FunctionTypeNodeFlags, + + IsIdentifier, + CreateIdentifier, + IdentifierName, + IdentifierTypeAnnotation, + IdentifierVariable, + IdentifierSetVariable, + + IsIfStatement, + CreateIfStatement, + IfStatementTest, + IfStatementConsequent, + IfStatementAlternate, + + IsImportDeclaration, + CreateImportDeclaration, + ImportDeclarationSource, + ImportDeclarationSpecifiers, + + IsImportExpression, + CreateImportExpression, + ImportExpressionSource, + + IsImportSpecifier, + CreateImportSpecifier, + ImportSpecifierImported, + ImportSpecifierLocal, + + IsMemberExpression, + CreateMemberExpression, + MemberExpressionObject, + MemberExpressionProperty, + MemberExpressionKind, + MemberExpressionIsComputed, + MemberExpressionIsOptional, + + IsMethodDefinition, + CreateMethodDefinition, + MethodDefinitionKind, + MethodDefinitionKey, + MethodDefinitionValue, + MethodDefinitionModifiers, + MethodDefinitionIsComputed, + MethodDefinitionOverloads, + MethodDefinitionSetOverloads, + MethodDefinitionAddOverload, + + IsNewClassInstanceExpression, + CreateNewClassInstanceExpression, + NewClassInstanceExpressionTypeReference, + NewClassInstanceExpressionArguments, + NewClassInstanceExpressionClassDefinition, + + IsNewArrayInstanceExpression, + CreateNewArrayInstanceExpression, + NewArrayInstanceExpressionTypeReference, + NewArrayInstanceExpressionDimension, + + IsNewMultiDimArrayInstanceExpression, + CreateNewMultiDimArrayInstanceExpression, + NewMultiDimArrayInstanceExpressionTypeReference, + NewMultiDimArrayInstanceExpressionDimensions, + + IsNonNullExpression, + IsNumberLiteral, + IsObjectExpression, + + IsParameterDeclaration, + CreateParameterDeclaration, + ParameterDeclarationIdentifierOrSpread, + ParameterDeclarationInitializer, + + IsPrimitiveTypeNode, + CreatePrimitiveTypeNode, + PrimitiveTypeNodeType, + + IsReturnStatement, + CreateReturnStatement, + ReturnStatementArgument, + ReturnStatementReturnType, + + IsScriptFunction, + CreateScriptFunction, + ScriptFunctionTypeParams, + ScriptFunctionParams, + ScriptFunctionReturnTypeAnnotation, + ScriptFunctionScriptFunctionFlags, + ScriptFunctionIsDeclare, + ScriptFunctionIdentifier, + ScriptFunctionBody, + ScriptFunctionSetIdentifier, + ScriptFunctionSetBody, + ScriptFunctionSetParams, + ScripFunctionAddParam, + + IsStringLiteral, + CreateStringLiteral, + StringLiteralString, + + IsThisExpression, + CreateThisExpression, + + IsTypeParameter, + CreateTypeParameter, + TypeParameterName, + TypeParameterConstraint, + TypeParameterDefaultType, + + IsTypeParameterDeclaration, + CreateTypeParameterDeclaration, + TypeParameterDeclarationAddTypeParameter, + TypeParameterDeclarationTypeParameters, + + IsTypeParameterInstantiation, + CreateTypeParameterInstantiation, + TypeParameterInstantiationTypeParameters, + + IsTypeReferenceNode, + CreateTypeReferenceNode, + TypeReferenceNodePart, + + IsTypeReferencePart, + CreateTypeReferencePart, + TypeReferencePartName, + TypeReferencePartTypeArguments, + TypeReferencePartPrevious, + + IsUnionTypeNode, + CreateUnionTypeNode, + UnionTypeNodeTypes, + + IsVariableDeclaration, + CreateVariableDeclaration, + VariableDeclarationKind, + VariableDeclarationDeclarators, + VariableDeclarationIsDeclare, + + IsVariableDeclarator, + CreateVariableDeclarator, + VariableDeclaratorIdentifier, + VariableDeclaratorInitializer, +}; } // namespace panda::es2panda::public_lib diff --git a/ets2panda/public/es2panda_lib.h b/ets2panda/public/es2panda_lib.h index d20aee7772e0c1f5f4cc3047186ae80618a76845..f61653f4653bc0a058a0ccf11a7d02cfa6b48aca 100644 --- a/ets2panda/public/es2panda_lib.h +++ b/ets2panda/public/es2panda_lib.h @@ -16,17 +16,27 @@ #ifndef ES2PANDA_LIB #define ES2PANDA_LIB +// Switch off the linter for C header +// NOLINTBEGIN + +#include +#include + #ifdef __cplusplus extern "C" { #endif -// Switch off the linter for C header -// NOLINTBEGIN +#define ES2PANDA_LIB_VERSION 1 -#define ES2PANDA_LIB_VERSION 0 +typedef struct es2panda_Config es2panda_Config; +typedef struct es2panda_Context es2panda_Context; -typedef void es2panda_Config; -typedef void es2panda_Context; +typedef struct es2panda_Program es2panda_Program; +typedef struct es2panda_ExternalSource es2panda_ExternalSource; +typedef struct es2panda_AstNode es2panda_AstNode; +typedef struct es2panda_Type es2panda_Type; +typedef struct es2panda_Variable es2panda_Variable; +typedef struct es2panda_Scope es2panda_Scope; enum es2panda_ContextState { ES2PANDA_STATE_NEW, @@ -40,6 +50,74 @@ enum es2panda_ContextState { }; typedef enum es2panda_ContextState es2panda_ContextState; +// NB: has to be synchronized with astNode.h +enum es2panda_ModifierFlags { + ES2PANDA_MODIFIER_NONE = 0U, + ES2PANDA_MODIFIER_STATIC = 1U << 0U, + ES2PANDA_MODIFIER_ASYNC = 1U << 1U, + ES2PANDA_MODIFIER_PUBLIC = 1U << 2U, + ES2PANDA_MODIFIER_PROTECTED = 1U << 3U, + ES2PANDA_MODIFIER_PRIVATE = 1U << 4U, + ES2PANDA_MODIFIER_DECLARE = 1U << 5U, + ES2PANDA_MODIFIER_READONLY = 1U << 6U, + ES2PANDA_MODIFIER_OPTIONAL = 1U << 7U, + ES2PANDA_MODIFIER_DEFINITE = 1U << 8U, + ES2PANDA_MODIFIER_ABSTRACT = 1U << 9U, + ES2PANDA_MODIFIER_CONST = 1U << 10U, + ES2PANDA_MODIFIER_FINAL = 1U << 11U, + ES2PANDA_MODIFIER_NATIVE = 1U << 12U, + ES2PANDA_MODIFIER_OVERRIDE = 1U << 13U, + ES2PANDA_MODIFIER_CONSTRUCTOR = 1U << 14U, + ES2PANDA_MODIFIER_SYNCHRONIZED = 1U << 15U, + ES2PANDA_MODIFIER_FUNCTIONAL = 1U << 16U, + ES2PANDA_MODIFIER_IN = 1U << 17U, + ES2PANDA_MODIFIER_OUT = 1U << 18U, + ES2PANDA_MODIFIER_INTERNAL = 1U << 19U, + ES2PANDA_MODIFIER_NULL_ASSIGNABLE = 1U << 20U, + ES2PANDA_MODIFIER_UNDEFINED_ASSIGNABLE = 1U << 21U, + ES2PANDA_MODIFIER_EXPORT = 1U << 22U, + ES2PANDA_MODIFIER_SETTER = 1U << 23U, + ES2PANDA_MODIFIER_DEFAULT_EXPORT = 1U << 24U, +}; +typedef enum es2panda_ModifierFlags es2panda_ModifierFlags; + +// Has to be synchronized with astNode.h +enum es2panda_ScriptFunctionFlags { + ES2PANDA_SCRIPT_FUNCTION_NONE = 0, + ES2PANDA_SCRIPT_FUNCTION_GENERATOR = 1U << 0U, + ES2PANDA_SCRIPT_FUNCTION_ASYNC = 1U << 1U, + ES2PANDA_SCRIPT_FUNCTION_ARROW = 1U << 2U, + ES2PANDA_SCRIPT_FUNCTION_EXPRESSION = 1U << 3U, + ES2PANDA_SCRIPT_FUNCTION_OVERLOAD = 1U << 4U, + ES2PANDA_SCRIPT_FUNCTION_CONSTRUCTOR = 1U << 5U, + ES2PANDA_SCRIPT_FUNCTION_METHOD = 1U << 6U, + ES2PANDA_SCRIPT_FUNCTION_STATIC_BLOCK = 1U << 7U, + ES2PANDA_SCRIPT_FUNCTION_HIDDEN = 1U << 8U, + ES2PANDA_SCRIPT_FUNCTION_IMPLICIT_SUPER_CALL_NEEDED = 1U << 9U, + ES2PANDA_SCRIPT_FUNCTION_ENUM = 1U << 10U, + ES2PANDA_SCRIPT_FUNCTION_EXTERNAL = 1U << 11U, + ES2PANDA_SCRIPT_FUNCTION_PROXY = 1U << 12U, + ES2PANDA_SCRIPT_FUNCTION_THROWS = 1U << 13U, + ES2PANDA_SCRIPT_FUNCTION_RETHROWS = 1U << 14U, + ES2PANDA_SCRIPT_FUNCTION_GETTER = 1U << 15U, + ES2PANDA_SCRIPT_FUNCTION_SETTER = 1U << 16U, + ES2PANDA_SCRIPT_FUNCTION_DEFAULT_PARAM_PROXY = 1U << 17U, + ES2PANDA_SCRIPT_FUNCTION_ENTRY_POINT = 1U << 18U, + ES2PANDA_SCRIPT_FUNCTION_INSTANCE_EXTENSION_METHOD = 1U << 19U, + ES2PANDA_SCRIPT_FUNCTION_HAS_RETURN = 1U << 20U +}; +typedef enum es2panda_ScriptFunctionFlags es2panda_ScriptFunctionFlags; + +// Needs to be synchronized with memberExpression.h +enum es2panda_MemberExpressionKind { + ES2PANDA_MEMBER_EXPRESSION_KIND_NONE = 0, + ES2PANDA_MEMBER_EXPRESSION_KIND_ELEMENT_ACCESS = 1U << 0U, + ES2PANDA_MEMBER_EXPRESSION_KIND_PROPERTY_ACCESS = 1U << 1U, + ES2PANDA_MEMBER_EXPRESSION_KIND_GETTER = 1U << 2U, + ES2PANDA_MEMBER_EXPRESSION_KIND_SETTER = 1U << 3U +}; +typedef enum es2panda_MemberExpressionKind es2panda_MemberExpressionKind; + struct es2panda_Impl { int version; @@ -53,6 +131,296 @@ struct es2panda_Impl { es2panda_ContextState (*ContextState)(es2panda_Context *context); char const *(*ContextErrorMessage)(es2panda_Context *context); + + es2panda_Program *(*ContextProgram)(es2panda_Context *context); + es2panda_AstNode *(*ProgramAst)(es2panda_Program *program); + es2panda_ExternalSource **(*ProgramExternalSources)(es2panda_Program *program, size_t *len_p); + char const *(*ExternalSourceName)(es2panda_ExternalSource *e_source); + es2panda_Program **(*ExternalSourcePrograms)(es2panda_ExternalSource *e_source, size_t *len_p); + + es2panda_Type *(*AstNodeType)(es2panda_AstNode *ast); + void (*AstNodeSetType)(es2panda_AstNode *ast, es2panda_Type *type); + + es2panda_AstNode *const *(*AstNodeDecorators)(es2panda_AstNode *ast, size_t *size_p); + void (*AstNodeSetDecorators)(es2panda_Context *context, es2panda_AstNode *ast, es2panda_AstNode **decorators, + size_t n_decorators); + + es2panda_ModifierFlags (*AstNodeModifierFlags)(es2panda_AstNode *ast); + + void (*AstNodeForEach)(es2panda_AstNode *ast, void (*func)(es2panda_AstNode *, void *), void *arg); + + bool (*IsArrowFunctionExpression)(es2panda_AstNode *ast); + es2panda_AstNode *(*CreateArrowFunctionExpression)(es2panda_Context *context, es2panda_AstNode *script_function); + es2panda_AstNode *(*ArrowFunctionExpressionScriptFunction)(es2panda_AstNode *ast); + + bool (*IsAsExpression)(es2panda_AstNode *ast); + es2panda_AstNode *(*CreateAsExpression)(es2panda_Context *context, es2panda_AstNode *expr, + es2panda_AstNode *type_annotation, bool is_const); + es2panda_AstNode *(*AsExpressionExpr)(es2panda_AstNode *ast); + es2panda_AstNode *(*AsExpressionTypeAnnotation)(es2panda_AstNode *ast); + bool (*AsExpressionIsConst)(es2panda_AstNode *ast); + void (*AsExpressionSetExpr)(es2panda_AstNode *ast, es2panda_AstNode *expr); + void (*AsExpressionSetTypeAnnotation)(es2panda_AstNode *ast, es2panda_AstNode *type_annotation); + + bool (*IsAssignmentExpression)(es2panda_AstNode *ast); + es2panda_AstNode *(*CreateAssignmentExpression)(es2panda_Context *context, es2panda_AstNode *left, + es2panda_AstNode *right, char const *operator_type); + es2panda_AstNode *(*AssignmentExpressionLeft)(es2panda_AstNode *ast); + es2panda_AstNode *(*AssignmentExpressionRight)(es2panda_AstNode *ast); + char const *(*AssignmentExpressionOperatorType)(es2panda_AstNode *ast); + void (*AssignmentExpressionSetOperatorType)(es2panda_AstNode *ast, char const *operator_type); + + bool (*IsBinaryExpression)(es2panda_AstNode *ast); + es2panda_AstNode *(*CreatebinaryExpression)(es2panda_Context *context, es2panda_AstNode *left, + es2panda_AstNode *right, char const *operator_type); + es2panda_AstNode *(*BinaryExpressionLeft)(es2panda_AstNode *ast); + es2panda_AstNode *(*BinaryExpressionRight)(es2panda_AstNode *ast); + char const *(*BinaryExpressionOperator)(es2panda_AstNode *ast); + void (*BinaryExpressionSetOperator)(es2panda_AstNode *ast, char const *operator_type); + + bool (*IsBlockStatement)(es2panda_AstNode *ast); + es2panda_AstNode *(*CreateBlockStatement)(es2panda_Context *context, es2panda_AstNode *in_scope_of); + es2panda_AstNode **(*BlockStatementStatements)(es2panda_AstNode *ast, size_t *size_p); + void (*BlockStatementAddStatement)(es2panda_AstNode *ast, es2panda_AstNode *statement); + + bool (*IsCallExpression)(es2panda_AstNode *ast); + es2panda_AstNode *(*CreateCallExpression)(es2panda_Context *context, es2panda_AstNode *callee, + es2panda_AstNode *type_arguments, es2panda_AstNode **arguments, + size_t n_arguments, bool optional); + es2panda_AstNode const *(*CallExpressionCallee)(es2panda_AstNode *ast); + es2panda_AstNode const *(*CallExpressionTypeArguments)(es2panda_AstNode *ast); + es2panda_AstNode **(*CallExpressionArguments)(es2panda_AstNode *ast, size_t *size_p); + bool (*CallExpressionIsOptional)(es2panda_AstNode *ast); + void (*CallExpressionSetTypeArguments)(es2panda_AstNode *ast, es2panda_AstNode *type_arguments); + + bool (*IsChainExpression)(es2panda_AstNode *ast); + es2panda_AstNode *(*CreateChainExpression)(es2panda_Context *context, es2panda_AstNode *child); + es2panda_AstNode const *(*ChainExpressionChild)(es2panda_AstNode *ast); + + bool (*IsClassDeclaration)(es2panda_AstNode *ast); + es2panda_AstNode *(*CreateClassDeclaration)(es2panda_Context *context, es2panda_AstNode *definition); + es2panda_AstNode *(*ClassDeclarationDefinition)(es2panda_AstNode *ast); + + bool (*IsClassDefinition)(es2panda_AstNode *ast); + es2panda_AstNode *(*CreateClassDefinition)(es2panda_Context *context, es2panda_AstNode *in_scope_of, + es2panda_AstNode *identifier, es2panda_ModifierFlags flags); + es2panda_AstNode *(*ClassDefinitionIdentifier)(es2panda_AstNode *ast); + es2panda_AstNode *(*ClassDefinitionTypeParameters)(es2panda_AstNode *ast); + es2panda_AstNode *(*ClassDefinitionSuperClass)(es2panda_AstNode *ast); + es2panda_AstNode **(*ClassDefinitionImplements)(es2panda_AstNode *ast, size_t *size_p); + es2panda_AstNode *(*ClassDefinitionConstructor)(es2panda_AstNode *ast); + es2panda_AstNode **(*ClassDefinitionBody)(es2panda_AstNode *ast, size_t *size_p); + void (*ClassDefinitionSetIdentifier)(es2panda_AstNode *ast, es2panda_AstNode *identifier); + void (*ClassDefinitionSetTypeParameters)(es2panda_AstNode *ast, es2panda_AstNode *type_params); + void (*ClassDefinitionSetSuperClass)(es2panda_AstNode *ast, es2panda_AstNode *super_class); + void (*ClassDefinitionSetImplements)(es2panda_AstNode *ast, es2panda_AstNode **implements, size_t n_implements); + void (*ClassDefinitionAddImplements)(es2panda_AstNode *ast, es2panda_AstNode *implements); + void (*ClassDefinitionSetConstructor)(es2panda_AstNode *ast, es2panda_AstNode *constructor); + void (*ClassDefinitonSetBody)(es2panda_AstNode *ast, es2panda_AstNode **body, size_t n_elems); + void (*ClassDefinitonAddToBody)(es2panda_AstNode *ast, es2panda_AstNode *statement); + + es2panda_AstNode *(*ClassElementKey)(es2panda_AstNode *ast); + es2panda_AstNode *(*ClassElementValue)(es2panda_AstNode *ast); + + bool (*IsClassImplementsClause)(es2panda_AstNode *ast); + es2panda_AstNode *(*CreateClassImplementsClause)(es2panda_Context *context, es2panda_AstNode *expression, + es2panda_AstNode *type_arguments); + es2panda_AstNode *(*ClassImplementsClauseExpression)(es2panda_AstNode *ast); + es2panda_AstNode const *(*ClassImplementsClauseTypeArguments)(es2panda_AstNode *ast); + + bool (*IsClassProperty)(es2panda_AstNode *ast); + es2panda_AstNode *(*CreateClassProperty)(es2panda_Context *context, es2panda_AstNode *key, es2panda_AstNode *value, + es2panda_AstNode *type_annotation, es2panda_ModifierFlags modifier_flags, + bool is_computed); + es2panda_AstNode *(*ClassPropertyTypeAnnotation)(es2panda_AstNode *ast); + + bool (*IsExpressionStatement)(es2panda_AstNode *ast); + es2panda_AstNode *(*CreateExpressionStatement)(es2panda_Context *context, es2panda_AstNode *expression); + es2panda_AstNode *(*ExpressionStatementExpression)(es2panda_AstNode *ast); + + bool (*IsFunctionDeclaration)(es2panda_AstNode *ast); + es2panda_AstNode *(*CreateFunctionDeclaration)(es2panda_Context *context, es2panda_AstNode *function); + es2panda_AstNode *(*FunctionDeclarationFunction)(es2panda_AstNode *ast); + + bool (*IsFunctionExpression)(es2panda_AstNode *ast); + es2panda_AstNode *(*CreateFunctionExpression)(es2panda_Context *context, es2panda_AstNode *function); + es2panda_AstNode *(*FunctionExpressionFunction)(es2panda_AstNode *ast); + + bool (*IsFunctionTypeNode)(es2panda_AstNode *ast); + es2panda_AstNode *(*CreateFunctionTypeNode)(es2panda_Context *context, es2panda_AstNode *in_scope_of, + es2panda_AstNode *type_params, es2panda_AstNode **params, + size_t n_params, es2panda_AstNode *return_type, + es2panda_ScriptFunctionFlags func_flags); + es2panda_AstNode const *(*FunctionTypeNodeTypeParams)(es2panda_AstNode *ast); + es2panda_AstNode *const *(*FunctionTypeNodeParams)(es2panda_AstNode *ast, size_t *size_p); + es2panda_AstNode *(*FunctionTypeNodeReturnType)(es2panda_AstNode *ast); + es2panda_ScriptFunctionFlags (*FunctionTypeNodeFlags)(es2panda_AstNode *ast); + + bool (*IsIdentifier)(es2panda_AstNode *ast); + es2panda_AstNode *(*CreateIdentifier)(es2panda_Context *context, char const *name, + es2panda_AstNode *type_annotation); + char const *(*IdentifierName)(es2panda_Context *context, es2panda_AstNode *identifier); + es2panda_AstNode *(*IdentifierTypeAnnotation)(es2panda_AstNode *identifier); + es2panda_Variable *(*IdentifierVariable)(es2panda_AstNode *identifier); + void (*IdentifierSetVariable)(es2panda_AstNode *identifier, es2panda_Variable *variable); + + bool (*IsIfStatement)(es2panda_AstNode *ast); + es2panda_AstNode *(*CreateIfStatement)(es2panda_Context *context, es2panda_AstNode *test, + es2panda_AstNode *consequent, es2panda_AstNode *alternate); + es2panda_AstNode const *(*IfStatementTest)(es2panda_AstNode *ast); + es2panda_AstNode const *(*IfStatementConsequent)(es2panda_AstNode *ast); + es2panda_AstNode const *(*IfStatementAlternate)(es2panda_AstNode *ast); + + bool (*IsImportDeclaration)(es2panda_AstNode *ast); + es2panda_AstNode *(*CreateImportDeclaration)(es2panda_Context *context, es2panda_AstNode *source, + es2panda_AstNode **specifiers, size_t n_specifiers); + es2panda_AstNode const *(*ImportDeclarationSource)(es2panda_AstNode *ast); + es2panda_AstNode *const *(*ImportDeclarationSpecifiers)(es2panda_AstNode *ast, size_t *size_p); + + bool (*IsImportExpression)(es2panda_AstNode *ast); + es2panda_AstNode *(*CreateImportExpression)(es2panda_Context *context, es2panda_AstNode *source); + es2panda_AstNode *(*ImportExpressionSource)(es2panda_AstNode *ast); + + bool (*IsImportSpecifier)(es2panda_AstNode *ast); + es2panda_AstNode *(*CreateImportSpecifier)(es2panda_Context *context, es2panda_AstNode *imported, + es2panda_AstNode *local); + es2panda_AstNode *(*ImportSpecifierImported)(es2panda_AstNode *ast); + es2panda_AstNode *(*ImportSpecifierLocal)(es2panda_AstNode *ast); + + bool (*IsMemberExpression)(es2panda_AstNode *ast); + es2panda_AstNode *(*CreateMemberExpression)(es2panda_Context *context, es2panda_AstNode *object, + es2panda_AstNode *property, es2panda_MemberExpressionKind kind, + bool is_computed, bool is_optional); + es2panda_AstNode *(*MemberExpressionObject)(es2panda_AstNode *ast); + es2panda_AstNode *(*MemberExpressionProperty)(es2panda_AstNode *ast); + es2panda_MemberExpressionKind (*MemberExpressionKind)(es2panda_AstNode *ast); + bool (*MemberExpressionIsComputed)(es2panda_AstNode *ast); + bool (*MemberExpressionIsOptional)(es2panda_AstNode *ast); + + bool (*IsMethodDefinition)(es2panda_AstNode *ast); + es2panda_AstNode *(*CreateMethodDefinition)(es2panda_Context *context, char const *kind, es2panda_AstNode *key, + es2panda_AstNode *value, es2panda_ModifierFlags modifiers, + bool is_computed); + char const *(*MethodDefinitionKind)(es2panda_AstNode *ast); + es2panda_AstNode const *(*MethodDefinitionKey)(es2panda_AstNode *ast); + es2panda_AstNode const *(*MethodDefinitionValue)(es2panda_AstNode *ast); + es2panda_ModifierFlags (*MethodDefinitionModifiers)(es2panda_AstNode *ast); + bool (*MethodDefinitionIsComputed)(es2panda_AstNode *ast); + es2panda_AstNode *const *(*MethodDefinitionOverloads)(es2panda_AstNode *ast, size_t *size_p); + void (*MethodDefinitionSetOverloads)(es2panda_AstNode *ast, es2panda_AstNode **overloads, size_t n_overloads); + void (*MethodDefinitionAddOverload)(es2panda_AstNode *ast, es2panda_AstNode *overload); + + bool (*IsNewClassInstanceExpression)(es2panda_AstNode *ast); + es2panda_AstNode *(*CreateNewClassInstanceExpression)(es2panda_Context *context, es2panda_AstNode *type_reference, + es2panda_AstNode **arguments, size_t n_arguments, + es2panda_AstNode *class_definition); + es2panda_AstNode *(*NewClassInstanceExpressionTypeReference)(es2panda_AstNode *ast); + es2panda_AstNode *const *(*NewClassInstanceExpressionArguments)(es2panda_AstNode *ast, size_t *size_p); + es2panda_AstNode *(*NewClassInstanceExpressionClassDefinition)(es2panda_AstNode *ast); + + bool (*IsNewArrayInstanceExpression)(es2panda_AstNode *ast); + es2panda_AstNode *(*CreateNewArrayInstanceExpression)(es2panda_Context *context, es2panda_AstNode *type_reference, + es2panda_AstNode *dimension); + es2panda_AstNode *(*NewArrayInstanceExpressionTypeReference)(es2panda_AstNode *ast); + es2panda_AstNode *(*NewArrayInstanceExpressionDimension)(es2panda_AstNode *ast); + + bool (*IsNewMultiDimArrayInstanceExpression)(es2panda_AstNode *ast); + es2panda_AstNode *(*CreateNewMultiDimArrayInstanceExpression)(es2panda_Context *context, + es2panda_AstNode *type_reference, + es2panda_AstNode **dimensions, size_t n_dimensions); + es2panda_AstNode *(*NewMultiDimArrayInstanceExpressionTypeReference)(es2panda_AstNode *ast); + es2panda_AstNode *const *(*NewMultiDimArrayInstanceExpressionDimensions)(es2panda_AstNode *ast, size_t *size_p); + + bool (*IsNonNullExpression)(es2panda_AstNode *ast); + bool (*IsNumberLiteral)(es2panda_AstNode *ast); + bool (*IsObjectExpression)(es2panda_AstNode *ast); + + bool (*IsParameterDeclaration)(es2panda_AstNode *ast); + es2panda_AstNode *(*CreateParameterDeclaration)(es2panda_Context *context, es2panda_AstNode *identifier_or_spread, + es2panda_AstNode *initializer); + es2panda_AstNode *(*ParameterDeclarationIdentifierOrSpread)(es2panda_AstNode *ast); + es2panda_AstNode *(*ParameterDeclarationInitializer)(es2panda_AstNode *ast); + + bool (*IsPrimitiveTypeNode)(es2panda_AstNode *ast); + es2panda_AstNode *(*CreatePrimitiveTypeNode)(es2panda_Context *context, char const *type); + char const *(*PrimitiveTypeNodeType)(es2panda_AstNode *ast); + + bool (*IsReturnStatement)(es2panda_AstNode *ast); + es2panda_AstNode *(*CreatereturnStatement)(es2panda_Context *context, es2panda_AstNode *argument); + es2panda_AstNode *(*ReturnStatementArgument)(es2panda_AstNode *ast); + es2panda_Type *(*ReturnStatementReturnType)(es2panda_AstNode *ast); + + bool (*IsScriptFunction)(es2panda_AstNode *ast); + es2panda_AstNode *(*CreateScriptFunction)(es2panda_Context *context, es2panda_AstNode *type_params, + es2panda_AstNode **params, size_t n_params, + es2panda_AstNode *return_type_annotation, + es2panda_ScriptFunctionFlags function_flags, + es2panda_ModifierFlags modifier_flags, bool is_declare, + es2panda_AstNode *in_scope_of); + es2panda_AstNode *(*ScriptFunctionTypeParams)(es2panda_AstNode *ast); + es2panda_AstNode *const *(*ScriptFunctionParams)(es2panda_AstNode *ast, size_t *size_p); + es2panda_AstNode *(*ScriptFunctionReturnTypeAnnotation)(es2panda_AstNode *ast); + es2panda_ScriptFunctionFlags (*ScriptFunctionScriptFunctionFlags)(es2panda_AstNode *ast); + bool (*ScriptFunctionIsDeclare)(es2panda_AstNode *ast); + es2panda_AstNode *(*ScriptFunctionIdentifier)(es2panda_AstNode *ast); + es2panda_AstNode *(*ScriptFunctionBody)(es2panda_AstNode *ast); + void (*ScriptFunctionSetIdentifier)(es2panda_AstNode *ast, es2panda_AstNode *ident); + void (*ScriptFunctionSetBody)(es2panda_AstNode *ast, es2panda_AstNode *body); + void (*ScriptFunctionSetParams)(es2panda_AstNode *ast, es2panda_AstNode **params, size_t n_params); + void (*ScripFunctionAddParam)(es2panda_AstNode *ast, es2panda_AstNode *param); + + bool (*IsStringLiteral)(es2panda_AstNode *ast); + es2panda_AstNode *(*CreateStringLiteral)(es2panda_Context *context, char const *string); + char const *(*StringLiteralString)(es2panda_Context *context, es2panda_AstNode *ast); + + bool (*IsThisExpression)(es2panda_AstNode *ast); + es2panda_AstNode *(*CreateThisExpression)(es2panda_Context *context); + + bool (*IsTypeParameter)(es2panda_AstNode *ast); + es2panda_AstNode *(*CreateTypeParameter)(es2panda_Context *context, es2panda_AstNode *name, + es2panda_AstNode *constraint, es2panda_AstNode *defaultType); + es2panda_AstNode const *(*TypeParameterName)(es2panda_AstNode *ast); + es2panda_AstNode const *(*TypeParameterConstraint)(es2panda_AstNode *ast); + es2panda_AstNode const *(*TypeParameterDefaultType)(es2panda_AstNode *ast); + + bool (*IsTypeParameterDeclaration)(es2panda_AstNode *ast); + es2panda_AstNode *(*CreateTypeParameterDeclaration)(es2panda_Context *context, es2panda_AstNode *in_scope_of); + void (*TypeParameterDeclarationAddTypeParameter)(es2panda_AstNode *ast, es2panda_AstNode *type_parameter); + es2panda_AstNode *const *(*TypeParameterDeclarationTypeParameters)(es2panda_AstNode *ast, size_t *size_p); + + bool (*IsTypeParameterInstantiation)(es2panda_AstNode *ast); + es2panda_AstNode *(*CreateTypeParameterInstantiation)(es2panda_Context *context, es2panda_AstNode **params, + size_t n_params); + es2panda_AstNode *const *(*TypeParameterInstantiationTypeParameters)(es2panda_AstNode *ast, size_t *size_p); + + bool (*IsTypeReferenceNode)(es2panda_AstNode *ast); + es2panda_AstNode *(*CreateTypeReferenceNode)(es2panda_Context *context, es2panda_AstNode *part); + es2panda_AstNode *(*TypeRefrenceNodePart)(es2panda_AstNode *ast); + + bool (*IsTypeReferencePart)(es2panda_AstNode *ast); + es2panda_AstNode *(*CreateTypeReferencePart)(es2panda_Context *context, es2panda_AstNode *name, + es2panda_AstNode *type_arguments, es2panda_AstNode *previous); + es2panda_AstNode *(*TypeReferencePartName)(es2panda_AstNode *ast); + es2panda_AstNode *(*TypeReferencePartTypeArguments)(es2panda_AstNode *ast); + es2panda_AstNode *(*TypeReferencePartPrevious)(es2panda_AstNode *ast); + + bool (*IsUnionTypeNode)(es2panda_AstNode *ast); + es2panda_AstNode *(*CreateUnionTypeNode)(es2panda_Context *context, es2panda_AstNode **types, size_t n_types); + es2panda_AstNode *const *(*UnionTypeNodeTypes)(es2panda_AstNode *ast, size_t *size_p); + + bool (*IsVariableDeclaration)(es2panda_AstNode *ast); + es2panda_AstNode *(*CreateVariableDeclaration)(es2panda_Context *context, char const *kind, + es2panda_AstNode **declarators, size_t n_declarators, + bool is_declare); + char const *(*VariableDeclarationKind)(es2panda_AstNode *ast); + es2panda_AstNode *const *(*VariableDeclarationDeclarators)(es2panda_AstNode *ast, size_t *size_p); + bool (*VariableDeclarationIsDeclare)(es2panda_AstNode *ast); + + bool (*IsVariableDeclarator)(es2panda_AstNode *ast); + es2panda_AstNode *(*CreateVariableDeclarator)(es2panda_Context *context, es2panda_AstNode *identifier, + es2panda_AstNode *initializer); + es2panda_AstNode *(*VariableDeclaratorIdentifier)(es2panda_AstNode *ast); + es2panda_AstNode *(*VariableDeclaratorInitializer)(es2panda_AstNode *ast); }; struct es2panda_Impl const *es2panda_GetImpl(int version); diff --git a/ets2panda/public/public.h b/ets2panda/public/public.h new file mode 100644 index 0000000000000000000000000000000000000000..81c04023c1b7ecf95082a8da2a8897c944d7aee0 --- /dev/null +++ b/ets2panda/public/public.h @@ -0,0 +1,65 @@ +/** + * Copyright (c) 2021-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. + */ + +#ifndef ES2PANDA_PUBLIC_PUBLIC_H +#define ES2PANDA_PUBLIC_PUBLIC_H + +#include "public/es2panda_lib.h" + +#include "assembler/assembly-program.h" +#include "libpandabase/mem/arena_allocator.h" + +#include "es2panda.h" +#include "compiler/core/compileQueue.h" +#include "parser/ETSparser.h" +#include "checker/checker.h" +#include "compiler/core/emitter.h" +#include "util/options.h" + +namespace panda::es2panda::compiler { +class Phase; +} // namespace panda::es2panda::compiler + +namespace panda::es2panda::public_lib { +struct ConfigImpl { + util::Options *options; +}; + +struct Context { + ConfigImpl *config = nullptr; + std::string source_file_name; + std::string input; + SourceFile const *source_file = nullptr; + ArenaAllocator *allocator = nullptr; + compiler::CompileQueue *queue = nullptr; + std::vector const *plugins = nullptr; + std::vector phases; + size_t current_phase = 0; + + parser::Program *parser_program = nullptr; + parser::ParserImpl *parser = nullptr; + checker::Checker *checker = nullptr; + checker::SemanticAnalyzer *analyzer = nullptr; + compiler::CompilerContext *compiler_context = nullptr; + compiler::Emitter *emitter = nullptr; + pandasm::Program *program = nullptr; + + es2panda_ContextState state = ES2PANDA_STATE_NEW; + std::string error_message; + lexer::SourcePosition error_pos; +}; +} // namespace panda::es2panda::public_lib + +#endif diff --git a/ets2panda/scripts/es2panda_coverage.sh b/ets2panda/scripts/es2panda_coverage.sh index 9af403a22b0ae730a15b89be8ff1a68916fcccb6..a299f1c515c1eb1cf3d7fd836cb52714f029d4bd 100644 --- a/ets2panda/scripts/es2panda_coverage.sh +++ b/ets2panda/scripts/es2panda_coverage.sh @@ -26,16 +26,16 @@ case "$ARGUMENT" in esac done -python $PANDA_ROOT/plugins/ecmascript/es2panda/scripts/test_runner.py \ +python $PANDA_ROOT/tools/es2panda/scripts/test_runner.py \ --builddir $PANDA_BINARY_ROOT --arkdir $PANDA_ROOT --all -gcov $PANDA_BINARY_ROOT/plugins/ecmascript/es2panda/CMakeFiles/es2panda-lib.dir/*/* +gcov $PANDA_BINARY_ROOT/tools/es2panda/CMakeFiles/es2panda-lib.dir/*/* if [ -x "$(command -v gcovr)" ]; then echo "gcovr found" gcovr --version - gcovr -v -r $PANDA_ROOT/plugins/ecmascript/es2panda \ - -e $PANDA_ROOT/plugins/ecmascript/es2panda/test \ + gcovr -v -r $PANDA_ROOT/tools/es2panda/ \ + -e $PANDA_ROOT/tools/es2panda/test \ --object-directory=$PANDA_BINARY_ROOT --html-details --html -o report.html else diff --git a/ets2panda/test/CMakeLists.txt b/ets2panda/test/CMakeLists.txt index ff14df7c4ae66ff22c3618052179032ef05d69e4..f30dfa56a469d7f307108abfd063d66a51b2dbeb 100644 --- a/ets2panda/test/CMakeLists.txt +++ b/ets2panda/test/CMakeLists.txt @@ -76,16 +76,30 @@ if(PANDA_WITH_ETS) endforeach() panda_add_gtest( - NAME es2panda_public_tests + NAME es2panda_public_test SOURCES - public/es2panda_public_test.cpp + unit/public/es2panda_public_test.cpp LIBRARIES es2panda-public es2panda-lib arkassembler arkbytecodeopt INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/.. SANITIZERS ${PANDA_SANITIZERS_LIST} + ) + + panda_add_library(e2p_test_plugin SHARED unit/public/e2p_test_plugin.c) + panda_target_include_directories(e2p_test_plugin PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/..") + panda_target_link_libraries(e2p_test_plugin es2panda-public) + + add_custom_target(es2panda-plugin-test + COMMENT "Test es2panda plugin functionality" + COMMAND ${CMAKE_COMMAND} -E env LD_LIBRARY_PATH=${CMAKE_LIBRARY_OUTPUT_DIRECTORY} $ --plugins=e2p_test_plugin + "${CMAKE_CURRENT_SOURCE_DIR}/unit/public/t.ets" > "${CMAKE_CURRENT_BINARY_DIR}/plugin_test.out" + COMMAND ${CMAKE_COMMAND} -E compare_files + "${CMAKE_CURRENT_BINARY_DIR}/plugin_test.out" "${CMAKE_CURRENT_SOURCE_DIR}/unit/public/plugin_test.expected.txt" ) + add_dependencies(es2panda-plugin-test es2panda e2p_test_plugin) + add_dependencies(es2panda_tests es2panda-plugin-test) add_dependencies(es2panda_tests es2panda-regression-tests) if(TARGET ets_tests) @@ -95,7 +109,7 @@ if(PANDA_WITH_ETS) panda_add_gtest( NAME es2panda_astverifier_tests SOURCES - public/ast_verifier_test.cpp + unit/public/ast_verifier_test.cpp LIBRARIES es2panda-lib INCLUDE_DIRS @@ -104,5 +118,19 @@ if(PANDA_WITH_ETS) ${PANDA_SANITIZERS_LIST} ) + panda_add_gtest( + NAME es2panda_astdumper_tests + SOURCES + unit/ast_dumper_test.cpp + LIBRARIES + es2panda-public es2panda-lib arkassembler arkbytecodeopt + INCLUDE_DIRS + ${ES2PANDA_PATH} + SANITIZERS + ${PANDA_SANITIZERS_LIST} + ) + add_subdirectory(tsconfig) endif() + +add_subdirectory(options) diff --git a/ets2panda/test/compiler/ets/FunctionType1-expected.txt b/ets2panda/test/compiler/ets/FunctionType1-expected.txt index 8a077af2aa1c71fa7e8cbec4bf39c1a4edcfc0f6..067f0174687c1432a88946ef6160ecd645cca7f2 100644 --- a/ets2panda/test/compiler/ets/FunctionType1-expected.txt +++ b/ets2panda/test/compiler/ets/FunctionType1-expected.txt @@ -594,12 +594,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 16, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 16, + "column": 35 } } }, diff --git a/ets2panda/test/compiler/ets/FunctionType2-expected.txt b/ets2panda/test/compiler/ets/FunctionType2-expected.txt index 071e519658d1b4ba336c9c2028e3f5eb16df4101..1dcaa7ce18cad300834afa778966c9f4f1368547 100644 --- a/ets2panda/test/compiler/ets/FunctionType2-expected.txt +++ b/ets2panda/test/compiler/ets/FunctionType2-expected.txt @@ -253,12 +253,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 16, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 16, + "column": 37 } } }, diff --git a/ets2panda/test/compiler/ets/FunctionType3-expected.txt b/ets2panda/test/compiler/ets/FunctionType3-expected.txt index ca35e1e27ca278512efc531856f662671c7d2acc..9f4f79c8571bd80cc8786da052cf4cd025e27c3d 100644 --- a/ets2panda/test/compiler/ets/FunctionType3-expected.txt +++ b/ets2panda/test/compiler/ets/FunctionType3-expected.txt @@ -281,12 +281,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 16, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 16, + "column": 36 } } }, diff --git a/ets2panda/test/compiler/ets/FunctionType4-expected.txt b/ets2panda/test/compiler/ets/FunctionType4-expected.txt index c2aedd46bf6c9423523616e25365b365f5e02e45..8927a880696633a15427e3a077bcfc4fde64e7e0 100644 --- a/ets2panda/test/compiler/ets/FunctionType4-expected.txt +++ b/ets2panda/test/compiler/ets/FunctionType4-expected.txt @@ -107,23 +107,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 20, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 20, + "column": 24 } } }, "loc": { "start": { - "line": 1, + "line": 20, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 20, + "column": 25 } } } @@ -393,12 +393,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 20, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 20, + "column": 24 } } }, diff --git a/ets2panda/test/compiler/ets/FunctionType5-expected.txt b/ets2panda/test/compiler/ets/FunctionType5-expected.txt index 20c6f2c6fc116e7aa3f1d881e6525bb7f4755aeb..c6c23c17deefe05dd99af1785a27875cdb188c55 100644 --- a/ets2panda/test/compiler/ets/FunctionType5-expected.txt +++ b/ets2panda/test/compiler/ets/FunctionType5-expected.txt @@ -107,23 +107,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 20, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 20, + "column": 13 } } }, "loc": { "start": { - "line": 1, + "line": 20, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 20, + "column": 14 } } } @@ -434,12 +434,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 20, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 20, + "column": 13 } } } diff --git a/ets2panda/test/compiler/ets/FunctionType6-expected.txt b/ets2panda/test/compiler/ets/FunctionType6-expected.txt index f0652030543c41e44a49166a1606092dd9ac3aca..909ce83c37a295537bee3d4ca6896fb2f6b23d13 100644 --- a/ets2panda/test/compiler/ets/FunctionType6-expected.txt +++ b/ets2panda/test/compiler/ets/FunctionType6-expected.txt @@ -446,12 +446,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 23, + "column": 3 }, "end": { - "line": 1, - "column": 1 + "line": 23, + "column": 17 } } }, diff --git a/ets2panda/test/compiler/ets/FunctionType8-expected.txt b/ets2panda/test/compiler/ets/FunctionType8-expected.txt index 98c579e069b0722d245a7204faaad75689f82f68..246720088183d754f5cd838c8689bdd222ac527a 100644 --- a/ets2panda/test/compiler/ets/FunctionType8-expected.txt +++ b/ets2panda/test/compiler/ets/FunctionType8-expected.txt @@ -448,12 +448,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 22, + "column": 3 }, "end": { - "line": 1, - "column": 1 + "line": 22, + "column": 42 } } }, @@ -978,12 +978,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 30, + "column": 3 }, "end": { - "line": 1, - "column": 1 + "line": 30, + "column": 34 } } }, diff --git a/ets2panda/test/compiler/ets/FunctionType9-expected.txt b/ets2panda/test/compiler/ets/FunctionType9-expected.txt index b0d532dda3f1bbc611e296d7984d3398daf13429..e6dafbd1aedc0b5c985c1960af18a070f203de10 100644 --- a/ets2panda/test/compiler/ets/FunctionType9-expected.txt +++ b/ets2panda/test/compiler/ets/FunctionType9-expected.txt @@ -338,12 +338,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 22, + "column": 11 }, "end": { - "line": 1, - "column": 1 + "line": 22, + "column": 37 } } }, diff --git a/ets2panda/test/compiler/ets/abstractNewClassInstanceExpression-expected.txt b/ets2panda/test/compiler/ets/abstractNewClassInstanceExpression-expected.txt index e136477e1f712db4ee485f8cf6108052094ec704..d2a660f61fd80d3a31797928ad2fc5a706b667fd 100644 --- a/ets2panda/test/compiler/ets/abstractNewClassInstanceExpression-expected.txt +++ b/ets2panda/test/compiler/ets/abstractNewClassInstanceExpression-expected.txt @@ -746,12 +746,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 25, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 31, + "column": 9 } } }, @@ -948,12 +948,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 31, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 34, + "column": 2 } } }, diff --git a/ets2panda/test/compiler/ets/extended_conditional_expression_not-expected.txt b/ets2panda/test/compiler/ets/extended_conditional_expression_not-expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..60a0330b805d2c13451cd7090c33072d4984b1f5 --- /dev/null +++ b/ets2panda/test/compiler/ets/extended_conditional_expression_not-expected.txt @@ -0,0 +1,444 @@ +{ + "type": "Program", + "statements": [ + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "ETSGLOBAL", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "superClass": null, + "implements": [], + "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "_$init$_", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "_$init$_", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "f", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 10 + }, + "end": { + "line": 16, + "column": 11 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "f", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 10 + }, + "end": { + "line": 16, + "column": 11 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [ + { + "type": "ETSParameterExpression", + "name": { + "type": "Identifier", + "name": "n", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "number", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 15 + }, + "end": { + "line": 16, + "column": 21 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 15 + }, + "end": { + "line": 16, + "column": 22 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 15 + }, + "end": { + "line": 16, + "column": 22 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 12 + }, + "end": { + "line": 16, + "column": 22 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 12 + }, + "end": { + "line": 16, + "column": 22 + } + } + } + ], + "returnType": { + "type": "ETSPrimitiveType", + "loc": { + "start": { + "line": 16, + "column": 24 + }, + "end": { + "line": 16, + "column": 27 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "IfStatement", + "test": { + "type": "UnaryExpression", + "operator": "!", + "prefix": true, + "argument": { + "type": "Identifier", + "name": "n", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 10 + }, + "end": { + "line": 17, + "column": 11 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 9 + }, + "end": { + "line": 17, + "column": 11 + } + } + }, + "consequent": { + "type": "BlockStatement", + "statements": [ + { + "type": "ReturnStatement", + "argument": { + "type": "NumberLiteral", + "value": 0, + "loc": { + "start": { + "line": 18, + "column": 16 + }, + "end": { + "line": 18, + "column": 17 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 9 + }, + "end": { + "line": 18, + "column": 18 + } + } + } + ], + "loc": { + "start": { + "line": 17, + "column": 13 + }, + "end": { + "line": 19, + "column": 6 + } + } + }, + "alternate": null, + "loc": { + "start": { + "line": 17, + "column": 5 + }, + "end": { + "line": 19, + "column": 6 + } + } + }, + { + "type": "ReturnStatement", + "argument": { + "type": "NumberLiteral", + "value": 1, + "loc": { + "start": { + "line": 20, + "column": 12 + }, + "end": { + "line": 20, + "column": 13 + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 5 + }, + "end": { + "line": 20, + "column": 14 + } + } + } + ], + "loc": { + "start": { + "line": 16, + "column": 28 + }, + "end": { + "line": 21, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 11 + }, + "end": { + "line": 21, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 11 + }, + "end": { + "line": 21, + "column": 2 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 1 + }, + "end": { + "line": 21, + "column": 2 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 22, + "column": 1 + } + } +} diff --git a/ets2panda/test/compiler/ets/extended_conditional_expression_not.ets b/ets2panda/test/compiler/ets/extended_conditional_expression_not.ets new file mode 100644 index 0000000000000000000000000000000000000000..a012fda36c85d881ae7b426a4f8b4911515bcc87 --- /dev/null +++ b/ets2panda/test/compiler/ets/extended_conditional_expression_not.ets @@ -0,0 +1,21 @@ +/* + * 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. + */ + +function f(n: number): int { + if (!n) { + return 0; + } + return 1; +} diff --git a/ets2panda/test/compiler/ets/extended_conditional_expression_not_return_type-expected.txt b/ets2panda/test/compiler/ets/extended_conditional_expression_not_return_type-expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..80a89ecb8f07b6a5a888052b2eb833e17e1edcc3 --- /dev/null +++ b/ets2panda/test/compiler/ets/extended_conditional_expression_not_return_type-expected.txt @@ -0,0 +1,374 @@ +{ + "type": "Program", + "statements": [ + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "ETSGLOBAL", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "superClass": null, + "implements": [], + "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "_$init$_", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "_$init$_", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "f", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 10 + }, + "end": { + "line": 16, + "column": 11 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "f", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 10 + }, + "end": { + "line": 16, + "column": 11 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [ + { + "type": "ETSParameterExpression", + "name": { + "type": "Identifier", + "name": "n", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "string", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 15 + }, + "end": { + "line": 16, + "column": 21 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 15 + }, + "end": { + "line": 16, + "column": 22 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 15 + }, + "end": { + "line": 16, + "column": 22 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 12 + }, + "end": { + "line": 16, + "column": 22 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 12 + }, + "end": { + "line": 16, + "column": 22 + } + } + } + ], + "returnType": { + "type": "ETSPrimitiveType", + "loc": { + "start": { + "line": 16, + "column": 24 + }, + "end": { + "line": 16, + "column": 31 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "ReturnStatement", + "argument": { + "type": "UnaryExpression", + "operator": "!", + "prefix": true, + "argument": { + "type": "Identifier", + "name": "n", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 13 + }, + "end": { + "line": 17, + "column": 14 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 12 + }, + "end": { + "line": 17, + "column": 14 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 5 + }, + "end": { + "line": 17, + "column": 15 + } + } + } + ], + "loc": { + "start": { + "line": 16, + "column": 32 + }, + "end": { + "line": 18, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 11 + }, + "end": { + "line": 18, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 11 + }, + "end": { + "line": 18, + "column": 2 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 1 + }, + "end": { + "line": 18, + "column": 2 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 18, + "column": 2 + } + } +} diff --git a/ets2panda/test/compiler/ets/extended_conditional_expression_not_return_type.ets b/ets2panda/test/compiler/ets/extended_conditional_expression_not_return_type.ets new file mode 100644 index 0000000000000000000000000000000000000000..1462fb5522085e9cb34fd2819dad2f339b6a8c23 --- /dev/null +++ b/ets2panda/test/compiler/ets/extended_conditional_expression_not_return_type.ets @@ -0,0 +1,18 @@ +/* + * 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. + */ + +function f(n: string): boolean { + return !n; +} \ No newline at end of file diff --git a/ets2panda/test/compiler/ets/for_of_missing_iterator_type-expected.txt b/ets2panda/test/compiler/ets/for_of_missing_iterator_type-expected.txt index bc25d70c78f102d30b18e19902252789f137459c..e2347bad084c1a78e4c09c379c4d19a1109714dd 100644 --- a/ets2panda/test/compiler/ets/for_of_missing_iterator_type-expected.txt +++ b/ets2panda/test/compiler/ets/for_of_missing_iterator_type-expected.txt @@ -62,12 +62,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 18, + "column": 11 }, "end": { - "line": 1, - "column": 1 + "line": 18, + "column": 17 } } }, diff --git a/ets2panda/test/compiler/ets/from-soft-keyword-0-expected.txt b/ets2panda/test/compiler/ets/from-soft-keyword-0-expected.txt index 7e25b44fe194e548df02e16ab173e5742b6a788f..3bbcd11e33ef65d1560400dab4ba7a68d1dc9f59 100644 --- a/ets2panda/test/compiler/ets/from-soft-keyword-0-expected.txt +++ b/ets2panda/test/compiler/ets/from-soft-keyword-0-expected.txt @@ -119,12 +119,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 19, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 19, + "column": 14 } } }, diff --git a/ets2panda/test/compiler/ets/generic_arrayaslist-expected.txt b/ets2panda/test/compiler/ets/generic_arrayaslist-expected.txt index e902bdbdba6b18c5653e8f9385f15b4f1f1e1952..4769cb130a3e19312293236b350d5ee01f41fd1c 100644 --- a/ets2panda/test/compiler/ets/generic_arrayaslist-expected.txt +++ b/ets2panda/test/compiler/ets/generic_arrayaslist-expected.txt @@ -20928,12 +20928,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 238, + "column": 13 }, "end": { - "line": 1, - "column": 1 + "line": 238, + "column": 23 } } }, @@ -20977,12 +20977,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 239, + "column": 13 }, "end": { - "line": 1, - "column": 1 + "line": 239, + "column": 25 } } } diff --git a/ets2panda/test/compiler/ets/generic_function_call_5-expected.txt b/ets2panda/test/compiler/ets/generic_function_call_5-expected.txt index f74eaa8b74e437a34c849d6ddd5300ce4519f4c1..42dbbefc7b1b9fc2284ff47ae8905ac98c15f221 100644 --- a/ets2panda/test/compiler/ets/generic_function_call_5-expected.txt +++ b/ets2panda/test/compiler/ets/generic_function_call_5-expected.txt @@ -466,12 +466,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 20, + "column": 13 }, "end": { - "line": 1, - "column": 1 + "line": 20, + "column": 25 } } } diff --git a/ets2panda/test/compiler/ets/generics_class_recursive_type_1-expected.txt b/ets2panda/test/compiler/ets/generics_class_recursive_type_1-expected.txt index bd5f6fdaac1d5fdeadccfd1b5a36c7c8988948c6..8c18f48d2d53e1b85e1adde629d867cf5b4b6376 100644 --- a/ets2panda/test/compiler/ets/generics_class_recursive_type_1-expected.txt +++ b/ets2panda/test/compiler/ets/generics_class_recursive_type_1-expected.txt @@ -355,12 +355,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 17, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 17, + "column": 23 } } }, @@ -432,12 +432,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 18, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 18, + "column": 12 } } }, @@ -509,12 +509,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 19, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 19, + "column": 14 } } }, @@ -558,12 +558,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 20, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 20, + "column": 16 } } }, @@ -732,12 +732,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 21, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 21, + "column": 24 } } }, @@ -5376,12 +5376,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 55, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 55, + "column": 13 } } }, @@ -5855,12 +5855,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 59, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 59, + "column": 20 } } }, @@ -6029,12 +6029,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 60, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 60, + "column": 20 } } }, diff --git a/ets2panda/test/compiler/ets/generics_implicit_lambda1-expected.txt b/ets2panda/test/compiler/ets/generics_implicit_lambda1-expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..7fc151e937e61413c69e749ea19af03abe4988d6 --- /dev/null +++ b/ets2panda/test/compiler/ets/generics_implicit_lambda1-expected.txt @@ -0,0 +1,2262 @@ +{ + "type": "Program", + "statements": [ + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "X", + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 7 + }, + "end": { + "line": 21, + "column": 8 + } + } + }, + "superClass": null, + "implements": [], + "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "foo", + "decorators": [], + "loc": { + "start": { + "line": 22, + "column": 12 + }, + "end": { + "line": 22, + "column": 15 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "foo", + "decorators": [], + "loc": { + "start": { + "line": 22, + "column": 12 + }, + "end": { + "line": 22, + "column": 15 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [ + { + "type": "ETSParameterExpression", + "name": { + "type": "Identifier", + "name": "first", + "typeAnnotation": { + "type": "ETSFunctionType", + "params": [], + "returnType": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "T", + "decorators": [], + "loc": { + "start": { + "line": 22, + "column": 32 + }, + "end": { + "line": 22, + "column": 33 + } + } + }, + "loc": { + "start": { + "line": 22, + "column": 32 + }, + "end": { + "line": 22, + "column": 34 + } + } + }, + "loc": { + "start": { + "line": 22, + "column": 32 + }, + "end": { + "line": 22, + "column": 34 + } + } + }, + "loc": { + "start": { + "line": 22, + "column": 26 + }, + "end": { + "line": 22, + "column": 34 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 22, + "column": 19 + }, + "end": { + "line": 22, + "column": 34 + } + } + }, + "loc": { + "start": { + "line": 22, + "column": 19 + }, + "end": { + "line": 22, + "column": 34 + } + } + }, + { + "type": "ETSParameterExpression", + "name": { + "type": "Identifier", + "name": "second", + "typeAnnotation": { + "type": "ETSFunctionType", + "params": [], + "returnType": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "void", + "decorators": [], + "loc": { + "start": { + "line": 22, + "column": 49 + }, + "end": { + "line": 22, + "column": 53 + } + } + }, + "loc": { + "start": { + "line": 22, + "column": 49 + }, + "end": { + "line": 22, + "column": 54 + } + } + }, + "loc": { + "start": { + "line": 22, + "column": 49 + }, + "end": { + "line": 22, + "column": 54 + } + } + }, + "loc": { + "start": { + "line": 22, + "column": 43 + }, + "end": { + "line": 22, + "column": 54 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 22, + "column": 35 + }, + "end": { + "line": 22, + "column": 54 + } + } + }, + "loc": { + "start": { + "line": 22, + "column": 35 + }, + "end": { + "line": 22, + "column": 54 + } + } + } + ], + "returnType": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "T", + "decorators": [], + "loc": { + "start": { + "line": 22, + "column": 56 + }, + "end": { + "line": 22, + "column": 57 + } + } + }, + "loc": { + "start": { + "line": 22, + "column": 56 + }, + "end": { + "line": 22, + "column": 59 + } + } + }, + "loc": { + "start": { + "line": 22, + "column": 56 + }, + "end": { + "line": 22, + "column": 59 + } + } + }, + "typeParameters": { + "type": "TSTypeParameterDeclaration", + "params": [ + { + "type": "TSTypeParameter", + "name": { + "type": "Identifier", + "name": "T", + "decorators": [], + "loc": { + "start": { + "line": 22, + "column": 16 + }, + "end": { + "line": 22, + "column": 17 + } + } + }, + "loc": { + "start": { + "line": 22, + "column": 16 + }, + "end": { + "line": 22, + "column": 18 + } + } + } + ], + "loc": { + "start": { + "line": 22, + "column": 15 + }, + "end": { + "line": 22, + "column": 18 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "instance", + "decorators": [], + "loc": { + "start": { + "line": 23, + "column": 15 + }, + "end": { + "line": 23, + "column": 23 + } + } + }, + "init": { + "type": "CallExpression", + "callee": { + "type": "Identifier", + "name": "first", + "decorators": [], + "loc": { + "start": { + "line": 23, + "column": 26 + }, + "end": { + "line": 23, + "column": 31 + } + } + }, + "arguments": [], + "optional": false, + "loc": { + "start": { + "line": 23, + "column": 26 + }, + "end": { + "line": 23, + "column": 33 + } + } + }, + "loc": { + "start": { + "line": 23, + "column": 15 + }, + "end": { + "line": 23, + "column": 33 + } + } + } + ], + "kind": "const", + "loc": { + "start": { + "line": 23, + "column": 9 + }, + "end": { + "line": 23, + "column": 33 + } + } + }, + { + "type": "ExpressionStatement", + "expression": { + "type": "CallExpression", + "callee": { + "type": "Identifier", + "name": "second", + "decorators": [], + "loc": { + "start": { + "line": 24, + "column": 9 + }, + "end": { + "line": 24, + "column": 15 + } + } + }, + "arguments": [], + "optional": false, + "loc": { + "start": { + "line": 24, + "column": 9 + }, + "end": { + "line": 24, + "column": 17 + } + } + }, + "loc": { + "start": { + "line": 24, + "column": 9 + }, + "end": { + "line": 24, + "column": 17 + } + } + }, + { + "type": "ReturnStatement", + "argument": { + "type": "Identifier", + "name": "instance", + "decorators": [], + "loc": { + "start": { + "line": 25, + "column": 16 + }, + "end": { + "line": 25, + "column": 24 + } + } + }, + "loc": { + "start": { + "line": 25, + "column": 9 + }, + "end": { + "line": 25, + "column": 24 + } + } + } + ], + "loc": { + "start": { + "line": 22, + "column": 58 + }, + "end": { + "line": 26, + "column": 6 + } + } + }, + "loc": { + "start": { + "line": 22, + "column": 15 + }, + "end": { + "line": 26, + "column": 6 + } + } + }, + "loc": { + "start": { + "line": 22, + "column": 15 + }, + "end": { + "line": 26, + "column": 6 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 22, + "column": 5 + }, + "end": { + "line": 26, + "column": 6 + } + } + }, + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "invoke", + "decorators": [], + "loc": { + "start": { + "line": 28, + "column": 12 + }, + "end": { + "line": 28, + "column": 18 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "invoke", + "decorators": [], + "loc": { + "start": { + "line": 28, + "column": 12 + }, + "end": { + "line": 28, + "column": 18 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [ + { + "type": "ETSParameterExpression", + "name": { + "type": "Identifier", + "name": "first", + "typeAnnotation": { + "type": "ETSFunctionType", + "params": [], + "returnType": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "T", + "decorators": [], + "loc": { + "start": { + "line": 28, + "column": 35 + }, + "end": { + "line": 28, + "column": 36 + } + } + }, + "loc": { + "start": { + "line": 28, + "column": 35 + }, + "end": { + "line": 28, + "column": 37 + } + } + }, + "loc": { + "start": { + "line": 28, + "column": 35 + }, + "end": { + "line": 28, + "column": 37 + } + } + }, + "loc": { + "start": { + "line": 28, + "column": 29 + }, + "end": { + "line": 28, + "column": 37 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 28, + "column": 22 + }, + "end": { + "line": 28, + "column": 37 + } + } + }, + "loc": { + "start": { + "line": 28, + "column": 22 + }, + "end": { + "line": 28, + "column": 37 + } + } + }, + { + "type": "ETSParameterExpression", + "name": { + "type": "Identifier", + "name": "second", + "typeAnnotation": { + "type": "ETSFunctionType", + "params": [], + "returnType": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "void", + "decorators": [], + "loc": { + "start": { + "line": 28, + "column": 52 + }, + "end": { + "line": 28, + "column": 56 + } + } + }, + "loc": { + "start": { + "line": 28, + "column": 52 + }, + "end": { + "line": 28, + "column": 57 + } + } + }, + "loc": { + "start": { + "line": 28, + "column": 52 + }, + "end": { + "line": 28, + "column": 57 + } + } + }, + "loc": { + "start": { + "line": 28, + "column": 46 + }, + "end": { + "line": 28, + "column": 57 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 28, + "column": 38 + }, + "end": { + "line": 28, + "column": 57 + } + } + }, + "loc": { + "start": { + "line": 28, + "column": 38 + }, + "end": { + "line": 28, + "column": 57 + } + } + } + ], + "returnType": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "T", + "decorators": [], + "loc": { + "start": { + "line": 28, + "column": 59 + }, + "end": { + "line": 28, + "column": 60 + } + } + }, + "loc": { + "start": { + "line": 28, + "column": 59 + }, + "end": { + "line": 28, + "column": 62 + } + } + }, + "loc": { + "start": { + "line": 28, + "column": 59 + }, + "end": { + "line": 28, + "column": 62 + } + } + }, + "typeParameters": { + "type": "TSTypeParameterDeclaration", + "params": [ + { + "type": "TSTypeParameter", + "name": { + "type": "Identifier", + "name": "T", + "decorators": [], + "loc": { + "start": { + "line": 28, + "column": 19 + }, + "end": { + "line": 28, + "column": 20 + } + } + }, + "loc": { + "start": { + "line": 28, + "column": 19 + }, + "end": { + "line": 28, + "column": 21 + } + } + } + ], + "loc": { + "start": { + "line": 28, + "column": 18 + }, + "end": { + "line": 28, + "column": 21 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "instance", + "decorators": [], + "loc": { + "start": { + "line": 29, + "column": 15 + }, + "end": { + "line": 29, + "column": 23 + } + } + }, + "init": { + "type": "CallExpression", + "callee": { + "type": "Identifier", + "name": "first", + "decorators": [], + "loc": { + "start": { + "line": 29, + "column": 26 + }, + "end": { + "line": 29, + "column": 31 + } + } + }, + "arguments": [], + "optional": false, + "loc": { + "start": { + "line": 29, + "column": 26 + }, + "end": { + "line": 29, + "column": 33 + } + } + }, + "loc": { + "start": { + "line": 29, + "column": 15 + }, + "end": { + "line": 29, + "column": 33 + } + } + } + ], + "kind": "const", + "loc": { + "start": { + "line": 29, + "column": 9 + }, + "end": { + "line": 29, + "column": 33 + } + } + }, + { + "type": "ExpressionStatement", + "expression": { + "type": "CallExpression", + "callee": { + "type": "Identifier", + "name": "second", + "decorators": [], + "loc": { + "start": { + "line": 30, + "column": 9 + }, + "end": { + "line": 30, + "column": 15 + } + } + }, + "arguments": [], + "optional": false, + "loc": { + "start": { + "line": 30, + "column": 9 + }, + "end": { + "line": 30, + "column": 17 + } + } + }, + "loc": { + "start": { + "line": 30, + "column": 9 + }, + "end": { + "line": 30, + "column": 17 + } + } + }, + { + "type": "ReturnStatement", + "argument": { + "type": "Identifier", + "name": "instance", + "decorators": [], + "loc": { + "start": { + "line": 31, + "column": 16 + }, + "end": { + "line": 31, + "column": 24 + } + } + }, + "loc": { + "start": { + "line": 31, + "column": 9 + }, + "end": { + "line": 31, + "column": 24 + } + } + } + ], + "loc": { + "start": { + "line": 28, + "column": 61 + }, + "end": { + "line": 32, + "column": 6 + } + } + }, + "loc": { + "start": { + "line": 28, + "column": 18 + }, + "end": { + "line": 32, + "column": 6 + } + } + }, + "loc": { + "start": { + "line": 28, + "column": 18 + }, + "end": { + "line": 32, + "column": 6 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 28, + "column": 5 + }, + "end": { + "line": 32, + "column": 6 + } + } + }, + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "constructor", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "constructor", + "static": false, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "constructor", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 33, + "column": 2 + }, + "end": { + "line": 33, + "column": 2 + } + } + } + ], + "loc": { + "start": { + "line": 21, + "column": 9 + }, + "end": { + "line": 33, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 21, + "column": 1 + }, + "end": { + "line": 33, + "column": 2 + } + } + }, + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "ETSGLOBAL", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "superClass": null, + "implements": [], + "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "_$init$_", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "_$init$_", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "foo", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 10 + }, + "end": { + "line": 16, + "column": 13 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "foo", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 10 + }, + "end": { + "line": 16, + "column": 13 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [ + { + "type": "ETSParameterExpression", + "name": { + "type": "Identifier", + "name": "first", + "typeAnnotation": { + "type": "ETSFunctionType", + "params": [], + "returnType": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "T", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 30 + }, + "end": { + "line": 16, + "column": 31 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 30 + }, + "end": { + "line": 16, + "column": 32 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 30 + }, + "end": { + "line": 16, + "column": 32 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 24 + }, + "end": { + "line": 16, + "column": 32 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 17 + }, + "end": { + "line": 16, + "column": 32 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 17 + }, + "end": { + "line": 16, + "column": 32 + } + } + } + ], + "returnType": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "T", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 34 + }, + "end": { + "line": 16, + "column": 35 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 34 + }, + "end": { + "line": 16, + "column": 37 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 34 + }, + "end": { + "line": 16, + "column": 37 + } + } + }, + "typeParameters": { + "type": "TSTypeParameterDeclaration", + "params": [ + { + "type": "TSTypeParameter", + "name": { + "type": "Identifier", + "name": "T", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 14 + }, + "end": { + "line": 16, + "column": 15 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 14 + }, + "end": { + "line": 16, + "column": 16 + } + } + } + ], + "loc": { + "start": { + "line": 16, + "column": 13 + }, + "end": { + "line": 16, + "column": 16 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "instance", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 11 + }, + "end": { + "line": 17, + "column": 19 + } + } + }, + "init": { + "type": "CallExpression", + "callee": { + "type": "Identifier", + "name": "first", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 22 + }, + "end": { + "line": 17, + "column": 27 + } + } + }, + "arguments": [], + "optional": false, + "loc": { + "start": { + "line": 17, + "column": 22 + }, + "end": { + "line": 17, + "column": 29 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 11 + }, + "end": { + "line": 17, + "column": 29 + } + } + } + ], + "kind": "const", + "loc": { + "start": { + "line": 17, + "column": 5 + }, + "end": { + "line": 17, + "column": 29 + } + } + }, + { + "type": "ReturnStatement", + "argument": { + "type": "Identifier", + "name": "instance", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 12 + }, + "end": { + "line": 18, + "column": 20 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 5 + }, + "end": { + "line": 18, + "column": 20 + } + } + } + ], + "loc": { + "start": { + "line": 16, + "column": 36 + }, + "end": { + "line": 19, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 13 + }, + "end": { + "line": 19, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 13 + }, + "end": { + "line": 19, + "column": 2 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 1 + }, + "end": { + "line": 19, + "column": 2 + } + } + }, + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 35, + "column": 10 + }, + "end": { + "line": 35, + "column": 14 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 35, + "column": 10 + }, + "end": { + "line": 35, + "column": 14 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "ExpressionStatement", + "expression": { + "type": "CallExpression", + "callee": { + "type": "Identifier", + "name": "foo", + "decorators": [], + "loc": { + "start": { + "line": 36, + "column": 5 + }, + "end": { + "line": 36, + "column": 8 + } + } + }, + "arguments": [ + { + "type": "ArrowFunctionExpression", + "function": { + "type": "ScriptFunction", + "id": null, + "generator": false, + "async": false, + "expression": false, + "params": [], + "returnType": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "String", + "decorators": [], + "loc": { + "start": { + "line": 36, + "column": 13 + }, + "end": { + "line": 36, + "column": 19 + } + } + }, + "loc": { + "start": { + "line": 36, + "column": 13 + }, + "end": { + "line": 36, + "column": 22 + } + } + }, + "loc": { + "start": { + "line": 36, + "column": 13 + }, + "end": { + "line": 36, + "column": 22 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "ReturnStatement", + "argument": { + "type": "StringLiteral", + "value": "XXX", + "loc": { + "start": { + "line": 36, + "column": 32 + }, + "end": { + "line": 36, + "column": 37 + } + } + }, + "loc": { + "start": { + "line": 36, + "column": 25 + }, + "end": { + "line": 36, + "column": 37 + } + } + } + ], + "loc": { + "start": { + "line": 36, + "column": 23 + }, + "end": { + "line": 36, + "column": 39 + } + } + }, + "loc": { + "start": { + "line": 36, + "column": 9 + }, + "end": { + "line": 36, + "column": 39 + } + } + }, + "loc": { + "start": { + "line": 36, + "column": 9 + }, + "end": { + "line": 36, + "column": 39 + } + } + } + ], + "optional": false, + "loc": { + "start": { + "line": 36, + "column": 5 + }, + "end": { + "line": 36, + "column": 40 + } + } + }, + "loc": { + "start": { + "line": 36, + "column": 5 + }, + "end": { + "line": 36, + "column": 41 + } + } + }, + { + "type": "ExpressionStatement", + "expression": { + "type": "CallExpression", + "callee": { + "type": "Identifier", + "name": "foo", + "decorators": [], + "loc": { + "start": { + "line": 38, + "column": 5 + }, + "end": { + "line": 38, + "column": 8 + } + } + }, + "arguments": [ + { + "type": "ArrowFunctionExpression", + "function": { + "type": "ScriptFunction", + "id": null, + "generator": false, + "async": false, + "expression": false, + "params": [], + "returnType": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Int", + "decorators": [], + "loc": { + "start": { + "line": 38, + "column": 13 + }, + "end": { + "line": 38, + "column": 16 + } + } + }, + "loc": { + "start": { + "line": 38, + "column": 13 + }, + "end": { + "line": 38, + "column": 19 + } + } + }, + "loc": { + "start": { + "line": 38, + "column": 13 + }, + "end": { + "line": 38, + "column": 19 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "ReturnStatement", + "argument": { + "type": "ETSNewClassInstanceExpression", + "typeReference": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Int", + "decorators": [], + "loc": { + "start": { + "line": 38, + "column": 33 + }, + "end": { + "line": 38, + "column": 36 + } + } + }, + "loc": { + "start": { + "line": 38, + "column": 33 + }, + "end": { + "line": 38, + "column": 37 + } + } + }, + "loc": { + "start": { + "line": 38, + "column": 33 + }, + "end": { + "line": 38, + "column": 37 + } + } + }, + "arguments": [ + { + "type": "NumberLiteral", + "value": 42, + "loc": { + "start": { + "line": 38, + "column": 37 + }, + "end": { + "line": 38, + "column": 39 + } + } + } + ], + "loc": { + "start": { + "line": 38, + "column": 29 + }, + "end": { + "line": 38, + "column": 42 + } + } + }, + "loc": { + "start": { + "line": 38, + "column": 22 + }, + "end": { + "line": 38, + "column": 42 + } + } + } + ], + "loc": { + "start": { + "line": 38, + "column": 20 + }, + "end": { + "line": 38, + "column": 42 + } + } + }, + "loc": { + "start": { + "line": 38, + "column": 9 + }, + "end": { + "line": 38, + "column": 42 + } + } + }, + "loc": { + "start": { + "line": 38, + "column": 9 + }, + "end": { + "line": 38, + "column": 42 + } + } + } + ], + "optional": false, + "loc": { + "start": { + "line": 38, + "column": 5 + }, + "end": { + "line": 38, + "column": 43 + } + } + }, + "loc": { + "start": { + "line": 38, + "column": 5 + }, + "end": { + "line": 38, + "column": 44 + } + } + }, + { + "type": "ExpressionStatement", + "expression": { + "type": "CallExpression", + "callee": { + "type": "Identifier", + "name": "X", + "decorators": [], + "loc": { + "start": { + "line": 40, + "column": 5 + }, + "end": { + "line": 40, + "column": 6 + } + } + }, + "arguments": [ + { + "type": "ArrowFunctionExpression", + "function": { + "type": "ScriptFunction", + "id": null, + "generator": false, + "async": false, + "expression": false, + "params": [], + "returnType": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "String", + "decorators": [], + "loc": { + "start": { + "line": 41, + "column": 9 + }, + "end": { + "line": 41, + "column": 15 + } + } + }, + "loc": { + "start": { + "line": 41, + "column": 9 + }, + "end": { + "line": 41, + "column": 18 + } + } + }, + "loc": { + "start": { + "line": 41, + "column": 9 + }, + "end": { + "line": 41, + "column": 18 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "ReturnStatement", + "argument": { + "type": "StringLiteral", + "value": "XXX", + "loc": { + "start": { + "line": 41, + "column": 28 + }, + "end": { + "line": 41, + "column": 33 + } + } + }, + "loc": { + "start": { + "line": 41, + "column": 21 + }, + "end": { + "line": 41, + "column": 33 + } + } + } + ], + "loc": { + "start": { + "line": 41, + "column": 19 + }, + "end": { + "line": 41, + "column": 35 + } + } + }, + "loc": { + "start": { + "line": 41, + "column": 5 + }, + "end": { + "line": 41, + "column": 35 + } + } + }, + "loc": { + "start": { + "line": 41, + "column": 5 + }, + "end": { + "line": 41, + "column": 35 + } + } + } + ], + "optional": false, + "loc": { + "start": { + "line": 40, + "column": 5 + }, + "end": { + "line": 42, + "column": 6 + } + } + }, + "loc": { + "start": { + "line": 40, + "column": 5 + }, + "end": { + "line": 42, + "column": 6 + } + } + } + ], + "loc": { + "start": { + "line": 35, + "column": 17 + }, + "end": { + "line": 44, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 35, + "column": 14 + }, + "end": { + "line": 44, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 35, + "column": 14 + }, + "end": { + "line": 44, + "column": 2 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 35, + "column": 1 + }, + "end": { + "line": 44, + "column": 2 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 44, + "column": 2 + } + } +} diff --git a/ets2panda/test/compiler/ets/generics_implicit_lambda1.ets b/ets2panda/test/compiler/ets/generics_implicit_lambda1.ets new file mode 100644 index 0000000000000000000000000000000000000000..d48b0a74d2dbe6d4702858d1159c96b502621855 --- /dev/null +++ b/ets2panda/test/compiler/ets/generics_implicit_lambda1.ets @@ -0,0 +1,44 @@ +/* + * 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. + */ + +function foo(first: () => T): T { + const instance = first() + return instance +} + +class X { + static foo(first: () => T, second: () => void): T { + const instance = first() + second() + return instance + } + + static invoke(first: () => T, second: () => void): T { + const instance = first() + second() + return instance + } +} + +function main() { + foo((): String => { return "XXX" }); + + foo((): Int => { return new Int(42) }); + + X( + (): String => { return "XXX" }, + ) { + } +} \ No newline at end of file diff --git a/ets2panda/test/compiler/ets/generics_implicit_lambda2-expected.txt b/ets2panda/test/compiler/ets/generics_implicit_lambda2-expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..642f8dc36d5fffe6d8748b7e9a1c46839a84700c --- /dev/null +++ b/ets2panda/test/compiler/ets/generics_implicit_lambda2-expected.txt @@ -0,0 +1,1085 @@ +{ + "type": "Program", + "statements": [ + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "ETSGLOBAL", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "superClass": null, + "implements": [], + "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "_$init$_", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "_$init$_", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "foo", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 10 + }, + "end": { + "line": 16, + "column": 13 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "foo", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 10 + }, + "end": { + "line": 16, + "column": 13 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [ + { + "type": "ETSParameterExpression", + "name": { + "type": "Identifier", + "name": "first", + "typeAnnotation": { + "type": "ETSFunctionType", + "params": [ + { + "type": "ETSParameterExpression", + "name": { + "type": "Identifier", + "name": "a", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "U", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 31 + }, + "end": { + "line": 16, + "column": 32 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 31 + }, + "end": { + "line": 16, + "column": 33 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 31 + }, + "end": { + "line": 16, + "column": 33 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 28 + }, + "end": { + "line": 16, + "column": 33 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 28 + }, + "end": { + "line": 16, + "column": 33 + } + } + }, + { + "type": "ETSParameterExpression", + "name": { + "type": "Identifier", + "name": "b", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "T", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 37 + }, + "end": { + "line": 16, + "column": 38 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 37 + }, + "end": { + "line": 16, + "column": 39 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 37 + }, + "end": { + "line": 16, + "column": 39 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 34 + }, + "end": { + "line": 16, + "column": 39 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 34 + }, + "end": { + "line": 16, + "column": 39 + } + } + }, + { + "type": "ETSParameterExpression", + "name": { + "type": "Identifier", + "name": "c", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "U", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 43 + }, + "end": { + "line": 16, + "column": 44 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 43 + }, + "end": { + "line": 16, + "column": 45 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 43 + }, + "end": { + "line": 16, + "column": 45 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 40 + }, + "end": { + "line": 16, + "column": 45 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 40 + }, + "end": { + "line": 16, + "column": 45 + } + } + } + ], + "returnType": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "T", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 49 + }, + "end": { + "line": 16, + "column": 50 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 49 + }, + "end": { + "line": 16, + "column": 51 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 49 + }, + "end": { + "line": 16, + "column": 51 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 27 + }, + "end": { + "line": 16, + "column": 51 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 20 + }, + "end": { + "line": 16, + "column": 51 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 20 + }, + "end": { + "line": 16, + "column": 51 + } + } + } + ], + "returnType": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "T", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 53 + }, + "end": { + "line": 16, + "column": 54 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 53 + }, + "end": { + "line": 16, + "column": 56 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 53 + }, + "end": { + "line": 16, + "column": 56 + } + } + }, + "typeParameters": { + "type": "TSTypeParameterDeclaration", + "params": [ + { + "type": "TSTypeParameter", + "name": { + "type": "Identifier", + "name": "T", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 14 + }, + "end": { + "line": 16, + "column": 15 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 14 + }, + "end": { + "line": 16, + "column": 16 + } + } + }, + { + "type": "TSTypeParameter", + "name": { + "type": "Identifier", + "name": "U", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 17 + }, + "end": { + "line": 16, + "column": 18 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 17 + }, + "end": { + "line": 16, + "column": 19 + } + } + } + ], + "loc": { + "start": { + "line": 16, + "column": 13 + }, + "end": { + "line": 16, + "column": 19 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 16, + "column": 55 + }, + "end": { + "line": 16, + "column": 57 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 13 + }, + "end": { + "line": 16, + "column": 57 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 13 + }, + "end": { + "line": 16, + "column": 57 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 1 + }, + "end": { + "line": 16, + "column": 57 + } + } + }, + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 10 + }, + "end": { + "line": 18, + "column": 14 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 10 + }, + "end": { + "line": 18, + "column": 14 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "ExpressionStatement", + "expression": { + "type": "CallExpression", + "callee": { + "type": "Identifier", + "name": "foo", + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 5 + }, + "end": { + "line": 19, + "column": 8 + } + } + }, + "arguments": [ + { + "type": "ArrowFunctionExpression", + "function": { + "type": "ScriptFunction", + "id": null, + "generator": false, + "async": false, + "expression": false, + "params": [ + { + "type": "ETSParameterExpression", + "name": { + "type": "Identifier", + "name": "a", + "typeAnnotation": { + "type": "ETSPrimitiveType", + "loc": { + "start": { + "line": 19, + "column": 13 + }, + "end": { + "line": 19, + "column": 16 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 10 + }, + "end": { + "line": 19, + "column": 16 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 10 + }, + "end": { + "line": 19, + "column": 16 + } + } + }, + { + "type": "ETSParameterExpression", + "name": { + "type": "Identifier", + "name": "b", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "String", + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 21 + }, + "end": { + "line": 19, + "column": 27 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 21 + }, + "end": { + "line": 19, + "column": 28 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 21 + }, + "end": { + "line": 19, + "column": 28 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 18 + }, + "end": { + "line": 19, + "column": 28 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 18 + }, + "end": { + "line": 19, + "column": 28 + } + } + }, + { + "type": "ETSParameterExpression", + "name": { + "type": "Identifier", + "name": "c", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "String", + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 32 + }, + "end": { + "line": 19, + "column": 38 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 32 + }, + "end": { + "line": 19, + "column": 39 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 32 + }, + "end": { + "line": 19, + "column": 39 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 29 + }, + "end": { + "line": 19, + "column": 39 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 29 + }, + "end": { + "line": 19, + "column": 39 + } + } + } + ], + "returnType": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "String", + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 41 + }, + "end": { + "line": 19, + "column": 47 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 41 + }, + "end": { + "line": 19, + "column": 50 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 41 + }, + "end": { + "line": 19, + "column": 50 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "ReturnStatement", + "argument": { + "type": "StringLiteral", + "value": "XXX", + "loc": { + "start": { + "line": 19, + "column": 60 + }, + "end": { + "line": 19, + "column": 65 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 53 + }, + "end": { + "line": 19, + "column": 65 + } + } + } + ], + "loc": { + "start": { + "line": 19, + "column": 51 + }, + "end": { + "line": 19, + "column": 67 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 9 + }, + "end": { + "line": 19, + "column": 67 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 9 + }, + "end": { + "line": 19, + "column": 67 + } + } + } + ], + "optional": false, + "loc": { + "start": { + "line": 19, + "column": 5 + }, + "end": { + "line": 19, + "column": 68 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 5 + }, + "end": { + "line": 19, + "column": 69 + } + } + } + ], + "loc": { + "start": { + "line": 18, + "column": 17 + }, + "end": { + "line": 20, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 14 + }, + "end": { + "line": 20, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 14 + }, + "end": { + "line": 20, + "column": 2 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 1 + }, + "end": { + "line": 20, + "column": 2 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 20, + "column": 2 + } + } +} +TypeError: Type parameter already instantiated with another type [generics_implicit_lambda2.ets:16:17] diff --git a/ets2panda/test/compiler/ets/generics_implicit_lambda2.ets b/ets2panda/test/compiler/ets/generics_implicit_lambda2.ets new file mode 100644 index 0000000000000000000000000000000000000000..df06746de6c860dbe8bdd698b8de020a053527e2 --- /dev/null +++ b/ets2panda/test/compiler/ets/generics_implicit_lambda2.ets @@ -0,0 +1,20 @@ +/* + * 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. + */ + +function foo(first: (a: U, b: T, c: U) => T): T {} + +function main() { + foo((a: int, b: String, c: String): String => { return "XXX" }); +} \ No newline at end of file diff --git a/ets2panda/test/compiler/ets/generics_instantiation_1-expected.txt b/ets2panda/test/compiler/ets/generics_instantiation_1-expected.txt index a39528d5a38ab36748bc8bc21b3cbea200b7b823..826c0e80a2a5d3a8bdbdc04ccce1745a3cf8cedc 100644 --- a/ets2panda/test/compiler/ets/generics_instantiation_1-expected.txt +++ b/ets2panda/test/compiler/ets/generics_instantiation_1-expected.txt @@ -174,12 +174,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 17, + "column": 13 }, "end": { - "line": 1, - "column": 1 + "line": 17, + "column": 19 } } }, diff --git a/ets2panda/test/compiler/ets/generics_instantiation_2-expected.txt b/ets2panda/test/compiler/ets/generics_instantiation_2-expected.txt index 9378ef0aa26c2df1f48d9148668533fa64f723af..2e60845699d3825ea362f56d7c1df654d0fdef7b 100644 --- a/ets2panda/test/compiler/ets/generics_instantiation_2-expected.txt +++ b/ets2panda/test/compiler/ets/generics_instantiation_2-expected.txt @@ -395,12 +395,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 21, + "column": 12 }, "end": { - "line": 1, - "column": 1 + "line": 21, + "column": 21 } } }, diff --git a/ets2panda/test/compiler/ets/generics_instantiation_3-expected.txt b/ets2panda/test/compiler/ets/generics_instantiation_3-expected.txt index 4304cd5d687d10c9e40f63cd3235c7113c7298ed..7aee3903115cb2f559b552a5dc20f616270cdc33 100644 --- a/ets2panda/test/compiler/ets/generics_instantiation_3-expected.txt +++ b/ets2panda/test/compiler/ets/generics_instantiation_3-expected.txt @@ -498,12 +498,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 21, + "column": 13 }, "end": { - "line": 1, - "column": 1 + "line": 21, + "column": 23 } } }, diff --git a/ets2panda/test/compiler/ets/generics_instantiation_4-expected.txt b/ets2panda/test/compiler/ets/generics_instantiation_4-expected.txt index 4d568d9bcf9474a674492185989acb10183bb7d9..58ac0be4cfac4fecd88f525982db39725aebebcf 100644 --- a/ets2panda/test/compiler/ets/generics_instantiation_4-expected.txt +++ b/ets2panda/test/compiler/ets/generics_instantiation_4-expected.txt @@ -1952,12 +1952,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 41, + "column": 12 }, "end": { - "line": 1, - "column": 1 + "line": 41, + "column": 21 } } }, diff --git a/ets2panda/test/compiler/ets/generics_interface_bounds_1-expected.txt b/ets2panda/test/compiler/ets/generics_interface_bounds_1-expected.txt index bcf0a134c96a95adf9a519c133d2610130162040..618aaf0ee73a60ef27168d8fd50d945a3e917aa8 100644 --- a/ets2panda/test/compiler/ets/generics_interface_bounds_1-expected.txt +++ b/ets2panda/test/compiler/ets/generics_interface_bounds_1-expected.txt @@ -509,12 +509,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 21, + "column": 13 }, "end": { - "line": 1, - "column": 1 + "line": 21, + "column": 23 } } }, diff --git a/ets2panda/test/compiler/ets/generics_primitive_type_param_1-expected.txt b/ets2panda/test/compiler/ets/generics_primitive_type_param_1-expected.txt index d17aa49e9fbfecdd6c5077b0f5e12bfa6b85ef79..beeda0916cc791e793dba090353c106ce47b51ef 100644 --- a/ets2panda/test/compiler/ets/generics_primitive_type_param_1-expected.txt +++ b/ets2panda/test/compiler/ets/generics_primitive_type_param_1-expected.txt @@ -133,12 +133,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 17, + "column": 12 }, "end": { - "line": 1, - "column": 1 + "line": 17, + "column": 21 } } }, @@ -196,12 +196,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 18, + "column": 12 }, "end": { - "line": 1, - "column": 1 + "line": 18, + "column": 31 } } }, diff --git a/ets2panda/test/compiler/ets/generics_primitive_type_param_neg_1-expected.txt b/ets2panda/test/compiler/ets/generics_primitive_type_param_neg_1-expected.txt index 0217b74e03617b6fa40af2736435e5e4cc702626..981fbdf9d51da28140bb7735680829375e60846c 100644 --- a/ets2panda/test/compiler/ets/generics_primitive_type_param_neg_1-expected.txt +++ b/ets2panda/test/compiler/ets/generics_primitive_type_param_neg_1-expected.txt @@ -133,12 +133,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 17, + "column": 12 }, "end": { - "line": 1, - "column": 1 + "line": 17, + "column": 21 } } }, diff --git a/ets2panda/test/compiler/ets/generics_primitive_type_param_neg_2-expected.txt b/ets2panda/test/compiler/ets/generics_primitive_type_param_neg_2-expected.txt index 64dcbdf3312e415af616aedcba2608594f09cfb9..cb01550c5cf92886f01e6485b96d5516e3b1b69c 100644 --- a/ets2panda/test/compiler/ets/generics_primitive_type_param_neg_2-expected.txt +++ b/ets2panda/test/compiler/ets/generics_primitive_type_param_neg_2-expected.txt @@ -133,12 +133,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 17, + "column": 12 }, "end": { - "line": 1, - "column": 1 + "line": 17, + "column": 21 } } }, diff --git a/ets2panda/test/compiler/ets/identifierReference10-expected.txt b/ets2panda/test/compiler/ets/identifierReference10-expected.txt index 3eb9089b8257dc353155625959fde77cc80781f5..c956b389498268a4a617309cf07097e15c35e852 100644 --- a/ets2panda/test/compiler/ets/identifierReference10-expected.txt +++ b/ets2panda/test/compiler/ets/identifierReference10-expected.txt @@ -76,12 +76,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 17, + "column": 3 }, "end": { - "line": 1, - "column": 1 + "line": 17, + "column": 13 } } }, @@ -345,12 +345,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 21, + "column": 3 }, "end": { - "line": 1, - "column": 1 + "line": 21, + "column": 18 } } }, diff --git a/ets2panda/test/compiler/ets/identifierReference11-expected.txt b/ets2panda/test/compiler/ets/identifierReference11-expected.txt index 0d57a8c2bcad8794cd44fc911adc825909b6ff0d..f0d601241052dc6a836894ef9b0cd87f1863b571 100644 --- a/ets2panda/test/compiler/ets/identifierReference11-expected.txt +++ b/ets2panda/test/compiler/ets/identifierReference11-expected.txt @@ -76,12 +76,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 17, + "column": 3 }, "end": { - "line": 1, - "column": 1 + "line": 17, + "column": 15 } } }, diff --git a/ets2panda/test/compiler/ets/identifierReference12-expected.txt b/ets2panda/test/compiler/ets/identifierReference12-expected.txt index efc3f35fc8f1630c140845997675ebec15a25652..c41ed2bceb102471cca4d21074d66d858b42c362 100644 --- a/ets2panda/test/compiler/ets/identifierReference12-expected.txt +++ b/ets2panda/test/compiler/ets/identifierReference12-expected.txt @@ -76,12 +76,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 17, + "column": 3 }, "end": { - "line": 1, - "column": 1 + "line": 17, + "column": 16 } } }, @@ -345,12 +345,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 21, + "column": 3 }, "end": { - "line": 1, - "column": 1 + "line": 21, + "column": 18 } } }, diff --git a/ets2panda/test/compiler/ets/identifierReference13-expected.txt b/ets2panda/test/compiler/ets/identifierReference13-expected.txt index f11520714b1f94145ed7f201a62f27580d7d664b..b9a14ad2ffcf30aecc632e992570e00be7fabb65 100644 --- a/ets2panda/test/compiler/ets/identifierReference13-expected.txt +++ b/ets2panda/test/compiler/ets/identifierReference13-expected.txt @@ -417,12 +417,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 21, + "column": 3 }, "end": { - "line": 1, - "column": 1 + "line": 21, + "column": 18 } } }, diff --git a/ets2panda/test/compiler/ets/identifierReference2-expected.txt b/ets2panda/test/compiler/ets/identifierReference2-expected.txt index 07248d61cc74133a3e39b310f113ced2d96a5c2d..4f28a2426c9af4f5c3ec56e6aa866368b4e95e0d 100644 --- a/ets2panda/test/compiler/ets/identifierReference2-expected.txt +++ b/ets2panda/test/compiler/ets/identifierReference2-expected.txt @@ -107,23 +107,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 16, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 16, + "column": 37 } } }, "loc": { "start": { - "line": 1, + "line": 16, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 16, + "column": 38 } } } @@ -354,12 +354,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 16, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 16, + "column": 37 } } } diff --git a/ets2panda/test/compiler/ets/identifierReference3-expected.txt b/ets2panda/test/compiler/ets/identifierReference3-expected.txt index 6495cedbd507534806dc7aa04c65d78638513a60..6e49f3f6047d4d305eb455b2495bc0e3260c1f38 100644 --- a/ets2panda/test/compiler/ets/identifierReference3-expected.txt +++ b/ets2panda/test/compiler/ets/identifierReference3-expected.txt @@ -435,23 +435,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 16, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 16, + "column": 15 } } }, "loc": { "start": { - "line": 1, + "line": 16, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 16, + "column": 16 } } } @@ -542,12 +542,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 16, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 16, + "column": 11 } } } diff --git a/ets2panda/test/compiler/ets/identifierReference4-expected.txt b/ets2panda/test/compiler/ets/identifierReference4-expected.txt index bed72d5ed11b89f0c4e5a6bdd14300794738428f..beb0f9de571c0db777b146fd15c7af262a494110 100644 --- a/ets2panda/test/compiler/ets/identifierReference4-expected.txt +++ b/ets2panda/test/compiler/ets/identifierReference4-expected.txt @@ -90,12 +90,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 19, + "column": 3 }, "end": { - "line": 1, - "column": 1 + "line": 19, + "column": 13 } } }, @@ -689,23 +689,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 16, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 16, + "column": 16 } } }, "loc": { "start": { - "line": 1, + "line": 16, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 16, + "column": 17 } } } @@ -796,12 +796,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 16, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 16, + "column": 11 } } } diff --git a/ets2panda/test/compiler/ets/identifierReference5-expected.txt b/ets2panda/test/compiler/ets/identifierReference5-expected.txt index e0cef05812a4d38732a01afb6743d0801ffbe325..ebaa3df0392c0733bb049e85472606fe1e15c774 100644 --- a/ets2panda/test/compiler/ets/identifierReference5-expected.txt +++ b/ets2panda/test/compiler/ets/identifierReference5-expected.txt @@ -76,12 +76,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 21, + "column": 3 }, "end": { - "line": 1, - "column": 1 + "line": 21, + "column": 13 } } }, @@ -209,12 +209,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 22, + "column": 3 }, "end": { - "line": 1, - "column": 1 + "line": 22, + "column": 23 } } }, diff --git a/ets2panda/test/compiler/ets/inferTypeOfArray-expected.txt b/ets2panda/test/compiler/ets/inferTypeOfArray-expected.txt index 835924e26a17c4e648145487aadfba3402cfb59b..ed3c6dd87d5fd3763b62d4bcef09dfb9a232888a 100644 --- a/ets2panda/test/compiler/ets/inferTypeOfArray-expected.txt +++ b/ets2panda/test/compiler/ets/inferTypeOfArray-expected.txt @@ -106,23 +106,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 16, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 16, + "column": 10 } } }, "loc": { "start": { - "line": 1, + "line": 16, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 16, + "column": 10 } } }, @@ -162,23 +162,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 17, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 17, + "column": 11 } } }, "loc": { "start": { - "line": 1, + "line": 17, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 17, + "column": 11 } } }, @@ -233,23 +233,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 18, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 18, + "column": 14 } } }, "loc": { "start": { - "line": 1, + "line": 18, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 18, + "column": 14 } } }, @@ -332,23 +332,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 19, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 19, + "column": 18 } } }, "loc": { "start": { - "line": 1, + "line": 19, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 19, + "column": 18 } } }, @@ -501,23 +501,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 20, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 20, + "column": 34 } } }, "loc": { "start": { - "line": 1, + "line": 20, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 20, + "column": 34 } } }, @@ -557,23 +557,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 21, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 21, + "column": 11 } } }, "loc": { "start": { - "line": 1, + "line": 21, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 21, + "column": 11 } } }, @@ -671,23 +671,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 22, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 22, + "column": 19 } } }, "loc": { "start": { - "line": 1, + "line": 22, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 22, + "column": 19 } } }, @@ -949,12 +949,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 16, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 16, + "column": 10 } } }, @@ -999,12 +999,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 17, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 17, + "column": 11 } } }, @@ -1064,12 +1064,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 18, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 18, + "column": 14 } } }, @@ -1157,12 +1157,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 19, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 19, + "column": 18 } } }, @@ -1320,12 +1320,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 20, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 20, + "column": 34 } } }, @@ -1370,12 +1370,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 21, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 21, + "column": 11 } } }, @@ -1478,12 +1478,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 22, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 22, + "column": 19 } } } diff --git a/ets2panda/test/compiler/ets/inferTypeOfArrayNegative1-expected.txt b/ets2panda/test/compiler/ets/inferTypeOfArrayNegative1-expected.txt index 88c70a3f2dd27e73d03dcb6a8d6589eb6a39a01d..8f6bb0ae1d0975589b7f81984e15d40d629ba372 100644 --- a/ets2panda/test/compiler/ets/inferTypeOfArrayNegative1-expected.txt +++ b/ets2panda/test/compiler/ets/inferTypeOfArrayNegative1-expected.txt @@ -149,23 +149,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 16, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 16, + "column": 23 } } }, "loc": { "start": { - "line": 1, + "line": 16, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 16, + "column": 23 } } } @@ -300,12 +300,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 16, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 16, + "column": 23 } } } diff --git a/ets2panda/test/compiler/ets/inferTypeOfArrayNegative2-expected.txt b/ets2panda/test/compiler/ets/inferTypeOfArrayNegative2-expected.txt index 8a219b90aaeaeb70f5101732898f1bfc95b46cc7..be6fbf6957dc573b9d43b407d70f4a2a4be7deca 100644 --- a/ets2panda/test/compiler/ets/inferTypeOfArrayNegative2-expected.txt +++ b/ets2panda/test/compiler/ets/inferTypeOfArrayNegative2-expected.txt @@ -106,23 +106,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 16, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 16, + "column": 11 } } }, "loc": { "start": { - "line": 1, + "line": 16, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 16, + "column": 11 } } }, @@ -420,23 +420,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 19, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 19, + "column": 20 } } }, "loc": { "start": { - "line": 1, + "line": 19, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 19, + "column": 20 } } } @@ -528,12 +528,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 16, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 16, + "column": 11 } } }, @@ -666,12 +666,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 19, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 19, + "column": 20 } } } diff --git a/ets2panda/test/compiler/ets/inferTypeOfArrayNegative3-expected.txt b/ets2panda/test/compiler/ets/inferTypeOfArrayNegative3-expected.txt index aca5d358ee60330e2d0ffb7355d4224539765564..6b9887c2443957e1e61566b49f2c8077b5b809e5 100644 --- a/ets2panda/test/compiler/ets/inferTypeOfArrayNegative3-expected.txt +++ b/ets2panda/test/compiler/ets/inferTypeOfArrayNegative3-expected.txt @@ -149,23 +149,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 16, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 16, + "column": 18 } } }, "loc": { "start": { - "line": 1, + "line": 16, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 16, + "column": 18 } } }, @@ -385,12 +385,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 16, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 16, + "column": 18 } } } diff --git a/ets2panda/test/compiler/ets/infinityNarrowing-expected.txt b/ets2panda/test/compiler/ets/infinityNarrowing-expected.txt index 15762d56248fd9d3714a8e176cddbba1c326798c..0e8ee965c51ef83140341a2831267caee8114ed2 100644 --- a/ets2panda/test/compiler/ets/infinityNarrowing-expected.txt +++ b/ets2panda/test/compiler/ets/infinityNarrowing-expected.txt @@ -198,12 +198,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 16, + "column": 14 }, "end": { - "line": 1, - "column": 1 + "line": 16, + "column": 41 } } }, @@ -289,12 +289,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 17, + "column": 14 }, "end": { - "line": 1, - "column": 1 + "line": 17, + "column": 39 } } }, @@ -380,12 +380,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 18, + "column": 14 }, "end": { - "line": 1, - "column": 1 + "line": 18, + "column": 41 } } } diff --git a/ets2panda/test/compiler/ets/invalidInheritance1-expected.txt b/ets2panda/test/compiler/ets/invalidInheritance1-expected.txt index c352a2bbf8d8919eeaa6bbc20989e755c08b8c61..035dd5dd21c1153e965fd16b527ba91e0703095a 100644 --- a/ets2panda/test/compiler/ets/invalidInheritance1-expected.txt +++ b/ets2panda/test/compiler/ets/invalidInheritance1-expected.txt @@ -76,12 +76,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 17, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 17, + "column": 15 } } }, diff --git a/ets2panda/test/compiler/ets/invalidInheritance3-expected.txt b/ets2panda/test/compiler/ets/invalidInheritance3-expected.txt index b51e8ebc28d9b4a9e7dfda61e70054c0e946f267..bb1005989a0af56b8f0cdd76857e7d4a8184ac95 100644 --- a/ets2panda/test/compiler/ets/invalidInheritance3-expected.txt +++ b/ets2panda/test/compiler/ets/invalidInheritance3-expected.txt @@ -187,12 +187,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 17, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 17, + "column": 33 } } }, @@ -427,12 +427,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 21, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 21, + "column": 15 } } }, diff --git a/ets2panda/test/compiler/ets/invalidPrivateAccess1-expected.txt b/ets2panda/test/compiler/ets/invalidPrivateAccess1-expected.txt index 050eafacd6e78562b37a13570083d4b2c800ed71..f902846d03329cbaf2f6f287b0d0a254703358b1 100644 --- a/ets2panda/test/compiler/ets/invalidPrivateAccess1-expected.txt +++ b/ets2panda/test/compiler/ets/invalidPrivateAccess1-expected.txt @@ -76,12 +76,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 17, + "column": 13 }, "end": { - "line": 1, - "column": 1 + "line": 17, + "column": 23 } } }, @@ -139,12 +139,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 18, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 18, + "column": 15 } } }, diff --git a/ets2panda/test/compiler/ets/invalidPrivateAccess2-expected.txt b/ets2panda/test/compiler/ets/invalidPrivateAccess2-expected.txt index 363fb01a7035caaf6ce91eb80df139c7611b0439..37596af9b0411671162bed3285e0892dfc1935ef 100644 --- a/ets2panda/test/compiler/ets/invalidPrivateAccess2-expected.txt +++ b/ets2panda/test/compiler/ets/invalidPrivateAccess2-expected.txt @@ -255,12 +255,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 21, + "column": 13 }, "end": { - "line": 1, - "column": 1 + "line": 21, + "column": 23 } } } diff --git a/ets2panda/test/compiler/ets/invalidPrivateAccess3-expected.txt b/ets2panda/test/compiler/ets/invalidPrivateAccess3-expected.txt index 2d7478d6bbb74531046405fff69057d2ebc6ff1c..7a5181e8f833dcd0efe9e484c626a4c8b470c3a3 100644 --- a/ets2panda/test/compiler/ets/invalidPrivateAccess3-expected.txt +++ b/ets2panda/test/compiler/ets/invalidPrivateAccess3-expected.txt @@ -255,12 +255,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 21, + "column": 13 }, "end": { - "line": 1, - "column": 1 + "line": 21, + "column": 23 } } }, diff --git a/ets2panda/test/compiler/ets/invalidPrivateAccess4-expected.txt b/ets2panda/test/compiler/ets/invalidPrivateAccess4-expected.txt index e32a0fe8b363c29033f82de27e2524ebcfc9828a..661b94b89bb836625aa5045129f81acd6c1a15c1 100644 --- a/ets2panda/test/compiler/ets/invalidPrivateAccess4-expected.txt +++ b/ets2panda/test/compiler/ets/invalidPrivateAccess4-expected.txt @@ -76,12 +76,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 17, + "column": 13 }, "end": { - "line": 1, - "column": 1 + "line": 17, + "column": 23 } } }, diff --git a/ets2panda/test/compiler/ets/invalidProtectedAccess1-expected.txt b/ets2panda/test/compiler/ets/invalidProtectedAccess1-expected.txt index 5614525b4dd15844890c659c258b6e5ad78d0da4..013fcfafc4406c822305c7b524edcaa704178a9e 100644 --- a/ets2panda/test/compiler/ets/invalidProtectedAccess1-expected.txt +++ b/ets2panda/test/compiler/ets/invalidProtectedAccess1-expected.txt @@ -76,12 +76,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 17, + "column": 15 }, "end": { - "line": 1, - "column": 1 + "line": 17, + "column": 26 } } }, @@ -139,12 +139,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 18, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 18, + "column": 16 } } }, diff --git a/ets2panda/test/compiler/ets/invalidProtectedAccess2-expected.txt b/ets2panda/test/compiler/ets/invalidProtectedAccess2-expected.txt index e0a657b55a3c1182d8c7e98a0f75da005ef5f5c2..e7356eb49ac88663605c00760fdfa126b2da8113 100644 --- a/ets2panda/test/compiler/ets/invalidProtectedAccess2-expected.txt +++ b/ets2panda/test/compiler/ets/invalidProtectedAccess2-expected.txt @@ -255,12 +255,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 21, + "column": 13 }, "end": { - "line": 1, - "column": 1 + "line": 21, + "column": 24 } } } diff --git a/ets2panda/test/compiler/ets/invalidProtectedAccess3-expected.txt b/ets2panda/test/compiler/ets/invalidProtectedAccess3-expected.txt index a3ba983dd75bc6a2498dfdae3e64ad4d1d57ee4f..fa41a9e7db8e6ea6dfb79ef3d996be4a197c9388 100644 --- a/ets2panda/test/compiler/ets/invalidProtectedAccess3-expected.txt +++ b/ets2panda/test/compiler/ets/invalidProtectedAccess3-expected.txt @@ -255,12 +255,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 21, + "column": 13 }, "end": { - "line": 1, - "column": 1 + "line": 21, + "column": 24 } } }, diff --git a/ets2panda/test/compiler/ets/lambdaFunction1-expected.txt b/ets2panda/test/compiler/ets/lambdaFunction1-expected.txt index 22a3b73a7aeabb59eb9a14bbf64c3778db3c2b05..132a58cca84c259f538604a00d25b0fbf40fcfb9 100644 --- a/ets2panda/test/compiler/ets/lambdaFunction1-expected.txt +++ b/ets2panda/test/compiler/ets/lambdaFunction1-expected.txt @@ -553,12 +553,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 34, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 36, + "column": 6 } } }, @@ -783,23 +783,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 16, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 16, + "column": 15 } } }, "loc": { "start": { - "line": 1, + "line": 16, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 16, + "column": 16 } } } @@ -890,12 +890,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 16, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 16, + "column": 11 } } }, @@ -1083,12 +1083,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 18, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 21, + "column": 2 } } }, diff --git a/ets2panda/test/compiler/ets/lambdaFunction4-expected.txt b/ets2panda/test/compiler/ets/lambdaFunction4-expected.txt index 1dc4a6da9a133b7a9ffcb444516db13c20737e51..581964183a2641672a9bbc8fde3b4fe0532fe59b 100644 --- a/ets2panda/test/compiler/ets/lambdaFunction4-expected.txt +++ b/ets2panda/test/compiler/ets/lambdaFunction4-expected.txt @@ -104,12 +104,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 17, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 17, + "column": 22 } } }, @@ -353,12 +353,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 19, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 21, + "column": 6 } } }, diff --git a/ets2panda/test/compiler/ets/lambdaFunction5-expected.txt b/ets2panda/test/compiler/ets/lambdaFunction5-expected.txt index 2cae57f050c12f9206ee759d2fff9109c6cac46a..131a90f02e35ec70e1ef761fb09451a38ed0d508 100644 --- a/ets2panda/test/compiler/ets/lambdaFunction5-expected.txt +++ b/ets2panda/test/compiler/ets/lambdaFunction5-expected.txt @@ -63,12 +63,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 17, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 17, + "column": 10 } } }, @@ -437,12 +437,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 19, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 21, + "column": 6 } } }, diff --git a/ets2panda/test/compiler/ets/launch_expression-expected.txt b/ets2panda/test/compiler/ets/launch_expression-expected.txt index 943aa3142140f683aabf5d6270246626eb436d73..ef4e77e94292a46fcb1550c006cc52d5d3b59384 100644 --- a/ets2panda/test/compiler/ets/launch_expression-expected.txt +++ b/ets2panda/test/compiler/ets/launch_expression-expected.txt @@ -106,23 +106,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 16, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 16, + "column": 14 } } }, "loc": { "start": { - "line": 1, + "line": 16, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 16, + "column": 14 } } }, @@ -162,23 +162,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 17, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 17, + "column": 10 } } }, "loc": { "start": { - "line": 1, + "line": 17, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 17, + "column": 10 } } }, @@ -245,23 +245,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 18, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 18, + "column": 30 } } }, "loc": { "start": { - "line": 1, + "line": 18, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 18, + "column": 31 } } }, @@ -328,23 +328,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 19, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 19, + "column": 30 } } }, "loc": { "start": { - "line": 1, + "line": 19, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 19, + "column": 31 } } } @@ -436,12 +436,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 16, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 16, + "column": 14 } } }, @@ -486,12 +486,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 17, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 17, + "column": 10 } } }, @@ -548,12 +548,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 18, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 18, + "column": 15 } } }, @@ -610,12 +610,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 19, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 19, + "column": 15 } } }, diff --git a/ets2panda/test/compiler/ets/loopWithinLambda-expected.txt b/ets2panda/test/compiler/ets/loopWithinLambda-expected.txt index 9c9103dccf00b6d76e65386ee61d42021ea14ca0..520b7c45cc2609b062daec9d91f721d5e9c14959 100644 --- a/ets2panda/test/compiler/ets/loopWithinLambda-expected.txt +++ b/ets2panda/test/compiler/ets/loopWithinLambda-expected.txt @@ -1390,12 +1390,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 20, + "column": 7 }, "end": { - "line": 1, - "column": 1 + "line": 25, + "column": 2 } } }, diff --git a/ets2panda/test/compiler/ets/manyLocalsParamRegUsage-expected.txt b/ets2panda/test/compiler/ets/manyLocalsParamRegUsage-expected.txt index 0420e8c4b96b71d6e36ac2179941af5bdd885130..9c8d5790d23a90e3ee6a20cb67a84306d46f7edd 100644 --- a/ets2panda/test/compiler/ets/manyLocalsParamRegUsage-expected.txt +++ b/ets2panda/test/compiler/ets/manyLocalsParamRegUsage-expected.txt @@ -10697,12 +10697,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 280, + "column": 12 }, "end": { - "line": 1, - "column": 1 + "line": 280, + "column": 18 } } }, @@ -14373,12 +14373,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 281, + "column": 12 }, "end": { - "line": 1, - "column": 1 + "line": 538, + "column": 7 } } }, diff --git a/ets2panda/test/compiler/ets/method-resolution-class-and-interface-in-signatures_1-expected.txt b/ets2panda/test/compiler/ets/method-resolution-class-and-interface-in-signatures_1-expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..f30d48b4dac54ccd8fac1cdbe1b0b408f4a07e5b --- /dev/null +++ b/ets2panda/test/compiler/ets/method-resolution-class-and-interface-in-signatures_1-expected.txt @@ -0,0 +1,2409 @@ +{ + "type": "Program", + "statements": [ + { + "type": "TSInterfaceDeclaration", + "body": { + "type": "TSInterfaceBody", + "body": [], + "loc": { + "start": { + "line": 16, + "column": 13 + }, + "end": { + "line": 16, + "column": 15 + } + } + }, + "id": { + "type": "Identifier", + "name": "I", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 11 + }, + "end": { + "line": 16, + "column": 12 + } + } + }, + "extends": [], + "loc": { + "start": { + "line": 16, + "column": 1 + }, + "end": { + "line": 17, + "column": 10 + } + } + }, + { + "type": "TSInterfaceDeclaration", + "body": { + "type": "TSInterfaceBody", + "body": [], + "loc": { + "start": { + "line": 17, + "column": 13 + }, + "end": { + "line": 17, + "column": 15 + } + } + }, + "id": { + "type": "Identifier", + "name": "J", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 11 + }, + "end": { + "line": 17, + "column": 12 + } + } + }, + "extends": [], + "loc": { + "start": { + "line": 17, + "column": 1 + }, + "end": { + "line": 18, + "column": 10 + } + } + }, + { + "type": "TSInterfaceDeclaration", + "body": { + "type": "TSInterfaceBody", + "body": [], + "loc": { + "start": { + "line": 18, + "column": 13 + }, + "end": { + "line": 18, + "column": 15 + } + } + }, + "id": { + "type": "Identifier", + "name": "K", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 11 + }, + "end": { + "line": 18, + "column": 12 + } + } + }, + "extends": [], + "loc": { + "start": { + "line": 18, + "column": 1 + }, + "end": { + "line": 19, + "column": 6 + } + } + }, + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "A", + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 7 + }, + "end": { + "line": 19, + "column": 8 + } + } + }, + "superClass": null, + "implements": [ + { + "type": "TSClassImplements", + "expression": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "J", + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 20 + }, + "end": { + "line": 19, + "column": 21 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 20 + }, + "end": { + "line": 19, + "column": 23 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 20 + }, + "end": { + "line": 19, + "column": 23 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 20 + }, + "end": { + "line": 19, + "column": 23 + } + } + } + ], + "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "constructor", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "constructor", + "static": false, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "constructor", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 24 + }, + "end": { + "line": 19, + "column": 24 + } + } + } + ], + "loc": { + "start": { + "line": 19, + "column": 22 + }, + "end": { + "line": 19, + "column": 24 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 1 + }, + "end": { + "line": 19, + "column": 24 + } + } + }, + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "B", + "decorators": [], + "loc": { + "start": { + "line": 20, + "column": 7 + }, + "end": { + "line": 20, + "column": 8 + } + } + }, + "superClass": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "A", + "decorators": [], + "loc": { + "start": { + "line": 20, + "column": 17 + }, + "end": { + "line": 20, + "column": 18 + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 17 + }, + "end": { + "line": 20, + "column": 20 + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 17 + }, + "end": { + "line": 20, + "column": 20 + } + } + }, + "implements": [], + "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "constructor", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "constructor", + "static": false, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "constructor", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 20, + "column": 21 + }, + "end": { + "line": 20, + "column": 21 + } + } + } + ], + "loc": { + "start": { + "line": 20, + "column": 19 + }, + "end": { + "line": 20, + "column": 21 + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 1 + }, + "end": { + "line": 20, + "column": 21 + } + } + }, + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "C", + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 7 + }, + "end": { + "line": 21, + "column": 8 + } + } + }, + "superClass": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "B", + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 17 + }, + "end": { + "line": 21, + "column": 18 + } + } + }, + "loc": { + "start": { + "line": 21, + "column": 17 + }, + "end": { + "line": 21, + "column": 29 + } + } + }, + "loc": { + "start": { + "line": 21, + "column": 17 + }, + "end": { + "line": 21, + "column": 29 + } + } + }, + "implements": [ + { + "type": "TSClassImplements", + "expression": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "I", + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 30 + }, + "end": { + "line": 21, + "column": 31 + } + } + }, + "loc": { + "start": { + "line": 21, + "column": 30 + }, + "end": { + "line": 21, + "column": 33 + } + } + }, + "loc": { + "start": { + "line": 21, + "column": 30 + }, + "end": { + "line": 21, + "column": 33 + } + } + }, + "loc": { + "start": { + "line": 21, + "column": 30 + }, + "end": { + "line": 21, + "column": 33 + } + } + } + ], + "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "constructor", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "constructor", + "static": false, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "constructor", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 34 + }, + "end": { + "line": 21, + "column": 34 + } + } + } + ], + "loc": { + "start": { + "line": 21, + "column": 32 + }, + "end": { + "line": 21, + "column": 34 + } + } + }, + "loc": { + "start": { + "line": 21, + "column": 1 + }, + "end": { + "line": 21, + "column": 34 + } + } + }, + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "D", + "decorators": [], + "loc": { + "start": { + "line": 22, + "column": 7 + }, + "end": { + "line": 22, + "column": 8 + } + } + }, + "superClass": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "C", + "decorators": [], + "loc": { + "start": { + "line": 22, + "column": 17 + }, + "end": { + "line": 22, + "column": 18 + } + } + }, + "loc": { + "start": { + "line": 22, + "column": 17 + }, + "end": { + "line": 22, + "column": 20 + } + } + }, + "loc": { + "start": { + "line": 22, + "column": 17 + }, + "end": { + "line": 22, + "column": 20 + } + } + }, + "implements": [], + "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "constructor", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "constructor", + "static": false, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "constructor", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 22, + "column": 21 + }, + "end": { + "line": 22, + "column": 21 + } + } + } + ], + "loc": { + "start": { + "line": 22, + "column": 19 + }, + "end": { + "line": 22, + "column": 21 + } + } + }, + "loc": { + "start": { + "line": 22, + "column": 1 + }, + "end": { + "line": 22, + "column": 21 + } + } + }, + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "ETSGLOBAL", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "superClass": null, + "implements": [], + "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "_$init$_", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "_$init$_", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "foo", + "decorators": [], + "loc": { + "start": { + "line": 24, + "column": 10 + }, + "end": { + "line": 24, + "column": 13 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "foo", + "decorators": [], + "loc": { + "start": { + "line": 24, + "column": 10 + }, + "end": { + "line": 24, + "column": 13 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [ + { + "type": "ETSParameterExpression", + "name": { + "type": "Identifier", + "name": "x", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "I", + "decorators": [], + "loc": { + "start": { + "line": 24, + "column": 17 + }, + "end": { + "line": 24, + "column": 18 + } + } + }, + "loc": { + "start": { + "line": 24, + "column": 17 + }, + "end": { + "line": 24, + "column": 19 + } + } + }, + "loc": { + "start": { + "line": 24, + "column": 17 + }, + "end": { + "line": 24, + "column": 19 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 24, + "column": 14 + }, + "end": { + "line": 24, + "column": 19 + } + } + }, + "loc": { + "start": { + "line": 24, + "column": 14 + }, + "end": { + "line": 24, + "column": 19 + } + } + } + ], + "returnType": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "string", + "decorators": [], + "loc": { + "start": { + "line": 24, + "column": 21 + }, + "end": { + "line": 24, + "column": 27 + } + } + }, + "loc": { + "start": { + "line": 24, + "column": 21 + }, + "end": { + "line": 24, + "column": 29 + } + } + }, + "loc": { + "start": { + "line": 24, + "column": 21 + }, + "end": { + "line": 24, + "column": 29 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "ReturnStatement", + "argument": { + "type": "StringLiteral", + "value": "I", + "loc": { + "start": { + "line": 25, + "column": 12 + }, + "end": { + "line": 25, + "column": 15 + } + } + }, + "loc": { + "start": { + "line": 25, + "column": 5 + }, + "end": { + "line": 25, + "column": 16 + } + } + } + ], + "loc": { + "start": { + "line": 24, + "column": 28 + }, + "end": { + "line": 26, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 24, + "column": 13 + }, + "end": { + "line": 26, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 24, + "column": 13 + }, + "end": { + "line": 26, + "column": 2 + } + } + }, + "overloads": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "foo", + "decorators": [], + "loc": { + "start": { + "line": 27, + "column": 10 + }, + "end": { + "line": 27, + "column": 13 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "foo", + "decorators": [], + "loc": { + "start": { + "line": 27, + "column": 10 + }, + "end": { + "line": 27, + "column": 13 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [ + { + "type": "ETSParameterExpression", + "name": { + "type": "Identifier", + "name": "x", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "J", + "decorators": [], + "loc": { + "start": { + "line": 27, + "column": 17 + }, + "end": { + "line": 27, + "column": 18 + } + } + }, + "loc": { + "start": { + "line": 27, + "column": 17 + }, + "end": { + "line": 27, + "column": 19 + } + } + }, + "loc": { + "start": { + "line": 27, + "column": 17 + }, + "end": { + "line": 27, + "column": 19 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 27, + "column": 14 + }, + "end": { + "line": 27, + "column": 19 + } + } + }, + "loc": { + "start": { + "line": 27, + "column": 14 + }, + "end": { + "line": 27, + "column": 19 + } + } + } + ], + "returnType": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "string", + "decorators": [], + "loc": { + "start": { + "line": 27, + "column": 21 + }, + "end": { + "line": 27, + "column": 27 + } + } + }, + "loc": { + "start": { + "line": 27, + "column": 21 + }, + "end": { + "line": 27, + "column": 29 + } + } + }, + "loc": { + "start": { + "line": 27, + "column": 21 + }, + "end": { + "line": 27, + "column": 29 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "ReturnStatement", + "argument": { + "type": "StringLiteral", + "value": "J", + "loc": { + "start": { + "line": 28, + "column": 12 + }, + "end": { + "line": 28, + "column": 15 + } + } + }, + "loc": { + "start": { + "line": 28, + "column": 5 + }, + "end": { + "line": 28, + "column": 16 + } + } + } + ], + "loc": { + "start": { + "line": 27, + "column": 28 + }, + "end": { + "line": 29, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 27, + "column": 13 + }, + "end": { + "line": 29, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 27, + "column": 13 + }, + "end": { + "line": 29, + "column": 2 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 27, + "column": 1 + }, + "end": { + "line": 29, + "column": 2 + } + } + }, + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "foo", + "decorators": [], + "loc": { + "start": { + "line": 30, + "column": 10 + }, + "end": { + "line": 30, + "column": 13 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "foo", + "decorators": [], + "loc": { + "start": { + "line": 30, + "column": 10 + }, + "end": { + "line": 30, + "column": 13 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [ + { + "type": "ETSParameterExpression", + "name": { + "type": "Identifier", + "name": "x", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "D", + "decorators": [], + "loc": { + "start": { + "line": 30, + "column": 17 + }, + "end": { + "line": 30, + "column": 18 + } + } + }, + "loc": { + "start": { + "line": 30, + "column": 17 + }, + "end": { + "line": 30, + "column": 19 + } + } + }, + "loc": { + "start": { + "line": 30, + "column": 17 + }, + "end": { + "line": 30, + "column": 19 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 30, + "column": 14 + }, + "end": { + "line": 30, + "column": 19 + } + } + }, + "loc": { + "start": { + "line": 30, + "column": 14 + }, + "end": { + "line": 30, + "column": 19 + } + } + } + ], + "returnType": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "string", + "decorators": [], + "loc": { + "start": { + "line": 30, + "column": 21 + }, + "end": { + "line": 30, + "column": 27 + } + } + }, + "loc": { + "start": { + "line": 30, + "column": 21 + }, + "end": { + "line": 30, + "column": 29 + } + } + }, + "loc": { + "start": { + "line": 30, + "column": 21 + }, + "end": { + "line": 30, + "column": 29 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "ReturnStatement", + "argument": { + "type": "StringLiteral", + "value": "D", + "loc": { + "start": { + "line": 31, + "column": 12 + }, + "end": { + "line": 31, + "column": 15 + } + } + }, + "loc": { + "start": { + "line": 31, + "column": 5 + }, + "end": { + "line": 31, + "column": 16 + } + } + } + ], + "loc": { + "start": { + "line": 30, + "column": 28 + }, + "end": { + "line": 32, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 30, + "column": 13 + }, + "end": { + "line": 32, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 30, + "column": 13 + }, + "end": { + "line": 32, + "column": 2 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 30, + "column": 1 + }, + "end": { + "line": 32, + "column": 2 + } + } + } + ], + "decorators": [], + "loc": { + "start": { + "line": 24, + "column": 1 + }, + "end": { + "line": 26, + "column": 2 + } + } + }, + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 34, + "column": 10 + }, + "end": { + "line": 34, + "column": 14 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 34, + "column": 10 + }, + "end": { + "line": 34, + "column": 14 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "returnType": { + "type": "ETSPrimitiveType", + "loc": { + "start": { + "line": 34, + "column": 18 + }, + "end": { + "line": 34, + "column": 21 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "a", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "string", + "decorators": [], + "loc": { + "start": { + "line": 35, + "column": 13 + }, + "end": { + "line": 35, + "column": 19 + } + } + }, + "loc": { + "start": { + "line": 35, + "column": 13 + }, + "end": { + "line": 35, + "column": 21 + } + } + }, + "loc": { + "start": { + "line": 35, + "column": 13 + }, + "end": { + "line": 35, + "column": 21 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 35, + "column": 9 + }, + "end": { + "line": 35, + "column": 10 + } + } + }, + "init": { + "type": "CallExpression", + "callee": { + "type": "Identifier", + "name": "foo", + "decorators": [], + "loc": { + "start": { + "line": 35, + "column": 22 + }, + "end": { + "line": 35, + "column": 25 + } + } + }, + "arguments": [ + { + "type": "ETSNewClassInstanceExpression", + "typeReference": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "A", + "decorators": [], + "loc": { + "start": { + "line": 35, + "column": 30 + }, + "end": { + "line": 35, + "column": 31 + } + } + }, + "loc": { + "start": { + "line": 35, + "column": 30 + }, + "end": { + "line": 35, + "column": 32 + } + } + }, + "loc": { + "start": { + "line": 35, + "column": 30 + }, + "end": { + "line": 35, + "column": 32 + } + } + }, + "arguments": [], + "loc": { + "start": { + "line": 35, + "column": 26 + }, + "end": { + "line": 35, + "column": 34 + } + } + } + ], + "optional": false, + "loc": { + "start": { + "line": 35, + "column": 22 + }, + "end": { + "line": 35, + "column": 34 + } + } + }, + "loc": { + "start": { + "line": 35, + "column": 9 + }, + "end": { + "line": 35, + "column": 34 + } + } + } + ], + "kind": "let", + "loc": { + "start": { + "line": 35, + "column": 5 + }, + "end": { + "line": 35, + "column": 35 + } + } + }, + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "b", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "string", + "decorators": [], + "loc": { + "start": { + "line": 36, + "column": 13 + }, + "end": { + "line": 36, + "column": 19 + } + } + }, + "loc": { + "start": { + "line": 36, + "column": 13 + }, + "end": { + "line": 36, + "column": 21 + } + } + }, + "loc": { + "start": { + "line": 36, + "column": 13 + }, + "end": { + "line": 36, + "column": 21 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 36, + "column": 9 + }, + "end": { + "line": 36, + "column": 10 + } + } + }, + "init": { + "type": "CallExpression", + "callee": { + "type": "Identifier", + "name": "foo", + "decorators": [], + "loc": { + "start": { + "line": 36, + "column": 22 + }, + "end": { + "line": 36, + "column": 25 + } + } + }, + "arguments": [ + { + "type": "ETSNewClassInstanceExpression", + "typeReference": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "B", + "decorators": [], + "loc": { + "start": { + "line": 36, + "column": 30 + }, + "end": { + "line": 36, + "column": 31 + } + } + }, + "loc": { + "start": { + "line": 36, + "column": 30 + }, + "end": { + "line": 36, + "column": 32 + } + } + }, + "loc": { + "start": { + "line": 36, + "column": 30 + }, + "end": { + "line": 36, + "column": 32 + } + } + }, + "arguments": [], + "loc": { + "start": { + "line": 36, + "column": 26 + }, + "end": { + "line": 36, + "column": 34 + } + } + } + ], + "optional": false, + "loc": { + "start": { + "line": 36, + "column": 22 + }, + "end": { + "line": 36, + "column": 34 + } + } + }, + "loc": { + "start": { + "line": 36, + "column": 9 + }, + "end": { + "line": 36, + "column": 34 + } + } + } + ], + "kind": "let", + "loc": { + "start": { + "line": 36, + "column": 5 + }, + "end": { + "line": 36, + "column": 35 + } + } + }, + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "c", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "string", + "decorators": [], + "loc": { + "start": { + "line": 37, + "column": 13 + }, + "end": { + "line": 37, + "column": 19 + } + } + }, + "loc": { + "start": { + "line": 37, + "column": 13 + }, + "end": { + "line": 37, + "column": 21 + } + } + }, + "loc": { + "start": { + "line": 37, + "column": 13 + }, + "end": { + "line": 37, + "column": 21 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 37, + "column": 9 + }, + "end": { + "line": 37, + "column": 10 + } + } + }, + "init": { + "type": "CallExpression", + "callee": { + "type": "Identifier", + "name": "foo", + "decorators": [], + "loc": { + "start": { + "line": 37, + "column": 22 + }, + "end": { + "line": 37, + "column": 25 + } + } + }, + "arguments": [ + { + "type": "ETSNewClassInstanceExpression", + "typeReference": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "C", + "decorators": [], + "loc": { + "start": { + "line": 37, + "column": 30 + }, + "end": { + "line": 37, + "column": 31 + } + } + }, + "loc": { + "start": { + "line": 37, + "column": 30 + }, + "end": { + "line": 37, + "column": 32 + } + } + }, + "loc": { + "start": { + "line": 37, + "column": 30 + }, + "end": { + "line": 37, + "column": 32 + } + } + }, + "arguments": [], + "loc": { + "start": { + "line": 37, + "column": 26 + }, + "end": { + "line": 37, + "column": 34 + } + } + } + ], + "optional": false, + "loc": { + "start": { + "line": 37, + "column": 22 + }, + "end": { + "line": 37, + "column": 34 + } + } + }, + "loc": { + "start": { + "line": 37, + "column": 9 + }, + "end": { + "line": 37, + "column": 34 + } + } + } + ], + "kind": "let", + "loc": { + "start": { + "line": 37, + "column": 5 + }, + "end": { + "line": 37, + "column": 35 + } + } + }, + { + "type": "ReturnStatement", + "argument": { + "type": "NumberLiteral", + "value": 0, + "loc": { + "start": { + "line": 38, + "column": 12 + }, + "end": { + "line": 38, + "column": 13 + } + } + }, + "loc": { + "start": { + "line": 38, + "column": 5 + }, + "end": { + "line": 38, + "column": 14 + } + } + } + ], + "loc": { + "start": { + "line": 34, + "column": 22 + }, + "end": { + "line": 39, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 34, + "column": 14 + }, + "end": { + "line": 39, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 34, + "column": 14 + }, + "end": { + "line": 39, + "column": 2 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 34, + "column": 1 + }, + "end": { + "line": 39, + "column": 2 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 41, + "column": 1 + } + } +} +TypeError: Call to `foo` is ambiguous as `2` versions of `foo` are available: `foo(x: I): String` and `foo(x: J): String` [method-resolution-class-and-interface-in-signatures_1.ets:37:22] diff --git a/ets2panda/test/compiler/ets/method-resolution-class-and-interface-in-signatures_1.ets b/ets2panda/test/compiler/ets/method-resolution-class-and-interface-in-signatures_1.ets new file mode 100644 index 0000000000000000000000000000000000000000..2cf7a458b711d4b28164da551d23a6c60655df72 --- /dev/null +++ b/ets2panda/test/compiler/ets/method-resolution-class-and-interface-in-signatures_1.ets @@ -0,0 +1,40 @@ +/* + * 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. + */ + +interface I {} +interface J {} +interface K {} +class A implements J {} +class B extends A {} +class C extends B implements I {} +class D extends C {} + +function foo(x: I): string { + return "I"; +} +function foo(x: J): string { + return "J"; +} +function foo(x: D): string { + return "D"; +} + +function main(): int { + let a : string = foo(new A()); + let b : string = foo(new B()); + let c : string = foo(new C()); + return 0; +} + diff --git a/ets2panda/test/compiler/ets/method-resolution-class-and-interface-in-signatures_2-expected.txt b/ets2panda/test/compiler/ets/method-resolution-class-and-interface-in-signatures_2-expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..095914af28b1db87b1529eddcd30bb278a0ad027 --- /dev/null +++ b/ets2panda/test/compiler/ets/method-resolution-class-and-interface-in-signatures_2-expected.txt @@ -0,0 +1,2409 @@ +{ + "type": "Program", + "statements": [ + { + "type": "TSInterfaceDeclaration", + "body": { + "type": "TSInterfaceBody", + "body": [], + "loc": { + "start": { + "line": 16, + "column": 13 + }, + "end": { + "line": 16, + "column": 15 + } + } + }, + "id": { + "type": "Identifier", + "name": "I", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 11 + }, + "end": { + "line": 16, + "column": 12 + } + } + }, + "extends": [], + "loc": { + "start": { + "line": 16, + "column": 1 + }, + "end": { + "line": 17, + "column": 10 + } + } + }, + { + "type": "TSInterfaceDeclaration", + "body": { + "type": "TSInterfaceBody", + "body": [], + "loc": { + "start": { + "line": 17, + "column": 13 + }, + "end": { + "line": 17, + "column": 15 + } + } + }, + "id": { + "type": "Identifier", + "name": "J", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 11 + }, + "end": { + "line": 17, + "column": 12 + } + } + }, + "extends": [], + "loc": { + "start": { + "line": 17, + "column": 1 + }, + "end": { + "line": 18, + "column": 10 + } + } + }, + { + "type": "TSInterfaceDeclaration", + "body": { + "type": "TSInterfaceBody", + "body": [], + "loc": { + "start": { + "line": 18, + "column": 13 + }, + "end": { + "line": 18, + "column": 15 + } + } + }, + "id": { + "type": "Identifier", + "name": "K", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 11 + }, + "end": { + "line": 18, + "column": 12 + } + } + }, + "extends": [], + "loc": { + "start": { + "line": 18, + "column": 1 + }, + "end": { + "line": 19, + "column": 6 + } + } + }, + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "A", + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 7 + }, + "end": { + "line": 19, + "column": 8 + } + } + }, + "superClass": null, + "implements": [ + { + "type": "TSClassImplements", + "expression": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "J", + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 20 + }, + "end": { + "line": 19, + "column": 21 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 20 + }, + "end": { + "line": 19, + "column": 23 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 20 + }, + "end": { + "line": 19, + "column": 23 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 20 + }, + "end": { + "line": 19, + "column": 23 + } + } + } + ], + "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "constructor", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "constructor", + "static": false, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "constructor", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 24 + }, + "end": { + "line": 19, + "column": 24 + } + } + } + ], + "loc": { + "start": { + "line": 19, + "column": 22 + }, + "end": { + "line": 19, + "column": 24 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 1 + }, + "end": { + "line": 19, + "column": 24 + } + } + }, + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "B", + "decorators": [], + "loc": { + "start": { + "line": 20, + "column": 7 + }, + "end": { + "line": 20, + "column": 8 + } + } + }, + "superClass": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "A", + "decorators": [], + "loc": { + "start": { + "line": 20, + "column": 17 + }, + "end": { + "line": 20, + "column": 18 + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 17 + }, + "end": { + "line": 20, + "column": 20 + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 17 + }, + "end": { + "line": 20, + "column": 20 + } + } + }, + "implements": [], + "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "constructor", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "constructor", + "static": false, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "constructor", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 20, + "column": 21 + }, + "end": { + "line": 20, + "column": 21 + } + } + } + ], + "loc": { + "start": { + "line": 20, + "column": 19 + }, + "end": { + "line": 20, + "column": 21 + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 1 + }, + "end": { + "line": 20, + "column": 21 + } + } + }, + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "C", + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 7 + }, + "end": { + "line": 21, + "column": 8 + } + } + }, + "superClass": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "B", + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 17 + }, + "end": { + "line": 21, + "column": 18 + } + } + }, + "loc": { + "start": { + "line": 21, + "column": 17 + }, + "end": { + "line": 21, + "column": 29 + } + } + }, + "loc": { + "start": { + "line": 21, + "column": 17 + }, + "end": { + "line": 21, + "column": 29 + } + } + }, + "implements": [ + { + "type": "TSClassImplements", + "expression": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "I", + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 30 + }, + "end": { + "line": 21, + "column": 31 + } + } + }, + "loc": { + "start": { + "line": 21, + "column": 30 + }, + "end": { + "line": 21, + "column": 33 + } + } + }, + "loc": { + "start": { + "line": 21, + "column": 30 + }, + "end": { + "line": 21, + "column": 33 + } + } + }, + "loc": { + "start": { + "line": 21, + "column": 30 + }, + "end": { + "line": 21, + "column": 33 + } + } + } + ], + "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "constructor", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "constructor", + "static": false, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "constructor", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 34 + }, + "end": { + "line": 21, + "column": 34 + } + } + } + ], + "loc": { + "start": { + "line": 21, + "column": 32 + }, + "end": { + "line": 21, + "column": 34 + } + } + }, + "loc": { + "start": { + "line": 21, + "column": 1 + }, + "end": { + "line": 21, + "column": 34 + } + } + }, + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "D", + "decorators": [], + "loc": { + "start": { + "line": 22, + "column": 7 + }, + "end": { + "line": 22, + "column": 8 + } + } + }, + "superClass": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "C", + "decorators": [], + "loc": { + "start": { + "line": 22, + "column": 17 + }, + "end": { + "line": 22, + "column": 18 + } + } + }, + "loc": { + "start": { + "line": 22, + "column": 17 + }, + "end": { + "line": 22, + "column": 20 + } + } + }, + "loc": { + "start": { + "line": 22, + "column": 17 + }, + "end": { + "line": 22, + "column": 20 + } + } + }, + "implements": [], + "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "constructor", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "constructor", + "static": false, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "constructor", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 22, + "column": 21 + }, + "end": { + "line": 22, + "column": 21 + } + } + } + ], + "loc": { + "start": { + "line": 22, + "column": 19 + }, + "end": { + "line": 22, + "column": 21 + } + } + }, + "loc": { + "start": { + "line": 22, + "column": 1 + }, + "end": { + "line": 22, + "column": 21 + } + } + }, + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "ETSGLOBAL", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "superClass": null, + "implements": [], + "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "_$init$_", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "_$init$_", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "foo", + "decorators": [], + "loc": { + "start": { + "line": 24, + "column": 10 + }, + "end": { + "line": 24, + "column": 13 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "foo", + "decorators": [], + "loc": { + "start": { + "line": 24, + "column": 10 + }, + "end": { + "line": 24, + "column": 13 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [ + { + "type": "ETSParameterExpression", + "name": { + "type": "Identifier", + "name": "x", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "I", + "decorators": [], + "loc": { + "start": { + "line": 24, + "column": 17 + }, + "end": { + "line": 24, + "column": 18 + } + } + }, + "loc": { + "start": { + "line": 24, + "column": 17 + }, + "end": { + "line": 24, + "column": 19 + } + } + }, + "loc": { + "start": { + "line": 24, + "column": 17 + }, + "end": { + "line": 24, + "column": 19 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 24, + "column": 14 + }, + "end": { + "line": 24, + "column": 19 + } + } + }, + "loc": { + "start": { + "line": 24, + "column": 14 + }, + "end": { + "line": 24, + "column": 19 + } + } + } + ], + "returnType": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "string", + "decorators": [], + "loc": { + "start": { + "line": 24, + "column": 21 + }, + "end": { + "line": 24, + "column": 27 + } + } + }, + "loc": { + "start": { + "line": 24, + "column": 21 + }, + "end": { + "line": 24, + "column": 29 + } + } + }, + "loc": { + "start": { + "line": 24, + "column": 21 + }, + "end": { + "line": 24, + "column": 29 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "ReturnStatement", + "argument": { + "type": "StringLiteral", + "value": "I", + "loc": { + "start": { + "line": 25, + "column": 12 + }, + "end": { + "line": 25, + "column": 15 + } + } + }, + "loc": { + "start": { + "line": 25, + "column": 5 + }, + "end": { + "line": 25, + "column": 16 + } + } + } + ], + "loc": { + "start": { + "line": 24, + "column": 28 + }, + "end": { + "line": 26, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 24, + "column": 13 + }, + "end": { + "line": 26, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 24, + "column": 13 + }, + "end": { + "line": 26, + "column": 2 + } + } + }, + "overloads": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "foo", + "decorators": [], + "loc": { + "start": { + "line": 27, + "column": 10 + }, + "end": { + "line": 27, + "column": 13 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "foo", + "decorators": [], + "loc": { + "start": { + "line": 27, + "column": 10 + }, + "end": { + "line": 27, + "column": 13 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [ + { + "type": "ETSParameterExpression", + "name": { + "type": "Identifier", + "name": "x", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "J", + "decorators": [], + "loc": { + "start": { + "line": 27, + "column": 17 + }, + "end": { + "line": 27, + "column": 18 + } + } + }, + "loc": { + "start": { + "line": 27, + "column": 17 + }, + "end": { + "line": 27, + "column": 19 + } + } + }, + "loc": { + "start": { + "line": 27, + "column": 17 + }, + "end": { + "line": 27, + "column": 19 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 27, + "column": 14 + }, + "end": { + "line": 27, + "column": 19 + } + } + }, + "loc": { + "start": { + "line": 27, + "column": 14 + }, + "end": { + "line": 27, + "column": 19 + } + } + } + ], + "returnType": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "string", + "decorators": [], + "loc": { + "start": { + "line": 27, + "column": 21 + }, + "end": { + "line": 27, + "column": 27 + } + } + }, + "loc": { + "start": { + "line": 27, + "column": 21 + }, + "end": { + "line": 27, + "column": 29 + } + } + }, + "loc": { + "start": { + "line": 27, + "column": 21 + }, + "end": { + "line": 27, + "column": 29 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "ReturnStatement", + "argument": { + "type": "StringLiteral", + "value": "J", + "loc": { + "start": { + "line": 28, + "column": 12 + }, + "end": { + "line": 28, + "column": 15 + } + } + }, + "loc": { + "start": { + "line": 28, + "column": 5 + }, + "end": { + "line": 28, + "column": 16 + } + } + } + ], + "loc": { + "start": { + "line": 27, + "column": 28 + }, + "end": { + "line": 29, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 27, + "column": 13 + }, + "end": { + "line": 29, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 27, + "column": 13 + }, + "end": { + "line": 29, + "column": 2 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 27, + "column": 1 + }, + "end": { + "line": 29, + "column": 2 + } + } + }, + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "foo", + "decorators": [], + "loc": { + "start": { + "line": 30, + "column": 10 + }, + "end": { + "line": 30, + "column": 13 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "foo", + "decorators": [], + "loc": { + "start": { + "line": 30, + "column": 10 + }, + "end": { + "line": 30, + "column": 13 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [ + { + "type": "ETSParameterExpression", + "name": { + "type": "Identifier", + "name": "x", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "B", + "decorators": [], + "loc": { + "start": { + "line": 30, + "column": 17 + }, + "end": { + "line": 30, + "column": 18 + } + } + }, + "loc": { + "start": { + "line": 30, + "column": 17 + }, + "end": { + "line": 30, + "column": 19 + } + } + }, + "loc": { + "start": { + "line": 30, + "column": 17 + }, + "end": { + "line": 30, + "column": 19 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 30, + "column": 14 + }, + "end": { + "line": 30, + "column": 19 + } + } + }, + "loc": { + "start": { + "line": 30, + "column": 14 + }, + "end": { + "line": 30, + "column": 19 + } + } + } + ], + "returnType": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "string", + "decorators": [], + "loc": { + "start": { + "line": 30, + "column": 21 + }, + "end": { + "line": 30, + "column": 27 + } + } + }, + "loc": { + "start": { + "line": 30, + "column": 21 + }, + "end": { + "line": 30, + "column": 29 + } + } + }, + "loc": { + "start": { + "line": 30, + "column": 21 + }, + "end": { + "line": 30, + "column": 29 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "ReturnStatement", + "argument": { + "type": "StringLiteral", + "value": "B", + "loc": { + "start": { + "line": 31, + "column": 12 + }, + "end": { + "line": 31, + "column": 15 + } + } + }, + "loc": { + "start": { + "line": 31, + "column": 5 + }, + "end": { + "line": 31, + "column": 16 + } + } + } + ], + "loc": { + "start": { + "line": 30, + "column": 28 + }, + "end": { + "line": 32, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 30, + "column": 13 + }, + "end": { + "line": 32, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 30, + "column": 13 + }, + "end": { + "line": 32, + "column": 2 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 30, + "column": 1 + }, + "end": { + "line": 32, + "column": 2 + } + } + } + ], + "decorators": [], + "loc": { + "start": { + "line": 24, + "column": 1 + }, + "end": { + "line": 26, + "column": 2 + } + } + }, + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 34, + "column": 10 + }, + "end": { + "line": 34, + "column": 14 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 34, + "column": 10 + }, + "end": { + "line": 34, + "column": 14 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "returnType": { + "type": "ETSPrimitiveType", + "loc": { + "start": { + "line": 34, + "column": 18 + }, + "end": { + "line": 34, + "column": 21 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "a", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "string", + "decorators": [], + "loc": { + "start": { + "line": 35, + "column": 13 + }, + "end": { + "line": 35, + "column": 19 + } + } + }, + "loc": { + "start": { + "line": 35, + "column": 13 + }, + "end": { + "line": 35, + "column": 21 + } + } + }, + "loc": { + "start": { + "line": 35, + "column": 13 + }, + "end": { + "line": 35, + "column": 21 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 35, + "column": 9 + }, + "end": { + "line": 35, + "column": 10 + } + } + }, + "init": { + "type": "CallExpression", + "callee": { + "type": "Identifier", + "name": "foo", + "decorators": [], + "loc": { + "start": { + "line": 35, + "column": 22 + }, + "end": { + "line": 35, + "column": 25 + } + } + }, + "arguments": [ + { + "type": "ETSNewClassInstanceExpression", + "typeReference": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "A", + "decorators": [], + "loc": { + "start": { + "line": 35, + "column": 30 + }, + "end": { + "line": 35, + "column": 31 + } + } + }, + "loc": { + "start": { + "line": 35, + "column": 30 + }, + "end": { + "line": 35, + "column": 32 + } + } + }, + "loc": { + "start": { + "line": 35, + "column": 30 + }, + "end": { + "line": 35, + "column": 32 + } + } + }, + "arguments": [], + "loc": { + "start": { + "line": 35, + "column": 26 + }, + "end": { + "line": 35, + "column": 34 + } + } + } + ], + "optional": false, + "loc": { + "start": { + "line": 35, + "column": 22 + }, + "end": { + "line": 35, + "column": 34 + } + } + }, + "loc": { + "start": { + "line": 35, + "column": 9 + }, + "end": { + "line": 35, + "column": 34 + } + } + } + ], + "kind": "let", + "loc": { + "start": { + "line": 35, + "column": 5 + }, + "end": { + "line": 35, + "column": 35 + } + } + }, + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "b", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "string", + "decorators": [], + "loc": { + "start": { + "line": 36, + "column": 13 + }, + "end": { + "line": 36, + "column": 19 + } + } + }, + "loc": { + "start": { + "line": 36, + "column": 13 + }, + "end": { + "line": 36, + "column": 21 + } + } + }, + "loc": { + "start": { + "line": 36, + "column": 13 + }, + "end": { + "line": 36, + "column": 21 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 36, + "column": 9 + }, + "end": { + "line": 36, + "column": 10 + } + } + }, + "init": { + "type": "CallExpression", + "callee": { + "type": "Identifier", + "name": "foo", + "decorators": [], + "loc": { + "start": { + "line": 36, + "column": 22 + }, + "end": { + "line": 36, + "column": 25 + } + } + }, + "arguments": [ + { + "type": "ETSNewClassInstanceExpression", + "typeReference": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "B", + "decorators": [], + "loc": { + "start": { + "line": 36, + "column": 30 + }, + "end": { + "line": 36, + "column": 31 + } + } + }, + "loc": { + "start": { + "line": 36, + "column": 30 + }, + "end": { + "line": 36, + "column": 32 + } + } + }, + "loc": { + "start": { + "line": 36, + "column": 30 + }, + "end": { + "line": 36, + "column": 32 + } + } + }, + "arguments": [], + "loc": { + "start": { + "line": 36, + "column": 26 + }, + "end": { + "line": 36, + "column": 34 + } + } + } + ], + "optional": false, + "loc": { + "start": { + "line": 36, + "column": 22 + }, + "end": { + "line": 36, + "column": 34 + } + } + }, + "loc": { + "start": { + "line": 36, + "column": 9 + }, + "end": { + "line": 36, + "column": 34 + } + } + } + ], + "kind": "let", + "loc": { + "start": { + "line": 36, + "column": 5 + }, + "end": { + "line": 36, + "column": 35 + } + } + }, + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "d", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "string", + "decorators": [], + "loc": { + "start": { + "line": 37, + "column": 13 + }, + "end": { + "line": 37, + "column": 19 + } + } + }, + "loc": { + "start": { + "line": 37, + "column": 13 + }, + "end": { + "line": 37, + "column": 21 + } + } + }, + "loc": { + "start": { + "line": 37, + "column": 13 + }, + "end": { + "line": 37, + "column": 21 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 37, + "column": 9 + }, + "end": { + "line": 37, + "column": 10 + } + } + }, + "init": { + "type": "CallExpression", + "callee": { + "type": "Identifier", + "name": "foo", + "decorators": [], + "loc": { + "start": { + "line": 37, + "column": 22 + }, + "end": { + "line": 37, + "column": 25 + } + } + }, + "arguments": [ + { + "type": "ETSNewClassInstanceExpression", + "typeReference": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "D", + "decorators": [], + "loc": { + "start": { + "line": 37, + "column": 30 + }, + "end": { + "line": 37, + "column": 31 + } + } + }, + "loc": { + "start": { + "line": 37, + "column": 30 + }, + "end": { + "line": 37, + "column": 32 + } + } + }, + "loc": { + "start": { + "line": 37, + "column": 30 + }, + "end": { + "line": 37, + "column": 32 + } + } + }, + "arguments": [], + "loc": { + "start": { + "line": 37, + "column": 26 + }, + "end": { + "line": 37, + "column": 34 + } + } + } + ], + "optional": false, + "loc": { + "start": { + "line": 37, + "column": 22 + }, + "end": { + "line": 37, + "column": 34 + } + } + }, + "loc": { + "start": { + "line": 37, + "column": 9 + }, + "end": { + "line": 37, + "column": 34 + } + } + } + ], + "kind": "let", + "loc": { + "start": { + "line": 37, + "column": 5 + }, + "end": { + "line": 37, + "column": 35 + } + } + }, + { + "type": "ReturnStatement", + "argument": { + "type": "NumberLiteral", + "value": 0, + "loc": { + "start": { + "line": 38, + "column": 12 + }, + "end": { + "line": 38, + "column": 13 + } + } + }, + "loc": { + "start": { + "line": 38, + "column": 5 + }, + "end": { + "line": 38, + "column": 14 + } + } + } + ], + "loc": { + "start": { + "line": 34, + "column": 22 + }, + "end": { + "line": 39, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 34, + "column": 14 + }, + "end": { + "line": 39, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 34, + "column": 14 + }, + "end": { + "line": 39, + "column": 2 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 34, + "column": 1 + }, + "end": { + "line": 39, + "column": 2 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 41, + "column": 1 + } + } +} +TypeError: Call to `foo` is ambiguous as `2` versions of `foo` are available: `foo(x: B): String` and `foo(x: I): String` [method-resolution-class-and-interface-in-signatures_2.ets:37:22] diff --git a/ets2panda/test/compiler/ets/method-resolution-class-and-interface-in-signatures_2.ets b/ets2panda/test/compiler/ets/method-resolution-class-and-interface-in-signatures_2.ets new file mode 100644 index 0000000000000000000000000000000000000000..c0928f87166814c5482d9831675fbafb4d591548 --- /dev/null +++ b/ets2panda/test/compiler/ets/method-resolution-class-and-interface-in-signatures_2.ets @@ -0,0 +1,40 @@ +/* + * 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. + */ + +interface I {} +interface J {} +interface K {} +class A implements J {} +class B extends A {} +class C extends B implements I {} +class D extends C {} + +function foo(x: I): string { + return "I"; +} +function foo(x: J): string { + return "J"; +} +function foo(x: B): string { + return "B"; +} + +function main(): int { + let a : string = foo(new A()); + let b : string = foo(new B()); + let d : string = foo(new D()); + return 0; +} + diff --git a/ets2panda/test/compiler/ets/method-resolution-class-and-interface-in-signatures_3-expected.txt b/ets2panda/test/compiler/ets/method-resolution-class-and-interface-in-signatures_3-expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..8e8b4891d9c68b1b7cca4bf7ad665092ac3f3d6b --- /dev/null +++ b/ets2panda/test/compiler/ets/method-resolution-class-and-interface-in-signatures_3-expected.txt @@ -0,0 +1,1833 @@ +{ + "type": "Program", + "statements": [ + { + "type": "TSInterfaceDeclaration", + "body": { + "type": "TSInterfaceBody", + "body": [], + "loc": { + "start": { + "line": 16, + "column": 13 + }, + "end": { + "line": 16, + "column": 15 + } + } + }, + "id": { + "type": "Identifier", + "name": "I", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 11 + }, + "end": { + "line": 16, + "column": 12 + } + } + }, + "extends": [], + "loc": { + "start": { + "line": 16, + "column": 1 + }, + "end": { + "line": 17, + "column": 10 + } + } + }, + { + "type": "TSInterfaceDeclaration", + "body": { + "type": "TSInterfaceBody", + "body": [], + "loc": { + "start": { + "line": 17, + "column": 13 + }, + "end": { + "line": 17, + "column": 15 + } + } + }, + "id": { + "type": "Identifier", + "name": "J", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 11 + }, + "end": { + "line": 17, + "column": 12 + } + } + }, + "extends": [], + "loc": { + "start": { + "line": 17, + "column": 1 + }, + "end": { + "line": 18, + "column": 10 + } + } + }, + { + "type": "TSInterfaceDeclaration", + "body": { + "type": "TSInterfaceBody", + "body": [], + "loc": { + "start": { + "line": 18, + "column": 13 + }, + "end": { + "line": 18, + "column": 15 + } + } + }, + "id": { + "type": "Identifier", + "name": "K", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 11 + }, + "end": { + "line": 18, + "column": 12 + } + } + }, + "extends": [], + "loc": { + "start": { + "line": 18, + "column": 1 + }, + "end": { + "line": 19, + "column": 6 + } + } + }, + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "A", + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 7 + }, + "end": { + "line": 19, + "column": 8 + } + } + }, + "superClass": null, + "implements": [], + "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "constructor", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "constructor", + "static": false, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "constructor", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 11 + }, + "end": { + "line": 19, + "column": 11 + } + } + } + ], + "loc": { + "start": { + "line": 19, + "column": 9 + }, + "end": { + "line": 19, + "column": 11 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 1 + }, + "end": { + "line": 19, + "column": 11 + } + } + }, + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "B", + "decorators": [], + "loc": { + "start": { + "line": 20, + "column": 7 + }, + "end": { + "line": 20, + "column": 8 + } + } + }, + "superClass": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "A", + "decorators": [], + "loc": { + "start": { + "line": 20, + "column": 17 + }, + "end": { + "line": 20, + "column": 18 + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 17 + }, + "end": { + "line": 20, + "column": 29 + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 17 + }, + "end": { + "line": 20, + "column": 29 + } + } + }, + "implements": [ + { + "type": "TSClassImplements", + "expression": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "I", + "decorators": [], + "loc": { + "start": { + "line": 20, + "column": 30 + }, + "end": { + "line": 20, + "column": 31 + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 30 + }, + "end": { + "line": 20, + "column": 32 + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 30 + }, + "end": { + "line": 20, + "column": 32 + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 30 + }, + "end": { + "line": 20, + "column": 32 + } + } + }, + { + "type": "TSClassImplements", + "expression": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "J", + "decorators": [], + "loc": { + "start": { + "line": 20, + "column": 33 + }, + "end": { + "line": 20, + "column": 34 + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 33 + }, + "end": { + "line": 20, + "column": 36 + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 33 + }, + "end": { + "line": 20, + "column": 36 + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 33 + }, + "end": { + "line": 20, + "column": 36 + } + } + } + ], + "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "constructor", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "constructor", + "static": false, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "constructor", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 20, + "column": 37 + }, + "end": { + "line": 20, + "column": 37 + } + } + } + ], + "loc": { + "start": { + "line": 20, + "column": 35 + }, + "end": { + "line": 20, + "column": 37 + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 1 + }, + "end": { + "line": 20, + "column": 37 + } + } + }, + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "C", + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 7 + }, + "end": { + "line": 21, + "column": 8 + } + } + }, + "superClass": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "B", + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 17 + }, + "end": { + "line": 21, + "column": 18 + } + } + }, + "loc": { + "start": { + "line": 21, + "column": 17 + }, + "end": { + "line": 21, + "column": 20 + } + } + }, + "loc": { + "start": { + "line": 21, + "column": 17 + }, + "end": { + "line": 21, + "column": 20 + } + } + }, + "implements": [], + "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "constructor", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "constructor", + "static": false, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "constructor", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 21 + }, + "end": { + "line": 21, + "column": 21 + } + } + } + ], + "loc": { + "start": { + "line": 21, + "column": 19 + }, + "end": { + "line": 21, + "column": 21 + } + } + }, + "loc": { + "start": { + "line": 21, + "column": 1 + }, + "end": { + "line": 21, + "column": 21 + } + } + }, + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "D", + "decorators": [], + "loc": { + "start": { + "line": 22, + "column": 7 + }, + "end": { + "line": 22, + "column": 8 + } + } + }, + "superClass": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "C", + "decorators": [], + "loc": { + "start": { + "line": 22, + "column": 17 + }, + "end": { + "line": 22, + "column": 18 + } + } + }, + "loc": { + "start": { + "line": 22, + "column": 17 + }, + "end": { + "line": 22, + "column": 20 + } + } + }, + "loc": { + "start": { + "line": 22, + "column": 17 + }, + "end": { + "line": 22, + "column": 20 + } + } + }, + "implements": [], + "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "constructor", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "constructor", + "static": false, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "constructor", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 22, + "column": 21 + }, + "end": { + "line": 22, + "column": 21 + } + } + } + ], + "loc": { + "start": { + "line": 22, + "column": 19 + }, + "end": { + "line": 22, + "column": 21 + } + } + }, + "loc": { + "start": { + "line": 22, + "column": 1 + }, + "end": { + "line": 22, + "column": 21 + } + } + }, + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "ETSGLOBAL", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "superClass": null, + "implements": [], + "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "_$init$_", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "_$init$_", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "foo", + "decorators": [], + "loc": { + "start": { + "line": 24, + "column": 10 + }, + "end": { + "line": 24, + "column": 13 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "foo", + "decorators": [], + "loc": { + "start": { + "line": 24, + "column": 10 + }, + "end": { + "line": 24, + "column": 13 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [ + { + "type": "ETSParameterExpression", + "name": { + "type": "Identifier", + "name": "x", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "I", + "decorators": [], + "loc": { + "start": { + "line": 24, + "column": 17 + }, + "end": { + "line": 24, + "column": 18 + } + } + }, + "loc": { + "start": { + "line": 24, + "column": 17 + }, + "end": { + "line": 24, + "column": 19 + } + } + }, + "loc": { + "start": { + "line": 24, + "column": 17 + }, + "end": { + "line": 24, + "column": 19 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 24, + "column": 14 + }, + "end": { + "line": 24, + "column": 19 + } + } + }, + "loc": { + "start": { + "line": 24, + "column": 14 + }, + "end": { + "line": 24, + "column": 19 + } + } + } + ], + "returnType": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "string", + "decorators": [], + "loc": { + "start": { + "line": 24, + "column": 21 + }, + "end": { + "line": 24, + "column": 27 + } + } + }, + "loc": { + "start": { + "line": 24, + "column": 21 + }, + "end": { + "line": 24, + "column": 29 + } + } + }, + "loc": { + "start": { + "line": 24, + "column": 21 + }, + "end": { + "line": 24, + "column": 29 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "ReturnStatement", + "argument": { + "type": "StringLiteral", + "value": "I", + "loc": { + "start": { + "line": 25, + "column": 12 + }, + "end": { + "line": 25, + "column": 15 + } + } + }, + "loc": { + "start": { + "line": 25, + "column": 5 + }, + "end": { + "line": 25, + "column": 16 + } + } + } + ], + "loc": { + "start": { + "line": 24, + "column": 28 + }, + "end": { + "line": 26, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 24, + "column": 13 + }, + "end": { + "line": 26, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 24, + "column": 13 + }, + "end": { + "line": 26, + "column": 2 + } + } + }, + "overloads": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "foo", + "decorators": [], + "loc": { + "start": { + "line": 27, + "column": 10 + }, + "end": { + "line": 27, + "column": 13 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "foo", + "decorators": [], + "loc": { + "start": { + "line": 27, + "column": 10 + }, + "end": { + "line": 27, + "column": 13 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [ + { + "type": "ETSParameterExpression", + "name": { + "type": "Identifier", + "name": "x", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "J", + "decorators": [], + "loc": { + "start": { + "line": 27, + "column": 17 + }, + "end": { + "line": 27, + "column": 18 + } + } + }, + "loc": { + "start": { + "line": 27, + "column": 17 + }, + "end": { + "line": 27, + "column": 19 + } + } + }, + "loc": { + "start": { + "line": 27, + "column": 17 + }, + "end": { + "line": 27, + "column": 19 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 27, + "column": 14 + }, + "end": { + "line": 27, + "column": 19 + } + } + }, + "loc": { + "start": { + "line": 27, + "column": 14 + }, + "end": { + "line": 27, + "column": 19 + } + } + } + ], + "returnType": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "string", + "decorators": [], + "loc": { + "start": { + "line": 27, + "column": 21 + }, + "end": { + "line": 27, + "column": 27 + } + } + }, + "loc": { + "start": { + "line": 27, + "column": 21 + }, + "end": { + "line": 27, + "column": 29 + } + } + }, + "loc": { + "start": { + "line": 27, + "column": 21 + }, + "end": { + "line": 27, + "column": 29 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "ReturnStatement", + "argument": { + "type": "StringLiteral", + "value": "J", + "loc": { + "start": { + "line": 28, + "column": 12 + }, + "end": { + "line": 28, + "column": 15 + } + } + }, + "loc": { + "start": { + "line": 28, + "column": 5 + }, + "end": { + "line": 28, + "column": 16 + } + } + } + ], + "loc": { + "start": { + "line": 27, + "column": 28 + }, + "end": { + "line": 29, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 27, + "column": 13 + }, + "end": { + "line": 29, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 27, + "column": 13 + }, + "end": { + "line": 29, + "column": 2 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 27, + "column": 1 + }, + "end": { + "line": 29, + "column": 2 + } + } + } + ], + "decorators": [], + "loc": { + "start": { + "line": 24, + "column": 1 + }, + "end": { + "line": 26, + "column": 2 + } + } + }, + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 31, + "column": 10 + }, + "end": { + "line": 31, + "column": 14 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 31, + "column": 10 + }, + "end": { + "line": 31, + "column": 14 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "returnType": { + "type": "ETSPrimitiveType", + "loc": { + "start": { + "line": 31, + "column": 18 + }, + "end": { + "line": 31, + "column": 21 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "d", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "string", + "decorators": [], + "loc": { + "start": { + "line": 32, + "column": 13 + }, + "end": { + "line": 32, + "column": 19 + } + } + }, + "loc": { + "start": { + "line": 32, + "column": 13 + }, + "end": { + "line": 32, + "column": 21 + } + } + }, + "loc": { + "start": { + "line": 32, + "column": 13 + }, + "end": { + "line": 32, + "column": 21 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 32, + "column": 9 + }, + "end": { + "line": 32, + "column": 10 + } + } + }, + "init": { + "type": "CallExpression", + "callee": { + "type": "Identifier", + "name": "foo", + "decorators": [], + "loc": { + "start": { + "line": 32, + "column": 22 + }, + "end": { + "line": 32, + "column": 25 + } + } + }, + "arguments": [ + { + "type": "ETSNewClassInstanceExpression", + "typeReference": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "D", + "decorators": [], + "loc": { + "start": { + "line": 32, + "column": 30 + }, + "end": { + "line": 32, + "column": 31 + } + } + }, + "loc": { + "start": { + "line": 32, + "column": 30 + }, + "end": { + "line": 32, + "column": 32 + } + } + }, + "loc": { + "start": { + "line": 32, + "column": 30 + }, + "end": { + "line": 32, + "column": 32 + } + } + }, + "arguments": [], + "loc": { + "start": { + "line": 32, + "column": 26 + }, + "end": { + "line": 32, + "column": 34 + } + } + } + ], + "optional": false, + "loc": { + "start": { + "line": 32, + "column": 22 + }, + "end": { + "line": 32, + "column": 34 + } + } + }, + "loc": { + "start": { + "line": 32, + "column": 9 + }, + "end": { + "line": 32, + "column": 34 + } + } + } + ], + "kind": "let", + "loc": { + "start": { + "line": 32, + "column": 5 + }, + "end": { + "line": 32, + "column": 35 + } + } + }, + { + "type": "ReturnStatement", + "argument": { + "type": "NumberLiteral", + "value": 0, + "loc": { + "start": { + "line": 33, + "column": 12 + }, + "end": { + "line": 33, + "column": 13 + } + } + }, + "loc": { + "start": { + "line": 33, + "column": 5 + }, + "end": { + "line": 33, + "column": 14 + } + } + } + ], + "loc": { + "start": { + "line": 31, + "column": 22 + }, + "end": { + "line": 34, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 31, + "column": 14 + }, + "end": { + "line": 34, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 31, + "column": 14 + }, + "end": { + "line": 34, + "column": 2 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 31, + "column": 1 + }, + "end": { + "line": 34, + "column": 2 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 36, + "column": 1 + } + } +} +TypeError: Call to `foo` is ambiguous as `2` versions of `foo` are available: `foo(x: I): String` and `foo(x: J): String` [method-resolution-class-and-interface-in-signatures_3.ets:32:22] diff --git a/ets2panda/test/compiler/ets/method-resolution-class-and-interface-in-signatures_3.ets b/ets2panda/test/compiler/ets/method-resolution-class-and-interface-in-signatures_3.ets new file mode 100644 index 0000000000000000000000000000000000000000..ef412316e118b65d514eb9b6eb2cf108279b406c --- /dev/null +++ b/ets2panda/test/compiler/ets/method-resolution-class-and-interface-in-signatures_3.ets @@ -0,0 +1,35 @@ +/* + * 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. + */ + +interface I {} +interface J {} +interface K {} +class A {} +class B extends A implements I, J {} +class C extends B {} +class D extends C {} + +function foo(x: I): string { + return "I"; +} +function foo(x: J): string { + return "J"; +} + +function main(): int { + let d : string = foo(new D()); + return 0; +} + diff --git a/ets2panda/test/compiler/ets/method-resolution-class-and-interface-in-signatures_4-expected.txt b/ets2panda/test/compiler/ets/method-resolution-class-and-interface-in-signatures_4-expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..80ef2eedb6715e433a4ab7efaacffbe967c03f13 --- /dev/null +++ b/ets2panda/test/compiler/ets/method-resolution-class-and-interface-in-signatures_4-expected.txt @@ -0,0 +1,1846 @@ +{ + "type": "Program", + "statements": [ + { + "type": "TSInterfaceDeclaration", + "body": { + "type": "TSInterfaceBody", + "body": [], + "loc": { + "start": { + "line": 16, + "column": 13 + }, + "end": { + "line": 16, + "column": 15 + } + } + }, + "id": { + "type": "Identifier", + "name": "I", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 11 + }, + "end": { + "line": 16, + "column": 12 + } + } + }, + "extends": [], + "loc": { + "start": { + "line": 16, + "column": 1 + }, + "end": { + "line": 17, + "column": 10 + } + } + }, + { + "type": "TSInterfaceDeclaration", + "body": { + "type": "TSInterfaceBody", + "body": [], + "loc": { + "start": { + "line": 17, + "column": 13 + }, + "end": { + "line": 17, + "column": 15 + } + } + }, + "id": { + "type": "Identifier", + "name": "J", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 11 + }, + "end": { + "line": 17, + "column": 12 + } + } + }, + "extends": [], + "loc": { + "start": { + "line": 17, + "column": 1 + }, + "end": { + "line": 19, + "column": 6 + } + } + }, + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "A", + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 7 + }, + "end": { + "line": 19, + "column": 8 + } + } + }, + "superClass": null, + "implements": [], + "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "constructor", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "constructor", + "static": false, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "constructor", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 11 + }, + "end": { + "line": 19, + "column": 11 + } + } + } + ], + "loc": { + "start": { + "line": 19, + "column": 9 + }, + "end": { + "line": 19, + "column": 11 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 1 + }, + "end": { + "line": 19, + "column": 11 + } + } + }, + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "B", + "decorators": [], + "loc": { + "start": { + "line": 20, + "column": 7 + }, + "end": { + "line": 20, + "column": 8 + } + } + }, + "superClass": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "A", + "decorators": [], + "loc": { + "start": { + "line": 20, + "column": 17 + }, + "end": { + "line": 20, + "column": 18 + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 17 + }, + "end": { + "line": 20, + "column": 29 + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 17 + }, + "end": { + "line": 20, + "column": 29 + } + } + }, + "implements": [ + { + "type": "TSClassImplements", + "expression": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "I", + "decorators": [], + "loc": { + "start": { + "line": 20, + "column": 30 + }, + "end": { + "line": 20, + "column": 31 + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 30 + }, + "end": { + "line": 20, + "column": 32 + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 30 + }, + "end": { + "line": 20, + "column": 32 + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 30 + }, + "end": { + "line": 20, + "column": 32 + } + } + }, + { + "type": "TSClassImplements", + "expression": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "J", + "decorators": [], + "loc": { + "start": { + "line": 20, + "column": 33 + }, + "end": { + "line": 20, + "column": 34 + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 33 + }, + "end": { + "line": 20, + "column": 36 + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 33 + }, + "end": { + "line": 20, + "column": 36 + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 33 + }, + "end": { + "line": 20, + "column": 36 + } + } + } + ], + "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "constructor", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "constructor", + "static": false, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "constructor", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 20, + "column": 37 + }, + "end": { + "line": 20, + "column": 37 + } + } + } + ], + "loc": { + "start": { + "line": 20, + "column": 35 + }, + "end": { + "line": 20, + "column": 37 + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 1 + }, + "end": { + "line": 20, + "column": 37 + } + } + }, + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "C", + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 7 + }, + "end": { + "line": 21, + "column": 8 + } + } + }, + "superClass": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "B", + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 17 + }, + "end": { + "line": 21, + "column": 18 + } + } + }, + "loc": { + "start": { + "line": 21, + "column": 17 + }, + "end": { + "line": 21, + "column": 20 + } + } + }, + "loc": { + "start": { + "line": 21, + "column": 17 + }, + "end": { + "line": 21, + "column": 20 + } + } + }, + "implements": [], + "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "constructor", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "constructor", + "static": false, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "constructor", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 21 + }, + "end": { + "line": 21, + "column": 21 + } + } + } + ], + "loc": { + "start": { + "line": 21, + "column": 19 + }, + "end": { + "line": 21, + "column": 21 + } + } + }, + "loc": { + "start": { + "line": 21, + "column": 1 + }, + "end": { + "line": 21, + "column": 21 + } + } + }, + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "ETSGLOBAL", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "superClass": null, + "implements": [], + "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "_$init$_", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "_$init$_", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "foo", + "decorators": [], + "loc": { + "start": { + "line": 23, + "column": 10 + }, + "end": { + "line": 23, + "column": 13 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "foo", + "decorators": [], + "loc": { + "start": { + "line": 23, + "column": 10 + }, + "end": { + "line": 23, + "column": 13 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [ + { + "type": "ETSParameterExpression", + "name": { + "type": "Identifier", + "name": "x", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "I", + "decorators": [], + "loc": { + "start": { + "line": 23, + "column": 17 + }, + "end": { + "line": 23, + "column": 18 + } + } + }, + "loc": { + "start": { + "line": 23, + "column": 17 + }, + "end": { + "line": 23, + "column": 19 + } + } + }, + "loc": { + "start": { + "line": 23, + "column": 17 + }, + "end": { + "line": 23, + "column": 19 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 23, + "column": 14 + }, + "end": { + "line": 23, + "column": 19 + } + } + }, + "loc": { + "start": { + "line": 23, + "column": 14 + }, + "end": { + "line": 23, + "column": 19 + } + } + } + ], + "returnType": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "string", + "decorators": [], + "loc": { + "start": { + "line": 23, + "column": 21 + }, + "end": { + "line": 23, + "column": 27 + } + } + }, + "loc": { + "start": { + "line": 23, + "column": 21 + }, + "end": { + "line": 23, + "column": 29 + } + } + }, + "loc": { + "start": { + "line": 23, + "column": 21 + }, + "end": { + "line": 23, + "column": 29 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "ReturnStatement", + "argument": { + "type": "StringLiteral", + "value": "I", + "loc": { + "start": { + "line": 24, + "column": 12 + }, + "end": { + "line": 24, + "column": 15 + } + } + }, + "loc": { + "start": { + "line": 24, + "column": 5 + }, + "end": { + "line": 24, + "column": 16 + } + } + } + ], + "loc": { + "start": { + "line": 23, + "column": 28 + }, + "end": { + "line": 25, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 23, + "column": 13 + }, + "end": { + "line": 25, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 23, + "column": 13 + }, + "end": { + "line": 25, + "column": 2 + } + } + }, + "overloads": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "foo", + "decorators": [], + "loc": { + "start": { + "line": 26, + "column": 10 + }, + "end": { + "line": 26, + "column": 13 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "foo", + "decorators": [], + "loc": { + "start": { + "line": 26, + "column": 10 + }, + "end": { + "line": 26, + "column": 13 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [ + { + "type": "ETSParameterExpression", + "name": { + "type": "Identifier", + "name": "x", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "J", + "decorators": [], + "loc": { + "start": { + "line": 26, + "column": 17 + }, + "end": { + "line": 26, + "column": 18 + } + } + }, + "loc": { + "start": { + "line": 26, + "column": 17 + }, + "end": { + "line": 26, + "column": 19 + } + } + }, + "loc": { + "start": { + "line": 26, + "column": 17 + }, + "end": { + "line": 26, + "column": 19 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 26, + "column": 14 + }, + "end": { + "line": 26, + "column": 19 + } + } + }, + "loc": { + "start": { + "line": 26, + "column": 14 + }, + "end": { + "line": 26, + "column": 19 + } + } + } + ], + "returnType": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "string", + "decorators": [], + "loc": { + "start": { + "line": 26, + "column": 21 + }, + "end": { + "line": 26, + "column": 27 + } + } + }, + "loc": { + "start": { + "line": 26, + "column": 21 + }, + "end": { + "line": 26, + "column": 29 + } + } + }, + "loc": { + "start": { + "line": 26, + "column": 21 + }, + "end": { + "line": 26, + "column": 29 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "ReturnStatement", + "argument": { + "type": "StringLiteral", + "value": "J", + "loc": { + "start": { + "line": 27, + "column": 12 + }, + "end": { + "line": 27, + "column": 15 + } + } + }, + "loc": { + "start": { + "line": 27, + "column": 5 + }, + "end": { + "line": 27, + "column": 16 + } + } + } + ], + "loc": { + "start": { + "line": 26, + "column": 28 + }, + "end": { + "line": 28, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 26, + "column": 13 + }, + "end": { + "line": 28, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 26, + "column": 13 + }, + "end": { + "line": 28, + "column": 2 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 26, + "column": 1 + }, + "end": { + "line": 28, + "column": 2 + } + } + }, + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "foo", + "decorators": [], + "loc": { + "start": { + "line": 29, + "column": 10 + }, + "end": { + "line": 29, + "column": 13 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "foo", + "decorators": [], + "loc": { + "start": { + "line": 29, + "column": 10 + }, + "end": { + "line": 29, + "column": 13 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [ + { + "type": "ETSParameterExpression", + "name": { + "type": "Identifier", + "name": "x", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "A", + "decorators": [], + "loc": { + "start": { + "line": 29, + "column": 17 + }, + "end": { + "line": 29, + "column": 18 + } + } + }, + "loc": { + "start": { + "line": 29, + "column": 17 + }, + "end": { + "line": 29, + "column": 19 + } + } + }, + "loc": { + "start": { + "line": 29, + "column": 17 + }, + "end": { + "line": 29, + "column": 19 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 29, + "column": 14 + }, + "end": { + "line": 29, + "column": 19 + } + } + }, + "loc": { + "start": { + "line": 29, + "column": 14 + }, + "end": { + "line": 29, + "column": 19 + } + } + } + ], + "returnType": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "string", + "decorators": [], + "loc": { + "start": { + "line": 29, + "column": 21 + }, + "end": { + "line": 29, + "column": 27 + } + } + }, + "loc": { + "start": { + "line": 29, + "column": 21 + }, + "end": { + "line": 29, + "column": 29 + } + } + }, + "loc": { + "start": { + "line": 29, + "column": 21 + }, + "end": { + "line": 29, + "column": 29 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "ReturnStatement", + "argument": { + "type": "StringLiteral", + "value": "A", + "loc": { + "start": { + "line": 30, + "column": 12 + }, + "end": { + "line": 30, + "column": 15 + } + } + }, + "loc": { + "start": { + "line": 30, + "column": 5 + }, + "end": { + "line": 30, + "column": 16 + } + } + } + ], + "loc": { + "start": { + "line": 29, + "column": 28 + }, + "end": { + "line": 31, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 29, + "column": 13 + }, + "end": { + "line": 31, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 29, + "column": 13 + }, + "end": { + "line": 31, + "column": 2 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 29, + "column": 1 + }, + "end": { + "line": 31, + "column": 2 + } + } + } + ], + "decorators": [], + "loc": { + "start": { + "line": 23, + "column": 1 + }, + "end": { + "line": 25, + "column": 2 + } + } + }, + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 33, + "column": 10 + }, + "end": { + "line": 33, + "column": 14 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 33, + "column": 10 + }, + "end": { + "line": 33, + "column": 14 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "returnType": { + "type": "ETSPrimitiveType", + "loc": { + "start": { + "line": 33, + "column": 18 + }, + "end": { + "line": 33, + "column": 21 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "c", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "string", + "decorators": [], + "loc": { + "start": { + "line": 34, + "column": 13 + }, + "end": { + "line": 34, + "column": 19 + } + } + }, + "loc": { + "start": { + "line": 34, + "column": 13 + }, + "end": { + "line": 34, + "column": 21 + } + } + }, + "loc": { + "start": { + "line": 34, + "column": 13 + }, + "end": { + "line": 34, + "column": 21 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 34, + "column": 9 + }, + "end": { + "line": 34, + "column": 10 + } + } + }, + "init": { + "type": "CallExpression", + "callee": { + "type": "Identifier", + "name": "foo", + "decorators": [], + "loc": { + "start": { + "line": 34, + "column": 22 + }, + "end": { + "line": 34, + "column": 25 + } + } + }, + "arguments": [ + { + "type": "ETSNewClassInstanceExpression", + "typeReference": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "C", + "decorators": [], + "loc": { + "start": { + "line": 34, + "column": 30 + }, + "end": { + "line": 34, + "column": 31 + } + } + }, + "loc": { + "start": { + "line": 34, + "column": 30 + }, + "end": { + "line": 34, + "column": 32 + } + } + }, + "loc": { + "start": { + "line": 34, + "column": 30 + }, + "end": { + "line": 34, + "column": 32 + } + } + }, + "arguments": [], + "loc": { + "start": { + "line": 34, + "column": 26 + }, + "end": { + "line": 34, + "column": 34 + } + } + } + ], + "optional": false, + "loc": { + "start": { + "line": 34, + "column": 22 + }, + "end": { + "line": 34, + "column": 34 + } + } + }, + "loc": { + "start": { + "line": 34, + "column": 9 + }, + "end": { + "line": 34, + "column": 34 + } + } + } + ], + "kind": "let", + "loc": { + "start": { + "line": 34, + "column": 5 + }, + "end": { + "line": 34, + "column": 35 + } + } + }, + { + "type": "ReturnStatement", + "argument": { + "type": "NumberLiteral", + "value": 0, + "loc": { + "start": { + "line": 35, + "column": 12 + }, + "end": { + "line": 35, + "column": 13 + } + } + }, + "loc": { + "start": { + "line": 35, + "column": 5 + }, + "end": { + "line": 35, + "column": 14 + } + } + } + ], + "loc": { + "start": { + "line": 33, + "column": 22 + }, + "end": { + "line": 36, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 33, + "column": 14 + }, + "end": { + "line": 36, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 33, + "column": 14 + }, + "end": { + "line": 36, + "column": 2 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 33, + "column": 1 + }, + "end": { + "line": 36, + "column": 2 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 38, + "column": 1 + } + } +} +TypeError: Call to `foo` is ambiguous as `2` versions of `foo` are available: `foo(x: A): String` and `foo(x: I): String` [method-resolution-class-and-interface-in-signatures_4.ets:34:22] diff --git a/ets2panda/test/compiler/ets/method-resolution-class-and-interface-in-signatures_4.ets b/ets2panda/test/compiler/ets/method-resolution-class-and-interface-in-signatures_4.ets new file mode 100644 index 0000000000000000000000000000000000000000..7eb0e88eb2d774d2cca77346aa8820d2772ae5bc --- /dev/null +++ b/ets2panda/test/compiler/ets/method-resolution-class-and-interface-in-signatures_4.ets @@ -0,0 +1,37 @@ +/* + * 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. + */ + +interface I {} +interface J {} + +class A {} +class B extends A implements I, J {} +class C extends B {} + +function foo(x: I): string { + return "I"; +} +function foo(x: J): string { + return "J"; +} +function foo(x: A): string { + return "A"; +} + +function main(): int { + let c : string = foo(new C()); + return 0; +} + diff --git a/ets2panda/test/compiler/ets/method-resolution-class-and-interface-in-signatures_5-expected.txt b/ets2panda/test/compiler/ets/method-resolution-class-and-interface-in-signatures_5-expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..f4277701d6b36c899890e070b686bffb67c93c10 --- /dev/null +++ b/ets2panda/test/compiler/ets/method-resolution-class-and-interface-in-signatures_5-expected.txt @@ -0,0 +1,2078 @@ +{ + "type": "Program", + "statements": [ + { + "type": "TSInterfaceDeclaration", + "body": { + "type": "TSInterfaceBody", + "body": [], + "loc": { + "start": { + "line": 16, + "column": 13 + }, + "end": { + "line": 16, + "column": 15 + } + } + }, + "id": { + "type": "Identifier", + "name": "I", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 11 + }, + "end": { + "line": 16, + "column": 12 + } + } + }, + "extends": [], + "loc": { + "start": { + "line": 16, + "column": 1 + }, + "end": { + "line": 17, + "column": 10 + } + } + }, + { + "type": "TSInterfaceDeclaration", + "body": { + "type": "TSInterfaceBody", + "body": [], + "loc": { + "start": { + "line": 17, + "column": 13 + }, + "end": { + "line": 17, + "column": 15 + } + } + }, + "id": { + "type": "Identifier", + "name": "J", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 11 + }, + "end": { + "line": 17, + "column": 12 + } + } + }, + "extends": [], + "loc": { + "start": { + "line": 17, + "column": 1 + }, + "end": { + "line": 19, + "column": 6 + } + } + }, + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "A", + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 7 + }, + "end": { + "line": 19, + "column": 8 + } + } + }, + "superClass": null, + "implements": [], + "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "constructor", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "constructor", + "static": false, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "constructor", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 11 + }, + "end": { + "line": 19, + "column": 11 + } + } + } + ], + "loc": { + "start": { + "line": 19, + "column": 9 + }, + "end": { + "line": 19, + "column": 11 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 1 + }, + "end": { + "line": 19, + "column": 11 + } + } + }, + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "B", + "decorators": [], + "loc": { + "start": { + "line": 20, + "column": 7 + }, + "end": { + "line": 20, + "column": 8 + } + } + }, + "superClass": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "A", + "decorators": [], + "loc": { + "start": { + "line": 20, + "column": 17 + }, + "end": { + "line": 20, + "column": 18 + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 17 + }, + "end": { + "line": 20, + "column": 29 + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 17 + }, + "end": { + "line": 20, + "column": 29 + } + } + }, + "implements": [ + { + "type": "TSClassImplements", + "expression": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "I", + "decorators": [], + "loc": { + "start": { + "line": 20, + "column": 30 + }, + "end": { + "line": 20, + "column": 31 + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 30 + }, + "end": { + "line": 20, + "column": 32 + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 30 + }, + "end": { + "line": 20, + "column": 32 + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 30 + }, + "end": { + "line": 20, + "column": 32 + } + } + }, + { + "type": "TSClassImplements", + "expression": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "J", + "decorators": [], + "loc": { + "start": { + "line": 20, + "column": 33 + }, + "end": { + "line": 20, + "column": 34 + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 33 + }, + "end": { + "line": 20, + "column": 36 + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 33 + }, + "end": { + "line": 20, + "column": 36 + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 33 + }, + "end": { + "line": 20, + "column": 36 + } + } + } + ], + "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "constructor", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "constructor", + "static": false, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "constructor", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 20, + "column": 37 + }, + "end": { + "line": 20, + "column": 37 + } + } + } + ], + "loc": { + "start": { + "line": 20, + "column": 35 + }, + "end": { + "line": 20, + "column": 37 + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 1 + }, + "end": { + "line": 20, + "column": 37 + } + } + }, + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "C", + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 7 + }, + "end": { + "line": 21, + "column": 8 + } + } + }, + "superClass": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "B", + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 17 + }, + "end": { + "line": 21, + "column": 18 + } + } + }, + "loc": { + "start": { + "line": 21, + "column": 17 + }, + "end": { + "line": 21, + "column": 20 + } + } + }, + "loc": { + "start": { + "line": 21, + "column": 17 + }, + "end": { + "line": 21, + "column": 20 + } + } + }, + "implements": [], + "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "constructor", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "constructor", + "static": false, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "constructor", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 21 + }, + "end": { + "line": 21, + "column": 21 + } + } + } + ], + "loc": { + "start": { + "line": 21, + "column": 19 + }, + "end": { + "line": 21, + "column": 21 + } + } + }, + "loc": { + "start": { + "line": 21, + "column": 1 + }, + "end": { + "line": 21, + "column": 21 + } + } + }, + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "ETSGLOBAL", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "superClass": null, + "implements": [], + "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "_$init$_", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "_$init$_", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "foo", + "decorators": [], + "loc": { + "start": { + "line": 23, + "column": 10 + }, + "end": { + "line": 23, + "column": 13 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "foo", + "decorators": [], + "loc": { + "start": { + "line": 23, + "column": 10 + }, + "end": { + "line": 23, + "column": 13 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [ + { + "type": "ETSParameterExpression", + "name": { + "type": "Identifier", + "name": "x", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "I", + "decorators": [], + "loc": { + "start": { + "line": 23, + "column": 17 + }, + "end": { + "line": 23, + "column": 18 + } + } + }, + "loc": { + "start": { + "line": 23, + "column": 17 + }, + "end": { + "line": 23, + "column": 19 + } + } + }, + "loc": { + "start": { + "line": 23, + "column": 17 + }, + "end": { + "line": 23, + "column": 19 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 23, + "column": 14 + }, + "end": { + "line": 23, + "column": 19 + } + } + }, + "loc": { + "start": { + "line": 23, + "column": 14 + }, + "end": { + "line": 23, + "column": 19 + } + } + } + ], + "returnType": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "string", + "decorators": [], + "loc": { + "start": { + "line": 23, + "column": 21 + }, + "end": { + "line": 23, + "column": 27 + } + } + }, + "loc": { + "start": { + "line": 23, + "column": 21 + }, + "end": { + "line": 23, + "column": 29 + } + } + }, + "loc": { + "start": { + "line": 23, + "column": 21 + }, + "end": { + "line": 23, + "column": 29 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "ReturnStatement", + "argument": { + "type": "StringLiteral", + "value": "I", + "loc": { + "start": { + "line": 24, + "column": 12 + }, + "end": { + "line": 24, + "column": 15 + } + } + }, + "loc": { + "start": { + "line": 24, + "column": 5 + }, + "end": { + "line": 24, + "column": 16 + } + } + } + ], + "loc": { + "start": { + "line": 23, + "column": 28 + }, + "end": { + "line": 25, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 23, + "column": 13 + }, + "end": { + "line": 25, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 23, + "column": 13 + }, + "end": { + "line": 25, + "column": 2 + } + } + }, + "overloads": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "foo", + "decorators": [], + "loc": { + "start": { + "line": 26, + "column": 10 + }, + "end": { + "line": 26, + "column": 13 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "foo", + "decorators": [], + "loc": { + "start": { + "line": 26, + "column": 10 + }, + "end": { + "line": 26, + "column": 13 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [ + { + "type": "ETSParameterExpression", + "name": { + "type": "Identifier", + "name": "x", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "J", + "decorators": [], + "loc": { + "start": { + "line": 26, + "column": 17 + }, + "end": { + "line": 26, + "column": 18 + } + } + }, + "loc": { + "start": { + "line": 26, + "column": 17 + }, + "end": { + "line": 26, + "column": 19 + } + } + }, + "loc": { + "start": { + "line": 26, + "column": 17 + }, + "end": { + "line": 26, + "column": 19 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 26, + "column": 14 + }, + "end": { + "line": 26, + "column": 19 + } + } + }, + "loc": { + "start": { + "line": 26, + "column": 14 + }, + "end": { + "line": 26, + "column": 19 + } + } + } + ], + "returnType": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "string", + "decorators": [], + "loc": { + "start": { + "line": 26, + "column": 21 + }, + "end": { + "line": 26, + "column": 27 + } + } + }, + "loc": { + "start": { + "line": 26, + "column": 21 + }, + "end": { + "line": 26, + "column": 29 + } + } + }, + "loc": { + "start": { + "line": 26, + "column": 21 + }, + "end": { + "line": 26, + "column": 29 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "ReturnStatement", + "argument": { + "type": "StringLiteral", + "value": "J", + "loc": { + "start": { + "line": 27, + "column": 12 + }, + "end": { + "line": 27, + "column": 15 + } + } + }, + "loc": { + "start": { + "line": 27, + "column": 5 + }, + "end": { + "line": 27, + "column": 16 + } + } + } + ], + "loc": { + "start": { + "line": 26, + "column": 28 + }, + "end": { + "line": 28, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 26, + "column": 13 + }, + "end": { + "line": 28, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 26, + "column": 13 + }, + "end": { + "line": 28, + "column": 2 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 26, + "column": 1 + }, + "end": { + "line": 28, + "column": 2 + } + } + }, + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "foo", + "decorators": [], + "loc": { + "start": { + "line": 29, + "column": 10 + }, + "end": { + "line": 29, + "column": 13 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "foo", + "decorators": [], + "loc": { + "start": { + "line": 29, + "column": 10 + }, + "end": { + "line": 29, + "column": 13 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [ + { + "type": "ETSParameterExpression", + "name": { + "type": "Identifier", + "name": "x", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "A", + "decorators": [], + "loc": { + "start": { + "line": 29, + "column": 17 + }, + "end": { + "line": 29, + "column": 18 + } + } + }, + "loc": { + "start": { + "line": 29, + "column": 17 + }, + "end": { + "line": 29, + "column": 19 + } + } + }, + "loc": { + "start": { + "line": 29, + "column": 17 + }, + "end": { + "line": 29, + "column": 19 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 29, + "column": 14 + }, + "end": { + "line": 29, + "column": 19 + } + } + }, + "loc": { + "start": { + "line": 29, + "column": 14 + }, + "end": { + "line": 29, + "column": 19 + } + } + } + ], + "returnType": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "string", + "decorators": [], + "loc": { + "start": { + "line": 29, + "column": 21 + }, + "end": { + "line": 29, + "column": 27 + } + } + }, + "loc": { + "start": { + "line": 29, + "column": 21 + }, + "end": { + "line": 29, + "column": 29 + } + } + }, + "loc": { + "start": { + "line": 29, + "column": 21 + }, + "end": { + "line": 29, + "column": 29 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "ReturnStatement", + "argument": { + "type": "StringLiteral", + "value": "A", + "loc": { + "start": { + "line": 30, + "column": 12 + }, + "end": { + "line": 30, + "column": 15 + } + } + }, + "loc": { + "start": { + "line": 30, + "column": 5 + }, + "end": { + "line": 30, + "column": 16 + } + } + } + ], + "loc": { + "start": { + "line": 29, + "column": 28 + }, + "end": { + "line": 31, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 29, + "column": 13 + }, + "end": { + "line": 31, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 29, + "column": 13 + }, + "end": { + "line": 31, + "column": 2 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 29, + "column": 1 + }, + "end": { + "line": 31, + "column": 2 + } + } + }, + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "foo", + "decorators": [], + "loc": { + "start": { + "line": 32, + "column": 10 + }, + "end": { + "line": 32, + "column": 13 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "foo", + "decorators": [], + "loc": { + "start": { + "line": 32, + "column": 10 + }, + "end": { + "line": 32, + "column": 13 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [ + { + "type": "ETSParameterExpression", + "name": { + "type": "Identifier", + "name": "x", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "B", + "decorators": [], + "loc": { + "start": { + "line": 32, + "column": 17 + }, + "end": { + "line": 32, + "column": 18 + } + } + }, + "loc": { + "start": { + "line": 32, + "column": 17 + }, + "end": { + "line": 32, + "column": 19 + } + } + }, + "loc": { + "start": { + "line": 32, + "column": 17 + }, + "end": { + "line": 32, + "column": 19 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 32, + "column": 14 + }, + "end": { + "line": 32, + "column": 19 + } + } + }, + "loc": { + "start": { + "line": 32, + "column": 14 + }, + "end": { + "line": 32, + "column": 19 + } + } + } + ], + "returnType": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "string", + "decorators": [], + "loc": { + "start": { + "line": 32, + "column": 21 + }, + "end": { + "line": 32, + "column": 27 + } + } + }, + "loc": { + "start": { + "line": 32, + "column": 21 + }, + "end": { + "line": 32, + "column": 29 + } + } + }, + "loc": { + "start": { + "line": 32, + "column": 21 + }, + "end": { + "line": 32, + "column": 29 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "ReturnStatement", + "argument": { + "type": "StringLiteral", + "value": "B", + "loc": { + "start": { + "line": 33, + "column": 12 + }, + "end": { + "line": 33, + "column": 15 + } + } + }, + "loc": { + "start": { + "line": 33, + "column": 5 + }, + "end": { + "line": 33, + "column": 16 + } + } + } + ], + "loc": { + "start": { + "line": 32, + "column": 28 + }, + "end": { + "line": 34, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 32, + "column": 13 + }, + "end": { + "line": 34, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 32, + "column": 13 + }, + "end": { + "line": 34, + "column": 2 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 32, + "column": 1 + }, + "end": { + "line": 34, + "column": 2 + } + } + } + ], + "decorators": [], + "loc": { + "start": { + "line": 23, + "column": 1 + }, + "end": { + "line": 25, + "column": 2 + } + } + }, + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 36, + "column": 10 + }, + "end": { + "line": 36, + "column": 14 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 36, + "column": 10 + }, + "end": { + "line": 36, + "column": 14 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "returnType": { + "type": "ETSPrimitiveType", + "loc": { + "start": { + "line": 36, + "column": 18 + }, + "end": { + "line": 36, + "column": 21 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "b", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "string", + "decorators": [], + "loc": { + "start": { + "line": 37, + "column": 13 + }, + "end": { + "line": 37, + "column": 19 + } + } + }, + "loc": { + "start": { + "line": 37, + "column": 13 + }, + "end": { + "line": 37, + "column": 21 + } + } + }, + "loc": { + "start": { + "line": 37, + "column": 13 + }, + "end": { + "line": 37, + "column": 21 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 37, + "column": 9 + }, + "end": { + "line": 37, + "column": 10 + } + } + }, + "init": { + "type": "CallExpression", + "callee": { + "type": "Identifier", + "name": "foo", + "decorators": [], + "loc": { + "start": { + "line": 37, + "column": 22 + }, + "end": { + "line": 37, + "column": 25 + } + } + }, + "arguments": [ + { + "type": "ETSNewClassInstanceExpression", + "typeReference": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "B", + "decorators": [], + "loc": { + "start": { + "line": 37, + "column": 30 + }, + "end": { + "line": 37, + "column": 31 + } + } + }, + "loc": { + "start": { + "line": 37, + "column": 30 + }, + "end": { + "line": 37, + "column": 32 + } + } + }, + "loc": { + "start": { + "line": 37, + "column": 30 + }, + "end": { + "line": 37, + "column": 32 + } + } + }, + "arguments": [], + "loc": { + "start": { + "line": 37, + "column": 26 + }, + "end": { + "line": 37, + "column": 34 + } + } + } + ], + "optional": false, + "loc": { + "start": { + "line": 37, + "column": 22 + }, + "end": { + "line": 37, + "column": 34 + } + } + }, + "loc": { + "start": { + "line": 37, + "column": 9 + }, + "end": { + "line": 37, + "column": 34 + } + } + } + ], + "kind": "let", + "loc": { + "start": { + "line": 37, + "column": 5 + }, + "end": { + "line": 37, + "column": 35 + } + } + }, + { + "type": "ReturnStatement", + "argument": { + "type": "NumberLiteral", + "value": 0, + "loc": { + "start": { + "line": 38, + "column": 12 + }, + "end": { + "line": 38, + "column": 13 + } + } + }, + "loc": { + "start": { + "line": 38, + "column": 5 + }, + "end": { + "line": 38, + "column": 14 + } + } + } + ], + "loc": { + "start": { + "line": 36, + "column": 22 + }, + "end": { + "line": 39, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 36, + "column": 14 + }, + "end": { + "line": 39, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 36, + "column": 14 + }, + "end": { + "line": 39, + "column": 2 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 36, + "column": 1 + }, + "end": { + "line": 39, + "column": 2 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 41, + "column": 1 + } + } +} diff --git a/ets2panda/test/compiler/ets/method-resolution-class-and-interface-in-signatures_5.ets b/ets2panda/test/compiler/ets/method-resolution-class-and-interface-in-signatures_5.ets new file mode 100644 index 0000000000000000000000000000000000000000..11d737240216d9bfd5573dc7492858a7da392d02 --- /dev/null +++ b/ets2panda/test/compiler/ets/method-resolution-class-and-interface-in-signatures_5.ets @@ -0,0 +1,40 @@ +/* + * 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. + */ + +interface I {} +interface J {} + +class A {} +class B extends A implements I, J {} +class C extends B {} + +function foo(x: I): string { + return "I"; +} +function foo(x: J): string { + return "J"; +} +function foo(x: A): string { + return "A"; +} +function foo(x: B): string { + return "B"; +} + +function main(): int { + let b : string = foo(new B()); + return 0; +} + diff --git a/ets2panda/test/compiler/ets/method-resolution-class-and-interface-in-signatures_6-expected.txt b/ets2panda/test/compiler/ets/method-resolution-class-and-interface-in-signatures_6-expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..789f220c2c38621c255c5d84276e6bafab7767f8 --- /dev/null +++ b/ets2panda/test/compiler/ets/method-resolution-class-and-interface-in-signatures_6-expected.txt @@ -0,0 +1,2642 @@ +{ + "type": "Program", + "statements": [ + { + "type": "TSInterfaceDeclaration", + "body": { + "type": "TSInterfaceBody", + "body": [], + "loc": { + "start": { + "line": 16, + "column": 13 + }, + "end": { + "line": 16, + "column": 15 + } + } + }, + "id": { + "type": "Identifier", + "name": "I", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 11 + }, + "end": { + "line": 16, + "column": 12 + } + } + }, + "extends": [], + "loc": { + "start": { + "line": 16, + "column": 1 + }, + "end": { + "line": 17, + "column": 10 + } + } + }, + { + "type": "TSInterfaceDeclaration", + "body": { + "type": "TSInterfaceBody", + "body": [], + "loc": { + "start": { + "line": 17, + "column": 13 + }, + "end": { + "line": 17, + "column": 15 + } + } + }, + "id": { + "type": "Identifier", + "name": "J", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 11 + }, + "end": { + "line": 17, + "column": 12 + } + } + }, + "extends": [], + "loc": { + "start": { + "line": 17, + "column": 1 + }, + "end": { + "line": 19, + "column": 6 + } + } + }, + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "A", + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 7 + }, + "end": { + "line": 19, + "column": 8 + } + } + }, + "superClass": null, + "implements": [ + { + "type": "TSClassImplements", + "expression": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "I", + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 20 + }, + "end": { + "line": 19, + "column": 21 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 20 + }, + "end": { + "line": 19, + "column": 22 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 20 + }, + "end": { + "line": 19, + "column": 22 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 20 + }, + "end": { + "line": 19, + "column": 22 + } + } + }, + { + "type": "TSClassImplements", + "expression": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "J", + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 23 + }, + "end": { + "line": 19, + "column": 24 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 23 + }, + "end": { + "line": 19, + "column": 26 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 23 + }, + "end": { + "line": 19, + "column": 26 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 23 + }, + "end": { + "line": 19, + "column": 26 + } + } + } + ], + "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "constructor", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "constructor", + "static": false, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "constructor", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 27 + }, + "end": { + "line": 19, + "column": 27 + } + } + } + ], + "loc": { + "start": { + "line": 19, + "column": 25 + }, + "end": { + "line": 19, + "column": 27 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 1 + }, + "end": { + "line": 19, + "column": 27 + } + } + }, + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "ETSGLOBAL", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "superClass": null, + "implements": [], + "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "_$init$_", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "_$init$_", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "foo", + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 10 + }, + "end": { + "line": 21, + "column": 13 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "foo", + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 10 + }, + "end": { + "line": 21, + "column": 13 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [ + { + "type": "ETSParameterExpression", + "name": { + "type": "Identifier", + "name": "b", + "typeAnnotation": { + "type": "ETSPrimitiveType", + "loc": { + "start": { + "line": 21, + "column": 17 + }, + "end": { + "line": 21, + "column": 20 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 14 + }, + "end": { + "line": 21, + "column": 20 + } + } + }, + "loc": { + "start": { + "line": 21, + "column": 14 + }, + "end": { + "line": 21, + "column": 20 + } + } + }, + { + "type": "ETSParameterExpression", + "name": { + "type": "Identifier", + "name": "a", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "I", + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 25 + }, + "end": { + "line": 21, + "column": 26 + } + } + }, + "loc": { + "start": { + "line": 21, + "column": 25 + }, + "end": { + "line": 21, + "column": 27 + } + } + }, + "loc": { + "start": { + "line": 21, + "column": 25 + }, + "end": { + "line": 21, + "column": 27 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 22 + }, + "end": { + "line": 21, + "column": 27 + } + } + }, + "loc": { + "start": { + "line": 21, + "column": 22 + }, + "end": { + "line": 21, + "column": 27 + } + } + } + ], + "returnType": { + "type": "ETSPrimitiveType", + "loc": { + "start": { + "line": 21, + "column": 29 + }, + "end": { + "line": 21, + "column": 32 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "ReturnStatement", + "argument": { + "type": "Identifier", + "name": "b", + "decorators": [], + "loc": { + "start": { + "line": 22, + "column": 12 + }, + "end": { + "line": 22, + "column": 13 + } + } + }, + "loc": { + "start": { + "line": 22, + "column": 5 + }, + "end": { + "line": 22, + "column": 14 + } + } + } + ], + "loc": { + "start": { + "line": 21, + "column": 33 + }, + "end": { + "line": 23, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 21, + "column": 13 + }, + "end": { + "line": 23, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 21, + "column": 13 + }, + "end": { + "line": 23, + "column": 2 + } + } + }, + "overloads": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "foo", + "decorators": [], + "loc": { + "start": { + "line": 24, + "column": 10 + }, + "end": { + "line": 24, + "column": 13 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "foo", + "decorators": [], + "loc": { + "start": { + "line": 24, + "column": 10 + }, + "end": { + "line": 24, + "column": 13 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [ + { + "type": "ETSParameterExpression", + "name": { + "type": "Identifier", + "name": "d", + "typeAnnotation": { + "type": "ETSPrimitiveType", + "loc": { + "start": { + "line": 24, + "column": 17 + }, + "end": { + "line": 24, + "column": 23 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 24, + "column": 14 + }, + "end": { + "line": 24, + "column": 23 + } + } + }, + "loc": { + "start": { + "line": 24, + "column": 14 + }, + "end": { + "line": 24, + "column": 23 + } + } + }, + { + "type": "ETSParameterExpression", + "name": { + "type": "Identifier", + "name": "a", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "J", + "decorators": [], + "loc": { + "start": { + "line": 24, + "column": 28 + }, + "end": { + "line": 24, + "column": 29 + } + } + }, + "loc": { + "start": { + "line": 24, + "column": 28 + }, + "end": { + "line": 24, + "column": 30 + } + } + }, + "loc": { + "start": { + "line": 24, + "column": 28 + }, + "end": { + "line": 24, + "column": 30 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 24, + "column": 25 + }, + "end": { + "line": 24, + "column": 30 + } + } + }, + "loc": { + "start": { + "line": 24, + "column": 25 + }, + "end": { + "line": 24, + "column": 30 + } + } + } + ], + "returnType": { + "type": "ETSPrimitiveType", + "loc": { + "start": { + "line": 24, + "column": 32 + }, + "end": { + "line": 24, + "column": 38 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "ReturnStatement", + "argument": { + "type": "Identifier", + "name": "d", + "decorators": [], + "loc": { + "start": { + "line": 25, + "column": 12 + }, + "end": { + "line": 25, + "column": 13 + } + } + }, + "loc": { + "start": { + "line": 25, + "column": 5 + }, + "end": { + "line": 25, + "column": 14 + } + } + } + ], + "loc": { + "start": { + "line": 24, + "column": 39 + }, + "end": { + "line": 26, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 24, + "column": 13 + }, + "end": { + "line": 26, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 24, + "column": 13 + }, + "end": { + "line": 26, + "column": 2 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 24, + "column": 1 + }, + "end": { + "line": 26, + "column": 2 + } + } + }, + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "foo", + "decorators": [], + "loc": { + "start": { + "line": 27, + "column": 10 + }, + "end": { + "line": 27, + "column": 13 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "foo", + "decorators": [], + "loc": { + "start": { + "line": 27, + "column": 10 + }, + "end": { + "line": 27, + "column": 13 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [ + { + "type": "ETSParameterExpression", + "name": { + "type": "Identifier", + "name": "a", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "I", + "decorators": [], + "loc": { + "start": { + "line": 27, + "column": 17 + }, + "end": { + "line": 27, + "column": 18 + } + } + }, + "loc": { + "start": { + "line": 27, + "column": 17 + }, + "end": { + "line": 27, + "column": 19 + } + } + }, + "loc": { + "start": { + "line": 27, + "column": 17 + }, + "end": { + "line": 27, + "column": 19 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 27, + "column": 14 + }, + "end": { + "line": 27, + "column": 19 + } + } + }, + "loc": { + "start": { + "line": 27, + "column": 14 + }, + "end": { + "line": 27, + "column": 19 + } + } + }, + { + "type": "ETSParameterExpression", + "name": { + "type": "Identifier", + "name": "b", + "typeAnnotation": { + "type": "ETSPrimitiveType", + "loc": { + "start": { + "line": 27, + "column": 23 + }, + "end": { + "line": 27, + "column": 26 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 27, + "column": 20 + }, + "end": { + "line": 27, + "column": 26 + } + } + }, + "loc": { + "start": { + "line": 27, + "column": 20 + }, + "end": { + "line": 27, + "column": 26 + } + } + } + ], + "returnType": { + "type": "ETSPrimitiveType", + "loc": { + "start": { + "line": 27, + "column": 29 + }, + "end": { + "line": 27, + "column": 32 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "ReturnStatement", + "argument": { + "type": "Identifier", + "name": "b", + "decorators": [], + "loc": { + "start": { + "line": 28, + "column": 12 + }, + "end": { + "line": 28, + "column": 13 + } + } + }, + "loc": { + "start": { + "line": 28, + "column": 5 + }, + "end": { + "line": 28, + "column": 14 + } + } + } + ], + "loc": { + "start": { + "line": 27, + "column": 33 + }, + "end": { + "line": 29, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 27, + "column": 13 + }, + "end": { + "line": 29, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 27, + "column": 13 + }, + "end": { + "line": 29, + "column": 2 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 27, + "column": 1 + }, + "end": { + "line": 29, + "column": 2 + } + } + }, + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "foo", + "decorators": [], + "loc": { + "start": { + "line": 30, + "column": 10 + }, + "end": { + "line": 30, + "column": 13 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "foo", + "decorators": [], + "loc": { + "start": { + "line": 30, + "column": 10 + }, + "end": { + "line": 30, + "column": 13 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [ + { + "type": "ETSParameterExpression", + "name": { + "type": "Identifier", + "name": "a", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "J", + "decorators": [], + "loc": { + "start": { + "line": 30, + "column": 17 + }, + "end": { + "line": 30, + "column": 18 + } + } + }, + "loc": { + "start": { + "line": 30, + "column": 17 + }, + "end": { + "line": 30, + "column": 19 + } + } + }, + "loc": { + "start": { + "line": 30, + "column": 17 + }, + "end": { + "line": 30, + "column": 19 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 30, + "column": 14 + }, + "end": { + "line": 30, + "column": 19 + } + } + }, + "loc": { + "start": { + "line": 30, + "column": 14 + }, + "end": { + "line": 30, + "column": 19 + } + } + }, + { + "type": "ETSParameterExpression", + "name": { + "type": "Identifier", + "name": "d", + "typeAnnotation": { + "type": "ETSPrimitiveType", + "loc": { + "start": { + "line": 30, + "column": 23 + }, + "end": { + "line": 30, + "column": 29 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 30, + "column": 20 + }, + "end": { + "line": 30, + "column": 29 + } + } + }, + "loc": { + "start": { + "line": 30, + "column": 20 + }, + "end": { + "line": 30, + "column": 29 + } + } + } + ], + "returnType": { + "type": "ETSPrimitiveType", + "loc": { + "start": { + "line": 30, + "column": 32 + }, + "end": { + "line": 30, + "column": 38 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "ReturnStatement", + "argument": { + "type": "Identifier", + "name": "d", + "decorators": [], + "loc": { + "start": { + "line": 31, + "column": 12 + }, + "end": { + "line": 31, + "column": 13 + } + } + }, + "loc": { + "start": { + "line": 31, + "column": 5 + }, + "end": { + "line": 31, + "column": 14 + } + } + } + ], + "loc": { + "start": { + "line": 30, + "column": 39 + }, + "end": { + "line": 32, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 30, + "column": 13 + }, + "end": { + "line": 32, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 30, + "column": 13 + }, + "end": { + "line": 32, + "column": 2 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 30, + "column": 1 + }, + "end": { + "line": 32, + "column": 2 + } + } + }, + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "foo", + "decorators": [], + "loc": { + "start": { + "line": 33, + "column": 10 + }, + "end": { + "line": 33, + "column": 13 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "foo", + "decorators": [], + "loc": { + "start": { + "line": 33, + "column": 10 + }, + "end": { + "line": 33, + "column": 13 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [ + { + "type": "ETSParameterExpression", + "name": { + "type": "Identifier", + "name": "a", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "I", + "decorators": [], + "loc": { + "start": { + "line": 33, + "column": 17 + }, + "end": { + "line": 33, + "column": 18 + } + } + }, + "loc": { + "start": { + "line": 33, + "column": 17 + }, + "end": { + "line": 33, + "column": 19 + } + } + }, + "loc": { + "start": { + "line": 33, + "column": 17 + }, + "end": { + "line": 33, + "column": 19 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 33, + "column": 14 + }, + "end": { + "line": 33, + "column": 19 + } + } + }, + "loc": { + "start": { + "line": 33, + "column": 14 + }, + "end": { + "line": 33, + "column": 19 + } + } + }, + { + "type": "ETSParameterExpression", + "name": { + "type": "Identifier", + "name": "d", + "typeAnnotation": { + "type": "ETSPrimitiveType", + "loc": { + "start": { + "line": 33, + "column": 23 + }, + "end": { + "line": 33, + "column": 29 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 33, + "column": 20 + }, + "end": { + "line": 33, + "column": 29 + } + } + }, + "loc": { + "start": { + "line": 33, + "column": 20 + }, + "end": { + "line": 33, + "column": 29 + } + } + } + ], + "returnType": { + "type": "ETSPrimitiveType", + "loc": { + "start": { + "line": 33, + "column": 32 + }, + "end": { + "line": 33, + "column": 38 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "ReturnStatement", + "argument": { + "type": "Identifier", + "name": "d", + "decorators": [], + "loc": { + "start": { + "line": 34, + "column": 12 + }, + "end": { + "line": 34, + "column": 13 + } + } + }, + "loc": { + "start": { + "line": 34, + "column": 5 + }, + "end": { + "line": 34, + "column": 14 + } + } + } + ], + "loc": { + "start": { + "line": 33, + "column": 39 + }, + "end": { + "line": 35, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 33, + "column": 13 + }, + "end": { + "line": 35, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 33, + "column": 13 + }, + "end": { + "line": 35, + "column": 2 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 33, + "column": 1 + }, + "end": { + "line": 35, + "column": 2 + } + } + } + ], + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 1 + }, + "end": { + "line": 23, + "column": 2 + } + } + }, + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 37, + "column": 10 + }, + "end": { + "line": 37, + "column": 14 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 37, + "column": 10 + }, + "end": { + "line": 37, + "column": 14 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "returnType": { + "type": "ETSPrimitiveType", + "loc": { + "start": { + "line": 37, + "column": 18 + }, + "end": { + "line": 37, + "column": 21 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "asd1", + "typeAnnotation": { + "type": "ETSPrimitiveType", + "loc": { + "start": { + "line": 38, + "column": 15 + }, + "end": { + "line": 38, + "column": 18 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 38, + "column": 9 + }, + "end": { + "line": 38, + "column": 13 + } + } + }, + "init": { + "type": "CallExpression", + "callee": { + "type": "Identifier", + "name": "foo", + "decorators": [], + "loc": { + "start": { + "line": 38, + "column": 21 + }, + "end": { + "line": 38, + "column": 24 + } + } + }, + "arguments": [ + { + "type": "NumberLiteral", + "value": 1, + "loc": { + "start": { + "line": 38, + "column": 25 + }, + "end": { + "line": 38, + "column": 26 + } + } + }, + { + "type": "ETSNewClassInstanceExpression", + "typeReference": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "A", + "decorators": [], + "loc": { + "start": { + "line": 38, + "column": 32 + }, + "end": { + "line": 38, + "column": 33 + } + } + }, + "loc": { + "start": { + "line": 38, + "column": 32 + }, + "end": { + "line": 38, + "column": 34 + } + } + }, + "loc": { + "start": { + "line": 38, + "column": 32 + }, + "end": { + "line": 38, + "column": 34 + } + } + }, + "arguments": [], + "loc": { + "start": { + "line": 38, + "column": 28 + }, + "end": { + "line": 38, + "column": 36 + } + } + } + ], + "optional": false, + "loc": { + "start": { + "line": 38, + "column": 21 + }, + "end": { + "line": 38, + "column": 36 + } + } + }, + "loc": { + "start": { + "line": 38, + "column": 9 + }, + "end": { + "line": 38, + "column": 36 + } + } + } + ], + "kind": "let", + "loc": { + "start": { + "line": 38, + "column": 5 + }, + "end": { + "line": 38, + "column": 37 + } + } + }, + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "asd2", + "typeAnnotation": { + "type": "ETSPrimitiveType", + "loc": { + "start": { + "line": 39, + "column": 15 + }, + "end": { + "line": 39, + "column": 21 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 39, + "column": 9 + }, + "end": { + "line": 39, + "column": 13 + } + } + }, + "init": { + "type": "CallExpression", + "callee": { + "type": "Identifier", + "name": "foo", + "decorators": [], + "loc": { + "start": { + "line": 39, + "column": 24 + }, + "end": { + "line": 39, + "column": 27 + } + } + }, + "arguments": [ + { + "type": "NumberLiteral", + "value": 2.1, + "loc": { + "start": { + "line": 39, + "column": 28 + }, + "end": { + "line": 39, + "column": 31 + } + } + }, + { + "type": "ETSNewClassInstanceExpression", + "typeReference": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "A", + "decorators": [], + "loc": { + "start": { + "line": 39, + "column": 37 + }, + "end": { + "line": 39, + "column": 38 + } + } + }, + "loc": { + "start": { + "line": 39, + "column": 37 + }, + "end": { + "line": 39, + "column": 39 + } + } + }, + "loc": { + "start": { + "line": 39, + "column": 37 + }, + "end": { + "line": 39, + "column": 39 + } + } + }, + "arguments": [], + "loc": { + "start": { + "line": 39, + "column": 33 + }, + "end": { + "line": 39, + "column": 41 + } + } + } + ], + "optional": false, + "loc": { + "start": { + "line": 39, + "column": 24 + }, + "end": { + "line": 39, + "column": 41 + } + } + }, + "loc": { + "start": { + "line": 39, + "column": 9 + }, + "end": { + "line": 39, + "column": 41 + } + } + } + ], + "kind": "let", + "loc": { + "start": { + "line": 39, + "column": 5 + }, + "end": { + "line": 39, + "column": 42 + } + } + }, + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "asd3", + "typeAnnotation": { + "type": "ETSPrimitiveType", + "loc": { + "start": { + "line": 40, + "column": 15 + }, + "end": { + "line": 40, + "column": 21 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 40, + "column": 9 + }, + "end": { + "line": 40, + "column": 13 + } + } + }, + "init": { + "type": "CallExpression", + "callee": { + "type": "Identifier", + "name": "foo", + "decorators": [], + "loc": { + "start": { + "line": 40, + "column": 24 + }, + "end": { + "line": 40, + "column": 27 + } + } + }, + "arguments": [ + { + "type": "NumberLiteral", + "value": 2, + "loc": { + "start": { + "line": 40, + "column": 28 + }, + "end": { + "line": 40, + "column": 31 + } + } + }, + { + "type": "ETSNewClassInstanceExpression", + "typeReference": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "A", + "decorators": [], + "loc": { + "start": { + "line": 40, + "column": 37 + }, + "end": { + "line": 40, + "column": 38 + } + } + }, + "loc": { + "start": { + "line": 40, + "column": 37 + }, + "end": { + "line": 40, + "column": 39 + } + } + }, + "loc": { + "start": { + "line": 40, + "column": 37 + }, + "end": { + "line": 40, + "column": 39 + } + } + }, + "arguments": [], + "loc": { + "start": { + "line": 40, + "column": 33 + }, + "end": { + "line": 40, + "column": 41 + } + } + } + ], + "optional": false, + "loc": { + "start": { + "line": 40, + "column": 24 + }, + "end": { + "line": 40, + "column": 41 + } + } + }, + "loc": { + "start": { + "line": 40, + "column": 9 + }, + "end": { + "line": 40, + "column": 41 + } + } + } + ], + "kind": "let", + "loc": { + "start": { + "line": 40, + "column": 5 + }, + "end": { + "line": 40, + "column": 42 + } + } + }, + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "asd4", + "typeAnnotation": { + "type": "ETSPrimitiveType", + "loc": { + "start": { + "line": 41, + "column": 15 + }, + "end": { + "line": 41, + "column": 18 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 41, + "column": 9 + }, + "end": { + "line": 41, + "column": 13 + } + } + }, + "init": { + "type": "CallExpression", + "callee": { + "type": "Identifier", + "name": "foo", + "decorators": [], + "loc": { + "start": { + "line": 41, + "column": 21 + }, + "end": { + "line": 41, + "column": 24 + } + } + }, + "arguments": [ + { + "type": "ETSNewClassInstanceExpression", + "typeReference": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "A", + "decorators": [], + "loc": { + "start": { + "line": 41, + "column": 29 + }, + "end": { + "line": 41, + "column": 30 + } + } + }, + "loc": { + "start": { + "line": 41, + "column": 29 + }, + "end": { + "line": 41, + "column": 31 + } + } + }, + "loc": { + "start": { + "line": 41, + "column": 29 + }, + "end": { + "line": 41, + "column": 31 + } + } + }, + "arguments": [], + "loc": { + "start": { + "line": 41, + "column": 25 + }, + "end": { + "line": 41, + "column": 33 + } + } + }, + { + "type": "NumberLiteral", + "value": 1, + "loc": { + "start": { + "line": 41, + "column": 34 + }, + "end": { + "line": 41, + "column": 35 + } + } + } + ], + "optional": false, + "loc": { + "start": { + "line": 41, + "column": 21 + }, + "end": { + "line": 41, + "column": 36 + } + } + }, + "loc": { + "start": { + "line": 41, + "column": 9 + }, + "end": { + "line": 41, + "column": 36 + } + } + } + ], + "kind": "let", + "loc": { + "start": { + "line": 41, + "column": 5 + }, + "end": { + "line": 41, + "column": 37 + } + } + }, + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "asd5", + "typeAnnotation": { + "type": "ETSPrimitiveType", + "loc": { + "start": { + "line": 42, + "column": 15 + }, + "end": { + "line": 42, + "column": 21 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 42, + "column": 9 + }, + "end": { + "line": 42, + "column": 13 + } + } + }, + "init": { + "type": "CallExpression", + "callee": { + "type": "Identifier", + "name": "foo", + "decorators": [], + "loc": { + "start": { + "line": 42, + "column": 24 + }, + "end": { + "line": 42, + "column": 27 + } + } + }, + "arguments": [ + { + "type": "ETSNewClassInstanceExpression", + "typeReference": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "A", + "decorators": [], + "loc": { + "start": { + "line": 42, + "column": 32 + }, + "end": { + "line": 42, + "column": 33 + } + } + }, + "loc": { + "start": { + "line": 42, + "column": 32 + }, + "end": { + "line": 42, + "column": 34 + } + } + }, + "loc": { + "start": { + "line": 42, + "column": 32 + }, + "end": { + "line": 42, + "column": 34 + } + } + }, + "arguments": [], + "loc": { + "start": { + "line": 42, + "column": 28 + }, + "end": { + "line": 42, + "column": 36 + } + } + }, + { + "type": "NumberLiteral", + "value": 2.1, + "loc": { + "start": { + "line": 42, + "column": 37 + }, + "end": { + "line": 42, + "column": 40 + } + } + } + ], + "optional": false, + "loc": { + "start": { + "line": 42, + "column": 24 + }, + "end": { + "line": 42, + "column": 41 + } + } + }, + "loc": { + "start": { + "line": 42, + "column": 9 + }, + "end": { + "line": 42, + "column": 41 + } + } + } + ], + "kind": "let", + "loc": { + "start": { + "line": 42, + "column": 5 + }, + "end": { + "line": 42, + "column": 42 + } + } + }, + { + "type": "ReturnStatement", + "argument": { + "type": "NumberLiteral", + "value": 0, + "loc": { + "start": { + "line": 43, + "column": 12 + }, + "end": { + "line": 43, + "column": 13 + } + } + }, + "loc": { + "start": { + "line": 43, + "column": 5 + }, + "end": { + "line": 43, + "column": 14 + } + } + } + ], + "loc": { + "start": { + "line": 37, + "column": 22 + }, + "end": { + "line": 44, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 37, + "column": 14 + }, + "end": { + "line": 44, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 37, + "column": 14 + }, + "end": { + "line": 44, + "column": 2 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 37, + "column": 1 + }, + "end": { + "line": 44, + "column": 2 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 44, + "column": 2 + } + } +} +TypeError: Call to `foo` is ambiguous as `2` versions of `foo` are available: `foo(a: J, d: double): double` and `foo(a: I, d: double): double` [method-resolution-class-and-interface-in-signatures_6.ets:42:24] diff --git a/ets2panda/test/compiler/ets/method-resolution-class-and-interface-in-signatures_6.ets b/ets2panda/test/compiler/ets/method-resolution-class-and-interface-in-signatures_6.ets new file mode 100644 index 0000000000000000000000000000000000000000..a6b43ef72ce4b2c8b95ddf1fd4d679b66e09c7dd --- /dev/null +++ b/ets2panda/test/compiler/ets/method-resolution-class-and-interface-in-signatures_6.ets @@ -0,0 +1,44 @@ +/* + * 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. + */ + +interface I {} +interface J {} + +class A implements I, J {} + +function foo(b: int, a: I): int { + return b; +} +function foo(d: double, a: J): double { + return d; +} +function foo(a: I, b: int): int { + return b; +} +function foo(a: J, d: double): double { + return d; +} +function foo(a: I, d: double): double { + return d; +} + +function main(): int { + let asd1: int = foo(1, new A()); + let asd2: double = foo(2.1, new A()); + let asd3: double = foo(2.0, new A()); + let asd4: int = foo(new A(), 1); + let asd5: double = foo(new A(), 2.1); + return 0; +} \ No newline at end of file diff --git a/ets2panda/test/compiler/ets/objectLiteralAbstract-expected.txt b/ets2panda/test/compiler/ets/objectLiteralAbstract-expected.txt index 69b8a1f75481b700c511885771312e5b850412c8..e4799e206c3975afe37d67236466909ca6fbeff2 100644 --- a/ets2panda/test/compiler/ets/objectLiteralAbstract-expected.txt +++ b/ets2panda/test/compiler/ets/objectLiteralAbstract-expected.txt @@ -243,23 +243,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 18, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 18, + "column": 14 } } }, "loc": { "start": { - "line": 1, + "line": 18, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 18, + "column": 15 } } } @@ -378,12 +378,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 18, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 18, + "column": 11 } } } diff --git a/ets2panda/test/compiler/ets/objectLiteralBadKey-expected.txt b/ets2panda/test/compiler/ets/objectLiteralBadKey-expected.txt index 69dabbbb8f507ece4fa449766a3bac54b2f53dd4..37364fa25b8d25f5d7a19254dfe384a02a91aee4 100644 --- a/ets2panda/test/compiler/ets/objectLiteralBadKey-expected.txt +++ b/ets2panda/test/compiler/ets/objectLiteralBadKey-expected.txt @@ -289,23 +289,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 19, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 21, + "column": 2 } } }, "loc": { "start": { - "line": 1, + "line": 19, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 21, + "column": 3 } } } @@ -424,12 +424,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 19, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 19, + "column": 11 } } } diff --git a/ets2panda/test/compiler/ets/objectLiteralInaccessibleKey-expected.txt b/ets2panda/test/compiler/ets/objectLiteralInaccessibleKey-expected.txt index 3d5876a288aea2b930633f3cdd5079405613bc24..7d776f219ab4f37e9980605c8736ed316acc3b00 100644 --- a/ets2panda/test/compiler/ets/objectLiteralInaccessibleKey-expected.txt +++ b/ets2panda/test/compiler/ets/objectLiteralInaccessibleKey-expected.txt @@ -62,12 +62,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 17, + "column": 13 }, "end": { - "line": 1, - "column": 1 + "line": 17, + "column": 19 } } }, @@ -339,23 +339,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 20, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 22, + "column": 2 } } }, "loc": { "start": { - "line": 1, + "line": 20, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 22, + "column": 3 } } } @@ -474,12 +474,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 20, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 20, + "column": 11 } } } diff --git a/ets2panda/test/compiler/ets/objectLiteralInterface-expected.txt b/ets2panda/test/compiler/ets/objectLiteralInterface-expected.txt index 2fca7389c448f7bcba61df2a0c56c44087316526..368098ad83f6eb7b5f35661510a5781ab22f2714 100644 --- a/ets2panda/test/compiler/ets/objectLiteralInterface-expected.txt +++ b/ets2panda/test/compiler/ets/objectLiteralInterface-expected.txt @@ -149,23 +149,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 18, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 18, + "column": 14 } } }, "loc": { "start": { - "line": 1, + "line": 18, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 18, + "column": 15 } } } @@ -284,12 +284,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 18, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 18, + "column": 11 } } } diff --git a/ets2panda/test/compiler/ets/objectLiteralNoContextType-expected.txt b/ets2panda/test/compiler/ets/objectLiteralNoContextType-expected.txt index 58b54f8ad1ed0153e11c6f54b1a8169e74561474..ef22164be00fe61f84da4df0bdc7c4adc381728e 100644 --- a/ets2panda/test/compiler/ets/objectLiteralNoContextType-expected.txt +++ b/ets2panda/test/compiler/ets/objectLiteralNoContextType-expected.txt @@ -106,23 +106,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 16, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 16, + "column": 11 } } }, "loc": { "start": { - "line": 1, + "line": 16, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 16, + "column": 12 } } } @@ -214,12 +214,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 16, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 16, + "column": 11 } } } diff --git a/ets2panda/test/compiler/ets/objectLiteralNoParameterlessConstructor-expected.txt b/ets2panda/test/compiler/ets/objectLiteralNoParameterlessConstructor-expected.txt index 8c92271a75f399b9b7089e85aedc90d9054cc2d7..365d537e22b794e553d61b68cf3d0407320c40f5 100644 --- a/ets2panda/test/compiler/ets/objectLiteralNoParameterlessConstructor-expected.txt +++ b/ets2panda/test/compiler/ets/objectLiteralNoParameterlessConstructor-expected.txt @@ -286,23 +286,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 20, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 20, + "column": 14 } } }, "loc": { "start": { - "line": 1, + "line": 20, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 20, + "column": 15 } } } @@ -421,12 +421,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 20, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 20, + "column": 11 } } } diff --git a/ets2panda/test/compiler/ets/objectLiteralNoSuchKey-expected.txt b/ets2panda/test/compiler/ets/objectLiteralNoSuchKey-expected.txt index 3a47a2cb86681feb3c7fd71b08a0399ba4820788..d7eb3607ecdda660cc4a5d74dd402f5e03f19c6d 100644 --- a/ets2panda/test/compiler/ets/objectLiteralNoSuchKey-expected.txt +++ b/ets2panda/test/compiler/ets/objectLiteralNoSuchKey-expected.txt @@ -290,23 +290,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 19, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 21, + "column": 2 } } }, "loc": { "start": { - "line": 1, + "line": 19, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 21, + "column": 3 } } } @@ -425,12 +425,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 19, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 19, + "column": 11 } } } diff --git a/ets2panda/test/compiler/ets/objectLiteralPrimitiveContextType-expected.txt b/ets2panda/test/compiler/ets/objectLiteralPrimitiveContextType-expected.txt index 67be00033869b6b07c182be1b7272d5bdf81ce6e..15dc9ad6b1f1d483d7ac083b9f8a22f8341d1e22 100644 --- a/ets2panda/test/compiler/ets/objectLiteralPrimitiveContextType-expected.txt +++ b/ets2panda/test/compiler/ets/objectLiteralPrimitiveContextType-expected.txt @@ -106,23 +106,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 16, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 16, + "column": 16 } } }, "loc": { "start": { - "line": 1, + "line": 16, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 16, + "column": 17 } } } @@ -213,12 +213,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 16, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 16, + "column": 11 } } } diff --git a/ets2panda/test/compiler/ets/objectLiteralPrivateConstructor-expected.txt b/ets2panda/test/compiler/ets/objectLiteralPrivateConstructor-expected.txt index 270254e5ab5f47498bbfd189e99e126943f37d16..65af224bc883906b76a4648d61499d8d66007624 100644 --- a/ets2panda/test/compiler/ets/objectLiteralPrivateConstructor-expected.txt +++ b/ets2panda/test/compiler/ets/objectLiteralPrivateConstructor-expected.txt @@ -244,23 +244,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 20, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 20, + "column": 14 } } }, "loc": { "start": { - "line": 1, + "line": 20, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 20, + "column": 15 } } } @@ -379,12 +379,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 20, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 20, + "column": 11 } } } diff --git a/ets2panda/test/compiler/ets/objectLiteralReadonlyKey-expected.txt b/ets2panda/test/compiler/ets/objectLiteralReadonlyKey-expected.txt index f98ed82a485635ee8ca5508daad2bd618b0d136c..277e55a111bd4dcedf02ac2061caecd338b5fc33 100644 --- a/ets2panda/test/compiler/ets/objectLiteralReadonlyKey-expected.txt +++ b/ets2panda/test/compiler/ets/objectLiteralReadonlyKey-expected.txt @@ -62,12 +62,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 17, + "column": 14 }, "end": { - "line": 1, - "column": 1 + "line": 17, + "column": 20 } } }, @@ -339,23 +339,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 20, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 22, + "column": 2 } } }, "loc": { "start": { - "line": 1, + "line": 20, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 22, + "column": 3 } } } @@ -474,12 +474,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 20, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 20, + "column": 11 } } } diff --git a/ets2panda/test/compiler/ets/objectLiteralWrongValueType-expected.txt b/ets2panda/test/compiler/ets/objectLiteralWrongValueType-expected.txt index cba33cf83f95878978207ba234016f9e56128c85..b391dd776152656baf1fa61458c423c4940fd5ce 100644 --- a/ets2panda/test/compiler/ets/objectLiteralWrongValueType-expected.txt +++ b/ets2panda/test/compiler/ets/objectLiteralWrongValueType-expected.txt @@ -62,12 +62,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 17, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 17, + "column": 11 } } }, @@ -339,23 +339,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 20, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 22, + "column": 2 } } }, "loc": { "start": { - "line": 1, + "line": 20, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 22, + "column": 3 } } } @@ -474,12 +474,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 20, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 20, + "column": 11 } } } diff --git a/ets2panda/test/compiler/ets/optionalLambdaParameter-expected.txt b/ets2panda/test/compiler/ets/optionalLambdaParameter-expected.txt index ca7577b0c36d6ae925de3505c46b5f2b8364e2c6..9924e957d690a3113855b4d71560149411b50da3 100644 --- a/ets2panda/test/compiler/ets/optionalLambdaParameter-expected.txt +++ b/ets2panda/test/compiler/ets/optionalLambdaParameter-expected.txt @@ -513,7 +513,7 @@ "type": "ETSParameterExpression", "name": { "type": "Identifier", - "name": "proxy_int", + "name": "$proxy_mask$", "typeAnnotation": { "type": "ETSPrimitiveType", "loc": { @@ -608,7 +608,7 @@ "operator": ">>", "left": { "type": "Identifier", - "name": "proxy_int", + "name": "$proxy_mask$", "decorators": [], "loc": { "start": { diff --git a/ets2panda/test/compiler/ets/setArrayLength1-expected.txt b/ets2panda/test/compiler/ets/setArrayLength1-expected.txt index a494136da14d4df2024aea6e9c83c5d5eb0b48d5..df6abda8adaa59f33375167c80fd2c1300d8de28 100644 --- a/ets2panda/test/compiler/ets/setArrayLength1-expected.txt +++ b/ets2panda/test/compiler/ets/setArrayLength1-expected.txt @@ -132,12 +132,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 17, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 17, + "column": 34 } } }, diff --git a/ets2panda/test/compiler/ets/superReferenceFromStaticContext-expected.txt b/ets2panda/test/compiler/ets/superReferenceFromStaticContext-expected.txt index 2d6182f988e66d750e26381fee3cc349495e7957..0fe5d6df8dda8edc812d63a41138d508cbd0428e 100644 --- a/ets2panda/test/compiler/ets/superReferenceFromStaticContext-expected.txt +++ b/ets2panda/test/compiler/ets/superReferenceFromStaticContext-expected.txt @@ -76,12 +76,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 17, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 17, + "column": 15 } } }, diff --git a/ets2panda/test/compiler/ets/thisReferenceFromStaticContext-expected.txt b/ets2panda/test/compiler/ets/thisReferenceFromStaticContext-expected.txt index 19f43b83628682f7616844eaa4604b51a56bfd86..28b0b12faeb806eaed28de7f60d7958426bbf331 100644 --- a/ets2panda/test/compiler/ets/thisReferenceFromStaticContext-expected.txt +++ b/ets2panda/test/compiler/ets/thisReferenceFromStaticContext-expected.txt @@ -233,12 +233,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 21, + "column": 12 }, "end": { - "line": 1, - "column": 1 + "line": 21, + "column": 23 } } }, diff --git a/ets2panda/test/compiler/ets/throwingFunctionCheck1-expected.txt b/ets2panda/test/compiler/ets/throwingFunctionCheck1-expected.txt index 76f6ac6fcda6ef5d615c5ba6043773fa4224bfbc..14b1a16a4052ff3326d0faf4d09ed45a02c3c214 100644 --- a/ets2panda/test/compiler/ets/throwingFunctionCheck1-expected.txt +++ b/ets2panda/test/compiler/ets/throwingFunctionCheck1-expected.txt @@ -122,23 +122,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 18, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 18, + "column": 27 } } }, "loc": { "start": { - "line": 1, + "line": 18, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 18, + "column": 28 } } } @@ -382,12 +382,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 18, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 18, + "column": 27 } } } diff --git a/ets2panda/test/compiler/ets/typeAlias-expected.txt b/ets2panda/test/compiler/ets/typeAlias-expected.txt index afd663e75c8cf939ac914e00ab8557a5902f9318..4f17d69d03438581f00eefe50e28732e1d2d4227 100644 --- a/ets2panda/test/compiler/ets/typeAlias-expected.txt +++ b/ets2panda/test/compiler/ets/typeAlias-expected.txt @@ -167,23 +167,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 17, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 17, + "column": 28 } } }, "loc": { "start": { - "line": 1, + "line": 17, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 17, + "column": 29 } } } @@ -336,12 +336,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 17, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 17, + "column": 28 } } } diff --git a/ets2panda/test/compiler/ets/union_types_1-expected.txt b/ets2panda/test/compiler/ets/union_types_1-expected.txt index 124c26c7ed81d78a771058243ca42cbbb295f32c..c6343a07d2af189303ee52626d73928658599864 100644 --- a/ets2panda/test/compiler/ets/union_types_1-expected.txt +++ b/ets2panda/test/compiler/ets/union_types_1-expected.txt @@ -76,12 +76,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 17, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 17, + "column": 18 } } }, @@ -276,12 +276,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 21, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 21, + "column": 18 } } }, @@ -476,12 +476,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 25, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 25, + "column": 18 } } }, diff --git a/ets2panda/test/compiler/ets/union_types_2-expected.txt b/ets2panda/test/compiler/ets/union_types_2-expected.txt index 868389447b183772a6d3affbcd902e8bfbcc5715..02bad5efa30c8e9a195fca186ff7cda9332d71c0 100644 --- a/ets2panda/test/compiler/ets/union_types_2-expected.txt +++ b/ets2panda/test/compiler/ets/union_types_2-expected.txt @@ -213,12 +213,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 19, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 19, + "column": 18 } } }, @@ -413,12 +413,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 23, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 23, + "column": 18 } } }, diff --git a/ets2panda/test/compiler/ets/union_types_4-expected.txt b/ets2panda/test/compiler/ets/union_types_4-expected.txt index f69abcff990d30f21f336bdbc510840c89d79cb4..3ae46f4f245c157c7e296e237c49a9f52d4ef420 100644 --- a/ets2panda/test/compiler/ets/union_types_4-expected.txt +++ b/ets2panda/test/compiler/ets/union_types_4-expected.txt @@ -76,12 +76,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 17, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 17, + "column": 18 } } }, diff --git a/ets2panda/test/compiler/ets/union_types_5-expected.txt b/ets2panda/test/compiler/ets/union_types_5-expected.txt index 1ca5dd87b41c5782c6c35e20978a00677fa6680f..3a041975ac79846e59708c3e456c28967f60f1c1 100644 --- a/ets2panda/test/compiler/ets/union_types_5-expected.txt +++ b/ets2panda/test/compiler/ets/union_types_5-expected.txt @@ -174,12 +174,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 17, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 17, + "column": 15 } } }, @@ -374,12 +374,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 20, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 20, + "column": 18 } } }, @@ -574,12 +574,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 23, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 23, + "column": 18 } } }, diff --git a/ets2panda/test/compiler/ets/voidTypeInBinaryOperation-expected.txt b/ets2panda/test/compiler/ets/voidTypeInBinaryOperation-expected.txt index 9447d6cad027d103c65b993701124e7455b4a3ba..b434ae012cb969a610d026fa49e92884441b5d35 100644 --- a/ets2panda/test/compiler/ets/voidTypeInBinaryOperation-expected.txt +++ b/ets2panda/test/compiler/ets/voidTypeInBinaryOperation-expected.txt @@ -494,3 +494,4 @@ } } } +TypeError: An expression of type 'void' cannot be tested for truthiness [voidTypeInBinaryOperation.ets:20:19] diff --git a/ets2panda/test/options/CMakeLists.txt b/ets2panda/test/options/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..dd46aabd24b3a973ddc8c820bc2c5ce49e6e2a7f --- /dev/null +++ b/ets2panda/test/options/CMakeLists.txt @@ -0,0 +1,36 @@ +# Copyright (c) 2021-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. + +if(CMAKE_CROSSCOMPILING) + return() +endif() + +add_custom_target(es2panda_tests_options) +add_dependencies(es2panda_tests es2panda_tests_options) + +function(check_option_help_otput target_name INPUT_ARGS OUTPUT_HELP_LINE) + separate_arguments(INPUT_ARGS) + add_custom_target(es2panda_check_opts_${target_name} + COMMENT "es2panda: checking option ${INPUT_ARGS}" + COMMAND es2panda ${INPUT_ARGS} 2> ${CMAKE_BINARY_DIR}/es2panda_check_opts_${target_name}.out || true + COMMAND grep -q ${OUTPUT_HELP_LINE} ${CMAKE_BINARY_DIR}/es2panda_check_opts_${target_name}.out + DEPENDS es2panda + ) + + add_dependencies(es2panda_tests_options es2panda_check_opts_${target_name}) +endfunction() + +check_option_help_otput(bco_opt "--help" "bco-optimizer:") +check_option_help_otput(bco_opt_help "--bco-optimizer --help" "bytecode-opt-peepholes:") +check_option_help_otput(comp_opt "--help" "bco-compiler:") +check_option_help_otput(comp_opt_help "--bco-compiler --help" "compiler-disasm-dump:") diff --git a/ets2panda/test/parser/ets/AccessBinaryTrees-expected.txt b/ets2panda/test/parser/ets/AccessBinaryTrees-expected.txt index df130879674f709131f58e8118451cf1885bee5f..d5501d37a78b4b9f0ffdf8acd77fb4c6087cdaf2 100644 --- a/ets2panda/test/parser/ets/AccessBinaryTrees-expected.txt +++ b/ets2panda/test/parser/ets/AccessBinaryTrees-expected.txt @@ -90,12 +90,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 17, + "column": 11 }, "end": { - "line": 1, - "column": 1 + "line": 17, + "column": 27 } } }, @@ -167,12 +167,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 18, + "column": 11 }, "end": { - "line": 1, - "column": 1 + "line": 18, + "column": 28 } } }, @@ -216,12 +216,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 19, + "column": 11 }, "end": { - "line": 1, - "column": 1 + "line": 19, + "column": 20 } } }, @@ -1348,12 +1348,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 36, + "column": 19 }, "end": { - "line": 1, - "column": 1 + "line": 36, + "column": 33 } } }, @@ -1398,12 +1398,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 37, + "column": 19 }, "end": { - "line": 1, - "column": 1 + "line": 37, + "column": 31 } } }, @@ -1463,12 +1463,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 38, + "column": 19 }, "end": { - "line": 1, - "column": 1 + "line": 38, + "column": 32 } } }, diff --git a/ets2panda/test/parser/ets/AccessFannkuch-expected.txt b/ets2panda/test/parser/ets/AccessFannkuch-expected.txt index ae08c0e2bc89e3161066f26273a90a2abac937a2..bf878c72fa03e37a869114189c2edde404646afe 100644 --- a/ets2panda/test/parser/ets/AccessFannkuch-expected.txt +++ b/ets2panda/test/parser/ets/AccessFannkuch-expected.txt @@ -62,12 +62,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 17, + "column": 12 }, "end": { - "line": 1, - "column": 1 + "line": 17, + "column": 18 } } }, @@ -304,12 +304,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 22, + "column": 12 }, "end": { - "line": 1, - "column": 1 + "line": 22, + "column": 30 } } }, diff --git a/ets2panda/test/parser/ets/AccessNBody-expected.txt b/ets2panda/test/parser/ets/AccessNBody-expected.txt index 71bf383517453d950e44559734f7abe60cc0a7a3..068b84444be6b15f224b93399867d68cccc4efd4 100644 --- a/ets2panda/test/parser/ets/AccessNBody-expected.txt +++ b/ets2panda/test/parser/ets/AccessNBody-expected.txt @@ -206,12 +206,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 20, + "column": 14 }, "end": { - "line": 1, - "column": 1 + "line": 20, + "column": 47 } } }, @@ -255,12 +255,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 21, + "column": 6 }, "end": { - "line": 1, - "column": 1 + "line": 21, + "column": 16 } } }, @@ -304,12 +304,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 22, + "column": 6 }, "end": { - "line": 1, - "column": 1 + "line": 22, + "column": 16 } } }, @@ -353,12 +353,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 23, + "column": 6 }, "end": { - "line": 1, - "column": 1 + "line": 23, + "column": 16 } } }, @@ -402,12 +402,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 24, + "column": 6 }, "end": { - "line": 1, - "column": 1 + "line": 24, + "column": 17 } } }, @@ -451,12 +451,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 25, + "column": 6 }, "end": { - "line": 1, - "column": 1 + "line": 25, + "column": 17 } } }, @@ -500,12 +500,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 26, + "column": 6 }, "end": { - "line": 1, - "column": 1 + "line": 26, + "column": 17 } } }, @@ -549,12 +549,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 27, + "column": 6 }, "end": { - "line": 1, - "column": 1 + "line": 27, + "column": 19 } } }, @@ -2418,12 +2418,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 47, + "column": 6 }, "end": { - "line": 1, - "column": 1 + "line": 47, + "column": 23 } } }, @@ -10644,12 +10644,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 119, + "column": 21 }, "end": { - "line": 1, - "column": 1 + "line": 119, + "column": 54 } } }, @@ -10707,12 +10707,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 120, + "column": 21 }, "end": { - "line": 1, - "column": 1 + "line": 120, + "column": 52 } } }, @@ -10770,12 +10770,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 121, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 121, + "column": 17 } } }, @@ -10833,12 +10833,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 122, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 122, + "column": 18 } } }, @@ -13551,12 +13551,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 139, + "column": 14 }, "end": { - "line": 1, - "column": 1 + "line": 139, + "column": 53 } } }, diff --git a/ets2panda/test/parser/ets/AccessNSieve-expected.txt b/ets2panda/test/parser/ets/AccessNSieve-expected.txt index c51455e4dd544f0e1444e2169f38211620f221ea..e9379ad0e68b659f0e6efe5606a982a1314bc11a 100644 --- a/ets2panda/test/parser/ets/AccessNSieve-expected.txt +++ b/ets2panda/test/parser/ets/AccessNSieve-expected.txt @@ -76,12 +76,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 17, + "column": 19 }, "end": { - "line": 1, - "column": 1 + "line": 17, + "column": 30 } } }, @@ -139,12 +139,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 18, + "column": 19 }, "end": { - "line": 1, - "column": 1 + "line": 18, + "column": 34 } } }, @@ -202,12 +202,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 19, + "column": 19 }, "end": { - "line": 1, - "column": 1 + "line": 19, + "column": 40 } } }, @@ -264,12 +264,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 20, + "column": 10 }, "end": { - "line": 1, - "column": 1 + "line": 20, + "column": 29 } } }, diff --git a/ets2panda/test/parser/ets/Bitops3BitBitsInByte-expected.txt b/ets2panda/test/parser/ets/Bitops3BitBitsInByte-expected.txt index 1eccd3fe82a3342280f4f27fe92748eee1cca953..a298f24c52b74b3278008473dccf4b51f0f2f877 100644 --- a/ets2panda/test/parser/ets/Bitops3BitBitsInByte-expected.txt +++ b/ets2panda/test/parser/ets/Bitops3BitBitsInByte-expected.txt @@ -893,12 +893,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 26, + "column": 11 }, "end": { - "line": 1, - "column": 1 + "line": 26, + "column": 24 } } }, @@ -956,12 +956,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 27, + "column": 11 }, "end": { - "line": 1, - "column": 1 + "line": 27, + "column": 24 } } }, @@ -1019,12 +1019,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 28, + "column": 27 }, "end": { - "line": 1, - "column": 1 + "line": 28, + "column": 49 } } }, diff --git a/ets2panda/test/parser/ets/BitopsBitsInByte-expected.txt b/ets2panda/test/parser/ets/BitopsBitsInByte-expected.txt index 9f7a9bfd2fbf598bb3d9bc99e2489e3de2186e25..dd67845c62470f0b84d2c2dcf4779e29c60d5636 100644 --- a/ets2panda/test/parser/ets/BitopsBitsInByte-expected.txt +++ b/ets2panda/test/parser/ets/BitopsBitsInByte-expected.txt @@ -667,12 +667,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 29, + "column": 11 }, "end": { - "line": 1, - "column": 1 + "line": 29, + "column": 24 } } }, @@ -730,12 +730,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 30, + "column": 11 }, "end": { - "line": 1, - "column": 1 + "line": 30, + "column": 24 } } }, @@ -793,12 +793,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 31, + "column": 27 }, "end": { - "line": 1, - "column": 1 + "line": 31, + "column": 49 } } }, diff --git a/ets2panda/test/parser/ets/BitopsBitwiseAnd-expected.txt b/ets2panda/test/parser/ets/BitopsBitwiseAnd-expected.txt index b7f077ed40726f59e9e5d73ebdef996d6a64967c..d9d3f5b4cc96b7c69151f5322ff837966c350543 100644 --- a/ets2panda/test/parser/ets/BitopsBitwiseAnd-expected.txt +++ b/ets2panda/test/parser/ets/BitopsBitwiseAnd-expected.txt @@ -76,12 +76,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 17, + "column": 3 }, "end": { - "line": 1, - "column": 1 + "line": 17, + "column": 18 } } }, @@ -139,12 +139,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 18, + "column": 19 }, "end": { - "line": 1, - "column": 1 + "line": 18, + "column": 37 } } }, diff --git a/ets2panda/test/parser/ets/BitopsNSieveBits-expected.txt b/ets2panda/test/parser/ets/BitopsNSieveBits-expected.txt index a9f4084f952173fceea4fab0ae77bbbce48d02fe..6e174ce74bed36e52d83d3388896a99a5954eadf 100644 --- a/ets2panda/test/parser/ets/BitopsNSieveBits-expected.txt +++ b/ets2panda/test/parser/ets/BitopsNSieveBits-expected.txt @@ -2192,12 +2192,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 42, + "column": 3 }, "end": { - "line": 1, - "column": 1 + "line": 42, + "column": 14 } } }, @@ -2255,12 +2255,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 43, + "column": 3 }, "end": { - "line": 1, - "column": 1 + "line": 43, + "column": 18 } } }, @@ -2333,12 +2333,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 44, + "column": 19 }, "end": { - "line": 1, - "column": 1 + "line": 44, + "column": 50 } } }, diff --git a/ets2panda/test/parser/ets/ControlFlowRecursive-expected.txt b/ets2panda/test/parser/ets/ControlFlowRecursive-expected.txt index d3f54dd3e82aa4f0c91c453e5ca33e53cd1cb6b1..5a053da53e353202d757f71054ec7a9d8c74bf2a 100644 --- a/ets2panda/test/parser/ets/ControlFlowRecursive-expected.txt +++ b/ets2panda/test/parser/ets/ControlFlowRecursive-expected.txt @@ -76,12 +76,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 17, + "column": 19 }, "end": { - "line": 1, - "column": 1 + "line": 17, + "column": 30 } } }, @@ -139,12 +139,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 18, + "column": 19 }, "end": { - "line": 1, - "column": 1 + "line": 18, + "column": 30 } } }, @@ -202,12 +202,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 19, + "column": 19 }, "end": { - "line": 1, - "column": 1 + "line": 19, + "column": 40 } } }, diff --git a/ets2panda/test/parser/ets/Dollar_dollar_1-expected.txt b/ets2panda/test/parser/ets/Dollar_dollar_1-expected.txt index d15e91cc98bfe094ee321a6a12461a4dac52fe31..b50e9e486748a14f8ad68761bfe6093b6b1ee9e0 100644 --- a/ets2panda/test/parser/ets/Dollar_dollar_1-expected.txt +++ b/ets2panda/test/parser/ets/Dollar_dollar_1-expected.txt @@ -121,23 +121,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 16, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 16, + "column": 15 } } }, "loc": { "start": { - "line": 1, + "line": 16, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 16, + "column": 15 } } } @@ -244,12 +244,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 16, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 16, + "column": 15 } } } diff --git a/ets2panda/test/parser/ets/Dollar_dollar_2-expected.txt b/ets2panda/test/parser/ets/Dollar_dollar_2-expected.txt index acae80b8e2e9cdc1cfe19d213215e491496b78a0..43188a188ab441342e467771d57b657272a91d01 100644 --- a/ets2panda/test/parser/ets/Dollar_dollar_2-expected.txt +++ b/ets2panda/test/parser/ets/Dollar_dollar_2-expected.txt @@ -76,12 +76,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 17, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 17, + "column": 29 } } }, @@ -139,12 +139,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 18, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 18, + "column": 23 } } }, @@ -230,12 +230,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 19, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 19, + "column": 36 } } }, diff --git a/ets2panda/test/parser/ets/Dollar_dollar_3-expected.txt b/ets2panda/test/parser/ets/Dollar_dollar_3-expected.txt index b0087ada5fdff4b2fad21b31af6acac4765737c7..f981e5c3544c73106fa0e317c75001073cc238bc 100644 --- a/ets2panda/test/parser/ets/Dollar_dollar_3-expected.txt +++ b/ets2panda/test/parser/ets/Dollar_dollar_3-expected.txt @@ -284,23 +284,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 17, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 18, + "column": 4 } } }, "loc": { "start": { - "line": 1, + "line": 17, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 18, + "column": 4 } } }, @@ -356,23 +356,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 18, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 18, + "column": 12 } } }, "loc": { "start": { - "line": 1, + "line": 18, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 18, + "column": 12 } } } @@ -505,12 +505,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 17, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 18, + "column": 4 } } }, @@ -571,12 +571,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 18, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 18, + "column": 12 } } } diff --git a/ets2panda/test/parser/ets/Dollar_dollar_4-expected.txt b/ets2panda/test/parser/ets/Dollar_dollar_4-expected.txt index ca830b055948632c62e206b61655010901def400..f38a7fdcfff8746312205053549a22f3cd26c14e 100644 --- a/ets2panda/test/parser/ets/Dollar_dollar_4-expected.txt +++ b/ets2panda/test/parser/ets/Dollar_dollar_4-expected.txt @@ -106,23 +106,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 16, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 16, + "column": 16 } } }, "loc": { "start": { - "line": 1, + "line": 16, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 16, + "column": 16 } } } @@ -214,12 +214,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 16, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 16, + "column": 16 } } } diff --git a/ets2panda/test/parser/ets/FunctionType-expected.txt b/ets2panda/test/parser/ets/FunctionType-expected.txt index e7dd67b60f462ab48b7a3449156cf6fc7b1ee24a..051ecf2aa9ba66bce0629e4cfa1a0f047d63f03c 100644 --- a/ets2panda/test/parser/ets/FunctionType-expected.txt +++ b/ets2panda/test/parser/ets/FunctionType-expected.txt @@ -187,12 +187,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 24, + "column": 3 }, "end": { - "line": 1, - "column": 1 + "line": 24, + "column": 32 } } }, @@ -564,12 +564,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 16, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 16, + "column": 32 } } }, @@ -669,12 +669,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 17, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 17, + "column": 26 } } }, diff --git a/ets2panda/test/parser/ets/MathCordic-expected.txt b/ets2panda/test/parser/ets/MathCordic-expected.txt index dd28c3583b68da9afc6a45575b1a8540a3064f04..56e1b883227409c26f070ad2413545b234710af2 100644 --- a/ets2panda/test/parser/ets/MathCordic-expected.txt +++ b/ets2panda/test/parser/ets/MathCordic-expected.txt @@ -76,12 +76,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 17, + "column": 21 }, "end": { - "line": 1, - "column": 1 + "line": 17, + "column": 53 } } }, @@ -139,12 +139,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 18, + "column": 21 }, "end": { - "line": 1, - "column": 1 + "line": 18, + "column": 51 } } }, @@ -202,12 +202,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 19, + "column": 21 }, "end": { - "line": 1, - "column": 1 + "line": 19, + "column": 59 } } }, @@ -1179,12 +1179,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 20, + "column": 21 }, "end": { - "line": 1, - "column": 1 + "line": 20, + "column": 391 } } }, @@ -4633,12 +4633,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 68, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 68, + "column": 12 } } }, diff --git a/ets2panda/test/parser/ets/MathPartialSums-expected.txt b/ets2panda/test/parser/ets/MathPartialSums-expected.txt index efb9d801cafd6b1dd0b5da554a83b48f3557e936..23eb4fa4753baadc7c0603ec692e79ba95aacab8 100644 --- a/ets2panda/test/parser/ets/MathPartialSums-expected.txt +++ b/ets2panda/test/parser/ets/MathPartialSums-expected.txt @@ -76,12 +76,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 17, + "column": 19 }, "end": { - "line": 1, - "column": 1 + "line": 17, + "column": 33 } } }, @@ -139,12 +139,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 18, + "column": 19 }, "end": { - "line": 1, - "column": 1 + "line": 18, + "column": 34 } } }, @@ -202,12 +202,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 19, + "column": 19 }, "end": { - "line": 1, - "column": 1 + "line": 19, + "column": 55 } } }, @@ -265,12 +265,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 20, + "column": 10 }, "end": { - "line": 1, - "column": 1 + "line": 20, + "column": 25 } } }, diff --git a/ets2panda/test/parser/ets/MathSpectralNorm-expected.txt b/ets2panda/test/parser/ets/MathSpectralNorm-expected.txt index 5a90ca960749ceae2867464814f7717b5827b9ab..2c9560bd208fa1b6efacdbb852355181094ec775 100644 --- a/ets2panda/test/parser/ets/MathSpectralNorm-expected.txt +++ b/ets2panda/test/parser/ets/MathSpectralNorm-expected.txt @@ -4998,12 +4998,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 76, + "column": 3 }, "end": { - "line": 1, - "column": 1 + "line": 76, + "column": 14 } } }, @@ -5061,12 +5061,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 77, + "column": 3 }, "end": { - "line": 1, - "column": 1 + "line": 77, + "column": 15 } } }, @@ -5124,12 +5124,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 78, + "column": 27 }, "end": { - "line": 1, - "column": 1 + "line": 78, + "column": 63 } } }, diff --git a/ets2panda/test/parser/ets/Morph3d-expected.txt b/ets2panda/test/parser/ets/Morph3d-expected.txt index 9d8cc669825ef4b65f85256fda25a6d6e7afccec..e5929d51a22301e09c8b302a1d222082630f165a 100644 --- a/ets2panda/test/parser/ets/Morph3d-expected.txt +++ b/ets2panda/test/parser/ets/Morph3d-expected.txt @@ -148,12 +148,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 19, + "column": 27 }, "end": { - "line": 1, - "column": 1 + "line": 19, + "column": 43 } } }, @@ -211,12 +211,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 20, + "column": 27 }, "end": { - "line": 1, - "column": 1 + "line": 20, + "column": 38 } } }, @@ -273,12 +273,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 22, + "column": 10 }, "end": { - "line": 1, - "column": 1 + "line": 22, + "column": 22 } } }, diff --git a/ets2panda/test/parser/ets/StringBase64-expected.txt b/ets2panda/test/parser/ets/StringBase64-expected.txt index 8957ad62c158195c72c9b01a6a3dacb15219a6b3..8ea38a24270626dc74d6c58efc5f568b80e96644 100644 --- a/ets2panda/test/parser/ets/StringBase64-expected.txt +++ b/ets2panda/test/parser/ets/StringBase64-expected.txt @@ -132,12 +132,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 17, + "column": 21 }, "end": { - "line": 1, - "column": 1 + "line": 17, + "column": 119 } } }, @@ -195,12 +195,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 18, + "column": 21 }, "end": { - "line": 1, - "column": 1 + "line": 18, + "column": 44 } } }, @@ -3009,12 +3009,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 19, + "column": 21 }, "end": { - "line": 1, - "column": 1 + "line": 19, + "column": 548 } } }, @@ -9357,12 +9357,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 70, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 70, + "column": 20 } } }, @@ -9420,12 +9420,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 71, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 71, + "column": 21 } } }, diff --git a/ets2panda/test/parser/ets/access_modifier_3-expected.txt b/ets2panda/test/parser/ets/access_modifier_3-expected.txt index a4b4adad2ca3510f091eb4e29cce685bd5631716..6e1441dd51416b58b74ffe14ab1af4e942c94038 100644 --- a/ets2panda/test/parser/ets/access_modifier_3-expected.txt +++ b/ets2panda/test/parser/ets/access_modifier_3-expected.txt @@ -62,12 +62,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 17, + "column": 19 }, "end": { - "line": 1, - "column": 1 + "line": 17, + "column": 25 } } }, diff --git a/ets2panda/test/parser/ets/ambiguous_call_3-expected.txt b/ets2panda/test/parser/ets/ambiguous_call_3-expected.txt index 03787bbfbcd6076f575cf5dd893c470f666ee72d..eaca9b0b5c8b670de976435123d9890766056d5c 100644 --- a/ets2panda/test/parser/ets/ambiguous_call_3-expected.txt +++ b/ets2panda/test/parser/ets/ambiguous_call_3-expected.txt @@ -1209,4 +1209,4 @@ } } } -TypeError: Call to `goo` is ambiguous as `2` versions of `goo` are available: `goo(p1: I1): void` and `goo(p2: B): void` [ambiguous_call_3.ets:23:5] +TypeError: Call to `goo` is ambiguous as `2` versions of `goo` are available: `goo(p2: B): void` and `goo(p1: I1): void` [ambiguous_call_3.ets:23:5] diff --git a/ets2panda/test/parser/ets/anonymous_class-expected.txt b/ets2panda/test/parser/ets/anonymous_class-expected.txt index 44d1aafb1a57c1994c14fafc673e6148e55c5e8f..efcfb803c883d651bd6c892aa919b7f136df6cfa 100644 --- a/ets2panda/test/parser/ets/anonymous_class-expected.txt +++ b/ets2panda/test/parser/ets/anonymous_class-expected.txt @@ -196,12 +196,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 18, + "column": 25 }, "end": { - "line": 1, - "column": 1 + "line": 18, + "column": 38 } } }, @@ -414,12 +414,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 17, + "column": 12 }, "end": { - "line": 1, - "column": 1 + "line": 20, + "column": 7 } } }, diff --git a/ets2panda/test/parser/ets/array-expected.txt b/ets2panda/test/parser/ets/array-expected.txt index b41cb428aa336649bb62adcb20ad8594249697ae..94a5bd22f3afa1dc49d04edd32d2342628ce3c27 100644 --- a/ets2panda/test/parser/ets/array-expected.txt +++ b/ets2panda/test/parser/ets/array-expected.txt @@ -149,23 +149,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 16, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 16, + "column": 23 } } }, "loc": { "start": { - "line": 1, + "line": 16, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 16, + "column": 24 } } }, @@ -248,23 +248,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 17, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 17, + "column": 34 } } }, "loc": { "start": { - "line": 1, + "line": 17, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 17, + "column": 35 } } } @@ -368,12 +368,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 16, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 16, + "column": 15 } } }, @@ -458,12 +458,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 17, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 17, + "column": 18 } } }, diff --git a/ets2panda/test/parser/ets/arrayHoldingNullValue-expected.txt b/ets2panda/test/parser/ets/arrayHoldingNullValue-expected.txt index dabdff4623bcbe79ae17ebc00332ac88bf5b23b4..d9ff0c65bccdf4ff3e8f29a7deff02413dc370e6 100644 --- a/ets2panda/test/parser/ets/arrayHoldingNullValue-expected.txt +++ b/ets2panda/test/parser/ets/arrayHoldingNullValue-expected.txt @@ -106,23 +106,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 16, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 16, + "column": 27 } } }, "loc": { "start": { - "line": 1, + "line": 16, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 16, + "column": 28 } } }, @@ -162,23 +162,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 17, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 17, + "column": 30 } } }, "loc": { "start": { - "line": 1, + "line": 17, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 17, + "column": 31 } } }, @@ -218,23 +218,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 18, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 18, + "column": 30 } } }, "loc": { "start": { - "line": 1, + "line": 18, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 18, + "column": 31 } } } @@ -338,12 +338,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 16, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 16, + "column": 15 } } }, @@ -400,12 +400,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 17, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 17, + "column": 18 } } }, @@ -490,12 +490,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 18, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 18, + "column": 18 } } }, diff --git a/ets2panda/test/parser/ets/array_type-expected.txt b/ets2panda/test/parser/ets/array_type-expected.txt index 58aa59e69cd4a99c9897683ef53036bab75393b3..d86b75cade346005dd3d2f529055dca1674a0e0b 100644 --- a/ets2panda/test/parser/ets/array_type-expected.txt +++ b/ets2panda/test/parser/ets/array_type-expected.txt @@ -215,12 +215,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 19, + "column": 13 }, "end": { - "line": 1, - "column": 1 + "line": 19, + "column": 24 } } }, @@ -303,12 +303,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 20, + "column": 15 }, "end": { - "line": 1, - "column": 1 + "line": 20, + "column": 32 } } }, diff --git a/ets2panda/test/parser/ets/assign-expected.txt b/ets2panda/test/parser/ets/assign-expected.txt index de7bfd7e216b62820733bfca1b4b51248a6e86de..89ce3dbfcaa36a1abdb33489da5ff8c2b95fcd1b 100644 --- a/ets2panda/test/parser/ets/assign-expected.txt +++ b/ets2panda/test/parser/ets/assign-expected.txt @@ -106,23 +106,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 16, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 16, + "column": 10 } } }, "loc": { "start": { - "line": 1, + "line": 16, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 16, + "column": 11 } } } @@ -214,12 +214,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 16, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 16, + "column": 10 } } }, @@ -264,12 +264,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 17, + "column": 7 }, "end": { - "line": 1, - "column": 1 + "line": 17, + "column": 12 } } }, diff --git a/ets2panda/test/parser/ets/assign-func-expected.txt b/ets2panda/test/parser/ets/assign-func-expected.txt index a391d586b28b76439b85bbdf61ac2ae21cb0bf06..9acaaa71d7e17739606f0832fb279a402f803b44 100644 --- a/ets2panda/test/parser/ets/assign-func-expected.txt +++ b/ets2panda/test/parser/ets/assign-func-expected.txt @@ -368,12 +368,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 21, + "column": 13 }, "end": { - "line": 1, - "column": 1 + "line": 21, + "column": 34 } } } diff --git a/ets2panda/test/parser/ets/assignments-expected.txt b/ets2panda/test/parser/ets/assignments-expected.txt index d5dbf6fbb6d7e7398860de6d5cd44a95ad36aea5..a23e936e229dd27f1da9aa2ba4bb7df8679d7bef 100644 --- a/ets2panda/test/parser/ets/assignments-expected.txt +++ b/ets2panda/test/parser/ets/assignments-expected.txt @@ -202,12 +202,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 19, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 19, + "column": 11 } } }, @@ -251,12 +251,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 20, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 20, + "column": 11 } } }, diff --git a/ets2panda/test/parser/ets/async_function-expected.txt b/ets2panda/test/parser/ets/async_function-expected.txt index f9b41ad62976230f90159731e78beb366c4d2b08..5ad52c7a2102a52b95198532b56e5b1029e9a5ba 100644 --- a/ets2panda/test/parser/ets/async_function-expected.txt +++ b/ets2panda/test/parser/ets/async_function-expected.txt @@ -999,12 +999,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 22, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 22, + "column": 96 } } } diff --git a/ets2panda/test/parser/ets/async_lambda_bad-expected.txt b/ets2panda/test/parser/ets/async_lambda_bad-expected.txt index 6928920e681cd9cff7853c4026ae65af7b547fdd..348a522a40c5f421097da5e12cfbec6c86be5e96 100644 --- a/ets2panda/test/parser/ets/async_lambda_bad-expected.txt +++ b/ets2panda/test/parser/ets/async_lambda_bad-expected.txt @@ -256,12 +256,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 16, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 16, + "column": 55 } } } diff --git a/ets2panda/test/parser/ets/async_with_lambda-expected.txt b/ets2panda/test/parser/ets/async_with_lambda-expected.txt index 2007b8a7be58dbdd60a7102bfe8470e58ad5a622..657afa171455554c64b5d2a5cf2dd6abbcda280e 100644 --- a/ets2panda/test/parser/ets/async_with_lambda-expected.txt +++ b/ets2panda/test/parser/ets/async_with_lambda-expected.txt @@ -156,12 +156,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 16, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 16, + "column": 16 } } }, diff --git a/ets2panda/test/parser/ets/await_keyword-expected.txt b/ets2panda/test/parser/ets/await_keyword-expected.txt index 9adc24bf5003ce6ca65d8a6dcb9b75b06f74f263..2159d4df660a84e8b58988960fd248006cbbf539 100644 --- a/ets2panda/test/parser/ets/await_keyword-expected.txt +++ b/ets2panda/test/parser/ets/await_keyword-expected.txt @@ -106,23 +106,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 38, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 38, + "column": 43 } } }, "loc": { "start": { - "line": 1, + "line": 38, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 38, + "column": 44 } } }, @@ -176,23 +176,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 39, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 39, + "column": 33 } } }, "loc": { "start": { - "line": 1, + "line": 39, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 39, + "column": 33 } } } @@ -1308,12 +1308,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 22, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 26, + "column": 2 } } }, @@ -2158,12 +2158,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 33, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 36, + "column": 2 } } }, @@ -2291,12 +2291,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 38, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 38, + "column": 31 } } }, @@ -2368,12 +2368,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 39, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 39, + "column": 18 } } } diff --git a/ets2panda/test/parser/ets/binary_op-expected.txt b/ets2panda/test/parser/ets/binary_op-expected.txt index 4be4d2ea48517d38274b99172e9921e0e2c1134b..f491c8074d578921dbadc41b6583978df7d70555 100644 --- a/ets2panda/test/parser/ets/binary_op-expected.txt +++ b/ets2panda/test/parser/ets/binary_op-expected.txt @@ -106,23 +106,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 17, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 17, + "column": 10 } } }, "loc": { "start": { - "line": 1, + "line": 17, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 17, + "column": 11 } } }, @@ -162,23 +162,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 18, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 18, + "column": 10 } } }, "loc": { "start": { - "line": 1, + "line": 18, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 18, + "column": 11 } } }, @@ -218,23 +218,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 19, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 19, + "column": 14 } } }, "loc": { "start": { - "line": 1, + "line": 19, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 19, + "column": 15 } } }, @@ -274,23 +274,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 20, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 20, + "column": 15 } } }, "loc": { "start": { - "line": 1, + "line": 20, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 20, + "column": 16 } } }, @@ -371,23 +371,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 21, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 21, + "column": 23 } } }, "loc": { "start": { - "line": 1, + "line": 21, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 21, + "column": 23 } } }, @@ -427,23 +427,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 22, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 22, + "column": 29 } } }, "loc": { "start": { - "line": 1, + "line": 22, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 22, + "column": 30 } } }, @@ -513,23 +513,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 25, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 25, + "column": 18 } } }, "loc": { "start": { - "line": 1, + "line": 25, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 25, + "column": 19 } } }, @@ -628,23 +628,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 26, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 26, + "column": 24 } } }, "loc": { "start": { - "line": 1, + "line": 26, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 26, + "column": 25 } } }, @@ -714,23 +714,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 29, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 29, + "column": 19 } } }, "loc": { "start": { - "line": 1, + "line": 29, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 29, + "column": 20 } } }, @@ -800,23 +800,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 30, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 30, + "column": 19 } } }, "loc": { "start": { - "line": 1, + "line": 30, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 30, + "column": 20 } } }, @@ -944,23 +944,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 31, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 31, + "column": 33 } } }, "loc": { "start": { - "line": 1, + "line": 31, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 31, + "column": 34 } } }, @@ -1088,23 +1088,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 32, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 32, + "column": 33 } } }, "loc": { "start": { - "line": 1, + "line": 32, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 32, + "column": 34 } } }, @@ -1232,23 +1232,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 33, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 33, + "column": 33 } } }, "loc": { "start": { - "line": 1, + "line": 33, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 33, + "column": 34 } } }, @@ -1376,23 +1376,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 34, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 34, + "column": 33 } } }, "loc": { "start": { - "line": 1, + "line": 34, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 34, + "column": 34 } } }, @@ -1462,23 +1462,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 37, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 37, + "column": 16 } } }, "loc": { "start": { - "line": 1, + "line": 37, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 37, + "column": 17 } } }, @@ -1548,23 +1548,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 38, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 38, + "column": 16 } } }, "loc": { "start": { - "line": 1, + "line": 38, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 38, + "column": 17 } } }, @@ -1634,23 +1634,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 39, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 39, + "column": 16 } } }, "loc": { "start": { - "line": 1, + "line": 39, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 39, + "column": 17 } } }, @@ -1836,23 +1836,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 40, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 40, + "column": 32 } } }, "loc": { "start": { - "line": 1, + "line": 40, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 40, + "column": 33 } } }, @@ -1922,23 +1922,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 43, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 43, + "column": 17 } } }, "loc": { "start": { - "line": 1, + "line": 43, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 43, + "column": 18 } } }, @@ -2008,23 +2008,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 44, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 44, + "column": 17 } } }, "loc": { "start": { - "line": 1, + "line": 44, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 44, + "column": 18 } } }, @@ -2094,23 +2094,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 45, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 45, + "column": 20 } } }, "loc": { "start": { - "line": 1, + "line": 45, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 45, + "column": 21 } } }, @@ -2180,23 +2180,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 46, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 46, + "column": 20 } } }, "loc": { "start": { - "line": 1, + "line": 46, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 46, + "column": 21 } } }, @@ -2266,23 +2266,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 49, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 49, + "column": 16 } } }, "loc": { "start": { - "line": 1, + "line": 49, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 49, + "column": 17 } } }, @@ -2352,23 +2352,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 50, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 50, + "column": 16 } } }, "loc": { "start": { - "line": 1, + "line": 50, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 50, + "column": 17 } } }, @@ -2438,23 +2438,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 51, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 51, + "column": 17 } } }, "loc": { "start": { - "line": 1, + "line": 51, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 51, + "column": 18 } } }, @@ -2524,23 +2524,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 52, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 52, + "column": 17 } } }, "loc": { "start": { - "line": 1, + "line": 52, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 52, + "column": 18 } } }, @@ -2610,23 +2610,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 53, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 53, + "column": 31 } } }, "loc": { "start": { - "line": 1, + "line": 53, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 53, + "column": 32 } } }, @@ -2696,23 +2696,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 56, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 56, + "column": 17 } } }, "loc": { "start": { - "line": 1, + "line": 56, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 56, + "column": 18 } } }, @@ -2782,23 +2782,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 57, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 57, + "column": 17 } } }, "loc": { "start": { - "line": 1, + "line": 57, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 57, + "column": 18 } } }, @@ -2868,23 +2868,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 58, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 58, + "column": 18 } } }, "loc": { "start": { - "line": 1, + "line": 58, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 58, + "column": 19 } } }, @@ -3012,23 +3012,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 59, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 59, + "column": 28 } } }, "loc": { "start": { - "line": 1, + "line": 59, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 59, + "column": 29 } } }, @@ -3098,23 +3098,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 62, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 62, + "column": 16 } } }, "loc": { "start": { - "line": 1, + "line": 62, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 62, + "column": 17 } } }, @@ -3184,23 +3184,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 63, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 63, + "column": 16 } } }, "loc": { "start": { - "line": 1, + "line": 63, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 63, + "column": 17 } } }, @@ -3328,23 +3328,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 64, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 64, + "column": 24 } } }, "loc": { "start": { - "line": 1, + "line": 64, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 64, + "column": 25 } } }, @@ -3414,23 +3414,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 67, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 67, + "column": 16 } } }, "loc": { "start": { - "line": 1, + "line": 67, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 67, + "column": 17 } } }, @@ -3500,23 +3500,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 68, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 68, + "column": 16 } } }, "loc": { "start": { - "line": 1, + "line": 68, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 68, + "column": 17 } } }, @@ -3586,23 +3586,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 69, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 69, + "column": 16 } } }, "loc": { "start": { - "line": 1, + "line": 69, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 69, + "column": 17 } } }, @@ -3788,23 +3788,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 70, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 70, + "column": 32 } } }, "loc": { "start": { - "line": 1, + "line": 70, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 70, + "column": 33 } } }, @@ -3932,23 +3932,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 73, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 73, + "column": 26 } } }, "loc": { "start": { - "line": 1, + "line": 73, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 73, + "column": 27 } } }, @@ -4076,23 +4076,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 74, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 74, + "column": 28 } } }, "loc": { "start": { - "line": 1, + "line": 74, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 74, + "column": 29 } } }, @@ -4423,23 +4423,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 75, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 75, + "column": 62 } } }, "loc": { "start": { - "line": 1, + "line": 75, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 75, + "column": 63 } } }, @@ -4770,23 +4770,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 76, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 76, + "column": 63 } } }, "loc": { "start": { - "line": 1, + "line": 76, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 76, + "column": 64 } } }, @@ -4943,23 +4943,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 77, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 77, + "column": 34 } } }, "loc": { "start": { - "line": 1, + "line": 77, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 77, + "column": 35 } } } @@ -5051,12 +5051,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 17, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 17, + "column": 10 } } }, @@ -5101,12 +5101,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 18, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 18, + "column": 10 } } }, @@ -5151,12 +5151,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 19, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 19, + "column": 14 } } }, @@ -5201,12 +5201,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 20, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 20, + "column": 15 } } }, @@ -5292,12 +5292,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 21, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 21, + "column": 23 } } }, @@ -5369,12 +5369,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 22, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 22, + "column": 17 } } }, @@ -5449,12 +5449,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 25, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 25, + "column": 18 } } }, @@ -5558,12 +5558,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 26, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 26, + "column": 24 } } }, @@ -5638,12 +5638,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 29, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 29, + "column": 19 } } }, @@ -5718,12 +5718,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 30, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 30, + "column": 19 } } }, @@ -5856,12 +5856,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 31, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 31, + "column": 33 } } }, @@ -5994,12 +5994,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 32, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 32, + "column": 33 } } }, @@ -6132,12 +6132,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 33, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 33, + "column": 33 } } }, @@ -6270,12 +6270,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 34, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 34, + "column": 33 } } }, @@ -6350,12 +6350,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 37, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 37, + "column": 16 } } }, @@ -6430,12 +6430,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 38, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 38, + "column": 16 } } }, @@ -6510,12 +6510,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 39, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 39, + "column": 16 } } }, @@ -6706,12 +6706,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 40, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 40, + "column": 32 } } }, @@ -6786,12 +6786,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 43, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 43, + "column": 17 } } }, @@ -6866,12 +6866,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 44, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 44, + "column": 17 } } }, @@ -6946,12 +6946,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 45, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 45, + "column": 20 } } }, @@ -7026,12 +7026,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 46, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 46, + "column": 20 } } }, @@ -7106,12 +7106,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 49, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 49, + "column": 16 } } }, @@ -7186,12 +7186,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 50, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 50, + "column": 16 } } }, @@ -7266,12 +7266,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 51, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 51, + "column": 17 } } }, @@ -7346,12 +7346,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 52, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 52, + "column": 17 } } }, @@ -7426,12 +7426,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 53, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 53, + "column": 31 } } }, @@ -7506,12 +7506,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 56, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 56, + "column": 17 } } }, @@ -7586,12 +7586,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 57, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 57, + "column": 17 } } }, @@ -7666,12 +7666,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 58, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 58, + "column": 18 } } }, @@ -7804,12 +7804,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 59, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 59, + "column": 28 } } }, @@ -7884,12 +7884,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 62, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 62, + "column": 16 } } }, @@ -7964,12 +7964,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 63, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 63, + "column": 16 } } }, @@ -8102,12 +8102,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 64, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 64, + "column": 24 } } }, @@ -8182,12 +8182,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 67, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 67, + "column": 16 } } }, @@ -8262,12 +8262,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 68, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 68, + "column": 16 } } }, @@ -8342,12 +8342,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 69, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 69, + "column": 16 } } }, @@ -8538,12 +8538,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 70, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 70, + "column": 32 } } }, @@ -8676,12 +8676,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 73, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 73, + "column": 26 } } }, @@ -8814,12 +8814,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 74, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 74, + "column": 28 } } }, @@ -9155,12 +9155,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 75, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 75, + "column": 62 } } }, @@ -9496,12 +9496,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 76, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 76, + "column": 63 } } }, @@ -9663,12 +9663,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 77, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 77, + "column": 34 } } } diff --git a/ets2panda/test/parser/ets/binary_operations-expected.txt b/ets2panda/test/parser/ets/binary_operations-expected.txt index 2b38694179b7aba9963c400a90cb5aec4081599d..7503903f1d4b105f07a41b3ea71fca47c0b8e0cb 100644 --- a/ets2panda/test/parser/ets/binary_operations-expected.txt +++ b/ets2panda/test/parser/ets/binary_operations-expected.txt @@ -244,12 +244,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 19, + "column": 13 }, "end": { - "line": 1, - "column": 1 + "line": 19, + "column": 31 } } }, @@ -391,12 +391,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 20, + "column": 13 }, "end": { - "line": 1, - "column": 1 + "line": 20, + "column": 39 } } }, @@ -482,12 +482,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 21, + "column": 13 }, "end": { - "line": 1, - "column": 1 + "line": 21, + "column": 31 } } }, @@ -601,12 +601,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 22, + "column": 13 }, "end": { - "line": 1, - "column": 1 + "line": 22, + "column": 35 } } }, @@ -692,12 +692,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 23, + "column": 13 }, "end": { - "line": 1, - "column": 1 + "line": 23, + "column": 31 } } }, @@ -839,12 +839,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 24, + "column": 13 }, "end": { - "line": 1, - "column": 1 + "line": 24, + "column": 39 } } }, @@ -930,12 +930,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 25, + "column": 13 }, "end": { - "line": 1, - "column": 1 + "line": 25, + "column": 39 } } }, @@ -1077,12 +1077,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 26, + "column": 13 }, "end": { - "line": 1, - "column": 1 + "line": 26, + "column": 54 } } }, @@ -1168,12 +1168,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 27, + "column": 13 }, "end": { - "line": 1, - "column": 1 + "line": 27, + "column": 37 } } }, @@ -1343,12 +1343,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 28, + "column": 13 }, "end": { - "line": 1, - "column": 1 + "line": 28, + "column": 60 } } }, @@ -1434,12 +1434,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 29, + "column": 13 }, "end": { - "line": 1, - "column": 1 + "line": 29, + "column": 31 } } }, @@ -1525,12 +1525,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 30, + "column": 13 }, "end": { - "line": 1, - "column": 1 + "line": 30, + "column": 32 } } }, @@ -1616,12 +1616,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 31, + "column": 13 }, "end": { - "line": 1, - "column": 1 + "line": 31, + "column": 33 } } }, @@ -1707,12 +1707,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 32, + "column": 13 }, "end": { - "line": 1, - "column": 1 + "line": 32, + "column": 31 } } }, @@ -1798,12 +1798,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 33, + "column": 13 }, "end": { - "line": 1, - "column": 1 + "line": 33, + "column": 31 } } }, @@ -1889,12 +1889,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 34, + "column": 13 }, "end": { - "line": 1, - "column": 1 + "line": 34, + "column": 31 } } }, @@ -1980,12 +1980,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 35, + "column": 13 }, "end": { - "line": 1, - "column": 1 + "line": 35, + "column": 33 } } }, @@ -2071,12 +2071,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 36, + "column": 13 }, "end": { - "line": 1, - "column": 1 + "line": 36, + "column": 34 } } }, @@ -2162,12 +2162,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 37, + "column": 13 }, "end": { - "line": 1, - "column": 1 + "line": 37, + "column": 34 } } }, @@ -2253,12 +2253,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 38, + "column": 13 }, "end": { - "line": 1, - "column": 1 + "line": 38, + "column": 33 } } }, @@ -2344,12 +2344,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 39, + "column": 13 }, "end": { - "line": 1, - "column": 1 + "line": 39, + "column": 34 } } }, @@ -2435,12 +2435,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 40, + "column": 13 }, "end": { - "line": 1, - "column": 1 + "line": 40, + "column": 34 } } }, @@ -2582,12 +2582,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 41, + "column": 13 }, "end": { - "line": 1, - "column": 1 + "line": 41, + "column": 46 } } }, @@ -2729,12 +2729,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 42, + "column": 13 }, "end": { - "line": 1, - "column": 1 + "line": 42, + "column": 46 } } }, diff --git a/ets2panda/test/parser/ets/boolean-expected.txt b/ets2panda/test/parser/ets/boolean-expected.txt index ef4e2d8e363389611b650ec6382d36d83b554c8d..ddbbcc7ffe442204fe38b00816e034e1440fa5c6 100644 --- a/ets2panda/test/parser/ets/boolean-expected.txt +++ b/ets2panda/test/parser/ets/boolean-expected.txt @@ -106,23 +106,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 16, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 16, + "column": 22 } } }, "loc": { "start": { - "line": 1, + "line": 16, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 16, + "column": 23 } } } @@ -213,12 +213,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 16, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 16, + "column": 15 } } }, @@ -263,12 +263,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 17, + "column": 7 }, "end": { - "line": 1, - "column": 1 + "line": 17, + "column": 16 } } } diff --git a/ets2panda/test/parser/ets/break-expected.txt b/ets2panda/test/parser/ets/break-expected.txt index 6f3b8210bd49cfc6bbb0e59c8d254cee4ff8b322..c165861131c3dca33733e7b1a729bb99e726b1c6 100644 --- a/ets2panda/test/parser/ets/break-expected.txt +++ b/ets2panda/test/parser/ets/break-expected.txt @@ -149,23 +149,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 16, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 16, + "column": 25 } } }, "loc": { "start": { - "line": 1, + "line": 16, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 16, + "column": 26 } } } @@ -269,12 +269,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 16, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 16, + "column": 15 } } }, diff --git a/ets2panda/test/parser/ets/cast_expressions5-expected.txt b/ets2panda/test/parser/ets/cast_expressions5-expected.txt index d791b13df928e116652ece4c009b538d4462c392..d8a3a2b217d8f3854979e80bd5d1110a4dd80f79 100644 --- a/ets2panda/test/parser/ets/cast_expressions5-expected.txt +++ b/ets2panda/test/parser/ets/cast_expressions5-expected.txt @@ -62,12 +62,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 23, + "column": 10 }, "end": { - "line": 1, - "column": 1 + "line": 23, + "column": 17 } } }, @@ -705,23 +705,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 16, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 16, + "column": 25 } } }, "loc": { "start": { - "line": 1, + "line": 16, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 16, + "column": 26 } } } @@ -812,12 +812,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 16, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 16, + "column": 21 } } }, diff --git a/ets2panda/test/parser/ets/class_init-expected.txt b/ets2panda/test/parser/ets/class_init-expected.txt index 985153831a02029cbcd5675e03ff5c08eced33db..ddee21102b0dd0ba05782339fc70cefafd44bfcf 100644 --- a/ets2panda/test/parser/ets/class_init-expected.txt +++ b/ets2panda/test/parser/ets/class_init-expected.txt @@ -62,12 +62,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 17, + "column": 17 }, "end": { - "line": 1, - "column": 1 + "line": 17, + "column": 23 } } }, diff --git a/ets2panda/test/parser/ets/class_instance-expected.txt b/ets2panda/test/parser/ets/class_instance-expected.txt index a6bdefd2f1df70c3c4fb72e391964ef91e012ec5..a4e953fd73edf315b9fb8640d579eb82ca42af9e 100644 --- a/ets2panda/test/parser/ets/class_instance-expected.txt +++ b/ets2panda/test/parser/ets/class_instance-expected.txt @@ -106,23 +106,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 16, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 16, + "column": 10 } } }, "loc": { "start": { - "line": 1, + "line": 16, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 16, + "column": 11 } } }, @@ -162,23 +162,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 17, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 17, + "column": 11 } } }, "loc": { "start": { - "line": 1, + "line": 17, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 17, + "column": 12 } } }, @@ -244,23 +244,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 19, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 19, + "column": 20 } } }, "loc": { "start": { - "line": 1, + "line": 19, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 19, + "column": 21 } } }, @@ -344,23 +344,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 20, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 20, + "column": 22 } } }, "loc": { "start": { - "line": 1, + "line": 20, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 20, + "column": 23 } } }, @@ -488,23 +488,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 21, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 21, + "column": 29 } } }, "loc": { "start": { - "line": 1, + "line": 21, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 21, + "column": 30 } } } @@ -596,12 +596,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 16, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 16, + "column": 10 } } }, @@ -646,12 +646,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 17, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 17, + "column": 11 } } }, @@ -722,12 +722,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 19, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 19, + "column": 20 } } }, @@ -816,12 +816,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 20, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 20, + "column": 22 } } }, @@ -954,12 +954,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 21, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 21, + "column": 29 } } } diff --git a/ets2panda/test/parser/ets/class_instance_creation-expected.txt b/ets2panda/test/parser/ets/class_instance_creation-expected.txt index b9cfb97c79990632e342474c80a00858871b54f4..5b17fb7414cddee4d27b172030303bf9817c700e 100644 --- a/ets2panda/test/parser/ets/class_instance_creation-expected.txt +++ b/ets2panda/test/parser/ets/class_instance_creation-expected.txt @@ -721,12 +721,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 28, + "column": 12 }, "end": { - "line": 1, - "column": 1 + "line": 28, + "column": 76 } } }, @@ -868,12 +868,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 29, + "column": 12 }, "end": { - "line": 1, - "column": 1 + "line": 29, + "column": 77 } } }, @@ -1029,12 +1029,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 30, + "column": 12 }, "end": { - "line": 1, - "column": 1 + "line": 30, + "column": 85 } } } diff --git a/ets2panda/test/parser/ets/class_instance_initializer-expected.txt b/ets2panda/test/parser/ets/class_instance_initializer-expected.txt index 4e1f9163543a795969ead5a52efeb9060873cd6c..f43d49e1c488306b3e7675a201dbe2f34e1cc96f 100644 --- a/ets2panda/test/parser/ets/class_instance_initializer-expected.txt +++ b/ets2panda/test/parser/ets/class_instance_initializer-expected.txt @@ -216,12 +216,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 19, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 19, + "column": 15 } } }, @@ -279,12 +279,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 20, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 20, + "column": 15 } } }, @@ -1705,12 +1705,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 44, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 44, + "column": 16 } } }, @@ -1768,12 +1768,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 45, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 45, + "column": 16 } } }, diff --git a/ets2panda/test/parser/ets/class_static_initializer-expected.txt b/ets2panda/test/parser/ets/class_static_initializer-expected.txt index 48f5bda364a58ff9fdaafe7739c644d25c130ca7..7a091612afe48d9247b68b4af9175904e01ddfce 100644 --- a/ets2panda/test/parser/ets/class_static_initializer-expected.txt +++ b/ets2panda/test/parser/ets/class_static_initializer-expected.txt @@ -216,12 +216,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 19, + "column": 12 }, "end": { - "line": 1, - "column": 1 + "line": 19, + "column": 23 } } }, @@ -696,12 +696,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 27, + "column": 12 }, "end": { - "line": 1, - "column": 1 + "line": 27, + "column": 23 } } }, diff --git a/ets2panda/test/parser/ets/const-expected.txt b/ets2panda/test/parser/ets/const-expected.txt index 15ceee614718d599536797de13e0a3f30f06aa1d..1747669044fc29618c620316a97b5d2989dc97a4 100644 --- a/ets2panda/test/parser/ets/const-expected.txt +++ b/ets2panda/test/parser/ets/const-expected.txt @@ -157,12 +157,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 16, + "column": 7 }, "end": { - "line": 1, - "column": 1 + "line": 16, + "column": 12 } } }, @@ -248,12 +248,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 17, + "column": 7 }, "end": { - "line": 1, - "column": 1 + "line": 17, + "column": 26 } } } diff --git a/ets2panda/test/parser/ets/constructor_with_return_1-expected.txt b/ets2panda/test/parser/ets/constructor_with_return_1-expected.txt index a8d99f387378ac1cf09f2f8e96d22c633561c261..09cc3fe47d3a9ba508b87908e9378bfb79c9cd15 100644 --- a/ets2panda/test/parser/ets/constructor_with_return_1-expected.txt +++ b/ets2panda/test/parser/ets/constructor_with_return_1-expected.txt @@ -62,12 +62,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 17, + "column": 10 }, "end": { - "line": 1, - "column": 1 + "line": 17, + "column": 16 } } }, diff --git a/ets2panda/test/parser/ets/constructor_with_return_2-expected.txt b/ets2panda/test/parser/ets/constructor_with_return_2-expected.txt index c12b546800e52d6f095b88dc9fc76f24fbad6a9b..39d854bcec258aa9336e357b7cb580f4613d8e39 100644 --- a/ets2panda/test/parser/ets/constructor_with_return_2-expected.txt +++ b/ets2panda/test/parser/ets/constructor_with_return_2-expected.txt @@ -62,12 +62,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 17, + "column": 10 }, "end": { - "line": 1, - "column": 1 + "line": 17, + "column": 16 } } }, diff --git a/ets2panda/test/parser/ets/constructors-expected.txt b/ets2panda/test/parser/ets/constructors-expected.txt index 762124e0a30691c56f463095e4166e5b8face1b8..3bbc3e2cd13139bb48d0059a568b70dd98077b33 100644 --- a/ets2panda/test/parser/ets/constructors-expected.txt +++ b/ets2panda/test/parser/ets/constructors-expected.txt @@ -62,12 +62,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 17, + "column": 13 }, "end": { - "line": 1, - "column": 1 + "line": 17, + "column": 19 } } }, @@ -111,12 +111,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 18, + "column": 13 }, "end": { - "line": 1, - "column": 1 + "line": 18, + "column": 21 } } }, @@ -799,12 +799,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 28, + "column": 13 }, "end": { - "line": 1, - "column": 1 + "line": 28, + "column": 19 } } }, diff --git a/ets2panda/test/parser/ets/continue-expected.txt b/ets2panda/test/parser/ets/continue-expected.txt index 278cbe5e954a88df3aa0ef780ff90a3ea92c636b..cd8cfe6fabf65c4e7e0b788ab216c52b559ed281 100644 --- a/ets2panda/test/parser/ets/continue-expected.txt +++ b/ets2panda/test/parser/ets/continue-expected.txt @@ -149,23 +149,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 16, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 16, + "column": 25 } } }, "loc": { "start": { - "line": 1, + "line": 16, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 16, + "column": 26 } } } @@ -269,12 +269,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 16, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 16, + "column": 15 } } }, diff --git a/ets2panda/test/parser/ets/decl_infer-expected.txt b/ets2panda/test/parser/ets/decl_infer-expected.txt index 6cf890abe7d7568f8768b3639687257d3c3a0188..0455f4f8b2e9110156d6a2d656885ede6c5def4d 100644 --- a/ets2panda/test/parser/ets/decl_infer-expected.txt +++ b/ets2panda/test/parser/ets/decl_infer-expected.txt @@ -106,23 +106,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 16, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 16, + "column": 11 } } }, "loc": { "start": { - "line": 1, + "line": 16, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 16, + "column": 12 } } }, @@ -162,23 +162,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 17, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 17, + "column": 13 } } }, "loc": { "start": { - "line": 1, + "line": 17, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 17, + "column": 14 } } }, @@ -218,23 +218,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 18, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 18, + "column": 14 } } }, "loc": { "start": { - "line": 1, + "line": 18, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 18, + "column": 15 } } }, @@ -274,23 +274,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 19, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 19, + "column": 14 } } }, "loc": { "start": { - "line": 1, + "line": 19, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 19, + "column": 15 } } }, @@ -330,23 +330,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 20, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 20, + "column": 15 } } }, "loc": { "start": { - "line": 1, + "line": 20, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 20, + "column": 16 } } } @@ -438,12 +438,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 16, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 16, + "column": 11 } } }, @@ -488,12 +488,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 17, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 17, + "column": 13 } } }, @@ -538,12 +538,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 18, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 18, + "column": 14 } } }, @@ -588,12 +588,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 19, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 19, + "column": 14 } } }, @@ -638,12 +638,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 20, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 20, + "column": 15 } } }, @@ -688,12 +688,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 22, + "column": 7 }, "end": { - "line": 1, - "column": 1 + "line": 22, + "column": 13 } } }, @@ -738,12 +738,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 23, + "column": 7 }, "end": { - "line": 1, - "column": 1 + "line": 23, + "column": 15 } } }, @@ -788,12 +788,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 24, + "column": 7 }, "end": { - "line": 1, - "column": 1 + "line": 24, + "column": 16 } } }, @@ -838,12 +838,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 25, + "column": 7 }, "end": { - "line": 1, - "column": 1 + "line": 25, + "column": 16 } } }, @@ -888,12 +888,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 26, + "column": 7 }, "end": { - "line": 1, - "column": 1 + "line": 26, + "column": 17 } } } diff --git a/ets2panda/test/parser/ets/declare_class-expected.txt b/ets2panda/test/parser/ets/declare_class-expected.txt index 373bf55cae62e02efecbe743687a1c915e608d92..4e26b0f34509b4b43ddfcbd42916bb3d78572795 100644 --- a/ets2panda/test/parser/ets/declare_class-expected.txt +++ b/ets2panda/test/parser/ets/declare_class-expected.txt @@ -90,12 +90,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 17, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 18, + "column": 11 } } }, @@ -139,12 +139,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 18, + "column": 12 }, "end": { - "line": 1, - "column": 1 + "line": 18, + "column": 22 } } }, diff --git a/ets2panda/test/parser/ets/declare_class_bad_2-expected.txt b/ets2panda/test/parser/ets/declare_class_bad_2-expected.txt index cdaf88a64574c4fd3fc9400d6848c420f763cb3a..8fc27406b67b17ec075baded8262001d885f9cda 100644 --- a/ets2panda/test/parser/ets/declare_class_bad_2-expected.txt +++ b/ets2panda/test/parser/ets/declare_class_bad_2-expected.txt @@ -90,12 +90,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 17, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 18, + "column": 8 } } }, diff --git a/ets2panda/test/parser/ets/declare_class_bad_4-expected.txt b/ets2panda/test/parser/ets/declare_class_bad_4-expected.txt index 752e4a97cdf2482ba45ea5ca5df3b5f02ed4c940..beb867b7c5edc03ddd55dd39c38464986da7c261 100644 --- a/ets2panda/test/parser/ets/declare_class_bad_4-expected.txt +++ b/ets2panda/test/parser/ets/declare_class_bad_4-expected.txt @@ -90,12 +90,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 17, + "column": 12 }, "end": { - "line": 1, - "column": 1 + "line": 18, + "column": 11 } } }, diff --git a/ets2panda/test/parser/ets/default_parameter1-expected.txt b/ets2panda/test/parser/ets/default_parameter1-expected.txt index 70a65a1979f1629eab79e45eba2f4ef217d0b2e3..41c4146c87dd859f8051680729b5de2477869813 100644 --- a/ets2panda/test/parser/ets/default_parameter1-expected.txt +++ b/ets2panda/test/parser/ets/default_parameter1-expected.txt @@ -691,7 +691,7 @@ "type": "ETSParameterExpression", "name": { "type": "Identifier", - "name": "proxy_int", + "name": "$proxy_mask$", "typeAnnotation": { "type": "ETSPrimitiveType", "loc": { @@ -758,7 +758,7 @@ "operator": ">>", "left": { "type": "Identifier", - "name": "proxy_int", + "name": "$proxy_mask$", "decorators": [], "loc": { "start": { @@ -1276,4 +1276,4 @@ } } } -TypeError: Reference to foo is ambiguous [default_parameter1.ets:18:5] +TypeError: Function already declared. [default_parameter1.ets:26:1] diff --git a/ets2panda/test/parser/ets/default_parameter2-expected.txt b/ets2panda/test/parser/ets/default_parameter2-expected.txt index 0267fc1b3f8eade491362cbca4a141f84537a4b9..1bc729dc18971726d43817eb01a32178dba82144 100644 --- a/ets2panda/test/parser/ets/default_parameter2-expected.txt +++ b/ets2panda/test/parser/ets/default_parameter2-expected.txt @@ -676,7 +676,7 @@ "type": "ETSParameterExpression", "name": { "type": "Identifier", - "name": "proxy_int", + "name": "$proxy_mask$", "typeAnnotation": { "type": "ETSPrimitiveType", "loc": { @@ -743,7 +743,7 @@ "operator": ">>", "left": { "type": "Identifier", - "name": "proxy_int", + "name": "$proxy_mask$", "decorators": [], "loc": { "start": { @@ -1261,4 +1261,4 @@ } } } -TypeError: No matching call signature [default_parameter2.ets:18:5] +TypeError: Function already declared. [default_parameter2.ets:26:1] diff --git a/ets2panda/test/parser/ets/default_parameter4-expected.txt b/ets2panda/test/parser/ets/default_parameter4-expected.txt index 35457f1bc8469a303faab6c21f02c386b621ccc7..9ddd3595837e5d7ce3500487c46e198fe039fd33 100644 --- a/ets2panda/test/parser/ets/default_parameter4-expected.txt +++ b/ets2panda/test/parser/ets/default_parameter4-expected.txt @@ -816,7 +816,7 @@ "type": "ETSParameterExpression", "name": { "type": "Identifier", - "name": "proxy_int", + "name": "$proxy_mask$", "typeAnnotation": { "type": "ETSPrimitiveType", "loc": { @@ -883,7 +883,7 @@ "operator": ">>", "left": { "type": "Identifier", - "name": "proxy_int", + "name": "$proxy_mask$", "decorators": [], "loc": { "start": { @@ -1067,7 +1067,7 @@ "operator": ">>", "left": { "type": "Identifier", - "name": "proxy_int", + "name": "$proxy_mask$", "decorators": [], "loc": { "start": { @@ -1656,7 +1656,7 @@ "type": "ETSParameterExpression", "name": { "type": "Identifier", - "name": "proxy_int", + "name": "$proxy_mask$", "typeAnnotation": { "type": "ETSPrimitiveType", "loc": { @@ -1723,7 +1723,7 @@ "operator": ">>", "left": { "type": "Identifier", - "name": "proxy_int", + "name": "$proxy_mask$", "decorators": [], "loc": { "start": { @@ -2048,4 +2048,4 @@ } } } -TypeError: Reference to foo is ambiguous [default_parameter4.ets:18:5] +TypeError: Function already declared. [default_parameter4.ets:26:1] diff --git a/ets2panda/test/parser/ets/default_parameter5-expected.txt b/ets2panda/test/parser/ets/default_parameter5-expected.txt index c7eec1185058bceee24bce0c0d2d7f0ddb7b34d4..ab0a5a6760f5398fd88173f216c0a6321beaadcd 100644 --- a/ets2panda/test/parser/ets/default_parameter5-expected.txt +++ b/ets2panda/test/parser/ets/default_parameter5-expected.txt @@ -861,7 +861,7 @@ "type": "ETSParameterExpression", "name": { "type": "Identifier", - "name": "proxy_int", + "name": "$proxy_mask$", "typeAnnotation": { "type": "ETSPrimitiveType", "loc": { @@ -928,7 +928,7 @@ "operator": ">>", "left": { "type": "Identifier", - "name": "proxy_int", + "name": "$proxy_mask$", "decorators": [], "loc": { "start": { diff --git a/ets2panda/test/parser/ets/default_parameter6-expected.txt b/ets2panda/test/parser/ets/default_parameter6-expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..ad8c1be4b178b428ef903861db2327627164809c --- /dev/null +++ b/ets2panda/test/parser/ets/default_parameter6-expected.txt @@ -0,0 +1,2637 @@ +{ + "type": "Program", + "statements": [ + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "ETSGLOBAL", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "superClass": null, + "implements": [], + "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "_$init$_", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "_$init$_", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "foo", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 10 + }, + "end": { + "line": 16, + "column": 13 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "foo", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 10 + }, + "end": { + "line": 16, + "column": 13 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [ + { + "type": "ETSParameterExpression", + "name": { + "type": "Identifier", + "name": "a", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Int", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 18 + }, + "end": { + "line": 16, + "column": 21 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 18 + }, + "end": { + "line": 16, + "column": 22 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 18 + }, + "end": { + "line": 16, + "column": 22 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 14 + }, + "end": { + "line": 16, + "column": 22 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 14 + }, + "end": { + "line": 16, + "column": 22 + } + } + }, + { + "type": "ETSParameterExpression", + "name": { + "type": "Identifier", + "name": "b", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Int", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 27 + }, + "end": { + "line": 16, + "column": 30 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 27 + }, + "end": { + "line": 16, + "column": 32 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 27 + }, + "end": { + "line": 16, + "column": 32 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 23 + }, + "end": { + "line": 16, + "column": 32 + } + } + }, + "initializer": { + "type": "NumberLiteral", + "value": 20, + "loc": { + "start": { + "line": 16, + "column": 33 + }, + "end": { + "line": 16, + "column": 35 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 23 + }, + "end": { + "line": 16, + "column": 35 + } + } + }, + { + "type": "ETSParameterExpression", + "name": { + "type": "Identifier", + "name": "c", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Int", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 41 + }, + "end": { + "line": 16, + "column": 44 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 41 + }, + "end": { + "line": 16, + "column": 46 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 41 + }, + "end": { + "line": 16, + "column": 46 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 37 + }, + "end": { + "line": 16, + "column": 46 + } + } + }, + "initializer": { + "type": "NumberLiteral", + "value": 30, + "loc": { + "start": { + "line": 16, + "column": 47 + }, + "end": { + "line": 16, + "column": 49 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 37 + }, + "end": { + "line": 16, + "column": 49 + } + } + } + ], + "returnType": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Int", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 53 + }, + "end": { + "line": 16, + "column": 56 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 53 + }, + "end": { + "line": 17, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 53 + }, + "end": { + "line": 17, + "column": 2 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "ReturnStatement", + "argument": { + "type": "NumberLiteral", + "value": 1, + "loc": { + "start": { + "line": 18, + "column": 12 + }, + "end": { + "line": 18, + "column": 13 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 5 + }, + "end": { + "line": 18, + "column": 14 + } + } + } + ], + "loc": { + "start": { + "line": 17, + "column": 1 + }, + "end": { + "line": 19, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 13 + }, + "end": { + "line": 19, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 13 + }, + "end": { + "line": 19, + "column": 2 + } + } + }, + "overloads": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "foo_proxy", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "foo_proxy", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [ + { + "type": "ETSParameterExpression", + "name": { + "type": "Identifier", + "name": "a", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Int", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + { + "type": "ETSParameterExpression", + "name": { + "type": "Identifier", + "name": "b", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Int", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + { + "type": "ETSParameterExpression", + "name": { + "type": "Identifier", + "name": "c", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Int", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + { + "type": "ETSParameterExpression", + "name": { + "type": "Identifier", + "name": "$proxy_mask$", + "typeAnnotation": { + "type": "ETSPrimitiveType", + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + } + ], + "returnType": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Int", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "IfStatement", + "test": { + "type": "BinaryExpression", + "operator": "==", + "left": { + "type": "BinaryExpression", + "operator": "&", + "left": { + "type": "BinaryExpression", + "operator": ">>", + "left": { + "type": "Identifier", + "name": "$proxy_mask$", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + "right": { + "type": "NumberLiteral", + "value": 1, + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + "right": { + "type": "NumberLiteral", + "value": 1, + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + "right": { + "type": "NumberLiteral", + "value": 1, + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + "consequent": { + "type": "BlockStatement", + "statements": [ + { + "type": "ExpressionStatement", + "expression": { + "type": "AssignmentExpression", + "operator": "=", + "left": { + "type": "Identifier", + "name": "b", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + "right": { + "type": "NumberLiteral", + "value": 20, + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + "alternate": null, + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + { + "type": "IfStatement", + "test": { + "type": "BinaryExpression", + "operator": "==", + "left": { + "type": "BinaryExpression", + "operator": "&", + "left": { + "type": "BinaryExpression", + "operator": ">>", + "left": { + "type": "Identifier", + "name": "$proxy_mask$", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + "right": { + "type": "NumberLiteral", + "value": 2, + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + "right": { + "type": "NumberLiteral", + "value": 1, + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + "right": { + "type": "NumberLiteral", + "value": 1, + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + "consequent": { + "type": "BlockStatement", + "statements": [ + { + "type": "ExpressionStatement", + "expression": { + "type": "AssignmentExpression", + "operator": "=", + "left": { + "type": "Identifier", + "name": "c", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + "right": { + "type": "NumberLiteral", + "value": 30, + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + "alternate": null, + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + { + "type": "ReturnStatement", + "argument": { + "type": "CallExpression", + "callee": { + "type": "Identifier", + "name": "foo", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + "arguments": [ + { + "type": "Identifier", + "name": "a", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + { + "type": "Identifier", + "name": "b", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + { + "type": "Identifier", + "name": "c", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + } + ], + "optional": false, + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "foo", + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 10 + }, + "end": { + "line": 21, + "column": 13 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "foo", + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 10 + }, + "end": { + "line": 21, + "column": 13 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [ + { + "type": "ETSParameterExpression", + "name": { + "type": "Identifier", + "name": "a", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Int", + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 18 + }, + "end": { + "line": 21, + "column": 21 + } + } + }, + "loc": { + "start": { + "line": 21, + "column": 18 + }, + "end": { + "line": 21, + "column": 22 + } + } + }, + "loc": { + "start": { + "line": 21, + "column": 18 + }, + "end": { + "line": 21, + "column": 22 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 14 + }, + "end": { + "line": 21, + "column": 22 + } + } + }, + "loc": { + "start": { + "line": 21, + "column": 14 + }, + "end": { + "line": 21, + "column": 22 + } + } + }, + { + "type": "ETSParameterExpression", + "name": { + "type": "Identifier", + "name": "b", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "string", + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 27 + }, + "end": { + "line": 21, + "column": 33 + } + } + }, + "loc": { + "start": { + "line": 21, + "column": 27 + }, + "end": { + "line": 21, + "column": 35 + } + } + }, + "loc": { + "start": { + "line": 21, + "column": 27 + }, + "end": { + "line": 21, + "column": 35 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 23 + }, + "end": { + "line": 21, + "column": 35 + } + } + }, + "initializer": { + "type": "StringLiteral", + "value": "a", + "loc": { + "start": { + "line": 21, + "column": 36 + }, + "end": { + "line": 21, + "column": 39 + } + } + }, + "loc": { + "start": { + "line": 21, + "column": 23 + }, + "end": { + "line": 21, + "column": 39 + } + } + }, + { + "type": "ETSParameterExpression", + "name": { + "type": "Identifier", + "name": "c", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Int", + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 45 + }, + "end": { + "line": 21, + "column": 48 + } + } + }, + "loc": { + "start": { + "line": 21, + "column": 45 + }, + "end": { + "line": 21, + "column": 50 + } + } + }, + "loc": { + "start": { + "line": 21, + "column": 45 + }, + "end": { + "line": 21, + "column": 50 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 41 + }, + "end": { + "line": 21, + "column": 50 + } + } + }, + "initializer": { + "type": "NumberLiteral", + "value": 30, + "loc": { + "start": { + "line": 21, + "column": 51 + }, + "end": { + "line": 21, + "column": 53 + } + } + }, + "loc": { + "start": { + "line": 21, + "column": 41 + }, + "end": { + "line": 21, + "column": 53 + } + } + } + ], + "returnType": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Int", + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 57 + }, + "end": { + "line": 21, + "column": 60 + } + } + }, + "loc": { + "start": { + "line": 21, + "column": 57 + }, + "end": { + "line": 22, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 21, + "column": 57 + }, + "end": { + "line": 22, + "column": 2 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "ReturnStatement", + "argument": { + "type": "NumberLiteral", + "value": 2, + "loc": { + "start": { + "line": 23, + "column": 12 + }, + "end": { + "line": 23, + "column": 13 + } + } + }, + "loc": { + "start": { + "line": 23, + "column": 5 + }, + "end": { + "line": 23, + "column": 14 + } + } + } + ], + "loc": { + "start": { + "line": 22, + "column": 1 + }, + "end": { + "line": 24, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 21, + "column": 13 + }, + "end": { + "line": 24, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 21, + "column": 13 + }, + "end": { + "line": 24, + "column": 2 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 1 + }, + "end": { + "line": 24, + "column": 2 + } + } + }, + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "foo_proxy", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "foo_proxy", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [ + { + "type": "ETSParameterExpression", + "name": { + "type": "Identifier", + "name": "a", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Int", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + { + "type": "ETSParameterExpression", + "name": { + "type": "Identifier", + "name": "b", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "string", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + { + "type": "ETSParameterExpression", + "name": { + "type": "Identifier", + "name": "c", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Int", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + { + "type": "ETSParameterExpression", + "name": { + "type": "Identifier", + "name": "$proxy_mask$", + "typeAnnotation": { + "type": "ETSPrimitiveType", + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + } + ], + "returnType": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Int", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "IfStatement", + "test": { + "type": "BinaryExpression", + "operator": "==", + "left": { + "type": "BinaryExpression", + "operator": "&", + "left": { + "type": "BinaryExpression", + "operator": ">>", + "left": { + "type": "Identifier", + "name": "$proxy_mask$", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + "right": { + "type": "NumberLiteral", + "value": 1, + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + "right": { + "type": "NumberLiteral", + "value": 1, + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + "right": { + "type": "NumberLiteral", + "value": 1, + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + "consequent": { + "type": "BlockStatement", + "statements": [ + { + "type": "ExpressionStatement", + "expression": { + "type": "AssignmentExpression", + "operator": "=", + "left": { + "type": "Identifier", + "name": "b", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + "right": { + "type": "StringLiteral", + "value": "a", + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + "alternate": null, + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + { + "type": "IfStatement", + "test": { + "type": "BinaryExpression", + "operator": "==", + "left": { + "type": "BinaryExpression", + "operator": "&", + "left": { + "type": "BinaryExpression", + "operator": ">>", + "left": { + "type": "Identifier", + "name": "$proxy_mask$", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + "right": { + "type": "NumberLiteral", + "value": 2, + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + "right": { + "type": "NumberLiteral", + "value": 1, + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + "right": { + "type": "NumberLiteral", + "value": 1, + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + "consequent": { + "type": "BlockStatement", + "statements": [ + { + "type": "ExpressionStatement", + "expression": { + "type": "AssignmentExpression", + "operator": "=", + "left": { + "type": "Identifier", + "name": "c", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + "right": { + "type": "NumberLiteral", + "value": 30, + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + "alternate": null, + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + { + "type": "ReturnStatement", + "argument": { + "type": "CallExpression", + "callee": { + "type": "Identifier", + "name": "foo", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + "arguments": [ + { + "type": "Identifier", + "name": "a", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + { + "type": "Identifier", + "name": "b", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + { + "type": "Identifier", + "name": "c", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + } + ], + "optional": false, + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 3 + } + } + } + ], + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 1 + }, + "end": { + "line": 19, + "column": 2 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 25, + "column": 1 + } + } +} +TypeError: Function already declared. [default_parameter6.ets:21:1] diff --git a/ets2panda/test/parser/ets/default_parameter6.ets b/ets2panda/test/parser/ets/default_parameter6.ets new file mode 100644 index 0000000000000000000000000000000000000000..2cb74c5e6531a4080dba3db027298bf7a6ac4e08 --- /dev/null +++ b/ets2panda/test/parser/ets/default_parameter6.ets @@ -0,0 +1,24 @@ +/* + * 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. + */ + +function foo(a : Int, b : Int = 20, c : Int = 30) : Int +{ + return 1; +} + +function foo(a : Int, b : string = "a", c : Int = 30) : Int +{ + return 2; +} diff --git a/ets2panda/test/parser/ets/default_parameter7-expected.txt b/ets2panda/test/parser/ets/default_parameter7-expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..c6d4b58f37b4e7b7ec71d7ec93e3d29cc8df1f35 --- /dev/null +++ b/ets2panda/test/parser/ets/default_parameter7-expected.txt @@ -0,0 +1,1655 @@ +{ + "type": "Program", + "statements": [ + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "ETSGLOBAL", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "superClass": null, + "implements": [], + "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "_$init$_", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "_$init$_", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "foo", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 10 + }, + "end": { + "line": 16, + "column": 13 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "foo", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 10 + }, + "end": { + "line": 16, + "column": 13 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [ + { + "type": "ETSParameterExpression", + "rest parameter": { + "type": "RestElement", + "argument": { + "type": "Identifier", + "name": "a", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 17 + }, + "end": { + "line": 16, + "column": 18 + } + } + }, + "typeAnnotation": { + "type": "TSArrayType", + "elementType": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Int", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 21 + }, + "end": { + "line": 16, + "column": 24 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 21 + }, + "end": { + "line": 16, + "column": 25 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 21 + }, + "end": { + "line": 16, + "column": 25 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 26 + }, + "end": { + "line": 16, + "column": 27 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 14 + }, + "end": { + "line": 16, + "column": 27 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 14 + }, + "end": { + "line": 16, + "column": 27 + } + } + } + ], + "returnType": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Int", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 30 + }, + "end": { + "line": 16, + "column": 33 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 30 + }, + "end": { + "line": 17, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 30 + }, + "end": { + "line": 17, + "column": 2 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "ReturnStatement", + "argument": { + "type": "NumberLiteral", + "value": 1, + "loc": { + "start": { + "line": 18, + "column": 12 + }, + "end": { + "line": 18, + "column": 13 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 5 + }, + "end": { + "line": 18, + "column": 14 + } + } + } + ], + "loc": { + "start": { + "line": 17, + "column": 1 + }, + "end": { + "line": 19, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 13 + }, + "end": { + "line": 19, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 13 + }, + "end": { + "line": 19, + "column": 2 + } + } + }, + "overloads": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "foo", + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 10 + }, + "end": { + "line": 21, + "column": 13 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "foo", + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 10 + }, + "end": { + "line": 21, + "column": 13 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [ + { + "type": "ETSParameterExpression", + "name": { + "type": "Identifier", + "name": "a", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Int", + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 18 + }, + "end": { + "line": 21, + "column": 21 + } + } + }, + "loc": { + "start": { + "line": 21, + "column": 18 + }, + "end": { + "line": 21, + "column": 22 + } + } + }, + "loc": { + "start": { + "line": 21, + "column": 18 + }, + "end": { + "line": 21, + "column": 22 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 14 + }, + "end": { + "line": 21, + "column": 22 + } + } + }, + "loc": { + "start": { + "line": 21, + "column": 14 + }, + "end": { + "line": 21, + "column": 22 + } + } + }, + { + "type": "ETSParameterExpression", + "name": { + "type": "Identifier", + "name": "b", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "String", + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 28 + }, + "end": { + "line": 21, + "column": 34 + } + } + }, + "loc": { + "start": { + "line": 21, + "column": 28 + }, + "end": { + "line": 21, + "column": 35 + } + } + }, + "loc": { + "start": { + "line": 21, + "column": 28 + }, + "end": { + "line": 21, + "column": 35 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 23 + }, + "end": { + "line": 21, + "column": 35 + } + } + }, + "initializer": { + "type": "UndefinedLiteral", + "value": undefined, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 21, + "column": 23 + }, + "end": { + "line": 21, + "column": 35 + } + } + }, + { + "type": "ETSParameterExpression", + "name": { + "type": "Identifier", + "name": "c", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Int", + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 40 + }, + "end": { + "line": 21, + "column": 43 + } + } + }, + "loc": { + "start": { + "line": 21, + "column": 40 + }, + "end": { + "line": 21, + "column": 45 + } + } + }, + "loc": { + "start": { + "line": 21, + "column": 40 + }, + "end": { + "line": 21, + "column": 45 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 36 + }, + "end": { + "line": 21, + "column": 45 + } + } + }, + "initializer": { + "type": "NumberLiteral", + "value": 30, + "loc": { + "start": { + "line": 21, + "column": 46 + }, + "end": { + "line": 21, + "column": 48 + } + } + }, + "loc": { + "start": { + "line": 21, + "column": 36 + }, + "end": { + "line": 21, + "column": 48 + } + } + } + ], + "returnType": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Int", + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 52 + }, + "end": { + "line": 21, + "column": 55 + } + } + }, + "loc": { + "start": { + "line": 21, + "column": 52 + }, + "end": { + "line": 22, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 21, + "column": 52 + }, + "end": { + "line": 22, + "column": 2 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "ReturnStatement", + "argument": { + "type": "NumberLiteral", + "value": 2, + "loc": { + "start": { + "line": 23, + "column": 12 + }, + "end": { + "line": 23, + "column": 13 + } + } + }, + "loc": { + "start": { + "line": 23, + "column": 5 + }, + "end": { + "line": 23, + "column": 14 + } + } + } + ], + "loc": { + "start": { + "line": 22, + "column": 1 + }, + "end": { + "line": 24, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 21, + "column": 13 + }, + "end": { + "line": 24, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 21, + "column": 13 + }, + "end": { + "line": 24, + "column": 2 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 1 + }, + "end": { + "line": 24, + "column": 2 + } + } + }, + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "foo_proxy", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "foo_proxy", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [ + { + "type": "ETSParameterExpression", + "name": { + "type": "Identifier", + "name": "a", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Int", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + { + "type": "ETSParameterExpression", + "name": { + "type": "Identifier", + "name": "b", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "String", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + { + "type": "ETSParameterExpression", + "name": { + "type": "Identifier", + "name": "c", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Int", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + { + "type": "ETSParameterExpression", + "name": { + "type": "Identifier", + "name": "$proxy_mask$", + "typeAnnotation": { + "type": "ETSPrimitiveType", + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + } + ], + "returnType": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Int", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "IfStatement", + "test": { + "type": "BinaryExpression", + "operator": "==", + "left": { + "type": "BinaryExpression", + "operator": "&", + "left": { + "type": "BinaryExpression", + "operator": ">>", + "left": { + "type": "Identifier", + "name": "$proxy_mask$", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + "right": { + "type": "NumberLiteral", + "value": 1, + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + "right": { + "type": "NumberLiteral", + "value": 1, + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + "right": { + "type": "NumberLiteral", + "value": 1, + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + "consequent": { + "type": "BlockStatement", + "statements": [ + { + "type": "ExpressionStatement", + "expression": { + "type": "AssignmentExpression", + "operator": "=", + "left": { + "type": "Identifier", + "name": "b", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + "right": { + "type": "UndefinedLiteral", + "value": undefined, + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + "alternate": null, + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + { + "type": "IfStatement", + "test": { + "type": "BinaryExpression", + "operator": "==", + "left": { + "type": "BinaryExpression", + "operator": "&", + "left": { + "type": "BinaryExpression", + "operator": ">>", + "left": { + "type": "Identifier", + "name": "$proxy_mask$", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + "right": { + "type": "NumberLiteral", + "value": 2, + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + "right": { + "type": "NumberLiteral", + "value": 1, + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + "right": { + "type": "NumberLiteral", + "value": 1, + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + "consequent": { + "type": "BlockStatement", + "statements": [ + { + "type": "ExpressionStatement", + "expression": { + "type": "AssignmentExpression", + "operator": "=", + "left": { + "type": "Identifier", + "name": "c", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + "right": { + "type": "NumberLiteral", + "value": 30, + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + "alternate": null, + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + { + "type": "ReturnStatement", + "argument": { + "type": "CallExpression", + "callee": { + "type": "Identifier", + "name": "foo", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + "arguments": [ + { + "type": "Identifier", + "name": "a", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + { + "type": "Identifier", + "name": "b", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + { + "type": "Identifier", + "name": "c", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + } + ], + "optional": false, + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 3 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 3 + } + } + } + ], + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 1 + }, + "end": { + "line": 19, + "column": 2 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 25, + "column": 1 + } + } +} +TypeError: Function already declared. [default_parameter7.ets:21:1] diff --git a/ets2panda/test/parser/ets/default_parameter7.ets b/ets2panda/test/parser/ets/default_parameter7.ets new file mode 100644 index 0000000000000000000000000000000000000000..490da83dbf0fbe969e33b5092425438102b5ed65 --- /dev/null +++ b/ets2panda/test/parser/ets/default_parameter7.ets @@ -0,0 +1,24 @@ +/* + * 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. + */ + +function foo(...a : Int[]) : Int +{ + return 1; +} + +function foo(a : Int, b? : String, c : Int = 30) : Int +{ + return 2; +} diff --git a/ets2panda/test/parser/ets/default_parameter_implicitly_typed_return_void-expected.txt b/ets2panda/test/parser/ets/default_parameter_implicitly_typed_return_void-expected.txt index fcf3644024f2146e28017c9b5ad9926bf3a01826..1e351257677d50d8e4af096df8a815f5869a7b4d 100644 --- a/ets2panda/test/parser/ets/default_parameter_implicitly_typed_return_void-expected.txt +++ b/ets2panda/test/parser/ets/default_parameter_implicitly_typed_return_void-expected.txt @@ -690,7 +690,7 @@ "type": "ETSParameterExpression", "name": { "type": "Identifier", - "name": "proxy_int", + "name": "$proxy_mask$", "typeAnnotation": { "type": "ETSPrimitiveType", "loc": { @@ -744,7 +744,7 @@ "operator": ">>", "left": { "type": "Identifier", - "name": "proxy_int", + "name": "$proxy_mask$", "decorators": [], "loc": { "start": { @@ -928,7 +928,7 @@ "operator": ">>", "left": { "type": "Identifier", - "name": "proxy_int", + "name": "$proxy_mask$", "decorators": [], "loc": { "start": { diff --git a/ets2panda/test/parser/ets/dynamic_import_tests/modules/module-expected.txt b/ets2panda/test/parser/ets/dynamic_import_tests/modules/module-expected.txt index 89bafa7dc78e11846fd1089dc1620841e5665318..63103e5c36e00436f54f6fe15496bc78c7c39ce4 100644 --- a/ets2panda/test/parser/ets/dynamic_import_tests/modules/module-expected.txt +++ b/ets2panda/test/parser/ets/dynamic_import_tests/modules/module-expected.txt @@ -90,12 +90,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 19, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 19, + "column": 16 } } }, @@ -139,12 +139,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 20, + "column": 12 }, "end": { - "line": 1, - "column": 1 + "line": 20, + "column": 22 } } }, diff --git a/ets2panda/test/parser/ets/empty_statement-expected.txt b/ets2panda/test/parser/ets/empty_statement-expected.txt index df7d09a3cd5d122eae7645c6e1315ec3e5d0a984..2e225881a50cdbead8412272e1fcb37864c37007 100644 --- a/ets2panda/test/parser/ets/empty_statement-expected.txt +++ b/ets2panda/test/parser/ets/empty_statement-expected.txt @@ -202,12 +202,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 19, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 19, + "column": 11 } } }, diff --git a/ets2panda/test/parser/ets/enum-expected.txt b/ets2panda/test/parser/ets/enum-expected.txt index 33faf5b2498f1fdc6c1fca6a04ba0484d27174d2..edcd158548ed00f63dd34d455018a1c3ffbcb6d7 100644 --- a/ets2panda/test/parser/ets/enum-expected.txt +++ b/ets2panda/test/parser/ets/enum-expected.txt @@ -247,12 +247,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 19, + "column": 10 }, "end": { - "line": 1, - "column": 1 + "line": 19, + "column": 19 } } }, diff --git a/ets2panda/test/parser/ets/enum19-expected.txt b/ets2panda/test/parser/ets/enum19-expected.txt index 7cc03bf96332f508a420c7a127e9b6d9848e182b..df747461ca68928a9989a06b7e889fb6ceddcba1 100644 --- a/ets2panda/test/parser/ets/enum19-expected.txt +++ b/ets2panda/test/parser/ets/enum19-expected.txt @@ -1 +1,310 @@ -SyntaxError: Duplicate enum initialization value -1 [enum19.ets:20:1] +{ + "type": "Program", + "statements": [ + { + "type": "TSEnumDeclaration", + "id": { + "type": "Identifier", + "name": "InvalidInitTypeEnum", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 6 + }, + "end": { + "line": 16, + "column": 25 + } + } + }, + "members": [ + { + "type": "TSEnumMember", + "id": { + "type": "Identifier", + "name": "Red", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 3 + }, + "end": { + "line": 17, + "column": 6 + } + } + }, + "initializer": { + "type": "NumberLiteral", + "value": 0, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 3 + }, + "end": { + "line": 17, + "column": 6 + } + } + }, + { + "type": "TSEnumMember", + "id": { + "type": "Identifier", + "name": "Green", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 3 + }, + "end": { + "line": 18, + "column": 8 + } + } + }, + "initializer": { + "type": "NumberLiteral", + "value": -1, + "loc": { + "start": { + "line": 18, + "column": 12 + }, + "end": { + "line": 18, + "column": 13 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 3 + }, + "end": { + "line": 18, + "column": 13 + } + } + }, + { + "type": "TSEnumMember", + "id": { + "type": "Identifier", + "name": "Blue", + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 3 + }, + "end": { + "line": 19, + "column": 7 + } + } + }, + "initializer": { + "type": "NumberLiteral", + "value": -1, + "loc": { + "start": { + "line": 19, + "column": 10 + }, + "end": { + "line": 19, + "column": 20 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 3 + }, + "end": { + "line": 19, + "column": 20 + } + } + } + ], + "const": false, + "loc": { + "start": { + "line": 16, + "column": 1 + }, + "end": { + "line": 20, + "column": 2 + } + } + }, + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "ETSGLOBAL", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "superClass": null, + "implements": [], + "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "_$init$_", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "_$init$_", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 21, + "column": 1 + } + } +} diff --git a/ets2panda/test/parser/ets/enum20-expected.txt b/ets2panda/test/parser/ets/enum20-expected.txt index 65d031f2b2887eb78f9de05b777525622354aab9..ddbf6ffb3da603c6a29106d0ab63c8a47d0cbc13 100644 --- a/ets2panda/test/parser/ets/enum20-expected.txt +++ b/ets2panda/test/parser/ets/enum20-expected.txt @@ -1 +1,1025 @@ -SyntaxError: Duplicate enum initialization value 0 [enum20.ets:16:52] +{ + "type": "Program", + "statements": [ + { + "type": "TSEnumDeclaration", + "id": { + "type": "Identifier", + "name": "Color", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 6 + }, + "end": { + "line": 16, + "column": 11 + } + } + }, + "members": [ + { + "type": "TSEnumMember", + "id": { + "type": "Identifier", + "name": "Red", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 14 + }, + "end": { + "line": 16, + "column": 17 + } + } + }, + "initializer": { + "type": "NumberLiteral", + "value": 0, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 14 + }, + "end": { + "line": 16, + "column": 17 + } + } + }, + { + "type": "TSEnumMember", + "id": { + "type": "Identifier", + "name": "Green", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 19 + }, + "end": { + "line": 16, + "column": 24 + } + } + }, + "initializer": { + "type": "NumberLiteral", + "value": -100, + "loc": { + "start": { + "line": 16, + "column": 28 + }, + "end": { + "line": 16, + "column": 31 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 19 + }, + "end": { + "line": 16, + "column": 31 + } + } + }, + { + "type": "TSEnumMember", + "id": { + "type": "Identifier", + "name": "Blue", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 33 + }, + "end": { + "line": 16, + "column": 37 + } + } + }, + "initializer": { + "type": "NumberLiteral", + "value": -99, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 33 + }, + "end": { + "line": 16, + "column": 37 + } + } + }, + { + "type": "TSEnumMember", + "id": { + "type": "Identifier", + "name": "White", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 39 + }, + "end": { + "line": 16, + "column": 44 + } + } + }, + "initializer": { + "type": "NumberLiteral", + "value": 0, + "loc": { + "start": { + "line": 16, + "column": 47 + }, + "end": { + "line": 16, + "column": 51 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 39 + }, + "end": { + "line": 16, + "column": 51 + } + } + } + ], + "const": false, + "loc": { + "start": { + "line": 16, + "column": 1 + }, + "end": { + "line": 16, + "column": 53 + } + } + }, + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "ETSGLOBAL", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "superClass": null, + "implements": [], + "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "_$init$_", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "_$init$_", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 10 + }, + "end": { + "line": 18, + "column": 14 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 10 + }, + "end": { + "line": 18, + "column": 14 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "returnType": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "void", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 18 + }, + "end": { + "line": 18, + "column": 22 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 18 + }, + "end": { + "line": 18, + "column": 24 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 18 + }, + "end": { + "line": 18, + "column": 24 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "red", + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 7 + }, + "end": { + "line": 19, + "column": 10 + } + } + }, + "init": { + "type": "CallExpression", + "callee": { + "type": "MemberExpression", + "object": { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "Color", + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 13 + }, + "end": { + "line": 19, + "column": 18 + } + } + }, + "property": { + "type": "Identifier", + "name": "Red", + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 19 + }, + "end": { + "line": 19, + "column": 22 + } + } + }, + "computed": false, + "optional": false, + "loc": { + "start": { + "line": 19, + "column": 13 + }, + "end": { + "line": 19, + "column": 22 + } + } + }, + "property": { + "type": "Identifier", + "name": "ordinal", + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 23 + }, + "end": { + "line": 19, + "column": 30 + } + } + }, + "computed": false, + "optional": false, + "loc": { + "start": { + "line": 19, + "column": 13 + }, + "end": { + "line": 19, + "column": 30 + } + } + }, + "arguments": [], + "optional": false, + "loc": { + "start": { + "line": 19, + "column": 13 + }, + "end": { + "line": 19, + "column": 32 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 7 + }, + "end": { + "line": 19, + "column": 32 + } + } + } + ], + "kind": "let", + "loc": { + "start": { + "line": 19, + "column": 3 + }, + "end": { + "line": 19, + "column": 33 + } + } + }, + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "green", + "decorators": [], + "loc": { + "start": { + "line": 20, + "column": 7 + }, + "end": { + "line": 20, + "column": 12 + } + } + }, + "init": { + "type": "CallExpression", + "callee": { + "type": "MemberExpression", + "object": { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "Color", + "decorators": [], + "loc": { + "start": { + "line": 20, + "column": 15 + }, + "end": { + "line": 20, + "column": 20 + } + } + }, + "property": { + "type": "Identifier", + "name": "Green", + "decorators": [], + "loc": { + "start": { + "line": 20, + "column": 21 + }, + "end": { + "line": 20, + "column": 26 + } + } + }, + "computed": false, + "optional": false, + "loc": { + "start": { + "line": 20, + "column": 15 + }, + "end": { + "line": 20, + "column": 26 + } + } + }, + "property": { + "type": "Identifier", + "name": "ordinal", + "decorators": [], + "loc": { + "start": { + "line": 20, + "column": 27 + }, + "end": { + "line": 20, + "column": 34 + } + } + }, + "computed": false, + "optional": false, + "loc": { + "start": { + "line": 20, + "column": 15 + }, + "end": { + "line": 20, + "column": 34 + } + } + }, + "arguments": [], + "optional": false, + "loc": { + "start": { + "line": 20, + "column": 15 + }, + "end": { + "line": 20, + "column": 36 + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 7 + }, + "end": { + "line": 20, + "column": 36 + } + } + } + ], + "kind": "let", + "loc": { + "start": { + "line": 20, + "column": 3 + }, + "end": { + "line": 20, + "column": 37 + } + } + }, + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "blue", + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 7 + }, + "end": { + "line": 21, + "column": 11 + } + } + }, + "init": { + "type": "CallExpression", + "callee": { + "type": "MemberExpression", + "object": { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "Color", + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 14 + }, + "end": { + "line": 21, + "column": 19 + } + } + }, + "property": { + "type": "Identifier", + "name": "Blue", + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 20 + }, + "end": { + "line": 21, + "column": 24 + } + } + }, + "computed": false, + "optional": false, + "loc": { + "start": { + "line": 21, + "column": 14 + }, + "end": { + "line": 21, + "column": 24 + } + } + }, + "property": { + "type": "Identifier", + "name": "ordinal", + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 25 + }, + "end": { + "line": 21, + "column": 32 + } + } + }, + "computed": false, + "optional": false, + "loc": { + "start": { + "line": 21, + "column": 14 + }, + "end": { + "line": 21, + "column": 32 + } + } + }, + "arguments": [], + "optional": false, + "loc": { + "start": { + "line": 21, + "column": 14 + }, + "end": { + "line": 21, + "column": 34 + } + } + }, + "loc": { + "start": { + "line": 21, + "column": 7 + }, + "end": { + "line": 21, + "column": 34 + } + } + } + ], + "kind": "let", + "loc": { + "start": { + "line": 21, + "column": 3 + }, + "end": { + "line": 21, + "column": 35 + } + } + }, + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "white", + "decorators": [], + "loc": { + "start": { + "line": 22, + "column": 7 + }, + "end": { + "line": 22, + "column": 12 + } + } + }, + "init": { + "type": "CallExpression", + "callee": { + "type": "MemberExpression", + "object": { + "type": "MemberExpression", + "object": { + "type": "Identifier", + "name": "Color", + "decorators": [], + "loc": { + "start": { + "line": 22, + "column": 15 + }, + "end": { + "line": 22, + "column": 20 + } + } + }, + "property": { + "type": "Identifier", + "name": "White", + "decorators": [], + "loc": { + "start": { + "line": 22, + "column": 21 + }, + "end": { + "line": 22, + "column": 26 + } + } + }, + "computed": false, + "optional": false, + "loc": { + "start": { + "line": 22, + "column": 15 + }, + "end": { + "line": 22, + "column": 26 + } + } + }, + "property": { + "type": "Identifier", + "name": "ordinal", + "decorators": [], + "loc": { + "start": { + "line": 22, + "column": 27 + }, + "end": { + "line": 22, + "column": 34 + } + } + }, + "computed": false, + "optional": false, + "loc": { + "start": { + "line": 22, + "column": 15 + }, + "end": { + "line": 22, + "column": 34 + } + } + }, + "arguments": [], + "optional": false, + "loc": { + "start": { + "line": 22, + "column": 15 + }, + "end": { + "line": 22, + "column": 36 + } + } + }, + "loc": { + "start": { + "line": 22, + "column": 7 + }, + "end": { + "line": 22, + "column": 36 + } + } + } + ], + "kind": "let", + "loc": { + "start": { + "line": 22, + "column": 3 + }, + "end": { + "line": 22, + "column": 37 + } + } + } + ], + "loc": { + "start": { + "line": 18, + "column": 23 + }, + "end": { + "line": 23, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 14 + }, + "end": { + "line": 23, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 14 + }, + "end": { + "line": 23, + "column": 2 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 1 + }, + "end": { + "line": 23, + "column": 2 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 24, + "column": 1 + } + } +} +TypeError: No enum item method called 'ordinal' [enum20.ets:19:23] diff --git a/ets2panda/test/parser/ets/enum21-expected.txt b/ets2panda/test/parser/ets/enum21-expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..cdccfed003d73dbb2108d33616e0ed7c91d4fb7a --- /dev/null +++ b/ets2panda/test/parser/ets/enum21-expected.txt @@ -0,0 +1,268 @@ +{ + "type": "Program", + "statements": [ + { + "type": "TSEnumDeclaration", + "id": { + "type": "Identifier", + "name": "ArkColor", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 6 + }, + "end": { + "line": 16, + "column": 14 + } + } + }, + "members": [ + { + "type": "TSEnumMember", + "id": { + "type": "Identifier", + "name": "Gray", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 3 + }, + "end": { + "line": 17, + "column": 7 + } + } + }, + "initializer": { + "type": "StringLiteral", + "value": "#ff808080", + "loc": { + "start": { + "line": 17, + "column": 10 + }, + "end": { + "line": 17, + "column": 21 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 3 + }, + "end": { + "line": 17, + "column": 21 + } + } + }, + { + "type": "TSEnumMember", + "id": { + "type": "Identifier", + "name": "Grey", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 3 + }, + "end": { + "line": 18, + "column": 7 + } + } + }, + "initializer": { + "type": "StringLiteral", + "value": "#ff808080", + "loc": { + "start": { + "line": 18, + "column": 10 + }, + "end": { + "line": 18, + "column": 21 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 3 + }, + "end": { + "line": 18, + "column": 21 + } + } + } + ], + "const": false, + "loc": { + "start": { + "line": 16, + "column": 1 + }, + "end": { + "line": 19, + "column": 2 + } + } + }, + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "ETSGLOBAL", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "superClass": null, + "implements": [], + "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "_$init$_", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "_$init$_", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 20, + "column": 1 + } + } +} diff --git a/ets2panda/test/parser/ets/enum21.ets b/ets2panda/test/parser/ets/enum21.ets new file mode 100644 index 0000000000000000000000000000000000000000..54dfe00e9fe265a1222713fa53e6fa86ef4b0879 --- /dev/null +++ b/ets2panda/test/parser/ets/enum21.ets @@ -0,0 +1,19 @@ +/* + * 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. + */ + +enum ArkColor { + Gray = "#ff808080", + Grey = "#ff808080" +} diff --git a/ets2panda/test/parser/ets/enum22-expected.txt b/ets2panda/test/parser/ets/enum22-expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..7c19b3b0f34b7abbaf250f0bec86fc5101f9d1bd --- /dev/null +++ b/ets2panda/test/parser/ets/enum22-expected.txt @@ -0,0 +1 @@ +SyntaxError: Variable 'Gray' has already been declared. [enum22.ets:18:5] diff --git a/ets2panda/test/parser/ets/enum22.ets b/ets2panda/test/parser/ets/enum22.ets new file mode 100644 index 0000000000000000000000000000000000000000..27f85fd0a413229006b668c08cbf5ed4578c6286 --- /dev/null +++ b/ets2panda/test/parser/ets/enum22.ets @@ -0,0 +1,19 @@ +/* + * 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. + */ + +enum duplicateKeysStringCase { + Gray = "#ff808080", + Gray = "#ff808080" +} \ No newline at end of file diff --git a/ets2panda/test/parser/ets/enum23-expected.txt b/ets2panda/test/parser/ets/enum23-expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..11869929521aa134465fb7df635e8d0d8eecc0a0 --- /dev/null +++ b/ets2panda/test/parser/ets/enum23-expected.txt @@ -0,0 +1 @@ +SyntaxError: Variable 'Red' has already been declared. [enum23.ets:18:5] diff --git a/ets2panda/test/parser/ets/enum23.ets b/ets2panda/test/parser/ets/enum23.ets new file mode 100644 index 0000000000000000000000000000000000000000..de2a396d37f6a2cb860b8392411501c05583a2dc --- /dev/null +++ b/ets2panda/test/parser/ets/enum23.ets @@ -0,0 +1,19 @@ +/* + * 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. + */ + +enum duplicateKeysNumCase { + Red = 1, + Red = 1 +} \ No newline at end of file diff --git a/ets2panda/test/parser/ets/exports-expected.txt b/ets2panda/test/parser/ets/exports-expected.txt index f0f84b4b21fd14ee348758a2c3d296b7725a2398..aab03ca6223b18134f4b881ca75b3b54274a573f 100644 --- a/ets2panda/test/parser/ets/exports-expected.txt +++ b/ets2panda/test/parser/ets/exports-expected.txt @@ -327,23 +327,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 16, + "column": 12 }, "end": { - "line": 1, - "column": 1 + "line": 16, + "column": 18 } } }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 16, + "column": 8 }, "end": { - "line": 1, - "column": 1 + "line": 16, + "column": 19 } } } @@ -435,12 +435,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 16, + "column": 12 }, "end": { - "line": 1, - "column": 1 + "line": 16, + "column": 18 } } }, @@ -485,12 +485,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 17, + "column": 14 }, "end": { - "line": 1, - "column": 1 + "line": 17, + "column": 20 } } }, diff --git a/ets2panda/test/parser/ets/extension_function_tests/extension_function_access_private_field-expected.txt b/ets2panda/test/parser/ets/extension_function_tests/extension_function_access_private_field-expected.txt index 9d29b2e8db9cb4bbdf0049eb8b5fa6ae35022fc7..81d573a8a844b6d159166b8c43b53155759fdf7a 100644 --- a/ets2panda/test/parser/ets/extension_function_tests/extension_function_access_private_field-expected.txt +++ b/ets2panda/test/parser/ets/extension_function_tests/extension_function_access_private_field-expected.txt @@ -76,12 +76,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 17, + "column": 13 }, "end": { - "line": 1, - "column": 1 + "line": 17, + "column": 24 } } }, diff --git a/ets2panda/test/parser/ets/field_decl-expected.txt b/ets2panda/test/parser/ets/field_decl-expected.txt index 13d0f0143d25fd65fe785bd4ddd82697f0ac54e3..25bfd9129a170d6fae7fa85d26d9c532dc07f18c 100644 --- a/ets2panda/test/parser/ets/field_decl-expected.txt +++ b/ets2panda/test/parser/ets/field_decl-expected.txt @@ -202,12 +202,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 19, + "column": 13 }, "end": { - "line": 1, - "column": 1 + "line": 19, + "column": 20 } } }, @@ -251,12 +251,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 20, + "column": 15 }, "end": { - "line": 1, - "column": 1 + "line": 20, + "column": 23 } } }, @@ -314,12 +314,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 21, + "column": 15 }, "end": { - "line": 1, - "column": 1 + "line": 21, + "column": 30 } } }, @@ -377,12 +377,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 22, + "column": 12 }, "end": { - "line": 1, - "column": 1 + "line": 22, + "column": 30 } } }, @@ -426,12 +426,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 23, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 23, + "column": 14 } } }, @@ -475,12 +475,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 24, + "column": 12 }, "end": { - "line": 1, - "column": 1 + "line": 24, + "column": 20 } } }, @@ -538,12 +538,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 25, + "column": 21 }, "end": { - "line": 1, - "column": 1 + "line": 25, + "column": 38 } } }, @@ -601,12 +601,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 26, + "column": 28 }, "end": { - "line": 1, - "column": 1 + "line": 26, + "column": 48 } } }, @@ -664,12 +664,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 27, + "column": 22 }, "end": { - "line": 1, - "column": 1 + "line": 27, + "column": 34 } } }, diff --git a/ets2panda/test/parser/ets/for_of-expected.txt b/ets2panda/test/parser/ets/for_of-expected.txt index 481464b7259e994d486816a998733452133af19c..d3446be05acb4a707042ce62be9e66b71e03153c 100644 --- a/ets2panda/test/parser/ets/for_of-expected.txt +++ b/ets2panda/test/parser/ets/for_of-expected.txt @@ -149,23 +149,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 17, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 17, + "column": 25 } } }, "loc": { "start": { - "line": 1, + "line": 17, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 17, + "column": 26 } } } @@ -269,12 +269,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 17, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 17, + "column": 15 } } }, diff --git a/ets2panda/test/parser/ets/for_of_02-expected.txt b/ets2panda/test/parser/ets/for_of_02-expected.txt index 7a44ae114a3c8ff1e0a1ddf081d9d10e615731de..f7ae611379b140d2abf221271420444eec740cd0 100644 --- a/ets2panda/test/parser/ets/for_of_02-expected.txt +++ b/ets2panda/test/parser/ets/for_of_02-expected.txt @@ -149,23 +149,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 16, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 16, + "column": 25 } } }, "loc": { "start": { - "line": 1, + "line": 16, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 16, + "column": 26 } } } @@ -269,12 +269,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 16, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 16, + "column": 15 } } }, diff --git a/ets2panda/test/parser/ets/function-expected.txt b/ets2panda/test/parser/ets/function-expected.txt index a5f03e6e932f58902a2622205dd5e2eda1c36623..f1b6103f28447ef581b227b2b2e7eb24c5667e1a 100644 --- a/ets2panda/test/parser/ets/function-expected.txt +++ b/ets2panda/test/parser/ets/function-expected.txt @@ -1467,12 +1467,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 34, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 36, + "column": 2 } } } diff --git a/ets2panda/test/parser/ets/functionTypeThrows-expected.txt b/ets2panda/test/parser/ets/functionTypeThrows-expected.txt index 9f504266b843b1daeaff8568c320056754be55b6..2c3510eb6070b6e709fbb43b7891a215c1cc35ee 100644 --- a/ets2panda/test/parser/ets/functionTypeThrows-expected.txt +++ b/ets2panda/test/parser/ets/functionTypeThrows-expected.txt @@ -254,12 +254,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 16, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 16, + "column": 32 } } } diff --git a/ets2panda/test/parser/ets/function_implicit_return_type2-expected.txt b/ets2panda/test/parser/ets/function_implicit_return_type2-expected.txt index e765b5e9e3e22a4c40d8e7145ad6bfd46973fb87..86dadbaca552b0b22c7f1cd3bcc89d9bc24254e7 100644 --- a/ets2panda/test/parser/ets/function_implicit_return_type2-expected.txt +++ b/ets2panda/test/parser/ets/function_implicit_return_type2-expected.txt @@ -272,12 +272,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 17, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 17, + "column": 44 } } } diff --git a/ets2panda/test/parser/ets/function_implicit_return_type3-expected.txt b/ets2panda/test/parser/ets/function_implicit_return_type3-expected.txt index 86c0bf3a67b14a00dad67ec7b52878c2d2541808..41e4545d599f50668ebfd4a924992a225a4b2899 100644 --- a/ets2panda/test/parser/ets/function_implicit_return_type3-expected.txt +++ b/ets2panda/test/parser/ets/function_implicit_return_type3-expected.txt @@ -107,23 +107,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 18, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 18, + "column": 32 } } }, "loc": { "start": { - "line": 1, + "line": 18, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 18, + "column": 33 } } } @@ -421,12 +421,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 18, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 18, + "column": 32 } } } diff --git a/ets2panda/test/parser/ets/generic_error-expected.txt b/ets2panda/test/parser/ets/generic_error-expected.txt index 9d5271352d066e77f851914a13fbaf3352e247ce..11e1c94b0ed0fde5ea2e79046eb404048864bbb0 100644 --- a/ets2panda/test/parser/ets/generic_error-expected.txt +++ b/ets2panda/test/parser/ets/generic_error-expected.txt @@ -138,6 +138,312 @@ } } }, + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "OldMap", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 7 + }, + "end": { + "line": 18, + "column": 13 + } + } + }, + "typeParameters": { + "type": "TSTypeParameterDeclaration", + "params": [ + { + "type": "TSTypeParameter", + "name": { + "type": "Identifier", + "name": "K", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 14 + }, + "end": { + "line": 18, + "column": 15 + } + } + }, + "constraint": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Comparable", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 24 + }, + "end": { + "line": 18, + "column": 34 + } + } + }, + "typeParams": { + "type": "TSTypeParameterInstantiation", + "params": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Object", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 35 + }, + "end": { + "line": 18, + "column": 41 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 35 + }, + "end": { + "line": 18, + "column": 42 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 35 + }, + "end": { + "line": 18, + "column": 42 + } + } + } + ], + "loc": { + "start": { + "line": 18, + "column": 34 + }, + "end": { + "line": 18, + "column": 42 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 24 + }, + "end": { + "line": 18, + "column": 43 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 24 + }, + "end": { + "line": 18, + "column": 43 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 14 + }, + "end": { + "line": 18, + "column": 43 + } + } + }, + { + "type": "TSTypeParameter", + "name": { + "type": "Identifier", + "name": "V", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 44 + }, + "end": { + "line": 18, + "column": 45 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 44 + }, + "end": { + "line": 18, + "column": 46 + } + } + } + ], + "loc": { + "start": { + "line": 18, + "column": 13 + }, + "end": { + "line": 18, + "column": 46 + } + } + }, + "superClass": null, + "implements": [], + "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "constructor", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "constructor", + "accessibility": "public", + "static": false, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "constructor", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 19, + "column": 18 + }, + "end": { + "line": 19, + "column": 20 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 15 + }, + "end": { + "line": 19, + "column": 20 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 15 + }, + "end": { + "line": 19, + "column": 20 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 4 + }, + "end": { + "line": 19, + "column": 20 + } + } + } + ], + "loc": { + "start": { + "line": 18, + "column": 47 + }, + "end": { + "line": 20, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 1 + }, + "end": { + "line": 20, + "column": 2 + } + } + }, { "type": "ClassDeclaration", "definition": { @@ -261,11 +567,11 @@ "decorators": [], "loc": { "start": { - "line": 18, + "line": 22, "column": 10 }, "end": { - "line": 18, + "line": 22, "column": 14 } } @@ -285,11 +591,11 @@ "decorators": [], "loc": { "start": { - "line": 18, + "line": 22, "column": 10 }, "end": { - "line": 18, + "line": 22, "column": 14 } } @@ -308,33 +614,33 @@ "decorators": [], "loc": { "start": { - "line": 18, + "line": 22, "column": 18 }, "end": { - "line": 18, + "line": 22, "column": 22 } } }, "loc": { "start": { - "line": 18, + "line": 22, "column": 18 }, "end": { - "line": 18, + "line": 22, "column": 24 } } }, "loc": { "start": { - "line": 18, + "line": 22, "column": 18 }, "end": { - "line": 18, + "line": 22, "column": 24 } } @@ -353,11 +659,11 @@ "decorators": [], "loc": { "start": { - "line": 19, + "line": 23, "column": 8 }, "end": { - "line": 19, + "line": 23, "column": 9 } } @@ -370,16 +676,16 @@ "type": "ETSTypeReferencePart", "name": { "type": "Identifier", - "name": "Map", + "name": "OldMap", "decorators": [], "loc": { "start": { - "line": 19, + "line": 23, "column": 16 }, "end": { - "line": 19, - "column": 19 + "line": 23, + "column": 22 } } }, @@ -396,34 +702,34 @@ "decorators": [], "loc": { "start": { - "line": 19, - "column": 20 + "line": 23, + "column": 23 }, "end": { - "line": 19, - "column": 21 + "line": 23, + "column": 24 } } }, "loc": { "start": { - "line": 19, - "column": 20 + "line": 23, + "column": 23 }, "end": { - "line": 19, - "column": 22 + "line": 23, + "column": 25 } } }, "loc": { "start": { - "line": 19, - "column": 20 + "line": 23, + "column": 23 }, "end": { - "line": 19, - "column": 22 + "line": 23, + "column": 25 } } }, @@ -437,91 +743,91 @@ "decorators": [], "loc": { "start": { - "line": 19, - "column": 23 + "line": 23, + "column": 26 }, "end": { - "line": 19, - "column": 29 + "line": 23, + "column": 32 } } }, "loc": { "start": { - "line": 19, - "column": 23 + "line": 23, + "column": 26 }, "end": { - "line": 19, - "column": 30 + "line": 23, + "column": 33 } } }, "loc": { "start": { - "line": 19, - "column": 23 + "line": 23, + "column": 26 }, "end": { - "line": 19, - "column": 30 + "line": 23, + "column": 33 } } } ], "loc": { "start": { - "line": 19, - "column": 19 + "line": 23, + "column": 22 }, "end": { - "line": 19, - "column": 30 + "line": 23, + "column": 33 } } }, "loc": { "start": { - "line": 19, + "line": 23, "column": 16 }, "end": { - "line": 19, - "column": 31 + "line": 23, + "column": 34 } } }, "loc": { "start": { - "line": 19, + "line": 23, "column": 16 }, "end": { - "line": 19, - "column": 31 + "line": 23, + "column": 34 } } }, "arguments": [], "loc": { "start": { - "line": 19, + "line": 23, "column": 12 }, "end": { - "line": 19, - "column": 31 + "line": 23, + "column": 36 } } }, "loc": { "start": { - "line": 19, + "line": 23, "column": 8 }, "end": { - "line": 19, - "column": 31 + "line": 23, + "column": 36 } } } @@ -529,45 +835,45 @@ "kind": "let", "loc": { "start": { - "line": 19, + "line": 23, "column": 4 }, "end": { - "line": 19, - "column": 31 + "line": 23, + "column": 36 } } } ], "loc": { "start": { - "line": 18, + "line": 22, "column": 23 }, "end": { - "line": 20, + "line": 24, "column": 2 } } }, "loc": { "start": { - "line": 18, + "line": 22, "column": 14 }, "end": { - "line": 20, + "line": 24, "column": 2 } } }, "loc": { "start": { - "line": 18, + "line": 22, "column": 14 }, "end": { - "line": 20, + "line": 24, "column": 2 } } @@ -576,11 +882,11 @@ "decorators": [], "loc": { "start": { - "line": 18, + "line": 22, "column": 1 }, "end": { - "line": 20, + "line": 24, "column": 2 } } @@ -615,9 +921,9 @@ "column": 1 }, "end": { - "line": 21, + "line": 25, "column": 1 } } } -TypeError: Type 'C' is not assignable to constraint type 'Comparable'. [generic_error.ets:19:20] +TypeError: Type 'C' is not assignable to constraint type 'Comparable'. [generic_error.ets:23:23] diff --git a/ets2panda/test/parser/ets/generic_error.ets b/ets2panda/test/parser/ets/generic_error.ets index 19c0ed785819e7ada294f706349abdc5961320da..46597ef15a88068c946aea70a97c68a24835a88f 100644 --- a/ets2panda/test/parser/ets/generic_error.ets +++ b/ets2panda/test/parser/ets/generic_error.ets @@ -15,6 +15,10 @@ class C {} +class OldMap, V> { + constructor() {} +} + function main(): void { - let m = new Map; + let m = new OldMap(); } diff --git a/ets2panda/test/parser/ets/generics_1-expected.txt b/ets2panda/test/parser/ets/generics_1-expected.txt index ef863b3f6522e330abc880b86838697f2ceadfb1..d8e381e5d79357471ad7d40e3f3153c46c732594 100644 --- a/ets2panda/test/parser/ets/generics_1-expected.txt +++ b/ets2panda/test/parser/ets/generics_1-expected.txt @@ -133,12 +133,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 17, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 17, + "column": 10 } } }, @@ -446,12 +446,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 21, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 21, + "column": 13 } } }, @@ -646,12 +646,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 25, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 25, + "column": 17 } } }, diff --git a/ets2panda/test/parser/ets/generics_type_param_constraint_1-expected.txt b/ets2panda/test/parser/ets/generics_type_param_constraint_1-expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..4e080ae9620bc835af391bfd5ede1f7c4679bd2a --- /dev/null +++ b/ets2panda/test/parser/ets/generics_type_param_constraint_1-expected.txt @@ -0,0 +1,524 @@ +{ + "type": "Program", + "statements": [ + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "X", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 7 + }, + "end": { + "line": 17, + "column": 8 + } + } + }, + "typeParameters": { + "type": "TSTypeParameterDeclaration", + "params": [ + { + "type": "TSTypeParameter", + "name": { + "type": "Identifier", + "name": "K", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 10 + }, + "end": { + "line": 17, + "column": 11 + } + } + }, + "constraint": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Comparable", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 20 + }, + "end": { + "line": 17, + "column": 30 + } + } + }, + "typeParams": { + "type": "TSTypeParameterInstantiation", + "params": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "K", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 31 + }, + "end": { + "line": 17, + "column": 32 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 31 + }, + "end": { + "line": 17, + "column": 34 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 31 + }, + "end": { + "line": 17, + "column": 34 + } + } + } + ], + "loc": { + "start": { + "line": 17, + "column": 30 + }, + "end": { + "line": 17, + "column": 34 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 20 + }, + "end": { + "line": 17, + "column": 34 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 20 + }, + "end": { + "line": 17, + "column": 34 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 10 + }, + "end": { + "line": 17, + "column": 34 + } + } + } + ], + "loc": { + "start": { + "line": 17, + "column": 9 + }, + "end": { + "line": 17, + "column": 34 + } + } + }, + "superClass": null, + "implements": [], + "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "constructor", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "constructor", + "static": false, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "constructor", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 37 + }, + "end": { + "line": 17, + "column": 37 + } + } + } + ], + "loc": { + "start": { + "line": 17, + "column": 35 + }, + "end": { + "line": 17, + "column": 37 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 1 + }, + "end": { + "line": 17, + "column": 37 + } + } + }, + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "ETSGLOBAL", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "superClass": null, + "implements": [], + "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "_$init$_", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "_$init$_", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 10 + }, + "end": { + "line": 18, + "column": 14 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 10 + }, + "end": { + "line": 18, + "column": 14 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 18, + "column": 17 + }, + "end": { + "line": 18, + "column": 19 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 14 + }, + "end": { + "line": 18, + "column": 19 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 14 + }, + "end": { + "line": 18, + "column": 19 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 1 + }, + "end": { + "line": 18, + "column": 19 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 19, + "column": 1 + } + } +} diff --git a/ets2panda/test/parser/ets/generics_type_param_constraint_1.ets b/ets2panda/test/parser/ets/generics_type_param_constraint_1.ets new file mode 100644 index 0000000000000000000000000000000000000000..d8417c9a359fe85b148aa07392d0169087672456 --- /dev/null +++ b/ets2panda/test/parser/ets/generics_type_param_constraint_1.ets @@ -0,0 +1,18 @@ +/* + * 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. + */ + + +class X > {} +function main() {} diff --git a/ets2panda/test/parser/ets/generics_type_param_constraint_10-expected.txt b/ets2panda/test/parser/ets/generics_type_param_constraint_10-expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..5d2baa5275ba064b0dff77cbe23ed32d5a5de3df --- /dev/null +++ b/ets2panda/test/parser/ets/generics_type_param_constraint_10-expected.txt @@ -0,0 +1,777 @@ +{ + "type": "Program", + "statements": [ + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "ETSGLOBAL", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "superClass": null, + "implements": [], + "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "_$init$_", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "_$init$_", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "bar", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 10 + }, + "end": { + "line": 17, + "column": 13 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "bar", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 10 + }, + "end": { + "line": 17, + "column": 13 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [ + { + "type": "ETSParameterExpression", + "name": { + "type": "Identifier", + "name": "x", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "T", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 42 + }, + "end": { + "line": 17, + "column": 43 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 42 + }, + "end": { + "line": 17, + "column": 44 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 42 + }, + "end": { + "line": 17, + "column": 44 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 39 + }, + "end": { + "line": 17, + "column": 44 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 39 + }, + "end": { + "line": 17, + "column": 44 + } + } + } + ], + "returnType": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "T", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 46 + }, + "end": { + "line": 17, + "column": 47 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 46 + }, + "end": { + "line": 17, + "column": 49 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 46 + }, + "end": { + "line": 17, + "column": 49 + } + } + }, + "typeParameters": { + "type": "TSTypeParameterDeclaration", + "params": [ + { + "type": "TSTypeParameter", + "name": { + "type": "Identifier", + "name": "T", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 14 + }, + "end": { + "line": 17, + "column": 15 + } + } + }, + "constraint": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Comparable", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 24 + }, + "end": { + "line": 17, + "column": 34 + } + } + }, + "typeParams": { + "type": "TSTypeParameterInstantiation", + "params": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "T", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 35 + }, + "end": { + "line": 17, + "column": 36 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 35 + }, + "end": { + "line": 17, + "column": 38 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 35 + }, + "end": { + "line": 17, + "column": 38 + } + } + } + ], + "loc": { + "start": { + "line": 17, + "column": 34 + }, + "end": { + "line": 17, + "column": 38 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 24 + }, + "end": { + "line": 17, + "column": 38 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 24 + }, + "end": { + "line": 17, + "column": 38 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 14 + }, + "end": { + "line": 17, + "column": 38 + } + } + } + ], + "loc": { + "start": { + "line": 17, + "column": 13 + }, + "end": { + "line": 17, + "column": 38 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "ReturnStatement", + "argument": { + "type": "Identifier", + "name": "x", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 12 + }, + "end": { + "line": 18, + "column": 13 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 5 + }, + "end": { + "line": 18, + "column": 14 + } + } + } + ], + "loc": { + "start": { + "line": 17, + "column": 48 + }, + "end": { + "line": 19, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 13 + }, + "end": { + "line": 19, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 13 + }, + "end": { + "line": 19, + "column": 2 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 1 + }, + "end": { + "line": 19, + "column": 2 + } + } + }, + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 10 + }, + "end": { + "line": 21, + "column": 14 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 10 + }, + "end": { + "line": 21, + "column": 14 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "returnType": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "void", + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 18 + }, + "end": { + "line": 21, + "column": 22 + } + } + }, + "loc": { + "start": { + "line": 21, + "column": 18 + }, + "end": { + "line": 21, + "column": 24 + } + } + }, + "loc": { + "start": { + "line": 21, + "column": 18 + }, + "end": { + "line": 21, + "column": 24 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "ExpressionStatement", + "expression": { + "type": "CallExpression", + "callee": { + "type": "Identifier", + "name": "bar", + "decorators": [], + "loc": { + "start": { + "line": 22, + "column": 5 + }, + "end": { + "line": 22, + "column": 8 + } + } + }, + "arguments": [ + { + "type": "StringLiteral", + "value": "456", + "loc": { + "start": { + "line": 22, + "column": 17 + }, + "end": { + "line": 22, + "column": 22 + } + } + } + ], + "optional": false, + "typeParameters": { + "type": "TSTypeParameterInstantiation", + "params": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "string", + "decorators": [], + "loc": { + "start": { + "line": 22, + "column": 9 + }, + "end": { + "line": 22, + "column": 15 + } + } + }, + "loc": { + "start": { + "line": 22, + "column": 9 + }, + "end": { + "line": 22, + "column": 16 + } + } + }, + "loc": { + "start": { + "line": 22, + "column": 9 + }, + "end": { + "line": 22, + "column": 16 + } + } + } + ], + "loc": { + "start": { + "line": 22, + "column": 8 + }, + "end": { + "line": 22, + "column": 16 + } + } + }, + "loc": { + "start": { + "line": 22, + "column": 5 + }, + "end": { + "line": 22, + "column": 23 + } + } + }, + "loc": { + "start": { + "line": 22, + "column": 5 + }, + "end": { + "line": 22, + "column": 24 + } + } + } + ], + "loc": { + "start": { + "line": 21, + "column": 23 + }, + "end": { + "line": 23, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 21, + "column": 14 + }, + "end": { + "line": 23, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 21, + "column": 14 + }, + "end": { + "line": 23, + "column": 2 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 1 + }, + "end": { + "line": 23, + "column": 2 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 24, + "column": 1 + } + } +} diff --git a/ets2panda/test/parser/ets/generics_type_param_constraint_10.ets b/ets2panda/test/parser/ets/generics_type_param_constraint_10.ets new file mode 100644 index 0000000000000000000000000000000000000000..17b5c5a98b3e028f0606db6ca3dcef9b668e0f2e --- /dev/null +++ b/ets2panda/test/parser/ets/generics_type_param_constraint_10.ets @@ -0,0 +1,23 @@ +/* + * 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. + */ + + +function bar>(x: T): T { + return x; +} + +function main(): void { + bar("456"); +} diff --git a/ets2panda/test/parser/ets/generics_type_param_constraint_2-expected.txt b/ets2panda/test/parser/ets/generics_type_param_constraint_2-expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..326439e5f9989bc22daf4762ec84a1504d7cbfab --- /dev/null +++ b/ets2panda/test/parser/ets/generics_type_param_constraint_2-expected.txt @@ -0,0 +1,336 @@ +{ + "type": "Program", + "statements": [ + { + "type": "TSInterfaceDeclaration", + "body": { + "type": "TSInterfaceBody", + "body": [], + "loc": { + "start": { + "line": 17, + "column": 39 + }, + "end": { + "line": 17, + "column": 41 + } + } + }, + "id": { + "type": "Identifier", + "name": "X", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 11 + }, + "end": { + "line": 17, + "column": 12 + } + } + }, + "extends": [], + "typeParameters": { + "type": "TSTypeParameterDeclaration", + "params": [ + { + "type": "TSTypeParameter", + "name": { + "type": "Identifier", + "name": "K", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 14 + }, + "end": { + "line": 17, + "column": 15 + } + } + }, + "constraint": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Comparable", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 24 + }, + "end": { + "line": 17, + "column": 34 + } + } + }, + "typeParams": { + "type": "TSTypeParameterInstantiation", + "params": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "K", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 35 + }, + "end": { + "line": 17, + "column": 36 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 35 + }, + "end": { + "line": 17, + "column": 38 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 35 + }, + "end": { + "line": 17, + "column": 38 + } + } + } + ], + "loc": { + "start": { + "line": 17, + "column": 34 + }, + "end": { + "line": 17, + "column": 38 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 24 + }, + "end": { + "line": 17, + "column": 38 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 24 + }, + "end": { + "line": 17, + "column": 38 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 14 + }, + "end": { + "line": 17, + "column": 38 + } + } + } + ], + "loc": { + "start": { + "line": 17, + "column": 13 + }, + "end": { + "line": 17, + "column": 38 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 1 + }, + "end": { + "line": 18, + "column": 1 + } + } + }, + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "ETSGLOBAL", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "superClass": null, + "implements": [], + "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "_$init$_", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "_$init$_", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 18, + "column": 1 + } + } +} diff --git a/ets2panda/test/parser/ets/generics_type_param_constraint_2.ets b/ets2panda/test/parser/ets/generics_type_param_constraint_2.ets new file mode 100644 index 0000000000000000000000000000000000000000..d06d34b560ab879ff7a8d50dc555b6be010509ea --- /dev/null +++ b/ets2panda/test/parser/ets/generics_type_param_constraint_2.ets @@ -0,0 +1,17 @@ +/* + * 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. + */ + + +interface X > {} diff --git a/ets2panda/test/parser/ets/generics_type_param_constraint_3-expected.txt b/ets2panda/test/parser/ets/generics_type_param_constraint_3-expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..3b525585b96fa00ef977c4c828c982d39924a93c --- /dev/null +++ b/ets2panda/test/parser/ets/generics_type_param_constraint_3-expected.txt @@ -0,0 +1,527 @@ +{ + "type": "Program", + "statements": [ + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "ETSGLOBAL", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "superClass": null, + "implements": [], + "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "_$init$_", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "_$init$_", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "X", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 10 + }, + "end": { + "line": 17, + "column": 11 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "X", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 10 + }, + "end": { + "line": 17, + "column": 11 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [ + { + "type": "ETSParameterExpression", + "name": { + "type": "Identifier", + "name": "value", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "K", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 45 + }, + "end": { + "line": 17, + "column": 46 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 45 + }, + "end": { + "line": 17, + "column": 47 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 45 + }, + "end": { + "line": 17, + "column": 47 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 38 + }, + "end": { + "line": 17, + "column": 47 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 38 + }, + "end": { + "line": 17, + "column": 47 + } + } + } + ], + "returnType": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "K", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 50 + }, + "end": { + "line": 17, + "column": 51 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 50 + }, + "end": { + "line": 17, + "column": 53 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 50 + }, + "end": { + "line": 17, + "column": 53 + } + } + }, + "typeParameters": { + "type": "TSTypeParameterDeclaration", + "params": [ + { + "type": "TSTypeParameter", + "name": { + "type": "Identifier", + "name": "K", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 13 + }, + "end": { + "line": 17, + "column": 14 + } + } + }, + "constraint": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Comparable", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 23 + }, + "end": { + "line": 17, + "column": 33 + } + } + }, + "typeParams": { + "type": "TSTypeParameterInstantiation", + "params": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "K", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 34 + }, + "end": { + "line": 17, + "column": 35 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 34 + }, + "end": { + "line": 17, + "column": 37 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 34 + }, + "end": { + "line": 17, + "column": 37 + } + } + } + ], + "loc": { + "start": { + "line": 17, + "column": 33 + }, + "end": { + "line": 17, + "column": 37 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 23 + }, + "end": { + "line": 17, + "column": 37 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 23 + }, + "end": { + "line": 17, + "column": 37 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 13 + }, + "end": { + "line": 17, + "column": 37 + } + } + } + ], + "loc": { + "start": { + "line": 17, + "column": 12 + }, + "end": { + "line": 17, + "column": 37 + } + } + }, + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "ReturnStatement", + "argument": { + "type": "Identifier", + "name": "value", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 12 + }, + "end": { + "line": 18, + "column": 17 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 5 + }, + "end": { + "line": 18, + "column": 18 + } + } + } + ], + "loc": { + "start": { + "line": 17, + "column": 52 + }, + "end": { + "line": 19, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 12 + }, + "end": { + "line": 19, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 12 + }, + "end": { + "line": 19, + "column": 2 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 1 + }, + "end": { + "line": 19, + "column": 2 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 20, + "column": 1 + } + } +} diff --git a/ets2panda/test/parser/ets/generics_type_param_constraint_3.ets b/ets2panda/test/parser/ets/generics_type_param_constraint_3.ets new file mode 100644 index 0000000000000000000000000000000000000000..5f22a296448f8662e92d5f9da27d96825a9b1d8f --- /dev/null +++ b/ets2panda/test/parser/ets/generics_type_param_constraint_3.ets @@ -0,0 +1,19 @@ +/* + * 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. + */ + + +function X >(value: K) : K { + return value; +} diff --git a/ets2panda/test/parser/ets/generics_type_param_constraint_4-expected.txt b/ets2panda/test/parser/ets/generics_type_param_constraint_4-expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..c01abfe35c951526eb766700c0f41f25a34061eb --- /dev/null +++ b/ets2panda/test/parser/ets/generics_type_param_constraint_4-expected.txt @@ -0,0 +1,709 @@ +{ + "type": "Program", + "statements": [ + { + "type": "TSInterfaceDeclaration", + "body": { + "type": "TSInterfaceBody", + "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "ifunc", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 5 + }, + "end": { + "line": 18, + "column": 10 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": false, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "ifunc", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 5 + }, + "end": { + "line": 18, + "column": 10 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [ + { + "type": "ETSParameterExpression", + "name": { + "type": "Identifier", + "name": "x", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "T", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 14 + }, + "end": { + "line": 18, + "column": 15 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 14 + }, + "end": { + "line": 18, + "column": 16 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 14 + }, + "end": { + "line": 18, + "column": 16 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 11 + }, + "end": { + "line": 18, + "column": 16 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 11 + }, + "end": { + "line": 18, + "column": 16 + } + } + } + ], + "returnType": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "void", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 18 + }, + "end": { + "line": 18, + "column": 22 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 18 + }, + "end": { + "line": 18, + "column": 23 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 18 + }, + "end": { + "line": 18, + "column": 23 + } + } + }, + "declare": true, + "loc": { + "start": { + "line": 18, + "column": 10 + }, + "end": { + "line": 18, + "column": 23 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 10 + }, + "end": { + "line": 18, + "column": 23 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 5 + }, + "end": { + "line": 18, + "column": 23 + } + } + } + ], + "loc": { + "start": { + "line": 17, + "column": 20 + }, + "end": { + "line": 19, + "column": 2 + } + } + }, + "id": { + "type": "Identifier", + "name": "func", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 11 + }, + "end": { + "line": 17, + "column": 15 + } + } + }, + "extends": [], + "typeParameters": { + "type": "TSTypeParameterDeclaration", + "params": [ + { + "type": "TSTypeParameter", + "name": { + "type": "Identifier", + "name": "T", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 17 + }, + "end": { + "line": 17, + "column": 18 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 17 + }, + "end": { + "line": 17, + "column": 19 + } + } + } + ], + "loc": { + "start": { + "line": 17, + "column": 16 + }, + "end": { + "line": 17, + "column": 19 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 1 + }, + "end": { + "line": 20, + "column": 6 + } + } + }, + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "X", + "decorators": [], + "loc": { + "start": { + "line": 20, + "column": 7 + }, + "end": { + "line": 20, + "column": 8 + } + } + }, + "typeParameters": { + "type": "TSTypeParameterDeclaration", + "params": [ + { + "type": "TSTypeParameter", + "name": { + "type": "Identifier", + "name": "K", + "decorators": [], + "loc": { + "start": { + "line": 20, + "column": 10 + }, + "end": { + "line": 20, + "column": 11 + } + } + }, + "constraint": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "func", + "decorators": [], + "loc": { + "start": { + "line": 20, + "column": 20 + }, + "end": { + "line": 20, + "column": 24 + } + } + }, + "typeParams": { + "type": "TSTypeParameterInstantiation", + "params": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "K", + "decorators": [], + "loc": { + "start": { + "line": 20, + "column": 25 + }, + "end": { + "line": 20, + "column": 26 + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 25 + }, + "end": { + "line": 20, + "column": 28 + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 25 + }, + "end": { + "line": 20, + "column": 28 + } + } + } + ], + "loc": { + "start": { + "line": 20, + "column": 24 + }, + "end": { + "line": 20, + "column": 28 + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 20 + }, + "end": { + "line": 20, + "column": 28 + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 20 + }, + "end": { + "line": 20, + "column": 28 + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 10 + }, + "end": { + "line": 20, + "column": 28 + } + } + } + ], + "loc": { + "start": { + "line": 20, + "column": 9 + }, + "end": { + "line": 20, + "column": 28 + } + } + }, + "superClass": null, + "implements": [], + "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "constructor", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "constructor", + "static": false, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "constructor", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 20, + "column": 31 + }, + "end": { + "line": 20, + "column": 31 + } + } + } + ], + "loc": { + "start": { + "line": 20, + "column": 29 + }, + "end": { + "line": 20, + "column": 31 + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 1 + }, + "end": { + "line": 20, + "column": 31 + } + } + }, + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "ETSGLOBAL", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "superClass": null, + "implements": [], + "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "_$init$_", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "_$init$_", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 21, + "column": 1 + } + } +} diff --git a/ets2panda/test/parser/ets/generics_type_param_constraint_4.ets b/ets2panda/test/parser/ets/generics_type_param_constraint_4.ets new file mode 100644 index 0000000000000000000000000000000000000000..369ca4643a150b496775136670484f83d02c5564 --- /dev/null +++ b/ets2panda/test/parser/ets/generics_type_param_constraint_4.ets @@ -0,0 +1,20 @@ +/* + * 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. + */ + + +interface func { + ifunc(x: T): void; +} +class X > {} diff --git a/ets2panda/test/parser/ets/generics_type_param_constraint_5-expected.txt b/ets2panda/test/parser/ets/generics_type_param_constraint_5-expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..fd54bd69e73bc35d596b15baeb8d66b7b262de96 --- /dev/null +++ b/ets2panda/test/parser/ets/generics_type_param_constraint_5-expected.txt @@ -0,0 +1,998 @@ +{ + "type": "Program", + "statements": [ + { + "type": "TSInterfaceDeclaration", + "body": { + "type": "TSInterfaceBody", + "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "ifunc1", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 5 + }, + "end": { + "line": 18, + "column": 11 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": false, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "ifunc1", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 5 + }, + "end": { + "line": 18, + "column": 11 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [ + { + "type": "ETSParameterExpression", + "name": { + "type": "Identifier", + "name": "x", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "T", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 15 + }, + "end": { + "line": 18, + "column": 16 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 15 + }, + "end": { + "line": 18, + "column": 17 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 15 + }, + "end": { + "line": 18, + "column": 17 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 12 + }, + "end": { + "line": 18, + "column": 17 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 12 + }, + "end": { + "line": 18, + "column": 17 + } + } + } + ], + "returnType": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "void", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 19 + }, + "end": { + "line": 18, + "column": 23 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 19 + }, + "end": { + "line": 18, + "column": 24 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 19 + }, + "end": { + "line": 18, + "column": 24 + } + } + }, + "declare": true, + "loc": { + "start": { + "line": 18, + "column": 11 + }, + "end": { + "line": 18, + "column": 24 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 11 + }, + "end": { + "line": 18, + "column": 24 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 5 + }, + "end": { + "line": 18, + "column": 24 + } + } + }, + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "ifunc2", + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 5 + }, + "end": { + "line": 19, + "column": 11 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": false, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "ifunc2", + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 5 + }, + "end": { + "line": 19, + "column": 11 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [ + { + "type": "ETSParameterExpression", + "name": { + "type": "Identifier", + "name": "x", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "K", + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 15 + }, + "end": { + "line": 19, + "column": 16 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 15 + }, + "end": { + "line": 19, + "column": 17 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 15 + }, + "end": { + "line": 19, + "column": 17 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 12 + }, + "end": { + "line": 19, + "column": 17 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 12 + }, + "end": { + "line": 19, + "column": 17 + } + } + } + ], + "returnType": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "void", + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 19 + }, + "end": { + "line": 19, + "column": 23 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 19 + }, + "end": { + "line": 19, + "column": 24 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 19 + }, + "end": { + "line": 19, + "column": 24 + } + } + }, + "declare": true, + "loc": { + "start": { + "line": 19, + "column": 11 + }, + "end": { + "line": 19, + "column": 24 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 11 + }, + "end": { + "line": 19, + "column": 24 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 5 + }, + "end": { + "line": 19, + "column": 24 + } + } + } + ], + "loc": { + "start": { + "line": 17, + "column": 22 + }, + "end": { + "line": 20, + "column": 2 + } + } + }, + "id": { + "type": "Identifier", + "name": "func", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 11 + }, + "end": { + "line": 17, + "column": 15 + } + } + }, + "extends": [], + "typeParameters": { + "type": "TSTypeParameterDeclaration", + "params": [ + { + "type": "TSTypeParameter", + "name": { + "type": "Identifier", + "name": "T", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 17 + }, + "end": { + "line": 17, + "column": 18 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 17 + }, + "end": { + "line": 17, + "column": 19 + } + } + }, + { + "type": "TSTypeParameter", + "name": { + "type": "Identifier", + "name": "K", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 19 + }, + "end": { + "line": 17, + "column": 20 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 19 + }, + "end": { + "line": 17, + "column": 21 + } + } + } + ], + "loc": { + "start": { + "line": 17, + "column": 16 + }, + "end": { + "line": 17, + "column": 21 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 1 + }, + "end": { + "line": 21, + "column": 6 + } + } + }, + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "X", + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 7 + }, + "end": { + "line": 21, + "column": 8 + } + } + }, + "typeParameters": { + "type": "TSTypeParameterDeclaration", + "params": [ + { + "type": "TSTypeParameter", + "name": { + "type": "Identifier", + "name": "T", + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 10 + }, + "end": { + "line": 21, + "column": 11 + } + } + }, + "loc": { + "start": { + "line": 21, + "column": 10 + }, + "end": { + "line": 21, + "column": 12 + } + } + }, + { + "type": "TSTypeParameter", + "name": { + "type": "Identifier", + "name": "K", + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 12 + }, + "end": { + "line": 21, + "column": 13 + } + } + }, + "constraint": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "func", + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 22 + }, + "end": { + "line": 21, + "column": 26 + } + } + }, + "typeParams": { + "type": "TSTypeParameterInstantiation", + "params": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "T", + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 27 + }, + "end": { + "line": 21, + "column": 28 + } + } + }, + "loc": { + "start": { + "line": 21, + "column": 27 + }, + "end": { + "line": 21, + "column": 29 + } + } + }, + "loc": { + "start": { + "line": 21, + "column": 27 + }, + "end": { + "line": 21, + "column": 29 + } + } + }, + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "K", + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 29 + }, + "end": { + "line": 21, + "column": 30 + } + } + }, + "loc": { + "start": { + "line": 21, + "column": 29 + }, + "end": { + "line": 21, + "column": 32 + } + } + }, + "loc": { + "start": { + "line": 21, + "column": 29 + }, + "end": { + "line": 21, + "column": 32 + } + } + } + ], + "loc": { + "start": { + "line": 21, + "column": 26 + }, + "end": { + "line": 21, + "column": 32 + } + } + }, + "loc": { + "start": { + "line": 21, + "column": 22 + }, + "end": { + "line": 21, + "column": 32 + } + } + }, + "loc": { + "start": { + "line": 21, + "column": 22 + }, + "end": { + "line": 21, + "column": 32 + } + } + }, + "loc": { + "start": { + "line": 21, + "column": 12 + }, + "end": { + "line": 21, + "column": 32 + } + } + } + ], + "loc": { + "start": { + "line": 21, + "column": 9 + }, + "end": { + "line": 21, + "column": 32 + } + } + }, + "superClass": null, + "implements": [], + "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "constructor", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "constructor", + "static": false, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "constructor", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 35 + }, + "end": { + "line": 21, + "column": 35 + } + } + } + ], + "loc": { + "start": { + "line": 21, + "column": 33 + }, + "end": { + "line": 21, + "column": 35 + } + } + }, + "loc": { + "start": { + "line": 21, + "column": 1 + }, + "end": { + "line": 21, + "column": 35 + } + } + }, + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "ETSGLOBAL", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "superClass": null, + "implements": [], + "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "_$init$_", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "_$init$_", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 22, + "column": 1 + } + } +} diff --git a/ets2panda/test/parser/ets/generics_type_param_constraint_5.ets b/ets2panda/test/parser/ets/generics_type_param_constraint_5.ets new file mode 100644 index 0000000000000000000000000000000000000000..c3f94be24d3d245c70035c757a4ba5f3ee209e3f --- /dev/null +++ b/ets2panda/test/parser/ets/generics_type_param_constraint_5.ets @@ -0,0 +1,21 @@ +/* + * 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. + */ + + +interface func { + ifunc1(x: T): void; + ifunc2(x: K): void; +} +class X > {} diff --git a/ets2panda/test/parser/ets/generics_type_param_constraint_6-expected.txt b/ets2panda/test/parser/ets/generics_type_param_constraint_6-expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..e843f6940ae2947cfc2b0f1c16ab9439228c8bc8 --- /dev/null +++ b/ets2panda/test/parser/ets/generics_type_param_constraint_6-expected.txt @@ -0,0 +1,552 @@ +{ + "type": "Program", + "statements": [ + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "X", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 7 + }, + "end": { + "line": 17, + "column": 8 + } + } + }, + "typeParameters": { + "type": "TSTypeParameterDeclaration", + "params": [ + { + "type": "TSTypeParameter", + "name": { + "type": "Identifier", + "name": "K", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 10 + }, + "end": { + "line": 17, + "column": 11 + } + } + }, + "constraint": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Comparable", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 20 + }, + "end": { + "line": 17, + "column": 30 + } + } + }, + "typeParams": { + "type": "TSTypeParameterInstantiation", + "params": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "T", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 31 + }, + "end": { + "line": 17, + "column": 32 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 31 + }, + "end": { + "line": 17, + "column": 33 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 31 + }, + "end": { + "line": 17, + "column": 33 + } + } + } + ], + "loc": { + "start": { + "line": 17, + "column": 30 + }, + "end": { + "line": 17, + "column": 33 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 20 + }, + "end": { + "line": 17, + "column": 34 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 20 + }, + "end": { + "line": 17, + "column": 34 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 10 + }, + "end": { + "line": 17, + "column": 34 + } + } + }, + { + "type": "TSTypeParameter", + "name": { + "type": "Identifier", + "name": "T", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 34 + }, + "end": { + "line": 17, + "column": 35 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 34 + }, + "end": { + "line": 17, + "column": 36 + } + } + } + ], + "loc": { + "start": { + "line": 17, + "column": 9 + }, + "end": { + "line": 17, + "column": 36 + } + } + }, + "superClass": null, + "implements": [], + "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "constructor", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "constructor", + "static": false, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "constructor", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 39 + }, + "end": { + "line": 17, + "column": 39 + } + } + } + ], + "loc": { + "start": { + "line": 17, + "column": 37 + }, + "end": { + "line": 17, + "column": 39 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 1 + }, + "end": { + "line": 17, + "column": 39 + } + } + }, + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "ETSGLOBAL", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "superClass": null, + "implements": [], + "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "_$init$_", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "_$init$_", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 10 + }, + "end": { + "line": 18, + "column": 14 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 10 + }, + "end": { + "line": 18, + "column": 14 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 18, + "column": 17 + }, + "end": { + "line": 18, + "column": 19 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 14 + }, + "end": { + "line": 18, + "column": 19 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 14 + }, + "end": { + "line": 18, + "column": 19 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 1 + }, + "end": { + "line": 18, + "column": 19 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 19, + "column": 1 + } + } +} diff --git a/ets2panda/test/parser/ets/generics_type_param_constraint_6.ets b/ets2panda/test/parser/ets/generics_type_param_constraint_6.ets new file mode 100644 index 0000000000000000000000000000000000000000..34cdb626a4fd7781a27a6f02023bac2e5481163f --- /dev/null +++ b/ets2panda/test/parser/ets/generics_type_param_constraint_6.ets @@ -0,0 +1,18 @@ +/* + * 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. + */ + + +class X ,T> {} +function main() {} diff --git a/ets2panda/test/parser/ets/generics_type_param_constraint_7-expected.txt b/ets2panda/test/parser/ets/generics_type_param_constraint_7-expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..6e4e9ef1deb0939a69252b0f46d32b1237bdc2d7 --- /dev/null +++ b/ets2panda/test/parser/ets/generics_type_param_constraint_7-expected.txt @@ -0,0 +1,680 @@ +{ + "type": "Program", + "statements": [ + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "X", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 7 + }, + "end": { + "line": 17, + "column": 8 + } + } + }, + "typeParameters": { + "type": "TSTypeParameterDeclaration", + "params": [ + { + "type": "TSTypeParameter", + "name": { + "type": "Identifier", + "name": "K", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 10 + }, + "end": { + "line": 17, + "column": 11 + } + } + }, + "constraint": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Comparable", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 20 + }, + "end": { + "line": 17, + "column": 30 + } + } + }, + "typeParams": { + "type": "TSTypeParameterInstantiation", + "params": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "K", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 31 + }, + "end": { + "line": 17, + "column": 32 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 31 + }, + "end": { + "line": 17, + "column": 34 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 31 + }, + "end": { + "line": 17, + "column": 34 + } + } + } + ], + "loc": { + "start": { + "line": 17, + "column": 30 + }, + "end": { + "line": 17, + "column": 34 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 20 + }, + "end": { + "line": 17, + "column": 34 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 20 + }, + "end": { + "line": 17, + "column": 34 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 10 + }, + "end": { + "line": 17, + "column": 34 + } + } + } + ], + "loc": { + "start": { + "line": 17, + "column": 9 + }, + "end": { + "line": 17, + "column": 34 + } + } + }, + "superClass": null, + "implements": [], + "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "constructor", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "constructor", + "static": false, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "constructor", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 37 + }, + "end": { + "line": 17, + "column": 37 + } + } + } + ], + "loc": { + "start": { + "line": 17, + "column": 35 + }, + "end": { + "line": 17, + "column": 37 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 1 + }, + "end": { + "line": 17, + "column": 37 + } + } + }, + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "ETSGLOBAL", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "superClass": null, + "implements": [], + "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "_$init$_", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "_$init$_", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 10 + }, + "end": { + "line": 18, + "column": 14 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 10 + }, + "end": { + "line": 18, + "column": 14 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "myCharClass", + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 11 + }, + "end": { + "line": 19, + "column": 22 + } + } + }, + "init": { + "type": "ETSNewClassInstanceExpression", + "typeReference": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "X", + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 29 + }, + "end": { + "line": 19, + "column": 30 + } + } + }, + "typeParams": { + "type": "TSTypeParameterInstantiation", + "params": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Char", + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 31 + }, + "end": { + "line": 19, + "column": 35 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 31 + }, + "end": { + "line": 19, + "column": 36 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 31 + }, + "end": { + "line": 19, + "column": 36 + } + } + } + ], + "loc": { + "start": { + "line": 19, + "column": 30 + }, + "end": { + "line": 19, + "column": 36 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 29 + }, + "end": { + "line": 19, + "column": 37 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 29 + }, + "end": { + "line": 19, + "column": 37 + } + } + }, + "arguments": [], + "loc": { + "start": { + "line": 19, + "column": 25 + }, + "end": { + "line": 19, + "column": 39 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 11 + }, + "end": { + "line": 19, + "column": 39 + } + } + } + ], + "kind": "const", + "loc": { + "start": { + "line": 19, + "column": 5 + }, + "end": { + "line": 19, + "column": 39 + } + } + } + ], + "loc": { + "start": { + "line": 18, + "column": 16 + }, + "end": { + "line": 20, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 14 + }, + "end": { + "line": 20, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 14 + }, + "end": { + "line": 20, + "column": 2 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 1 + }, + "end": { + "line": 20, + "column": 2 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 21, + "column": 1 + } + } +} diff --git a/ets2panda/test/parser/ets/generics_type_param_constraint_7.ets b/ets2panda/test/parser/ets/generics_type_param_constraint_7.ets new file mode 100644 index 0000000000000000000000000000000000000000..5144fef006c5a3aeb8a63f5c026f496d87120dce --- /dev/null +++ b/ets2panda/test/parser/ets/generics_type_param_constraint_7.ets @@ -0,0 +1,20 @@ +/* + * 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. + */ + + +class X > {} +function main(){ + const myCharClass = new X(); +} diff --git a/ets2panda/test/parser/ets/generics_type_param_constraint_8-expected.txt b/ets2panda/test/parser/ets/generics_type_param_constraint_8-expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..cedf6ac5edb651aad900d73b1e46f789874a6e0e --- /dev/null +++ b/ets2panda/test/parser/ets/generics_type_param_constraint_8-expected.txt @@ -0,0 +1,750 @@ +{ + "type": "Program", + "statements": [ + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "X", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 7 + }, + "end": { + "line": 17, + "column": 8 + } + } + }, + "typeParameters": { + "type": "TSTypeParameterDeclaration", + "params": [ + { + "type": "TSTypeParameter", + "name": { + "type": "Identifier", + "name": "K", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 10 + }, + "end": { + "line": 17, + "column": 11 + } + } + }, + "constraint": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Comparable", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 20 + }, + "end": { + "line": 17, + "column": 30 + } + } + }, + "typeParams": { + "type": "TSTypeParameterInstantiation", + "params": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "T", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 31 + }, + "end": { + "line": 17, + "column": 32 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 31 + }, + "end": { + "line": 17, + "column": 33 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 31 + }, + "end": { + "line": 17, + "column": 33 + } + } + } + ], + "loc": { + "start": { + "line": 17, + "column": 30 + }, + "end": { + "line": 17, + "column": 33 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 20 + }, + "end": { + "line": 17, + "column": 34 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 20 + }, + "end": { + "line": 17, + "column": 34 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 10 + }, + "end": { + "line": 17, + "column": 34 + } + } + }, + { + "type": "TSTypeParameter", + "name": { + "type": "Identifier", + "name": "T", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 34 + }, + "end": { + "line": 17, + "column": 35 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 34 + }, + "end": { + "line": 17, + "column": 36 + } + } + } + ], + "loc": { + "start": { + "line": 17, + "column": 9 + }, + "end": { + "line": 17, + "column": 36 + } + } + }, + "superClass": null, + "implements": [], + "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "constructor", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "constructor", + "static": false, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "constructor", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 39 + }, + "end": { + "line": 17, + "column": 39 + } + } + } + ], + "loc": { + "start": { + "line": 17, + "column": 37 + }, + "end": { + "line": 17, + "column": 39 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 1 + }, + "end": { + "line": 17, + "column": 39 + } + } + }, + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "ETSGLOBAL", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "superClass": null, + "implements": [], + "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "_$init$_", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "_$init$_", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 10 + }, + "end": { + "line": 18, + "column": 14 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 10 + }, + "end": { + "line": 18, + "column": 14 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "myCharClass", + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 11 + }, + "end": { + "line": 19, + "column": 22 + } + } + }, + "init": { + "type": "ETSNewClassInstanceExpression", + "typeReference": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "X", + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 29 + }, + "end": { + "line": 19, + "column": 30 + } + } + }, + "typeParams": { + "type": "TSTypeParameterInstantiation", + "params": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Char", + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 31 + }, + "end": { + "line": 19, + "column": 35 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 31 + }, + "end": { + "line": 19, + "column": 36 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 31 + }, + "end": { + "line": 19, + "column": 36 + } + } + }, + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "String", + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 36 + }, + "end": { + "line": 19, + "column": 42 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 36 + }, + "end": { + "line": 19, + "column": 43 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 36 + }, + "end": { + "line": 19, + "column": 43 + } + } + } + ], + "loc": { + "start": { + "line": 19, + "column": 30 + }, + "end": { + "line": 19, + "column": 43 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 29 + }, + "end": { + "line": 19, + "column": 44 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 29 + }, + "end": { + "line": 19, + "column": 44 + } + } + }, + "arguments": [], + "loc": { + "start": { + "line": 19, + "column": 25 + }, + "end": { + "line": 19, + "column": 46 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 11 + }, + "end": { + "line": 19, + "column": 46 + } + } + } + ], + "kind": "const", + "loc": { + "start": { + "line": 19, + "column": 5 + }, + "end": { + "line": 19, + "column": 46 + } + } + } + ], + "loc": { + "start": { + "line": 18, + "column": 16 + }, + "end": { + "line": 20, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 14 + }, + "end": { + "line": 20, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 14 + }, + "end": { + "line": 20, + "column": 2 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 1 + }, + "end": { + "line": 20, + "column": 2 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 21, + "column": 1 + } + } +} +TypeError: Type 'Char' is not assignable to constraint type 'Comparable'. [generics_type_param_constraint_8.ets:19:31] diff --git a/ets2panda/test/parser/ets/generics_type_param_constraint_8.ets b/ets2panda/test/parser/ets/generics_type_param_constraint_8.ets new file mode 100644 index 0000000000000000000000000000000000000000..75d51601cc589f6793877cbefaf8ec887d70a4c8 --- /dev/null +++ b/ets2panda/test/parser/ets/generics_type_param_constraint_8.ets @@ -0,0 +1,20 @@ +/* + * 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. + */ + + +class X ,T> {} +function main(){ + const myCharClass = new X(); +} diff --git a/ets2panda/test/parser/ets/generics_type_param_constraint_9-expected.txt b/ets2panda/test/parser/ets/generics_type_param_constraint_9-expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..51f8058c292d76263a4fe008edbf2bc4fdbae3f5 --- /dev/null +++ b/ets2panda/test/parser/ets/generics_type_param_constraint_9-expected.txt @@ -0,0 +1,1080 @@ +{ + "type": "Program", + "statements": [ + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "Base", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 7 + }, + "end": { + "line": 17, + "column": 11 + } + } + }, + "typeParameters": { + "type": "TSTypeParameterDeclaration", + "params": [ + { + "type": "TSTypeParameter", + "name": { + "type": "Identifier", + "name": "T", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 12 + }, + "end": { + "line": 17, + "column": 13 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 12 + }, + "end": { + "line": 17, + "column": 14 + } + } + } + ], + "loc": { + "start": { + "line": 17, + "column": 11 + }, + "end": { + "line": 17, + "column": 14 + } + } + }, + "superClass": null, + "implements": [], + "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "constructor", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "constructor", + "static": false, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "constructor", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 18 + }, + "end": { + "line": 17, + "column": 18 + } + } + } + ], + "loc": { + "start": { + "line": 17, + "column": 15 + }, + "end": { + "line": 17, + "column": 18 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 1 + }, + "end": { + "line": 17, + "column": 18 + } + } + }, + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "Derived", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 7 + }, + "end": { + "line": 18, + "column": 14 + } + } + }, + "superClass": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Base", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 23 + }, + "end": { + "line": 18, + "column": 27 + } + } + }, + "typeParams": { + "type": "TSTypeParameterInstantiation", + "params": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Derived", + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 28 + }, + "end": { + "line": 18, + "column": 35 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 28 + }, + "end": { + "line": 18, + "column": 36 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 28 + }, + "end": { + "line": 18, + "column": 36 + } + } + } + ], + "loc": { + "start": { + "line": 18, + "column": 27 + }, + "end": { + "line": 18, + "column": 36 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 23 + }, + "end": { + "line": 18, + "column": 38 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 23 + }, + "end": { + "line": 18, + "column": 38 + } + } + }, + "implements": [], + "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "constructor", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "constructor", + "static": false, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "constructor", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 18, + "column": 40 + }, + "end": { + "line": 18, + "column": 40 + } + } + } + ], + "loc": { + "start": { + "line": 18, + "column": 37 + }, + "end": { + "line": 18, + "column": 40 + } + } + }, + "loc": { + "start": { + "line": 18, + "column": 1 + }, + "end": { + "line": 18, + "column": 40 + } + } + }, + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "G", + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 7 + }, + "end": { + "line": 19, + "column": 8 + } + } + }, + "typeParameters": { + "type": "TSTypeParameterDeclaration", + "params": [ + { + "type": "TSTypeParameter", + "name": { + "type": "Identifier", + "name": "T", + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 9 + }, + "end": { + "line": 19, + "column": 10 + } + } + }, + "constraint": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Base", + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 19 + }, + "end": { + "line": 19, + "column": 23 + } + } + }, + "typeParams": { + "type": "TSTypeParameterInstantiation", + "params": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "T", + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 24 + }, + "end": { + "line": 19, + "column": 25 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 24 + }, + "end": { + "line": 19, + "column": 27 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 24 + }, + "end": { + "line": 19, + "column": 27 + } + } + } + ], + "loc": { + "start": { + "line": 19, + "column": 23 + }, + "end": { + "line": 19, + "column": 27 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 19 + }, + "end": { + "line": 19, + "column": 27 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 19 + }, + "end": { + "line": 19, + "column": 27 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 9 + }, + "end": { + "line": 19, + "column": 27 + } + } + } + ], + "loc": { + "start": { + "line": 19, + "column": 8 + }, + "end": { + "line": 19, + "column": 27 + } + } + }, + "superClass": null, + "implements": [], + "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "constructor", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "constructor", + "static": false, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "constructor", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 31 + }, + "end": { + "line": 19, + "column": 31 + } + } + } + ], + "loc": { + "start": { + "line": 19, + "column": 28 + }, + "end": { + "line": 19, + "column": 31 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 1 + }, + "end": { + "line": 19, + "column": 31 + } + } + }, + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "ETSGLOBAL", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "superClass": null, + "implements": [], + "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "_$init$_", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "_$init$_", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 20, + "column": 10 + }, + "end": { + "line": 20, + "column": 14 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 20, + "column": 10 + }, + "end": { + "line": 20, + "column": 14 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "VariableDeclaration", + "declarations": [ + { + "type": "VariableDeclarator", + "id": { + "type": "Identifier", + "name": "y", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "G", + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 12 + }, + "end": { + "line": 21, + "column": 13 + } + } + }, + "typeParams": { + "type": "TSTypeParameterInstantiation", + "params": [ + { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "Derived", + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 14 + }, + "end": { + "line": 21, + "column": 21 + } + } + }, + "loc": { + "start": { + "line": 21, + "column": 14 + }, + "end": { + "line": 21, + "column": 22 + } + } + }, + "loc": { + "start": { + "line": 21, + "column": 14 + }, + "end": { + "line": 21, + "column": 22 + } + } + } + ], + "loc": { + "start": { + "line": 21, + "column": 13 + }, + "end": { + "line": 21, + "column": 22 + } + } + }, + "loc": { + "start": { + "line": 21, + "column": 12 + }, + "end": { + "line": 22, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 21, + "column": 12 + }, + "end": { + "line": 22, + "column": 2 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 21, + "column": 9 + }, + "end": { + "line": 21, + "column": 10 + } + } + }, + "init": null, + "loc": { + "start": { + "line": 21, + "column": 9 + }, + "end": { + "line": 21, + "column": 10 + } + } + } + ], + "kind": "let", + "loc": { + "start": { + "line": 21, + "column": 5 + }, + "end": { + "line": 21, + "column": 10 + } + } + } + ], + "loc": { + "start": { + "line": 20, + "column": 16 + }, + "end": { + "line": 22, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 14 + }, + "end": { + "line": 22, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 14 + }, + "end": { + "line": 22, + "column": 2 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 20, + "column": 1 + }, + "end": { + "line": 22, + "column": 2 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 23, + "column": 1 + } + } +} diff --git a/ets2panda/test/parser/ets/generics_type_param_constraint_9.ets b/ets2panda/test/parser/ets/generics_type_param_constraint_9.ets new file mode 100644 index 0000000000000000000000000000000000000000..b210876fe1ae353ef7dbea4f0958f55c973437a2 --- /dev/null +++ b/ets2panda/test/parser/ets/generics_type_param_constraint_9.ets @@ -0,0 +1,22 @@ +/* + * 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. + */ + + +class Base { } +class Derived extends Base { } +class G> { } +function main(){ + let y: G +} diff --git a/ets2panda/test/parser/ets/getter_native-expected.txt b/ets2panda/test/parser/ets/getter_native-expected.txt index 51137c86a61adabd0385189fa1bcc65993b3e95c..707c2e0c1e51639dbff40384c94e9d624469bdc8 100644 --- a/ets2panda/test/parser/ets/getter_native-expected.txt +++ b/ets2panda/test/parser/ets/getter_native-expected.txt @@ -62,12 +62,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 17, + "column": 13 }, "end": { - "line": 1, - "column": 1 + "line": 17, + "column": 24 } } }, diff --git a/ets2panda/test/parser/ets/getter_setter_access_modifiers-expected.txt b/ets2panda/test/parser/ets/getter_setter_access_modifiers-expected.txt index 2ee593916541e3b04478b472877c837761d8d1ad..3412eacfea5a68acaf1a45299365245c543af3f4 100644 --- a/ets2panda/test/parser/ets/getter_setter_access_modifiers-expected.txt +++ b/ets2panda/test/parser/ets/getter_setter_access_modifiers-expected.txt @@ -62,12 +62,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 17, + "column": 13 }, "end": { - "line": 1, - "column": 1 + "line": 17, + "column": 22 } } }, @@ -111,12 +111,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 18, + "column": 13 }, "end": { - "line": 1, - "column": 1 + "line": 18, + "column": 24 } } }, @@ -769,12 +769,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 27, + "column": 13 }, "end": { - "line": 1, - "column": 1 + "line": 27, + "column": 22 } } }, @@ -818,12 +818,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 28, + "column": 13 }, "end": { - "line": 1, - "column": 1 + "line": 28, + "column": 24 } } }, diff --git a/ets2panda/test/parser/ets/getter_setter_access_modifiers_2-expected.txt b/ets2panda/test/parser/ets/getter_setter_access_modifiers_2-expected.txt index f4338c189264a1da8aab028e2b93d0e9fb727c55..ed873fe6929caabb985252186532009293bcd939 100644 --- a/ets2panda/test/parser/ets/getter_setter_access_modifiers_2-expected.txt +++ b/ets2panda/test/parser/ets/getter_setter_access_modifiers_2-expected.txt @@ -62,12 +62,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 17, + "column": 13 }, "end": { - "line": 1, - "column": 1 + "line": 17, + "column": 23 } } }, @@ -111,12 +111,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 18, + "column": 13 }, "end": { - "line": 1, - "column": 1 + "line": 18, + "column": 24 } } }, @@ -765,12 +765,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 30, + "column": 13 }, "end": { - "line": 1, - "column": 1 + "line": 30, + "column": 23 } } }, @@ -814,12 +814,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 31, + "column": 13 }, "end": { - "line": 1, - "column": 1 + "line": 31, + "column": 24 } } }, diff --git a/ets2panda/test/parser/ets/global_const_vars3-expected.txt b/ets2panda/test/parser/ets/global_const_vars3-expected.txt index e04656ffbcb0632b906f3c1e08779d294f3ff7e0..e2c12eaa49798fdd8480024812da446e5f294a71 100644 --- a/ets2panda/test/parser/ets/global_const_vars3-expected.txt +++ b/ets2panda/test/parser/ets/global_const_vars3-expected.txt @@ -90,12 +90,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 20, + "column": 21 }, "end": { - "line": 1, - "column": 1 + "line": 20, + "column": 32 } } }, @@ -646,12 +646,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 16, + "column": 7 }, "end": { - "line": 1, - "column": 1 + "line": 16, + "column": 17 } } }, @@ -778,12 +778,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 17, + "column": 7 }, "end": { - "line": 1, - "column": 1 + "line": 17, + "column": 30 } } } diff --git a/ets2panda/test/parser/ets/global_const_vars4-expected.txt b/ets2panda/test/parser/ets/global_const_vars4-expected.txt index 256ab597dba491525248d5785704f8f19a9478d5..8d67d403e87a8e200ea9088362ca8a568d1e9889 100644 --- a/ets2panda/test/parser/ets/global_const_vars4-expected.txt +++ b/ets2panda/test/parser/ets/global_const_vars4-expected.txt @@ -145,12 +145,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 17, + "column": 21 }, "end": { - "line": 1, - "column": 1 + "line": 17, + "column": 45 } } }, @@ -889,4 +889,4 @@ } } } -TypeError: Cannot assign to a constant variable date [global_const_vars4.ets:1:1] +TypeError: Cannot assign to a constant variable date [global_const_vars4.ets:17:21] diff --git a/ets2panda/test/parser/ets/identifier-expected.txt b/ets2panda/test/parser/ets/identifier-expected.txt index ffe91080804c1082ba423295668914b2efd6a291..79101bcf96800d89de1a50e9199225cedaac2967 100644 --- a/ets2panda/test/parser/ets/identifier-expected.txt +++ b/ets2panda/test/parser/ets/identifier-expected.txt @@ -106,23 +106,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 17, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 17, + "column": 26 } } }, "loc": { "start": { - "line": 1, + "line": 17, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 17, + "column": 27 } } }, @@ -162,23 +162,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 18, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 18, + "column": 31 } } }, "loc": { "start": { - "line": 1, + "line": 18, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 18, + "column": 32 } } }, @@ -218,23 +218,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 19, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 19, + "column": 27 } } }, "loc": { "start": { - "line": 1, + "line": 19, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 19, + "column": 28 } } } @@ -325,12 +325,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 17, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 17, + "column": 22 } } }, @@ -374,12 +374,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 18, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 18, + "column": 27 } } }, @@ -423,12 +423,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 19, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 19, + "column": 23 } } } diff --git a/ets2panda/test/parser/ets/import_tests/diamond/test2-expected.txt b/ets2panda/test/parser/ets/import_tests/diamond/test2-expected.txt index beebde9f92c0b04f55b1d6501e1b1b159a9530f5..020e5e183aa1dbcfcab384d8c6d778ab10b19a39 100644 --- a/ets2panda/test/parser/ets/import_tests/diamond/test2-expected.txt +++ b/ets2panda/test/parser/ets/import_tests/diamond/test2-expected.txt @@ -179,23 +179,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 18, + "column": 12 }, "end": { - "line": 1, - "column": 1 + "line": 18, + "column": 21 } } }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 18, + "column": 8 }, "end": { - "line": 1, - "column": 1 + "line": 18, + "column": 22 } } } @@ -288,12 +288,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 18, + "column": 12 }, "end": { - "line": 1, - "column": 1 + "line": 18, + "column": 21 } } } diff --git a/ets2panda/test/parser/ets/import_tests/diamond/test3-expected.txt b/ets2panda/test/parser/ets/import_tests/diamond/test3-expected.txt index 64d88326d9155dcd267df70c0dd0c750b559273d..41d64f40ed99bea9ccd0c10a920cb18aa1ab0606 100644 --- a/ets2panda/test/parser/ets/import_tests/diamond/test3-expected.txt +++ b/ets2panda/test/parser/ets/import_tests/diamond/test3-expected.txt @@ -179,23 +179,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 18, + "column": 12 }, "end": { - "line": 1, - "column": 1 + "line": 18, + "column": 21 } } }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 18, + "column": 8 }, "end": { - "line": 1, - "column": 1 + "line": 18, + "column": 22 } } } @@ -288,12 +288,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 18, + "column": 12 }, "end": { - "line": 1, - "column": 1 + "line": 18, + "column": 21 } } } diff --git a/ets2panda/test/parser/ets/import_tests/diamond/test4-expected.txt b/ets2panda/test/parser/ets/import_tests/diamond/test4-expected.txt index 953043cdc28dc0c38dc0313fc693867501509c1f..49fc3015d82ec7acb23970b392f82ebe012f81e4 100644 --- a/ets2panda/test/parser/ets/import_tests/diamond/test4-expected.txt +++ b/ets2panda/test/parser/ets/import_tests/diamond/test4-expected.txt @@ -106,23 +106,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 16, + "column": 12 }, "end": { - "line": 1, - "column": 1 + "line": 16, + "column": 19 } } }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 16, + "column": 8 }, "end": { - "line": 1, - "column": 1 + "line": 16, + "column": 20 } } } @@ -214,12 +214,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 16, + "column": 12 }, "end": { - "line": 1, - "column": 1 + "line": 16, + "column": 19 } } } diff --git a/ets2panda/test/parser/ets/import_tests/import_alias/export-expected.txt b/ets2panda/test/parser/ets/import_tests/import_alias/export-expected.txt index 7b824f2ff048cb9d101d5e9e35c121531704cc74..6f65df047697c0e17df741ac22d048b7e86750ad 100644 --- a/ets2panda/test/parser/ets/import_tests/import_alias/export-expected.txt +++ b/ets2panda/test/parser/ets/import_tests/import_alias/export-expected.txt @@ -568,23 +568,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 28, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 28, + "column": 14 } } }, "loc": { "start": { - "line": 1, + "line": 28, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 28, + "column": 15 } } }, @@ -624,23 +624,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 30, + "column": 12 }, "end": { - "line": 1, - "column": 1 + "line": 30, + "column": 21 } } }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 30, + "column": 8 }, "end": { - "line": 1, - "column": 1 + "line": 30, + "column": 22 } } } @@ -1002,12 +1002,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 28, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 28, + "column": 14 } } }, @@ -1052,12 +1052,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 30, + "column": 12 }, "end": { - "line": 1, - "column": 1 + "line": 30, + "column": 21 } } } diff --git a/ets2panda/test/parser/ets/import_tests/import_all-expected.txt b/ets2panda/test/parser/ets/import_tests/import_all-expected.txt index c8d0f42b5e41cd6e56583df841617ad486a60803..a05f2eaec9c5335ddc4a9a6d7c354587f81b8448 100755 --- a/ets2panda/test/parser/ets/import_tests/import_all-expected.txt +++ b/ets2panda/test/parser/ets/import_tests/import_all-expected.txt @@ -252,23 +252,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 19, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 19, + "column": 46 } } }, "loc": { "start": { - "line": 1, + "line": 19, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 19, + "column": 47 } } }, @@ -340,23 +340,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 20, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 20, + "column": 45 } } }, "loc": { "start": { - "line": 1, + "line": 20, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 20, + "column": 46 } } }, @@ -427,23 +427,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 21, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 21, + "column": 48 } } }, "loc": { "start": { - "line": 1, + "line": 21, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 21, + "column": 49 } } } @@ -567,12 +567,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 19, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 19, + "column": 46 } } }, @@ -649,12 +649,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 20, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 20, + "column": 45 } } }, @@ -730,12 +730,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 21, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 21, + "column": 48 } } } diff --git a/ets2panda/test/parser/ets/import_tests/import_all_alias_1-expected.txt b/ets2panda/test/parser/ets/import_tests/import_all_alias_1-expected.txt index aa4820bf60d0775cc2d8c378fd129d5f1f140729..e105d8c13c3fde8e3d43cebdb57dc782431d5609 100644 --- a/ets2panda/test/parser/ets/import_tests/import_all_alias_1-expected.txt +++ b/ets2panda/test/parser/ets/import_tests/import_all_alias_1-expected.txt @@ -255,23 +255,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 18, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 18, + "column": 56 } } }, "loc": { "start": { - "line": 1, + "line": 18, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 18, + "column": 57 } } }, @@ -403,23 +403,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 19, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 19, + "column": 55 } } }, "loc": { "start": { - "line": 1, + "line": 19, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 19, + "column": 56 } } } @@ -603,12 +603,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 18, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 18, + "column": 56 } } }, @@ -745,12 +745,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 19, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 19, + "column": 55 } } } diff --git a/ets2panda/test/parser/ets/import_tests/import_all_alias_2-expected.txt b/ets2panda/test/parser/ets/import_tests/import_all_alias_2-expected.txt index 996057b92504c02391e37b37e25c0d7abe60ca4c..18b018cd704c49b55d3b2850048acc8fb99099d5 100755 --- a/ets2panda/test/parser/ets/import_tests/import_all_alias_2-expected.txt +++ b/ets2panda/test/parser/ets/import_tests/import_all_alias_2-expected.txt @@ -195,23 +195,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 20, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 20, + "column": 46 } } }, "loc": { "start": { - "line": 1, + "line": 20, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 20, + "column": 47 } } } @@ -335,12 +335,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 20, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 20, + "column": 46 } } } diff --git a/ets2panda/test/parser/ets/import_tests/import_diff_paths-expected.txt b/ets2panda/test/parser/ets/import_tests/import_diff_paths-expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..36509b55153e8311516dca72e239119504b13963 --- /dev/null +++ b/ets2panda/test/parser/ets/import_tests/import_diff_paths-expected.txt @@ -0,0 +1,491 @@ +{ + "type": "Program", + "statements": [ + { + "type": "ImportDeclaration", + "source": { + "type": "StringLiteral", + "value": "./modules", + "loc": { + "start": { + "line": 16, + "column": 19 + }, + "end": { + "line": 16, + "column": 40 + } + } + }, + "specifiers": [ + { + "type": "ImportSpecifier", + "local": { + "type": "Identifier", + "name": "C", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 10 + }, + "end": { + "line": 16, + "column": 11 + } + } + }, + "imported": { + "type": "Identifier", + "name": "C", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 10 + }, + "end": { + "line": 16, + "column": 11 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 10 + }, + "end": { + "line": 16, + "column": 11 + } + } + } + ], + "loc": { + "start": { + "line": 16, + "column": 1 + }, + "end": { + "line": 16, + "column": 40 + } + } + }, + { + "type": "ImportDeclaration", + "source": { + "type": "StringLiteral", + "value": "./modules", + "loc": { + "start": { + "line": 17, + "column": 19 + }, + "end": { + "line": 17, + "column": 40 + } + } + }, + "specifiers": [ + { + "type": "ImportSpecifier", + "local": { + "type": "Identifier", + "name": "f", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 10 + }, + "end": { + "line": 17, + "column": 11 + } + } + }, + "imported": { + "type": "Identifier", + "name": "f", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 10 + }, + "end": { + "line": 17, + "column": 11 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 10 + }, + "end": { + "line": 17, + "column": 11 + } + } + } + ], + "loc": { + "start": { + "line": 17, + "column": 1 + }, + "end": { + "line": 17, + "column": 40 + } + } + }, + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "ETSGLOBAL", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "superClass": null, + "implements": [], + "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "_$init$_", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "_$init$_", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 10 + }, + "end": { + "line": 19, + "column": 14 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "main", + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 10 + }, + "end": { + "line": 19, + "column": 14 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [ + { + "type": "ExpressionStatement", + "expression": { + "type": "CallExpression", + "callee": { + "type": "Identifier", + "name": "f", + "decorators": [], + "loc": { + "start": { + "line": 20, + "column": 5 + }, + "end": { + "line": 20, + "column": 6 + } + } + }, + "arguments": [ + { + "type": "ETSNewClassInstanceExpression", + "typeReference": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "C", + "decorators": [], + "loc": { + "start": { + "line": 20, + "column": 11 + }, + "end": { + "line": 20, + "column": 12 + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 11 + }, + "end": { + "line": 20, + "column": 13 + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 11 + }, + "end": { + "line": 20, + "column": 13 + } + } + }, + "arguments": [], + "loc": { + "start": { + "line": 20, + "column": 7 + }, + "end": { + "line": 20, + "column": 15 + } + } + } + ], + "optional": false, + "loc": { + "start": { + "line": 20, + "column": 5 + }, + "end": { + "line": 20, + "column": 15 + } + } + }, + "loc": { + "start": { + "line": 20, + "column": 5 + }, + "end": { + "line": 20, + "column": 16 + } + } + } + ], + "loc": { + "start": { + "line": 19, + "column": 17 + }, + "end": { + "line": 21, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 14 + }, + "end": { + "line": 21, + "column": 2 + } + } + }, + "loc": { + "start": { + "line": 19, + "column": 14 + }, + "end": { + "line": 21, + "column": 2 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 19, + "column": 1 + }, + "end": { + "line": 21, + "column": 2 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 21, + "column": 2 + } + } +} diff --git a/ets2panda/test/parser/ets/import_tests/import_diff_paths.ets b/ets2panda/test/parser/ets/import_tests/import_diff_paths.ets new file mode 100644 index 0000000000000000000000000000000000000000..b768dbc1fc517af0a86ca3eb0b19f77873d6b0cf --- /dev/null +++ b/ets2panda/test/parser/ets/import_tests/import_diff_paths.ets @@ -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. + */ + +import { C } from "./modules/test_lib1" +import { f } from "./modules/test_lib2" + +function main() { + f(new C()); +} \ No newline at end of file diff --git a/ets2panda/test/parser/ets/import_tests/import_name_1-expected.txt b/ets2panda/test/parser/ets/import_tests/import_name_1-expected.txt index eb9dd09cbc92d5d265f6fd02ab8564ab9d122067..77c11005f850e46bb01176d0824fede31f297e9c 100755 --- a/ets2panda/test/parser/ets/import_tests/import_name_1-expected.txt +++ b/ets2panda/test/parser/ets/import_tests/import_name_1-expected.txt @@ -296,23 +296,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 18, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 18, + "column": 46 } } }, "loc": { "start": { - "line": 1, + "line": 18, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 18, + "column": 47 } } }, @@ -384,23 +384,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 19, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 19, + "column": 45 } } }, "loc": { "start": { - "line": 1, + "line": 19, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 19, + "column": 45 } } } @@ -524,12 +524,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 18, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 18, + "column": 46 } } }, @@ -606,12 +606,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 19, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 19, + "column": 45 } } } diff --git a/ets2panda/test/parser/ets/import_tests/import_name_2-expected.txt b/ets2panda/test/parser/ets/import_tests/import_name_2-expected.txt index 32d4a693e6a9bf9f3661d40355e607305f69b4d4..4ce97a3c9bc8f6c6ea014f36e35c67458b7b276e 100755 --- a/ets2panda/test/parser/ets/import_tests/import_name_2-expected.txt +++ b/ets2panda/test/parser/ets/import_tests/import_name_2-expected.txt @@ -253,23 +253,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 19, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 19, + "column": 17 } } }, "loc": { "start": { - "line": 1, + "line": 19, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 19, + "column": 18 } } } @@ -393,12 +393,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 19, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 19, + "column": 17 } } } diff --git a/ets2panda/test/parser/ets/import_tests/import_name_alias_1-expected.txt b/ets2panda/test/parser/ets/import_tests/import_name_alias_1-expected.txt index e2ec55d6b007e5439c8eed0298118ea3cda05fc5..8192941368ea24f6f7720624dde7df81d27bece2 100755 --- a/ets2panda/test/parser/ets/import_tests/import_name_alias_1-expected.txt +++ b/ets2panda/test/parser/ets/import_tests/import_name_alias_1-expected.txt @@ -296,23 +296,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 18, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 18, + "column": 46 } } }, "loc": { "start": { - "line": 1, + "line": 18, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 18, + "column": 47 } } }, @@ -384,23 +384,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 19, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 19, + "column": 45 } } }, "loc": { "start": { - "line": 1, + "line": 19, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 19, + "column": 46 } } } @@ -524,12 +524,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 18, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 18, + "column": 46 } } }, @@ -606,12 +606,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 19, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 19, + "column": 45 } } } diff --git a/ets2panda/test/parser/ets/import_tests/import_name_alias_2-expected.txt b/ets2panda/test/parser/ets/import_tests/import_name_alias_2-expected.txt index 55cc9b92604e9d3ae8135c786f80dc1078b33be1..6c17455873bca42a862bb6654b85a19a7df8d4dc 100755 --- a/ets2panda/test/parser/ets/import_tests/import_name_alias_2-expected.txt +++ b/ets2panda/test/parser/ets/import_tests/import_name_alias_2-expected.txt @@ -253,23 +253,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 19, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 19, + "column": 17 } } }, "loc": { "start": { - "line": 1, + "line": 19, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 19, + "column": 18 } } } @@ -393,12 +393,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 19, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 19, + "column": 17 } } } diff --git a/ets2panda/test/parser/ets/import_tests/import_relative_path-expected.txt b/ets2panda/test/parser/ets/import_tests/import_relative_path-expected.txt index 8d440877dc15a8db81d0ba3b32511450728b6e4c..c99810cb09868251e1b25b32ac77b981cfe998d0 100755 --- a/ets2panda/test/parser/ets/import_tests/import_relative_path-expected.txt +++ b/ets2panda/test/parser/ets/import_tests/import_relative_path-expected.txt @@ -195,23 +195,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 18, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 18, + "column": 46 } } }, "loc": { "start": { - "line": 1, + "line": 18, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 18, + "column": 47 } } }, @@ -283,23 +283,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 19, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 19, + "column": 45 } } }, "loc": { "start": { - "line": 1, + "line": 19, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 19, + "column": 46 } } } @@ -423,12 +423,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 18, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 18, + "column": 46 } } }, @@ -505,12 +505,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 19, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 19, + "column": 45 } } } diff --git a/ets2panda/test/parser/ets/import_tests/import_several_1-expected.txt b/ets2panda/test/parser/ets/import_tests/import_several_1-expected.txt index 8214b5801d6d26b4eb8db16df8f561db06ca4a34..7ceeda97255e793639dafa3e9ea26440a915fc1a 100755 --- a/ets2panda/test/parser/ets/import_tests/import_several_1-expected.txt +++ b/ets2panda/test/parser/ets/import_tests/import_several_1-expected.txt @@ -354,23 +354,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 20, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 20, + "column": 46 } } }, "loc": { "start": { - "line": 1, + "line": 20, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 20, + "column": 47 } } }, @@ -442,23 +442,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 21, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 21, + "column": 45 } } }, "loc": { "start": { - "line": 1, + "line": 21, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 21, + "column": 46 } } } @@ -582,12 +582,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 20, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 20, + "column": 46 } } }, @@ -664,12 +664,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 21, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 21, + "column": 45 } } } diff --git a/ets2panda/test/parser/ets/import_tests/import_several_2-expected.txt b/ets2panda/test/parser/ets/import_tests/import_several_2-expected.txt index 359cefafad21243794d99dc7c48165b343dcaa8b..a1118839c3ec9252ace25799812f2ba32ca32d5e 100755 --- a/ets2panda/test/parser/ets/import_tests/import_several_2-expected.txt +++ b/ets2panda/test/parser/ets/import_tests/import_several_2-expected.txt @@ -252,23 +252,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 19, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 19, + "column": 18 } } }, "loc": { "start": { - "line": 1, + "line": 19, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 19, + "column": 19 } } } @@ -391,12 +391,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 19, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 19, + "column": 18 } } } diff --git a/ets2panda/test/parser/ets/import_tests/import_several_3-expected.txt b/ets2panda/test/parser/ets/import_tests/import_several_3-expected.txt index d3ab1b4c34ed9851d9438ab8e2ae3f111832bef5..bb89ff35a9cc410bace3f4991833478b5450fbf3 100755 --- a/ets2panda/test/parser/ets/import_tests/import_several_3-expected.txt +++ b/ets2panda/test/parser/ets/import_tests/import_several_3-expected.txt @@ -267,23 +267,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 19, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 19, + "column": 46 } } }, "loc": { "start": { - "line": 1, + "line": 19, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 19, + "column": 47 } } }, @@ -355,23 +355,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 20, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 20, + "column": 45 } } }, "loc": { "start": { - "line": 1, + "line": 20, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 20, + "column": 46 } } } @@ -495,12 +495,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 19, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 19, + "column": 46 } } }, @@ -577,12 +577,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 20, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 20, + "column": 45 } } } diff --git a/ets2panda/test/parser/ets/import_tests/import_several_4-expected.txt b/ets2panda/test/parser/ets/import_tests/import_several_4-expected.txt index 89ec61fe08d5433199b5a25bafeb05ba2565ccd3..614c31accbe1145a796a297de4be41908887f17d 100644 --- a/ets2panda/test/parser/ets/import_tests/import_several_4-expected.txt +++ b/ets2panda/test/parser/ets/import_tests/import_several_4-expected.txt @@ -297,23 +297,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 19, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 19, + "column": 51 } } }, "loc": { "start": { - "line": 1, + "line": 19, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 19, + "column": 52 } } }, @@ -445,23 +445,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 20, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 20, + "column": 55 } } }, "loc": { "start": { - "line": 1, + "line": 20, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 20, + "column": 56 } } } @@ -615,12 +615,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 19, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 19, + "column": 51 } } }, @@ -757,12 +757,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 20, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 20, + "column": 55 } } } diff --git a/ets2panda/test/parser/ets/import_tests/import_several_5-expected.txt b/ets2panda/test/parser/ets/import_tests/import_several_5-expected.txt index 95e2b9ca99e899d603e9c8bb410372d23921b9e6..3d619efbbe134e3b0c9ea4606b046b17bddc6a98 100755 --- a/ets2panda/test/parser/ets/import_tests/import_several_5-expected.txt +++ b/ets2panda/test/parser/ets/import_tests/import_several_5-expected.txt @@ -267,23 +267,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 19, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 19, + "column": 46 } } }, "loc": { "start": { - "line": 1, + "line": 19, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 19, + "column": 47 } } }, @@ -355,23 +355,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 20, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 20, + "column": 45 } } }, "loc": { "start": { - "line": 1, + "line": 20, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 20, + "column": 46 } } } @@ -495,12 +495,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 19, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 19, + "column": 46 } } }, @@ -577,12 +577,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 20, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 20, + "column": 45 } } } diff --git a/ets2panda/test/parser/ets/import_tests/import_several_6-expected.txt b/ets2panda/test/parser/ets/import_tests/import_several_6-expected.txt index 6502defab4343385e930f0a5417495e20aa01f75..08763cfb560d323b79d9c3dced590c61c5054767 100644 --- a/ets2panda/test/parser/ets/import_tests/import_several_6-expected.txt +++ b/ets2panda/test/parser/ets/import_tests/import_several_6-expected.txt @@ -297,23 +297,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 19, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 19, + "column": 51 } } }, "loc": { "start": { - "line": 1, + "line": 19, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 19, + "column": 52 } } }, @@ -445,23 +445,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 20, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 20, + "column": 55 } } }, "loc": { "start": { - "line": 1, + "line": 20, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 20, + "column": 56 } } } @@ -615,12 +615,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 19, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 19, + "column": 51 } } }, @@ -757,12 +757,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 20, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 20, + "column": 55 } } } diff --git a/ets2panda/test/parser/ets/import_tests/import_several_7-expected.txt b/ets2panda/test/parser/ets/import_tests/import_several_7-expected.txt index a092b0c023ce35de044ad529cf2cfa8816d0cf06..a522257b8f57f2d4b3ac7d8ad4e250a471f6dde5 100755 --- a/ets2panda/test/parser/ets/import_tests/import_several_7-expected.txt +++ b/ets2panda/test/parser/ets/import_tests/import_several_7-expected.txt @@ -339,23 +339,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 20, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 20, + "column": 46 } } }, "loc": { "start": { - "line": 1, + "line": 20, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 20, + "column": 47 } } }, @@ -427,23 +427,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 21, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 21, + "column": 45 } } }, "loc": { "start": { - "line": 1, + "line": 21, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 21, + "column": 46 } } } @@ -567,12 +567,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 20, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 20, + "column": 46 } } }, @@ -649,12 +649,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 21, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 21, + "column": 45 } } } diff --git a/ets2panda/test/parser/ets/import_tests/modules/struct_default_module-expected.txt b/ets2panda/test/parser/ets/import_tests/modules/struct_default_module-expected.txt index 2afbc6d7abbcb9fc2e9cce7dc85ae0d92fd1305f..8e84f0f521ad0a24ddda14fe4fa34ab86a8b4a08 100644 --- a/ets2panda/test/parser/ets/import_tests/modules/struct_default_module-expected.txt +++ b/ets2panda/test/parser/ets/import_tests/modules/struct_default_module-expected.txt @@ -76,12 +76,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 17, + "column": 12 }, "end": { - "line": 1, - "column": 1 + "line": 17, + "column": 22 } } }, diff --git a/ets2panda/test/parser/ets/import_tests/modules/struct_module-expected.txt b/ets2panda/test/parser/ets/import_tests/modules/struct_module-expected.txt index 888bdee534c5fc99a46cacf3ecfab842c1093c88..1401356c1015f9bb7a7ded17a7013cb066157bff 100644 --- a/ets2panda/test/parser/ets/import_tests/modules/struct_module-expected.txt +++ b/ets2panda/test/parser/ets/import_tests/modules/struct_module-expected.txt @@ -76,12 +76,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 17, + "column": 12 }, "end": { - "line": 1, - "column": 1 + "line": 17, + "column": 22 } } }, diff --git a/ets2panda/test/parser/ets/import_tests/modules/test_lib1-expected.txt b/ets2panda/test/parser/ets/import_tests/modules/test_lib1-expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..8386d8940fdfa9763ec4838ac085a8774aca2486 --- /dev/null +++ b/ets2panda/test/parser/ets/import_tests/modules/test_lib1-expected.txt @@ -0,0 +1,290 @@ +{ + "type": "Program", + "statements": [ + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "C", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 14 + }, + "end": { + "line": 16, + "column": 15 + } + } + }, + "superClass": null, + "implements": [], + "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "constructor", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "constructor", + "static": false, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "constructor", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 18 + }, + "end": { + "line": 16, + "column": 18 + } + } + } + ], + "loc": { + "start": { + "line": 16, + "column": 16 + }, + "end": { + "line": 16, + "column": 18 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 8 + }, + "end": { + "line": 16, + "column": 18 + } + } + }, + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "ETSGLOBAL", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "superClass": null, + "implements": [], + "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "_$init$_", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "_$init$_", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 18, + "column": 1 + } + } +} diff --git a/ets2panda/test/parser/ets/import_tests/modules/test_lib1.ets b/ets2panda/test/parser/ets/import_tests/modules/test_lib1.ets new file mode 100644 index 0000000000000000000000000000000000000000..03521fe13593e1469c909510dd335ce508a94cc4 --- /dev/null +++ b/ets2panda/test/parser/ets/import_tests/modules/test_lib1.ets @@ -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. + */ + +export class C {} + diff --git a/ets2panda/test/parser/ets/import_tests/modules/test_lib2-expected.txt b/ets2panda/test/parser/ets/import_tests/modules/test_lib2-expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..51e505772ffa256ffde70ae899396377f0748de7 --- /dev/null +++ b/ets2panda/test/parser/ets/import_tests/modules/test_lib2-expected.txt @@ -0,0 +1,389 @@ +{ + "type": "Program", + "statements": [ + { + "type": "ImportDeclaration", + "source": { + "type": "StringLiteral", + "value": "./", + "loc": { + "start": { + "line": 16, + "column": 19 + }, + "end": { + "line": 16, + "column": 32 + } + } + }, + "specifiers": [ + { + "type": "ImportSpecifier", + "local": { + "type": "Identifier", + "name": "C", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 10 + }, + "end": { + "line": 16, + "column": 11 + } + } + }, + "imported": { + "type": "Identifier", + "name": "C", + "decorators": [], + "loc": { + "start": { + "line": 16, + "column": 10 + }, + "end": { + "line": 16, + "column": 11 + } + } + }, + "loc": { + "start": { + "line": 16, + "column": 10 + }, + "end": { + "line": 16, + "column": 11 + } + } + } + ], + "loc": { + "start": { + "line": 16, + "column": 1 + }, + "end": { + "line": 16, + "column": 32 + } + } + }, + { + "type": "ClassDeclaration", + "definition": { + "id": { + "type": "Identifier", + "name": "ETSGLOBAL", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "superClass": null, + "implements": [], + "body": [ + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "_$init$_", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "_$init$_", + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + { + "type": "MethodDefinition", + "key": { + "type": "Identifier", + "name": "f", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 17 + }, + "end": { + "line": 17, + "column": 18 + } + } + }, + "kind": "method", + "accessibility": "public", + "static": true, + "optional": false, + "computed": false, + "value": { + "type": "FunctionExpression", + "function": { + "type": "ScriptFunction", + "id": { + "type": "Identifier", + "name": "f", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 17 + }, + "end": { + "line": 17, + "column": 18 + } + } + }, + "generator": false, + "async": false, + "expression": false, + "params": [ + { + "type": "ETSParameterExpression", + "name": { + "type": "Identifier", + "name": "c", + "typeAnnotation": { + "type": "ETSTypeReference", + "part": { + "type": "ETSTypeReferencePart", + "name": { + "type": "Identifier", + "name": "C", + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 22 + }, + "end": { + "line": 17, + "column": 23 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 22 + }, + "end": { + "line": 17, + "column": 24 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 22 + }, + "end": { + "line": 17, + "column": 24 + } + } + }, + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 19 + }, + "end": { + "line": 17, + "column": 24 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 19 + }, + "end": { + "line": 17, + "column": 24 + } + } + } + ], + "body": { + "type": "BlockStatement", + "statements": [], + "loc": { + "start": { + "line": 17, + "column": 25 + }, + "end": { + "line": 17, + "column": 27 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 18 + }, + "end": { + "line": 17, + "column": 27 + } + } + }, + "loc": { + "start": { + "line": 17, + "column": 18 + }, + "end": { + "line": 17, + "column": 27 + } + } + }, + "overloads": [], + "decorators": [], + "loc": { + "start": { + "line": 17, + "column": 8 + }, + "end": { + "line": 17, + "column": 27 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + }, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 1 + } + } + } + ], + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 19, + "column": 1 + } + } +} diff --git a/ets2panda/test/parser/ets/import_tests/modules/test_lib2.ets b/ets2panda/test/parser/ets/import_tests/modules/test_lib2.ets new file mode 100644 index 0000000000000000000000000000000000000000..858acdc0f8047a12b81fb01915405adba4fa3b0a --- /dev/null +++ b/ets2panda/test/parser/ets/import_tests/modules/test_lib2.ets @@ -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 { C } from "./test_lib1" +export function f(c: C) {} + diff --git a/ets2panda/test/parser/ets/import_tests/packages/different-header/subpackage_module_1-expected.txt b/ets2panda/test/parser/ets/import_tests/packages/different-header/subpackage_module_1-expected.txt index 044b63affb8e6505e69a4a438392ae7ed5fb6998..85f26116667833d6e3b93976544a522ecad636d2 100755 --- a/ets2panda/test/parser/ets/import_tests/packages/different-header/subpackage_module_1-expected.txt +++ b/ets2panda/test/parser/ets/import_tests/packages/different-header/subpackage_module_1-expected.txt @@ -188,12 +188,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 18, + "column": 12 }, "end": { - "line": 1, - "column": 1 + "line": 18, + "column": 37 } } } diff --git a/ets2panda/test/parser/ets/import_tests/packages/different-header/subpackage_module_2-expected.txt b/ets2panda/test/parser/ets/import_tests/packages/different-header/subpackage_module_2-expected.txt index 3b6b6fbb30311934bfb0841b4759cccc7128d033..925e41d76aaf4ba07a500af1f679f963d288e3df 100755 --- a/ets2panda/test/parser/ets/import_tests/packages/different-header/subpackage_module_2-expected.txt +++ b/ets2panda/test/parser/ets/import_tests/packages/different-header/subpackage_module_2-expected.txt @@ -188,12 +188,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 18, + "column": 12 }, "end": { - "line": 1, - "column": 1 + "line": 18, + "column": 37 } } } diff --git a/ets2panda/test/parser/ets/import_tests/packages/package_module_1-expected.txt b/ets2panda/test/parser/ets/import_tests/packages/package_module_1-expected.txt index 4706c5778946b15742e6e6265449d1d10d2d368a..e22b6128f4292dfc54edbf937aa6c598a3f78184 100755 --- a/ets2panda/test/parser/ets/import_tests/packages/package_module_1-expected.txt +++ b/ets2panda/test/parser/ets/import_tests/packages/package_module_1-expected.txt @@ -132,12 +132,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 18, + "column": 14 }, "end": { - "line": 1, - "column": 1 + "line": 18, + "column": 38 } } }, diff --git a/ets2panda/test/parser/ets/import_tests/packages/package_module_2-expected.txt b/ets2panda/test/parser/ets/import_tests/packages/package_module_2-expected.txt index 11c8c5ed4a5c89d416f201d5b5dabdc3cbf9f5cb..e11f163db86c2353dc6efe6bef5022613ebac601 100755 --- a/ets2panda/test/parser/ets/import_tests/packages/package_module_2-expected.txt +++ b/ets2panda/test/parser/ets/import_tests/packages/package_module_2-expected.txt @@ -132,12 +132,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 18, + "column": 14 }, "end": { - "line": 1, - "column": 1 + "line": 18, + "column": 33 } } } diff --git a/ets2panda/test/parser/ets/import_tests/packages/subpackage-1/package_module_1-expected.txt b/ets2panda/test/parser/ets/import_tests/packages/subpackage-1/package_module_1-expected.txt index 068e9cc8aafeea67998740f6741201c923ac741f..6db77e6e7f0a7f582a5b7b2a500d876badb9c8da 100644 --- a/ets2panda/test/parser/ets/import_tests/packages/subpackage-1/package_module_1-expected.txt +++ b/ets2panda/test/parser/ets/import_tests/packages/subpackage-1/package_module_1-expected.txt @@ -147,12 +147,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 18, + "column": 12 }, "end": { - "line": 1, - "column": 1 + "line": 18, + "column": 19 } } } diff --git a/ets2panda/test/parser/ets/import_tests/packages/subpackage-2/package_module_1-expected.txt b/ets2panda/test/parser/ets/import_tests/packages/subpackage-2/package_module_1-expected.txt index 1c44fc097c9600200e81cb3d45ccca5bef5984a5..fd7dc9f6ab8cf66f6e59e5db3eef3a87c8896c8f 100644 --- a/ets2panda/test/parser/ets/import_tests/packages/subpackage-2/package_module_1-expected.txt +++ b/ets2panda/test/parser/ets/import_tests/packages/subpackage-2/package_module_1-expected.txt @@ -147,12 +147,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 18, + "column": 12 }, "end": { - "line": 1, - "column": 1 + "line": 18, + "column": 19 } } } diff --git a/ets2panda/test/parser/ets/import_tests/packages/var-duplication/subpackage_module_1-expected.txt b/ets2panda/test/parser/ets/import_tests/packages/var-duplication/subpackage_module_1-expected.txt index ab9f2deb442f8b6e9a4559d662de8e6234c269f1..889698997e73fb93fdd0aed624c83923c26bd76b 100755 --- a/ets2panda/test/parser/ets/import_tests/packages/var-duplication/subpackage_module_1-expected.txt +++ b/ets2panda/test/parser/ets/import_tests/packages/var-duplication/subpackage_module_1-expected.txt @@ -188,12 +188,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 19, + "column": 12 }, "end": { - "line": 1, - "column": 1 + "line": 19, + "column": 37 } } } diff --git a/ets2panda/test/parser/ets/import_tests/packages/var-duplication/subpackage_module_2-expected.txt b/ets2panda/test/parser/ets/import_tests/packages/var-duplication/subpackage_module_2-expected.txt index ab9f2deb442f8b6e9a4559d662de8e6234c269f1..889698997e73fb93fdd0aed624c83923c26bd76b 100755 --- a/ets2panda/test/parser/ets/import_tests/packages/var-duplication/subpackage_module_2-expected.txt +++ b/ets2panda/test/parser/ets/import_tests/packages/var-duplication/subpackage_module_2-expected.txt @@ -188,12 +188,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 19, + "column": 12 }, "end": { - "line": 1, - "column": 1 + "line": 19, + "column": 37 } } } diff --git a/ets2panda/test/parser/ets/import_tests/relative_import/Line-expected.txt b/ets2panda/test/parser/ets/import_tests/relative_import/Line-expected.txt index 54408f63cd3436bf11c146f687f7761f6fd2e93c..e4fbb33d05932a8e7ff8ebe0a6d6dcdc89c496c4 100644 --- a/ets2panda/test/parser/ets/import_tests/relative_import/Line-expected.txt +++ b/ets2panda/test/parser/ets/import_tests/relative_import/Line-expected.txt @@ -162,12 +162,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 19, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 19, + "column": 18 } } }, @@ -239,12 +239,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 20, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 20, + "column": 16 } } }, diff --git a/ets2panda/test/parser/ets/import_tests/relative_import/Point-expected.txt b/ets2panda/test/parser/ets/import_tests/relative_import/Point-expected.txt index 522f0a8f0b79d01871a1b23072aa79c8e04e6856..db8f03c2be7f5600f3ca8df48f3a191819b8a5af 100644 --- a/ets2panda/test/parser/ets/import_tests/relative_import/Point-expected.txt +++ b/ets2panda/test/parser/ets/import_tests/relative_import/Point-expected.txt @@ -62,12 +62,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 17, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 17, + "column": 14 } } }, @@ -111,12 +111,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 18, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 18, + "column": 14 } } }, diff --git a/ets2panda/test/parser/ets/import_tests/relative_import/alias2-expected.txt b/ets2panda/test/parser/ets/import_tests/relative_import/alias2-expected.txt index 76e0d220b2c9091b2cd70a248f427665e7eedd47..78b1a6b2bbd6691406f23800e20c09cbf2293a27 100644 --- a/ets2panda/test/parser/ets/import_tests/relative_import/alias2-expected.txt +++ b/ets2panda/test/parser/ets/import_tests/relative_import/alias2-expected.txt @@ -337,23 +337,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 16, + "column": 12 }, "end": { - "line": 1, - "column": 1 + "line": 16, + "column": 19 } } }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 16, + "column": 8 }, "end": { - "line": 1, - "column": 1 + "line": 16, + "column": 20 } } } @@ -445,12 +445,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 16, + "column": 12 }, "end": { - "line": 1, - "column": 1 + "line": 16, + "column": 19 } } }, diff --git a/ets2panda/test/parser/ets/index_expressions-expected.txt b/ets2panda/test/parser/ets/index_expressions-expected.txt index 5eafc0fe04534fc684551488be77f8af5f9c1936..da4f14491678ca06393920994b7ddf1ca0802ee6 100644 --- a/ets2panda/test/parser/ets/index_expressions-expected.txt +++ b/ets2panda/test/parser/ets/index_expressions-expected.txt @@ -132,23 +132,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 17, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 17, + "column": 19 } } }, "loc": { "start": { - "line": 1, + "line": 17, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 17, + "column": 20 } } }, @@ -218,23 +218,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 18, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 18, + "column": 13 } } }, "loc": { "start": { - "line": 1, + "line": 18, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 18, + "column": 14 } } }, @@ -305,23 +305,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 19, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 19, + "column": 13 } } }, "loc": { "start": { - "line": 1, + "line": 19, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 19, + "column": 14 } } }, @@ -422,23 +422,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 20, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 20, + "column": 16 } } }, "loc": { "start": { - "line": 1, + "line": 20, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 20, + "column": 17 } } } @@ -556,12 +556,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 17, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 17, + "column": 19 } } }, @@ -636,12 +636,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 18, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 18, + "column": 13 } } }, @@ -717,12 +717,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 19, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 19, + "column": 13 } } }, @@ -828,12 +828,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 20, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 20, + "column": 16 } } } diff --git a/ets2panda/test/parser/ets/internalParsing-expected.txt b/ets2panda/test/parser/ets/internalParsing-expected.txt index 63c475014317bf699b92bc5785f00b06f2be0fa4..a2fe1faccdd55da48ffec893504596803c38dc1f 100644 --- a/ets2panda/test/parser/ets/internalParsing-expected.txt +++ b/ets2panda/test/parser/ets/internalParsing-expected.txt @@ -62,12 +62,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 17, + "column": 12 }, "end": { - "line": 1, - "column": 1 + "line": 17, + "column": 19 } } }, @@ -111,12 +111,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 18, + "column": 12 }, "end": { - "line": 1, - "column": 1 + "line": 18, + "column": 19 } } }, diff --git a/ets2panda/test/parser/ets/internalProtectedParsing-expected.txt b/ets2panda/test/parser/ets/internalProtectedParsing-expected.txt index e225935409c974d2a3a9497bb55de6c9daa33956..9c8de543ac0094195f72e82a9368f8251bfb76a4 100644 --- a/ets2panda/test/parser/ets/internalProtectedParsing-expected.txt +++ b/ets2panda/test/parser/ets/internalProtectedParsing-expected.txt @@ -62,12 +62,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 17, + "column": 22 }, "end": { - "line": 1, - "column": 1 + "line": 17, + "column": 29 } } }, @@ -111,12 +111,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 18, + "column": 22 }, "end": { - "line": 1, - "column": 1 + "line": 18, + "column": 29 } } }, diff --git a/ets2panda/test/parser/ets/lambdaThrowsRethrows-expected.txt b/ets2panda/test/parser/ets/lambdaThrowsRethrows-expected.txt index cccfa91bfb237216be2a0a65e0c2d123f87459d7..bc9900bde930e18dea026ae0db5bf707db5b03da 100644 --- a/ets2panda/test/parser/ets/lambdaThrowsRethrows-expected.txt +++ b/ets2panda/test/parser/ets/lambdaThrowsRethrows-expected.txt @@ -286,12 +286,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 16, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 16, + "column": 54 } } }, @@ -745,12 +745,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 18, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 18, + "column": 133 } } } diff --git a/ets2panda/test/parser/ets/launch_with_call_expression-expected.txt b/ets2panda/test/parser/ets/launch_with_call_expression-expected.txt index 2eb0ed8184ae5ddd698b42934f76de172a83b26e..d5c78505507622de816eb29934b2c123c3b49b33 100644 --- a/ets2panda/test/parser/ets/launch_with_call_expression-expected.txt +++ b/ets2panda/test/parser/ets/launch_with_call_expression-expected.txt @@ -396,23 +396,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 21, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 21, + "column": 25 } } }, "loc": { "start": { - "line": 1, + "line": 21, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 21, + "column": 25 } } } @@ -563,12 +563,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 21, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 21, + "column": 25 } } } diff --git a/ets2panda/test/parser/ets/literals-expected.txt b/ets2panda/test/parser/ets/literals-expected.txt index 102b4b5cf5793da386c5ffa5eb222a2a180740af..019093d519550c2c3fce3b09662c62afae81ba86 100644 --- a/ets2panda/test/parser/ets/literals-expected.txt +++ b/ets2panda/test/parser/ets/literals-expected.txt @@ -157,12 +157,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 16, + "column": 7 }, "end": { - "line": 1, - "column": 1 + "line": 16, + "column": 16 } } }, @@ -207,12 +207,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 17, + "column": 7 }, "end": { - "line": 1, - "column": 1 + "line": 17, + "column": 18 } } }, @@ -257,12 +257,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 20, + "column": 7 }, "end": { - "line": 1, - "column": 1 + "line": 20, + "column": 23 } } }, @@ -307,12 +307,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 21, + "column": 7 }, "end": { - "line": 1, - "column": 1 + "line": 21, + "column": 21 } } }, @@ -357,12 +357,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 22, + "column": 7 }, "end": { - "line": 1, - "column": 1 + "line": 22, + "column": 24 } } }, @@ -407,12 +407,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 23, + "column": 7 }, "end": { - "line": 1, - "column": 1 + "line": 23, + "column": 21 } } }, @@ -457,12 +457,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 24, + "column": 7 }, "end": { - "line": 1, - "column": 1 + "line": 24, + "column": 21 } } }, @@ -522,12 +522,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 25, + "column": 7 }, "end": { - "line": 1, - "column": 1 + "line": 25, + "column": 22 } } }, @@ -572,12 +572,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 26, + "column": 7 }, "end": { - "line": 1, - "column": 1 + "line": 26, + "column": 19 } } }, @@ -622,12 +622,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 27, + "column": 7 }, "end": { - "line": 1, - "column": 1 + "line": 27, + "column": 24 } } }, @@ -672,12 +672,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 28, + "column": 7 }, "end": { - "line": 1, - "column": 1 + "line": 28, + "column": 19 } } }, @@ -722,12 +722,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 29, + "column": 7 }, "end": { - "line": 1, - "column": 1 + "line": 29, + "column": 20 } } }, @@ -772,12 +772,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 30, + "column": 7 }, "end": { - "line": 1, - "column": 1 + "line": 30, + "column": 19 } } }, @@ -822,12 +822,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 31, + "column": 7 }, "end": { - "line": 1, - "column": 1 + "line": 31, + "column": 17 } } }, @@ -915,12 +915,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 32, + "column": 7 }, "end": { - "line": 1, - "column": 1 + "line": 32, + "column": 22 } } }, @@ -1008,12 +1008,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 33, + "column": 7 }, "end": { - "line": 1, - "column": 1 + "line": 33, + "column": 28 } } }, @@ -1101,12 +1101,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 34, + "column": 7 }, "end": { - "line": 1, - "column": 1 + "line": 34, + "column": 28 } } } diff --git a/ets2panda/test/parser/ets/null-expected.txt b/ets2panda/test/parser/ets/null-expected.txt index fe48855d5646fa0642363eda4a33acae5fac7f6d..f069f5a6a679ab99caee7be78a77b7c0c31c644c 100644 --- a/ets2panda/test/parser/ets/null-expected.txt +++ b/ets2panda/test/parser/ets/null-expected.txt @@ -243,23 +243,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 18, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 18, + "column": 26 } } }, "loc": { "start": { - "line": 1, + "line": 18, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 18, + "column": 27 } } }, @@ -340,23 +340,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 19, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 19, + "column": 25 } } }, "loc": { "start": { - "line": 1, + "line": 19, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 19, + "column": 25 } } } @@ -475,12 +475,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 18, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 18, + "column": 14 } } }, @@ -552,12 +552,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 19, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 19, + "column": 14 } } }, diff --git a/ets2panda/test/parser/ets/null_invalid-expected.txt b/ets2panda/test/parser/ets/null_invalid-expected.txt index 63b294b65cabc536d959139b79a669dbbacbc9b5..1c9ab91eeeac7352aace79b9b760748ca182065d 100644 --- a/ets2panda/test/parser/ets/null_invalid-expected.txt +++ b/ets2panda/test/parser/ets/null_invalid-expected.txt @@ -107,23 +107,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 17, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 17, + "column": 19 } } }, "loc": { "start": { - "line": 1, + "line": 17, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 17, + "column": 20 } } } @@ -215,12 +215,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 16, + "column": 7 }, "end": { - "line": 1, - "column": 1 + "line": 16, + "column": 15 } } }, @@ -292,12 +292,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 17, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 17, + "column": 17 } } } diff --git a/ets2panda/test/parser/ets/null_valid-expected.txt b/ets2panda/test/parser/ets/null_valid-expected.txt index 78a7b9c1a8d0f1bae13a38b1bc0e8bd8dd1f5f82..1891cfc564194d2f8b9d7038adff79c3ca03b7e2 100644 --- a/ets2panda/test/parser/ets/null_valid-expected.txt +++ b/ets2panda/test/parser/ets/null_valid-expected.txt @@ -107,23 +107,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 17, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 17, + "column": 26 } } }, "loc": { "start": { - "line": 1, + "line": 17, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 17, + "column": 27 } } } @@ -215,12 +215,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 16, + "column": 7 }, "end": { - "line": 1, - "column": 1 + "line": 16, + "column": 15 } } }, @@ -292,12 +292,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 17, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 17, + "column": 17 } } } diff --git a/ets2panda/test/parser/ets/nullableType-expected.txt b/ets2panda/test/parser/ets/nullableType-expected.txt index 4ffaa76dd684359644472e7adf7c6e4ac0783152..ed0d54068514e413f44c031d2e948014ed8deeff 100644 --- a/ets2panda/test/parser/ets/nullableType-expected.txt +++ b/ets2panda/test/parser/ets/nullableType-expected.txt @@ -958,12 +958,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 132, + "column": 11 }, "end": { - "line": 1, - "column": 1 + "line": 132, + "column": 30 } } }, diff --git a/ets2panda/test/parser/ets/object-expected.txt b/ets2panda/test/parser/ets/object-expected.txt index d44e5d101d1718d1c02c7d60091edbff13e49162..9f1511caa9e1a0346b5142108441c96124fe7ba3 100644 --- a/ets2panda/test/parser/ets/object-expected.txt +++ b/ets2panda/test/parser/ets/object-expected.txt @@ -184,12 +184,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 16, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 16, + "column": 15 } } } diff --git a/ets2panda/test/parser/ets/optional-chaining-array-expected.txt b/ets2panda/test/parser/ets/optional-chaining-array-expected.txt index 756f1572dc51df08b3c8d4ddef31e8ceea094106..bf7e6b46de5daf47cc82e78ab51fb9b83eaf8580 100644 --- a/ets2panda/test/parser/ets/optional-chaining-array-expected.txt +++ b/ets2panda/test/parser/ets/optional-chaining-array-expected.txt @@ -149,23 +149,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 16, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 16, + "column": 27 } } }, "loc": { "start": { - "line": 1, + "line": 16, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 16, + "column": 28 } } }, @@ -263,23 +263,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 17, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 17, + "column": 33 } } }, "loc": { "start": { - "line": 1, + "line": 17, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 17, + "column": 34 } } }, @@ -377,23 +377,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 20, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 20, + "column": 38 } } }, "loc": { "start": { - "line": 1, + "line": 20, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 20, + "column": 39 } } } @@ -525,12 +525,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 16, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 16, + "column": 17 } } }, @@ -633,12 +633,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 17, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 17, + "column": 33 } } }, @@ -723,12 +723,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 19, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 19, + "column": 20 } } }, @@ -831,12 +831,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 20, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 20, + "column": 38 } } } diff --git a/ets2panda/test/parser/ets/optional_chaining_invalid_property-expected.txt b/ets2panda/test/parser/ets/optional_chaining_invalid_property-expected.txt index 597585d0b1eefecbc5a5bba5ee268a9e46484900..2c046490ecfedd22b633e419f3eb37b98677be33 100644 --- a/ets2panda/test/parser/ets/optional_chaining_invalid_property-expected.txt +++ b/ets2panda/test/parser/ets/optional_chaining_invalid_property-expected.txt @@ -90,12 +90,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 18, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 18, + "column": 18 } } }, @@ -167,12 +167,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 19, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 19, + "column": 15 } } }, @@ -444,23 +444,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 22, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 24, + "column": 2 } } }, "loc": { "start": { - "line": 1, + "line": 22, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 24, + "column": 2 } } }, @@ -531,23 +531,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 26, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 26, + "column": 29 } } }, "loc": { "start": { - "line": 1, + "line": 26, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 26, + "column": 30 } } } @@ -666,12 +666,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 22, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 22, + "column": 15 } } }, @@ -747,12 +747,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 26, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 26, + "column": 29 } } } diff --git a/ets2panda/test/parser/ets/optional_chaining_nested_property-expected.txt b/ets2panda/test/parser/ets/optional_chaining_nested_property-expected.txt index 8aa877a567ea517f331b9f5f14301cb0d055753e..47d2b4e1241a24507e64380127f6f1c2680bc3de 100644 --- a/ets2panda/test/parser/ets/optional_chaining_nested_property-expected.txt +++ b/ets2panda/test/parser/ets/optional_chaining_nested_property-expected.txt @@ -90,12 +90,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 18, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 18, + "column": 21 } } }, @@ -167,12 +167,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 19, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 19, + "column": 18 } } }, @@ -244,12 +244,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 20, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 20, + "column": 16 } } }, @@ -521,23 +521,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 23, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 25, + "column": 2 } } }, "loc": { "start": { - "line": 1, + "line": 23, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 25, + "column": 2 } } }, @@ -653,23 +653,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 27, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 27, + "column": 43 } } }, "loc": { "start": { - "line": 1, + "line": 27, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 27, + "column": 44 } } } @@ -788,12 +788,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 23, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 23, + "column": 15 } } }, @@ -914,12 +914,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 27, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 27, + "column": 43 } } } diff --git a/ets2panda/test/parser/ets/optional_chaining_object_property-expected.txt b/ets2panda/test/parser/ets/optional_chaining_object_property-expected.txt index 3bba741952961de68772d69182e696fb700ab0f7..3e7ff288e94a231fe72888e0eb4ed591a370d76e 100644 --- a/ets2panda/test/parser/ets/optional_chaining_object_property-expected.txt +++ b/ets2panda/test/parser/ets/optional_chaining_object_property-expected.txt @@ -90,12 +90,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 18, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 18, + "column": 18 } } }, @@ -167,12 +167,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 19, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 19, + "column": 15 } } }, @@ -444,23 +444,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 22, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 24, + "column": 2 } } }, "loc": { "start": { - "line": 1, + "line": 22, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 24, + "column": 2 } } }, @@ -559,23 +559,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 26, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 26, + "column": 32 } } }, "loc": { "start": { - "line": 1, + "line": 26, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 26, + "column": 33 } } }, @@ -674,23 +674,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 27, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 27, + "column": 35 } } }, "loc": { "start": { - "line": 1, + "line": 27, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 27, + "column": 36 } } } @@ -809,12 +809,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 22, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 22, + "column": 15 } } }, @@ -918,12 +918,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 26, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 26, + "column": 32 } } }, @@ -967,12 +967,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 27, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 27, + "column": 18 } } } diff --git a/ets2panda/test/parser/ets/parentheses_expression_value-expected.txt b/ets2panda/test/parser/ets/parentheses_expression_value-expected.txt index dd1396ae0e6b1529feb4b40fe86c5c4073141b20..32bc14b3a4b55db92bda2c320d9de403f2147a19 100644 --- a/ets2panda/test/parser/ets/parentheses_expression_value-expected.txt +++ b/ets2panda/test/parser/ets/parentheses_expression_value-expected.txt @@ -106,23 +106,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 17, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 17, + "column": 10 } } }, "loc": { "start": { - "line": 1, + "line": 17, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 17, + "column": 11 } } }, @@ -162,23 +162,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 18, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 18, + "column": 12 } } }, "loc": { "start": { - "line": 1, + "line": 18, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 18, + "column": 13 } } }, @@ -218,23 +218,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 19, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 19, + "column": 14 } } }, "loc": { "start": { - "line": 1, + "line": 19, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 19, + "column": 15 } } }, @@ -275,23 +275,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 20, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 20, + "column": 12 } } }, "loc": { "start": { - "line": 1, + "line": 20, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 20, + "column": 13 } } } @@ -383,12 +383,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 17, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 17, + "column": 10 } } }, @@ -433,12 +433,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 18, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 18, + "column": 12 } } }, @@ -483,12 +483,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 19, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 19, + "column": 14 } } }, @@ -534,12 +534,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 20, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 20, + "column": 12 } } }, diff --git a/ets2panda/test/parser/ets/predefined_types-expected.txt b/ets2panda/test/parser/ets/predefined_types-expected.txt index d2ef41f276e8c6c7af60cd0ddf4c208c3b04c0c2..1917db3b8842b16629c2f9391abcdb0ffb8e33ac 100644 --- a/ets2panda/test/parser/ets/predefined_types-expected.txt +++ b/ets2panda/test/parser/ets/predefined_types-expected.txt @@ -156,12 +156,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 17, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 17, + "column": 12 } } }, @@ -205,12 +205,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 18, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 18, + "column": 13 } } }, @@ -254,12 +254,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 19, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 19, + "column": 11 } } }, @@ -303,12 +303,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 20, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 20, + "column": 12 } } }, @@ -352,12 +352,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 22, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 22, + "column": 13 } } }, @@ -401,12 +401,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 23, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 23, + "column": 14 } } }, @@ -450,12 +450,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 25, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 25, + "column": 12 } } } diff --git a/ets2panda/test/parser/ets/property-access-field-1-expected.txt b/ets2panda/test/parser/ets/property-access-field-1-expected.txt index cd63a35ca3f673f3561a065d21271b4aa0349e17..786506feadd070852cd1dcb1c89045986fd7b231 100644 --- a/ets2panda/test/parser/ets/property-access-field-1-expected.txt +++ b/ets2panda/test/parser/ets/property-access-field-1-expected.txt @@ -76,12 +76,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 17, + "column": 12 }, "end": { - "line": 1, - "column": 1 + "line": 17, + "column": 30 } } }, diff --git a/ets2panda/test/parser/ets/property-access-field-2-expected.txt b/ets2panda/test/parser/ets/property-access-field-2-expected.txt index daabca2798b09bf2243f3a8d466c3482b31dfaeb..c9cce528be18588d97328e5f21b5156a794771c2 100644 --- a/ets2panda/test/parser/ets/property-access-field-2-expected.txt +++ b/ets2panda/test/parser/ets/property-access-field-2-expected.txt @@ -76,12 +76,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 17, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 17, + "column": 26 } } }, diff --git a/ets2panda/test/parser/ets/rest_parameter_02-expected.txt b/ets2panda/test/parser/ets/rest_parameter_02-expected.txt index 9dcbe17e90d034af530d6b66d7dddac9ec318cbc..87a53b8d5ad3652e22ff54d040f3e644ec706331 100644 --- a/ets2panda/test/parser/ets/rest_parameter_02-expected.txt +++ b/ets2panda/test/parser/ets/rest_parameter_02-expected.txt @@ -793,7 +793,7 @@ "type": "ETSParameterExpression", "name": { "type": "Identifier", - "name": "proxy_int", + "name": "$proxy_mask$", "typeAnnotation": { "type": "ETSPrimitiveType", "loc": { @@ -860,7 +860,7 @@ "operator": ">>", "left": { "type": "Identifier", - "name": "proxy_int", + "name": "$proxy_mask$", "decorators": [], "loc": { "start": { diff --git a/ets2panda/test/parser/ets/return-expected.txt b/ets2panda/test/parser/ets/return-expected.txt index 75e777bf826819d99683549fe677322b2d42d548..ee83fa8590954398b414c31cfa2e74c94becba16 100644 --- a/ets2panda/test/parser/ets/return-expected.txt +++ b/ets2panda/test/parser/ets/return-expected.txt @@ -149,23 +149,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 16, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 16, + "column": 25 } } }, "loc": { "start": { - "line": 1, + "line": 16, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 16, + "column": 26 } } } @@ -269,12 +269,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 16, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 16, + "column": 15 } } }, diff --git a/ets2panda/test/parser/ets/setter_native-expected.txt b/ets2panda/test/parser/ets/setter_native-expected.txt index ba515f59a5bd535ed5985860ccdc8ed4332e32d9..a36ac4231486e9f480afa0f14d6552268db17c58 100644 --- a/ets2panda/test/parser/ets/setter_native-expected.txt +++ b/ets2panda/test/parser/ets/setter_native-expected.txt @@ -62,12 +62,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 17, + "column": 13 }, "end": { - "line": 1, - "column": 1 + "line": 17, + "column": 24 } } }, diff --git a/ets2panda/test/parser/ets/setter_with_non_void-expected.txt b/ets2panda/test/parser/ets/setter_with_non_void-expected.txt index e0dd8b95dfebfd005adbd9b4f422ca66e25d4849..d346044787d7970a6dd03d7d99a5a386758f3fea 100644 --- a/ets2panda/test/parser/ets/setter_with_non_void-expected.txt +++ b/ets2panda/test/parser/ets/setter_with_non_void-expected.txt @@ -62,12 +62,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 17, + "column": 13 }, "end": { - "line": 1, - "column": 1 + "line": 17, + "column": 24 } } }, diff --git a/ets2panda/test/parser/ets/simple_types-expected.txt b/ets2panda/test/parser/ets/simple_types-expected.txt index 1f81b8c3616d84239c091cbf2251a74dc5758995..b75839eeb2747a4359414db7de8f4f03e8be5477 100644 --- a/ets2panda/test/parser/ets/simple_types-expected.txt +++ b/ets2panda/test/parser/ets/simple_types-expected.txt @@ -106,23 +106,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 16, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 16, + "column": 18 } } }, "loc": { "start": { - "line": 1, + "line": 16, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 16, + "column": 19 } } }, @@ -177,23 +177,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 17, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 17, + "column": 22 } } }, "loc": { "start": { - "line": 1, + "line": 17, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 17, + "column": 23 } } }, @@ -233,23 +233,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 18, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 18, + "column": 24 } } }, "loc": { "start": { - "line": 1, + "line": 18, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 18, + "column": 25 } } }, @@ -304,23 +304,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 19, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 19, + "column": 35 } } }, "loc": { "start": { - "line": 1, + "line": 19, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 19, + "column": 36 } } }, @@ -360,23 +360,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 21, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 21, + "column": 22 } } }, "loc": { "start": { - "line": 1, + "line": 21, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 21, + "column": 23 } } }, @@ -416,23 +416,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 22, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 22, + "column": 19 } } }, "loc": { "start": { - "line": 1, + "line": 22, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 22, + "column": 20 } } }, @@ -472,23 +472,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 26, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 26, + "column": 22 } } }, "loc": { "start": { - "line": 1, + "line": 26, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 26, + "column": 23 } } }, @@ -528,23 +528,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 27, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 27, + "column": 23 } } }, "loc": { "start": { - "line": 1, + "line": 27, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 27, + "column": 24 } } }, @@ -585,23 +585,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 29, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 29, + "column": 16 } } }, "loc": { "start": { - "line": 1, + "line": 29, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 29, + "column": 17 } } } @@ -692,12 +692,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 16, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 16, + "column": 12 } } }, @@ -741,12 +741,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 17, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 17, + "column": 13 } } }, @@ -790,12 +790,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 18, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 18, + "column": 11 } } }, @@ -839,12 +839,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 19, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 19, + "column": 12 } } }, @@ -888,12 +888,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 21, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 21, + "column": 15 } } }, @@ -937,12 +937,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 22, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 22, + "column": 12 } } }, @@ -1014,12 +1014,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 24, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 24, + "column": 13 } } }, @@ -1063,12 +1063,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 26, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 26, + "column": 13 } } }, @@ -1112,12 +1112,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 27, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 27, + "column": 14 } } }, @@ -1161,12 +1161,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 29, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 29, + "column": 12 } } } diff --git a/ets2panda/test/parser/ets/string-expected.txt b/ets2panda/test/parser/ets/string-expected.txt index 03becdb639ee516e35bdc4e2a833e1a27651e45a..657641c2443d16f5e35b06a8d4469fe9ac19ce13 100644 --- a/ets2panda/test/parser/ets/string-expected.txt +++ b/ets2panda/test/parser/ets/string-expected.txt @@ -106,23 +106,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 16, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 16, + "column": 24 } } }, "loc": { "start": { - "line": 1, + "line": 16, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 16, + "column": 25 } } }, @@ -162,23 +162,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 17, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 17, + "column": 24 } } }, "loc": { "start": { - "line": 1, + "line": 17, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 17, + "column": 25 } } } @@ -297,12 +297,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 16, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 16, + "column": 16 } } }, @@ -374,12 +374,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 17, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 17, + "column": 16 } } } diff --git a/ets2panda/test/parser/ets/struct_identifier-expected.txt b/ets2panda/test/parser/ets/struct_identifier-expected.txt index 3ea6f12b26f0e14b697ef21f26e5a313c595ecee..cfd8673216d5c3d28983eaf5b900a406a53159ba 100644 --- a/ets2panda/test/parser/ets/struct_identifier-expected.txt +++ b/ets2panda/test/parser/ets/struct_identifier-expected.txt @@ -76,12 +76,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 16, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 16, + "column": 20 } } }, diff --git a/ets2panda/test/parser/ets/struct_init-expected.txt b/ets2panda/test/parser/ets/struct_init-expected.txt index ce12d14a1578e7edcf07c2f64b9e14ce4f19a3bb..68015c8f2f8b1ecdc26451d0caaf4268969ea4d6 100644 --- a/ets2panda/test/parser/ets/struct_init-expected.txt +++ b/ets2panda/test/parser/ets/struct_init-expected.txt @@ -62,12 +62,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 17, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 17, + "column": 10 } } }, diff --git a/ets2panda/test/parser/ets/struct_static_initializer-expected.txt b/ets2panda/test/parser/ets/struct_static_initializer-expected.txt index 86b94856915fd61b4942aa15260c4ac61297dc54..1d09901886df78a5787cb5965ab0e3bbaaa96121 100644 --- a/ets2panda/test/parser/ets/struct_static_initializer-expected.txt +++ b/ets2panda/test/parser/ets/struct_static_initializer-expected.txt @@ -76,12 +76,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 17, + "column": 12 }, "end": { - "line": 1, - "column": 1 + "line": 17, + "column": 23 } } }, @@ -556,12 +556,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 25, + "column": 12 }, "end": { - "line": 1, - "column": 1 + "line": 25, + "column": 23 } } }, diff --git a/ets2panda/test/parser/ets/struct_templete-expected.txt b/ets2panda/test/parser/ets/struct_templete-expected.txt index 5223d017d73c2e73079646d51e675860ff86ae73..5060c2b73b24c7c1345fe7a4e9af9b9775e6b4f7 100644 --- a/ets2panda/test/parser/ets/struct_templete-expected.txt +++ b/ets2panda/test/parser/ets/struct_templete-expected.txt @@ -133,12 +133,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 17, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 17, + "column": 10 } } }, @@ -446,12 +446,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 21, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 21, + "column": 13 } } }, @@ -646,12 +646,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 25, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 25, + "column": 17 } } }, diff --git a/ets2panda/test/parser/ets/switch_readonly_member-expected.txt b/ets2panda/test/parser/ets/switch_readonly_member-expected.txt index a1f6f441709f98012c7b76d278741ba479e6ace9..a0429f6a7db7e3a089173aa136253133094a590e 100644 --- a/ets2panda/test/parser/ets/switch_readonly_member-expected.txt +++ b/ets2panda/test/parser/ets/switch_readonly_member-expected.txt @@ -63,12 +63,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 17, + "column": 21 }, "end": { - "line": 1, - "column": 1 + "line": 17, + "column": 30 } } }, @@ -250,12 +250,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 21, + "column": 21 }, "end": { - "line": 1, - "column": 1 + "line": 21, + "column": 30 } } }, diff --git a/ets2panda/test/parser/ets/switch_readonly_member_compare_char-expected.txt b/ets2panda/test/parser/ets/switch_readonly_member_compare_char-expected.txt index cffaacb12ff6d7553bb062aff8fd2cc1842620d3..04b54186be83e3fcdd5aeaf816dea2c58e7b2b34 100644 --- a/ets2panda/test/parser/ets/switch_readonly_member_compare_char-expected.txt +++ b/ets2panda/test/parser/ets/switch_readonly_member_compare_char-expected.txt @@ -63,12 +63,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 17, + "column": 21 }, "end": { - "line": 1, - "column": 1 + "line": 17, + "column": 30 } } }, @@ -250,12 +250,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 21, + "column": 21 }, "end": { - "line": 1, - "column": 1 + "line": 21, + "column": 30 } } }, diff --git a/ets2panda/test/parser/ets/switch_readonly_member_compare_char_2-expected.txt b/ets2panda/test/parser/ets/switch_readonly_member_compare_char_2-expected.txt index b4210967be804120b0e50db5e9eae783d581c525..0f99422e115d451281e74d7b5b26e20b74623338 100644 --- a/ets2panda/test/parser/ets/switch_readonly_member_compare_char_2-expected.txt +++ b/ets2panda/test/parser/ets/switch_readonly_member_compare_char_2-expected.txt @@ -63,12 +63,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 17, + "column": 21 }, "end": { - "line": 1, - "column": 1 + "line": 17, + "column": 30 } } }, @@ -250,12 +250,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 21, + "column": 21 }, "end": { - "line": 1, - "column": 1 + "line": 21, + "column": 30 } } }, diff --git a/ets2panda/test/parser/ets/switch_readonly_member_different_enum-expected.txt b/ets2panda/test/parser/ets/switch_readonly_member_different_enum-expected.txt index 0d057e60f5737bd7675c77aa38ce115571497256..f34d7e3f9246eb67d65876ae8c128e8bd56ab57c 100644 --- a/ets2panda/test/parser/ets/switch_readonly_member_different_enum-expected.txt +++ b/ets2panda/test/parser/ets/switch_readonly_member_different_enum-expected.txt @@ -408,12 +408,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 25, + "column": 21 }, "end": { - "line": 1, - "column": 1 + "line": 25, + "column": 29 } } }, @@ -626,12 +626,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 29, + "column": 21 }, "end": { - "line": 1, - "column": 1 + "line": 29, + "column": 29 } } }, diff --git a/ets2panda/test/parser/ets/switch_readonly_member_different_enum_2-expected.txt b/ets2panda/test/parser/ets/switch_readonly_member_different_enum_2-expected.txt index da9f79eae86b676bd051435fc935ed71952c2c34..3ef004f3ec9a6b0181d78255d6c875c3b60de6b3 100644 --- a/ets2panda/test/parser/ets/switch_readonly_member_different_enum_2-expected.txt +++ b/ets2panda/test/parser/ets/switch_readonly_member_different_enum_2-expected.txt @@ -408,12 +408,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 24, + "column": 21 }, "end": { - "line": 1, - "column": 1 + "line": 24, + "column": 29 } } }, @@ -626,12 +626,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 28, + "column": 21 }, "end": { - "line": 1, - "column": 1 + "line": 28, + "column": 29 } } }, diff --git a/ets2panda/test/parser/ets/switch_readonly_member_enum-expected.txt b/ets2panda/test/parser/ets/switch_readonly_member_enum-expected.txt index 9b68e099f815767b04466ea7a364597fa89ba5ac..cc9db9fc4a73b6404a9f3e753ccfc0c0c81514cb 100644 --- a/ets2panda/test/parser/ets/switch_readonly_member_enum-expected.txt +++ b/ets2panda/test/parser/ets/switch_readonly_member_enum-expected.txt @@ -408,12 +408,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 25, + "column": 21 }, "end": { - "line": 1, - "column": 1 + "line": 25, + "column": 29 } } }, @@ -626,12 +626,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 29, + "column": 21 }, "end": { - "line": 1, - "column": 1 + "line": 29, + "column": 29 } } }, diff --git a/ets2panda/test/parser/ets/switch_readonly_member_enum_duplicate-expected.txt b/ets2panda/test/parser/ets/switch_readonly_member_enum_duplicate-expected.txt index 4515834d1ca3ac63a4b520308a60725a192113e3..c37cacffebdfd380c90cdc1ad55f41fe2d790157 100644 --- a/ets2panda/test/parser/ets/switch_readonly_member_enum_duplicate-expected.txt +++ b/ets2panda/test/parser/ets/switch_readonly_member_enum_duplicate-expected.txt @@ -408,12 +408,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 25, + "column": 21 }, "end": { - "line": 1, - "column": 1 + "line": 25, + "column": 29 } } }, @@ -626,12 +626,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 29, + "column": 21 }, "end": { - "line": 1, - "column": 1 + "line": 29, + "column": 29 } } }, diff --git a/ets2panda/test/parser/ets/switch_readonly_member_number_duplicate-expected.txt b/ets2panda/test/parser/ets/switch_readonly_member_number_duplicate-expected.txt index 72fb18d07217ae10845664831d6e015c9bd02a1c..2ce1ff962ac981cf80603be3f45e0c24c4a9b352 100644 --- a/ets2panda/test/parser/ets/switch_readonly_member_number_duplicate-expected.txt +++ b/ets2panda/test/parser/ets/switch_readonly_member_number_duplicate-expected.txt @@ -63,12 +63,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 17, + "column": 21 }, "end": { - "line": 1, - "column": 1 + "line": 17, + "column": 28 } } }, @@ -250,12 +250,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 21, + "column": 21 }, "end": { - "line": 1, - "column": 1 + "line": 21, + "column": 30 } } }, diff --git a/ets2panda/test/parser/ets/ternary-expected.txt b/ets2panda/test/parser/ets/ternary-expected.txt index a870370edbf4d77582dec8627cc1b56832d9946b..b80d1cd97c9239f52f71459d19eda0c19fd35b4e 100644 --- a/ets2panda/test/parser/ets/ternary-expected.txt +++ b/ets2panda/test/parser/ets/ternary-expected.txt @@ -106,23 +106,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 16, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 16, + "column": 10 } } }, "loc": { "start": { - "line": 1, + "line": 16, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 16, + "column": 11 } } }, @@ -162,23 +162,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 17, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 17, + "column": 10 } } }, "loc": { "start": { - "line": 1, + "line": 17, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 17, + "column": 11 } } }, @@ -291,23 +291,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 19, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 19, + "column": 22 } } }, "loc": { "start": { - "line": 1, + "line": 19, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 19, + "column": 23 } } } @@ -399,12 +399,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 16, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 16, + "column": 10 } } }, @@ -449,12 +449,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 17, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 17, + "column": 10 } } }, @@ -572,12 +572,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 19, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 19, + "column": 22 } } } diff --git a/ets2panda/test/parser/ets/test_jsvalue-expected.txt b/ets2panda/test/parser/ets/test_jsvalue-expected.txt index 9f9d588fe8353e2a9fe54d6c4cb3b400bb3895cd..f172336108f9f1c27fa523ff53efe64d4124ef69 100644 --- a/ets2panda/test/parser/ets/test_jsvalue-expected.txt +++ b/ets2panda/test/parser/ets/test_jsvalue-expected.txt @@ -184,12 +184,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 16, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 16, + "column": 16 } } } diff --git a/ets2panda/test/parser/ets/test_jsvalue_get_double-expected.txt b/ets2panda/test/parser/ets/test_jsvalue_get_double-expected.txt index 435dd5eb18b46f600ac005bab5dd87f043ed49aa..59de21d316643ba4412ad6bb533b38326006b41f 100644 --- a/ets2panda/test/parser/ets/test_jsvalue_get_double-expected.txt +++ b/ets2panda/test/parser/ets/test_jsvalue_get_double-expected.txt @@ -107,23 +107,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 17, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 17, + "column": 22 } } }, "loc": { "start": { - "line": 1, + "line": 17, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 17, + "column": 23 } } } @@ -242,12 +242,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 16, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 16, + "column": 16 } } }, @@ -291,12 +291,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 17, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 17, + "column": 18 } } } diff --git a/ets2panda/test/parser/ets/test_jsvalue_get_property_1-expected.txt b/ets2panda/test/parser/ets/test_jsvalue_get_property_1-expected.txt index b046e7b05299218614ef4fb73a88031287ede417..dfd10c05a70cb678eac98f913ed6c2dde59eb601 100644 --- a/ets2panda/test/parser/ets/test_jsvalue_get_property_1-expected.txt +++ b/ets2panda/test/parser/ets/test_jsvalue_get_property_1-expected.txt @@ -137,23 +137,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 17, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 17, + "column": 32 } } }, "loc": { "start": { - "line": 1, + "line": 17, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 17, + "column": 33 } } } @@ -272,12 +272,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 16, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 16, + "column": 16 } } }, @@ -349,12 +349,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 17, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 17, + "column": 20 } } } diff --git a/ets2panda/test/parser/ets/test_jsvalue_get_property_2-expected.txt b/ets2panda/test/parser/ets/test_jsvalue_get_property_2-expected.txt index fc03e2ef4a53b0e8fe9cc63697cac8b210ebc259..b19aae63841f98e1262b375be17e6061f97d1eb2 100644 --- a/ets2panda/test/parser/ets/test_jsvalue_get_property_2-expected.txt +++ b/ets2panda/test/parser/ets/test_jsvalue_get_property_2-expected.txt @@ -167,23 +167,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 17, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 17, + "column": 46 } } }, "loc": { "start": { - "line": 1, + "line": 17, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 17, + "column": 47 } } } @@ -302,12 +302,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 16, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 16, + "column": 16 } } }, @@ -379,12 +379,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 17, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 17, + "column": 20 } } } diff --git a/ets2panda/test/parser/ets/test_type_alias9-expected.txt b/ets2panda/test/parser/ets/test_type_alias9-expected.txt index 5c564550d19d44a0774bc63c5045f33b63eb2009..20df64b662c0a1a355500af56dffb173b65c20bf 100644 --- a/ets2panda/test/parser/ets/test_type_alias9-expected.txt +++ b/ets2panda/test/parser/ets/test_type_alias9-expected.txt @@ -214,23 +214,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 19, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 19, + "column": 16 } } }, "loc": { "start": { - "line": 1, + "line": 19, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 19, + "column": 17 } } }, @@ -385,23 +385,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 20, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 20, + "column": 51 } } }, "loc": { "start": { - "line": 1, + "line": 20, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 20, + "column": 52 } } } @@ -520,12 +520,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 19, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 19, + "column": 13 } } }, @@ -597,12 +597,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 20, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 20, + "column": 16 } } } diff --git a/ets2panda/test/parser/ets/throwsRethrowsAsVariables-expected.txt b/ets2panda/test/parser/ets/throwsRethrowsAsVariables-expected.txt index 58e965b05166f8b1e019b1bc05d24a37052ebdae..203a0147ad78122484ca1943d0a1535679d7cac4 100644 --- a/ets2panda/test/parser/ets/throwsRethrowsAsVariables-expected.txt +++ b/ets2panda/test/parser/ets/throwsRethrowsAsVariables-expected.txt @@ -106,23 +106,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 16, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 16, + "column": 15 } } }, "loc": { "start": { - "line": 1, + "line": 16, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 16, + "column": 16 } } }, @@ -162,23 +162,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 17, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 17, + "column": 17 } } }, "loc": { "start": { - "line": 1, + "line": 17, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 17, + "column": 18 } } } @@ -270,12 +270,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 16, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 16, + "column": 15 } } }, @@ -320,12 +320,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 17, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 17, + "column": 17 } } }, diff --git a/ets2panda/test/parser/ets/trailing_lambda_tests/trailing_lambda_mismatch_lambda_signature-expected.txt b/ets2panda/test/parser/ets/trailing_lambda_tests/trailing_lambda_mismatch_lambda_signature-expected.txt index 8520e0bd7d5ae0e815a0c66772d6f8a36063336a..fba13eb71c47ee15f33656c8ef2708ad9bd50150 100644 --- a/ets2panda/test/parser/ets/trailing_lambda_tests/trailing_lambda_mismatch_lambda_signature-expected.txt +++ b/ets2panda/test/parser/ets/trailing_lambda_tests/trailing_lambda_mismatch_lambda_signature-expected.txt @@ -106,23 +106,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 16, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 16, + "column": 10 } } }, "loc": { "start": { - "line": 1, + "line": 16, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 16, + "column": 10 } } } @@ -214,12 +214,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 16, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 16, + "column": 10 } } }, diff --git a/ets2panda/test/parser/ets/type_cast-expected.txt b/ets2panda/test/parser/ets/type_cast-expected.txt index f8965d9172a6034c67f5d6c0ef7d00f076bfad4b..cde9ff443ea1cbeafa4ca9a3593142d8d0c4df84 100644 --- a/ets2panda/test/parser/ets/type_cast-expected.txt +++ b/ets2panda/test/parser/ets/type_cast-expected.txt @@ -216,12 +216,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 19, + "column": 13 }, "end": { - "line": 1, - "column": 1 + "line": 19, + "column": 25 } } }, @@ -279,12 +279,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 20, + "column": 13 }, "end": { - "line": 1, - "column": 1 + "line": 20, + "column": 28 } } }, @@ -397,12 +397,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 21, + "column": 13 }, "end": { - "line": 1, - "column": 1 + "line": 21, + "column": 29 } } }, @@ -460,12 +460,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 22, + "column": 15 }, "end": { - "line": 1, - "column": 1 + "line": 22, + "column": 29 } } }, @@ -578,12 +578,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 23, + "column": 15 }, "end": { - "line": 1, - "column": 1 + "line": 23, + "column": 31 } } }, @@ -696,12 +696,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 24, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 24, + "column": 22 } } }, diff --git a/ets2panda/test/parser/ets/type_variance1-expected.txt b/ets2panda/test/parser/ets/type_variance1-expected.txt index 7006bc04a7b9cdc5fa1155d72fb7a50009e0a24a..526d6a2a596d5a2f79c9d894f7dd105a53196202 100644 --- a/ets2panda/test/parser/ets/type_variance1-expected.txt +++ b/ets2panda/test/parser/ets/type_variance1-expected.txt @@ -3245,12 +3245,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 20, + "column": 7 }, "end": { - "line": 1, - "column": 1 + "line": 20, + "column": 52 } } }, diff --git a/ets2panda/test/parser/ets/unary_op-expected.txt b/ets2panda/test/parser/ets/unary_op-expected.txt index cd8baaf5044840ba2b685491b90ccb156169ad0e..9a9d965671f43a0614d6fbf981349d914768d60c 100644 --- a/ets2panda/test/parser/ets/unary_op-expected.txt +++ b/ets2panda/test/parser/ets/unary_op-expected.txt @@ -106,23 +106,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 16, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 16, + "column": 10 } } }, "loc": { "start": { - "line": 1, + "line": 16, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 16, + "column": 11 } } }, @@ -178,23 +178,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 17, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 17, + "column": 12 } } }, "loc": { "start": { - "line": 1, + "line": 17, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 17, + "column": 13 } } }, @@ -250,23 +250,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 18, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 18, + "column": 12 } } }, "loc": { "start": { - "line": 1, + "line": 18, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 18, + "column": 13 } } }, @@ -321,23 +321,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 19, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 19, + "column": 11 } } }, "loc": { "start": { - "line": 1, + "line": 19, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 19, + "column": 12 } } }, @@ -393,23 +393,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 20, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 20, + "column": 11 } } }, "loc": { "start": { - "line": 1, + "line": 20, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 20, + "column": 12 } } }, @@ -465,23 +465,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 21, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 21, + "column": 11 } } }, "loc": { "start": { - "line": 1, + "line": 21, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 21, + "column": 12 } } }, @@ -521,23 +521,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 22, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 22, + "column": 13 } } }, "loc": { "start": { - "line": 1, + "line": 22, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 22, + "column": 14 } } }, @@ -593,23 +593,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 23, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 23, + "column": 11 } } }, "loc": { "start": { - "line": 1, + "line": 23, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 23, + "column": 12 } } }, @@ -665,23 +665,23 @@ }, "loc": { "start": { - "line": 1, - "column": 1 + "line": 25, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 25, + "column": 11 } } }, "loc": { "start": { - "line": 1, + "line": 25, "column": 1 }, "end": { - "line": 1, - "column": 1 + "line": 25, + "column": 12 } } } @@ -773,12 +773,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 16, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 16, + "column": 10 } } }, @@ -839,12 +839,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 17, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 17, + "column": 12 } } }, @@ -905,12 +905,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 18, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 18, + "column": 12 } } }, @@ -970,12 +970,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 19, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 19, + "column": 11 } } }, @@ -1036,12 +1036,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 20, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 20, + "column": 11 } } }, @@ -1102,12 +1102,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 21, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 21, + "column": 11 } } }, @@ -1152,12 +1152,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 22, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 22, + "column": 13 } } }, @@ -1218,12 +1218,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 23, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 23, + "column": 11 } } }, @@ -1268,12 +1268,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 24, + "column": 7 }, "end": { - "line": 1, - "column": 1 + "line": 24, + "column": 15 } } }, @@ -1334,12 +1334,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 25, + "column": 5 }, "end": { - "line": 1, - "column": 1 + "line": 25, + "column": 11 } } } diff --git a/ets2panda/test/parser/ets/unary_operations-expected.txt b/ets2panda/test/parser/ets/unary_operations-expected.txt index 685a1b84e0bcc96305addc11dc566510c0a54ada..4dcbbcdf600992a032c1eb9ecee891a2932e7571 100644 --- a/ets2panda/test/parser/ets/unary_operations-expected.txt +++ b/ets2panda/test/parser/ets/unary_operations-expected.txt @@ -216,12 +216,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 19, + "column": 13 }, "end": { - "line": 1, - "column": 1 + "line": 19, + "column": 23 } } }, @@ -323,12 +323,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 20, + "column": 13 }, "end": { - "line": 1, - "column": 1 + "line": 20, + "column": 33 } } }, @@ -430,12 +430,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 21, + "column": 13 }, "end": { - "line": 1, - "column": 1 + "line": 21, + "column": 33 } } }, @@ -537,12 +537,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 22, + "column": 13 }, "end": { - "line": 1, - "column": 1 + "line": 22, + "column": 34 } } }, @@ -644,12 +644,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 23, + "column": 13 }, "end": { - "line": 1, - "column": 1 + "line": 23, + "column": 34 } } }, @@ -751,12 +751,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 24, + "column": 13 }, "end": { - "line": 1, - "column": 1 + "line": 24, + "column": 33 } } }, @@ -814,12 +814,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 25, + "column": 13 }, "end": { - "line": 1, - "column": 1 + "line": 25, + "column": 31 } } }, @@ -921,12 +921,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 26, + "column": 13 }, "end": { - "line": 1, - "column": 1 + "line": 26, + "column": 37 } } }, @@ -1028,12 +1028,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 27, + "column": 13 }, "end": { - "line": 1, - "column": 1 + "line": 27, + "column": 34 } } }, @@ -1135,12 +1135,12 @@ "decorators": [], "loc": { "start": { - "line": 1, - "column": 1 + "line": 28, + "column": 13 }, "end": { - "line": 1, - "column": 1 + "line": 28, + "column": 34 } } }, diff --git a/ets2panda/test/runtime/ets/DefaultParam_1.ets b/ets2panda/test/runtime/ets/DefaultParam_1.ets index af964ea38290210115ffa3634a3cb9ead5e0d2fa..72368a9610877e34c916d6490be473bf4c892aca 100644 --- a/ets2panda/test/runtime/ets/DefaultParam_1.ets +++ b/ets2panda/test/runtime/ets/DefaultParam_1.ets @@ -35,16 +35,6 @@ function main():void{ assert foo15(10,5) == 20; assert foo16(10,5) == 30; - - - assert foo17(1,2) == 1; - assert foo17(1,9999999999) == 2; - - assert foo18(1,2) == 1; - assert foo18(1,false) == 2; - - assert foo19(1,2) == 1; - assert foo19(1,c'a') == 2; } function foo1(a : int = 10) : int { @@ -96,27 +86,3 @@ function foo15(a : int, b : int, c : int = 5) : int { function foo16(a : int, b : int, c : int = 10, d : int = 5) : int { return a + b + c + d; } - -function foo17(a : int, b : int = 20, c : int = 30) : int { - return 1; -} - -function foo17(a : int, b : long = 20, c : int = 30) : int { - return 2; -} - -function foo18(a : int, b : int = 20, c : int = 30) : int { - return 1; -} - -function foo18(a : int, b : boolean = true, c : int = 30) : int { - return 2; -} - -function foo19(a : int, b : int = 20, c : int = 30) : int { - return 1; -} - -function foo19(a : int, b : char = c'a', c : int = 30) : int { - return 2; -} diff --git a/ets2panda/test/runtime/ets/DefaultParam_2.ets b/ets2panda/test/runtime/ets/DefaultParam_2.ets index d00f90d1989f11f944f16efa9f74c75462dcd8e8..c82f36b460aab51764a5f0cb312c113e8ea06503 100644 --- a/ets2panda/test/runtime/ets/DefaultParam_2.ets +++ b/ets2panda/test/runtime/ets/DefaultParam_2.ets @@ -43,15 +43,6 @@ function main():void{ assert foo15(new Int(10),new Int(5)) == 20; assert foo16(new Int(10),new Int(5)) == 30; - - assert foo17(new Int(1),new Int(2)) == 1; - assert foo17(new Int(1),new Long(9999999999)) == 2; - - assert foo18(new Int(1),new Int(2)) == 1; - assert foo18(new Int(1),new Boolean(true)) == 2; - - assert foo19(new Int(1),new Int(1)) == 1; - assert foo19(new Int(1),"a") == 2; } function foo1(a : Int = 10) : Int { @@ -142,27 +133,3 @@ function foo15(a : Int, b : Int, c : Int = 5) : Int { function foo16(a : Int, b : Int, c : Int = 10, d : Int = 5) : Int { return a + b + c + d; } - -function foo17(a : Int, b : Int = 20, c : Int = 30) : Int { - return 1; -} - -function foo17(a : Int, b : Long = 9999999999, c : Int = 30) : Int { - return 2; -} - -function foo18(a : Int, b : Int = 20, c : Int = 30) : Int { - return 1; -} - -function foo18(a : Int, b : Boolean = true, c : Int = 30) : Int { - return 2; -} - -function foo19(a : Int, b : Int = 20, c : Int = 30) : Int { - return 1; -} - -function foo19(a : Int, b : string = "a", c : Int = 30) : Int { - return 2; -} diff --git a/ets2panda/test/runtime/ets/DefaultParam_4.ets b/ets2panda/test/runtime/ets/DefaultParam_4.ets index 696647a3b79e20d33363daf183484a23ef6ab8ba..38a37046f5d2a4536f7e35464002c74a2b7cfac5 100644 --- a/ets2panda/test/runtime/ets/DefaultParam_4.ets +++ b/ets2panda/test/runtime/ets/DefaultParam_4.ets @@ -45,15 +45,6 @@ function main():void{ assert boo.foo15(new Int(10),new Int(5)) == 20; assert boo.foo16(new Int(10),new Int(5)) == 30; - - assert boo.foo17(new Int(1),new Int(2)) == 1; - assert boo.foo17(new Int(1),new Long(9999999999)) == 2; - - assert boo.foo18(new Int(1),new Int(2)) == 1; - assert boo.foo18(new Int(1),new Boolean(true)) == 2; - - assert boo.foo19(new Int(1),new Int(1)) == 1; - assert boo.foo19(new Int(1),"a") == 2; } class bar { @@ -145,28 +136,4 @@ class bar { foo16(a : Int, b : Int, c : Int = 10, d : Int = 5) : Int { return a + b + c + d; } - - foo17(a : Int, b : Int = 20, c : Int = 30) : Int { - return 1; - } - - foo17(a : Int, b : Long = 9999999999, c : Int = 30) : Int { - return 2; - } - - foo18(a : Int, b : Int = 20, c : Int = 30) : Int { - return 1; - } - - foo18(a : Int, b : Boolean = true, c : Int = 30) : Int { - return 2; - } - - foo19(a : Int, b : Int = 20, c : Int = 30) : Int { - return 1; - } - - foo19(a : Int, b : string = "a", c : Int = 30) : Int { - return 2; - } } diff --git a/ets2panda/test/runtime/ets/StringBase64.ets b/ets2panda/test/runtime/ets/StringBase64.ets index 17e894db3d19df9f7cf25ab5aa797c8f813d13d0..ebca0d923bae6144cba88c3a8c91888ddf41cc3d 100644 --- a/ets2panda/test/runtime/ets/StringBase64.ets +++ b/ets2panda/test/runtime/ets/StringBase64.ets @@ -67,7 +67,7 @@ export class StringBase64 { } return result.toString(); } - n1 : int = 8192; + n1 : int = 4096; n2 : int = 16384; public run(): void { let str : String = ""; diff --git a/ets2panda/test/runtime/ets/assignment_lowering.ets b/ets2panda/test/runtime/ets/assignment_lowering.ets new file mode 100644 index 0000000000000000000000000000000000000000..75bbd8afd99dc0d06404023e421b1a5d68fbd492 --- /dev/null +++ b/ets2panda/test/runtime/ets/assignment_lowering.ets @@ -0,0 +1,43 @@ +/* + * 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. + */ + +class B { + c: int = 11; + d: int = 33; + public constructor() { + this.c += 22; + this.d -= 44; + } +} + +function main(): void { + + let b = new B(); + assert (b.c == 33); + assert (b.d == -11); + + let x: int[] = [1, 2, 3]; + + for (let i: int = 0; i < 3; ++i) { + i <<= 2; + + x[i >> 2] *= 2; + i >>= 2; + } + + for (let i: int = 0; i < 3; ++i) { + assert (x[i] == (i + 1) * 2); + } +} diff --git a/ets2panda/test/runtime/ets/autoboxing.ets b/ets2panda/test/runtime/ets/autoboxing.ets new file mode 100644 index 0000000000000000000000000000000000000000..f66dbbb41beb1e59fbe8b454950c4bdca77c0a9d --- /dev/null +++ b/ets2panda/test/runtime/ets/autoboxing.ets @@ -0,0 +1,35 @@ +/* + * 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. + */ + +function foo_i(value: int): string { + return value.toString(); +} + +function foo_d(value: double): string { + return value.toString(); +} + +function foo_n(value: number): string { + return value.toString(); +} + +function main(): void { + let str_i: string = foo_i(4); + assert str_i == "4"; + let str_d: string = foo_d(3.14); + assert str_d == "3.14"; + let str_n: string = foo_n(5); + assert str_n == "5"; +} \ No newline at end of file diff --git a/ets2panda/test/runtime/ets/condition-with-boolean-reference.ets b/ets2panda/test/runtime/ets/condition-with-boolean-reference.ets index afeab4d42883c20242e0282d38709e2920672987..1acb9754930406a5667c16a6545c776d8dec84ac 100644 --- a/ets2panda/test/runtime/ets/condition-with-boolean-reference.ets +++ b/ets2panda/test/runtime/ets/condition-with-boolean-reference.ets @@ -14,7 +14,7 @@ */ function main() : void { - let cond: Boolean = true; + let cond: boolean = true; // Check conditional expression let a: String = "foo"; @@ -39,13 +39,14 @@ function main() : void { assert(i == 3); // Check while statement - while (cond) { - cond = false; + let while_cond = true + while (while_cond) { + while_cond = !cond; } - assert (cond == false); + assert (while_cond == false); // Check do-while statement do { - assert (cond == false); - } while (cond); + assert (while_cond == false); + } while (while_cond); } diff --git a/ets2panda/test/runtime/ets/conversion-char-boolean.ets b/ets2panda/test/runtime/ets/conversion-char-boolean.ets index baa0ddaf614ab8e97a99219405246df2547f0e43..76f9ea8e29cc817dac783009e3bda81123d9b699 100644 --- a/ets2panda/test/runtime/ets/conversion-char-boolean.ets +++ b/ets2panda/test/runtime/ets/conversion-char-boolean.ets @@ -20,7 +20,7 @@ function check(): Boolean { function main(): void { let x: Boolean = false; - assert !(x && check()); + assert (x || check()); let y: Char = c'a'; assert (y != c'b'); diff --git a/ets2panda/test/runtime/ets/default_parameters.ets b/ets2panda/test/runtime/ets/default_parameters.ets new file mode 100644 index 0000000000000000000000000000000000000000..a660a80c0402aacf32fb2b3925706a3618af51aa --- /dev/null +++ b/ets2panda/test/runtime/ets/default_parameters.ets @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2021-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. + */ + +function foo(a: int = 3, b: int = 5): int { + return a * 10 + b; +} + +class C { + x: int; + y: int; + + constructor (a: int = 3, b: int = 5) { + this.x = a; + this.y = b; + } +} + +function main(): void { + + let res = foo(5, 7); + assert (res == 57); + + res = foo(7); + assert (res == 75); + + res = foo(); + assert (res == 35); + + let c0 = new C(); + assert (c0.x == 3 && c0.y == 5); + + let c1 = new C(7); + assert (c1.x == 7 && c1.y == 5); + + let c2 = new C(5, 7); + assert (c2.x == 5 && c2.y == 7); +} diff --git a/ets2panda/test/runtime/ets/exdended_conditional_expression_float.ets b/ets2panda/test/runtime/ets/exdended_conditional_expression_float.ets new file mode 100644 index 0000000000000000000000000000000000000000..1d07e495518354a1bbedce318bfb96313ac43886 --- /dev/null +++ b/ets2panda/test/runtime/ets/exdended_conditional_expression_float.ets @@ -0,0 +1,19 @@ +/* + * 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. + */ + +function main(): int { + let res: int = 0.1 ? 0 : 1 + return res +} \ No newline at end of file diff --git a/ets2panda/test/runtime/ets/extended_conditional_expression_string.ets b/ets2panda/test/runtime/ets/extended_conditional_expression_string.ets new file mode 100644 index 0000000000000000000000000000000000000000..f02379770060f14cd733ca1f152b4bf454508f46 --- /dev/null +++ b/ets2panda/test/runtime/ets/extended_conditional_expression_string.ets @@ -0,0 +1,32 @@ +/* + * 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. + */ + +function fun(s: Object) : boolean { + if (s) { + return true; + } else { + return false; + } +} + + +function main(): int { + let emptyString = ""; + if (fun(emptyString)) { + return 1; + } else { + return 0 + } +} \ No newline at end of file diff --git a/ets2panda/test/runtime/ets/lambdaExpressionWithRestParameter.ets b/ets2panda/test/runtime/ets/lambdaExpressionWithRestParameter.ets new file mode 100644 index 0000000000000000000000000000000000000000..b6f03111fa971471eaedff4788df753f36b1be11 --- /dev/null +++ b/ets2panda/test/runtime/ets/lambdaExpressionWithRestParameter.ets @@ -0,0 +1,36 @@ +/* + * 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. + */ + +type LambdaType = (prefix: string, ...args: string[]) => string; + + +function main(): void { + + let lam: LambdaType = (prefix: string, ...args: string[]): string => { + let ret = prefix; + for (let arg of args) { + ret += arg; + } + return ret; + } + + let x: string = lam("Test 1:", " case 1,", " case 2,", " case 3."); + assert (x == "Test 1: case 1, case 2, case 3."); + + let arr: string[] = [" case 4,", " case 5,", " case 6."]; + + let y = lam("Test 2:", ...arr); + assert (y == "Test 2: case 4, case 5, case 6."); +} diff --git a/ets2panda/test/runtime/ets/number-from-narrow-prim.ets b/ets2panda/test/runtime/ets/number-from-narrow-prim.ets new file mode 100644 index 0000000000000000000000000000000000000000..0c4744297c403b3b804c44fe10538ff22b76584b --- /dev/null +++ b/ets2panda/test/runtime/ets/number-from-narrow-prim.ets @@ -0,0 +1,24 @@ +/* + * 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. + * + * + * Based on https://gitee.com/openharmony/arkcompiler_ets_frontend/issues/I8EZ44 + */ + + +function main() { + let n: Number = 5 + + assert n == 5 +} diff --git a/ets2panda/test/runtime/ets/unboxingBooleanConversion.ets b/ets2panda/test/runtime/ets/unboxingBooleanConversion.ets index 4ee6904ae13e4915f4f2a1e0a5dd715bec9705a6..23ae74c084ab06775be988e3359841dcce893b3c 100644 --- a/ets2panda/test/runtime/ets/unboxingBooleanConversion.ets +++ b/ets2panda/test/runtime/ets/unboxingBooleanConversion.ets @@ -24,7 +24,7 @@ function returnRefBool(a: boolean): Boolean { function main(): void { let a: Boolean = false; - let b: Boolean = a || returnTrue(); + let b: Boolean = a && returnTrue(); assert b == true let c: Boolean = returnRefBool(a || returnRefBool(returnTrue() && returnRefBool(a))); diff --git a/ets2panda/test/ets-runtime-excluded-JIT-REPEATS.txt b/ets2panda/test/test-lists/ets-runtime/ets-runtime-excluded-JIT-REPEATS.txt similarity index 100% rename from ets2panda/test/ets-runtime-excluded-JIT-REPEATS.txt rename to ets2panda/test/test-lists/ets-runtime/ets-runtime-excluded-JIT-REPEATS.txt diff --git a/ets2panda/test/ets-runtime-ignored-ARM32-INT.txt b/ets2panda/test/test-lists/ets-runtime/ets-runtime-ignored-ARM32-INT.txt similarity index 100% rename from ets2panda/test/ets-runtime-ignored-ARM32-INT.txt rename to ets2panda/test/test-lists/ets-runtime/ets-runtime-ignored-ARM32-INT.txt diff --git a/ets2panda/test/ets-runtime-ignored.txt b/ets2panda/test/test-lists/ets-runtime/ets-runtime-ignored.txt similarity index 87% rename from ets2panda/test/ets-runtime-ignored.txt rename to ets2panda/test/test-lists/ets-runtime/ets-runtime-ignored.txt index 8ca4924b095a39133a6b5a97f6ba1b85bff53c24..d348c96b6c0159a6fccde481d6e04eb6eb9b7848 100644 --- a/ets2panda/test/ets-runtime-ignored.txt +++ b/ets2panda/test/test-lists/ets-runtime/ets-runtime-ignored.txt @@ -22,9 +22,6 @@ unboxing.ets # panda#11326 GenericsTest.ets -# panda#11106 -LongLiteralLimits.ets - # panda#11327 objectEquality.ets @@ -33,4 +30,4 @@ CastReference3.ets conditionalExpressionGenericLUB.ets # Failed due to lambda captures -trailing-lambda-with-capture.ets \ No newline at end of file +trailing-lambda-with-capture.ets diff --git a/ets2panda/test/parser-ets-ignored.txt b/ets2panda/test/test-lists/parser/parser-ets-ignored.txt similarity index 100% rename from ets2panda/test/parser-ets-ignored.txt rename to ets2panda/test/test-lists/parser/parser-ets-ignored.txt diff --git a/ets2panda/test/parser-js-ignored.txt b/ets2panda/test/test-lists/parser/parser-js-ignored.txt similarity index 100% rename from ets2panda/test/parser-js-ignored.txt rename to ets2panda/test/test-lists/parser/parser-js-ignored.txt diff --git a/ets2panda/test/union_types_4-expected.txt b/ets2panda/test/union_types_4-expected.txt deleted file mode 100644 index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..0000000000000000000000000000000000000000 diff --git a/ets2panda/test/unit/ast_dumper_test.cpp b/ets2panda/test/unit/ast_dumper_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..6d38b78fe12935540b47fd79bef2131b805105ce --- /dev/null +++ b/ets2panda/test/unit/ast_dumper_test.cpp @@ -0,0 +1,121 @@ +/** + * Copyright (c) 2021-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 +#include +#include "macros.h" + +#include "assembler/assembly-program.h" +#include "compiler/core/ASTVerifier.h" +#include "ir/astDump.h" +#include "ir/expressions/literals/stringLiteral.h" + +#include "bytecode_optimizer/bytecodeopt_options.h" +#include "compiler/compiler_logger.h" +#include "mem/arena_allocator.h" +#include "mem/pool_manager.h" +#include "es2panda.h" +#include "util/arktsconfig.h" +#include "util/generateBin.h" +#include "util/options.h" +#include "libpandabase/mem/mem.h" + +class ASTDumperTest : public testing::Test { +public: + ASTDumperTest() + { + constexpr auto COMPILER_SIZE = 268435456; + + panda::mem::MemConfig::Initialize(0, 0, COMPILER_SIZE, 0, 0, 0); + panda::PoolManager::Initialize(panda::PoolType::MMAP); + } + ~ASTDumperTest() override + { + panda::PoolManager::Finalize(); + panda::mem::MemConfig::Finalize(); + }; + + static panda::pandasm::Program *GetProgram(int argc, const char **argv, std::string_view file_name, + std::string_view src) + { + auto options = std::make_unique(); + if (!options->Parse(argc, argv)) { + std::cerr << options->ErrorMsg() << std::endl; + return nullptr; + } + + panda::Logger::ComponentMask mask {}; + mask.set(panda::Logger::Component::ES2PANDA); + panda::Logger::InitializeStdLogging(panda::Logger::LevelFromString(options->LogLevel()), mask); + + panda::es2panda::Compiler compiler(options->Extension(), options->ThreadCount()); + panda::es2panda::SourceFile input(file_name, src, options->ParseModule()); + + return compiler.Compile(input, options->CompilerOptions()); + } + + NO_COPY_SEMANTIC(ASTDumperTest); + NO_MOVE_SEMANTIC(ASTDumperTest); + +private: +}; + +TEST_F(ASTDumperTest, DumpJsonSimple) +{ + static constexpr std::string_view FILE_NAME = "dummy.ets"; + static constexpr std::string_view SRC = + "\ + function main(args: String[]): int {\ + let a: int = 2;\ + let b: int = 3;\ + return a + b;\ + }"; + + int argc = 0; + const char *argv = ""; + + auto program = std::unique_ptr {GetProgram(argc, &argv, FILE_NAME, SRC)}; + + ASSERT_NE(program, nullptr); + + auto dump_str = program->JsonDump(); + + ASSERT_FALSE(dump_str.empty()); +} + +TEST_F(ASTDumperTest, DumpJsonUTF16Char) +{ + static constexpr std::string_view FILE_NAME = "dummy.ets"; + static constexpr std::string_view SRC = + "\ + function main(args: String[]): int {\ + let a: char = c'\\uDBFF';\ + let b: char = c'\\uDC00';\ + console.log(a);\ + console.log(b);\ + return 0;\ + }"; + + int argc = 0; + const char *argv = ""; + + auto program = std::unique_ptr {GetProgram(argc, &argv, FILE_NAME, SRC)}; + + ASSERT_NE(program, nullptr); + + auto dump_str = program->JsonDump(); + + ASSERT_FALSE(dump_str.empty()); +} diff --git a/ets2panda/test/public/ast_verifier_test.cpp b/ets2panda/test/unit/public/ast_verifier_test.cpp similarity index 100% rename from ets2panda/test/public/ast_verifier_test.cpp rename to ets2panda/test/unit/public/ast_verifier_test.cpp diff --git a/ets2panda/test/unit/public/e2p_test_plugin.c b/ets2panda/test/unit/public/e2p_test_plugin.c new file mode 100644 index 0000000000000000000000000000000000000000..2de3ca54a7544505776c8c793151fc32847cd4b5 --- /dev/null +++ b/ets2panda/test/unit/public/e2p_test_plugin.c @@ -0,0 +1,57 @@ +/** + * 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. + */ + +// No linting for pure C file +// NOLINTBEGIN + +#include +#include + +#include "public/es2panda_lib.h" + +static struct es2panda_Impl const *impl = NULL; + +void e2p_test_plugin_Initialize() +{ + puts("Hi there!"); + impl = es2panda_GetImpl(ES2PANDA_LIB_VERSION); +} + +static void PrintIfIdentifier(es2panda_AstNode *node, void *arg) +{ + es2panda_Context *ctx = arg; + if (impl->IsIdentifier(node)) { + puts(impl->IdentifierName(ctx, node)); + } +} + +void e2p_test_plugin_AfterParse(es2panda_Context *ctx) +{ + puts("After parse"); + es2panda_AstNode *ast = impl->ProgramAst(impl->ContextProgram(ctx)); + impl->AstNodeForEach(ast, PrintIfIdentifier, ctx); +} + +void e2p_test_plugin_AfterCheck(es2panda_Context *ctx) +{ + puts("After check"); +} + +void e2p_test_plugin_AfterLowerings(es2panda_Context *ctx) +{ + puts("After lowerings"); +} + +// NOLINTEND diff --git a/ets2panda/test/public/es2panda_public_test.cpp b/ets2panda/test/unit/public/es2panda_public_test.cpp similarity index 57% rename from ets2panda/test/public/es2panda_public_test.cpp rename to ets2panda/test/unit/public/es2panda_public_test.cpp index 03846b4edb2ad52bc77c706bb89004f1a4cb8c28..723fd07de0e1eab8243f6312eb72f5d8d1972c97 100644 --- a/ets2panda/test/public/es2panda_public_test.cpp +++ b/ets2panda/test/unit/public/es2panda_public_test.cpp @@ -53,10 +53,51 @@ TEST_F(Es2PandaLibTest, NoError) TEST_F(Es2PandaLibTest, TypeError) { es2panda_Context *ctx = - impl_->CreateContextFromString(cfg_, "function main() { let x: int = \"\" }", "no-error.ets"); - impl_->ProceedToState(ctx, ES2PANDA_STATE_ASM_GENERATED); // don't produce any object files + impl_->CreateContextFromString(cfg_, "function main() { let x: int = \"\" }", "type-error.ets"); + impl_->ProceedToState(ctx, ES2PANDA_STATE_ASM_GENERATED); ASSERT_EQ(impl_->ContextState(ctx), ES2PANDA_STATE_ERROR); ASSERT_EQ(std::string(impl_->ContextErrorMessage(ctx)), - "TypeError: Initializers type is not assignable to the target type[no-error.ets:1,32]"); + "TypeError: Initializers type is not assignable to the target type[type-error.ets:1,32]"); + impl_->DestroyContext(ctx); +} + +TEST_F(Es2PandaLibTest, ListIdentifiers) +{ + char const *text = R"XXX( +class C { + n: string = "oh" +} + +function main() { + let c = new C + console.log(c.n + 1) // type error, but not syntax error +} +)XXX"; + es2panda_Context *ctx = impl_->CreateContextFromString(cfg_, text, "list-ids.ets"); + ctx = impl_->ProceedToState(ctx, ES2PANDA_STATE_PARSED); + ASSERT_EQ(impl_->ContextState(ctx), ES2PANDA_STATE_PARSED); + + struct Arg { + es2panda_Impl const *impl = nullptr; + es2panda_Context *ctx = nullptr; + std::vector ids; + } arg; + arg.impl = impl_; + arg.ctx = ctx; + + auto func = [](es2panda_AstNode *ast, void *argp) { + auto *a = reinterpret_cast(argp); + if (a->impl->IsIdentifier(ast)) { + a->ids.emplace_back(a->impl->IdentifierName(a->ctx, ast)); + } + }; + + impl_->AstNodeForEach(impl_->ProgramAst(impl_->ContextProgram(ctx)), func, &arg); + + std::vector expected {"C", "n", "string", "constructor", "constructor", "ETSGLOBAL", + "_$init$_", "_$init$_", "main", "main", "c", "C", + "console", "log", "c", "n", ""}; + ASSERT_EQ(arg.ids, expected); + impl_->DestroyContext(ctx); } diff --git a/ets2panda/test/unit/public/plugin_test.expected.txt b/ets2panda/test/unit/public/plugin_test.expected.txt new file mode 100644 index 0000000000000000000000000000000000000000..f578824e8435dd77777c35b1233f0e02b4ea338d --- /dev/null +++ b/ets2panda/test/unit/public/plugin_test.expected.txt @@ -0,0 +1,16 @@ +Hi there! +After parse +ETSGLOBAL +_$init$_ +_$init$_ +main +main +m +n +console +log +m +n + +After check +After lowerings diff --git a/ets2panda/test/unit/public/t.ets b/ets2panda/test/unit/public/t.ets new file mode 100644 index 0000000000000000000000000000000000000000..56969fa7e1bbcadaafa51e626c343bb58a055f7f --- /dev/null +++ b/ets2panda/test/unit/public/t.ets @@ -0,0 +1,20 @@ +/** + * 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. + */ + +function main() { + let m: int = 1 + let n: int = 2 + console.log(m + n) +} diff --git a/ets2panda/util/helpers.cpp b/ets2panda/util/helpers.cpp index f0195c7dbcb05b58f1937f04574b15dbaa7a6c0a..b1f4abe0f922c5c9d3b8254d34c7016f3ec9581a 100644 --- a/ets2panda/util/helpers.cpp +++ b/ets2panda/util/helpers.cpp @@ -42,8 +42,8 @@ #include "ir/ets/etsParameterExpression.h" #include "ir/module/importDeclaration.h" #include "lexer/token/letters.h" -#include -#include +#include "libpandabase/utils/utf.h" +#include "libpandabase/os/filesystem.h" namespace panda::es2panda::util { // Helpers @@ -170,6 +170,40 @@ bool Helpers::IsRelativePath(const std::string &path) return ((path.find(current_dir_reference) == 0) || (path.find(parent_dir_reference) == 0)); } +std::string Helpers::GetAbsPath(const std::string &path) +{ + std::string full_file_path = path; + std::string import_extension; + if (!panda::os::file::File::IsRegularFile(path) && (panda::os::GetAbsolutePath(path).empty())) { + import_extension = ".ets"; + full_file_path = path + import_extension; + if (!panda::os::file::File::IsRegularFile(full_file_path)) { + import_extension = ".ts"; + full_file_path = path + import_extension; + if (!panda::os::file::File::IsRegularFile(full_file_path)) { + return path; + } + } + } + std::string abs_file_path = panda::os::GetAbsolutePath(full_file_path); + abs_file_path.erase(abs_file_path.find(import_extension), import_extension.size()); + return abs_file_path; +} + +bool Helpers::IsRealPath(const std::string &path) +{ + if (!panda::os::file::File::IsRegularFile(path) && (panda::os::GetAbsolutePath(path).empty())) { + auto import_extension = ".ets"; + if (!panda::os::file::File::IsRegularFile(path + import_extension)) { + import_extension = ".ts"; + if (!panda::os::file::File::IsRegularFile(path + import_extension)) { + return false; + } + } + } + return true; +} + const ir::ScriptFunction *Helpers::GetContainingConstructor(const ir::AstNode *node) { const ir::ScriptFunction *iter = GetContainingFunction(node); @@ -654,8 +688,8 @@ std::string Helpers::CreateEscapedString(const std::string &str) std::string Helpers::UTF16toUTF8(const char16_t c) { - std::wstring_convert, char16_t> convert {}; - return convert.to_bytes(c); + const utf::Utf8Char utf8_ch = utf::ConvertUtf16ToUtf8(c, 0, false); + return std::string(reinterpret_cast(utf8_ch.ch.data()), utf8_ch.n); } std::pair Helpers::SplitSignature(std::string_view signature) diff --git a/ets2panda/util/helpers.h b/ets2panda/util/helpers.h index 2611e7914153a1febb170e0ce3c5d93883de6292..bd32ed03a52f53ddab63ad9ec57bdb8bb4cf6f15 100644 --- a/ets2panda/util/helpers.h +++ b/ets2panda/util/helpers.h @@ -79,6 +79,8 @@ public: static util::StringView ToStringView(ArenaAllocator *allocator, int32_t number); static util::StringView ToStringView(ArenaAllocator *allocator, uint32_t number); static bool IsRelativePath(const std::string &path); + static bool IsRealPath(const std::string &path); + static std::string GetAbsPath(const std::string &path); static const ir::ScriptFunction *GetContainingConstructor(const ir::AstNode *node); static const ir::ScriptFunction *GetContainingConstructor(const ir::ClassProperty *node); diff --git a/ets2panda/util/options.cpp b/ets2panda/util/options.cpp index f5d6b87d989a9251c759e0300d71a9ce9f92c19a..f05099ad672a2ebebad10aaccc9559b9db65ed75 100644 --- a/ets2panda/util/options.cpp +++ b/ets2panda/util/options.cpp @@ -19,6 +19,11 @@ #include +#ifdef PANDA_WITH_BYTECODE_OPTIMIZER +#include "bytecode_optimizer/bytecodeopt_options.h" +#include "compiler/compiler_options.h" +#endif + namespace panda::es2panda::util { template T RemoveExtension(T const &filename) @@ -36,28 +41,113 @@ Options::~Options() delete argparser_; } -static std::unordered_set StringToStringSet(const std::string &str) +static std::vector SplitToStringVector(std::string const &str) { - std::unordered_set res; + std::vector res; std::string_view curr_str {str}; auto ix = curr_str.find(','); while (ix != std::string::npos) { if (ix != 0) { - res.insert(std::string(curr_str.substr(0, ix))); + res.emplace_back(curr_str.substr(0, ix)); } curr_str = curr_str.substr(ix + 1); ix = curr_str.find(','); } if (!curr_str.empty()) { - res.insert(std::string(curr_str)); + res.emplace_back(curr_str); } return res; } +static std::unordered_set SplitToStringSet(std::string const &str) +{ + std::vector vec = SplitToStringVector(str); + std::unordered_set res; + for (auto &elem : vec) { + res.emplace(elem); + } + return res; +} + +// NOLINTNEXTLINE(modernize-avoid-c-arrays, hicpp-avoid-c-arrays) +static void SplitArgs(int argc, const char *argv[], std::vector &es2panda_args, + std::vector &bco_compiler_args, std::vector &bytecodeopt_args) +{ + constexpr std::string_view COMPILER_PREFIX = "--bco-compiler"; + constexpr std::string_view OPTIMIZER_PREFIX = "--bco-optimizer"; + + enum class OptState { ES2PANDA, JIT_COMPILER, OPTIMIZER }; + OptState opt_state = OptState::ES2PANDA; + + std::unordered_map *> args_map = {{OptState::ES2PANDA, &es2panda_args}, + {OptState::JIT_COMPILER, &bco_compiler_args}, + {OptState::OPTIMIZER, &bytecodeopt_args}}; + + for (int i = 1; i < argc; i++) { + // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) + const char *arg_i = argv[i]; + if (COMPILER_PREFIX == arg_i) { + opt_state = OptState::JIT_COMPILER; + continue; + } + + if (OPTIMIZER_PREFIX == arg_i) { + opt_state = OptState::OPTIMIZER; + continue; + } + + args_map[opt_state]->emplace_back(arg_i); + opt_state = OptState::ES2PANDA; + } +} + +template +static bool ParseComponentArgs(const std::vector &args, T &options) +{ + panda::PandArgParser parser; + options.AddOptions(&parser); + if (!parser.Parse(args)) { + std::cerr << parser.GetErrorString(); + std::cerr << parser.GetHelpString(); + return false; + } + + if (auto options_err = options.Validate(); options_err) { + std::cerr << "Error: " << options_err.value().GetMessage() << std::endl; + return false; + } + + return true; +} + +static bool ParseBCOCompilerOptions([[maybe_unused]] const std::vector &compiler_args, + [[maybe_unused]] const std::vector &bytecodeopt_args) +{ +#ifdef PANDA_WITH_BYTECODE_OPTIMIZER + if (!ParseComponentArgs(compiler_args, panda::compiler::OPTIONS)) { + return false; + } + if (!ParseComponentArgs(bytecodeopt_args, panda::bytecodeopt::OPTIONS)) { + return false; + } +#endif + + return true; +} + // NOLINTNEXTLINE(readability-function-size) bool Options::Parse(int argc, const char **argv) { + std::vector es2panda_args; + std::vector bco_compiler_args; + std::vector bytecodeopt_args; + + SplitArgs(argc, argv, es2panda_args, bco_compiler_args, bytecodeopt_args); + if (!ParseBCOCompilerOptions(bco_compiler_args, bytecodeopt_args)) { + return false; + } + panda::PandArg op_help("help", false, "Print this message and exit"); // parser @@ -66,6 +156,8 @@ bool Options::Parse(int argc, const char **argv) panda::PandArg op_module("module", false, "Parse the input as module (JS only option)"); panda::PandArg op_parse_only("parse-only", false, "Parse the input only"); panda::PandArg op_dump_ast("dump-ast", false, "Dump the parsed AST"); + panda::PandArg op_dump_ast_only_silent( + "dump-ast-only-silent", false, "Dump parsed AST with all dumpers available but don't print to stdout"); panda::PandArg op_dump_checked_ast("dump-dynamic-ast", false, "Dump AST with synthetic nodes for dynamic languages"); panda::PandArg op_list_files("list-files", false, "Print names of files that are part of compilation"); @@ -85,6 +177,7 @@ bool Options::Parse(int argc, const char **argv) panda::PandArg log_level("log-level", "error", "Log-level"); panda::PandArg std_lib("stdlib", "", "Path to standard library"); panda::PandArg gen_std_lib("gen-stdlib", false, "Gen standard library"); + panda::PandArg plugins("plugins", "", "Plugins"); panda::PandArg skip_phases("skip-phases", "", "Phases to skip"); panda::PandArg dump_before_phases("dump-before-phases", "", "Generate program dump before running phases in the list"); @@ -98,6 +191,7 @@ bool Options::Parse(int argc, const char **argv) argparser_->Add(&op_help); argparser_->Add(&op_module); argparser_->Add(&op_dump_ast); + argparser_->Add(&op_dump_ast_only_silent); argparser_->Add(&op_dump_checked_ast); argparser_->Add(&op_parse_only); argparser_->Add(&op_dump_assembly); @@ -115,6 +209,7 @@ bool Options::Parse(int argc, const char **argv) argparser_->Add(&log_level); argparser_->Add(&std_lib); argparser_->Add(&gen_std_lib); + argparser_->Add(&plugins); argparser_->Add(&skip_phases); argparser_->Add(&dump_before_phases); argparser_->Add(&dump_after_phases); @@ -125,7 +220,7 @@ bool Options::Parse(int argc, const char **argv) argparser_->EnableTail(); argparser_->EnableRemainder(); - if (!argparser_->Parse(argc, argv) || op_help.GetValue()) { + if (!argparser_->Parse(es2panda_args) || op_help.GetValue()) { std::stringstream ss; ss << argparser_->GetErrorString() << std::endl; @@ -136,6 +231,12 @@ bool Options::Parse(int argc, const char **argv) ss << "optional arguments:" << std::endl; ss << argparser_->GetHelpString() << std::endl; + ss << std::endl; + ss << "--bco-optimizer: Argument directly to bytecode optimizer can be passed after this prefix" << std::endl; + ss << "--bco-compiler: Argument directly to jit-compiler inside bytecode optimizer can be passed after this " + "prefix" + << std::endl; + error_msg_ = ss.str(); return false; } @@ -290,6 +391,7 @@ bool Options::Parse(int argc, const char **argv) compiler_options_.ts_decl_out = op_ts_decl_out.GetValue(); compiler_options_.dump_asm = op_dump_assembly.GetValue(); compiler_options_.dump_ast = op_dump_ast.GetValue(); + compiler_options_.op_dump_ast_only_silent = op_dump_ast_only_silent.GetValue(); compiler_options_.dump_checked_ast = op_dump_checked_ast.GetValue(); compiler_options_.dump_debug_info = op_dump_debug_info.GetValue(); compiler_options_.is_debug = op_debug_info.GetValue(); @@ -297,9 +399,10 @@ bool Options::Parse(int argc, const char **argv) compiler_options_.std_lib = std_lib.GetValue(); compiler_options_.compilation_mode = compilation_mode; compiler_options_.is_ets_module = op_ets_module.GetValue(); - compiler_options_.skip_phases = StringToStringSet(skip_phases.GetValue()); - compiler_options_.dump_before_phases = StringToStringSet(dump_before_phases.GetValue()); - compiler_options_.dump_after_phases = StringToStringSet(dump_after_phases.GetValue()); + compiler_options_.plugins = SplitToStringVector(plugins.GetValue()); + compiler_options_.skip_phases = SplitToStringSet(skip_phases.GetValue()); + compiler_options_.dump_before_phases = SplitToStringSet(dump_before_phases.GetValue()); + compiler_options_.dump_after_phases = SplitToStringSet(dump_after_phases.GetValue()); return true; } diff --git a/ets2panda/util/plugin.cpp b/ets2panda/util/plugin.cpp new file mode 100644 index 0000000000000000000000000000000000000000..74c1e273fdf397e8568e098809249f668265318d --- /dev/null +++ b/ets2panda/util/plugin.cpp @@ -0,0 +1,55 @@ +/** + * Copyright (c) 2021-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. + */ +#include "plugin.h" +#include "os/library_loader.h" + +namespace panda::es2panda::util { + +std::string Plugin::FullNameForProcedure(std::string const &short_name) +{ + return std::string(name_.Utf8()) + "_" + short_name; +} + +Plugin::Plugin(util::StringView const &name) : name_ {name}, err_ {0}, h_ {nullptr} +{ + std::string so_name = + os::library_loader::DYNAMIC_LIBRARY_PREFIX + std::string(name) + os::library_loader::DYNAMIC_LIBRARY_SUFFIX; + if (auto load_res = os::library_loader::Load(so_name); load_res.HasValue()) { + h_ = std::move(load_res.Value()); + } else { + err_ = load_res.Error(); + ok_ = false; + } + + if (auto init_res = os::library_loader::ResolveSymbol(h_, FullNameForProcedure("Initialize")); + init_res.HasValue()) { + initialize_ = reinterpret_cast(init_res.Value()); + } + + if (auto ap_res = os::library_loader::ResolveSymbol(h_, FullNameForProcedure("AfterParse")); ap_res.HasValue()) { + after_parse_ = reinterpret_cast(ap_res.Value()); + } + + if (auto ac_res = os::library_loader::ResolveSymbol(h_, FullNameForProcedure("AfterCheck")); ac_res.HasValue()) { + after_check_ = reinterpret_cast(ac_res.Value()); + } + + if (auto al_res = os::library_loader::ResolveSymbol(h_, FullNameForProcedure("AfterLowerings")); + al_res.HasValue()) { + after_lowerings_ = reinterpret_cast(al_res.Value()); + } +} + +} // namespace panda::es2panda::util diff --git a/ets2panda/util/plugin.h b/ets2panda/util/plugin.h new file mode 100644 index 0000000000000000000000000000000000000000..74fd3c88563c537aa91323be61beff536075fc04 --- /dev/null +++ b/ets2panda/util/plugin.h @@ -0,0 +1,87 @@ +/** + * Copyright (c) 2021-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. + */ +#ifndef ES2PANDA_UTIL_PLUGINS_H +#define ES2PANDA_UTIL_PLUGINS_H + +#include "macros.h" +#include "os/library_loader.h" +#include "public/es2panda_lib.h" +#include "util/ustring.h" + +namespace panda::es2panda::util { + +class Plugin { +public: + explicit Plugin(util::StringView const &name); + ~Plugin() = default; + + NO_COPY_SEMANTIC(Plugin); + DEFAULT_MOVE_SEMANTIC(Plugin); + + bool IsOk() + { + return ok_; + } + + os::Error Error() + { + return err_; + } + + void Initialize() const + { + if (initialize_ != nullptr) { + initialize_(); + } + } + + void AfterParse(es2panda_Context *context) const + { + if (after_parse_ != nullptr) { + after_parse_(context); + } + } + + void AfterCheck(es2panda_Context *context) const + { + if (after_check_ != nullptr) { + after_check_(context); + } + } + + void AfterLowerings(es2panda_Context *context) const + { + if (after_lowerings_ != nullptr) { + after_lowerings_(context); + } + } + +private: + std::string FullNameForProcedure(std::string const &short_name); + + util::StringView name_; + bool ok_ {true}; + os::Error err_; + os::library_loader::LibraryHandle h_; + + void (*initialize_)() = nullptr; + void (*after_parse_)(es2panda_Context *) = nullptr; + void (*after_check_)(es2panda_Context *) = nullptr; + void (*after_lowerings_)(es2panda_Context *) = nullptr; +}; + +} // namespace panda::es2panda::util + +#endif diff --git a/ets2panda/varbinder/ETSBinder.cpp b/ets2panda/varbinder/ETSBinder.cpp index cd271713f1002ce6f728df4394d835ba25d759b4..61c93cd5b95543c6bf55f05b30c6d8353eeb0630 100644 --- a/ets2panda/varbinder/ETSBinder.cpp +++ b/ets2panda/varbinder/ETSBinder.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021 - 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 @@ -133,6 +133,40 @@ void ETSBinder::LookupTypeReference(ir::Identifier *ident, bool allow_dynamic_na ThrowUnresolvableType(ident->Start(), name); } +void ETSBinder::ResolveReferencesForScope(ir::AstNode const *const parent, Scope *const scope) +{ + parent->Iterate([this, scope](auto *node) { ResolveReferenceForScope(node, scope); }); +} + +void ETSBinder::ResolveReferenceForScope(ir::AstNode *const node, Scope *const scope) +{ + switch (node->Type()) { + case ir::AstNodeType::IDENTIFIER: { + auto *ident = node->AsIdentifier(); + if (auto const res = scope->Find(ident->Name(), ResolveBindingOptions::ALL); res.variable != nullptr) { + ident->SetVariable(res.variable); + } + break; + } + case ir::AstNodeType::VARIABLE_DECLARATOR: { + auto scope_ctx = LexicalScope::Enter(this, scope); + BuildVarDeclarator(node->AsVariableDeclarator()); + break; + } + /* Maybe will be used + case ir::AstNodeType::BLOCK_STATEMENT: { + auto scope_ctx = LexicalScope::Enter(this, node->AsBlockStatement()->Scope()); + ResolveReferences(node); + break; + } + */ + default: { + ResolveReferencesForScope(node, scope); + break; + } + } +} + void ETSBinder::LookupIdentReference(ir::Identifier *ident) { const auto &name = ident->Name(); @@ -548,6 +582,23 @@ varbinder::Variable *ETSBinder::FindStaticBinding(const ArenaVectorsecond; } +ArenaVector ETSBinder::GetExternalProgram(const util::StringView &source_name, + const ir::StringLiteral *import_path) +{ + const auto &ext_records = global_record_table_.Program()->ExternalSources(); + auto record_res = [this, ext_records, source_name]() { + auto res = ext_records.find(source_name); + return (res != ext_records.end()) ? res : ext_records.find(GetResolvedImportPath(source_name)); + }(); + if (record_res == ext_records.end()) { + ThrowError(import_path->Start(), "Cannot find import: " + std::string(source_name)); + } + + ASSERT(!record_res->second.empty()); + + return record_res->second; +} + void ETSBinder::AddSpecifiersToTopBindings(ir::AstNode *const specifier, const ir::ETSImportDeclaration *const import) { const ir::StringLiteral *const import_path = import->Source(); @@ -557,18 +608,20 @@ void ETSBinder::AddSpecifiersToTopBindings(ir::AstNode *const specifier, const i return; } - const auto &ext_records = global_record_table_.Program()->ExternalSources(); - const util::StringView source_name = - (import->Module() == nullptr) - ? import_path->Str() - : util::UString(import_path->Str().Mutf8() + import->Module()->Str().Mutf8(), Allocator()).View(); - const auto record_res = ext_records.find(source_name); - if (record_res == ext_records.end()) { - ThrowError(import_path->Start(), "Cannot find import: " + std::string(source_name)); - } + const util::StringView source_name = [import, import_path, this]() { + if (import->Module() == nullptr) { + return import_path->Str(); + } + char path_delimiter = panda::os::file::File::GetPathDelim().at(0); + auto str_import_path = import_path->Str().Mutf8(); + if (str_import_path.find(path_delimiter) == (str_import_path.size() - 1)) { + return util::UString(str_import_path + import->Module()->Str().Mutf8(), Allocator()).View(); + } + return util::UString(str_import_path + path_delimiter + import->Module()->Str().Mutf8(), Allocator()).View(); + }(); - ASSERT(!record_res->second.empty()); - const auto *const import_program = record_res->second.front(); + auto record = GetExternalProgram(source_name, import_path); + const auto *const import_program = record.front(); const auto *const import_global_scope = import_program->GlobalScope(); const auto &global_bindings = import_global_scope->Bindings(); @@ -584,7 +637,7 @@ void ETSBinder::AddSpecifiersToTopBindings(ir::AstNode *const specifier, const i return; } - if (AddImportSpecifiersToTopBindings(specifier, global_bindings, import, record_res->second)) { + if (AddImportSpecifiersToTopBindings(specifier, global_bindings, import, record)) { return; } @@ -594,7 +647,7 @@ void ETSBinder::AddSpecifiersToTopBindings(ir::AstNode *const specifier, const i auto item = std::find_if(global_bindings.begin(), global_bindings.end(), predicate_func); if (item == global_bindings.end()) { insert_foreign_binding(specifier->AsImportDefaultSpecifier()->Local()->Name(), - FindStaticBinding(record_res->second, import_path)); + FindStaticBinding(record, import_path)); return; } diff --git a/ets2panda/varbinder/ETSBinder.h b/ets2panda/varbinder/ETSBinder.h index 32b7feae10e0d0f8ee9cc872b07369f5db05bc42..48d7cf964ec457b0a99015b9c082b3f6925b2ac5 100644 --- a/ets2panda/varbinder/ETSBinder.h +++ b/ets2panda/varbinder/ETSBinder.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021 - 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 @@ -43,7 +43,8 @@ public: dynamic_imports_(Allocator()->Adapter()), lambda_objects_(Allocator()->Adapter()), dynamic_import_vars_(Allocator()->Adapter()), - import_specifiers_(Allocator()->Adapter()) + import_specifiers_(Allocator()->Adapter()), + resolved_import_pathes_map_(Allocator()->Adapter()) { InitImplicitThisParam(); } @@ -119,6 +120,8 @@ public: void BuildImportDeclaration(ir::ETSImportDeclaration *decl); void BuildETSNewClassInstanceExpression(ir::ETSNewClassInstanceExpression *class_instance); void AddSpecifiersToTopBindings(ir::AstNode *specifier, const ir::ETSImportDeclaration *import); + ArenaVector GetExternalProgram(const util::StringView &source_name, + const ir::StringLiteral *import_path); bool AddImportNamespaceSpecifiersToTopBindings(ir::AstNode *specifier, const varbinder::Scope::VariableMap &global_bindings, const parser::Program *import_program, @@ -184,6 +187,26 @@ public: default_export_ = default_export; } + const ArenaUnorderedMap &ResolvedImportPathesMap() const + { + return resolved_import_pathes_map_; + } + + const util::StringView &GetResolvedImportPath(const util::StringView &path) const + { + ASSERT(resolved_import_pathes_map_.find(path) != resolved_import_pathes_map_.end()); + + return resolved_import_pathes_map_.find(path)->second; + } + + void FillResolvedImportPathes(const std::unordered_map &map, ArenaAllocator *allocator) + { + for (const auto &path : map) { + resolved_import_pathes_map_.emplace(util::UString(path.first, allocator).View(), + util::UString(path.second, allocator).View()); + } + } + bool IsDynamicModuleVariable(const Variable *var) const; bool IsDynamicNamespaceVariable(const Variable *var) const; const DynamicImportData *DynamicImportDataForVar(const Variable *var) const; @@ -198,6 +221,9 @@ import * from "std/interop/js"; import * from "escompat"; )"; + void ResolveReferenceForScope(ir::AstNode *node, Scope *scope); + void ResolveReferencesForScope(ir::AstNode const *parent, Scope *scope); + private: void BuildClassDefinitionImpl(ir::ClassDefinition *class_def); void InitImplicitThisParam(); @@ -215,6 +241,7 @@ private: DynamicImportVariables dynamic_import_vars_; ir::Identifier *this_param_ {}; ArenaVector> import_specifiers_; + ArenaUnorderedMap resolved_import_pathes_map_; ir::AstNode *default_export_ {}; }; diff --git a/ets2panda/varbinder/scope.cpp b/ets2panda/varbinder/scope.cpp index 8999d8cb9eb5e294fd1bbcdaacb90b8f39c38759..7d1e614da8bbcaec66a418514e48f1aa1ffdeb9c 100644 --- a/ets2panda/varbinder/scope.cpp +++ b/ets2panda/varbinder/scope.cpp @@ -480,7 +480,7 @@ Scope::InsertResult GlobalScope::InsertImpl(const util::StringView &name, Variab if (const bool exported = node->IsClassDefinition() ? node->Parent()->IsExported() : node->IsExported(); !exported) { if (!node->IsDefaultExported()) { - return Scope::InsertResult {{}, false}; + return Scope::InsertResult {Bindings().end(), false}; } } } diff --git a/ets2panda/varbinder/scope.h b/ets2panda/varbinder/scope.h index 644e49e5c4fb8212c5cfd4d348301a37ac194a26..c1c11520e3e6ff59618c14635b6bc1fe5159d3ca 100644 --- a/ets2panda/varbinder/scope.h +++ b/ets2panda/varbinder/scope.h @@ -73,7 +73,7 @@ public: NO_MOVE_SEMANTIC(Scope); using VariableMap = ArenaUnorderedMap; - using InsertResult = std::pair; + using InsertResult = std::pair; virtual ScopeType Type() const = 0; diff --git a/test262/config.py b/test262/config.py index 44501352a09130e61cb824e741f10638b6bbade9..7005c8b746baf9707533bf4b1bc9983012503ea0 100755 --- a/test262/config.py +++ b/test262/config.py @@ -22,9 +22,13 @@ Description: Execute 262 test suite configuration file import os from multiprocessing import cpu_count +FUZZY_DIR_NAME = 'fuzzy' +FUZZILLI_DIR_NAME = 'fuzzilli' +FUZZILLI_OUTPUT_DIR_NAME = 'output' DATA_DIR = os.path.join("test262", "data") ESHOST_DIR = os.path.join("test262", "eshost") HARNESS_DIR = os.path.join("test262", "harness") +FUZZY_DIR = os.path.join(FUZZY_DIR_NAME, FUZZILLI_DIR_NAME) BASE_OUT_DIR = os.path.join("out", "test262") @@ -87,10 +91,12 @@ TEST262_GIT_HASH = "6f4601d095a3899d6102f2c320b671495cbe8757" HARNESS_GIT_HASH = "9c499f028eb24e67781435c0bb442e00343eb39d" ESHOST_GIT_HASH = "fa2d4d27d9d6152002bdef36ee2d17e98b886268" ESNEXT_GIT_HASH = "281eb10b2844929a7c0ac04527f5b42ce56509fd" +FUZZY_GIT_HASH = "79c777839d23114e6f85322eefa6d44af53814ab" TEST262_GIT_URL = "https://gitee.com/hufeng20/test262.git" ESHOST_GIT_URL = "https://gitee.com/hufeng20/eshost.git" HARNESS_GIT_URL = "https://gitee.com/hufeng20/test262-harness.git" +FUZZY_GIT_URL = "https://gitee.com/mirrors_googleprojectzero/fuzzilli.git" SKIP_LIST_FILE = os.path.join("test262", "skip_tests.json") ES2ABC_SKIP_LIST_FILE = os.path.join("test262", "es2abc_skip_tests.json") @@ -107,7 +113,7 @@ ARK_FRONTEND_LIST = [ "ts2panda", "es2panda" ] - +ES2ABC_NAME = 'es2abc' ARK_FRONTEND_BINARY_LIST = [ os.path.join(DEFAULT_ARK_DIR, "build", "src", "index.js"), os.path.join(DEFAULT_ARK_DIR, "es2abc") @@ -116,7 +122,7 @@ ARK_FRONTEND_BINARY_LIST = [ DEFAULT_ARK_FRONTEND = ARK_FRONTEND_LIST[0] DEFAULT_ARK_FRONTEND_BINARY = ARK_FRONTEND_BINARY_LIST[0] DEFAULT_MERGE_ABC_BINARY = os.path.join(DEFAULT_ARK_DIR, "merge_abc") - +FUZZY_DEFAULT_ARK_FRONTEND_BINARY = os.path.join(ARGS_PREFIX, RK3568_PRODUCT_NAME, ARK_DIR_SUFFIX, ES2ABC_NAME) ARK_ARCH_LIST = [ "x64", "aarch64", @@ -127,6 +133,7 @@ DEFAULT_ARK_ARCH = ARK_ARCH_LIST[0] DEFAULT_OPT_LEVEL = 2 DEFAULT_ES2ABC_THREAD_COUNT = 0 DEFAULT_MERGE_ABC_MODE = 1 +DEFAULT_OPEN_FUZZILLI_MODE = False OHOS_TYPESCRIPT = "ohos-typescript-4.2.3-r2.tgz" OHOS_TYPESCRIPT_TGZ_PATH = f"{CODE_ROOT}/third_party/typescript/build_package/{OHOS_TYPESCRIPT}" diff --git a/test262/es2022_tests.txt b/test262/es2022_tests.txt index e0131662d890893208298dff8d6cc35b1f3d5efb..b0cdbf7ce4b825bc8e667befaa941a94425a9602 100644 --- a/test262/es2022_tests.txt +++ b/test262/es2022_tests.txt @@ -182,4 +182,2424 @@ language/statements/variable/dstr/ary-ptrn-elem-id-static-init-await-valid.js language/statements/variable/dstr/obj-ptrn-elem-id-static-init-await-invalid.js language/statements/variable/dstr/obj-ptrn-elem-id-static-init-await-valid.js language/statements/variable/static-init-await-binding-invalid.js -language/statements/variable/static-init-await-binding-valid.js \ No newline at end of file +language/statements/variable/static-init-await-binding-valid.js +language/expressions/class/cpn-class-expr-fields-methods-computed-property-name-from-assignment-expression-assignment.js +language/expressions/class/cpn-class-expr-fields-methods-computed-property-name-from-additive-expression-add.js +language/expressions/class/cpn-class-expr-fields-computed-property-name-from-expression-coalesce.js +language/expressions/class/cpn-class-expr-fields-computed-property-name-from-identifier.js +language/expressions/class/cpn-class-expr-fields-computed-property-name-from-additive-expression-subtract.js +language/expressions/class/cpn-class-expr-fields-methods-computed-property-name-from-condition-expression-true.js +language/expressions/class/cpn-class-expr-fields-methods-computed-property-name-from-numeric-literal.js +language/expressions/class/cpn-class-expr-fields-methods-computed-property-name-from-null.js +language/expressions/class/cpn-class-expr-fields-methods-computed-property-name-from-additive-expression-subtract.js +language/expressions/class/cpn-class-expr-fields-methods-computed-property-name-from-function-declaration.js +language/expressions/class/cpn-class-expr-fields-methods-computed-property-name-from-assignment-expression-bitwise-or.js +language/expressions/class/cpn-class-expr-fields-computed-property-name-from-multiplicative-expression-mult.js +language/expressions/class/cpn-class-expr-fields-computed-property-name-from-integer-separators.js +language/expressions/class/cpn-class-expr-fields-methods-computed-property-name-from-multiplicative-expression-div.js +language/expressions/class/cpn-class-expr-fields-methods-computed-property-name-from-expression-coalesce.js +language/expressions/class/cpn-class-expr-fields-methods-computed-property-name-from-multiplicative-expression-mult.js +language/expressions/class/cpn-class-expr-fields-methods-computed-property-name-from-integer-e-notational-literal.js +language/expressions/class/cpn-class-expr-fields-computed-property-name-from-expression-logical-or.js +language/expressions/class/cpn-class-expr-fields-computed-property-name-from-assignment-expression-coalesce.js +language/expressions/class/cpn-class-expr-fields-computed-property-name-from-math.js +language/expressions/class/cpn-class-expr-fields-methods-computed-property-name-from-condition-expression-false.js +language/expressions/class/cpn-class-expr-fields-computed-property-name-from-function-declaration.js +language/expressions/class/cpn-class-expr-fields-computed-property-name-from-assignment-expression-bitwise-or.js +language/expressions/class/cpn-class-expr-fields-computed-property-name-from-numeric-literal.js +language/expressions/class/cpn-class-expr-fields-methods-computed-property-name-from-assignment-expression-coalesce.js +language/expressions/class/elements/after-same-line-method-rs-field-identifier.js +language/expressions/class/elements/static-as-valid-instance-field-assigned.js +language/expressions/class/elements/regular-definitions-rs-field-identifier-initializer.js +language/expressions/class/elements/after-same-line-static-async-gen-computed-names.js +language/expressions/class/elements/init-err-evaluation.js +language/expressions/class/elements/same-line-async-gen-rs-field-identifier-initializer.js +language/expressions/class/elements/literal-name-init-err-contains-arguments.js +language/expressions/class/elements/regular-definitions-literal-names.js +language/expressions/class/elements/new-sc-line-gen-literal-names-asi.js +language/expressions/class/elements/new-sc-line-method-computed-symbol-names.js +language/expressions/class/elements/new-sc-line-method-string-literal-names.js +language/expressions/class/elements/multiple-stacked-definitions-rs-field-identifier-initializer.js +language/expressions/class/elements/new-sc-line-method-literal-names.js +language/expressions/class/elements/regular-definitions-rs-field-identifier.js +language/expressions/class/elements/redeclaration.js +language/expressions/class/elements/after-same-line-method-computed-names.js +language/expressions/class/elements/same-line-async-gen-literal-names-asi.js +language/expressions/class/elements/after-same-line-static-async-gen-literal-names.js +language/expressions/class/elements/equality-init-err-contains-super.js +language/expressions/class/elements/static-literal-init-err-contains-arguments.js +language/expressions/class/elements/same-line-async-method-literal-names-asi.js +language/expressions/class/elements/fields-string-name-static-propname-constructor.js +language/expressions/class/elements/static-comp-name-init-err-contains-super.js +language/expressions/class/elements/after-same-line-static-async-gen-rs-field-identifier.js +language/expressions/class/elements/after-same-line-method-literal-names-asi.js +language/expressions/class/elements/regular-definitions-string-literal-names.js +language/expressions/class/elements/after-same-line-static-method-literal-names.js +language/expressions/class/elements/comp-name-init-err-contains-super.js +language/expressions/class/elements/arrow-fnc-init-err-contains-super.js +language/expressions/class/elements/same-line-method-computed-symbol-names.js +language/expressions/class/elements/same-line-gen-rs-field-identifier-initializer.js +language/expressions/class/elements/init-value-incremental.js +language/expressions/class/elements/same-line-gen-literal-names-asi.js +language/expressions/class/elements/after-same-line-method-string-literal-names.js +language/expressions/class/elements/same-line-method-computed-names.js +language/expressions/class/elements/new-no-sc-line-method-computed-names.js +language/expressions/class/elements/ternary-init-err-contains-super.js +language/expressions/class/elements/new-sc-line-gen-rs-field-identifier-initializer.js +language/expressions/class/elements/after-same-line-static-gen-computed-names.js +language/expressions/class/elements/after-same-line-static-gen-rs-field-identifier-initializer.js +language/expressions/class/elements/after-same-line-method-computed-symbol-names.js +language/expressions/class/elements/new-sc-line-gen-literal-names.js +language/expressions/class/elements/multiple-stacked-definitions-rs-field-identifier.js +language/expressions/class/elements/same-line-async-method-computed-symbol-names.js +language/expressions/class/elements/nested-comp-name-init-err-contains-arguments.js +language/expressions/class/elements/nested-static-comp-name-init-err-contains-super.js +language/expressions/class/elements/field-declaration.js +language/expressions/class/elements/same-line-async-gen-computed-names.js +language/expressions/class/elements/fields-literal-name-propname-constructor.js +language/expressions/class/elements/wrapped-in-sc-computed-symbol-names.js +language/expressions/class/elements/after-same-line-static-method-literal-names-asi.js +language/expressions/class/elements/after-same-line-static-gen-rs-field-identifier.js +language/expressions/class/elements/static-as-valid-instance-field.js +language/expressions/class/elements/new-sc-line-method-rs-field-identifier-initializer.js +language/expressions/class/elements/new-sc-line-gen-computed-names.js +language/expressions/class/elements/nested-literal-name-init-err-contains-super.js +language/expressions/class/elements/typeof-init-err-contains-arguments.js +language/expressions/class/elements/fields-literal-name-static-propname-constructor.js +language/expressions/class/elements/regular-definitions-computed-names.js +language/expressions/class/elements/super-access-from-arrow-func-on-field.js +language/expressions/class/elements/ctor-called-after-fields-init.js +language/expressions/class/elements/same-line-method-literal-names-asi.js +language/expressions/class/elements/comp-name-init-err-contains-arguments.js +language/expressions/class/elements/new-no-sc-line-method-rs-field-identifier-initializer.js +language/expressions/class/elements/regular-definitions-computed-symbol-names.js +language/expressions/class/elements/same-line-gen-rs-field-identifier.js +language/expressions/class/elements/after-same-line-static-method-rs-field-identifier-initializer.js +language/expressions/class/elements/same-line-gen-computed-names.js +language/expressions/class/elements/new-sc-line-gen-string-literal-names.js +language/expressions/class/elements/same-line-async-gen-rs-field-identifier.js +language/expressions/class/elements/after-same-line-static-async-method-string-literal-names.js +language/expressions/class/elements/after-same-line-gen-literal-names.js +language/expressions/class/elements/fields-asi-2.js +language/expressions/class/elements/new-sc-line-method-computed-names.js +language/expressions/class/elements/regular-definitions-literal-names-asi.js +language/expressions/class/elements/same-line-gen-computed-symbol-names.js +language/expressions/class/elements/same-line-async-gen-computed-symbol-names.js +language/expressions/class/elements/fields-asi-1.js +language/expressions/class/elements/multiple-stacked-definitions-computed-symbol-names.js +language/expressions/class/elements/wrapped-in-sc-computed-names.js +language/expressions/class/elements/string-literal-name-init-err-contains-super.js +language/expressions/class/elements/after-same-line-static-gen-computed-symbol-names.js +language/expressions/class/elements/same-line-async-method-string-literal-names.js +language/expressions/class/elements/fields-string-name-static-propname-prototype.js +language/expressions/class/elements/nested-ternary-init-err-contains-arguments.js +language/expressions/class/elements/same-line-async-method-rs-field-identifier.js +language/expressions/class/elements/string-literal-name-init-err-contains-arguments.js +language/expressions/class/elements/arrow-fnc-init-err-contains-arguments.js +language/expressions/class/elements/same-line-async-method-computed-names.js +language/expressions/class/elements/new-sc-line-gen-computed-symbol-names.js +language/expressions/class/elements/after-same-line-static-method-string-literal-names.js +language/expressions/class/elements/static-comp-name-init-err-contains-arguments.js +language/expressions/class/elements/fields-asi-3.js +language/expressions/class/elements/after-same-line-gen-computed-names.js +language/expressions/class/elements/nested-typeof-init-err-contains-super.js +language/expressions/class/elements/after-same-line-static-async-method-computed-symbol-names.js +language/expressions/class/elements/multiple-stacked-definitions-string-literal-names.js +language/expressions/class/elements/nested-static-string-literal-name-init-err-contains-arguments.js +language/expressions/class/elements/after-same-line-gen-literal-names-asi.js +language/expressions/class/elements/multiple-stacked-definitions-literal-names.js +language/expressions/class/elements/equality-init-err-contains-arguments.js +language/expressions/class/elements/new-no-sc-line-method-literal-names-asi.js +language/expressions/class/elements/after-same-line-static-async-gen-computed-symbol-names.js +language/expressions/class/elements/evaluation-error/computed-name-referenceerror.js +language/expressions/class/elements/nested-string-literal-name-init-err-contains-super.js +language/expressions/class/elements/wrapped-in-sc-rs-field-identifier.js +language/expressions/class/elements/after-same-line-static-method-rs-field-identifier.js +language/expressions/class/elements/nested-static-string-literal-name-init-err-contains-super.js +language/expressions/class/elements/after-same-line-gen-string-literal-names.js +language/expressions/class/elements/same-line-async-method-literal-names.js +language/expressions/class/elements/nested-arrow-fnc-init-err-contains-super.js +language/expressions/class/elements/after-same-line-static-gen-literal-names.js +language/expressions/class/elements/after-same-line-static-async-gen-literal-names-asi.js +language/expressions/class/elements/fields-asi-same-line-1.js +language/expressions/class/elements/nested-ternary-init-err-contains-super.js +language/expressions/class/elements/ternary-init-err-contains-arguments.js +language/expressions/class/elements/fields-asi-5.js +language/expressions/class/elements/new-no-sc-line-method-literal-names.js +language/expressions/class/elements/nested-static-literal-init-err-contains-arguments.js +language/expressions/class/elements/intercalated-static-non-static-computed-fields.js +language/expressions/class/elements/typeof-init-err-contains-super.js +language/expressions/class/elements/after-same-line-static-gen-literal-names-asi.js +language/expressions/class/elements/same-line-async-gen-string-literal-names.js +language/expressions/class/elements/syntax/early-errors/grammar-field-identifier-invalid-zwj-error.js +language/expressions/class/elements/syntax/early-errors/grammar-fields-same-line-error.js +language/expressions/class/elements/syntax/early-errors/grammar-field-identifier-invalid-ues-error.js +language/expressions/class/elements/syntax/early-errors/grammar-field-identifier-invalid-zwnj-error.js +language/expressions/class/elements/syntax/valid/grammar-field-classelementname-initializer-alt.js +language/expressions/class/elements/syntax/valid/grammar-field-identifier-alt.js +language/expressions/class/elements/syntax/valid/grammar-fields-multi-line.js +language/expressions/class/elements/syntax/valid/grammar-field-identifier.js +language/expressions/class/elements/syntax/valid/grammar-field-classelementname-initializer.js +language/expressions/class/elements/new-sc-line-method-rs-field-identifier.js +language/expressions/class/elements/static-string-literal-name-init-err-contains-super.js +language/expressions/class/elements/new-no-sc-line-method-rs-field-identifier.js +language/expressions/class/elements/after-same-line-static-method-computed-symbol-names.js +language/expressions/class/elements/after-same-line-static-async-method-computed-names.js +language/expressions/class/elements/fields-asi-same-line-2.js +language/expressions/class/elements/init-value-defined-after-class.js +language/expressions/class/elements/fields-asi-4.js +language/expressions/class/elements/after-same-line-gen-rs-field-identifier.js +language/expressions/class/elements/static-string-literal-name-init-err-contains-arguments.js +language/expressions/class/elements/nested-arrow-fnc-init-err-contains-arguments.js +language/expressions/class/elements/fields-literal-name-static-propname-prototype.js +language/expressions/class/elements/new-sc-line-method-literal-names-asi.js +language/expressions/class/elements/new-sc-line-gen-rs-field-identifier.js +language/expressions/class/elements/after-same-line-static-async-method-literal-names-asi.js +language/expressions/class/elements/same-line-method-rs-field-identifier-initializer.js +language/expressions/class/elements/wrapped-in-sc-string-literal-names.js +language/expressions/class/elements/after-same-line-static-async-gen-rs-field-identifier-initializer.js +language/expressions/class/elements/new-no-sc-line-method-computed-symbol-names.js +language/expressions/class/elements/nested-static-literal-init-err-contains-super.js +language/expressions/class/elements/same-line-method-rs-field-identifier.js +language/expressions/class/elements/literal-name-init-err-contains-super.js +language/expressions/class/elements/after-same-line-static-gen-string-literal-names.js +language/expressions/class/elements/after-same-line-static-async-method-literal-names.js +language/expressions/class/elements/multiple-stacked-definitions-computed-names.js +language/expressions/class/elements/nested-string-literal-name-init-err-contains-arguments.js +language/expressions/class/elements/after-same-line-gen-rs-field-identifier-initializer.js +language/expressions/class/elements/fields-run-once-on-double-super.js +language/expressions/class/elements/after-same-line-static-method-computed-names.js +language/expressions/class/elements/same-line-method-string-literal-names.js +language/expressions/class/elements/after-same-line-static-async-method-rs-field-identifier.js +language/expressions/class/elements/wrapped-in-sc-rs-field-identifier-initializer.js +language/expressions/class/elements/after-same-line-static-async-gen-string-literal-names.js +language/expressions/class/elements/after-same-line-method-literal-names.js +language/expressions/class/elements/nested-literal-name-init-err-contains-arguments.js +language/expressions/class/elements/same-line-gen-literal-names.js +language/expressions/class/elements/multiple-stacked-definitions-literal-names-asi.js +language/expressions/class/elements/wrapped-in-sc-literal-names-asi.js +language/expressions/class/elements/redeclaration-symbol.js +language/expressions/class/elements/same-line-method-literal-names.js +language/expressions/class/elements/after-same-line-method-rs-field-identifier-initializer.js +language/expressions/class/elements/same-line-async-method-rs-field-identifier-initializer.js +language/expressions/class/elements/nested-comp-name-init-err-contains-super.js +language/expressions/class/elements/same-line-gen-string-literal-names.js +language/expressions/class/elements/nested-equality-init-err-contains-arguments.js +language/expressions/class/elements/static-literal-init-err-contains-super.js +language/expressions/class/elements/after-same-line-gen-computed-symbol-names.js +language/expressions/class/elements/nested-static-comp-name-init-err-contains-arguments.js +language/expressions/class/elements/nested-equality-init-err-contains-super.js +language/expressions/class/elements/fields-string-name-propname-constructor.js +language/expressions/class/elements/nested-typeof-init-err-contains-arguments.js +language/expressions/class/elements/same-line-async-gen-literal-names.js +language/expressions/class/elements/wrapped-in-sc-literal-names.js +language/expressions/class/cpn-class-expr-fields-computed-property-name-from-exponetiation-expression.js +language/expressions/class/cpn-class-expr-fields-methods-computed-property-name-from-identifier.js +language/expressions/class/cpn-class-expr-fields-computed-property-name-from-condition-expression-false.js +language/expressions/class/cpn-class-expr-fields-methods-computed-property-name-from-string-literal.js +language/expressions/class/cpn-class-expr-fields-computed-property-name-from-decimal-literal.js +language/expressions/class/cpn-class-expr-fields-methods-computed-property-name-from-decimal-literal.js +language/expressions/class/cpn-class-expr-fields-computed-property-name-from-additive-expression-add.js +language/expressions/class/cpn-class-expr-fields-computed-property-name-from-string-literal.js +language/expressions/class/cpn-class-expr-fields-methods-computed-property-name-from-expression-logical-or.js +language/expressions/class/cpn-class-expr-fields-methods-computed-property-name-from-exponetiation-expression.js +language/expressions/class/cpn-class-expr-fields-computed-property-name-from-decimal-e-notational-literal.js +language/expressions/class/cpn-class-expr-fields-methods-computed-property-name-from-yield-expression.js +language/expressions/class/cpn-class-expr-fields-methods-computed-property-name-from-assignment-expression-logical-and.js +language/expressions/class/cpn-class-expr-fields-computed-property-name-from-null.js +language/expressions/class/cpn-class-expr-fields-methods-computed-property-name-from-decimal-e-notational-literal.js +language/expressions/class/cpn-class-expr-fields-computed-property-name-from-expression-logical-and.js +language/expressions/class/constructor-this-tdz-during-initializers.js +language/expressions/class/cpn-class-expr-fields-computed-property-name-from-yield-expression.js +language/expressions/class/cpn-class-expr-fields-methods-computed-property-name-from-integer-separators.js +language/expressions/class/cpn-class-expr-fields-methods-computed-property-name-from-math.js +language/expressions/class/cpn-class-expr-fields-computed-property-name-from-multiplicative-expression-div.js +language/expressions/class/cpn-class-expr-fields-computed-property-name-from-integer-e-notational-literal.js +language/expressions/class/cpn-class-expr-fields-computed-property-name-from-assignment-expression-logical-and.js +language/expressions/class/cpn-class-expr-fields-methods-computed-property-name-from-expression-logical-and.js +language/expressions/class/cpn-class-expr-fields-computed-property-name-from-assignment-expression-assignment.js +language/expressions/class/cpn-class-expr-fields-computed-property-name-from-assignment-expression-logical-or.js +language/expressions/class/cpn-class-expr-fields-methods-computed-property-name-from-assignment-expression-logical-or.js +language/expressions/class/cpn-class-expr-fields-computed-property-name-from-condition-expression-true.js +language/statements/class/cpn-class-decl-fields-methods-computed-property-name-from-math.js +language/statements/class/cpn-class-decl-fields-methods-computed-property-name-from-additive-expression-add.js +language/statements/class/cpn-class-decl-fields-computed-property-name-from-expression-logical-or.js +language/statements/class/cpn-class-decl-fields-computed-property-name-from-yield-expression.js +language/statements/class/cpn-class-decl-fields-methods-computed-property-name-from-assignment-expression-logical-or.js +language/statements/class/cpn-class-decl-fields-methods-computed-property-name-from-assignment-expression-bitwise-or.js +language/statements/class/cpn-class-decl-fields-computed-property-name-from-assignment-expression-coalesce.js +language/statements/class/cpn-class-decl-fields-computed-property-name-from-numeric-literal.js +language/statements/class/cpn-class-decl-fields-computed-property-name-from-identifier.js +language/statements/class/cpn-class-decl-fields-methods-computed-property-name-from-yield-expression.js +language/statements/class/cpn-class-decl-fields-computed-property-name-from-assignment-expression-logical-and.js +language/statements/class/cpn-class-decl-fields-computed-property-name-from-decimal-literal.js +language/statements/class/cpn-class-decl-fields-computed-property-name-from-null.js +language/statements/class/cpn-class-decl-fields-methods-computed-property-name-from-function-declaration.js +language/statements/class/cpn-class-decl-fields-computed-property-name-from-decimal-e-notational-literal.js +language/statements/class/cpn-class-decl-fields-computed-property-name-from-integer-e-notational-literal.js +language/statements/class/cpn-class-decl-fields-methods-computed-property-name-from-decimal-literal.js +language/statements/class/cpn-class-decl-fields-methods-computed-property-name-from-string-literal.js +language/statements/class/cpn-class-decl-fields-computed-property-name-from-integer-separators.js +language/statements/class/cpn-class-decl-fields-methods-computed-property-name-from-assignment-expression-assignment.js +language/statements/class/cpn-class-decl-fields-methods-computed-property-name-from-null.js +language/statements/class/cpn-class-decl-fields-computed-property-name-from-expression-logical-and.js +language/statements/class/elements/after-same-line-method-rs-field-identifier.js +language/statements/class/elements/static-as-valid-instance-field-assigned.js +language/statements/class/elements/regular-definitions-rs-field-identifier-initializer.js +language/statements/class/elements/after-same-line-static-async-gen-computed-names.js +language/statements/class/elements/init-err-evaluation.js +language/statements/class/elements/same-line-async-gen-rs-field-identifier-initializer.js +language/statements/class/elements/literal-name-init-err-contains-arguments.js +language/statements/class/elements/regular-definitions-literal-names.js +language/statements/class/elements/new-sc-line-gen-literal-names-asi.js +language/statements/class/elements/new-sc-line-method-computed-symbol-names.js +language/statements/class/elements/new-sc-line-method-string-literal-names.js +language/statements/class/elements/multiple-stacked-definitions-rs-field-identifier-initializer.js +language/statements/class/elements/new-sc-line-method-literal-names.js +language/statements/class/elements/regular-definitions-rs-field-identifier.js +language/statements/class/elements/redeclaration.js +language/statements/class/elements/after-same-line-method-computed-names.js +language/statements/class/elements/same-line-async-gen-literal-names-asi.js +language/statements/class/elements/after-same-line-static-async-gen-literal-names.js +language/statements/class/elements/equality-init-err-contains-super.js +language/statements/class/elements/static-literal-init-err-contains-arguments.js +language/statements/class/elements/same-line-async-method-literal-names-asi.js +language/statements/class/elements/static-comp-name-init-err-contains-super.js +language/statements/class/elements/after-same-line-static-async-gen-rs-field-identifier.js +language/statements/class/elements/after-same-line-method-literal-names-asi.js +language/statements/class/elements/regular-definitions-string-literal-names.js +language/statements/class/elements/after-same-line-static-method-literal-names.js +language/statements/class/elements/comp-name-init-err-contains-super.js +language/statements/class/elements/arrow-fnc-init-err-contains-super.js +language/statements/class/elements/same-line-method-computed-symbol-names.js +language/statements/class/elements/same-line-gen-rs-field-identifier-initializer.js +language/statements/class/elements/init-value-incremental.js +language/statements/class/elements/super-fielddefinition-initializer-abrupt-completion.js +language/statements/class/elements/same-line-gen-literal-names-asi.js +language/statements/class/elements/after-same-line-method-string-literal-names.js +language/statements/class/elements/same-line-method-computed-names.js +language/statements/class/elements/new-no-sc-line-method-computed-names.js +language/statements/class/elements/ternary-init-err-contains-super.js +language/statements/class/elements/new-sc-line-gen-rs-field-identifier-initializer.js +language/statements/class/elements/after-same-line-static-gen-computed-names.js +language/statements/class/elements/after-same-line-static-gen-rs-field-identifier-initializer.js +language/statements/class/elements/computed-property-abrupt-completition.js +language/statements/class/elements/after-same-line-method-computed-symbol-names.js +language/statements/class/elements/new-sc-line-gen-literal-names.js +language/statements/class/elements/multiple-stacked-definitions-rs-field-identifier.js +language/statements/class/elements/same-line-async-method-computed-symbol-names.js +language/statements/class/elements/nested-comp-name-init-err-contains-arguments.js +language/statements/class/elements/nested-static-comp-name-init-err-contains-super.js +language/statements/class/elements/field-declaration.js +language/statements/class/elements/same-line-async-gen-computed-names.js +language/statements/class/elements/fields-literal-name-propname-constructor.js +language/statements/class/elements/new-no-sc-line-method-string-literal-names.js +language/statements/class/elements/wrapped-in-sc-computed-symbol-names.js +language/statements/class/elements/after-same-line-static-method-literal-names-asi.js +language/statements/class/elements/after-same-line-static-gen-rs-field-identifier.js +language/statements/class/elements/static-as-valid-instance-field.js +language/statements/class/elements/new-sc-line-method-rs-field-identifier-initializer.js +language/statements/class/elements/new-sc-line-gen-computed-names.js +language/statements/class/elements/nested-literal-name-init-err-contains-super.js +language/statements/class/elements/typeof-init-err-contains-arguments.js +language/statements/class/elements/regular-definitions-computed-names.js +language/statements/class/elements/super-access-from-arrow-func-on-field.js +language/statements/class/elements/ctor-called-after-fields-init.js +language/statements/class/elements/same-line-method-literal-names-asi.js +language/statements/class/elements/comp-name-init-err-contains-arguments.js +language/statements/class/elements/new-no-sc-line-method-rs-field-identifier-initializer.js +language/statements/class/elements/regular-definitions-computed-symbol-names.js +language/statements/class/elements/same-line-gen-rs-field-identifier.js +language/statements/class/elements/after-same-line-static-method-rs-field-identifier-initializer.js +language/statements/class/elements/same-line-gen-computed-names.js +language/statements/class/elements/new-sc-line-gen-string-literal-names.js +language/statements/class/elements/same-line-async-gen-rs-field-identifier.js +language/statements/class/elements/after-same-line-static-async-method-string-literal-names.js +language/statements/class/elements/after-same-line-gen-literal-names.js +language/statements/class/elements/fields-asi-2.js +language/statements/class/elements/new-sc-line-method-computed-names.js +language/statements/class/elements/regular-definitions-literal-names-asi.js +language/statements/class/elements/same-line-gen-computed-symbol-names.js +language/statements/class/elements/same-line-async-gen-computed-symbol-names.js +language/statements/class/elements/fields-asi-1.js +language/statements/class/elements/multiple-stacked-definitions-computed-symbol-names.js +language/statements/class/elements/wrapped-in-sc-computed-names.js +language/statements/class/elements/string-literal-name-init-err-contains-super.js +language/statements/class/elements/after-same-line-static-gen-computed-symbol-names.js +language/statements/class/elements/same-line-async-method-string-literal-names.js +language/statements/class/elements/fielddefinition-initializer-abrupt-completion.js +language/statements/class/elements/nested-ternary-init-err-contains-arguments.js +language/statements/class/elements/class-field-is-observable-by-proxy.js +language/statements/class/elements/same-line-async-method-rs-field-identifier.js +language/statements/class/elements/string-literal-name-init-err-contains-arguments.js +language/statements/class/elements/arrow-fnc-init-err-contains-arguments.js +language/statements/class/elements/same-line-async-method-computed-names.js +language/statements/class/elements/new-sc-line-gen-computed-symbol-names.js +language/statements/class/elements/after-same-line-static-method-string-literal-names.js +language/statements/class/elements/static-comp-name-init-err-contains-arguments.js +language/statements/class/elements/fields-asi-3.js +language/statements/class/elements/after-same-line-gen-computed-names.js +language/statements/class/elements/nested-typeof-init-err-contains-super.js +language/statements/class/elements/after-same-line-static-async-method-computed-symbol-names.js +language/statements/class/elements/multiple-stacked-definitions-string-literal-names.js +language/statements/class/elements/nested-static-string-literal-name-init-err-contains-arguments.js +language/statements/class/elements/after-same-line-gen-literal-names-asi.js +language/statements/class/elements/multiple-stacked-definitions-literal-names.js +language/statements/class/elements/equality-init-err-contains-arguments.js +language/statements/class/elements/fields-hash-constructor-is-a-valid-name.js +language/statements/class/elements/new-no-sc-line-method-literal-names-asi.js +language/statements/class/elements/after-same-line-static-async-gen-computed-symbol-names.js +language/statements/class/elements/evaluation-error/computed-name-referenceerror.js +language/statements/class/elements/nested-string-literal-name-init-err-contains-super.js +language/statements/class/elements/wrapped-in-sc-rs-field-identifier.js +language/statements/class/elements/after-same-line-static-method-rs-field-identifier.js +language/statements/class/elements/nested-static-string-literal-name-init-err-contains-super.js +language/statements/class/elements/after-same-line-gen-string-literal-names.js +language/statements/class/elements/same-line-async-method-literal-names.js +language/statements/class/elements/nested-arrow-fnc-init-err-contains-super.js +language/statements/class/elements/after-same-line-static-gen-literal-names.js +language/statements/class/elements/after-same-line-static-async-gen-literal-names-asi.js +language/statements/class/elements/fields-asi-same-line-1.js +language/statements/class/elements/nested-ternary-init-err-contains-super.js +language/statements/class/elements/ternary-init-err-contains-arguments.js +language/statements/class/elements/fields-asi-5.js +language/statements/class/elements/new-no-sc-line-method-literal-names.js +language/statements/class/elements/nested-static-literal-init-err-contains-arguments.js +language/statements/class/elements/intercalated-static-non-static-computed-fields.js +language/statements/class/elements/typeof-init-err-contains-super.js +language/statements/class/elements/after-same-line-static-gen-literal-names-asi.js +language/statements/class/elements/same-line-async-gen-string-literal-names.js +language/statements/class/elements/syntax/early-errors/grammar-field-identifier-invalid-zwj-error.js +language/statements/class/elements/syntax/early-errors/grammar-fields-same-line-error.js +language/statements/class/elements/syntax/early-errors/grammar-field-identifier-invalid-ues-error.js +language/statements/class/elements/syntax/early-errors/grammar-field-identifier-invalid-zwnj-error.js +language/statements/class/elements/syntax/valid/grammar-field-classelementname-initializer-alt.js +language/statements/class/elements/syntax/valid/grammar-field-identifier-alt.js +language/statements/class/elements/syntax/valid/grammar-fields-multi-line.js +language/statements/class/elements/syntax/valid/grammar-field-identifier.js +language/statements/class/elements/syntax/valid/grammar-field-classelementname-initializer.js +language/statements/class/elements/new-sc-line-method-rs-field-identifier.js +language/statements/class/elements/static-string-literal-name-init-err-contains-super.js +language/statements/class/elements/after-same-line-static-async-method-rs-field-identifier-initializer.js +language/statements/class/elements/new-no-sc-line-method-rs-field-identifier.js +language/statements/class/elements/after-same-line-static-method-computed-symbol-names.js +language/statements/class/elements/after-same-line-static-async-method-computed-names.js +language/statements/class/elements/public-class-field-initialization-on-super-class-with-setter.js +language/statements/class/elements/fields-asi-same-line-2.js +language/statements/class/elements/abrupt-completition-on-field-initializer.js +language/statements/class/elements/init-value-defined-after-class.js +language/statements/class/elements/fields-asi-4.js +language/statements/class/elements/after-same-line-gen-rs-field-identifier.js +language/statements/class/elements/static-string-literal-name-init-err-contains-arguments.js +language/statements/class/elements/nested-arrow-fnc-init-err-contains-arguments.js +language/statements/class/elements/new-sc-line-method-literal-names-asi.js +language/statements/class/elements/new-sc-line-gen-rs-field-identifier.js +language/statements/class/elements/after-same-line-static-async-method-literal-names-asi.js +language/statements/class/elements/same-line-method-rs-field-identifier-initializer.js +language/statements/class/elements/wrapped-in-sc-string-literal-names.js +language/statements/class/elements/after-same-line-static-async-gen-rs-field-identifier-initializer.js +language/statements/class/elements/new-no-sc-line-method-computed-symbol-names.js +language/statements/class/elements/nested-static-literal-init-err-contains-super.js +language/statements/class/elements/same-line-method-rs-field-identifier.js +language/statements/class/elements/literal-name-init-err-contains-super.js +language/statements/class/elements/after-same-line-static-gen-string-literal-names.js +language/statements/class/elements/after-same-line-static-async-method-literal-names.js +language/statements/class/elements/multiple-stacked-definitions-computed-names.js +language/statements/class/elements/nested-string-literal-name-init-err-contains-arguments.js +language/statements/class/elements/after-same-line-gen-rs-field-identifier-initializer.js +language/statements/class/elements/after-same-line-static-method-computed-names.js +language/statements/class/elements/same-line-method-string-literal-names.js +language/statements/class/elements/after-same-line-static-async-method-rs-field-identifier.js +language/statements/class/elements/wrapped-in-sc-rs-field-identifier-initializer.js +language/statements/class/elements/after-same-line-static-async-gen-string-literal-names.js +language/statements/class/elements/after-same-line-method-literal-names.js +language/statements/class/elements/nested-literal-name-init-err-contains-arguments.js +language/statements/class/elements/same-line-gen-literal-names.js +language/statements/class/elements/multiple-stacked-definitions-literal-names-asi.js +language/statements/class/elements/wrapped-in-sc-literal-names-asi.js +language/statements/class/elements/redeclaration-symbol.js +language/statements/class/elements/same-line-method-literal-names.js +language/statements/class/elements/after-same-line-method-rs-field-identifier-initializer.js +language/statements/class/elements/same-line-async-method-rs-field-identifier-initializer.js +language/statements/class/elements/nested-comp-name-init-err-contains-super.js +language/statements/class/elements/fields-computed-name-propname-constructor.js +language/statements/class/elements/same-line-gen-string-literal-names.js +language/statements/class/elements/nested-equality-init-err-contains-arguments.js +language/statements/class/elements/static-literal-init-err-contains-super.js +language/statements/class/elements/after-same-line-gen-computed-symbol-names.js +language/statements/class/elements/nested-static-comp-name-init-err-contains-arguments.js +language/statements/class/elements/nested-equality-init-err-contains-super.js +language/statements/class/elements/fields-string-name-propname-constructor.js +language/statements/class/elements/nested-typeof-init-err-contains-arguments.js +language/statements/class/elements/same-line-async-gen-literal-names.js +language/statements/class/elements/wrapped-in-sc-literal-names.js +language/statements/class/cpn-class-decl-fields-methods-computed-property-name-from-condition-expression-true.js +language/statements/class/cpn-class-decl-fields-methods-computed-property-name-from-identifier.js +language/statements/class/cpn-class-decl-fields-methods-computed-property-name-from-numeric-literal.js +language/statements/class/cpn-class-decl-fields-methods-computed-property-name-from-expression-logical-or.js +language/statements/class/cpn-class-decl-fields-computed-property-name-from-additive-expression-subtract.js +language/statements/class/cpn-class-decl-fields-methods-computed-property-name-from-assignment-expression-logical-and.js +language/statements/class/cpn-class-decl-fields-methods-computed-property-name-from-expression-coalesce.js +language/statements/class/cpn-class-decl-fields-computed-property-name-from-assignment-expression-bitwise-or.js +language/statements/class/cpn-class-decl-fields-methods-computed-property-name-from-expression-logical-and.js +language/statements/class/cpn-class-decl-fields-methods-computed-property-name-from-multiplicative-expression-div.js +language/statements/class/cpn-class-decl-fields-computed-property-name-from-additive-expression-add.js +language/statements/class/cpn-class-decl-fields-methods-computed-property-name-from-multiplicative-expression-mult.js +language/statements/class/cpn-class-decl-fields-computed-property-name-from-multiplicative-expression-mult.js +language/statements/class/cpn-class-decl-fields-computed-property-name-from-string-literal.js +language/statements/class/cpn-class-decl-fields-computed-property-name-from-function-declaration.js +language/statements/class/cpn-class-decl-fields-computed-property-name-from-condition-expression-true.js +language/statements/class/cpn-class-decl-fields-methods-computed-property-name-from-assignment-expression-coalesce.js +language/statements/class/cpn-class-decl-fields-computed-property-name-from-assignment-expression-assignment.js +language/statements/class/cpn-class-decl-fields-methods-computed-property-name-from-exponetiation-expression.js +language/statements/class/cpn-class-decl-fields-methods-computed-property-name-from-integer-e-notational-literal.js +language/statements/class/cpn-class-decl-fields-computed-property-name-from-exponetiation-expression.js +language/statements/class/cpn-class-decl-fields-methods-computed-property-name-from-integer-separators.js +language/statements/class/cpn-class-decl-fields-methods-computed-property-name-from-condition-expression-false.js +language/statements/class/cpn-class-decl-fields-computed-property-name-from-multiplicative-expression-div.js +language/statements/class/cpn-class-decl-fields-computed-property-name-from-expression-coalesce.js +language/statements/class/cpn-class-decl-fields-methods-computed-property-name-from-decimal-e-notational-literal.js +language/statements/class/cpn-class-decl-fields-computed-property-name-from-assignment-expression-logical-or.js +language/statements/class/cpn-class-decl-fields-computed-property-name-from-condition-expression-false.js +language/statements/class/classelementname-abrupt-completion.js +language/statements/class/cpn-class-decl-fields-computed-property-name-from-math.js +language/statements/class/cpn-class-decl-fields-methods-computed-property-name-from-additive-expression-subtract.js +language/statements/class/elements/multiple-definitions-string-literal-names.js +language/expressions/class/elements/multiple-definitions-string-literal-names.js +language/expressions/class/elements/multiple-definitions-literal-names.js +language/statements/class/elements/multiple-definitions-literal-names.js +language/expressions/class/elements/multiple-definitions-rs-field-identifier-initializer.js +language/expressions/class/elements/multiple-definitions-literal-names-asi.js +language/statements/class/elements/multiple-definitions-literal-names-asi.js +language/statements/class/elements/multiple-definitions-rs-field-identifier.js +language/statements/class/elements/multiple-definitions-rs-field-identifier-initializer.js +language/expressions/class/elements/multiple-definitions-rs-field-identifier.js +language/expressions/class/elements/multiple-definitions-computed-symbol-names.js +language/statements/class/elements/multiple-definitions-computed-symbol-names.js +language/expressions/class/elements/multiple-definitions-computed-names.js +language/statements/class/elements/multiple-definitions-computed-names.js +language/statements/class/elements/class-field-on-frozen-objects.js +language/statements/class/elements/public-class-field-initialization-is-visible-to-proxy.js +language/statements/class/cpn-class-decl-fields-methods-computed-property-name-from-generator-function-declaration.js +language/statements/class/cpn-class-decl-fields-methods-computed-property-name-from-function-expression.js +language/statements/class/cpn-class-decl-fields-methods-computed-property-name-from-arrow-function-expression.js +language/statements/class/cpn-class-decl-fields-computed-property-name-from-arrow-function-expression.js +language/statements/class/cpn-class-decl-fields-methods-computed-property-name-from-async-arrow-function-expression.js +language/statements/class/cpn-class-decl-fields-computed-property-name-from-async-arrow-function-expression.js +language/statements/class/cpn-class-decl-fields-computed-property-name-from-generator-function-declaration.js +language/statements/class/cpn-class-decl-fields-computed-property-name-from-function-expression.js +language/expressions/class/cpn-class-expr-fields-methods-computed-property-name-from-generator-function-declaration.js +language/expressions/class/cpn-class-expr-fields-methods-computed-property-name-from-function-expression.js +language/expressions/class/cpn-class-expr-fields-methods-computed-property-name-from-async-arrow-function-expression.js +language/expressions/class/cpn-class-expr-fields-methods-computed-property-name-from-arrow-function-expression.js +language/expressions/class/cpn-class-expr-fields-computed-property-name-from-generator-function-declaration.js +language/expressions/class/cpn-class-expr-fields-computed-property-name-from-function-expression.js +language/expressions/class/cpn-class-expr-fields-computed-property-name-from-async-arrow-function-expression.js +language/expressions/class/cpn-class-expr-fields-computed-property-name-from-arrow-function-expression.js +language/expressions/class/elements/evaluation-error/computed-name-valueof-err.js +language/statements/class/elements/evaluation-error/computed-name-valueof-err.js +language/statements/class/elements/evaluation-error/computed-name-tostring-err.js +language/expressions/class/elements/evaluation-error/computed-name-tostring-err.js +language/expressions/class/elements/evaluation-error/computed-name-toprimitive-err.js +language/statements/class/elements/evaluation-error/computed-name-toprimitive-err.js +language/expressions/class/elements/computed-name-toprimitive.js +language/statements/class/elements/computed-name-toprimitive.js +language/expressions/class/elements/evaluation-error/computed-name-toprimitive-returns-noncallable.js +language/statements/class/elements/evaluation-error/computed-name-toprimitive-returns-noncallable.js +language/expressions/class/elements/evaluation-error/computed-name-toprimitive-returns-nonobject.js +language/statements/class/elements/evaluation-error/computed-name-toprimitive-returns-nonobject.js +language/expressions/class/elements/computed-name-toprimitive-symbol.js +language/statements/class/elements/computed-name-toprimitive-symbol.js +language/expressions/object/method-definition/private-name-early-error-async-fn-inside-class.js +language/expressions/object/method-definition/private-name-early-error-get-method-inside-class.js +language/expressions/object/method-definition/private-name-early-error-method-inside-class.js +language/expressions/object/method-definition/private-name-early-error-gen-inside-class.js +language/expressions/object/method-definition/private-name-early-error-async-gen-inside-class.js +language/expressions/object/method-definition/private-name-early-error-set-method-inside-class.js +language/expressions/class/cpn-class-expr-fields-methods-computed-property-name-from-assignment-expression-assignment.js +language/expressions/class/cpn-class-expr-fields-methods-computed-property-name-from-assignment-expression-bitwise-or.js +language/expressions/class/cpn-class-expr-fields-methods-computed-property-name-from-integer-separators.js +language/expressions/class/cpn-class-expr-fields-computed-property-name-from-expression-logical-or.js +language/expressions/class/cpn-class-expr-fields-computed-property-name-from-decimal-literal.js +language/expressions/class/cpn-class-expr-fields-methods-computed-property-name-from-assignment-expression-logical-and.js +language/expressions/class/cpn-class-expr-fields-computed-property-name-from-multiplicative-expression-mult.js +language/expressions/class/cpn-class-expr-fields-computed-property-name-from-math.js +language/expressions/class/elements/same-line-async-method-rs-private-method.js +language/expressions/class/elements/after-same-line-method-rs-private-setter.js +language/expressions/class/elements/after-same-line-gen-rs-static-privatename-identifier-by-classname.js +language/expressions/class/elements/wrapped-in-sc-grammar-privatename-identifier-semantics-stringvalue.js +language/expressions/class/elements/new-no-sc-line-method-private-method-usage.js +language/expressions/class/elements/after-same-line-static-gen-rs-static-privatename-identifier-by-classname.js +language/expressions/class/elements/after-same-line-static-method-rs-privatename-identifier-alt.js +language/expressions/class/elements/same-line-gen-rs-static-async-generator-method-privatename-identifier-alt.js +language/expressions/class/elements/after-same-line-static-gen-rs-static-async-method-privatename-identifier-alt.js +language/expressions/class/elements/after-same-line-static-method-computed-names.js +language/expressions/class/elements/same-line-async-method-rs-privatename-identifier-initializer-alt.js +language/expressions/class/elements/multiple-definitions-rs-static-privatename-identifier-initializer.js +language/expressions/class/elements/after-same-line-static-method-literal-names.js +language/expressions/class/elements/multiple-definitions-rs-static-privatename-identifier-by-classname.js +language/expressions/class/elements/after-same-line-gen-rs-private-method.js +language/expressions/class/elements/typeof-init-err-contains-arguments.js +language/expressions/class/elements/after-same-line-static-method-rs-static-async-method-privatename-identifier.js +language/expressions/class/elements/after-same-line-static-method-private-field-usage.js +language/expressions/class/elements/nested-string-literal-name-init-err-contains-super.js +language/expressions/class/elements/new-sc-line-gen-rs-field-identifier.js +language/expressions/class/elements/after-same-line-static-gen-rs-static-generator-method-privatename-identifier-alt.js +language/expressions/class/elements/static-as-valid-instance-field-assigned.js +language/expressions/class/elements/same-line-gen-string-literal-names.js +language/expressions/class/elements/after-same-line-static-gen-literal-names-asi.js +language/expressions/class/elements/same-line-gen-rs-static-async-generator-method-privatename-identifier.js +language/expressions/class/elements/same-line-gen-rs-static-generator-method-privatename-identifier-alt.js +language/expressions/class/elements/same-line-async-gen-rs-private-getter.js +language/expressions/class/elements/same-line-async-method-static-private-methods.js +language/expressions/class/elements/after-same-line-static-gen-rs-static-privatename-identifier-alt-by-classname.js +language/expressions/class/elements/fields-run-once-on-double-super.js +language/expressions/class/elements/regular-definitions-private-method-getter-usage.js +language/expressions/class/elements/typeof-init-err-contains-super.js +language/expressions/class/elements/after-same-line-static-async-gen-rs-privatename-identifier-initializer.js +language/expressions/class/elements/after-same-line-gen-literal-names-asi.js +language/expressions/class/elements/regular-definitions-rs-private-setter-alt.js +language/expressions/class/elements/new-sc-line-gen-grammar-privatename-identifier-semantics-stringvalue.js +language/expressions/class/elements/multiple-stacked-definitions-private-method-usage.js +language/expressions/class/elements/same-line-async-gen-rs-static-privatename-identifier-alt-by-classname.js +language/expressions/class/elements/multiple-stacked-definitions-rs-static-privatename-identifier.js +language/expressions/class/elements/nested-private-literal-name-init-err-contains-arguments.js +language/expressions/class/elements/nested-typeof-init-err-contains-super.js +language/expressions/class/elements/after-same-line-gen-static-private-methods.js +language/expressions/class/elements/after-same-line-static-async-gen-rs-private-setter-alt.js +language/expressions/class/elements/wrapped-in-sc-rs-privatename-identifier-initializer.js +language/expressions/class/elements/wrapped-in-sc-rs-private-getter.js +language/expressions/class/elements/new-sc-line-gen-rs-static-async-generator-method-privatename-identifier.js +language/expressions/class/elements/after-same-line-static-gen-rs-privatename-identifier-alt.js +language/expressions/class/elements/after-same-line-static-async-method-rs-static-privatename-identifier-initializer-alt.js +language/expressions/class/elements/regular-definitions-private-names.js +language/expressions/class/elements/new-no-sc-line-method-rs-private-getter-alt.js +language/expressions/class/elements/wrapped-in-sc-rs-static-privatename-identifier-initializer-alt-by-classname.js +language/expressions/class/elements/after-same-line-static-async-gen-rs-static-privatename-identifier-by-classname.js +language/expressions/class/elements/same-line-async-gen-computed-symbol-names.js +language/expressions/class/elements/after-same-line-gen-rs-privatename-identifier-initializer.js +language/expressions/class/elements/private-method-shadowed-by-setter-on-nested-class.js +language/expressions/class/elements/comp-name-init-err-contains-super.js +language/expressions/class/elements/new-no-sc-line-method-rs-private-setter.js +language/expressions/class/elements/same-line-async-gen-rs-static-privatename-identifier-initializer-alt.js +language/expressions/class/elements/after-same-line-static-async-gen-rs-private-getter-alt.js +language/expressions/class/elements/multiple-definitions-rs-private-getter.js +language/expressions/class/elements/multiple-stacked-definitions-rs-static-generator-method-privatename-identifier.js +language/expressions/class/elements/wrapped-in-sc-string-literal-names.js +language/expressions/class/elements/new-no-sc-line-method-string-literal-names.js +language/expressions/class/elements/regular-definitions-computed-names.js +language/expressions/class/elements/same-line-async-method-rs-field-identifier-initializer.js +language/expressions/class/elements/multiple-definitions-private-names.js +language/expressions/class/elements/same-line-async-gen-static-private-fields.js +language/expressions/class/elements/same-line-async-method-rs-static-method-privatename-identifier-alt.js +language/expressions/class/elements/same-line-async-gen-rs-static-privatename-identifier-initializer.js +language/expressions/class/elements/same-line-gen-rs-static-async-method-privatename-identifier-alt.js +language/expressions/class/elements/same-line-async-gen-rs-private-setter-alt.js +language/expressions/class/elements/same-line-gen-private-method-usage.js +language/expressions/class/elements/after-same-line-static-method-rs-static-async-generator-method-privatename-identifier-alt.js +language/expressions/class/elements/multiple-stacked-definitions-computed-symbol-names.js +language/expressions/class/elements/wrapped-in-sc-rs-field-identifier.js +language/expressions/class/elements/after-same-line-static-async-method-rs-static-privatename-identifier-initializer.js +language/expressions/class/elements/regular-definitions-grammar-privatename-identifier-semantics-stringvalue.js +language/expressions/class/elements/after-same-line-method-rs-private-method.js +language/expressions/class/elements/private-field-on-nested-class.js +language/expressions/class/elements/string-literal-name-init-err-contains-super.js +language/expressions/class/elements/multiple-definitions-rs-static-method-privatename-identifier-alt.js +language/expressions/class/elements/new-sc-line-method-rs-static-privatename-identifier-initializer-alt-by-classname.js +language/expressions/class/elements/after-same-line-static-async-gen-rs-private-method-alt.js +language/expressions/class/elements/new-sc-line-gen-rs-private-setter.js +language/expressions/class/elements/after-same-line-static-async-method-rs-private-method-alt.js +language/expressions/class/elements/same-line-gen-static-private-methods-with-fields.js +language/expressions/class/elements/after-same-line-gen-rs-field-identifier.js +language/expressions/class/elements/after-same-line-static-method-rs-privatename-identifier.js +language/expressions/class/elements/after-same-line-static-method-computed-symbol-names.js +language/expressions/class/elements/fields-string-name-static-propname-prototype.js +language/expressions/class/elements/after-same-line-method-private-names.js +language/expressions/class/elements/same-line-async-method-rs-static-privatename-identifier-initializer-alt-by-classname.js +language/expressions/class/elements/same-line-async-method-rs-privatename-identifier-initializer.js +language/expressions/class/elements/new-sc-line-method-rs-private-setter.js +language/expressions/class/elements/equality-init-err-contains-super.js +language/expressions/class/elements/new-no-sc-line-method-grammar-privatename-identifier-semantics-stringvalue.js +language/expressions/class/elements/multiple-stacked-definitions-rs-private-setter-alt.js +language/expressions/class/elements/new-sc-line-gen-rs-static-privatename-identifier-alt.js +language/expressions/class/elements/new-sc-line-method-rs-privatename-identifier-initializer-alt.js +language/expressions/class/elements/after-same-line-static-async-gen-static-private-methods.js +language/expressions/class/elements/after-same-line-static-async-gen-rs-static-privatename-identifier-initializer-alt.js +language/expressions/class/elements/same-line-method-private-method-getter-usage.js +language/expressions/class/elements/new-no-sc-line-method-rs-static-privatename-identifier-by-classname.js +language/expressions/class/elements/new-sc-line-method-rs-static-privatename-identifier-by-classname.js +language/expressions/class/elements/same-line-async-gen-rs-field-identifier.js +language/expressions/class/elements/same-line-async-method-rs-static-method-privatename-identifier.js +language/expressions/class/elements/private-method-shadowed-by-field-on-nested-class.js +language/expressions/class/elements/new-no-sc-line-method-computed-names.js +language/expressions/class/elements/same-line-method-static-private-fields.js +language/expressions/class/elements/after-same-line-static-async-method-rs-privatename-identifier-initializer.js +language/expressions/class/elements/after-same-line-static-async-gen-grammar-privatename-identifier-semantics-stringvalue.js +language/expressions/class/elements/regular-definitions-literal-names-asi.js +language/expressions/class/elements/after-same-line-static-async-method-static-private-methods.js +language/expressions/class/elements/new-sc-line-gen-rs-static-privatename-identifier-by-classname.js +language/expressions/class/elements/same-line-gen-literal-names-asi.js +language/expressions/class/elements/nested-private-typeof-init-err-contains-arguments.js +language/expressions/class/elements/new-sc-line-gen-rs-private-getter-alt.js +language/expressions/class/elements/same-line-async-gen-rs-static-method-privatename-identifier-alt.js +language/expressions/class/elements/same-line-method-rs-private-method-alt.js +language/expressions/class/elements/after-same-line-static-gen-static-private-methods-with-fields.js +language/expressions/class/elements/nested-private-arrow-fnc-init-err-contains-super.js +language/expressions/class/elements/same-line-async-method-literal-names-asi.js +language/expressions/class/elements/same-line-async-method-private-method-getter-usage.js +language/expressions/class/elements/regular-definitions-static-private-methods.js +language/expressions/class/elements/after-same-line-static-async-gen-rs-static-generator-method-privatename-identifier-alt.js +language/expressions/class/elements/after-same-line-static-async-method-grammar-privatename-identifier-semantics-stringvalue.js +language/expressions/class/elements/after-same-line-gen-rs-static-async-generator-method-privatename-identifier.js +language/expressions/class/elements/after-same-line-static-gen-rs-private-setter.js +language/expressions/class/elements/multiple-stacked-definitions-rs-field-identifier.js +language/expressions/class/elements/init-err-evaluation.js +language/expressions/class/elements/after-same-line-method-rs-private-setter-alt.js +language/expressions/class/elements/same-line-async-gen-literal-names-asi.js +language/expressions/class/elements/nested-private-literal-name-init-err-contains-super.js +language/expressions/class/elements/private-arrow-fnc-init-err-contains-super.js +language/expressions/class/elements/after-same-line-gen-rs-private-getter-alt.js +language/expressions/class/elements/after-same-line-static-async-gen-rs-static-async-generator-method-privatename-identifier.js +language/expressions/class/elements/multiple-stacked-definitions-rs-static-method-privatename-identifier.js +language/expressions/class/elements/after-same-line-static-method-private-method-usage.js +language/expressions/class/elements/multiple-stacked-definitions-rs-static-async-method-privatename-identifier.js +language/expressions/class/elements/regular-definitions-rs-static-async-method-privatename-identifier-alt.js +language/expressions/class/elements/after-same-line-static-method-rs-private-getter.js +language/expressions/class/elements/same-line-async-gen-rs-private-setter.js +language/expressions/class/elements/after-same-line-gen-grammar-privatename-identifier-semantics-stringvalue.js +language/expressions/class/elements/fields-asi-3.js +language/expressions/class/elements/after-same-line-static-method-literal-names-asi.js +language/expressions/class/elements/after-same-line-method-rs-static-privatename-identifier-initializer-alt.js +language/expressions/class/elements/static-as-valid-instance-field.js +language/expressions/class/elements/same-line-gen-rs-static-privatename-identifier-alt-by-classname.js +language/expressions/class/elements/new-sc-line-gen-literal-names.js +language/expressions/class/elements/new-no-sc-line-method-static-private-methods.js +language/expressions/class/elements/same-line-method-rs-private-method.js +language/expressions/class/elements/multiple-stacked-definitions-rs-field-identifier-initializer.js +language/expressions/class/elements/after-same-line-static-async-method-rs-static-generator-method-privatename-identifier-alt.js +language/expressions/class/elements/after-same-line-static-method-string-literal-names.js +language/expressions/class/elements/same-line-gen-rs-static-method-privatename-identifier-alt.js +language/expressions/class/elements/new-no-sc-line-method-rs-private-method.js +language/expressions/class/elements/same-line-gen-rs-static-generator-method-privatename-identifier.js +language/expressions/class/elements/after-same-line-static-async-gen-rs-private-setter.js +language/expressions/class/elements/after-same-line-static-async-gen-computed-symbol-names.js +language/expressions/class/elements/new-no-sc-line-method-computed-symbol-names.js +language/expressions/class/elements/after-same-line-gen-rs-private-setter.js +language/expressions/class/elements/same-line-async-method-computed-names.js +language/expressions/class/elements/same-line-gen-rs-field-identifier-initializer.js +language/expressions/class/elements/wrapped-in-sc-rs-static-async-method-privatename-identifier-alt.js +language/expressions/class/elements/after-same-line-static-async-gen-rs-field-identifier.js +language/expressions/class/elements/literal-name-init-err-contains-super.js +language/expressions/class/elements/new-no-sc-line-method-private-method-getter-usage.js +language/expressions/class/elements/after-same-line-gen-rs-static-privatename-identifier-alt-by-classname.js +language/expressions/class/elements/same-line-async-gen-rs-field-identifier-initializer.js +language/expressions/class/elements/after-same-line-static-async-gen-rs-field-identifier-initializer.js +language/expressions/class/elements/after-same-line-static-async-gen-rs-static-privatename-identifier-initializer.js +language/expressions/class/elements/after-same-line-gen-rs-static-method-privatename-identifier-alt.js +language/expressions/class/elements/nested-static-private-init-err-contains-arguments.js +language/expressions/class/elements/wrapped-in-sc-static-private-fields.js +language/expressions/class/elements/after-same-line-method-rs-static-method-privatename-identifier-alt.js +language/expressions/class/elements/after-same-line-static-gen-rs-private-method-alt.js +language/expressions/class/elements/static-private-init-err-contains-arguments.js +language/expressions/class/elements/after-same-line-static-async-gen-computed-names.js +language/expressions/class/elements/private-ternary-init-err-contains-super.js +language/expressions/class/elements/same-line-async-method-rs-static-async-method-privatename-identifier-alt.js +language/expressions/class/elements/regular-definitions-rs-static-method-privatename-identifier.js +language/expressions/class/elements/after-same-line-gen-rs-static-async-method-privatename-identifier-alt.js +language/expressions/class/elements/wrapped-in-sc-rs-static-method-privatename-identifier.js +language/expressions/class/elements/intercalated-static-non-static-computed-fields.js +language/expressions/class/elements/after-same-line-gen-computed-names.js +language/expressions/class/elements/same-line-method-static-private-methods.js +language/expressions/class/elements/regular-definitions-rs-static-privatename-identifier-by-classname.js +language/expressions/class/elements/new-sc-line-method-rs-static-privatename-identifier.js +language/expressions/class/elements/same-line-method-rs-static-async-method-privatename-identifier-alt.js +language/expressions/class/elements/same-line-async-method-private-field-usage.js +language/expressions/class/elements/after-same-line-static-async-method-rs-static-async-generator-method-privatename-identifier.js +language/expressions/class/elements/after-same-line-static-async-method-rs-private-getter-alt.js +language/expressions/class/elements/same-line-async-gen-rs-static-generator-method-privatename-identifier.js +language/expressions/class/elements/new-no-sc-line-method-rs-privatename-identifier-initializer-alt.js +language/expressions/class/elements/new-sc-line-gen-rs-static-privatename-identifier-initializer-alt.js +language/expressions/class/elements/after-same-line-static-async-method-static-private-fields.js +language/expressions/class/elements/nested-private-ternary-init-err-contains-super.js +language/expressions/class/elements/regular-definitions-rs-static-method-privatename-identifier-alt.js +language/expressions/class/elements/wrapped-in-sc-rs-static-privatename-identifier-alt-by-classname.js +language/expressions/class/elements/new-sc-line-gen-rs-static-generator-method-privatename-identifier.js +language/expressions/class/elements/after-same-line-static-method-rs-privatename-identifier-initializer.js +language/expressions/class/elements/same-line-async-gen-rs-privatename-identifier-initializer.js +language/expressions/class/elements/fields-asi-same-line-2.js +language/expressions/class/elements/after-same-line-method-literal-names.js +language/expressions/class/elements/after-same-line-gen-rs-private-method-alt.js +language/expressions/class/elements/same-line-async-method-static-private-fields.js +language/expressions/class/elements/regular-definitions-rs-static-generator-method-privatename-identifier-alt.js +language/expressions/class/elements/new-sc-line-method-rs-static-method-privatename-identifier-alt.js +language/expressions/class/elements/after-same-line-static-method-rs-private-setter-alt.js +language/expressions/class/elements/nested-literal-name-init-err-contains-super.js +language/expressions/class/elements/multiple-stacked-definitions-string-literal-names.js +language/expressions/class/elements/regular-definitions-rs-private-setter.js +language/expressions/class/elements/multiple-stacked-definitions-rs-static-privatename-identifier-alt.js +language/expressions/class/elements/nested-static-string-literal-name-init-err-contains-arguments.js +language/expressions/class/elements/after-same-line-method-rs-static-privatename-identifier-initializer-alt-by-classname.js +language/expressions/class/elements/multiple-stacked-definitions-static-private-methods-with-fields.js +language/expressions/class/elements/after-same-line-static-async-method-rs-static-privatename-identifier-alt.js +language/expressions/class/elements/after-same-line-static-async-gen-rs-static-async-generator-method-privatename-identifier-alt.js +language/expressions/class/elements/after-same-line-static-async-method-literal-names.js +language/expressions/class/elements/new-no-sc-line-method-rs-static-generator-method-privatename-identifier-alt.js +language/expressions/class/elements/after-same-line-static-method-rs-private-method-alt.js +language/expressions/class/elements/private-getter-shadowed-by-method-on-nested-class.js +language/expressions/class/elements/same-line-async-gen-static-private-methods.js +language/expressions/class/elements/after-same-line-static-gen-rs-static-privatename-identifier-initializer-alt.js +language/expressions/class/elements/fields-asi-1.js +language/expressions/class/elements/multiple-definitions-rs-static-generator-method-privatename-identifier-alt.js +language/expressions/class/elements/fields-asi-2.js +language/expressions/class/elements/multiple-stacked-definitions-private-names.js +language/expressions/class/elements/new-sc-line-gen-rs-private-method.js +language/expressions/class/elements/static-literal-init-err-contains-arguments.js +language/expressions/class/elements/private-arrow-fnc-init-err-contains-arguments.js +language/expressions/class/elements/new-sc-line-gen-rs-privatename-identifier-initializer.js +language/expressions/class/elements/same-line-async-method-literal-names.js +language/expressions/class/elements/computed-name-toprimitive.js +language/expressions/class/elements/new-no-sc-line-method-rs-private-getter.js +language/expressions/class/elements/after-same-line-gen-static-private-methods-with-fields.js +language/expressions/class/elements/init-value-incremental.js +language/expressions/class/elements/same-line-method-rs-static-privatename-identifier-by-classname.js +language/expressions/class/elements/same-line-method-rs-static-async-method-privatename-identifier.js +language/expressions/class/elements/multiple-stacked-definitions-rs-static-privatename-identifier-initializer-alt.js +language/expressions/class/elements/regular-definitions-rs-privatename-identifier-initializer.js +language/expressions/class/elements/new-sc-line-method-string-literal-names.js +language/expressions/class/elements/after-same-line-static-method-rs-static-privatename-identifier-initializer-alt.js +language/expressions/class/elements/static-comp-name-init-err-contains-super.js +language/expressions/class/elements/after-same-line-static-async-gen-private-names.js +language/expressions/class/elements/nested-static-comp-name-init-err-contains-super.js +language/expressions/class/elements/multiple-stacked-definitions-rs-static-privatename-identifier-initializer.js +language/expressions/class/elements/new-sc-line-gen-rs-static-privatename-identifier-alt-by-classname.js +language/expressions/class/elements/after-same-line-static-gen-rs-static-async-method-privatename-identifier.js +language/expressions/class/elements/after-same-line-static-method-rs-private-getter-alt.js +language/expressions/class/elements/new-no-sc-line-method-rs-static-async-generator-method-privatename-identifier-alt.js +language/expressions/class/elements/multiple-stacked-definitions-rs-private-setter.js +language/expressions/class/elements/new-sc-line-gen-static-private-fields.js +language/expressions/class/elements/new-sc-line-method-rs-private-getter-alt.js +language/expressions/class/elements/after-same-line-static-gen-rs-static-generator-method-privatename-identifier.js +language/expressions/class/elements/new-sc-line-method-computed-names.js +language/expressions/class/elements/same-line-method-rs-privatename-identifier-initializer.js +language/expressions/class/elements/multiple-stacked-definitions-grammar-privatename-identifier-semantics-stringvalue.js +language/expressions/class/elements/after-same-line-static-async-gen-private-method-getter-usage.js +language/expressions/class/elements/fields-string-name-propname-constructor.js +language/expressions/class/elements/after-same-line-method-rs-field-identifier.js +language/expressions/class/elements/new-sc-line-method-rs-private-getter.js +language/expressions/class/elements/after-same-line-static-method-rs-static-privatename-identifier.js +language/expressions/class/elements/new-sc-line-gen-computed-names.js +language/expressions/class/elements/multiple-definitions-computed-symbol-names.js +language/expressions/class/elements/after-same-line-static-async-method-rs-static-method-privatename-identifier-alt.js +language/expressions/class/elements/after-same-line-static-async-method-rs-static-method-privatename-identifier.js +language/expressions/class/elements/new-sc-line-gen-rs-static-method-privatename-identifier-alt.js +language/expressions/class/elements/same-line-gen-rs-private-setter.js +language/expressions/class/elements/regular-definitions-rs-privatename-identifier-alt.js +language/expressions/class/elements/wrapped-in-sc-private-names.js +language/expressions/class/elements/wrapped-in-sc-private-method-getter-usage.js +language/expressions/class/elements/same-line-async-method-rs-static-privatename-identifier.js +language/expressions/class/elements/new-sc-line-method-rs-privatename-identifier-initializer.js +language/expressions/class/elements/regular-definitions-rs-static-generator-method-privatename-identifier.js +language/expressions/class/elements/fields-literal-name-static-propname-prototype.js +language/expressions/class/elements/regular-definitions-private-method-usage.js +language/expressions/class/elements/after-same-line-static-gen-rs-field-identifier-initializer.js +language/expressions/class/elements/same-line-async-method-grammar-privatename-identifier-semantics-stringvalue.js +language/expressions/class/elements/same-line-method-string-literal-names.js +language/expressions/class/elements/same-line-gen-rs-private-setter-alt.js +language/expressions/class/elements/same-line-method-rs-field-identifier.js +language/expressions/class/elements/same-line-async-gen-private-field-usage.js +language/expressions/class/elements/same-line-gen-private-names.js +language/expressions/class/elements/new-sc-line-method-private-names.js +language/expressions/class/elements/same-line-async-method-rs-static-privatename-identifier-by-classname.js +language/expressions/class/elements/after-same-line-method-rs-private-getter.js +language/expressions/class/elements/same-line-async-method-rs-static-generator-method-privatename-identifier-alt.js +language/expressions/class/elements/new-sc-line-gen-rs-privatename-identifier-initializer-alt.js +language/expressions/class/elements/after-same-line-static-gen-private-method-usage.js +language/expressions/class/elements/after-same-line-gen-private-names.js +language/expressions/class/elements/after-same-line-method-private-field-usage.js +language/expressions/class/elements/regular-definitions-static-private-methods-with-fields.js +language/expressions/class/elements/multiple-definitions-literal-names.js +language/expressions/class/elements/after-same-line-static-async-gen-static-private-methods-with-fields.js +language/expressions/class/elements/new-sc-line-gen-rs-static-privatename-identifier-initializer.js +language/expressions/class/elements/wrapped-in-sc-rs-field-identifier-initializer.js +language/expressions/class/elements/multiple-definitions-rs-privatename-identifier-initializer.js +language/expressions/class/elements/after-same-line-static-gen-rs-static-method-privatename-identifier-alt.js +language/expressions/class/elements/init-value-defined-after-class.js +language/expressions/class/elements/nested-static-string-literal-name-init-err-contains-super.js +language/expressions/class/elements/same-line-method-rs-privatename-identifier-initializer-alt.js +language/expressions/class/elements/same-line-method-rs-static-async-generator-method-privatename-identifier.js +language/expressions/class/elements/after-same-line-static-method-private-method-getter-usage.js +language/expressions/class/elements/nested-arrow-fnc-init-err-contains-super.js +language/expressions/class/elements/after-same-line-method-rs-static-async-generator-method-privatename-identifier-alt.js +language/expressions/class/elements/new-sc-line-method-private-method-usage.js +language/expressions/class/elements/same-line-async-gen-rs-private-getter-alt.js +language/expressions/class/elements/multiple-definitions-rs-field-identifier.js +language/expressions/class/elements/wrapped-in-sc-rs-private-setter-alt.js +language/expressions/class/elements/wrapped-in-sc-rs-static-async-generator-method-privatename-identifier.js +language/expressions/class/elements/new-sc-line-method-static-private-methods.js +language/expressions/class/elements/after-same-line-static-gen-computed-names.js +language/expressions/class/elements/after-same-line-static-async-gen-private-field-usage.js +language/expressions/class/elements/same-line-async-gen-rs-privatename-identifier.js +language/expressions/class/elements/new-no-sc-line-method-rs-field-identifier.js +language/expressions/class/elements/new-sc-line-gen-literal-names-asi.js +language/expressions/class/elements/new-sc-line-method-rs-static-privatename-identifier-alt-by-classname.js +language/expressions/class/elements/after-same-line-static-async-gen-private-method-usage.js +language/expressions/class/elements/new-sc-line-method-rs-static-privatename-identifier-alt.js +language/expressions/class/elements/multiple-stacked-definitions-rs-static-async-generator-method-privatename-identifier-alt.js +language/expressions/class/elements/after-same-line-static-async-gen-literal-names-asi.js +language/expressions/class/elements/nested-literal-name-init-err-contains-arguments.js +language/expressions/class/elements/after-same-line-method-rs-static-privatename-identifier.js +language/expressions/class/elements/same-line-async-method-rs-static-generator-method-privatename-identifier.js +language/expressions/class/elements/after-same-line-static-gen-rs-static-async-generator-method-privatename-identifier.js +language/expressions/class/elements/after-same-line-static-method-rs-static-async-generator-method-privatename-identifier.js +language/expressions/class/elements/same-line-async-method-rs-static-async-method-privatename-identifier.js +language/expressions/class/elements/multiple-definitions-rs-privatename-identifier-initializer-alt.js +language/expressions/class/elements/new-no-sc-line-method-rs-static-privatename-identifier-initializer-alt.js +language/expressions/class/elements/new-sc-line-method-rs-static-method-privatename-identifier.js +language/expressions/class/elements/private-getter-on-nested-class.js +language/expressions/class/elements/private-method-shadowed-on-nested-class.js +language/expressions/class/elements/field-declaration.js +language/expressions/class/elements/after-same-line-method-string-literal-names.js +language/expressions/class/elements/same-line-gen-rs-static-privatename-identifier-initializer-alt-by-classname.js +language/expressions/class/elements/private-setter-shadowed-by-field-on-nested-class.js +language/expressions/class/elements/new-sc-line-method-rs-static-generator-method-privatename-identifier.js +language/expressions/class/elements/after-same-line-gen-rs-static-privatename-identifier-initializer.js +language/expressions/class/elements/multiple-definitions-grammar-privatename-identifier-semantics-stringvalue.js +language/expressions/class/elements/after-same-line-static-gen-private-names.js +language/expressions/class/elements/same-line-async-gen-rs-static-privatename-identifier-by-classname.js +language/expressions/class/elements/after-same-line-static-method-rs-static-method-privatename-identifier.js +language/expressions/class/elements/after-same-line-static-gen-rs-private-method.js +language/expressions/class/elements/same-line-async-gen-rs-static-privatename-identifier-alt.js +language/expressions/class/elements/string-literal-name-init-err-contains-arguments.js +language/expressions/class/elements/same-line-async-method-rs-static-async-generator-method-privatename-identifier.js +language/expressions/class/elements/after-same-line-static-async-method-rs-static-privatename-identifier-alt-by-classname.js +language/expressions/class/elements/new-sc-line-method-computed-symbol-names.js +language/expressions/class/elements/same-line-method-rs-private-setter-alt.js +language/expressions/class/elements/wrapped-in-sc-rs-static-privatename-identifier-initializer.js +language/expressions/class/elements/nested-string-literal-name-init-err-contains-arguments.js +language/expressions/class/elements/after-same-line-static-async-gen-rs-static-privatename-identifier-alt-by-classname.js +language/expressions/class/elements/fields-asi-5.js +language/expressions/class/elements/regular-definitions-rs-static-async-method-privatename-identifier.js +language/expressions/class/elements/regular-definitions-rs-field-identifier-initializer.js +language/expressions/class/elements/new-sc-line-gen-rs-static-async-method-privatename-identifier.js +language/expressions/class/elements/multiple-stacked-definitions-rs-privatename-identifier-alt.js +language/expressions/class/elements/new-sc-line-method-rs-private-method.js +language/expressions/class/elements/new-no-sc-line-method-rs-privatename-identifier-alt.js +language/expressions/class/elements/nested-equality-init-err-contains-arguments.js +language/expressions/class/elements/after-same-line-static-method-rs-private-setter.js +language/expressions/class/elements/new-no-sc-line-method-rs-static-async-method-privatename-identifier.js +language/expressions/class/elements/private-typeof-init-err-contains-arguments.js +language/expressions/class/elements/new-sc-line-method-rs-static-generator-method-privatename-identifier-alt.js +language/expressions/class/elements/wrapped-in-sc-rs-static-generator-method-privatename-identifier.js +language/expressions/class/elements/ternary-init-err-contains-arguments.js +language/expressions/class/elements/multiple-definitions-rs-privatename-identifier.js +language/expressions/class/elements/same-line-gen-grammar-privatename-identifier-semantics-stringvalue.js +language/expressions/class/elements/new-no-sc-line-method-rs-static-privatename-identifier-alt-by-classname.js +language/expressions/class/elements/same-line-method-rs-static-privatename-identifier.js +language/expressions/class/elements/multiple-definitions-static-private-methods-with-fields.js +language/expressions/class/elements/after-same-line-static-async-gen-rs-privatename-identifier-initializer-alt.js +language/expressions/class/elements/same-line-async-method-private-names.js +language/expressions/class/elements/comp-name-init-err-contains-arguments.js +language/expressions/class/elements/after-same-line-static-gen-literal-names.js +language/expressions/class/elements/after-same-line-gen-rs-static-async-method-privatename-identifier.js +language/expressions/class/elements/multiple-stacked-definitions-rs-privatename-identifier-initializer.js +language/expressions/class/elements/multiple-stacked-definitions-literal-names.js +language/expressions/class/elements/same-line-method-private-names.js +language/expressions/class/elements/wrapped-in-sc-rs-static-generator-method-privatename-identifier-alt.js +language/expressions/class/elements/wrapped-in-sc-literal-names.js +language/expressions/class/elements/after-same-line-static-async-gen-string-literal-names.js +language/expressions/class/elements/same-line-async-method-rs-private-method-alt.js +language/expressions/class/elements/new-no-sc-line-method-rs-field-identifier-initializer.js +language/expressions/class/elements/same-line-async-gen-private-method-getter-usage.js +language/expressions/class/elements/multiple-definitions-static-private-fields.js +language/expressions/class/elements/after-same-line-static-async-gen-rs-static-async-method-privatename-identifier.js +language/expressions/class/elements/after-same-line-static-method-rs-privatename-identifier-initializer-alt.js +language/expressions/class/elements/regular-definitions-rs-static-async-generator-method-privatename-identifier.js +language/expressions/class/elements/wrapped-in-sc-static-private-methods.js +language/expressions/class/elements/after-same-line-method-rs-private-method-alt.js +language/expressions/class/elements/multiple-stacked-definitions-rs-static-method-privatename-identifier-alt.js +language/expressions/class/elements/multiple-stacked-definitions-rs-private-getter-alt.js +language/expressions/class/elements/private-getter-shadowed-by-getter-on-nested-class.js +language/expressions/class/elements/after-same-line-static-method-rs-static-privatename-identifier-initializer.js +language/expressions/class/elements/same-line-async-method-rs-static-privatename-identifier-alt-by-classname.js +language/expressions/class/elements/after-same-line-static-method-private-names.js +language/expressions/class/elements/same-line-gen-rs-static-async-method-privatename-identifier.js +language/expressions/class/elements/new-sc-line-gen-rs-static-generator-method-privatename-identifier-alt.js +language/expressions/class/elements/after-same-line-static-async-method-static-private-methods-with-fields.js +language/expressions/class/elements/same-line-gen-rs-static-privatename-identifier-alt.js +language/expressions/class/elements/same-line-gen-rs-field-identifier.js +language/expressions/class/elements/new-no-sc-line-method-rs-static-privatename-identifier.js +language/expressions/class/elements/same-line-async-gen-computed-names.js +language/expressions/class/elements/after-same-line-static-async-method-private-names.js +language/expressions/class/elements/private-ternary-init-err-contains-arguments.js +language/expressions/class/elements/after-same-line-static-async-gen-rs-static-method-privatename-identifier.js +language/expressions/class/elements/new-sc-line-method-rs-field-identifier-initializer.js +language/expressions/class/elements/private-setter-shadowed-by-method-on-nested-class.js +language/expressions/class/elements/multiple-definitions-rs-static-privatename-identifier.js +language/expressions/class/elements/same-line-async-method-rs-static-privatename-identifier-initializer.js +language/expressions/class/elements/after-same-line-static-async-gen-rs-privatename-identifier-alt.js +language/expressions/class/elements/wrapped-in-sc-rs-static-privatename-identifier-initializer-alt.js +language/expressions/class/elements/after-same-line-method-rs-privatename-identifier-initializer-alt.js +language/expressions/class/elements/multiple-stacked-definitions-rs-static-privatename-identifier-initializer-alt-by-classname.js +language/expressions/class/elements/same-line-gen-private-method-getter-usage.js +language/expressions/class/elements/after-same-line-static-method-rs-static-method-privatename-identifier-alt.js +language/expressions/class/elements/after-same-line-static-gen-rs-static-method-privatename-identifier.js +language/expressions/class/elements/same-line-async-method-rs-private-setter.js +language/expressions/class/elements/after-same-line-gen-static-private-fields.js +language/expressions/class/elements/after-same-line-static-method-rs-field-identifier.js +language/expressions/class/elements/ctor-called-after-fields-init.js +language/expressions/class/elements/same-line-async-gen-rs-static-privatename-identifier.js +language/expressions/class/elements/new-sc-line-gen-rs-static-method-privatename-identifier.js +language/expressions/class/elements/new-sc-line-method-rs-field-identifier.js +language/expressions/class/elements/new-no-sc-line-method-rs-static-generator-method-privatename-identifier.js +language/expressions/class/elements/computed-name-toprimitive-symbol.js +language/expressions/class/elements/after-same-line-method-rs-privatename-identifier-initializer.js +language/expressions/class/elements/after-same-line-gen-private-field-usage.js +language/expressions/class/elements/wrapped-in-sc-computed-symbol-names.js +language/expressions/class/elements/nested-equality-init-err-contains-super.js +language/expressions/class/elements/after-same-line-static-async-method-rs-private-setter.js +language/expressions/class/elements/regular-definitions-rs-static-privatename-identifier-initializer.js +language/expressions/class/elements/after-same-line-gen-rs-private-setter-alt.js +language/expressions/class/elements/nested-private-typeof-init-err-contains-super.js +language/expressions/class/elements/new-sc-line-gen-rs-private-getter.js +language/expressions/class/elements/wrapped-in-sc-rs-privatename-identifier-alt.js +language/expressions/class/elements/new-sc-line-method-literal-names.js +language/expressions/class/elements/new-sc-line-gen-rs-private-setter-alt.js +language/expressions/class/elements/wrapped-in-sc-literal-names-asi.js +language/expressions/class/elements/after-same-line-method-rs-static-privatename-identifier-initializer.js +language/expressions/class/elements/same-line-async-gen-rs-static-async-method-privatename-identifier.js +language/expressions/class/elements/after-same-line-gen-rs-static-privatename-identifier-initializer-alt.js +language/expressions/class/elements/multiple-stacked-definitions-static-private-fields.js +language/expressions/class/elements/static-literal-init-err-contains-super.js +language/expressions/class/elements/wrapped-in-sc-private-field-usage.js +language/expressions/class/elements/multiple-definitions-rs-private-getter-alt.js +language/expressions/class/elements/after-same-line-method-rs-static-method-privatename-identifier.js +language/expressions/class/elements/regular-definitions-literal-names.js +language/expressions/class/elements/same-line-async-gen-rs-privatename-identifier-initializer-alt.js +language/expressions/class/elements/literal-name-init-err-contains-arguments.js +language/expressions/class/elements/same-line-async-gen-rs-privatename-identifier-alt.js +language/expressions/class/elements/private-methods/prod-private-method-initialize-order.js +language/expressions/class/elements/regular-definitions-rs-static-privatename-identifier-alt-by-classname.js +language/expressions/class/elements/regular-definitions-rs-privatename-identifier.js +language/expressions/class/elements/prod-private-setter-before-super-return-in-field-initializer.js +language/expressions/class/elements/redeclaration-symbol.js +language/expressions/class/elements/after-same-line-static-gen-rs-static-privatename-identifier.js +language/expressions/class/elements/regular-definitions-rs-static-async-generator-method-privatename-identifier-alt.js +language/expressions/class/elements/after-same-line-static-async-method-rs-privatename-identifier.js +language/expressions/class/elements/after-same-line-static-async-method-private-method-getter-usage.js +language/expressions/class/elements/multiple-definitions-rs-static-method-privatename-identifier.js +language/expressions/class/elements/after-same-line-method-rs-private-getter-alt.js +language/expressions/class/elements/after-same-line-static-method-rs-static-privatename-identifier-alt-by-classname.js +language/expressions/class/elements/same-line-gen-rs-static-privatename-identifier-by-classname.js +language/expressions/class/elements/after-same-line-static-method-rs-field-identifier-initializer.js +language/expressions/class/elements/same-line-method-private-field-usage.js +language/expressions/class/elements/after-same-line-method-literal-names-asi.js +language/expressions/class/elements/wrapped-in-sc-rs-static-privatename-identifier.js +language/expressions/class/elements/same-line-method-literal-names.js +language/expressions/class/elements/wrapped-in-sc-computed-names.js +language/expressions/class/elements/same-line-async-gen-rs-static-generator-method-privatename-identifier-alt.js +language/expressions/class/elements/multiple-definitions-private-method-getter-usage.js +language/expressions/class/elements/after-same-line-static-async-gen-rs-static-privatename-identifier.js +language/expressions/class/elements/after-same-line-gen-private-method-getter-usage.js +language/expressions/class/elements/after-same-line-static-gen-static-private-methods.js +language/expressions/class/elements/prod-private-method-before-super-return-in-field-initializer.js +language/expressions/class/elements/fields-literal-name-propname-constructor.js +language/expressions/class/elements/multiple-stacked-definitions-rs-static-async-generator-method-privatename-identifier.js +language/expressions/class/elements/new-sc-line-method-rs-privatename-identifier.js +language/expressions/class/elements/new-no-sc-line-method-static-private-fields.js +language/expressions/class/elements/wrapped-in-sc-rs-private-setter.js +language/expressions/class/elements/multiple-definitions-computed-names.js +language/expressions/class/elements/after-same-line-method-rs-privatename-identifier.js +language/expressions/class/elements/same-line-method-rs-field-identifier-initializer.js +language/expressions/class/elements/same-line-method-computed-names.js +language/expressions/class/elements/private-setter-shadowed-by-getter-on-nested-class.js +language/expressions/class/elements/after-same-line-method-rs-static-privatename-identifier-by-classname.js +language/expressions/class/elements/new-sc-line-gen-rs-field-identifier-initializer.js +language/expressions/class/elements/after-same-line-static-async-method-rs-privatename-identifier-alt.js +language/expressions/class/elements/after-same-line-static-method-rs-static-async-method-privatename-identifier-alt.js +language/expressions/class/elements/regular-definitions-rs-private-method.js +language/expressions/class/elements/static-private-init-err-contains-super.js +language/expressions/class/elements/after-same-line-gen-computed-symbol-names.js +language/expressions/class/elements/same-line-method-rs-static-method-privatename-identifier-alt.js +language/expressions/class/elements/static-string-literal-name-init-err-contains-super.js +language/expressions/class/elements/after-same-line-static-method-static-private-fields.js +language/expressions/class/elements/after-same-line-method-rs-field-identifier-initializer.js +language/expressions/class/elements/new-no-sc-line-method-rs-static-async-method-privatename-identifier-alt.js +language/expressions/class/elements/same-line-async-gen-rs-static-privatename-identifier-initializer-alt-by-classname.js +language/expressions/class/elements/same-line-async-gen-grammar-privatename-identifier-semantics-stringvalue.js +language/expressions/class/elements/same-line-method-rs-private-getter-alt.js +language/expressions/class/elements/multiple-definitions-static-private-methods.js +language/expressions/class/elements/same-line-gen-rs-privatename-identifier-initializer.js +language/expressions/class/elements/new-no-sc-line-method-rs-static-privatename-identifier-initializer-alt-by-classname.js +language/expressions/class/elements/nested-private-ternary-init-err-contains-arguments.js +language/expressions/class/elements/after-same-line-static-async-gen-rs-static-async-method-privatename-identifier-alt.js +language/expressions/class/elements/after-same-line-static-gen-rs-privatename-identifier.js +language/expressions/class/elements/new-sc-line-method-private-field-usage.js +language/expressions/class/elements/after-same-line-static-method-static-private-methods-with-fields.js +language/expressions/class/elements/same-line-async-gen-rs-static-method-privatename-identifier.js +language/expressions/class/elements/wrapped-in-sc-rs-private-method-alt.js +language/expressions/class/elements/multiple-definitions-rs-private-method.js +language/expressions/class/elements/after-same-line-static-gen-computed-symbol-names.js +language/expressions/class/elements/multiple-stacked-definitions-static-private-methods.js +language/expressions/class/elements/after-same-line-gen-literal-names.js +language/expressions/class/elements/same-line-method-private-method-usage.js +language/expressions/class/elements/new-sc-line-method-rs-privatename-identifier-alt.js +language/expressions/class/elements/multiple-definitions-rs-static-async-method-privatename-identifier.js +language/expressions/class/elements/after-same-line-static-async-gen-rs-static-generator-method-privatename-identifier.js +language/expressions/class/elements/new-sc-line-gen-rs-static-privatename-identifier.js +language/expressions/class/elements/after-same-line-method-static-private-methods-with-fields.js +language/expressions/class/elements/fields-asi-4.js +language/expressions/class/elements/multiple-definitions-rs-static-privatename-identifier-initializer-alt.js +language/expressions/class/elements/static-string-literal-name-init-err-contains-arguments.js +language/expressions/class/elements/same-line-async-method-rs-privatename-identifier.js +language/expressions/class/elements/multiple-stacked-definitions-rs-static-privatename-identifier-alt-by-classname.js +language/expressions/class/elements/nested-ternary-init-err-contains-arguments.js +language/expressions/class/elements/nested-static-literal-init-err-contains-super.js +language/expressions/class/elements/multiple-stacked-definitions-rs-static-async-method-privatename-identifier-alt.js +language/expressions/class/elements/multiple-definitions-rs-static-privatename-identifier-alt.js +language/expressions/class/elements/after-same-line-method-rs-static-async-method-privatename-identifier.js +language/expressions/class/elements/multiple-definitions-rs-private-setter-alt.js +language/expressions/class/elements/after-same-line-static-async-method-string-literal-names.js +language/expressions/class/elements/same-line-gen-rs-static-privatename-identifier-initializer-alt.js +language/expressions/class/elements/multiple-definitions-rs-static-privatename-identifier-alt-by-classname.js +language/expressions/class/elements/after-same-line-static-async-gen-rs-private-method.js +language/expressions/class/elements/same-line-gen-computed-symbol-names.js +language/expressions/class/elements/same-line-gen-private-field-usage.js +language/expressions/class/elements/after-same-line-static-method-rs-static-generator-method-privatename-identifier-alt.js +language/expressions/class/elements/private-literal-name-init-err-contains-arguments.js +language/expressions/class/elements/new-sc-line-gen-rs-static-privatename-identifier-initializer-alt-by-classname.js +language/expressions/class/elements/new-sc-line-method-rs-static-async-method-privatename-identifier.js +language/expressions/class/elements/same-line-async-method-rs-static-async-generator-method-privatename-identifier-alt.js +language/expressions/class/elements/after-same-line-static-async-gen-rs-static-privatename-identifier-alt.js +language/expressions/class/elements/multiple-stacked-definitions-computed-names.js +language/expressions/class/elements/new-sc-line-method-rs-static-async-generator-method-privatename-identifier-alt.js +language/expressions/class/elements/after-same-line-static-method-rs-static-generator-method-privatename-identifier.js +language/expressions/class/elements/after-same-line-static-async-method-rs-privatename-identifier-initializer-alt.js +language/expressions/class/elements/same-line-async-gen-private-method-usage.js +language/expressions/class/elements/same-line-method-rs-privatename-identifier.js +language/expressions/class/elements/multiple-stacked-definitions-private-method-getter-usage.js +language/expressions/class/elements/same-line-method-static-private-methods-with-fields.js +language/expressions/class/elements/new-no-sc-line-method-literal-names-asi.js +language/expressions/class/elements/after-same-line-static-async-method-rs-private-getter.js +language/expressions/class/elements/regular-definitions-rs-private-getter.js +language/expressions/class/elements/same-line-async-gen-rs-static-async-method-privatename-identifier-alt.js +language/expressions/class/elements/after-same-line-static-async-method-rs-static-async-method-privatename-identifier.js +language/expressions/class/elements/after-same-line-method-private-method-getter-usage.js +language/expressions/class/elements/new-no-sc-line-method-rs-static-method-privatename-identifier.js +language/expressions/class/elements/new-no-sc-line-method-literal-names.js +language/expressions/class/elements/after-same-line-method-private-method-usage.js +language/expressions/class/elements/same-line-gen-static-private-methods.js +language/expressions/class/elements/after-same-line-static-method-grammar-privatename-identifier-semantics-stringvalue.js +language/expressions/class/elements/same-line-method-computed-symbol-names.js +language/expressions/class/elements/after-same-line-static-async-gen-rs-privatename-identifier.js +language/expressions/class/elements/nested-typeof-init-err-contains-arguments.js +language/expressions/class/elements/after-same-line-gen-private-method-usage.js +language/expressions/class/elements/new-sc-line-gen-rs-private-method-alt.js +language/expressions/class/elements/multiple-definitions-rs-static-generator-method-privatename-identifier.js +language/expressions/class/elements/nested-comp-name-init-err-contains-super.js +language/expressions/class/elements/private-getter-shadowed-by-setter-on-nested-class.js +language/expressions/class/elements/after-same-line-static-gen-private-field-usage.js +language/expressions/class/elements/after-same-line-static-async-method-rs-field-identifier.js +language/expressions/class/elements/new-sc-line-gen-private-method-getter-usage.js +language/expressions/class/elements/after-same-line-static-async-method-computed-symbol-names.js +language/expressions/class/elements/after-same-line-static-gen-rs-private-setter-alt.js +language/expressions/class/elements/after-same-line-method-rs-static-generator-method-privatename-identifier.js +language/expressions/class/elements/same-line-async-gen-string-literal-names.js +language/expressions/class/elements/new-sc-line-gen-static-private-methods-with-fields.js +language/expressions/class/elements/same-line-async-gen-static-private-methods-with-fields.js +language/expressions/class/elements/syntax/valid/grammar-field-identifier-alt.js +language/expressions/class/elements/syntax/valid/grammar-field-classelementname-initializer-alt.js +language/expressions/class/elements/syntax/valid/grammar-field-identifier.js +language/expressions/class/elements/syntax/valid/grammar-fields-multi-line.js +language/expressions/class/elements/syntax/valid/grammar-field-classelementname-initializer.js +language/expressions/class/elements/syntax/early-errors/delete/field-delete-twice-covered-err-delete-call-expression-private-method-gen.js +language/expressions/class/elements/syntax/early-errors/delete/field-delete-twice-covered-err-delete-call-expression-private-method-accessor-set.js +language/expressions/class/elements/syntax/early-errors/delete/field-delete-twice-covered-err-delete-member-expression-private-method-accessor-get.js +language/expressions/class/elements/syntax/early-errors/delete/field-delete-twice-covered-err-delete-call-expression-private-method-async-gen.js +language/expressions/class/elements/syntax/early-errors/delete/field-delete-covered-err-delete-member-expression-privatename.js +language/expressions/class/elements/syntax/early-errors/delete/method-delete-covered-err-delete-call-expression-private-method-accessor-set.js +language/expressions/class/elements/syntax/early-errors/delete/field-delete-err-delete-member-expression-private-method-accessor-set.js +language/expressions/class/elements/syntax/early-errors/delete/field-delete-covered-err-delete-member-expression-private-method-accessor-get.js +language/expressions/class/elements/syntax/early-errors/delete/field-delete-err-delete-call-expression-private-method-async.js +language/expressions/class/elements/syntax/early-errors/delete/field-delete-err-delete-member-expression-private-method-gen.js +language/expressions/class/elements/syntax/early-errors/delete/field-delete-err-delete-member-expression-private-no-reference.js +language/expressions/class/elements/syntax/early-errors/delete/field-delete-covered-err-delete-call-expression-private-no-reference.js +language/expressions/class/elements/syntax/early-errors/delete/field-delete-twice-covered-err-delete-call-expression-private-method-accessor-get.js +language/expressions/class/elements/syntax/early-errors/delete/field-delete-twice-covered-err-delete-call-expression-private-method.js +language/expressions/class/elements/syntax/early-errors/delete/field-delete-covered-err-delete-member-expression-private-method.js +language/expressions/class/elements/syntax/early-errors/delete/field-delete-err-delete-call-expression-privatename.js +language/expressions/class/elements/syntax/early-errors/delete/field-delete-err-delete-member-expression-private-method-async.js +language/expressions/class/elements/syntax/early-errors/delete/field-delete-covered-err-delete-call-expression-private-method-accessor-get.js +language/expressions/class/elements/syntax/early-errors/delete/field-delete-err-delete-call-expression-private-method-accessor-get.js +language/expressions/class/elements/syntax/early-errors/delete/field-delete-err-delete-member-expression-private-method-async-gen.js +language/expressions/class/elements/syntax/early-errors/delete/field-delete-covered-err-delete-member-expression-private-method-async-gen.js +language/expressions/class/elements/syntax/early-errors/delete/field-delete-err-delete-call-expression-private-method-gen.js +language/expressions/class/elements/syntax/early-errors/delete/field-delete-covered-err-delete-call-expression-privatename.js +language/expressions/class/elements/syntax/early-errors/delete/field-delete-covered-err-delete-call-expression-private-method-gen.js +language/expressions/class/elements/syntax/early-errors/delete/field-delete-twice-covered-err-delete-member-expression-private-method-async-gen.js +language/expressions/class/elements/syntax/early-errors/delete/field-delete-covered-err-delete-call-expression-private-method-accessor-set.js +language/expressions/class/elements/syntax/early-errors/delete/field-delete-twice-covered-err-delete-member-expression-private-method-gen.js +language/expressions/class/elements/syntax/early-errors/delete/field-delete-covered-err-delete-member-expression-private-method-async.js +language/expressions/class/elements/syntax/early-errors/delete/field-delete-twice-covered-err-delete-call-expression-private-no-reference.js +language/expressions/class/elements/syntax/early-errors/delete/field-delete-twice-covered-err-delete-member-expression-private-method.js +language/expressions/class/elements/syntax/early-errors/delete/field-delete-err-delete-call-expression-private-no-reference.js +language/expressions/class/elements/syntax/early-errors/delete/field-delete-twice-covered-err-delete-member-expression-private-no-reference.js +language/expressions/class/elements/syntax/early-errors/delete/field-delete-err-delete-member-expression-private-method.js +language/expressions/class/elements/syntax/early-errors/delete/field-delete-covered-err-delete-call-expression-private-method-async.js +language/expressions/class/elements/syntax/early-errors/delete/method-delete-twice-covered-err-delete-call-expression-private-method-accessor-get.js +language/expressions/class/elements/syntax/early-errors/delete/field-delete-twice-covered-err-delete-member-expression-private-method-async.js +language/expressions/class/elements/syntax/early-errors/delete/field-delete-err-delete-member-expression-private-method-accessor-get.js +language/expressions/class/elements/syntax/early-errors/delete/method-delete-twice-covered-err-delete-call-expression-private-method-accessor-set.js +language/expressions/class/elements/syntax/early-errors/delete/field-delete-covered-err-delete-call-expression-private-method-async-gen.js +language/expressions/class/elements/syntax/early-errors/delete/field-delete-twice-covered-err-delete-call-expression-privatename.js +language/expressions/class/elements/syntax/early-errors/delete/method-delete-err-delete-call-expression-private-method-accessor-get.js +language/expressions/class/elements/syntax/early-errors/delete/field-delete-twice-covered-err-delete-member-expression-private-method-accessor-set.js +language/expressions/class/elements/syntax/early-errors/delete/method-delete-covered-err-delete-call-expression-private-method-accessor-get.js +language/expressions/class/elements/syntax/early-errors/delete/field-delete-twice-covered-err-delete-call-expression-private-method-async.js +language/expressions/class/elements/syntax/early-errors/delete/field-delete-err-delete-call-expression-private-method-accessor-set.js +language/expressions/class/elements/syntax/early-errors/delete/field-delete-covered-err-delete-member-expression-private-method-gen.js +language/expressions/class/elements/syntax/early-errors/delete/field-delete-err-delete-call-expression-private-method-async-gen.js +language/expressions/class/elements/syntax/early-errors/delete/method-delete-err-delete-call-expression-private-method-accessor-set.js +language/expressions/class/elements/syntax/early-errors/delete/field-delete-covered-err-delete-call-expression-private-method.js +language/expressions/class/elements/syntax/early-errors/delete/field-delete-err-delete-call-expression-private-method.js +language/expressions/class/elements/syntax/early-errors/delete/field-delete-covered-err-delete-member-expression-private-method-accessor-set.js +language/expressions/class/elements/syntax/early-errors/delete/field-delete-err-delete-member-expression-privatename.js +language/expressions/class/elements/syntax/early-errors/delete/field-delete-covered-err-delete-member-expression-private-no-reference.js +language/expressions/class/elements/syntax/early-errors/delete/field-delete-twice-covered-err-delete-member-expression-privatename.js +language/expressions/class/elements/syntax/early-errors/grammar-private-environment-on-class-heritage-obj-literal.js +language/expressions/class/elements/syntax/early-errors/grammar-private-environment-on-class-heritage.js +language/expressions/class/elements/syntax/early-errors/grammar-private-environment-on-class-heritage-function-expression.js +language/expressions/class/elements/syntax/early-errors/grammar-field-identifier-invalid-ues-error.js +language/expressions/class/elements/syntax/early-errors/grammar-private-environment-on-class-heritage-array-literal.js +language/expressions/class/elements/syntax/early-errors/grammar-field-identifier-invalid-zwnj-error.js +language/expressions/class/elements/syntax/early-errors/grammar-private-environment-on-class-heritage-recursive.js +language/expressions/class/elements/syntax/early-errors/grammar-privatename-in-computed-property-missing.js +language/expressions/class/elements/syntax/early-errors/invalid-names/field-init-fn-call-expression-bad-reference.js +language/expressions/class/elements/syntax/early-errors/invalid-names/field-init-member-expression-bad-reference.js +language/expressions/class/elements/syntax/early-errors/invalid-names/field-init-fn-call-expression-this.js +language/expressions/class/elements/syntax/early-errors/invalid-names/field-init-member-expression-this.js +language/expressions/class/elements/syntax/early-errors/invalid-names/field-init-fn-member-expression-this.js +language/expressions/class/elements/syntax/early-errors/invalid-names/field-init-fn-member-expression-bad-reference.js +language/expressions/class/elements/syntax/early-errors/invalid-names/field-init-call-expression-bad-reference.js +language/expressions/class/elements/syntax/early-errors/invalid-names/field-init-call-expression-this.js +language/expressions/class/elements/syntax/early-errors/grammar-field-identifier-invalid-zwj-error.js +language/expressions/class/elements/syntax/early-errors/grammar-fields-same-line-error.js +language/expressions/class/elements/syntax/early-errors/grammar-private-environment-on-class-heritage-chained-usage.js +language/expressions/class/elements/private-setter-on-nested-class.js +language/expressions/class/elements/same-line-method-rs-static-generator-method-privatename-identifier-alt.js +language/expressions/class/elements/same-line-method-rs-static-privatename-identifier-alt.js +language/expressions/class/elements/same-line-async-method-private-method-usage.js +language/expressions/class/elements/multiple-definitions-literal-names-asi.js +language/expressions/class/elements/after-same-line-static-method-rs-static-privatename-identifier-by-classname.js +language/expressions/class/elements/after-same-line-method-rs-static-async-method-privatename-identifier-alt.js +language/expressions/class/elements/same-line-method-rs-static-privatename-identifier-alt-by-classname.js +language/expressions/class/elements/same-line-method-rs-static-privatename-identifier-initializer-alt.js +language/expressions/class/elements/same-line-method-rs-static-privatename-identifier-initializer.js +language/expressions/class/elements/private-typeof-init-err-contains-super.js +language/expressions/class/elements/same-line-gen-computed-names.js +language/expressions/class/elements/new-sc-line-method-grammar-privatename-identifier-semantics-stringvalue.js +language/expressions/class/elements/same-line-async-method-rs-private-setter-alt.js +language/expressions/class/elements/multiple-stacked-definitions-rs-private-getter.js +language/expressions/class/elements/after-same-line-method-rs-static-generator-method-privatename-identifier-alt.js +language/expressions/class/elements/after-same-line-gen-rs-static-privatename-identifier-alt.js +language/expressions/class/elements/arrow-fnc-init-err-contains-super.js +language/expressions/class/elements/after-same-line-method-computed-symbol-names.js +language/expressions/class/elements/new-no-sc-line-method-rs-privatename-identifier.js +language/expressions/class/elements/wrapped-in-sc-rs-static-privatename-identifier-by-classname.js +language/expressions/class/elements/private-getter-shadowed-by-field-on-nested-class.js +language/expressions/class/elements/same-line-method-rs-private-getter.js +language/expressions/class/elements/new-no-sc-line-method-rs-private-method-alt.js +language/expressions/class/elements/after-same-line-static-async-method-rs-private-method.js +language/expressions/class/elements/after-same-line-method-static-private-methods.js +language/expressions/class/elements/same-line-async-method-static-private-methods-with-fields.js +language/expressions/class/elements/multiple-stacked-definitions-rs-static-privatename-identifier-by-classname.js +language/expressions/class/elements/after-same-line-method-rs-privatename-identifier-alt.js +language/expressions/class/elements/same-line-gen-rs-static-privatename-identifier.js +language/expressions/class/elements/same-line-method-grammar-privatename-identifier-semantics-stringvalue.js +language/expressions/class/elements/static-comp-name-init-err-contains-arguments.js +language/expressions/class/elements/after-same-line-gen-rs-static-async-generator-method-privatename-identifier-alt.js +language/expressions/class/elements/after-same-line-static-async-method-rs-static-generator-method-privatename-identifier.js +language/expressions/class/elements/super-access-from-arrow-func-on-field.js +language/expressions/class/elements/after-same-line-static-async-method-rs-static-privatename-identifier.js +language/expressions/class/elements/private-literal-name-init-err-contains-super.js +language/expressions/class/elements/multiple-definitions-rs-static-privatename-identifier-initializer-alt-by-classname.js +language/expressions/class/elements/arrow-fnc-init-err-contains-arguments.js +language/expressions/class/elements/after-same-line-method-grammar-privatename-identifier-semantics-stringvalue.js +language/expressions/class/elements/multiple-stacked-definitions-rs-static-generator-method-privatename-identifier-alt.js +language/expressions/class/elements/after-same-line-gen-rs-field-identifier-initializer.js +language/expressions/class/elements/after-same-line-static-gen-string-literal-names.js +language/expressions/class/elements/after-same-line-static-gen-rs-static-async-generator-method-privatename-identifier-alt.js +language/expressions/class/elements/evaluation-error/computed-name-referenceerror.js +language/expressions/class/elements/evaluation-error/computed-name-valueof-err.js +language/expressions/class/elements/evaluation-error/computed-name-toprimitive-err.js +language/expressions/class/elements/evaluation-error/computed-name-toprimitive-returns-nonobject.js +language/expressions/class/elements/evaluation-error/computed-name-tostring-err.js +language/expressions/class/elements/evaluation-error/computed-name-toprimitive-returns-noncallable.js +language/expressions/class/elements/same-line-gen-rs-private-method.js +language/expressions/class/elements/new-no-sc-line-method-rs-static-async-generator-method-privatename-identifier.js +language/expressions/class/elements/new-sc-line-method-static-private-methods-with-fields.js +language/expressions/class/elements/after-same-line-static-gen-rs-private-getter-alt.js +language/expressions/class/elements/after-same-line-static-gen-rs-privatename-identifier-initializer.js +language/expressions/class/elements/same-line-async-method-rs-static-privatename-identifier-alt.js +language/expressions/class/elements/after-same-line-static-async-gen-literal-names.js +language/expressions/class/elements/after-same-line-gen-rs-static-generator-method-privatename-identifier-alt.js +language/expressions/class/elements/after-same-line-static-async-method-rs-static-privatename-identifier-initializer-alt-by-classname.js +language/expressions/class/elements/after-same-line-gen-rs-privatename-identifier.js +language/expressions/class/elements/new-sc-line-method-rs-private-method-alt.js +language/expressions/class/elements/new-no-sc-line-method-rs-static-privatename-identifier-alt.js +language/expressions/class/elements/multiple-definitions-rs-field-identifier-initializer.js +language/expressions/class/elements/wrapped-in-sc-rs-static-async-method-privatename-identifier.js +language/expressions/class/elements/new-sc-line-gen-computed-symbol-names.js +language/expressions/class/elements/after-same-line-gen-rs-static-privatename-identifier.js +language/expressions/class/elements/new-sc-line-gen-private-method-usage.js +language/expressions/class/elements/after-same-line-static-method-rs-static-privatename-identifier-initializer-alt-by-classname.js +language/expressions/class/elements/after-same-line-gen-rs-private-getter.js +language/expressions/class/elements/same-line-async-gen-rs-private-method.js +language/expressions/class/elements/new-sc-line-method-private-method-getter-usage.js +language/expressions/class/elements/prod-private-getter-before-super-return-in-field-initializer.js +language/expressions/class/elements/new-no-sc-line-method-rs-privatename-identifier-initializer.js +language/expressions/class/elements/after-same-line-method-rs-static-privatename-identifier-alt.js +language/expressions/class/elements/same-line-gen-literal-names.js +language/expressions/class/elements/wrapped-in-sc-rs-privatename-identifier-initializer-alt.js +language/expressions/class/elements/fields-asi-same-line-1.js +language/expressions/class/elements/same-line-async-method-computed-symbol-names.js +language/expressions/class/elements/multiple-stacked-definitions-rs-privatename-identifier.js +language/expressions/class/elements/after-same-line-static-async-method-rs-field-identifier-initializer.js +language/expressions/class/elements/after-same-line-static-method-rs-private-method.js +language/expressions/class/elements/same-line-method-literal-names-asi.js +language/expressions/class/elements/after-same-line-static-gen-rs-field-identifier.js +language/expressions/class/elements/multiple-definitions-rs-privatename-identifier-alt.js +language/expressions/class/elements/after-same-line-gen-rs-privatename-identifier-initializer-alt.js +language/expressions/class/elements/new-sc-line-gen-private-field-usage.js +language/expressions/class/elements/new-sc-line-gen-rs-privatename-identifier.js +language/expressions/class/elements/same-line-method-rs-static-async-generator-method-privatename-identifier-alt.js +language/expressions/class/elements/nested-ternary-init-err-contains-super.js +language/expressions/class/elements/after-same-line-static-gen-rs-static-privatename-identifier-initializer.js +language/expressions/class/elements/same-line-method-rs-private-setter.js +language/expressions/class/elements/wrapped-in-sc-rs-privatename-identifier.js +language/expressions/class/elements/new-sc-line-gen-rs-static-async-generator-method-privatename-identifier-alt.js +language/expressions/class/elements/fields-literal-name-static-propname-constructor.js +language/expressions/class/elements/same-line-gen-rs-privatename-identifier-alt.js +language/expressions/class/elements/after-same-line-static-async-method-rs-private-setter-alt.js +language/expressions/class/elements/same-line-method-rs-static-method-privatename-identifier.js +language/expressions/class/elements/nested-private-arrow-fnc-init-err-contains-arguments.js +language/expressions/class/elements/new-sc-line-gen-rs-static-async-method-privatename-identifier-alt.js +language/expressions/class/elements/new-no-sc-line-method-rs-private-setter-alt.js +language/expressions/class/elements/after-same-line-static-async-method-private-method-usage.js +language/expressions/class/elements/nested-static-private-init-err-contains-super.js +language/expressions/class/elements/after-same-line-static-async-method-private-field-usage.js +language/expressions/class/elements/after-same-line-static-async-gen-rs-static-method-privatename-identifier-alt.js +language/expressions/class/elements/multiple-definitions-string-literal-names.js +language/expressions/class/elements/same-line-method-rs-static-privatename-identifier-initializer-alt-by-classname.js +language/expressions/class/elements/multiple-definitions-rs-static-async-generator-method-privatename-identifier.js +language/expressions/class/elements/after-same-line-static-async-method-rs-static-privatename-identifier-by-classname.js +language/expressions/class/elements/new-no-sc-line-method-static-private-methods-with-fields.js +language/expressions/class/elements/new-no-sc-line-method-private-field-usage.js +language/expressions/class/elements/same-line-async-gen-private-names.js +language/expressions/class/elements/wrapped-in-sc-rs-static-method-privatename-identifier-alt.js +language/expressions/class/elements/new-sc-line-method-rs-static-privatename-identifier-initializer-alt.js +language/expressions/class/elements/new-sc-line-method-rs-static-async-method-privatename-identifier-alt.js +language/expressions/class/elements/same-line-method-rs-static-generator-method-privatename-identifier.js +language/expressions/class/elements/wrapped-in-sc-rs-private-getter-alt.js +language/expressions/class/elements/new-no-sc-line-method-rs-static-privatename-identifier-initializer.js +language/expressions/class/elements/same-line-gen-rs-private-getter.js +language/expressions/class/elements/multiple-stacked-definitions-private-field-usage.js +language/expressions/class/elements/after-same-line-method-static-private-fields.js +language/expressions/class/elements/nested-static-literal-init-err-contains-arguments.js +language/expressions/class/elements/multiple-definitions-rs-static-async-method-privatename-identifier-alt.js +language/expressions/class/elements/new-sc-line-method-rs-private-setter-alt.js +language/expressions/class/elements/after-same-line-static-async-method-literal-names-asi.js +language/expressions/class/elements/multiple-definitions-private-field-usage.js +language/expressions/class/elements/fields-string-name-static-propname-constructor.js +language/expressions/class/elements/private-setter-shadowed-by-setter-on-nested-class.js +language/expressions/class/elements/same-line-method-rs-privatename-identifier-alt.js +language/expressions/class/elements/regular-definitions-rs-private-method-alt.js +language/expressions/class/elements/same-line-async-method-rs-field-identifier.js +language/expressions/class/elements/multiple-stacked-definitions-rs-private-method.js +language/expressions/class/elements/after-same-line-static-async-gen-rs-static-privatename-identifier-initializer-alt-by-classname.js +language/expressions/class/elements/same-line-gen-rs-privatename-identifier.js +language/expressions/class/elements/private-method-on-nested-class.js +language/expressions/class/elements/same-line-async-method-rs-private-getter.js +language/expressions/class/elements/after-same-line-static-gen-grammar-privatename-identifier-semantics-stringvalue.js +language/expressions/class/elements/after-same-line-gen-string-literal-names.js +language/expressions/class/elements/new-sc-line-gen-private-names.js +language/expressions/class/elements/after-same-line-static-gen-rs-private-getter.js +language/expressions/class/elements/regular-definitions-string-literal-names.js +language/expressions/class/elements/fields-anonymous-function-length.js +language/expressions/class/elements/regular-definitions-rs-static-privatename-identifier-initializer-alt-by-classname.js +language/expressions/class/elements/after-same-line-method-rs-static-async-generator-method-privatename-identifier.js +language/expressions/class/elements/new-sc-line-method-literal-names-asi.js +language/expressions/class/elements/same-line-async-gen-literal-names.js +language/expressions/class/elements/wrapped-in-sc-private-method-usage.js +language/expressions/class/elements/after-same-line-static-gen-rs-static-privatename-identifier-initializer-alt-by-classname.js +language/expressions/class/elements/after-same-line-static-async-gen-static-private-fields.js +language/expressions/class/elements/same-line-async-method-rs-privatename-identifier-alt.js +language/expressions/class/elements/after-same-line-static-gen-private-method-getter-usage.js +language/expressions/class/elements/multiple-definitions-rs-private-method-alt.js +language/expressions/class/elements/new-no-sc-line-method-rs-static-method-privatename-identifier-alt.js +language/expressions/class/elements/new-no-sc-line-method-private-names.js +language/expressions/class/elements/after-same-line-static-gen-rs-static-privatename-identifier-alt.js +language/expressions/class/elements/regular-definitions-rs-privatename-identifier-initializer-alt.js +language/expressions/class/elements/same-line-gen-rs-privatename-identifier-initializer-alt.js +language/expressions/class/elements/nested-static-comp-name-init-err-contains-arguments.js +language/expressions/class/elements/new-sc-line-gen-static-private-methods.js +language/expressions/class/elements/ternary-init-err-contains-super.js +language/expressions/class/elements/nested-comp-name-init-err-contains-arguments.js +language/expressions/class/elements/after-same-line-static-method-static-private-methods.js +language/expressions/class/elements/same-line-async-method-rs-static-privatename-identifier-initializer-alt.js +language/expressions/class/elements/same-line-async-method-rs-private-getter-alt.js +language/expressions/class/elements/multiple-definitions-rs-static-async-generator-method-privatename-identifier-alt.js +language/expressions/class/elements/wrapped-in-sc-rs-static-privatename-identifier-alt.js +language/expressions/class/elements/after-same-line-gen-rs-static-method-privatename-identifier.js +language/expressions/class/elements/after-same-line-static-async-gen-rs-private-getter.js +language/expressions/class/elements/multiple-stacked-definitions-literal-names-asi.js +language/expressions/class/elements/after-same-line-static-method-rs-static-privatename-identifier-alt.js +language/expressions/class/elements/after-same-line-gen-rs-privatename-identifier-alt.js +language/expressions/class/elements/after-same-line-static-async-method-computed-names.js +language/expressions/class/elements/after-same-line-gen-rs-static-generator-method-privatename-identifier.js +language/expressions/class/elements/same-line-gen-rs-private-getter-alt.js +language/expressions/class/elements/after-same-line-static-async-method-rs-static-async-method-privatename-identifier-alt.js +language/expressions/class/elements/same-line-async-gen-rs-static-async-generator-method-privatename-identifier.js +language/expressions/class/elements/equality-init-err-contains-arguments.js +language/expressions/class/elements/regular-definitions-rs-field-identifier.js +language/expressions/class/elements/same-line-gen-rs-static-method-privatename-identifier.js +language/expressions/class/elements/after-same-line-method-rs-static-privatename-identifier-alt-by-classname.js +language/expressions/class/elements/wrapped-in-sc-rs-private-method.js +language/expressions/class/elements/multiple-stacked-definitions-rs-privatename-identifier-initializer-alt.js +language/expressions/class/elements/wrapped-in-sc-static-private-methods-with-fields.js +language/expressions/class/elements/new-sc-line-method-rs-static-privatename-identifier-initializer.js +language/expressions/class/elements/new-sc-line-gen-rs-privatename-identifier-alt.js +language/expressions/class/elements/multiple-stacked-definitions-rs-private-method-alt.js +language/expressions/class/elements/after-same-line-gen-rs-static-privatename-identifier-initializer-alt-by-classname.js +language/expressions/class/elements/regular-definitions-rs-static-privatename-identifier-initializer-alt.js +language/expressions/class/elements/same-line-gen-rs-private-method-alt.js +language/expressions/class/elements/regular-definitions-rs-static-privatename-identifier.js +language/expressions/class/elements/after-same-line-static-gen-rs-privatename-identifier-initializer-alt.js +language/expressions/class/elements/after-same-line-static-gen-static-private-fields.js +language/expressions/class/elements/same-line-async-method-string-literal-names.js +language/expressions/class/elements/regular-definitions-static-private-fields.js +language/expressions/class/elements/same-line-gen-rs-static-privatename-identifier-initializer.js +language/expressions/class/elements/new-sc-line-method-rs-static-async-generator-method-privatename-identifier.js +language/expressions/class/elements/same-line-async-gen-rs-static-async-generator-method-privatename-identifier-alt.js +language/expressions/class/elements/regular-definitions-computed-symbol-names.js +language/expressions/class/elements/multiple-definitions-rs-private-setter.js +language/expressions/class/elements/regular-definitions-rs-private-getter-alt.js +language/expressions/class/elements/redeclaration.js +language/expressions/class/elements/same-line-gen-static-private-fields.js +language/expressions/class/elements/nested-arrow-fnc-init-err-contains-arguments.js +language/expressions/class/elements/new-sc-line-gen-string-literal-names.js +language/expressions/class/elements/wrapped-in-sc-rs-static-async-generator-method-privatename-identifier-alt.js +language/expressions/class/elements/private-method-shadowed-by-getter-on-nested-class.js +language/expressions/class/elements/new-sc-line-method-static-private-fields.js +language/expressions/class/elements/after-same-line-method-computed-names.js +language/expressions/class/elements/same-line-async-gen-rs-private-method-alt.js +language/expressions/class/elements/regular-definitions-private-field-usage.js +language/expressions/class/elements/regular-definitions-rs-static-privatename-identifier-alt.js +language/expressions/class/elements/multiple-definitions-private-method-usage.js +language/expressions/class/elements/after-same-line-static-async-method-rs-static-async-generator-method-privatename-identifier-alt.js +language/expressions/class/cpn-class-expr-fields-methods-computed-property-name-from-string-literal.js +language/expressions/class/cpn-class-expr-fields-computed-property-name-from-exponetiation-expression.js +language/expressions/class/cpn-class-expr-fields-methods-computed-property-name-from-condition-expression-false.js +language/expressions/class/cpn-class-expr-fields-computed-property-name-from-expression-logical-and.js +language/expressions/class/cpn-class-expr-fields-computed-property-name-from-null.js +language/expressions/class/cpn-class-expr-fields-methods-computed-property-name-from-yield-expression.js +language/expressions/class/cpn-class-expr-fields-methods-computed-property-name-from-null.js +language/expressions/class/cpn-class-expr-fields-computed-property-name-from-decimal-e-notational-literal.js +language/expressions/class/cpn-class-expr-fields-computed-property-name-from-function-declaration.js +language/expressions/class/cpn-class-expr-fields-computed-property-name-from-integer-e-notational-literal.js +language/expressions/class/cpn-class-expr-fields-computed-property-name-from-async-arrow-function-expression.js +language/expressions/class/cpn-class-expr-fields-methods-computed-property-name-from-arrow-function-expression.js +language/expressions/class/cpn-class-expr-fields-methods-computed-property-name-from-identifier.js +language/expressions/class/cpn-class-expr-fields-computed-property-name-from-identifier.js +language/expressions/class/cpn-class-expr-fields-computed-property-name-from-assignment-expression-coalesce.js +language/expressions/class/cpn-class-expr-fields-methods-computed-property-name-from-additive-expression-add.js +language/expressions/class/cpn-class-expr-fields-methods-computed-property-name-from-assignment-expression-logical-or.js +language/expressions/class/cpn-class-expr-fields-methods-computed-property-name-from-multiplicative-expression-div.js +language/expressions/class/cpn-class-expr-fields-computed-property-name-from-assignment-expression-bitwise-or.js +language/expressions/class/cpn-class-expr-fields-computed-property-name-from-additive-expression-add.js +language/expressions/class/cpn-class-expr-fields-computed-property-name-from-numeric-literal.js +language/expressions/class/cpn-class-expr-fields-methods-computed-property-name-from-async-arrow-function-expression.js +language/expressions/class/cpn-class-expr-fields-methods-computed-property-name-from-function-expression.js +language/expressions/class/cpn-class-expr-fields-computed-property-name-from-arrow-function-expression.js +language/expressions/class/cpn-class-expr-fields-computed-property-name-from-assignment-expression-logical-or.js +language/expressions/class/constructor-this-tdz-during-initializers.js +language/expressions/class/cpn-class-expr-fields-methods-computed-property-name-from-generator-function-declaration.js +language/expressions/class/cpn-class-expr-fields-methods-computed-property-name-from-expression-coalesce.js +language/expressions/class/cpn-class-expr-fields-methods-computed-property-name-from-expression-logical-or.js +language/expressions/class/cpn-class-expr-fields-computed-property-name-from-string-literal.js +language/expressions/class/cpn-class-expr-fields-methods-computed-property-name-from-assignment-expression-coalesce.js +language/expressions/class/cpn-class-expr-fields-computed-property-name-from-additive-expression-subtract.js +language/expressions/class/cpn-class-expr-fields-computed-property-name-from-assignment-expression-assignment.js +language/expressions/class/cpn-class-expr-fields-methods-computed-property-name-from-function-declaration.js +language/expressions/class/cpn-class-expr-fields-methods-computed-property-name-from-decimal-literal.js +language/expressions/class/cpn-class-expr-fields-computed-property-name-from-integer-separators.js +language/expressions/class/cpn-class-expr-fields-methods-computed-property-name-from-multiplicative-expression-mult.js +language/expressions/class/cpn-class-expr-fields-methods-computed-property-name-from-math.js +language/expressions/class/cpn-class-expr-fields-computed-property-name-from-yield-expression.js +language/expressions/class/cpn-class-expr-fields-methods-computed-property-name-from-exponetiation-expression.js +language/expressions/class/cpn-class-expr-fields-computed-property-name-from-condition-expression-true.js +language/expressions/class/cpn-class-expr-fields-methods-computed-property-name-from-additive-expression-subtract.js +language/expressions/class/cpn-class-expr-fields-methods-computed-property-name-from-expression-logical-and.js +language/expressions/class/cpn-class-expr-fields-computed-property-name-from-condition-expression-false.js +language/expressions/class/cpn-class-expr-fields-computed-property-name-from-generator-function-declaration.js +language/expressions/class/cpn-class-expr-fields-methods-computed-property-name-from-condition-expression-true.js +language/expressions/class/cpn-class-expr-fields-methods-computed-property-name-from-integer-e-notational-literal.js +language/expressions/class/cpn-class-expr-fields-methods-computed-property-name-from-decimal-e-notational-literal.js +language/expressions/class/cpn-class-expr-fields-computed-property-name-from-expression-coalesce.js +language/expressions/class/cpn-class-expr-fields-methods-computed-property-name-from-numeric-literal.js +language/expressions/class/cpn-class-expr-fields-computed-property-name-from-assignment-expression-logical-and.js +language/expressions/class/cpn-class-expr-fields-computed-property-name-from-multiplicative-expression-div.js +language/expressions/class/cpn-class-expr-fields-computed-property-name-from-function-expression.js +language/statements/class/cpn-class-decl-fields-methods-computed-property-name-from-expression-logical-or.js +language/statements/class/cpn-class-decl-fields-methods-computed-property-name-from-expression-coalesce.js +language/statements/class/cpn-class-decl-fields-computed-property-name-from-assignment-expression-assignment.js +language/statements/class/cpn-class-decl-fields-computed-property-name-from-multiplicative-expression-div.js +language/statements/class/cpn-class-decl-fields-computed-property-name-from-condition-expression-false.js +language/statements/class/cpn-class-decl-fields-computed-property-name-from-assignment-expression-bitwise-or.js +language/statements/class/cpn-class-decl-fields-computed-property-name-from-exponetiation-expression.js +language/statements/class/cpn-class-decl-fields-computed-property-name-from-assignment-expression-logical-or.js +language/statements/class/cpn-class-decl-fields-methods-computed-property-name-from-assignment-expression-logical-or.js +language/statements/class/cpn-class-decl-fields-methods-computed-property-name-from-exponetiation-expression.js +language/statements/class/elements/same-line-async-method-rs-private-method.js +language/statements/class/elements/after-same-line-method-rs-private-setter.js +language/statements/class/elements/after-same-line-gen-rs-static-privatename-identifier-by-classname.js +language/statements/class/elements/wrapped-in-sc-grammar-privatename-identifier-semantics-stringvalue.js +language/statements/class/elements/new-no-sc-line-method-private-method-usage.js +language/statements/class/elements/after-same-line-static-gen-rs-static-privatename-identifier-by-classname.js +language/statements/class/elements/after-same-line-static-method-rs-privatename-identifier-alt.js +language/statements/class/elements/same-line-gen-rs-static-async-generator-method-privatename-identifier-alt.js +language/statements/class/elements/after-same-line-static-gen-rs-static-async-method-privatename-identifier-alt.js +language/statements/class/elements/after-same-line-static-method-computed-names.js +language/statements/class/elements/same-line-async-method-rs-privatename-identifier-initializer-alt.js +language/statements/class/elements/multiple-definitions-rs-static-privatename-identifier-initializer.js +language/statements/class/elements/abrupt-completition-on-field-initializer.js +language/statements/class/elements/after-same-line-static-method-literal-names.js +language/statements/class/elements/multiple-definitions-rs-static-privatename-identifier-by-classname.js +language/statements/class/elements/after-same-line-gen-rs-private-method.js +language/statements/class/elements/typeof-init-err-contains-arguments.js +language/statements/class/elements/after-same-line-static-method-rs-static-async-method-privatename-identifier.js +language/statements/class/elements/after-same-line-static-method-private-field-usage.js +language/statements/class/elements/nested-string-literal-name-init-err-contains-super.js +language/statements/class/elements/new-sc-line-gen-rs-field-identifier.js +language/statements/class/elements/after-same-line-static-gen-rs-static-generator-method-privatename-identifier-alt.js +language/statements/class/elements/static-as-valid-instance-field-assigned.js +language/statements/class/elements/same-line-gen-string-literal-names.js +language/statements/class/elements/after-same-line-static-gen-literal-names-asi.js +language/statements/class/elements/same-line-gen-rs-static-async-generator-method-privatename-identifier.js +language/statements/class/elements/same-line-gen-rs-static-generator-method-privatename-identifier-alt.js +language/statements/class/elements/same-line-async-gen-rs-private-getter.js +language/statements/class/elements/same-line-async-method-static-private-methods.js +language/statements/class/elements/after-same-line-static-gen-rs-static-privatename-identifier-alt-by-classname.js +language/statements/class/elements/regular-definitions-private-method-getter-usage.js +language/statements/class/elements/typeof-init-err-contains-super.js +language/statements/class/elements/after-same-line-static-async-gen-rs-privatename-identifier-initializer.js +language/statements/class/elements/after-same-line-gen-literal-names-asi.js +language/statements/class/elements/regular-definitions-rs-private-setter-alt.js +language/statements/class/elements/new-sc-line-gen-grammar-privatename-identifier-semantics-stringvalue.js +language/statements/class/elements/multiple-stacked-definitions-private-method-usage.js +language/statements/class/elements/same-line-async-gen-rs-static-privatename-identifier-alt-by-classname.js +language/statements/class/elements/super-fielddefinition-initializer-abrupt-completion.js +language/statements/class/elements/multiple-stacked-definitions-rs-static-privatename-identifier.js +language/statements/class/elements/nested-private-literal-name-init-err-contains-arguments.js +language/statements/class/elements/nested-typeof-init-err-contains-super.js +language/statements/class/elements/after-same-line-gen-static-private-methods.js +language/statements/class/elements/after-same-line-static-async-gen-rs-private-setter-alt.js +language/statements/class/elements/wrapped-in-sc-rs-privatename-identifier-initializer.js +language/statements/class/elements/wrapped-in-sc-rs-private-getter.js +language/statements/class/elements/new-sc-line-gen-rs-static-async-generator-method-privatename-identifier.js +language/statements/class/elements/after-same-line-static-gen-rs-privatename-identifier-alt.js +language/statements/class/elements/after-same-line-static-async-method-rs-static-privatename-identifier-initializer-alt.js +language/statements/class/elements/regular-definitions-private-names.js +language/statements/class/elements/new-no-sc-line-method-rs-private-getter-alt.js +language/statements/class/elements/wrapped-in-sc-rs-static-privatename-identifier-initializer-alt-by-classname.js +language/statements/class/elements/after-same-line-static-async-gen-rs-static-privatename-identifier-by-classname.js +language/statements/class/elements/same-line-async-gen-computed-symbol-names.js +language/statements/class/elements/after-same-line-gen-rs-privatename-identifier-initializer.js +language/statements/class/elements/private-method-shadowed-by-setter-on-nested-class.js +language/statements/class/elements/comp-name-init-err-contains-super.js +language/statements/class/elements/new-no-sc-line-method-rs-private-setter.js +language/statements/class/elements/same-line-async-gen-rs-static-privatename-identifier-initializer-alt.js +language/statements/class/elements/after-same-line-static-async-gen-rs-private-getter-alt.js +language/statements/class/elements/multiple-definitions-rs-private-getter.js +language/statements/class/elements/multiple-stacked-definitions-rs-static-generator-method-privatename-identifier.js +language/statements/class/elements/wrapped-in-sc-string-literal-names.js +language/statements/class/elements/new-no-sc-line-method-string-literal-names.js +language/statements/class/elements/regular-definitions-computed-names.js +language/statements/class/elements/same-line-async-method-rs-field-identifier-initializer.js +language/statements/class/elements/multiple-definitions-private-names.js +language/statements/class/elements/same-line-async-gen-static-private-fields.js +language/statements/class/elements/same-line-async-method-rs-static-method-privatename-identifier-alt.js +language/statements/class/elements/same-line-async-gen-rs-static-privatename-identifier-initializer.js +language/statements/class/elements/same-line-gen-rs-static-async-method-privatename-identifier-alt.js +language/statements/class/elements/same-line-async-gen-rs-private-setter-alt.js +language/statements/class/elements/same-line-gen-private-method-usage.js +language/statements/class/elements/after-same-line-static-method-rs-static-async-generator-method-privatename-identifier-alt.js +language/statements/class/elements/multiple-stacked-definitions-computed-symbol-names.js +language/statements/class/elements/wrapped-in-sc-rs-field-identifier.js +language/statements/class/elements/after-same-line-static-async-method-rs-static-privatename-identifier-initializer.js +language/statements/class/elements/regular-definitions-grammar-privatename-identifier-semantics-stringvalue.js +language/statements/class/elements/after-same-line-method-rs-private-method.js +language/statements/class/elements/private-field-on-nested-class.js +language/statements/class/elements/string-literal-name-init-err-contains-super.js +language/statements/class/elements/multiple-definitions-rs-static-method-privatename-identifier-alt.js +language/statements/class/elements/new-sc-line-method-rs-static-privatename-identifier-initializer-alt-by-classname.js +language/statements/class/elements/after-same-line-static-async-gen-rs-private-method-alt.js +language/statements/class/elements/new-sc-line-gen-rs-private-setter.js +language/statements/class/elements/after-same-line-static-async-method-rs-private-method-alt.js +language/statements/class/elements/same-line-gen-static-private-methods-with-fields.js +language/statements/class/elements/after-same-line-gen-rs-field-identifier.js +language/statements/class/elements/after-same-line-static-method-rs-privatename-identifier.js +language/statements/class/elements/after-same-line-static-method-computed-symbol-names.js +language/statements/class/elements/after-same-line-method-private-names.js +language/statements/class/elements/same-line-async-method-rs-static-privatename-identifier-initializer-alt-by-classname.js +language/statements/class/elements/same-line-async-method-rs-privatename-identifier-initializer.js +language/statements/class/elements/new-sc-line-method-rs-private-setter.js +language/statements/class/elements/equality-init-err-contains-super.js +language/statements/class/elements/new-no-sc-line-method-grammar-privatename-identifier-semantics-stringvalue.js +language/statements/class/elements/multiple-stacked-definitions-rs-private-setter-alt.js +language/statements/class/elements/new-sc-line-gen-rs-static-privatename-identifier-alt.js +language/statements/class/elements/new-sc-line-method-rs-privatename-identifier-initializer-alt.js +language/statements/class/elements/after-same-line-static-async-gen-static-private-methods.js +language/statements/class/elements/after-same-line-static-async-gen-rs-static-privatename-identifier-initializer-alt.js +language/statements/class/elements/same-line-method-private-method-getter-usage.js +language/statements/class/elements/new-no-sc-line-method-rs-static-privatename-identifier-by-classname.js +language/statements/class/elements/new-sc-line-method-rs-static-privatename-identifier-by-classname.js +language/statements/class/elements/same-line-async-gen-rs-field-identifier.js +language/statements/class/elements/same-line-async-method-rs-static-method-privatename-identifier.js +language/statements/class/elements/private-method-shadowed-by-field-on-nested-class.js +language/statements/class/elements/new-no-sc-line-method-computed-names.js +language/statements/class/elements/same-line-method-static-private-fields.js +language/statements/class/elements/after-same-line-static-async-method-rs-privatename-identifier-initializer.js +language/statements/class/elements/after-same-line-static-async-gen-grammar-privatename-identifier-semantics-stringvalue.js +language/statements/class/elements/regular-definitions-literal-names-asi.js +language/statements/class/elements/after-same-line-static-async-method-static-private-methods.js +language/statements/class/elements/new-sc-line-gen-rs-static-privatename-identifier-by-classname.js +language/statements/class/elements/same-line-gen-literal-names-asi.js +language/statements/class/elements/nested-private-typeof-init-err-contains-arguments.js +language/statements/class/elements/new-sc-line-gen-rs-private-getter-alt.js +language/statements/class/elements/same-line-async-gen-rs-static-method-privatename-identifier-alt.js +language/statements/class/elements/same-line-method-rs-private-method-alt.js +language/statements/class/elements/after-same-line-static-gen-static-private-methods-with-fields.js +language/statements/class/elements/private-method-is-not-clobbered-by-computed-property.js +language/statements/class/elements/nested-private-arrow-fnc-init-err-contains-super.js +language/statements/class/elements/same-line-async-method-literal-names-asi.js +language/statements/class/elements/same-line-async-method-private-method-getter-usage.js +language/statements/class/elements/regular-definitions-static-private-methods.js +language/statements/class/elements/after-same-line-static-async-gen-rs-static-generator-method-privatename-identifier-alt.js +language/statements/class/elements/after-same-line-static-async-method-grammar-privatename-identifier-semantics-stringvalue.js +language/statements/class/elements/after-same-line-gen-rs-static-async-generator-method-privatename-identifier.js +language/statements/class/elements/after-same-line-static-gen-rs-private-setter.js +language/statements/class/elements/multiple-stacked-definitions-rs-field-identifier.js +language/statements/class/elements/init-err-evaluation.js +language/statements/class/elements/after-same-line-method-rs-private-setter-alt.js +language/statements/class/elements/same-line-async-gen-literal-names-asi.js +language/statements/class/elements/nested-private-literal-name-init-err-contains-super.js +language/statements/class/elements/private-arrow-fnc-init-err-contains-super.js +language/statements/class/elements/after-same-line-gen-rs-private-getter-alt.js +language/statements/class/elements/after-same-line-static-async-gen-rs-static-async-generator-method-privatename-identifier.js +language/statements/class/elements/multiple-stacked-definitions-rs-static-method-privatename-identifier.js +language/statements/class/elements/after-same-line-static-method-private-method-usage.js +language/statements/class/elements/multiple-stacked-definitions-rs-static-async-method-privatename-identifier.js +language/statements/class/elements/regular-definitions-rs-static-async-method-privatename-identifier-alt.js +language/statements/class/elements/after-same-line-static-method-rs-private-getter.js +language/statements/class/elements/same-line-async-gen-rs-private-setter.js +language/statements/class/elements/after-same-line-gen-grammar-privatename-identifier-semantics-stringvalue.js +language/statements/class/elements/fields-asi-3.js +language/statements/class/elements/after-same-line-static-method-literal-names-asi.js +language/statements/class/elements/after-same-line-method-rs-static-privatename-identifier-initializer-alt.js +language/statements/class/elements/static-as-valid-instance-field.js +language/statements/class/elements/same-line-gen-rs-static-privatename-identifier-alt-by-classname.js +language/statements/class/elements/new-sc-line-gen-literal-names.js +language/statements/class/elements/private-field-is-visible-in-computed-properties.js +language/statements/class/elements/new-no-sc-line-method-static-private-methods.js +language/statements/class/elements/same-line-method-rs-private-method.js +language/statements/class/elements/multiple-stacked-definitions-rs-field-identifier-initializer.js +language/statements/class/elements/after-same-line-static-async-method-rs-static-generator-method-privatename-identifier-alt.js +language/statements/class/elements/after-same-line-static-method-string-literal-names.js +language/statements/class/elements/same-line-gen-rs-static-method-privatename-identifier-alt.js +language/statements/class/elements/new-no-sc-line-method-rs-private-method.js +language/statements/class/elements/same-line-gen-rs-static-generator-method-privatename-identifier.js +language/statements/class/elements/after-same-line-static-async-gen-rs-private-setter.js +language/statements/class/elements/after-same-line-static-async-gen-computed-symbol-names.js +language/statements/class/elements/new-no-sc-line-method-computed-symbol-names.js +language/statements/class/elements/after-same-line-gen-rs-private-setter.js +language/statements/class/elements/same-line-async-method-computed-names.js +language/statements/class/elements/same-line-gen-rs-field-identifier-initializer.js +language/statements/class/elements/wrapped-in-sc-rs-static-async-method-privatename-identifier-alt.js +language/statements/class/elements/after-same-line-static-async-gen-rs-field-identifier.js +language/statements/class/elements/literal-name-init-err-contains-super.js +language/statements/class/elements/new-no-sc-line-method-private-method-getter-usage.js +language/statements/class/elements/after-same-line-gen-rs-static-privatename-identifier-alt-by-classname.js +language/statements/class/elements/same-line-async-gen-rs-field-identifier-initializer.js +language/statements/class/elements/after-same-line-static-async-gen-rs-field-identifier-initializer.js +language/statements/class/elements/after-same-line-static-async-gen-rs-static-privatename-identifier-initializer.js +language/statements/class/elements/after-same-line-gen-rs-static-method-privatename-identifier-alt.js +language/statements/class/elements/nested-static-private-init-err-contains-arguments.js +language/statements/class/elements/wrapped-in-sc-static-private-fields.js +language/statements/class/elements/after-same-line-method-rs-static-method-privatename-identifier-alt.js +language/statements/class/elements/after-same-line-static-gen-rs-private-method-alt.js +language/statements/class/elements/static-private-init-err-contains-arguments.js +language/statements/class/elements/after-same-line-static-async-gen-computed-names.js +language/statements/class/elements/private-ternary-init-err-contains-super.js +language/statements/class/elements/same-line-async-method-rs-static-async-method-privatename-identifier-alt.js +language/statements/class/elements/class-field-on-frozen-objects.js +language/statements/class/elements/regular-definitions-rs-static-method-privatename-identifier.js +language/statements/class/elements/after-same-line-gen-rs-static-async-method-privatename-identifier-alt.js +language/statements/class/elements/wrapped-in-sc-rs-static-method-privatename-identifier.js +language/statements/class/elements/intercalated-static-non-static-computed-fields.js +language/statements/class/elements/after-same-line-gen-computed-names.js +language/statements/class/elements/same-line-method-static-private-methods.js +language/statements/class/elements/regular-definitions-rs-static-privatename-identifier-by-classname.js +language/statements/class/elements/new-sc-line-method-rs-static-privatename-identifier.js +language/statements/class/elements/same-line-method-rs-static-async-method-privatename-identifier-alt.js +language/statements/class/elements/same-line-async-method-private-field-usage.js +language/statements/class/elements/after-same-line-static-async-method-rs-static-async-generator-method-privatename-identifier.js +language/statements/class/elements/after-same-line-static-async-method-rs-private-getter-alt.js +language/statements/class/elements/same-line-async-gen-rs-static-generator-method-privatename-identifier.js +language/statements/class/elements/new-no-sc-line-method-rs-privatename-identifier-initializer-alt.js +language/statements/class/elements/new-sc-line-gen-rs-static-privatename-identifier-initializer-alt.js +language/statements/class/elements/after-same-line-static-async-method-static-private-fields.js +language/statements/class/elements/nested-private-ternary-init-err-contains-super.js +language/statements/class/elements/regular-definitions-rs-static-method-privatename-identifier-alt.js +language/statements/class/elements/wrapped-in-sc-rs-static-privatename-identifier-alt-by-classname.js +language/statements/class/elements/new-sc-line-gen-rs-static-generator-method-privatename-identifier.js +language/statements/class/elements/after-same-line-static-method-rs-privatename-identifier-initializer.js +language/statements/class/elements/same-line-async-gen-rs-privatename-identifier-initializer.js +language/statements/class/elements/fields-asi-same-line-2.js +language/statements/class/elements/after-same-line-method-literal-names.js +language/statements/class/elements/after-same-line-gen-rs-private-method-alt.js +language/statements/class/elements/same-line-async-method-static-private-fields.js +language/statements/class/elements/regular-definitions-rs-static-generator-method-privatename-identifier-alt.js +language/statements/class/elements/new-sc-line-method-rs-static-method-privatename-identifier-alt.js +language/statements/class/elements/after-same-line-static-method-rs-private-setter-alt.js +language/statements/class/elements/nested-literal-name-init-err-contains-super.js +language/statements/class/elements/multiple-stacked-definitions-string-literal-names.js +language/statements/class/elements/regular-definitions-rs-private-setter.js +language/statements/class/elements/multiple-stacked-definitions-rs-static-privatename-identifier-alt.js +language/statements/class/elements/nested-static-string-literal-name-init-err-contains-arguments.js +language/statements/class/elements/after-same-line-method-rs-static-privatename-identifier-initializer-alt-by-classname.js +language/statements/class/elements/multiple-stacked-definitions-static-private-methods-with-fields.js +language/statements/class/elements/after-same-line-static-async-method-rs-static-privatename-identifier-alt.js +language/statements/class/elements/after-same-line-static-async-gen-rs-static-async-generator-method-privatename-identifier-alt.js +language/statements/class/elements/after-same-line-static-async-method-literal-names.js +language/statements/class/elements/new-no-sc-line-method-rs-static-generator-method-privatename-identifier-alt.js +language/statements/class/elements/after-same-line-static-method-rs-private-method-alt.js +language/statements/class/elements/private-getter-shadowed-by-method-on-nested-class.js +language/statements/class/elements/same-line-async-gen-static-private-methods.js +language/statements/class/elements/after-same-line-static-gen-rs-static-privatename-identifier-initializer-alt.js +language/statements/class/elements/fields-asi-1.js +language/statements/class/elements/multiple-definitions-rs-static-generator-method-privatename-identifier-alt.js +language/statements/class/elements/fields-asi-2.js +language/statements/class/elements/multiple-stacked-definitions-private-names.js +language/statements/class/elements/new-sc-line-gen-rs-private-method.js +language/statements/class/elements/static-literal-init-err-contains-arguments.js +language/statements/class/elements/private-arrow-fnc-init-err-contains-arguments.js +language/statements/class/elements/new-sc-line-gen-rs-privatename-identifier-initializer.js +language/statements/class/elements/same-line-async-method-literal-names.js +language/statements/class/elements/computed-name-toprimitive.js +language/statements/class/elements/new-no-sc-line-method-rs-private-getter.js +language/statements/class/elements/after-same-line-gen-static-private-methods-with-fields.js +language/statements/class/elements/init-value-incremental.js +language/statements/class/elements/same-line-method-rs-static-privatename-identifier-by-classname.js +language/statements/class/elements/same-line-method-rs-static-async-method-privatename-identifier.js +language/statements/class/elements/multiple-stacked-definitions-rs-static-privatename-identifier-initializer-alt.js +language/statements/class/elements/regular-definitions-rs-privatename-identifier-initializer.js +language/statements/class/elements/new-sc-line-method-string-literal-names.js +language/statements/class/elements/after-same-line-static-method-rs-static-privatename-identifier-initializer-alt.js +language/statements/class/elements/static-comp-name-init-err-contains-super.js +language/statements/class/elements/after-same-line-static-async-gen-private-names.js +language/statements/class/elements/nested-static-comp-name-init-err-contains-super.js +language/statements/class/elements/class-field-is-observable-by-proxy.js +language/statements/class/elements/multiple-stacked-definitions-rs-static-privatename-identifier-initializer.js +language/statements/class/elements/new-sc-line-gen-rs-static-privatename-identifier-alt-by-classname.js +language/statements/class/elements/after-same-line-static-gen-rs-static-async-method-privatename-identifier.js +language/statements/class/elements/after-same-line-static-method-rs-private-getter-alt.js +language/statements/class/elements/new-no-sc-line-method-rs-static-async-generator-method-privatename-identifier-alt.js +language/statements/class/elements/multiple-stacked-definitions-rs-private-setter.js +language/statements/class/elements/new-sc-line-gen-static-private-fields.js +language/statements/class/elements/new-sc-line-method-rs-private-getter-alt.js +language/statements/class/elements/after-same-line-static-gen-rs-static-generator-method-privatename-identifier.js +language/statements/class/elements/new-sc-line-method-computed-names.js +language/statements/class/elements/same-line-method-rs-privatename-identifier-initializer.js +language/statements/class/elements/multiple-stacked-definitions-grammar-privatename-identifier-semantics-stringvalue.js +language/statements/class/elements/after-same-line-static-async-gen-private-method-getter-usage.js +language/statements/class/elements/fields-string-name-propname-constructor.js +language/statements/class/elements/after-same-line-method-rs-field-identifier.js +language/statements/class/elements/new-sc-line-method-rs-private-getter.js +language/statements/class/elements/after-same-line-static-method-rs-static-privatename-identifier.js +language/statements/class/elements/new-sc-line-gen-computed-names.js +language/statements/class/elements/multiple-definitions-computed-symbol-names.js +language/statements/class/elements/after-same-line-static-async-method-rs-static-method-privatename-identifier-alt.js +language/statements/class/elements/after-same-line-static-async-method-rs-static-method-privatename-identifier.js +language/statements/class/elements/new-sc-line-gen-rs-static-method-privatename-identifier-alt.js +language/statements/class/elements/same-line-gen-rs-private-setter.js +language/statements/class/elements/regular-definitions-rs-privatename-identifier-alt.js +language/statements/class/elements/wrapped-in-sc-private-names.js +language/statements/class/elements/wrapped-in-sc-private-method-getter-usage.js +language/statements/class/elements/same-line-async-method-rs-static-privatename-identifier.js +language/statements/class/elements/new-sc-line-method-rs-privatename-identifier-initializer.js +language/statements/class/elements/regular-definitions-rs-static-generator-method-privatename-identifier.js +language/statements/class/elements/regular-definitions-private-method-usage.js +language/statements/class/elements/after-same-line-static-gen-rs-field-identifier-initializer.js +language/statements/class/elements/same-line-async-method-grammar-privatename-identifier-semantics-stringvalue.js +language/statements/class/elements/same-line-method-string-literal-names.js +language/statements/class/elements/same-line-gen-rs-private-setter-alt.js +language/statements/class/elements/same-line-method-rs-field-identifier.js +language/statements/class/elements/same-line-async-gen-private-field-usage.js +language/statements/class/elements/same-line-gen-private-names.js +language/statements/class/elements/new-sc-line-method-private-names.js +language/statements/class/elements/same-line-async-method-rs-static-privatename-identifier-by-classname.js +language/statements/class/elements/after-same-line-method-rs-private-getter.js +language/statements/class/elements/same-line-async-method-rs-static-generator-method-privatename-identifier-alt.js +language/statements/class/elements/new-sc-line-gen-rs-privatename-identifier-initializer-alt.js +language/statements/class/elements/after-same-line-static-gen-private-method-usage.js +language/statements/class/elements/after-same-line-gen-private-names.js +language/statements/class/elements/after-same-line-method-private-field-usage.js +language/statements/class/elements/regular-definitions-static-private-methods-with-fields.js +language/statements/class/elements/multiple-definitions-literal-names.js +language/statements/class/elements/after-same-line-static-async-gen-static-private-methods-with-fields.js +language/statements/class/elements/new-sc-line-gen-rs-static-privatename-identifier-initializer.js +language/statements/class/elements/wrapped-in-sc-rs-field-identifier-initializer.js +language/statements/class/elements/multiple-definitions-rs-privatename-identifier-initializer.js +language/statements/class/elements/after-same-line-static-gen-rs-static-method-privatename-identifier-alt.js +language/statements/class/elements/init-value-defined-after-class.js +language/statements/class/elements/nested-static-string-literal-name-init-err-contains-super.js +language/statements/class/elements/same-line-method-rs-privatename-identifier-initializer-alt.js +language/statements/class/elements/same-line-method-rs-static-async-generator-method-privatename-identifier.js +language/statements/class/elements/after-same-line-static-method-private-method-getter-usage.js +language/statements/class/elements/nested-arrow-fnc-init-err-contains-super.js +language/statements/class/elements/after-same-line-method-rs-static-async-generator-method-privatename-identifier-alt.js +language/statements/class/elements/new-sc-line-method-private-method-usage.js +language/statements/class/elements/same-line-async-gen-rs-private-getter-alt.js +language/statements/class/elements/multiple-definitions-rs-field-identifier.js +language/statements/class/elements/wrapped-in-sc-rs-private-setter-alt.js +language/statements/class/elements/wrapped-in-sc-rs-static-async-generator-method-privatename-identifier.js +language/statements/class/elements/new-sc-line-method-static-private-methods.js +language/statements/class/elements/after-same-line-static-gen-computed-names.js +language/statements/class/elements/after-same-line-static-async-gen-private-field-usage.js +language/statements/class/elements/same-line-async-gen-rs-privatename-identifier.js +language/statements/class/elements/new-no-sc-line-method-rs-field-identifier.js +language/statements/class/elements/new-sc-line-gen-literal-names-asi.js +language/statements/class/elements/new-sc-line-method-rs-static-privatename-identifier-alt-by-classname.js +language/statements/class/elements/set-access-of-shadowed-private-method.js +language/statements/class/elements/after-same-line-static-async-gen-private-method-usage.js +language/statements/class/elements/new-sc-line-method-rs-static-privatename-identifier-alt.js +language/statements/class/elements/multiple-stacked-definitions-rs-static-async-generator-method-privatename-identifier-alt.js +language/statements/class/elements/after-same-line-static-async-gen-literal-names-asi.js +language/statements/class/elements/nested-literal-name-init-err-contains-arguments.js +language/statements/class/elements/after-same-line-method-rs-static-privatename-identifier.js +language/statements/class/elements/same-line-async-method-rs-static-generator-method-privatename-identifier.js +language/statements/class/elements/after-same-line-static-gen-rs-static-async-generator-method-privatename-identifier.js +language/statements/class/elements/after-same-line-static-method-rs-static-async-generator-method-privatename-identifier.js +language/statements/class/elements/same-line-async-method-rs-static-async-method-privatename-identifier.js +language/statements/class/elements/multiple-definitions-rs-privatename-identifier-initializer-alt.js +language/statements/class/elements/new-no-sc-line-method-rs-static-privatename-identifier-initializer-alt.js +language/statements/class/elements/new-sc-line-method-rs-static-method-privatename-identifier.js +language/statements/class/elements/private-getter-on-nested-class.js +language/statements/class/elements/private-getter-is-not-clobbered-by-computed-property.js +language/statements/class/elements/private-method-shadowed-on-nested-class.js +language/statements/class/elements/field-declaration.js +language/statements/class/elements/after-same-line-method-string-literal-names.js +language/statements/class/elements/same-line-gen-rs-static-privatename-identifier-initializer-alt-by-classname.js +language/statements/class/elements/private-setter-shadowed-by-field-on-nested-class.js +language/statements/class/elements/new-sc-line-method-rs-static-generator-method-privatename-identifier.js +language/statements/class/elements/after-same-line-gen-rs-static-privatename-identifier-initializer.js +language/statements/class/elements/public-class-field-initialization-on-super-class-with-setter.js +language/statements/class/elements/multiple-definitions-grammar-privatename-identifier-semantics-stringvalue.js +language/statements/class/elements/after-same-line-static-gen-private-names.js +language/statements/class/elements/same-line-async-gen-rs-static-privatename-identifier-by-classname.js +language/statements/class/elements/private-class-field-on-frozen-objects.js +language/statements/class/elements/after-same-line-static-method-rs-static-method-privatename-identifier.js +language/statements/class/elements/after-same-line-static-gen-rs-private-method.js +language/statements/class/elements/same-line-async-gen-rs-static-privatename-identifier-alt.js +language/statements/class/elements/string-literal-name-init-err-contains-arguments.js +language/statements/class/elements/same-line-async-method-rs-static-async-generator-method-privatename-identifier.js +language/statements/class/elements/after-same-line-static-async-method-rs-static-privatename-identifier-alt-by-classname.js +language/statements/class/elements/new-sc-line-method-computed-symbol-names.js +language/statements/class/elements/same-line-method-rs-private-setter-alt.js +language/statements/class/elements/wrapped-in-sc-rs-static-privatename-identifier-initializer.js +language/statements/class/elements/nested-string-literal-name-init-err-contains-arguments.js +language/statements/class/elements/after-same-line-static-async-gen-rs-static-privatename-identifier-alt-by-classname.js +language/statements/class/elements/fields-asi-5.js +language/statements/class/elements/regular-definitions-rs-static-async-method-privatename-identifier.js +language/statements/class/elements/regular-definitions-rs-field-identifier-initializer.js +language/statements/class/elements/new-sc-line-gen-rs-static-async-method-privatename-identifier.js +language/statements/class/elements/multiple-stacked-definitions-rs-privatename-identifier-alt.js +language/statements/class/elements/new-sc-line-method-rs-private-method.js +language/statements/class/elements/new-no-sc-line-method-rs-privatename-identifier-alt.js +language/statements/class/elements/nested-equality-init-err-contains-arguments.js +language/statements/class/elements/after-same-line-static-method-rs-private-setter.js +language/statements/class/elements/new-no-sc-line-method-rs-static-async-method-privatename-identifier.js +language/statements/class/elements/private-typeof-init-err-contains-arguments.js +language/statements/class/elements/new-sc-line-method-rs-static-generator-method-privatename-identifier-alt.js +language/statements/class/elements/wrapped-in-sc-rs-static-generator-method-privatename-identifier.js +language/statements/class/elements/ternary-init-err-contains-arguments.js +language/statements/class/elements/multiple-definitions-rs-privatename-identifier.js +language/statements/class/elements/same-line-gen-grammar-privatename-identifier-semantics-stringvalue.js +language/statements/class/elements/new-no-sc-line-method-rs-static-privatename-identifier-alt-by-classname.js +language/statements/class/elements/same-line-method-rs-static-privatename-identifier.js +language/statements/class/elements/multiple-definitions-static-private-methods-with-fields.js +language/statements/class/elements/after-same-line-static-async-gen-rs-privatename-identifier-initializer-alt.js +language/statements/class/elements/same-line-async-method-private-names.js +language/statements/class/elements/comp-name-init-err-contains-arguments.js +language/statements/class/elements/after-same-line-static-gen-literal-names.js +language/statements/class/elements/after-same-line-gen-rs-static-async-method-privatename-identifier.js +language/statements/class/elements/multiple-stacked-definitions-rs-privatename-identifier-initializer.js +language/statements/class/elements/multiple-stacked-definitions-literal-names.js +language/statements/class/elements/same-line-method-private-names.js +language/statements/class/elements/wrapped-in-sc-rs-static-generator-method-privatename-identifier-alt.js +language/statements/class/elements/wrapped-in-sc-literal-names.js +language/statements/class/elements/after-same-line-static-async-gen-string-literal-names.js +language/statements/class/elements/same-line-async-method-rs-private-method-alt.js +language/statements/class/elements/new-no-sc-line-method-rs-field-identifier-initializer.js +language/statements/class/elements/same-line-async-gen-private-method-getter-usage.js +language/statements/class/elements/multiple-definitions-static-private-fields.js +language/statements/class/elements/after-same-line-static-async-gen-rs-static-async-method-privatename-identifier.js +language/statements/class/elements/after-same-line-static-method-rs-privatename-identifier-initializer-alt.js +language/statements/class/elements/regular-definitions-rs-static-async-generator-method-privatename-identifier.js +language/statements/class/elements/wrapped-in-sc-static-private-methods.js +language/statements/class/elements/after-same-line-method-rs-private-method-alt.js +language/statements/class/elements/multiple-stacked-definitions-rs-static-method-privatename-identifier-alt.js +language/statements/class/elements/multiple-stacked-definitions-rs-private-getter-alt.js +language/statements/class/elements/private-getter-shadowed-by-getter-on-nested-class.js +language/statements/class/elements/after-same-line-static-method-rs-static-privatename-identifier-initializer.js +language/statements/class/elements/same-line-async-method-rs-static-privatename-identifier-alt-by-classname.js +language/statements/class/elements/after-same-line-static-method-private-names.js +language/statements/class/elements/same-line-gen-rs-static-async-method-privatename-identifier.js +language/statements/class/elements/new-sc-line-gen-rs-static-generator-method-privatename-identifier-alt.js +language/statements/class/elements/after-same-line-static-async-method-static-private-methods-with-fields.js +language/statements/class/elements/same-line-gen-rs-static-privatename-identifier-alt.js +language/statements/class/elements/same-line-gen-rs-field-identifier.js +language/statements/class/elements/new-no-sc-line-method-rs-static-privatename-identifier.js +language/statements/class/elements/same-line-async-gen-computed-names.js +language/statements/class/elements/after-same-line-static-async-method-private-names.js +language/statements/class/elements/fielddefinition-initializer-abrupt-completion.js +language/statements/class/elements/private-ternary-init-err-contains-arguments.js +language/statements/class/elements/after-same-line-static-async-gen-rs-static-method-privatename-identifier.js +language/statements/class/elements/new-sc-line-method-rs-field-identifier-initializer.js +language/statements/class/elements/private-setter-shadowed-by-method-on-nested-class.js +language/statements/class/elements/multiple-definitions-rs-static-privatename-identifier.js +language/statements/class/elements/same-line-async-method-rs-static-privatename-identifier-initializer.js +language/statements/class/elements/privatefieldset-typeerror-1.js +language/statements/class/elements/after-same-line-static-async-gen-rs-privatename-identifier-alt.js +language/statements/class/elements/wrapped-in-sc-rs-static-privatename-identifier-initializer-alt.js +language/statements/class/elements/after-same-line-method-rs-privatename-identifier-initializer-alt.js +language/statements/class/elements/multiple-stacked-definitions-rs-static-privatename-identifier-initializer-alt-by-classname.js +language/statements/class/elements/same-line-gen-private-method-getter-usage.js +language/statements/class/elements/after-same-line-static-method-rs-static-method-privatename-identifier-alt.js +language/statements/class/elements/after-same-line-static-gen-rs-static-method-privatename-identifier.js +language/statements/class/elements/same-line-async-method-rs-private-setter.js +language/statements/class/elements/after-same-line-gen-static-private-fields.js +language/statements/class/elements/after-same-line-static-method-rs-field-identifier.js +language/statements/class/elements/ctor-called-after-fields-init.js +language/statements/class/elements/same-line-async-gen-rs-static-privatename-identifier.js +language/statements/class/elements/new-sc-line-gen-rs-static-method-privatename-identifier.js +language/statements/class/elements/new-sc-line-method-rs-field-identifier.js +language/statements/class/elements/new-no-sc-line-method-rs-static-generator-method-privatename-identifier.js +language/statements/class/elements/computed-name-toprimitive-symbol.js +language/statements/class/elements/after-same-line-method-rs-privatename-identifier-initializer.js +language/statements/class/elements/after-same-line-gen-private-field-usage.js +language/statements/class/elements/wrapped-in-sc-computed-symbol-names.js +language/statements/class/elements/nested-equality-init-err-contains-super.js +language/statements/class/elements/after-same-line-static-async-method-rs-private-setter.js +language/statements/class/elements/regular-definitions-rs-static-privatename-identifier-initializer.js +language/statements/class/elements/after-same-line-gen-rs-private-setter-alt.js +language/statements/class/elements/nested-private-typeof-init-err-contains-super.js +language/statements/class/elements/new-sc-line-gen-rs-private-getter.js +language/statements/class/elements/wrapped-in-sc-rs-privatename-identifier-alt.js +language/statements/class/elements/new-sc-line-method-literal-names.js +language/statements/class/elements/new-sc-line-gen-rs-private-setter-alt.js +language/statements/class/elements/wrapped-in-sc-literal-names-asi.js +language/statements/class/elements/after-same-line-method-rs-static-privatename-identifier-initializer.js +language/statements/class/elements/same-line-async-gen-rs-static-async-method-privatename-identifier.js +language/statements/class/elements/after-same-line-gen-rs-static-privatename-identifier-initializer-alt.js +language/statements/class/elements/multiple-stacked-definitions-static-private-fields.js +language/statements/class/elements/static-literal-init-err-contains-super.js +language/statements/class/elements/wrapped-in-sc-private-field-usage.js +language/statements/class/elements/multiple-definitions-rs-private-getter-alt.js +language/statements/class/elements/after-same-line-method-rs-static-method-privatename-identifier.js +language/statements/class/elements/regular-definitions-literal-names.js +language/statements/class/elements/same-line-async-gen-rs-privatename-identifier-initializer-alt.js +language/statements/class/elements/literal-name-init-err-contains-arguments.js +language/statements/class/elements/same-line-async-gen-rs-privatename-identifier-alt.js +language/statements/class/elements/private-methods/prod-private-method-initialize-order.js +language/statements/class/elements/regular-definitions-rs-static-privatename-identifier-alt-by-classname.js +language/statements/class/elements/regular-definitions-rs-privatename-identifier.js +language/statements/class/elements/prod-private-setter-before-super-return-in-field-initializer.js +language/statements/class/elements/redeclaration-symbol.js +language/statements/class/elements/after-same-line-static-gen-rs-static-privatename-identifier.js +language/statements/class/elements/regular-definitions-rs-static-async-generator-method-privatename-identifier-alt.js +language/statements/class/elements/after-same-line-static-async-method-rs-privatename-identifier.js +language/statements/class/elements/after-same-line-static-async-method-private-method-getter-usage.js +language/statements/class/elements/multiple-definitions-rs-static-method-privatename-identifier.js +language/statements/class/elements/after-same-line-method-rs-private-getter-alt.js +language/statements/class/elements/after-same-line-static-method-rs-static-privatename-identifier-alt-by-classname.js +language/statements/class/elements/same-line-gen-rs-static-privatename-identifier-by-classname.js +language/statements/class/elements/after-same-line-static-method-rs-field-identifier-initializer.js +language/statements/class/elements/same-line-method-private-field-usage.js +language/statements/class/elements/after-same-line-method-literal-names-asi.js +language/statements/class/elements/wrapped-in-sc-rs-static-privatename-identifier.js +language/statements/class/elements/same-line-method-literal-names.js +language/statements/class/elements/wrapped-in-sc-computed-names.js +language/statements/class/elements/same-line-async-gen-rs-static-generator-method-privatename-identifier-alt.js +language/statements/class/elements/multiple-definitions-private-method-getter-usage.js +language/statements/class/elements/after-same-line-static-async-gen-rs-static-privatename-identifier.js +language/statements/class/elements/after-same-line-gen-private-method-getter-usage.js +language/statements/class/elements/after-same-line-static-gen-static-private-methods.js +language/statements/class/elements/prod-private-method-before-super-return-in-field-initializer.js +language/statements/class/elements/fields-literal-name-propname-constructor.js +language/statements/class/elements/multiple-stacked-definitions-rs-static-async-generator-method-privatename-identifier.js +language/statements/class/elements/new-sc-line-method-rs-privatename-identifier.js +language/statements/class/elements/new-no-sc-line-method-static-private-fields.js +language/statements/class/elements/wrapped-in-sc-rs-private-setter.js +language/statements/class/elements/multiple-definitions-computed-names.js +language/statements/class/elements/after-same-line-method-rs-privatename-identifier.js +language/statements/class/elements/same-line-method-rs-field-identifier-initializer.js +language/statements/class/elements/same-line-method-computed-names.js +language/statements/class/elements/private-setter-shadowed-by-getter-on-nested-class.js +language/statements/class/elements/after-same-line-method-rs-static-privatename-identifier-by-classname.js +language/statements/class/elements/new-sc-line-gen-rs-field-identifier-initializer.js +language/statements/class/elements/after-same-line-static-async-method-rs-privatename-identifier-alt.js +language/statements/class/elements/after-same-line-static-method-rs-static-async-method-privatename-identifier-alt.js +language/statements/class/elements/regular-definitions-rs-private-method.js +language/statements/class/elements/static-private-init-err-contains-super.js +language/statements/class/elements/after-same-line-gen-computed-symbol-names.js +language/statements/class/elements/same-line-method-rs-static-method-privatename-identifier-alt.js +language/statements/class/elements/static-string-literal-name-init-err-contains-super.js +language/statements/class/elements/after-same-line-static-method-static-private-fields.js +language/statements/class/elements/after-same-line-method-rs-field-identifier-initializer.js +language/statements/class/elements/new-no-sc-line-method-rs-static-async-method-privatename-identifier-alt.js +language/statements/class/elements/same-line-async-gen-rs-static-privatename-identifier-initializer-alt-by-classname.js +language/statements/class/elements/same-line-async-gen-grammar-privatename-identifier-semantics-stringvalue.js +language/statements/class/elements/same-line-method-rs-private-getter-alt.js +language/statements/class/elements/multiple-definitions-static-private-methods.js +language/statements/class/elements/same-line-gen-rs-privatename-identifier-initializer.js +language/statements/class/elements/new-no-sc-line-method-rs-static-privatename-identifier-initializer-alt-by-classname.js +language/statements/class/elements/nested-private-ternary-init-err-contains-arguments.js +language/statements/class/elements/after-same-line-static-async-gen-rs-static-async-method-privatename-identifier-alt.js +language/statements/class/elements/after-same-line-static-gen-rs-privatename-identifier.js +language/statements/class/elements/new-sc-line-method-private-field-usage.js +language/statements/class/elements/after-same-line-static-method-static-private-methods-with-fields.js +language/statements/class/elements/same-line-async-gen-rs-static-method-privatename-identifier.js +language/statements/class/elements/wrapped-in-sc-rs-private-method-alt.js +language/statements/class/elements/multiple-definitions-rs-private-method.js +language/statements/class/elements/after-same-line-static-gen-computed-symbol-names.js +language/statements/class/elements/multiple-stacked-definitions-static-private-methods.js +language/statements/class/elements/after-same-line-gen-literal-names.js +language/statements/class/elements/same-line-method-private-method-usage.js +language/statements/class/elements/new-sc-line-method-rs-privatename-identifier-alt.js +language/statements/class/elements/multiple-definitions-rs-static-async-method-privatename-identifier.js +language/statements/class/elements/after-same-line-static-async-gen-rs-static-generator-method-privatename-identifier.js +language/statements/class/elements/new-sc-line-gen-rs-static-privatename-identifier.js +language/statements/class/elements/after-same-line-method-static-private-methods-with-fields.js +language/statements/class/elements/fields-asi-4.js +language/statements/class/elements/multiple-definitions-rs-static-privatename-identifier-initializer-alt.js +language/statements/class/elements/static-string-literal-name-init-err-contains-arguments.js +language/statements/class/elements/same-line-async-method-rs-privatename-identifier.js +language/statements/class/elements/multiple-stacked-definitions-rs-static-privatename-identifier-alt-by-classname.js +language/statements/class/elements/nested-ternary-init-err-contains-arguments.js +language/statements/class/elements/nested-static-literal-init-err-contains-super.js +language/statements/class/elements/multiple-stacked-definitions-rs-static-async-method-privatename-identifier-alt.js +language/statements/class/elements/multiple-definitions-rs-static-privatename-identifier-alt.js +language/statements/class/elements/after-same-line-method-rs-static-async-method-privatename-identifier.js +language/statements/class/elements/multiple-definitions-rs-private-setter-alt.js +language/statements/class/elements/after-same-line-static-async-method-string-literal-names.js +language/statements/class/elements/same-line-gen-rs-static-privatename-identifier-initializer-alt.js +language/statements/class/elements/multiple-definitions-rs-static-privatename-identifier-alt-by-classname.js +language/statements/class/elements/after-same-line-static-async-gen-rs-private-method.js +language/statements/class/elements/same-line-gen-computed-symbol-names.js +language/statements/class/elements/same-line-gen-private-field-usage.js +language/statements/class/elements/after-same-line-static-method-rs-static-generator-method-privatename-identifier-alt.js +language/statements/class/elements/private-literal-name-init-err-contains-arguments.js +language/statements/class/elements/new-sc-line-gen-rs-static-privatename-identifier-initializer-alt-by-classname.js +language/statements/class/elements/new-sc-line-method-rs-static-async-method-privatename-identifier.js +language/statements/class/elements/same-line-async-method-rs-static-async-generator-method-privatename-identifier-alt.js +language/statements/class/elements/fields-computed-name-propname-constructor.js +language/statements/class/elements/get-access-of-missing-shadowed-private-getter.js +language/statements/class/elements/after-same-line-static-async-gen-rs-static-privatename-identifier-alt.js +language/statements/class/elements/multiple-stacked-definitions-computed-names.js +language/statements/class/elements/new-sc-line-method-rs-static-async-generator-method-privatename-identifier-alt.js +language/statements/class/elements/after-same-line-static-method-rs-static-generator-method-privatename-identifier.js +language/statements/class/elements/after-same-line-static-async-method-rs-privatename-identifier-initializer-alt.js +language/statements/class/elements/same-line-async-gen-private-method-usage.js +language/statements/class/elements/same-line-method-rs-privatename-identifier.js +language/statements/class/elements/multiple-stacked-definitions-private-method-getter-usage.js +language/statements/class/elements/same-line-method-static-private-methods-with-fields.js +language/statements/class/elements/new-no-sc-line-method-literal-names-asi.js +language/statements/class/elements/after-same-line-static-async-method-rs-private-getter.js +language/statements/class/elements/regular-definitions-rs-private-getter.js +language/statements/class/elements/same-line-async-gen-rs-static-async-method-privatename-identifier-alt.js +language/statements/class/elements/after-same-line-static-async-method-rs-static-async-method-privatename-identifier.js +language/statements/class/elements/after-same-line-method-private-method-getter-usage.js +language/statements/class/elements/new-no-sc-line-method-rs-static-method-privatename-identifier.js +language/statements/class/elements/new-no-sc-line-method-literal-names.js +language/statements/class/elements/after-same-line-method-private-method-usage.js +language/statements/class/elements/same-line-gen-static-private-methods.js +language/statements/class/elements/after-same-line-static-method-grammar-privatename-identifier-semantics-stringvalue.js +language/statements/class/elements/same-line-method-computed-symbol-names.js +language/statements/class/elements/after-same-line-static-async-gen-rs-privatename-identifier.js +language/statements/class/elements/nested-typeof-init-err-contains-arguments.js +language/statements/class/elements/after-same-line-gen-private-method-usage.js +language/statements/class/elements/new-sc-line-gen-rs-private-method-alt.js +language/statements/class/elements/multiple-definitions-rs-static-generator-method-privatename-identifier.js +language/statements/class/elements/nested-comp-name-init-err-contains-super.js +language/statements/class/elements/private-getter-shadowed-by-setter-on-nested-class.js +language/statements/class/elements/after-same-line-static-gen-private-field-usage.js +language/statements/class/elements/after-same-line-static-async-method-rs-field-identifier.js +language/statements/class/elements/new-sc-line-gen-private-method-getter-usage.js +language/statements/class/elements/after-same-line-static-async-method-computed-symbol-names.js +language/statements/class/elements/after-same-line-static-gen-rs-private-setter-alt.js +language/statements/class/elements/after-same-line-method-rs-static-generator-method-privatename-identifier.js +language/statements/class/elements/same-line-async-gen-string-literal-names.js +language/statements/class/elements/new-sc-line-gen-static-private-methods-with-fields.js +language/statements/class/elements/same-line-async-gen-static-private-methods-with-fields.js +language/statements/class/elements/syntax/valid/grammar-field-identifier-alt.js +language/statements/class/elements/syntax/valid/grammar-field-classelementname-initializer-alt.js +language/statements/class/elements/syntax/valid/grammar-field-identifier.js +language/statements/class/elements/syntax/valid/grammar-fields-multi-line.js +language/statements/class/elements/syntax/valid/grammar-field-classelementname-initializer.js +language/statements/class/elements/syntax/early-errors/delete/field-delete-twice-covered-err-delete-call-expression-private-method-gen.js +language/statements/class/elements/syntax/early-errors/delete/field-delete-twice-covered-err-delete-call-expression-private-method-accessor-set.js +language/statements/class/elements/syntax/early-errors/delete/field-delete-twice-covered-err-delete-member-expression-private-method-accessor-get.js +language/statements/class/elements/syntax/early-errors/delete/field-delete-twice-covered-err-delete-call-expression-private-method-async-gen.js +language/statements/class/elements/syntax/early-errors/delete/field-delete-covered-err-delete-member-expression-privatename.js +language/statements/class/elements/syntax/early-errors/delete/method-delete-covered-err-delete-call-expression-private-method-accessor-set.js +language/statements/class/elements/syntax/early-errors/delete/field-delete-err-delete-member-expression-private-method-accessor-set.js +language/statements/class/elements/syntax/early-errors/delete/field-delete-covered-err-delete-member-expression-private-method-accessor-get.js +language/statements/class/elements/syntax/early-errors/delete/field-delete-err-delete-call-expression-private-method-async.js +language/statements/class/elements/syntax/early-errors/delete/field-delete-err-delete-member-expression-private-method-gen.js +language/statements/class/elements/syntax/early-errors/delete/field-delete-err-delete-member-expression-private-no-reference.js +language/statements/class/elements/syntax/early-errors/delete/field-delete-covered-err-delete-call-expression-private-no-reference.js +language/statements/class/elements/syntax/early-errors/delete/field-delete-twice-covered-err-delete-call-expression-private-method-accessor-get.js +language/statements/class/elements/syntax/early-errors/delete/field-delete-twice-covered-err-delete-call-expression-private-method.js +language/statements/class/elements/syntax/early-errors/delete/field-delete-covered-err-delete-member-expression-private-method.js +language/statements/class/elements/syntax/early-errors/delete/field-delete-err-delete-call-expression-privatename.js +language/statements/class/elements/syntax/early-errors/delete/field-delete-err-delete-member-expression-private-method-async.js +language/statements/class/elements/syntax/early-errors/delete/field-delete-covered-err-delete-call-expression-private-method-accessor-get.js +language/statements/class/elements/syntax/early-errors/delete/field-delete-err-delete-call-expression-private-method-accessor-get.js +language/statements/class/elements/syntax/early-errors/delete/field-delete-err-delete-member-expression-private-method-async-gen.js +language/statements/class/elements/syntax/early-errors/delete/field-delete-covered-err-delete-member-expression-private-method-async-gen.js +language/statements/class/elements/syntax/early-errors/delete/field-delete-err-delete-call-expression-private-method-gen.js +language/statements/class/elements/syntax/early-errors/delete/field-delete-covered-err-delete-call-expression-privatename.js +language/statements/class/elements/syntax/early-errors/delete/field-delete-covered-err-delete-call-expression-private-method-gen.js +language/statements/class/elements/syntax/early-errors/delete/field-delete-twice-covered-err-delete-member-expression-private-method-async-gen.js +language/statements/class/elements/syntax/early-errors/delete/field-delete-covered-err-delete-call-expression-private-method-accessor-set.js +language/statements/class/elements/syntax/early-errors/delete/field-delete-twice-covered-err-delete-member-expression-private-method-gen.js +language/statements/class/elements/syntax/early-errors/delete/field-delete-covered-err-delete-member-expression-private-method-async.js +language/statements/class/elements/syntax/early-errors/delete/field-delete-twice-covered-err-delete-call-expression-private-no-reference.js +language/statements/class/elements/syntax/early-errors/delete/field-delete-twice-covered-err-delete-member-expression-private-method.js +language/statements/class/elements/syntax/early-errors/delete/field-delete-err-delete-call-expression-private-no-reference.js +language/statements/class/elements/syntax/early-errors/delete/field-delete-twice-covered-err-delete-member-expression-private-no-reference.js +language/statements/class/elements/syntax/early-errors/delete/field-delete-err-delete-member-expression-private-method.js +language/statements/class/elements/syntax/early-errors/delete/field-delete-covered-err-delete-call-expression-private-method-async.js +language/statements/class/elements/syntax/early-errors/delete/method-delete-twice-covered-err-delete-call-expression-private-method-accessor-get.js +language/statements/class/elements/syntax/early-errors/delete/field-delete-twice-covered-err-delete-member-expression-private-method-async.js +language/statements/class/elements/syntax/early-errors/delete/field-delete-err-delete-member-expression-private-method-accessor-get.js +language/statements/class/elements/syntax/early-errors/delete/method-delete-twice-covered-err-delete-call-expression-private-method-accessor-set.js +language/statements/class/elements/syntax/early-errors/delete/field-delete-covered-err-delete-call-expression-private-method-async-gen.js +language/statements/class/elements/syntax/early-errors/delete/field-delete-twice-covered-err-delete-call-expression-privatename.js +language/statements/class/elements/syntax/early-errors/delete/method-delete-err-delete-call-expression-private-method-accessor-get.js +language/statements/class/elements/syntax/early-errors/delete/field-delete-twice-covered-err-delete-member-expression-private-method-accessor-set.js +language/statements/class/elements/syntax/early-errors/delete/method-delete-covered-err-delete-call-expression-private-method-accessor-get.js +language/statements/class/elements/syntax/early-errors/delete/field-delete-twice-covered-err-delete-call-expression-private-method-async.js +language/statements/class/elements/syntax/early-errors/delete/field-delete-err-delete-call-expression-private-method-accessor-set.js +language/statements/class/elements/syntax/early-errors/delete/field-delete-covered-err-delete-member-expression-private-method-gen.js +language/statements/class/elements/syntax/early-errors/delete/field-delete-err-delete-call-expression-private-method-async-gen.js +language/statements/class/elements/syntax/early-errors/delete/method-delete-err-delete-call-expression-private-method-accessor-set.js +language/statements/class/elements/syntax/early-errors/delete/field-delete-covered-err-delete-call-expression-private-method.js +language/statements/class/elements/syntax/early-errors/delete/field-delete-err-delete-call-expression-private-method.js +language/statements/class/elements/syntax/early-errors/delete/field-delete-covered-err-delete-member-expression-private-method-accessor-set.js +language/statements/class/elements/syntax/early-errors/delete/field-delete-err-delete-member-expression-privatename.js +language/statements/class/elements/syntax/early-errors/delete/field-delete-covered-err-delete-member-expression-private-no-reference.js +language/statements/class/elements/syntax/early-errors/delete/field-delete-twice-covered-err-delete-member-expression-privatename.js +language/statements/class/elements/syntax/early-errors/grammar-private-environment-on-class-heritage-obj-literal.js +language/statements/class/elements/syntax/early-errors/grammar-private-environment-on-class-heritage.js +language/statements/class/elements/syntax/early-errors/grammar-private-environment-on-class-heritage-function-expression.js +language/statements/class/elements/syntax/early-errors/grammar-field-identifier-invalid-ues-error.js +language/statements/class/elements/syntax/early-errors/grammar-private-environment-on-class-heritage-array-literal.js +language/statements/class/elements/syntax/early-errors/grammar-field-identifier-invalid-zwnj-error.js +language/statements/class/elements/syntax/early-errors/grammar-private-environment-on-class-heritage-recursive.js +language/statements/class/elements/syntax/early-errors/grammar-privatename-in-computed-property-missing.js +language/statements/class/elements/syntax/early-errors/invalid-names/field-init-fn-call-expression-bad-reference.js +language/statements/class/elements/syntax/early-errors/invalid-names/field-init-member-expression-bad-reference.js +language/statements/class/elements/syntax/early-errors/invalid-names/field-init-fn-call-expression-this.js +language/statements/class/elements/syntax/early-errors/invalid-names/field-init-member-expression-this.js +language/statements/class/elements/syntax/early-errors/invalid-names/field-init-fn-member-expression-this.js +language/statements/class/elements/syntax/early-errors/invalid-names/field-init-fn-member-expression-bad-reference.js +language/statements/class/elements/syntax/early-errors/invalid-names/field-init-call-expression-bad-reference.js +language/statements/class/elements/syntax/early-errors/invalid-names/field-init-call-expression-this.js +language/statements/class/elements/syntax/early-errors/grammar-field-identifier-invalid-zwj-error.js +language/statements/class/elements/syntax/early-errors/grammar-fields-same-line-error.js +language/statements/class/elements/syntax/early-errors/grammar-private-environment-on-class-heritage-chained-usage.js +language/statements/class/elements/private-setter-on-nested-class.js +language/statements/class/elements/same-line-method-rs-static-generator-method-privatename-identifier-alt.js +language/statements/class/elements/same-line-method-rs-static-privatename-identifier-alt.js +language/statements/class/elements/same-line-async-method-private-method-usage.js +language/statements/class/elements/multiple-definitions-literal-names-asi.js +language/statements/class/elements/after-same-line-static-method-rs-static-privatename-identifier-by-classname.js +language/statements/class/elements/after-same-line-method-rs-static-async-method-privatename-identifier-alt.js +language/statements/class/elements/same-line-method-rs-static-privatename-identifier-alt-by-classname.js +language/statements/class/elements/same-line-method-rs-static-privatename-identifier-initializer-alt.js +language/statements/class/elements/same-line-method-rs-static-privatename-identifier-initializer.js +language/statements/class/elements/private-typeof-init-err-contains-super.js +language/statements/class/elements/same-line-gen-computed-names.js +language/statements/class/elements/new-sc-line-method-grammar-privatename-identifier-semantics-stringvalue.js +language/statements/class/elements/same-line-async-method-rs-private-setter-alt.js +language/statements/class/elements/multiple-stacked-definitions-rs-private-getter.js +language/statements/class/elements/after-same-line-method-rs-static-generator-method-privatename-identifier-alt.js +language/statements/class/elements/after-same-line-gen-rs-static-privatename-identifier-alt.js +language/statements/class/elements/arrow-fnc-init-err-contains-super.js +language/statements/class/elements/after-same-line-method-computed-symbol-names.js +language/statements/class/elements/new-no-sc-line-method-rs-privatename-identifier.js +language/statements/class/elements/wrapped-in-sc-rs-static-privatename-identifier-by-classname.js +language/statements/class/elements/private-getter-shadowed-by-field-on-nested-class.js +language/statements/class/elements/same-line-method-rs-private-getter.js +language/statements/class/elements/new-no-sc-line-method-rs-private-method-alt.js +language/statements/class/elements/after-same-line-static-async-method-rs-private-method.js +language/statements/class/elements/after-same-line-method-static-private-methods.js +language/statements/class/elements/same-line-async-method-static-private-methods-with-fields.js +language/statements/class/elements/multiple-stacked-definitions-rs-static-privatename-identifier-by-classname.js +language/statements/class/elements/after-same-line-method-rs-privatename-identifier-alt.js +language/statements/class/elements/same-line-gen-rs-static-privatename-identifier.js +language/statements/class/elements/same-line-method-grammar-privatename-identifier-semantics-stringvalue.js +language/statements/class/elements/static-comp-name-init-err-contains-arguments.js +language/statements/class/elements/after-same-line-gen-rs-static-async-generator-method-privatename-identifier-alt.js +language/statements/class/elements/after-same-line-static-async-method-rs-static-generator-method-privatename-identifier.js +language/statements/class/elements/super-access-from-arrow-func-on-field.js +language/statements/class/elements/after-same-line-static-async-method-rs-static-privatename-identifier.js +language/statements/class/elements/private-literal-name-init-err-contains-super.js +language/statements/class/elements/multiple-definitions-rs-static-privatename-identifier-initializer-alt-by-classname.js +language/statements/class/elements/arrow-fnc-init-err-contains-arguments.js +language/statements/class/elements/after-same-line-method-grammar-privatename-identifier-semantics-stringvalue.js +language/statements/class/elements/multiple-stacked-definitions-rs-static-generator-method-privatename-identifier-alt.js +language/statements/class/elements/after-same-line-gen-rs-field-identifier-initializer.js +language/statements/class/elements/after-same-line-static-gen-string-literal-names.js +language/statements/class/elements/after-same-line-static-gen-rs-static-async-generator-method-privatename-identifier-alt.js +language/statements/class/elements/evaluation-error/computed-name-referenceerror.js +language/statements/class/elements/evaluation-error/computed-name-valueof-err.js +language/statements/class/elements/evaluation-error/computed-name-toprimitive-err.js +language/statements/class/elements/evaluation-error/computed-name-toprimitive-returns-nonobject.js +language/statements/class/elements/evaluation-error/computed-name-tostring-err.js +language/statements/class/elements/evaluation-error/computed-name-toprimitive-returns-noncallable.js +language/statements/class/elements/same-line-gen-rs-private-method.js +language/statements/class/elements/new-no-sc-line-method-rs-static-async-generator-method-privatename-identifier.js +language/statements/class/elements/new-sc-line-method-static-private-methods-with-fields.js +language/statements/class/elements/after-same-line-static-gen-rs-private-getter-alt.js +language/statements/class/elements/after-same-line-static-gen-rs-privatename-identifier-initializer.js +language/statements/class/elements/same-line-async-method-rs-static-privatename-identifier-alt.js +language/statements/class/elements/after-same-line-static-async-gen-literal-names.js +language/statements/class/elements/after-same-line-gen-rs-static-generator-method-privatename-identifier-alt.js +language/statements/class/elements/after-same-line-static-async-method-rs-static-privatename-identifier-initializer-alt-by-classname.js +language/statements/class/elements/after-same-line-gen-rs-privatename-identifier.js +language/statements/class/elements/new-sc-line-method-rs-private-method-alt.js +language/statements/class/elements/new-no-sc-line-method-rs-static-privatename-identifier-alt.js +language/statements/class/elements/multiple-definitions-rs-field-identifier-initializer.js +language/statements/class/elements/wrapped-in-sc-rs-static-async-method-privatename-identifier.js +language/statements/class/elements/new-sc-line-gen-computed-symbol-names.js +language/statements/class/elements/after-same-line-gen-rs-static-privatename-identifier.js +language/statements/class/elements/new-sc-line-gen-private-method-usage.js +language/statements/class/elements/after-same-line-static-method-rs-static-privatename-identifier-initializer-alt-by-classname.js +language/statements/class/elements/after-same-line-gen-rs-private-getter.js +language/statements/class/elements/private-setter-is-not-clobbered-by-computed-property.js +language/statements/class/elements/same-line-async-gen-rs-private-method.js +language/statements/class/elements/new-sc-line-method-private-method-getter-usage.js +language/statements/class/elements/prod-private-getter-before-super-return-in-field-initializer.js +language/statements/class/elements/new-no-sc-line-method-rs-privatename-identifier-initializer.js +language/statements/class/elements/after-same-line-method-rs-static-privatename-identifier-alt.js +language/statements/class/elements/same-line-gen-literal-names.js +language/statements/class/elements/wrapped-in-sc-rs-privatename-identifier-initializer-alt.js +language/statements/class/elements/fields-asi-same-line-1.js +language/statements/class/elements/same-line-async-method-computed-symbol-names.js +language/statements/class/elements/multiple-stacked-definitions-rs-privatename-identifier.js +language/statements/class/elements/privatename-not-valid-earlyerr-script-3.js +language/statements/class/elements/after-same-line-static-async-method-rs-field-identifier-initializer.js +language/statements/class/elements/after-same-line-static-method-rs-private-method.js +language/statements/class/elements/same-line-method-literal-names-asi.js +language/statements/class/elements/after-same-line-static-gen-rs-field-identifier.js +language/statements/class/elements/multiple-definitions-rs-privatename-identifier-alt.js +language/statements/class/elements/after-same-line-gen-rs-privatename-identifier-initializer-alt.js +language/statements/class/elements/new-sc-line-gen-private-field-usage.js +language/statements/class/elements/new-sc-line-gen-rs-privatename-identifier.js +language/statements/class/elements/same-line-method-rs-static-async-generator-method-privatename-identifier-alt.js +language/statements/class/elements/nested-ternary-init-err-contains-super.js +language/statements/class/elements/after-same-line-static-gen-rs-static-privatename-identifier-initializer.js +language/statements/class/elements/same-line-method-rs-private-setter.js +language/statements/class/elements/wrapped-in-sc-rs-privatename-identifier.js +language/statements/class/elements/new-sc-line-gen-rs-static-async-generator-method-privatename-identifier-alt.js +language/statements/class/elements/same-line-gen-rs-privatename-identifier-alt.js +language/statements/class/elements/after-same-line-static-async-method-rs-private-setter-alt.js +language/statements/class/elements/same-line-method-rs-static-method-privatename-identifier.js +language/statements/class/elements/nested-private-arrow-fnc-init-err-contains-arguments.js +language/statements/class/elements/private-field-is-not-clobbered-by-computed-property.js +language/statements/class/elements/new-sc-line-gen-rs-static-async-method-privatename-identifier-alt.js +language/statements/class/elements/new-no-sc-line-method-rs-private-setter-alt.js +language/statements/class/elements/after-same-line-static-async-method-private-method-usage.js +language/statements/class/elements/nested-static-private-init-err-contains-super.js +language/statements/class/elements/after-same-line-static-async-method-private-field-usage.js +language/statements/class/elements/after-same-line-static-async-gen-rs-static-method-privatename-identifier-alt.js +language/statements/class/elements/multiple-definitions-string-literal-names.js +language/statements/class/elements/same-line-method-rs-static-privatename-identifier-initializer-alt-by-classname.js +language/statements/class/elements/multiple-definitions-rs-static-async-generator-method-privatename-identifier.js +language/statements/class/elements/after-same-line-static-async-method-rs-static-privatename-identifier-by-classname.js +language/statements/class/elements/new-no-sc-line-method-static-private-methods-with-fields.js +language/statements/class/elements/new-no-sc-line-method-private-field-usage.js +language/statements/class/elements/same-line-async-gen-private-names.js +language/statements/class/elements/wrapped-in-sc-rs-static-method-privatename-identifier-alt.js +language/statements/class/elements/set-access-of-missing-shadowed-private-setter.js +language/statements/class/elements/new-sc-line-method-rs-static-privatename-identifier-initializer-alt.js +language/statements/class/elements/new-sc-line-method-rs-static-async-method-privatename-identifier-alt.js +language/statements/class/elements/same-line-method-rs-static-generator-method-privatename-identifier.js +language/statements/class/elements/wrapped-in-sc-rs-private-getter-alt.js +language/statements/class/elements/new-no-sc-line-method-rs-static-privatename-identifier-initializer.js +language/statements/class/elements/same-line-gen-rs-private-getter.js +language/statements/class/elements/multiple-stacked-definitions-private-field-usage.js +language/statements/class/elements/fields-hash-constructor-is-a-valid-name.js +language/statements/class/elements/after-same-line-method-static-private-fields.js +language/statements/class/elements/nested-static-literal-init-err-contains-arguments.js +language/statements/class/elements/multiple-definitions-rs-static-async-method-privatename-identifier-alt.js +language/statements/class/elements/new-sc-line-method-rs-private-setter-alt.js +language/statements/class/elements/after-same-line-static-async-method-literal-names-asi.js +language/statements/class/elements/multiple-definitions-private-field-usage.js +language/statements/class/elements/private-setter-shadowed-by-setter-on-nested-class.js +language/statements/class/elements/same-line-method-rs-privatename-identifier-alt.js +language/statements/class/elements/regular-definitions-rs-private-method-alt.js +language/statements/class/elements/same-line-async-method-rs-field-identifier.js +language/statements/class/elements/multiple-stacked-definitions-rs-private-method.js +language/statements/class/elements/after-same-line-static-async-gen-rs-static-privatename-identifier-initializer-alt-by-classname.js +language/statements/class/elements/same-line-gen-rs-privatename-identifier.js +language/statements/class/elements/private-method-on-nested-class.js +language/statements/class/elements/same-line-async-method-rs-private-getter.js +language/statements/class/elements/after-same-line-static-gen-grammar-privatename-identifier-semantics-stringvalue.js +language/statements/class/elements/after-same-line-gen-string-literal-names.js +language/statements/class/elements/new-sc-line-gen-private-names.js +language/statements/class/elements/after-same-line-static-gen-rs-private-getter.js +language/statements/class/elements/regular-definitions-string-literal-names.js +language/statements/class/elements/fields-anonymous-function-length.js +language/statements/class/elements/public-class-field-initialization-is-visible-to-proxy.js +language/statements/class/elements/regular-definitions-rs-static-privatename-identifier-initializer-alt-by-classname.js +language/statements/class/elements/after-same-line-method-rs-static-async-generator-method-privatename-identifier.js +language/statements/class/elements/new-sc-line-method-literal-names-asi.js +language/statements/class/elements/same-line-async-gen-literal-names.js +language/statements/class/elements/wrapped-in-sc-private-method-usage.js +language/statements/class/elements/after-same-line-static-gen-rs-static-privatename-identifier-initializer-alt-by-classname.js +language/statements/class/elements/after-same-line-static-async-gen-static-private-fields.js +language/statements/class/elements/same-line-async-method-rs-privatename-identifier-alt.js +language/statements/class/elements/computed-property-abrupt-completition.js +language/statements/class/elements/after-same-line-static-gen-private-method-getter-usage.js +language/statements/class/elements/multiple-definitions-rs-private-method-alt.js +language/statements/class/elements/new-no-sc-line-method-rs-static-method-privatename-identifier-alt.js +language/statements/class/elements/new-no-sc-line-method-private-names.js +language/statements/class/elements/after-same-line-static-gen-rs-static-privatename-identifier-alt.js +language/statements/class/elements/regular-definitions-rs-privatename-identifier-initializer-alt.js +language/statements/class/elements/same-line-gen-rs-privatename-identifier-initializer-alt.js +language/statements/class/elements/nested-static-comp-name-init-err-contains-arguments.js +language/statements/class/elements/new-sc-line-gen-static-private-methods.js +language/statements/class/elements/ternary-init-err-contains-super.js +language/statements/class/elements/nested-comp-name-init-err-contains-arguments.js +language/statements/class/elements/private-field-with-initialized-id-is-visible-in-computed-properties.js +language/statements/class/elements/after-same-line-static-method-static-private-methods.js +language/statements/class/elements/same-line-async-method-rs-static-privatename-identifier-initializer-alt.js +language/statements/class/elements/same-line-async-method-rs-private-getter-alt.js +language/statements/class/elements/multiple-definitions-rs-static-async-generator-method-privatename-identifier-alt.js +language/statements/class/elements/wrapped-in-sc-rs-static-privatename-identifier-alt.js +language/statements/class/elements/after-same-line-gen-rs-static-method-privatename-identifier.js +language/statements/class/elements/after-same-line-static-async-gen-rs-private-getter.js +language/statements/class/elements/multiple-stacked-definitions-literal-names-asi.js +language/statements/class/elements/after-same-line-static-method-rs-static-privatename-identifier-alt.js +language/statements/class/elements/after-same-line-gen-rs-privatename-identifier-alt.js +language/statements/class/elements/after-same-line-static-async-method-computed-names.js +language/statements/class/elements/after-same-line-gen-rs-static-generator-method-privatename-identifier.js +language/statements/class/elements/same-line-gen-rs-private-getter-alt.js +language/statements/class/elements/after-same-line-static-async-method-rs-static-async-method-privatename-identifier-alt.js +language/statements/class/elements/same-line-async-gen-rs-static-async-generator-method-privatename-identifier.js +language/statements/class/elements/equality-init-err-contains-arguments.js +language/statements/class/elements/regular-definitions-rs-field-identifier.js +language/statements/class/elements/privatefieldget-typeerror-1.js +language/statements/class/elements/same-line-gen-rs-static-method-privatename-identifier.js +language/statements/class/elements/after-same-line-method-rs-static-privatename-identifier-alt-by-classname.js +language/statements/class/elements/wrapped-in-sc-rs-private-method.js +language/statements/class/elements/multiple-stacked-definitions-rs-privatename-identifier-initializer-alt.js +language/statements/class/elements/wrapped-in-sc-static-private-methods-with-fields.js +language/statements/class/elements/new-sc-line-method-rs-static-privatename-identifier-initializer.js +language/statements/class/elements/new-sc-line-gen-rs-privatename-identifier-alt.js +language/statements/class/elements/multiple-stacked-definitions-rs-private-method-alt.js +language/statements/class/elements/after-same-line-gen-rs-static-privatename-identifier-initializer-alt-by-classname.js +language/statements/class/elements/private-method-is-visible-in-computed-properties.js +language/statements/class/elements/regular-definitions-rs-static-privatename-identifier-initializer-alt.js +language/statements/class/elements/same-line-gen-rs-private-method-alt.js +language/statements/class/elements/regular-definitions-rs-static-privatename-identifier.js +language/statements/class/elements/after-same-line-static-gen-rs-privatename-identifier-initializer-alt.js +language/statements/class/elements/after-same-line-static-gen-static-private-fields.js +language/statements/class/elements/same-line-async-method-string-literal-names.js +language/statements/class/elements/regular-definitions-static-private-fields.js +language/statements/class/elements/same-line-gen-rs-static-privatename-identifier-initializer.js +language/statements/class/elements/new-sc-line-method-rs-static-async-generator-method-privatename-identifier.js +language/statements/class/elements/same-line-async-gen-rs-static-async-generator-method-privatename-identifier-alt.js +language/statements/class/elements/regular-definitions-computed-symbol-names.js +language/statements/class/elements/multiple-definitions-rs-private-setter.js +language/statements/class/elements/regular-definitions-rs-private-getter-alt.js +language/statements/class/elements/redeclaration.js +language/statements/class/elements/same-line-gen-static-private-fields.js +language/statements/class/elements/nested-arrow-fnc-init-err-contains-arguments.js +language/statements/class/elements/new-sc-line-gen-string-literal-names.js +language/statements/class/elements/wrapped-in-sc-rs-static-async-generator-method-privatename-identifier-alt.js +language/statements/class/elements/private-method-shadowed-by-getter-on-nested-class.js +language/statements/class/elements/new-sc-line-method-static-private-fields.js +language/statements/class/elements/after-same-line-method-computed-names.js +language/statements/class/elements/same-line-async-gen-rs-private-method-alt.js +language/statements/class/elements/regular-definitions-private-field-usage.js +language/statements/class/elements/private-accessor-is-visible-in-computed-properties.js +language/statements/class/elements/regular-definitions-rs-static-privatename-identifier-alt.js +language/statements/class/elements/multiple-definitions-private-method-usage.js +language/statements/class/elements/after-same-line-static-async-method-rs-static-async-generator-method-privatename-identifier-alt.js +language/statements/class/cpn-class-decl-fields-computed-property-name-from-integer-separators.js +language/statements/class/cpn-class-decl-fields-methods-computed-property-name-from-additive-expression-add.js +language/statements/class/cpn-class-decl-fields-computed-property-name-from-function-expression.js +language/statements/class/cpn-class-decl-fields-methods-computed-property-name-from-string-literal.js +language/statements/class/cpn-class-decl-fields-computed-property-name-from-additive-expression-add.js +language/statements/class/cpn-class-decl-fields-methods-computed-property-name-from-integer-e-notational-literal.js +language/statements/class/cpn-class-decl-fields-methods-computed-property-name-from-assignment-expression-assignment.js +language/statements/class/cpn-class-decl-fields-computed-property-name-from-expression-logical-or.js +language/statements/class/cpn-class-decl-fields-computed-property-name-from-async-arrow-function-expression.js +language/statements/class/cpn-class-decl-fields-computed-property-name-from-yield-expression.js +language/statements/class/cpn-class-decl-fields-computed-property-name-from-identifier.js +language/statements/class/cpn-class-decl-fields-computed-property-name-from-function-declaration.js +language/statements/class/cpn-class-decl-fields-methods-computed-property-name-from-assignment-expression-coalesce.js +language/statements/class/cpn-class-decl-fields-computed-property-name-from-decimal-literal.js +language/statements/class/cpn-class-decl-fields-methods-computed-property-name-from-decimal-literal.js +language/statements/class/cpn-class-decl-fields-computed-property-name-from-assignment-expression-logical-and.js +language/statements/class/cpn-class-decl-fields-methods-computed-property-name-from-expression-logical-and.js +language/statements/class/cpn-class-decl-fields-computed-property-name-from-expression-logical-and.js +language/statements/class/cpn-class-decl-fields-methods-computed-property-name-from-yield-expression.js +language/statements/class/cpn-class-decl-fields-methods-computed-property-name-from-assignment-expression-bitwise-or.js +language/statements/class/classelementname-abrupt-completion.js +language/statements/class/cpn-class-decl-fields-computed-property-name-from-additive-expression-subtract.js +language/statements/class/cpn-class-decl-fields-methods-computed-property-name-from-function-declaration.js +language/statements/class/cpn-class-decl-fields-methods-computed-property-name-from-generator-function-declaration.js +language/statements/class/cpn-class-decl-fields-methods-computed-property-name-from-additive-expression-subtract.js +language/statements/class/cpn-class-decl-fields-methods-computed-property-name-from-condition-expression-true.js +language/statements/class/cpn-class-decl-fields-methods-computed-property-name-from-decimal-e-notational-literal.js +language/statements/class/cpn-class-decl-fields-computed-property-name-from-null.js +language/statements/class/cpn-class-decl-fields-methods-computed-property-name-from-condition-expression-false.js +language/statements/class/cpn-class-decl-fields-methods-computed-property-name-from-null.js +language/statements/class/cpn-class-decl-fields-methods-computed-property-name-from-integer-separators.js +language/statements/class/cpn-class-decl-fields-computed-property-name-from-generator-function-declaration.js +language/statements/class/cpn-class-decl-fields-computed-property-name-from-assignment-expression-coalesce.js +language/statements/class/cpn-class-decl-fields-computed-property-name-from-condition-expression-true.js +language/statements/class/cpn-class-decl-fields-computed-property-name-from-math.js +language/statements/class/cpn-class-decl-fields-computed-property-name-from-multiplicative-expression-mult.js +language/statements/class/cpn-class-decl-fields-methods-computed-property-name-from-async-arrow-function-expression.js +language/statements/class/cpn-class-decl-fields-methods-computed-property-name-from-multiplicative-expression-mult.js +language/statements/class/cpn-class-decl-fields-methods-computed-property-name-from-numeric-literal.js +language/statements/class/cpn-class-decl-fields-computed-property-name-from-arrow-function-expression.js +language/statements/class/cpn-class-decl-fields-methods-computed-property-name-from-math.js +language/statements/class/cpn-class-decl-fields-methods-computed-property-name-from-arrow-function-expression.js +language/statements/class/cpn-class-decl-fields-computed-property-name-from-integer-e-notational-literal.js +language/statements/class/cpn-class-decl-fields-computed-property-name-from-string-literal.js +language/statements/class/cpn-class-decl-fields-computed-property-name-from-decimal-e-notational-literal.js +language/statements/class/cpn-class-decl-fields-computed-property-name-from-numeric-literal.js +language/statements/class/cpn-class-decl-fields-computed-property-name-from-expression-coalesce.js +language/statements/class/cpn-class-decl-fields-methods-computed-property-name-from-multiplicative-expression-div.js +language/statements/class/cpn-class-decl-fields-methods-computed-property-name-from-assignment-expression-logical-and.js +language/statements/class/cpn-class-decl-fields-methods-computed-property-name-from-identifier.js +language/statements/class/cpn-class-decl-fields-methods-computed-property-name-from-function-expression.js +language/module-code/privatename-not-valid-earlyerr-module-3.js \ No newline at end of file