Coverage Report

Created: 2025-11-29 07:01

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/proc/self/cwd/external/antlr4-cpp-runtime~/runtime/src/Vocabulary.cpp
Line
Count
Source
1
/* Copyright (c) 2012-2017 The ANTLR Project. All rights reserved.
2
 * Use of this file is governed by the BSD 3-clause license that
3
 * can be found in the LICENSE.txt file in the project root.
4
 */
5
6
#include "Token.h"
7
8
#include "Vocabulary.h"
9
10
using namespace antlr4::dfa;
11
12
const Vocabulary Vocabulary::EMPTY_VOCABULARY;
13
14
Vocabulary::Vocabulary(std::vector<std::string> literalNames, std::vector<std::string> symbolicNames)
15
2
: Vocabulary(std::move(literalNames), std::move(symbolicNames), {}) {
16
2
}
17
18
Vocabulary::Vocabulary(std::vector<std::string> literalNames,
19
  std::vector<std::string> symbolicNames, std::vector<std::string> displayNames)
20
2
  : _literalNames(std::move(literalNames)), _symbolicNames(std::move(symbolicNames)), _displayNames(std::move(displayNames)),
21
2
    _maxTokenType(std::max(_displayNames.size(), std::max(_literalNames.size(), _symbolicNames.size())) - 1) {
22
  // See note here on -1 part: https://github.com/antlr/antlr4/pull/1146
23
2
}
24
25
116k
std::string_view Vocabulary::getLiteralName(size_t tokenType) const {
26
116k
  if (tokenType < _literalNames.size()) {
27
73.3k
    return _literalNames[tokenType];
28
73.3k
  }
29
30
43.3k
  return "";
31
116k
}
32
33
43.3k
std::string_view Vocabulary::getSymbolicName(size_t tokenType) const {
34
43.3k
  if (tokenType == Token::EOF) {
35
0
    return "EOF";
36
0
  }
37
38
43.3k
  if (tokenType < _symbolicNames.size()) {
39
43.3k
    return _symbolicNames[tokenType];
40
43.3k
  }
41
42
0
  return "";
43
43.3k
}
44
45
116k
std::string Vocabulary::getDisplayName(size_t tokenType) const {
46
116k
  if (tokenType < _displayNames.size()) {
47
0
    std::string_view displayName = _displayNames[tokenType];
48
0
    if (!displayName.empty()) {
49
0
      return std::string(displayName);
50
0
    }
51
0
  }
52
53
116k
  std::string_view literalName = getLiteralName(tokenType);
54
116k
  if (!literalName.empty()) {
55
73.3k
    return std::string(literalName);
56
73.3k
  }
57
58
43.3k
  std::string_view symbolicName = getSymbolicName(tokenType);
59
43.3k
  if (!symbolicName.empty()) {
60
43.3k
    return std::string(symbolicName);
61
43.3k
  }
62
63
0
  return std::to_string(tokenType);
64
43.3k
}