cpp

Coverage Report

Created: 2024-07-28 06:14

/home/uke/oil/cpp/pgen2.cc
Line
Count
Source (jump to first uncovered line)
1
// pgen2.cc
2
3
#include "pgen2.h"
4
5
#include <vector>
6
7
namespace pnode {
8
9
PNode::PNode(int typ, syntax_asdl::Token* tok, List<PNode*>*)
10
0
    : typ(typ), tok(tok), children() {
11
0
}
12
13
0
void PNode::AddChild(PNode* node) {
14
0
  children.push_back(node);
15
0
}
16
17
0
PNode* PNode::GetChild(int i) {
18
0
  int j = i;
19
0
  if (j < 0) {
20
0
    j += NumChildren();
21
0
  }
22
0
  return children[j];
23
0
}
24
25
0
int PNode::NumChildren() {
26
0
  return children.size();
27
0
}
28
29
0
PNodeAllocator::PNodeAllocator() : arena_(new std::vector<PNode>()) {
30
0
  arena_->reserve(512);
31
0
}
32
33
0
PNode* PNodeAllocator::NewPNode(int typ, syntax_asdl::Token* tok) {
34
0
  CHECK(arena_->size() < arena_->capacity());
35
0
  arena_->emplace_back(typ, tok, nullptr);
36
0
  return arena_->data() + (arena_->size() - 1);
37
0
}
38
39
0
void PNodeAllocator::Clear() {
40
0
  delete arena_;
41
0
  arena_ = nullptr;
42
0
}
43
44
}  // namespace pnode