1/*
2 * Copyright (c) 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#ifndef ES2PANDA_EVALUATE_EVALUATE_CONTEXT_H
17#define ES2PANDA_EVALUATE_EVALUATE_CONTEXT_H
18
19#include "es2panda.h"
20#include "util/ustring.h"
21
22#include "libpandabase/utils/arena_containers.h"
23#include "libpandafile/debug_info_extractor.h"
24#include "libpandafile/file.h"
25
26#include <memory>
27#include <string_view>
28
29namespace ark::es2panda::parser {
30class Program;
31}  // namespace ark::es2panda::parser
32
33namespace ark::es2panda::ir {
34class BlockStatement;
35class ClassDefinition;
36class ExpressionStatement;
37class MethodDefinition;
38class ScriptFunction;
39}  // namespace ark::es2panda::ir
40
41namespace ark::es2panda::evaluate {
42
43struct EvaluateContext {
44    explicit EvaluateContext(const CompilerOptions &options)
45        : sourceFilePath(options.debuggerEvalSource), lineNumber(options.debuggerEvalLine)
46    {
47    }
48
49    /**
50     * @brief Searches Program for evaluation method according to convention.
51     * Initializes `methodStatements`, which are always non-null after this function,
52     * as well as `lastStatement`, which is non-null only if the last statement have expression.
53     * Must be called once after parser and before checker phase.
54     * @param evalMethodProgram compiler Program corresponding to expression file.
55     */
56    void FindEvaluationMethod(parser::Program *evalMethodProgram);
57
58    // NOLINTBEGIN(misc-non-private-member-variables-in-classes)
59    util::StringView sourceFilePath;
60    uint64_t lineNumber {0};
61    const panda_file::File *file {nullptr};
62    std::unique_ptr<panda_file::DebugInfoExtractor> extractor {nullptr};
63    panda_file::File::EntityId methodId;
64    uint32_t bytecodeOffset {0};
65
66    // es2panda specific information about the compiled expression's static method.
67    ir::BlockStatement *methodStatements {nullptr};
68    ir::ExpressionStatement *lastStatement {nullptr};
69    // NOLINTEND(misc-non-private-member-variables-in-classes)
70};
71
72}  // namespace ark::es2panda::evaluate
73
74#endif  // ES2PANDA_EVALUATE_EVALUATE_CONTEXT_H
75