GCC Code Coverage Report


Directory: src/
File: src/mir/symbols.cpp
Date: 2025-10-24 11:14:59
Exec Total Coverage
Lines: 46 47 97.9%
Functions: 10 10 100.0%
Branches: 8 10 80.0%

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-mir/symbols.hpp>
16
17 using namespace Gyoji::mir;
18
19 318 Symbol::Symbol(
20 std::string _name,
21 SymbolType _type,
22 318 const Type *_mir_type)
23 318 : name(_name)
24 318 , type(_type)
25 318 , mir_type(_mir_type)
26 318 {}
27
28 318 Symbol::~Symbol()
29 318 {}
30
31 std::string
32 318 Symbol::get_name() const
33 318 { return name; }
34
35 const Type *
36 762 Symbol::get_mir_type() const
37 762 { return mir_type; }
38
39 Symbol::SymbolType
40 672 Symbol::get_type() const
41 672 { return type; }
42
43
44 30 Symbols::Symbols()
45 30 {}
46
47 30 Symbols::~Symbols()
48 30 {}
49
50 void
51 326 Symbols::define_symbol(
52 std::string name,
53 Symbol::SymbolType type,
54 const Type *mir_type)
55 {
56 326 const auto & it = symbols.find(name);
57
2/2
✓ Branch 2 taken 8 times.
✓ Branch 3 taken 318 times.
326 if (it != symbols.end()) {
58 8 return;
59 }
60 318 symbols.insert(std::pair(name, std::make_unique<Symbol>(name, type, mir_type)));
61 }
62
63 void
64 28 Symbols::dump(FILE *out) const
65 {
66
2/2
✓ Branch 5 taken 318 times.
✓ Branch 6 taken 28 times.
346 for (const auto & symbol : symbols) {
67 318 const Gyoji::owned<Symbol> & sym = symbol.second;
68 318 std::string type;
69
3/4
✓ Branch 2 taken 312 times.
✓ Branch 3 taken 4 times.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
318 switch (sym->get_type()) {
70 312 case Symbol::SYMBOL_STATIC_FUNCTION:
71 312 type = std::string("static function");
72 312 break;
73 4 case Symbol::SYMBOL_MEMBER_DESTRUCTOR:
74 4 type = std::string("member destructor");
75 4 break;
76 2 case Symbol::SYMBOL_MEMBER_METHOD:
77 2 type = std::string("member method");
78 2 break;
79 }
80 636 fprintf(out, " %s : %s %s\n",
81 636 sym->get_name().c_str(),
82 type.c_str(),
83 318 sym->get_mir_type()->get_name().c_str());
84 318 }
85 28 }
86
87
88 const Symbol *
89 450 Symbols::get_symbol(std::string name) const
90 {
91 450 const auto & it = symbols.find(name);
92
1/2
✗ Branch 2 not taken.
✓ Branch 3 taken 450 times.
450 if (it == symbols.end()) {
93 return nullptr;
94 }
95 450 return it->second.get();
96 }
97