GCC Code Coverage Report


Directory: src/
File: src/cmdline/jformat-identity.cpp
Date: 2025-10-24 11:14:59
Exec Total Coverage
Lines: 43 43 100.0%
Functions: 9 9 100.0%
Branches: 10 11 90.9%

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 "jformat-identity.hpp"
16 #include <iostream>
17
18 using namespace Gyoji::frontend::ast;
19 using namespace Gyoji::frontend::tree;
20 using namespace Gyoji::cmdline;
21
22 48 JFormatIdentity::JFormatIdentity()
23 48 {}
24 48 JFormatIdentity::~JFormatIdentity()
25 48 {}
26
27 3826 static void print_whitespace(const TerminalNonSyntax & node)
28 {
29 3826 printf("%s", node.get_data().c_str());
30 3826 }
31 96 static void print_comment_single_line(const TerminalNonSyntax & node)
32 {
33 96 printf("%s", node.get_data().c_str());
34 96 }
35 12 static void print_comment_multi_line(const TerminalNonSyntax & node)
36 {
37 12 printf("%s", node.get_data().c_str());
38 12 }
39 4 static void print_file_metadata(const TerminalNonSyntax & node)
40 {
41 4 printf("%s", node.get_data().c_str());
42 4 }
43
44
45 3938 static void print_non_syntax(const TerminalNonSyntax & node)
46 {
47
4/5
✓ Branch 1 taken 12 times.
✓ Branch 2 taken 96 times.
✓ Branch 3 taken 3826 times.
✓ Branch 4 taken 4 times.
✗ Branch 5 not taken.
3938 switch (node.get_type()) {
48 12 case TerminalNonSyntax::Type::EXTRA_COMMENT_MULTI_LINE:
49 12 print_comment_multi_line(node);
50 12 break;
51 96 case TerminalNonSyntax::Type::EXTRA_COMMENT_SINGLE_LINE:
52 96 print_comment_single_line(node);
53 96 break;
54 3826 case TerminalNonSyntax::Type::EXTRA_WHITESPACE:
55 3826 print_whitespace(node);
56 3826 break;
57 4 case TerminalNonSyntax::Type::EXTRA_FILE_METADATA:
58 4 print_file_metadata(node);
59 4 break;
60 }
61 3938 }
62
63 12474 static void print_node(const SyntaxNode &node)
64 {
65
2/2
✓ Branch 1 taken 4620 times.
✓ Branch 2 taken 7854 times.
12474 if (node.has_data<Terminal>()) {
66 4620 const Terminal & terminal = node.get_data<Terminal>();
67
2/2
✓ Branch 5 taken 3938 times.
✓ Branch 6 taken 4620 times.
8558 for (const auto &non_syntax : terminal.non_syntax) {
68 3938 print_non_syntax(*non_syntax);
69 }
70 4620 printf("%s", terminal.get_value().c_str());
71 }
72
2/2
✓ Branch 6 taken 12426 times.
✓ Branch 7 taken 12474 times.
24900 for (auto child : node.get_children()) {
73 12426 print_node(child);
74 }
75 12474 }
76
77 48 int JFormatIdentity::process(const SyntaxNode &file)
78 {
79 48 print_node(file);
80 48 return 0;
81 }
82