1/**
2 * Copyright (c) 2021-2024 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16#include "public/es2panda_lib.h"
17#include "public/public.h"
18#include "declgenEts2Ts.h"
19
20namespace ark::es2panda::declgen_ets2ts {
21
22static int Run(int argc, const char **argv)
23{
24    const auto *impl = es2panda_GetImpl(ES2PANDA_LIB_VERSION);
25    auto *cfg = impl->CreateConfig(argc, argv);
26    if (cfg == nullptr) {
27        return 1;
28    }
29    auto *cfgImpl = reinterpret_cast<ark::es2panda::public_lib::ConfigImpl *>(cfg);
30
31    es2panda_Context *ctx = impl->CreateContextFromString(cfg, cfgImpl->options->ParserInput().c_str(),
32                                                          cfgImpl->options->SourceFile().c_str());
33
34    auto *ctxImpl = reinterpret_cast<ark::es2panda::public_lib::Context *>(ctx);
35    auto *checker = reinterpret_cast<checker::ETSChecker *>(ctxImpl->checker);
36
37    impl->ProceedToState(ctx, ES2PANDA_STATE_CHECKED);
38
39    int res = 0;
40    if (!GenerateTsDeclarations(checker, ctxImpl->parserProgram, cfgImpl->options->CompilerOutput())) {
41        res = 1;
42    }
43
44    impl->DestroyContext(ctx);
45    impl->DestroyConfig(cfg);
46
47    return res;
48}
49}  // namespace ark::es2panda::declgen_ets2ts
50
51int main(int argc, const char **argv)
52{
53    return ark::es2panda::declgen_ets2ts::Run(argc, argv);
54}
55