Coverage Report

Created: 2026-11-12 06:35

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/WasmEdge/include/validator/component_name.h
Line
Count
Source
1
// SPDX-License-Identifier: Apache-2.0
2
// SPDX-FileCopyrightText: Copyright The WasmEdge Authors
3
#pragma once
4
5
#include "common/errcode.h"
6
#include "common/expected.h"
7
8
#include <cstdint>
9
#include <string_view>
10
11
namespace WasmEdge {
12
namespace Validator {
13
namespace Component {
14
15
/// A parsed extern name of a component import or export.
16
class ExternName {
17
public:
18
  enum class Kind : uint8_t {
19
    Invalid,
20
    Constructor,
21
    Method,
22
    Static,
23
    InterfaceType,
24
    Label
25
  };
26
27
  /// Fragments as views into the input; the kind decides which are set.
28
  struct Detail {
29
    std::string_view Resource;  // Constructor, Method, Static
30
    std::string_view Method;    // Method, Static
31
    std::string_view Namespace; // InterfaceType
32
    std::string_view Package;   // InterfaceType
33
    std::string_view Interface; // InterfaceType
34
    std::string_view Version;   // InterfaceType
35
  };
36
37
  /// Returns true if Input is a label: <first-fragment> ( '-' <fragment> )*.
38
  static bool isKebabString(std::string_view Input) noexcept;
39
40
  /// Parses Name into this object, which stays Invalid on failure.
41
  Expect<void> parse(std::string_view Name) noexcept;
42
43
91.8k
  Kind getKind() const noexcept { return NameKind; }
44
24.5k
  std::string_view getOriginalName() const noexcept { return OriName; }
45
  /// The name without its annotation tag; empty when the name carries none.
46
26
  std::string_view getNoTagName() const noexcept { return NoTagName; }
47
2
  const Detail &getDetail() const noexcept { return NameDetail; }
48
  /// Checks the interface version, completed by Suffix when it is not empty.
49
  Expect<void> checkVersion(std::string_view Suffix) const noexcept;
50
51
private:
52
  // Cursor primitives, all consuming from Rest.
53
  bool tryRead(std::string_view Prefix) noexcept;
54
  bool readUntil(char Delim, std::string_view &Output) noexcept;
55
  std::string_view readLabelChars() noexcept;
56
57
  // One member per production, consuming the rest after its leading tag.
58
  Expect<void> parsePlainName() noexcept;
59
  Expect<void> parseInterfaceName() noexcept;
60
61
  // Grammar checks over a substring; the semver scanners stay unlogged.
62
  Expect<void> checkWordsLabel(std::string_view Label,
63
                               std::string_view What) const noexcept;
64
  Expect<void> scanSemver(std::string_view V) const noexcept;
65
  Expect<void> scanSemverIdentifiers(std::string_view Idents,
66
                                     bool CheckLeadingZeros) const noexcept;
67
68
  std::string_view OriName;
69
  std::string_view NoTagName;
70
  std::string_view Rest;
71
  Kind NameKind = Kind::Invalid;
72
  Detail NameDetail;
73
};
74
75
} // namespace Component
76
} // namespace Validator
77
} // namespace WasmEdge