GCC Code Coverage Report


Directory: src/
File: src/cmdline/jtokenize.cpp
Date: 2025-10-24 11:14:59
Exec Total Coverage
Lines: 24 29 82.8%
Functions: 1 1 100.0%
Branches: 6 8 75.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-misc/input-source-file.hpp>
16 #include <gyoji-frontend.hpp>
17 #include <gyoji-context.hpp>
18 #include <gyoji.l.hpp>
19 #include <gyoji.y.hpp>
20
21 using namespace Gyoji::context;
22 using namespace Gyoji::frontend::tree;
23 using namespace Gyoji::frontend::yacc;
24
25 48 int main(int argc, char **argv)
26 {
27
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 48 times.
48 if (argc != 2) {
28 fprintf(stderr, "Invalid number of arguments %d\n", argc);
29 fprintf(stderr, "Usage: jformat-identity file\n");
30 exit(1);
31 }
32
33 48 int input = open(argv[1], O_RDONLY);
34
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 48 times.
48 if (input == -1) {
35 fprintf(stderr, "Cannot open file %s\n", argv[1]);
36 exit(1);
37 }
38
39 48 CompilerContext context(argv[1]);
40 48 Gyoji::frontend::namespaces::NS2Context ns2_context;
41
42 48 Gyoji::misc::InputSourceFile input_source(input);
43
44 LexContext lex_context(
45 ns2_context,
46 context,
47 48 input_source);
48
49 yyscan_t scanner;
50 48 yylex_init(&scanner);
51 48 yyset_extra(&lex_context, scanner);
52
53 while (true) {
54 4616 Gyoji::frontend::yacc::YaccParser::semantic_type lvalue;
55 4616 int rc = yylex (&lvalue, scanner);
56
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 4568 times.
4616 if (rc == 0) {
57 48 break;
58 }
59 4568 const Gyoji::owned<Gyoji::frontend::tree::Terminal> & token = lvalue.as<Gyoji::owned<Gyoji::frontend::tree::Terminal>>();
60 18272 printf("%ld %ld : %d %s : %s\n",
61 4568 token->get_source_ref().get_line(),
62 4568 token->get_source_ref().get_column(),
63 4568 token->get_type(),
64 9136 token->get_name().c_str(),
65 9136 token->get_fully_qualified_name().c_str()
66 );
67
2/2
✓ Branch 1 taken 4568 times.
✓ Branch 2 taken 48 times.
9184 }
68
69 48 return 0;
70 48 }
71