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

vla5924-practice / compiler-project / 13884489619

16 Mar 2025 02:44PM UTC coverage: 77.883% (+1.2%) from 76.638%
13884489619

Pull #212

github

web-flow
Merge 37571da47 into 9f356f9ca
Pull Request #212: Implement fold control flow optimization

25 of 37 new or added lines in 1 file covered. (67.57%)

323 existing lines in 11 files now uncovered.

4437 of 5697 relevant lines covered (77.88%)

250.1 hits per line

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

96.67
/compiler/include/compiler/frontend/converter/converter_context.hpp
1
#pragma once
2

3
#include <cstddef>
4
#include <forward_list>
5
#include <string>
6
#include <tuple>
7
#include <unordered_map>
8
#include <utility>
9
#include <variant>
10

11
#include "compiler/ast/node.hpp"
12
#include "compiler/optree/builder.hpp"
13
#include "compiler/optree/operation.hpp"
14
#include "compiler/optree/types.hpp"
15
#include "compiler/optree/value.hpp"
16
#include "compiler/utils/error_buffer.hpp"
17

18
#include "compiler/frontend/converter/converter_error.hpp"
19

20
namespace converter {
21

22
struct ConverterContext {
23
    struct LocalVariable {
24
        using NumElementsStorage = std::variant<std::monostate, optree::Value::Ptr, size_t>;
25

26
        optree::Value::Ptr value = {};
27
        bool needsLoad = true;
28
        bool aggregate = false;
29
        NumElementsStorage numElements = {};
30
    };
31

32
    optree::Operation::Ptr op;
33
    std::unordered_map<std::string, optree::Type::Ptr> functions;
34
    std::forward_list<std::unordered_map<std::string, LocalVariable>> variables;
35
    optree::Builder builder;
36
    ErrorBuffer errors;
37

38
    template <typename AdaptorType, typename... Args>
39
    AdaptorType insert(Args... args) {
361✔
40
        return builder.insert<AdaptorType>(std::forward<Args>(args)...);
361✔
41
    }
42

43
    void goInto(const optree::Operation::Ptr &rootOp) {
141✔
44
        op = rootOp;
141✔
45
        builder.setInsertPointAtBodyEnd(op);
141✔
46
    }
141✔
47

48
    void goParent() {
59✔
49
        if (op->parent == nullptr)
59✔
UNCOV
50
            return;
×
51
        goInto(op->parent);
59✔
52
    }
53

54
    void enterScope() {
94✔
55
        variables.emplace_front();
94✔
56
    }
94✔
57

58
    void exitScope() {
84✔
59
        variables.pop_front();
84✔
60
    }
84✔
61

62
    void saveVariable(const std::string &name, optree::Value::Ptr value, bool needsLoad = true, bool aggregate = false,
61✔
63
                      const LocalVariable::NumElementsStorage &numElements = {}) {
64
        variables.front().emplace(std::piecewise_construct, std::forward_as_tuple(name),
122✔
65
                                  std::forward_as_tuple(value, needsLoad, aggregate, numElements));
61✔
66
    }
61✔
67

68
    const LocalVariable *findVariable(const std::string &name) {
86✔
69
        for (auto &scope : variables)
181✔
70
            if (scope.contains(name))
180✔
71
                return &scope[name];
85✔
72
        return nullptr;
1✔
73
    }
74

75
    bool wouldBeRedeclaration(const std::string &name) {
27✔
76
        return variables.front().contains(name);
27✔
77
    }
78

79
    void pushError(const ast::Node::Ptr &node, const std::string &message) {
7✔
80
        errors.push<ConverterError>(node, message);
7✔
81
    }
7✔
82
};
83

84
} // namespace converter
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

© 2025 Coveralls, Inc