GCC Code Coverage Report


Directory: src/
File: src/analysis/analysis-type-resolution.cpp
Date: 2025-10-24 11:14:59
Exec Total Coverage
Lines: 16 22 72.7%
Functions: 4 4 100.0%
Branches: 7 8 87.5%

Line Branch Exec Source
1 /* Copyright 2025 Jonathan S. Arney
2 *
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 * https://github.com/jarney/gyoji/blob/master/LICENSE
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 #include <gyoji-analysis.hpp>
16 #include <stdio.h>
17
18 using namespace Gyoji::mir;
19 using namespace Gyoji::context;
20 using namespace Gyoji::analysis;
21
22 28 AnalysisPassTypeResolution::AnalysisPassTypeResolution(CompilerContext & _compiler_context)
23 56 : AnalysisPass(_compiler_context, "type resolution")
24 28 {}
25 112 AnalysisPassTypeResolution::~AnalysisPassTypeResolution()
26 112 {}
27
28 void
29 28 AnalysisPassTypeResolution::check(const MIR & mir) const
30 {
31 // TODO: Go back through all of the types and make sure that every type
32 // that is used in a structure 'inline' is actually complete.
33 // If not, produce a compile error to that effect.
34 // This needs to be recursive!
35
2/2
✓ Branch 7 taken 524 times.
✓ Branch 8 taken 28 times.
552 for (const auto & type_it : mir.get_types().get_types()) {
36 524 const Type & type = *type_it.second;
37 524 check_type(type);
38 }
39 28 }
40
41 void
42 536 AnalysisPassTypeResolution::check_type(const Type & type) const
43 {
44
2/2
✓ Branch 1 taken 6 times.
✓ Branch 2 taken 530 times.
536 if (type.get_type() == Type::TYPE_COMPOSITE) {
45
2/2
✓ Branch 6 taken 12 times.
✓ Branch 7 taken 6 times.
18 for (const auto & member : type.get_members()) {
46
1/2
✗ Branch 2 not taken.
✓ Branch 3 taken 12 times.
12 if (!member.get_type()->is_complete()) {
47 std::unique_ptr<Gyoji::context::Error> error = std::make_unique<Gyoji::context::Error>("Class contains incomplete type");
48 error->add_message(member.get_source_ref(),
49 std::string("Incomplete type in member ") + member.get_name() + std::string(" of type ") + type.get_name());
50 error->add_message(member.get_type()->get_declared_source_ref(),
51 "Forward declaration is here.");
52 get_compiler_context().get_errors().add_error(std::move(error));
53 }
54 12 check_type(*member.get_type());
55 }
56 }
57 536 }
58
59
60