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

rieske / trans / 28323069258

28 Jun 2026 01:01PM UTC coverage: 90.637% (+0.006%) from 90.631%
28323069258

Pull #38

github

rieske
Implement C-like block scopes and shadowing

Use a monotonic scope-id stack for nested and sibling blocks. Share one
scope between parameters and the function body (visit body children
without entering a new scope). Reject redeclaring parameters as locals.
Add tests for nested/sibling shadowing and parameter scope rules.
Pull Request #38: Implement C-like block scopes and shadowing

37 of 38 new or added lines in 4 files covered. (97.37%)

6 existing lines in 1 file now uncovered.

4937 of 5447 relevant lines covered (90.64%)

228243.83 hits per line

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

95.24
/src/ast/FunctionDefinition.cpp
1
#include "FunctionDefinition.h"
2

3
#include <algorithm>
4
#include <stdexcept>
5

6
#include "AbstractSyntaxTreeVisitor.h"
7
#include "Block.h"
8

9
namespace ast {
10

11
FunctionDefinition::FunctionDefinition(
366✔
12
        DeclarationSpecifiers returnType,
13
        std::unique_ptr<Declarator> declarator,
14
        std::unique_ptr<AbstractSyntaxTreeNode> body)
366✔
15
:
16
        returnType { returnType },
366✔
17
        declarator { std::move(declarator) },
366✔
18
        body { std::move(body) }
732✔
19
{
20
}
366✔
21

22
void FunctionDefinition::accept(AbstractSyntaxTreeVisitor& visitor) {
1,086✔
23
    visitor.visit(*this);
1,086✔
24
}
1,086✔
25

26
void FunctionDefinition::visitReturnType(AbstractSyntaxTreeVisitor& visitor) {
732✔
27
    returnType.accept(visitor);
732✔
28
}
732✔
29

30
void FunctionDefinition::visitDeclarator(AbstractSyntaxTreeVisitor& visitor) {
1,086✔
31
    declarator->accept(visitor);
1,086✔
32
}
1,086✔
33

34
void FunctionDefinition::visitBody(AbstractSyntaxTreeVisitor& visitor) {
720✔
35
    body->accept(visitor);
720✔
36
}
720✔
37

38
void FunctionDefinition::visitBodyChildren(AbstractSyntaxTreeVisitor& visitor) {
366✔
39
    if (auto* block = dynamic_cast<Block*>(body.get())) {
366✔
40
        block->visitChildren(visitor);
366✔
41
        return;
366✔
42
    }
NEW
43
    body->accept(visitor);
×
44
}
45

46
void FunctionDefinition::setSymbol(semantic_analyzer::FunctionEntry symbol) {
366✔
47
    this->symbol = std::make_unique<semantic_analyzer::FunctionEntry>(symbol);
366✔
48
}
366✔
49

50
semantic_analyzer::FunctionEntry* FunctionDefinition::getSymbol() const {
708✔
51
    if (!symbol) {
708✔
52
        throw std::runtime_error { "FunctionDefinition::getSymbol() == nullptr" };
×
53
    }
54
    return symbol.get();
708✔
55
}
56

57
std::string FunctionDefinition::getName() const {
732✔
58
    return declarator->getName();
732✔
59
}
60

61

62
void FunctionDefinition::setLocalVariables(std::map<std::string, semantic_analyzer::ValueEntry> localVariables) {
366✔
63
    this->localVariables = localVariables;
366✔
64
}
366✔
65

66
void FunctionDefinition::setArguments(std::vector<semantic_analyzer::ValueEntry> arguments) {
366✔
67
    this->arguments = arguments;
366✔
68
}
366✔
69

70
std::map<std::string, semantic_analyzer::ValueEntry> FunctionDefinition::getLocalVariables() const {
354✔
71
    return localVariables;
354✔
72
}
73

74
std::vector<semantic_analyzer::ValueEntry> FunctionDefinition::getArguments() const {
354✔
75
    return arguments;
354✔
76
}
77

78
} // namespace ast
79

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