Coverage Report

Created: 2026-05-27 07:00

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
4
: Vocabulary(std::move(literalNames), std::move(symbolicNames), {}) {
16
4
}
17
18
Vocabulary::Vocabulary(std::vector<std::string> literalNames,
19
  std::vector<std::string> symbolicNames, std::vector<std::string> displayNames)
20
4
  : _literalNames(std::move(literalNames)), _symbolicNames(std::move(symbolicNames)), _displayNames(std::move(displayNames)),
21
4
    _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
4
}
24
25
375k
std::string_view Vocabulary::getLiteralName(size_t tokenType) const {
26
375k
  if (tokenType < _literalNames.size()) {
27
236k
    return _literalNames[tokenType];
28
236k
  }
29
30
139k
  return "";
31
375k
}
32
33
139k
std::string_view Vocabulary::getSymbolicName(size_t tokenType) const {
34
139k
  if (tokenType == Token::EOF) {
35
0
    return "EOF";
36
0
  }
37
38
139k
  if (tokenType < _symbolicNames.size()) {
39
139k
    return _symbolicNames[tokenType];
40
139k
  }
41
42
0
  return "";
43
139k
}
44
45
375k
std::string Vocabulary::getDisplayName(size_t tokenType) const {
46
375k
  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
375k
  std::string_view literalName = getLiteralName(tokenType);
54
375k
  if (!literalName.empty()) {
55
236k
    return std::string(literalName);
56
236k
  }
57
58
139k
  std::string_view symbolicName = getSymbolicName(tokenType);
59
139k
  if (!symbolicName.empty()) {
60
139k
    return std::string(symbolicName);
61
139k
  }
62
63
0
  return std::to_string(tokenType);
64
139k
}