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

rieske / trans / 29993228457

23 Jul 2026 08:57AM UTC coverage: 91.09% (-0.6%) from 91.733%
29993228457

push

github

web-flow
Harden process invocation, exit codes, and ownership (#57)

Replace shell system() with an argv-based Process helper that drains
stdout/stderr concurrently and fails hard on non-zero tool exits.
Propagate compile failures from Driver to main, move parsing/scanner
factories to unique_ptr, and throw from unfinished array codegen.
Add focused util/driver/codegen tests; keep production free of coverage
tooling hooks.

130 of 202 new or added lines in 9 files covered. (64.36%)

5643 of 6195 relevant lines covered (91.09%)

186846.55 hits per line

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

66.67
/src/driver/CompilerComponentsFactory.cpp
1
#include "CompilerComponentsFactory.h"
2

3
#include "ast/AbstractSyntaxTreeBuilder.h"
4
#include "ast/VerboseSyntaxTreeBuilder.h"
5
#include "parser/BNFFileReader.h"
6
#include "parser/FilePersistedParsingTable.h"
7
#include "parser/GeneratedParsingTable.h"
8
#include "parser/LR1Parser.h"
9
#include "parser/ParseTreeBuilder.h"
10
#include "scanner/LexFileScannerReader.h"
11
#include "util/Logger.h"
12
#include "util/LogManager.h"
13
#include "Configuration.h"
14

15
#include "codegen/AssemblyGenerator.h"
16
#include "codegen/IntelInstructionSet.h"
17

18
#include <chrono>
19

20
CompilerComponentsFactory::CompilerComponentsFactory(Configuration configuration) :
237✔
21
        configuration { configuration }
237✔
22
{
23
}
237✔
24

25
std::unique_ptr<scanner::Scanner> CompilerComponentsFactory::makeScannerForSourceFile(std::string sourceFileName) const {
238✔
26
    Logger logger { configuration.isScannerLoggingEnabled() ? &std::cout : &NullStream::getInstance() };
238✔
27
    LogManager::registerComponentLogger(Component::SCANNER, logger);
238✔
28

29
    scanner::LexFileScannerReader scannerReader;
30
    return std::make_unique<scanner::Scanner>(sourceFileName, scannerReader.fromConfiguration(configuration.getLexPath()));
480✔
31
}
238✔
32

33
parser::Grammar CompilerComponentsFactory::makeGrammar() const {
234✔
34
    parser::BNFFileReader reader;
35
    return reader.readGrammar(configuration.getGrammarPath());
234✔
36
}
37

38
std::unique_ptr<parser::Parser> CompilerComponentsFactory::makeParser(parser::Grammar* grammar) const {
234✔
39
    Logger logger { configuration.isParserLoggingEnabled() ? &std::cout : &NullStream::getInstance() };
234✔
40
    LogManager::registerComponentLogger(Component::PARSER, logger);
234✔
41

42
    std::unique_ptr<parser::ParsingTable> parsingTable;
234✔
43
    if (configuration.usingCustomGrammar()) {
234✔
44
        parsingTable = generateParsingTable(grammar);
×
45
    } else {
46
        parsingTable = std::make_unique<parser::FilePersistedParsingTable>(configuration.getParsingTablePath(), grammar);
234✔
47
    }
48

49
    return std::make_unique<parser::LR1Parser>(std::move(parsingTable));
468✔
50
}
234✔
51

NEW
52
std::unique_ptr<parser::ParsingTable> CompilerComponentsFactory::generateParsingTable(const parser::Grammar* grammar) const {
×
53
    std::cout << "Generating parsing table" << std::endl;
×
54
    std::chrono::steady_clock::time_point begin = std::chrono::steady_clock::now();
×
55

NEW
56
    auto generatedTable = std::make_unique<parser::GeneratedParsingTable>(grammar);
×
57

58
    std::chrono::steady_clock::time_point end = std::chrono::steady_clock::now();
×
59
    std::cout << "Parsing table generation took "
×
60
        << std::chrono::duration_cast<std::chrono::microseconds>(end - begin).count()
×
61
        << "[µs]" << std::endl;
×
62

63
    std::string parsingTableLocation {"logs/parsing_table"};
×
64
    generatedTable->persistToFile(parsingTableLocation);
×
65

66
    std::cout << "Parsing table saved to: " << parsingTableLocation << std::endl;
×
67

68
    return generatedTable;
×
69
}
×
70

71
std::unique_ptr<parser::SyntaxTreeBuilder> CompilerComponentsFactory::makeSyntaxTreeBuilder(
234✔
72
        std::string sourceFileName, const parser::Grammar* grammar) const
73
{
74
    if (configuration.usingCustomGrammar()) {
234✔
75
        return std::make_unique<parser::ParseTreeBuilder>(sourceFileName, grammar);
3✔
76
    }
77
    if (configuration.isSyntaxTreeLoggingEnabled()) {
231✔
78
        return std::make_unique<ast::VerboseSyntaxTreeBuilder>(sourceFileName, grammar);
228✔
79
    }
80
    return std::make_unique<ast::AbstractSyntaxTreeBuilder>(grammar);
3✔
81
}
82

83
std::unique_ptr<codegen::AssemblyGenerator> CompilerComponentsFactory::makeAssemblyGenerator(std::ostream* assemblyFile) const {
211✔
84
    return std::make_unique<codegen::AssemblyGenerator>(
85
            std::make_unique<codegen::StackMachine>(
422✔
86
                    assemblyFile,
87
                    std::make_unique<codegen::IntelInstructionSet>(),
422✔
88
                    std::make_unique<codegen::Amd64Registers>()));
633✔
89
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc