Coverage Report

Created: 2019-07-24 05:18

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/lib/Remarks/YAMLRemarkParser.h
Line
Count
Source (jump to first uncovered line)
1
//===-- YAMLRemarkParser.h - Parser for YAML remarks ------------*- C++/-*-===//
2
//
3
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4
// See https://llvm.org/LICENSE.txt for license information.
5
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6
//
7
//===----------------------------------------------------------------------===//
8
//
9
// This file provides the impementation of the YAML remark parser.
10
//
11
//===----------------------------------------------------------------------===//
12
13
#ifndef LLVM_REMARKS_YAML_REMARK_PARSER_H
14
#define LLVM_REMARKS_YAML_REMARK_PARSER_H
15
16
#include "llvm/ADT/Optional.h"
17
#include "llvm/ADT/SmallVector.h"
18
#include "llvm/Remarks/Remark.h"
19
#include "llvm/Remarks/RemarkParser.h"
20
#include "llvm/Support/Error.h"
21
#include "llvm/Support/SourceMgr.h"
22
#include "llvm/Support/YAMLParser.h"
23
#include "llvm/Support/YAMLTraits.h"
24
#include "llvm/Support/raw_ostream.h"
25
#include <string>
26
27
namespace llvm {
28
namespace remarks {
29
30
class YAMLParseError : public ErrorInfo<YAMLParseError> {
31
public:
32
  static char ID;
33
34
  YAMLParseError(StringRef Message, SourceMgr &SM, yaml::Stream &Stream,
35
                 yaml::Node &Node);
36
37
1
  YAMLParseError(StringRef Message) : Message(Message) {}
38
39
24
  void log(raw_ostream &OS) const override { OS << Message; }
40
0
  std::error_code convertToErrorCode() const override {
41
0
    return inconvertibleErrorCode();
42
0
  }
43
44
private:
45
  std::string Message;
46
};
47
48
/// Regular YAML to Remark parser.
49
struct YAMLRemarkParser : public Parser {
50
  /// The string table used for parsing strings.
51
  Optional<ParsedStringTable> StrTab;
52
  /// Last error message that can come from the YAML parser diagnostics.
53
  /// We need this for catching errors in the constructor.
54
  std::string LastErrorMessage;
55
  /// Source manager for better error messages.
56
  SourceMgr SM;
57
  /// Stream for yaml parsing.
58
  yaml::Stream Stream;
59
  /// Iterator in the YAML stream.
60
  yaml::document_iterator YAMLIt;
61
62
  YAMLRemarkParser(StringRef Buf);
63
64
  Expected<std::unique_ptr<Remark>> next() override;
65
66
0
  static bool classof(const Parser *P) {
67
0
    return P->ParserFormat == Format::YAML;
68
0
  }
69
70
protected:
71
  YAMLRemarkParser(StringRef Buf, Optional<ParsedStringTable> StrTab);
72
  /// Create a YAMLParseError error from an existing error generated by the YAML
73
  /// parser.
74
  /// If there is no error, this returns Success.
75
  Error error();
76
  /// Create a YAMLParseError error referencing a specific node.
77
  Error error(StringRef Message, yaml::Node &Node);
78
  /// Parse a YAML remark to a remarks::Remark object.
79
  Expected<std::unique_ptr<Remark>> parseRemark(yaml::Document &Remark);
80
  /// Parse the type of a remark to an enum type.
81
  Expected<Type> parseType(yaml::MappingNode &Node);
82
  /// Parse one key to a string.
83
  Expected<StringRef> parseKey(yaml::KeyValueNode &Node);
84
  /// Parse one value to a string.
85
  virtual Expected<StringRef> parseStr(yaml::KeyValueNode &Node);
86
  /// Parse one value to an unsigned.
87
  Expected<unsigned> parseUnsigned(yaml::KeyValueNode &Node);
88
  /// Parse a debug location.
89
  Expected<RemarkLocation> parseDebugLoc(yaml::KeyValueNode &Node);
90
  /// Parse an argument.
91
  Expected<Argument> parseArg(yaml::Node &Node);
92
};
93
94
/// YAML with a string table to Remark parser.
95
struct YAMLStrTabRemarkParser : public YAMLRemarkParser {
96
  YAMLStrTabRemarkParser(StringRef Buf, ParsedStringTable StrTab)
97
2
      : YAMLRemarkParser(Buf, std::move(StrTab)) {}
98
99
0
  static bool classof(const Parser *P) {
100
0
    return P->ParserFormat == Format::YAMLStrTab;
101
0
  }
102
103
protected:
104
  /// Parse one value to a string.
105
  Expected<StringRef> parseStr(yaml::KeyValueNode &Node) override;
106
};
107
} // end namespace remarks
108
} // end namespace llvm
109
110
#endif /* LLVM_REMARKS_YAML_REMARK_PARSER_H */