idlize

Форк
0
51 строка · 1.8 Кб
1
/*
2
 * Copyright (c) 2022-2023 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
import * as ts from "typescript"
17
import { AbstractVisitor } from "./AbstractVisitor";
18
import { FunctionKind, FunctionTable, isAnyMemoKind, isFunctionOrMethod, Tracer } from "./util";
19

20
export class DumpVisitor extends AbstractVisitor {
21
    constructor(
22
        public tracer: Tracer,
23
        public sourceFile: ts.SourceFile,
24
        public functionTable: FunctionTable,
25
        ctx: ts.TransformationContext
26
    ) {
27
        super(ctx)
28
    }
29

30
    declarationKind(node: ts.FunctionLikeDeclarationBase): FunctionKind {
31
        const originalNode = ts.getOriginalNode(node) as ts.FunctionLikeDeclarationBase
32
        return this.functionTable.get(originalNode) ?? FunctionKind.REGULAR
33
    }
34

35
    isAnyMemo(node: ts.FunctionLikeDeclarationBase): boolean {
36
        return isAnyMemoKind(this.declarationKind(node))
37
    }
38

39
    visitor(beforeChildren: ts.Node): ts.Node {
40
        const node = this.visitEachChild(beforeChildren)
41
        let transformed: ts.Node|undefined = undefined
42

43
        if (isFunctionOrMethod(node)) {
44
            if (isAnyMemoKind(this.declarationKind(node))) {
45
                this.tracer.keepTransformedFunction(node, this.sourceFile)
46
            }
47
            return node
48
        }
49
        return transformed ?? node
50
    }
51
}

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.