• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

vla5924-practice / compiler-project / 13926013161

18 Mar 2025 02:40PM UTC coverage: 82.886% (+6.2%) from 76.638%
13926013161

Pull #212

github

web-flow
Merge fde87dfba into 993c9a6a4
Pull Request #212: Implement fold control flow optimization

35 of 37 new or added lines in 1 file covered. (94.59%)

234 existing lines in 10 files now uncovered.

4722 of 5697 relevant lines covered (82.89%)

270.6 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

90.48
/compiler/include/compiler/backend/ast/optimizer/optimizer_context.hpp
1
#pragma once
2

3
#include <cstdint>
4
#include <forward_list>
5
#include <stdexcept>
6
#include <string>
7
#include <unordered_map>
8
#include <variant>
9

10
#include "compiler/ast/functions_table.hpp"
11
#include "compiler/ast/node.hpp"
12
#include "compiler/ast/variables_table.hpp"
13

14
#include "compiler/backend/ast/optimizer/optimizer_options.hpp"
15

16
namespace optimizer {
17

18
using VariableValue = std::variant<int64_t, double>;
19

20
struct OptimizerContext {
21
    std::forward_list<ast::VariablesTable *> variables;
22
    std::forward_list<std::unordered_map<std::string, VariableValue>> values;
23
    ast::FunctionsTable &functions;
24
    ast::Node::Ptr root;
25
    OptimizerOptions options;
26

27
    OptimizerContext(ast::FunctionsTable &functions, const OptimizerOptions &options)
30✔
28
        : variables(), values(), functions(functions), options(options){};
30✔
29

30
    ast::Variable &findVariable(const std::string &name) {
94✔
31
        for (auto &table : variables) {
94✔
32
            auto varIter = table->find(name);
94✔
33
            if (varIter != table->cend()) {
94✔
34
                return varIter->second;
94✔
35
            }
36
        }
37

UNCOV
38
        throw std::runtime_error("Variable not found");
×
39
    }
40

41
    ast::Variable &findVariable(const ast::Node::Ptr &varNode) {
94✔
42
        return findVariable(varNode->str());
94✔
43
    }
44

45
    VariableValue &findVariableValue(const std::string &name) {
19✔
46
        for (auto &table : values) {
19✔
47
            auto varIter = table.find(name);
19✔
48
            if (varIter != table.cend()) {
19✔
49
                return varIter->second;
19✔
50
            }
51
        }
52

UNCOV
53
        throw std::runtime_error("Variable not found");
×
54
    }
55

56
    bool hasVariable(const std::string &name) {
7✔
57
        for (auto &table : values)
8✔
58
            if (table.find(name) != table.cend())
7✔
59
                return true;
6✔
60

61
        return false;
1✔
62
    }
63
};
64

65
} // namespace optimizer
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc