summaryrefslogtreecommitdiffstats
path: root/yql/essentials/core/yql_module_helpers.cpp
blob: c423315d31fa67db7b9c29f5eb6ce02abbd74154 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#include "yql_module_helpers.h"

#include <library/cpp/iterator/enumerate.h>

namespace NYql {

namespace {

const TExprNode::TPtr* ImportFreezed(
    const TPosition& position,
    const TString& path,
    const TString& name,
    TExprContext& ctx,
    TTypeAnnotationContext& types,
    TExprContext** src)
{
    const TExportTable* exports = types.Modules->GetModule(path);
    if (!exports) {
        ctx.AddError(TIssue(
            position,
            TStringBuilder()
                << "Module '" << path << "' not found"));
        return nullptr;
    }

    const TExprNode::TPtr* symbol = exports->Symbols().FindPtr(name);
    if (!symbol) {
        ctx.AddError(TIssue(
            position,
            TStringBuilder()
                << "Symbol '" << name << "' not found "
                << "in module '" << path << "'"));
        return nullptr;
    }

    if (src) {
        *src = &exports->ExprCtx();
    }

    return symbol;
}

} // namespace

const TExprNode::TPtr* ImportFreezed(
    const TPosition& position,
    const TString& path,
    const TString& name,
    TExprContext& ctx,
    TTypeAnnotationContext& types)
{
    return ImportFreezed(
        position, path, name, ctx, types, /*src=*/nullptr);
}

TExprNode::TPtr ImportDeeplyCopied(
    const TPosition& position,
    const TString& path,
    const TString& name,
    TExprContext& ctx,
    TTypeAnnotationContext& types)
{
    TExprContext* src = nullptr;
    const TExprNode::TPtr* symbol = ImportFreezed(
        position, path, name, ctx, types, &src);
    if (!symbol) {
        return nullptr;
    }

    TNodeOnNodeOwnedMap clones;
    return ctx.DeepCopy(
        /*node=*/*(*symbol),
        /*nodeContext=*/*src,
        /*deepClones=*/clones,
        /*internStrings=*/true,
        /*copyTypes=*/false);
}

} // namespace NYql