Coverage Report

Created: 2025-12-29 06:46

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
234k
std::string_view Vocabulary::getLiteralName(size_t tokenType) const {
26
234k
  if (tokenType < _literalNames.size()) {
27
148k
    return _literalNames[tokenType];
28
148k
  }
29
30
86.3k
  return "";
31
234k
}
32
33
86.3k
std::string_view Vocabulary::getSymbolicName(size_t tokenType) const {
34
86.3k
  if (tokenType == Token::EOF) {
35
0
    return "EOF";
36
0
  }
37
38
86.3k
  if (tokenType < _symbolicNames.size()) {
39
86.3k
    return _symbolicNames[tokenType];
40
86.3k
  }
41
42
0
  return "";
43
86.3k
}
44
45
234k
std::string Vocabulary::getDisplayName(size_t tokenType) const {
46
234k
  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
234k
  std::string_view literalName = getLiteralName(tokenType);
54
234k
  if (!literalName.empty()) {
55
148k
    return std::string(literalName);
56
148k
  }
57
58
86.3k
  std::string_view symbolicName = getSymbolicName(tokenType);
59
86.3k
  if (!symbolicName.empty()) {
60
86.3k
    return std::string(symbolicName);
61
86.3k
  }
62
63
0
  return std::to_string(tokenType);
64
86.3k
}