Files
RedBear-OS/local/recipes/dev/libclc/source/llvm/lib/Remarks/YAMLRemarkParser.h
T
vasilito cb424d7448 build: static patch-sanity linter (shift-left the malformed-patch class)
verify-patch-sanity.py validates every active recipe .patch has internally-
consistent hunk line counts — catching the 'malformed patch at line N' failure
at commit/CI/preflight time instead of hours into a cook. This cycle hit that
class three times (qtwaylandscanner, sddm, xwayland), each only discovered when
cookbook tried to apply the patch.

Running it across the repo found 29 latent malformed patches (validated against
GNU patch: e.g. relibc/P3-sysv-ipc reproduces 'malformed patch at line 22').
They were harmless only because they sit in vendored recipes (baked, not re-
applied) — but would fail on any version-bump re-derivation. --fix recounts the
hunk headers (body untouched) and repaired all 29.

Wired into build-preflight.sh (Phase 1.0D) and redbear-ci.yml, with a unit test
(test-patch-sanity.sh). Skips archived/legacy trees and unvalidatable formats
(empty placeholders, bare-@@ git hunks).
2026-08-01 05:13:02 +03:00

101 lines
3.3 KiB
C++

//===-- YAMLRemarkParser.h - Parser for YAML remarks ------------*- C++/-*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
//
// This file provides the impementation of the YAML remark parser.
//
//===----------------------------------------------------------------------===//
#ifndef LLVM_REMARKS_YAML_REMARK_PARSER_H
#define LLVM_REMARKS_YAML_REMARK_PARSER_H
#include "llvm/Remarks/Remark.h"
#include "llvm/Remarks/RemarkParser.h"
#include "llvm/Support/Error.h"
#include "llvm/Support/MemoryBuffer.h"
#include "llvm/Support/SourceMgr.h"
#include "llvm/Support/YAMLParser.h"
#include "llvm/Support/raw_ostream.h"
#include <optional>
#include <string>
namespace llvm {
namespace remarks {
class YAMLParseError : public ErrorInfo<YAMLParseError> {
public:
static char ID;
YAMLParseError(StringRef Message, SourceMgr &SM, yaml::Stream &Stream,
yaml::Node &Node);
YAMLParseError(StringRef Message) : Message(std::string(Message)) {}
void log(raw_ostream &OS) const override { OS << Message; }
std::error_code convertToErrorCode() const override {
return inconvertibleErrorCode();
}
private:
std::string Message;
};
/// Regular YAML to Remark parser.
struct YAMLRemarkParser : public RemarkParser {
/// Last error message that can come from the YAML parser diagnostics.
/// We need this for catching errors in the constructor.
std::string LastErrorMessage;
/// Source manager for better error messages.
SourceMgr SM;
/// Stream for yaml parsing.
yaml::Stream Stream;
/// Iterator in the YAML stream.
yaml::document_iterator YAMLIt;
/// If we parse remark metadata in separate mode, we need to open a new file
/// and parse that.
std::unique_ptr<MemoryBuffer> SeparateBuf;
YAMLRemarkParser(StringRef Buf);
Expected<std::unique_ptr<Remark>> next() override;
static bool classof(const RemarkParser *P) {
return P->ParserFormat == Format::YAML;
}
protected:
/// Create a YAMLParseError error from an existing error generated by the YAML
/// parser.
/// If there is no error, this returns Success.
Error error();
/// Create a YAMLParseError error referencing a specific node.
Error error(StringRef Message, yaml::Node &Node);
/// Parse a YAML remark to a remarks::Remark object.
Expected<std::unique_ptr<Remark>> parseRemark(yaml::Document &Remark);
/// Parse the type of a remark to an enum type.
Expected<Type> parseType(yaml::MappingNode &Node);
/// Parse one key to a string.
Expected<StringRef> parseKey(yaml::KeyValueNode &Node);
/// Parse one value to a string.
virtual Expected<StringRef> parseStr(yaml::KeyValueNode &Node);
/// Parse one value to an unsigned.
Expected<unsigned> parseUnsigned(yaml::KeyValueNode &Node);
/// Parse a debug location.
Expected<RemarkLocation> parseDebugLoc(yaml::KeyValueNode &Node);
/// Parse an argument.
Expected<Argument> parseArg(yaml::Node &Node);
};
Expected<std::unique_ptr<YAMLRemarkParser>> createYAMLParserFromMeta(
StringRef Buf,
std::optional<StringRef> ExternalFilePrependPath = std::nullopt);
} // end namespace remarks
} // end namespace llvm
#endif /* LLVM_REMARKS_YAML_REMARK_PARSER_H */