Coverage Report

Created: 2026-02-09 06:48

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/wabt/include/wabt/result.h
Line
Count
Source
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
#ifndef WABT_RESULT_H_
18
#define WABT_RESULT_H_
19
20
namespace wabt {
21
22
struct Result {
23
  enum Enum {
24
    Ok,
25
    Error,
26
  };
27
28
768k
  Result() : Result(Ok) {}
29
361M
  Result(Enum e) : enum_(e) {}
30
360M
  operator Enum() const { return enum_; }
31
  Result& operator|=(Result rhs);
32
33
 private:
34
  Enum enum_;
35
};
36
37
7.62M
inline Result operator|(Result lhs, Result rhs) {
38
7.62M
  return (lhs == Result::Error || rhs == Result::Error) ? Result::Error
39
7.62M
                                                        : Result::Ok;
40
7.62M
}
41
42
7.28M
inline Result& Result::operator|=(Result rhs) {
43
7.28M
  enum_ = *this | rhs;
44
7.28M
  return *this;
45
7.28M
}
46
47
83.5M
inline bool Succeeded(Result result) {
48
83.5M
  return result == Result::Ok;
49
83.5M
}
50
254M
inline bool Failed(Result result) {
51
254M
  return result == Result::Error;
52
254M
}
53
54
#define CHECK_RESULT(expr)          \
55
222M
  do {                              \
56
222M
    if (Failed(expr)) {             \
57
14.0M
      return ::wabt::Result::Error; \
58
14.0M
    }                               \
59
222M
  } while (0)
60
61
}  // namespace wabt
62
63
#endif  // WABT_RESULT_H_