aboutsummaryrefslogtreecommitdiffstats
path: root/yql/essentials/core/yql_func_stack.cpp
blob: 6398961c601b15af4baa35fd5dd3c6e400f0ba34 (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
#include "yql_func_stack.h"
#include "yql_expr_type_annotation.h"

#include <util/generic/scope.h>

namespace NYql {

void TFunctionStack::EnterFrame(const TExprNode& input, TExprContext& ctx) {
    if (input.Type() == TExprNode::Callable) {
        CurrentFunctions_.push(std::make_pair(input.Content(), false));
    }

    ctx.IssueManager.AddScope([this, &input, &ctx]() -> TIssuePtr {
        if (!CurrentFunctions_.empty() && CurrentFunctions_.top().second) {
            return nullptr;
        }

        if (input.Type() == TExprNode::Callable && input.Content().EndsWith('!')) {
            return nullptr;
        }

        TStringBuilder str;
        str << "At ";
        switch (input.Type()) {
        case TExprNode::Callable:
            str << "function: " << NormalizeCallableName(input.Content());
            break;
        case TExprNode::List:
            str << "tuple";
            break;
        case TExprNode::Lambda:
            str << "lambda";
            break;
        default:
            str << "unknown";
        }

        return MakeIntrusive<TIssue>(ctx.GetPosition(input.Pos()), str);
    });
}

void TFunctionStack::LeaveFrame(const TExprNode& input, TExprContext& ctx) {
    if (input.Type() == TExprNode::Callable) {
        CurrentFunctions_.pop();
    }

    ctx.IssueManager.LeaveScope();
}

void TFunctionStack::Reset() {
    CurrentFunctions_ = {};
}

void TFunctionStack::MarkUsed() {
    if (!CurrentFunctions_.empty()) {
        CurrentFunctions_.top().second = true;
    }
}

}