Coverage Report

Created: 2025-06-13 06:50

/src/wabt/src/lexer-source.cc
Line
Count
Source (jump to first uncovered line)
1
/*
2
 * Copyright 2017 WebAssembly Community Group participants
3
 *
4
 * Licensed under the Apache License, Version 2.0 (the "License");
5
 * you may not use this file except in compliance with the License.
6
 * You may obtain a copy of the License at
7
 *
8
 *     http://www.apache.org/licenses/LICENSE-2.0
9
 *
10
 * Unless required by applicable law or agreed to in writing, software
11
 * distributed under the License is distributed on an "AS IS" BASIS,
12
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
 * See the License for the specific language governing permissions and
14
 * limitations under the License.
15
 */
16
17
#include "wabt/lexer-source.h"
18
19
#include <algorithm>
20
21
namespace wabt {
22
23
LexerSource::LexerSource(const void* data, Offset size)
24
23.2k
    : data_(data), size_(size), read_offset_(0) {}
25
26
0
std::unique_ptr<LexerSource> LexerSource::Clone() {
27
0
  LexerSource* result = new LexerSource(data_, size_);
28
0
  result->read_offset_ = read_offset_;
29
0
  return std::unique_ptr<LexerSource>(result);
30
0
}
31
32
0
Result LexerSource::Tell(Offset* out_offset) {
33
0
  *out_offset = read_offset_;
34
0
  return Result::Ok;
35
0
}
36
37
0
size_t LexerSource::Fill(void* dest, Offset size) {
38
0
  Offset read_size = std::min(size, size_ - read_offset_);
39
0
  if (read_size > 0) {
40
0
    const void* src = static_cast<const char*>(data_) + read_offset_;
41
0
    memcpy(dest, src, read_size);
42
0
    read_offset_ += read_size;
43
0
  }
44
0
  return read_size;
45
0
}
46
47
0
Result LexerSource::Seek(Offset offset) {
48
0
  if (offset < size_) {
49
0
    read_offset_ = offset;
50
0
    return Result::Ok;
51
0
  }
52
0
  return Result::Error;
53
0
}
54
55
0
Result LexerSource::ReadRange(OffsetRange range, std::vector<char>* out_data) {
56
0
  OffsetRange clamped = range;
57
0
  clamped.start = std::min(clamped.start, size_);
58
0
  clamped.end = std::min(clamped.end, size_);
59
0
  if (clamped.size()) {
60
0
    out_data->resize(clamped.size());
61
0
    const void* src = static_cast<const char*>(data_) + clamped.start;
62
0
    memcpy(out_data->data(), src, clamped.size());
63
0
  }
64
0
  return Result::Ok;
65
0
}
66
67
}  // namespace wabt