idlize
50 строк · 1.6 Кб
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
16import * as ts from 'typescript'
17import { Rewrite } from './transformation-context';
18import { AbstractVisitor } from './AbstractVisitor'
19import { FunctionKind, isAnyMemoKind } from './util';
20
21export class MemoArgumentDetector extends AbstractVisitor {
22constructor(
23public typechecker: ts.TypeChecker,
24public rewrite: Rewrite,
25public memoArgument: ts.Node,
26ctx: ts.TransformationContext,
27) {
28super(ctx)
29}
30hasMemoArgument : boolean = false
31
32
33visitor(node: ts.Node): ts.Node {
34
35if(ts.isCallExpression(node)){
36const callKind = this.rewrite.callTable.get(node) ?? FunctionKind.REGULAR
37if(isAnyMemoKind(callKind)) {
38this.hasMemoArgument = true
39this.memoArgument = node
40}
41}
42return this.visitEachChild(node)
43}
44
45usingMemoFunction(node: ts.Expression): boolean {
46this.hasMemoArgument = false
47this.visitor(node)
48return this.hasMemoArgument
49}
50}