Coverage Report

Created: 2026-02-26 06:24

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/flatbuffers/include/codegen/python.cc
Line
Count
Source
1
#include "codegen/python.h"
2
3
#include <set>
4
#include <sstream>
5
#include <string>
6
#include <utility>
7
8
namespace flatbuffers {
9
namespace python {
10
0
Version::Version(const std::string& version) {
11
0
  std::stringstream ss(version);
12
0
  char dot;
13
0
  ss >> major >> dot >> minor >> dot >> micro;
14
0
}
15
16
0
bool Version::IsValid() const {
17
0
  return (major == 0 || major == 2 || major == 3) && minor >= 0 && micro >= 0;
18
0
}
19
20
0
std::set<std::string> Keywords(const Version& version) {
21
0
  switch (version.major) {
22
0
    case 2:
23
      // https://docs.python.org/2/reference/lexical_analysis.html#keywords
24
0
      return {
25
0
          "and",   "as",     "assert", "break",  "class", "continue", "def",
26
0
          "del",   "elif",   "else",   "except", "exec",  "finally",  "for",
27
0
          "from",  "global", "if",     "import", "in",    "is",       "lambda",
28
0
          "not",   "or",     "pass",   "print",  "raise", "return",   "try",
29
0
          "while", "with",   "yield",
30
0
      };
31
0
    case 0:
32
0
    case 3:
33
      // https://docs.python.org/3/reference/lexical_analysis.html#keywords
34
0
      return {
35
0
          "and",      "as",       "assert",  "async", "await",  "break",
36
0
          "class",    "continue", "def",     "del",   "elif",   "else",
37
0
          "except",   "False",    "finally", "for",   "from",   "global",
38
0
          "if",       "import",   "in",      "is",    "lambda", "None",
39
0
          "nonlocal", "not",      "or",      "pass",  "raise",  "return",
40
0
          "True",     "try",      "while",   "with",  "yield",
41
0
      };
42
0
    default:
43
0
      return {};
44
0
  }
45
0
}
46
47
0
const python::Import& python::Imports::Import(const std::string& module) {
48
0
  python::Import import;
49
0
  import.module = module;
50
0
  imports.push_back(std::move(import));
51
0
  return imports.back();
52
0
}
53
54
const python::Import& python::Imports::Import(const std::string& module,
55
0
                                              const std::string& name) {
56
0
  python::Import import;
57
0
  import.module = module;
58
0
  import.name = name;
59
0
  imports.push_back(std::move(import));
60
0
  return imports.back();
61
0
}
62
63
0
const python::Import& python::Imports::Export(const std::string& module) {
64
0
  python::Import import;
65
0
  import.module = module;
66
0
  exports.push_back(std::move(import));
67
0
  return exports.back();
68
0
}
69
70
const python::Import& python::Imports::Export(const std::string& module,
71
0
                                              const std::string& name) {
72
0
  python::Import import;
73
0
  import.module = module;
74
0
  import.name = name;
75
0
  exports.push_back(std::move(import));
76
0
  return exports.back();
77
0
}
78
}  // namespace python
79
}  // namespace flatbuffers