LLVM  16.0.0git
JSON.h
Go to the documentation of this file.
1 //===--- JSON.h - JSON values, parsing and serialization -------*- 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 /// \file
10 /// This file supports working with JSON data.
11 ///
12 /// It comprises:
13 ///
14 /// - classes which hold dynamically-typed parsed JSON structures
15 /// These are value types that can be composed, inspected, and modified.
16 /// See json::Value, and the related types json::Object and json::Array.
17 ///
18 /// - functions to parse JSON text into Values, and to serialize Values to text.
19 /// See parse(), operator<<, and format_provider.
20 ///
21 /// - a convention and helpers for mapping between json::Value and user-defined
22 /// types. See fromJSON(), ObjectMapper, and the class comment on Value.
23 ///
24 /// - an output API json::OStream which can emit JSON without materializing
25 /// all structures as json::Value.
26 ///
27 /// Typically, JSON data would be read from an external source, parsed into
28 /// a Value, and then converted into some native data structure before doing
29 /// real work on it. (And vice versa when writing).
30 ///
31 /// Other serialization mechanisms you may consider:
32 ///
33 /// - YAML is also text-based, and more human-readable than JSON. It's a more
34 /// complex format and data model, and YAML parsers aren't ubiquitous.
35 /// YAMLParser.h is a streaming parser suitable for parsing large documents
36 /// (including JSON, as YAML is a superset). It can be awkward to use
37 /// directly. YAML I/O (YAMLTraits.h) provides data mapping that is more
38 /// declarative than the toJSON/fromJSON conventions here.
39 ///
40 /// - LLVM bitstream is a space- and CPU- efficient binary format. Typically it
41 /// encodes LLVM IR ("bitcode"), but it can be a container for other data.
42 /// Low-level reader/writer libraries are in Bitstream/Bitstream*.h
43 ///
44 //===---------------------------------------------------------------------===//
45 
46 #ifndef LLVM_SUPPORT_JSON_H
47 #define LLVM_SUPPORT_JSON_H
48 
49 #include "llvm/ADT/DenseMap.h"
50 #include "llvm/ADT/SmallVector.h"
51 #include "llvm/ADT/StringRef.h"
53 #include "llvm/Support/Error.h"
56 #include <cmath>
57 #include <map>
58 
59 namespace llvm {
60 namespace json {
61 
62 // === String encodings ===
63 //
64 // JSON strings are character sequences (not byte sequences like std::string).
65 // We need to know the encoding, and for simplicity only support UTF-8.
66 //
67 // - When parsing, invalid UTF-8 is a syntax error like any other
68 //
69 // - When creating Values from strings, callers must ensure they are UTF-8.
70 // with asserts on, invalid UTF-8 will crash the program
71 // with asserts off, we'll substitute the replacement character (U+FFFD)
72 // Callers can use json::isUTF8() and json::fixUTF8() for validation.
73 //
74 // - When retrieving strings from Values (e.g. asString()), the result will
75 // always be valid UTF-8.
76 
77 /// Returns true if \p S is valid UTF-8, which is required for use as JSON.
78 /// If it returns false, \p Offset is set to a byte offset near the first error.
79 bool isUTF8(llvm::StringRef S, size_t *ErrOffset = nullptr);
80 /// Replaces invalid UTF-8 sequences in \p S with the replacement character
81 /// (U+FFFD). The returned string is valid UTF-8.
82 /// This is much slower than isUTF8, so test that first.
83 std::string fixUTF8(llvm::StringRef S);
84 
85 class Array;
86 class ObjectKey;
87 class Value;
88 template <typename T> Value toJSON(const llvm::Optional<T> &Opt);
89 
90 /// An Object is a JSON object, which maps strings to heterogenous JSON values.
91 /// It simulates DenseMap<ObjectKey, Value>. ObjectKey is a maybe-owned string.
92 class Object {
94  Storage M;
95 
96 public:
98  using mapped_type = Value;
102 
103  Object() = default;
104  // KV is a trivial key-value struct for list-initialization.
105  // (using std::pair forces extra copies).
106  struct KV;
107  explicit Object(std::initializer_list<KV> Properties);
108 
109  iterator begin() { return M.begin(); }
110  const_iterator begin() const { return M.begin(); }
111  iterator end() { return M.end(); }
112  const_iterator end() const { return M.end(); }
113 
114  bool empty() const { return M.empty(); }
115  size_t size() const { return M.size(); }
116 
117  void clear() { M.clear(); }
118  std::pair<iterator, bool> insert(KV E);
119  template <typename... Ts>
120  std::pair<iterator, bool> try_emplace(const ObjectKey &K, Ts &&... Args) {
121  return M.try_emplace(K, std::forward<Ts>(Args)...);
122  }
123  template <typename... Ts>
124  std::pair<iterator, bool> try_emplace(ObjectKey &&K, Ts &&... Args) {
125  return M.try_emplace(std::move(K), std::forward<Ts>(Args)...);
126  }
127  bool erase(StringRef K);
128  void erase(iterator I) { M.erase(I); }
129 
130  iterator find(StringRef K) { return M.find_as(K); }
131  const_iterator find(StringRef K) const { return M.find_as(K); }
132  // operator[] acts as if Value was default-constructible as null.
133  Value &operator[](const ObjectKey &K);
134  Value &operator[](ObjectKey &&K);
135  // Look up a property, returning nullptr if it doesn't exist.
136  Value *get(StringRef K);
137  const Value *get(StringRef K) const;
138  // Typed accessors return None/nullptr if
139  // - the property doesn't exist
140  // - or it has the wrong type
146  const json::Object *getObject(StringRef K) const;
148  const json::Array *getArray(StringRef K) const;
150 };
151 bool operator==(const Object &LHS, const Object &RHS);
152 inline bool operator!=(const Object &LHS, const Object &RHS) {
153  return !(LHS == RHS);
154 }
155 
156 /// An Array is a JSON array, which contains heterogeneous JSON values.
157 /// It simulates std::vector<Value>.
158 class Array {
159  std::vector<Value> V;
160 
161 public:
162  using value_type = Value;
163  using iterator = std::vector<Value>::iterator;
164  using const_iterator = std::vector<Value>::const_iterator;
165 
166  Array() = default;
167  explicit Array(std::initializer_list<Value> Elements);
168  template <typename Collection> explicit Array(const Collection &C) {
169  for (const auto &V : C)
170  emplace_back(V);
171  }
172 
173  Value &operator[](size_t I);
174  const Value &operator[](size_t I) const;
175  Value &front();
176  const Value &front() const;
177  Value &back();
178  const Value &back() const;
179  Value *data();
180  const Value *data() const;
181 
182  iterator begin();
183  const_iterator begin() const;
184  iterator end();
185  const_iterator end() const;
186 
187  bool empty() const;
188  size_t size() const;
189  void reserve(size_t S);
190 
191  void clear();
192  void push_back(const Value &E);
193  void push_back(Value &&E);
194  template <typename... Args> void emplace_back(Args &&...A);
195  void pop_back();
196  // FIXME: insert() takes const_iterator since C++11, old libstdc++ disagrees.
197  iterator insert(iterator P, const Value &E);
199  template <typename It> iterator insert(iterator P, It A, It Z);
200  template <typename... Args> iterator emplace(const_iterator P, Args &&...A);
201 
202  friend bool operator==(const Array &L, const Array &R);
203 };
204 inline bool operator!=(const Array &L, const Array &R) { return !(L == R); }
205 
206 /// A Value is an JSON value of unknown type.
207 /// They can be copied, but should generally be moved.
208 ///
209 /// === Composing values ===
210 ///
211 /// You can implicitly construct Values from:
212 /// - strings: std::string, SmallString, formatv, StringRef, char*
213 /// (char*, and StringRef are references, not copies!)
214 /// - numbers
215 /// - booleans
216 /// - null: nullptr
217 /// - arrays: {"foo", 42.0, false}
218 /// - serializable things: types with toJSON(const T&)->Value, found by ADL
219 ///
220 /// They can also be constructed from object/array helpers:
221 /// - json::Object is a type like map<ObjectKey, Value>
222 /// - json::Array is a type like vector<Value>
223 /// These can be list-initialized, or used to build up collections in a loop.
224 /// json::ary(Collection) converts all items in a collection to Values.
225 ///
226 /// === Inspecting values ===
227 ///
228 /// Each Value is one of the JSON kinds:
229 /// null (nullptr_t)
230 /// boolean (bool)
231 /// number (double, int64 or uint64)
232 /// string (StringRef)
233 /// array (json::Array)
234 /// object (json::Object)
235 ///
236 /// The kind can be queried directly, or implicitly via the typed accessors:
237 /// if (Optional<StringRef> S = E.getAsString()
238 /// assert(E.kind() == Value::String);
239 ///
240 /// Array and Object also have typed indexing accessors for easy traversal:
241 /// Expected<Value> E = parse(R"( {"options": {"font": "sans-serif"}} )");
242 /// if (Object* O = E->getAsObject())
243 /// if (Object* Opts = O->getObject("options"))
244 /// if (Optional<StringRef> Font = Opts->getString("font"))
245 /// assert(Opts->at("font").kind() == Value::String);
246 ///
247 /// === Converting JSON values to C++ types ===
248 ///
249 /// The convention is to have a deserializer function findable via ADL:
250 /// fromJSON(const json::Value&, T&, Path) -> bool
251 ///
252 /// The return value indicates overall success, and Path is used for precise
253 /// error reporting. (The Path::Root passed in at the top level fromJSON call
254 /// captures any nested error and can render it in context).
255 /// If conversion fails, fromJSON calls Path::report() and immediately returns.
256 /// This ensures that the first fatal error survives.
257 ///
258 /// Deserializers are provided for:
259 /// - bool
260 /// - int and int64_t
261 /// - double
262 /// - std::string
263 /// - vector<T>, where T is deserializable
264 /// - map<string, T>, where T is deserializable
265 /// - Optional<T>, where T is deserializable
266 /// ObjectMapper can help writing fromJSON() functions for object types.
267 ///
268 /// For conversion in the other direction, the serializer function is:
269 /// toJSON(const T&) -> json::Value
270 /// If this exists, then it also allows constructing Value from T, and can
271 /// be used to serialize vector<T>, map<string, T>, and Optional<T>.
272 ///
273 /// === Serialization ===
274 ///
275 /// Values can be serialized to JSON:
276 /// 1) raw_ostream << Value // Basic formatting.
277 /// 2) raw_ostream << formatv("{0}", Value) // Basic formatting.
278 /// 3) raw_ostream << formatv("{0:2}", Value) // Pretty-print with indent 2.
279 ///
280 /// And parsed:
281 /// Expected<Value> E = json::parse("[1, 2, null]");
282 /// assert(E && E->kind() == Value::Array);
283 class Value {
284 public:
285  enum Kind {
288  /// Number values can store both int64s and doubles at full precision,
289  /// depending on what they were constructed/parsed from.
294  };
295 
296  // It would be nice to have Value() be null. But that would make {} null too.
297  Value(const Value &M) { copyFrom(M); }
298  Value(Value &&M) { moveFrom(std::move(M)); }
299  Value(std::initializer_list<Value> Elements);
300  Value(json::Array &&Elements) : Type(T_Array) {
301  create<json::Array>(std::move(Elements));
302  }
303  template <typename Elt>
304  Value(const std::vector<Elt> &C) : Value(json::Array(C)) {}
305  Value(json::Object &&Properties) : Type(T_Object) {
306  create<json::Object>(std::move(Properties));
307  }
308  template <typename Elt>
309  Value(const std::map<std::string, Elt> &C) : Value(json::Object(C)) {}
310  // Strings: types with value semantics. Must be valid UTF-8.
311  Value(std::string V) : Type(T_String) {
312  if (LLVM_UNLIKELY(!isUTF8(V))) {
313  assert(false && "Invalid UTF-8 in value used as JSON");
314  V = fixUTF8(std::move(V));
315  }
316  create<std::string>(std::move(V));
317  }
319  : Value(std::string(V.begin(), V.end())) {}
320  Value(const llvm::formatv_object_base &V) : Value(V.str()) {}
321  // Strings: types with reference semantics. Must be valid UTF-8.
322  Value(StringRef V) : Type(T_StringRef) {
323  create<llvm::StringRef>(V);
324  if (LLVM_UNLIKELY(!isUTF8(V))) {
325  assert(false && "Invalid UTF-8 in value used as JSON");
326  *this = Value(fixUTF8(V));
327  }
328  }
329  Value(const char *V) : Value(StringRef(V)) {}
330  Value(std::nullptr_t) : Type(T_Null) {}
331  // Boolean (disallow implicit conversions).
332  // (The last template parameter is a dummy to keep templates distinct.)
333  template <typename T,
334  typename = std::enable_if_t<std::is_same<T, bool>::value>,
335  bool = false>
336  Value(T B) : Type(T_Boolean) {
337  create<bool>(B);
338  }
339 
340  // Unsigned 64-bit long integers.
341  template <typename T,
342  typename = std::enable_if_t<std::is_same<T, uint64_t>::value>,
343  bool = false, bool = false>
344  Value(T V) : Type(T_UINT64) {
345  create<uint64_t>(uint64_t{V});
346  }
347 
348  // Integers (except boolean and uint64_t).
349  // Must be non-narrowing convertible to int64_t.
350  template <typename T, typename = std::enable_if_t<std::is_integral<T>::value>,
351  typename = std::enable_if_t<!std::is_same<T, bool>::value>,
352  typename = std::enable_if_t<!std::is_same<T, uint64_t>::value>>
353  Value(T I) : Type(T_Integer) {
354  create<int64_t>(int64_t{I});
355  }
356  // Floating point. Must be non-narrowing convertible to double.
357  template <typename T,
358  typename = std::enable_if_t<std::is_floating_point<T>::value>,
359  double * = nullptr>
360  Value(T D) : Type(T_Double) {
361  create<double>(double{D});
362  }
363  // Serializable types: with a toJSON(const T&)->Value function, found by ADL.
364  template <typename T,
365  typename = std::enable_if_t<std::is_same<
366  Value, decltype(toJSON(*(const T *)nullptr))>::value>,
367  Value * = nullptr>
368  Value(const T &V) : Value(toJSON(V)) {}
369 
370  Value &operator=(const Value &M) {
371  destroy();
372  copyFrom(M);
373  return *this;
374  }
376  destroy();
377  moveFrom(std::move(M));
378  return *this;
379  }
380  ~Value() { destroy(); }
381 
382  Kind kind() const {
383  switch (Type) {
384  case T_Null:
385  return Null;
386  case T_Boolean:
387  return Boolean;
388  case T_Double:
389  case T_Integer:
390  case T_UINT64:
391  return Number;
392  case T_String:
393  case T_StringRef:
394  return String;
395  case T_Object:
396  return Object;
397  case T_Array:
398  return Array;
399  }
400  llvm_unreachable("Unknown kind");
401  }
402 
403  // Typed accessors return None/nullptr if the Value is not of this type.
405  if (LLVM_LIKELY(Type == T_Null))
406  return nullptr;
407  return llvm::None;
408  }
410  if (LLVM_LIKELY(Type == T_Boolean))
411  return as<bool>();
412  return llvm::None;
413  }
415  if (LLVM_LIKELY(Type == T_Double))
416  return as<double>();
417  if (LLVM_LIKELY(Type == T_Integer))
418  return as<int64_t>();
419  if (LLVM_LIKELY(Type == T_UINT64))
420  return as<uint64_t>();
421  return llvm::None;
422  }
423  // Succeeds if the Value is a Number, and exactly representable as int64_t.
425  if (LLVM_LIKELY(Type == T_Integer))
426  return as<int64_t>();
427  if (LLVM_LIKELY(Type == T_Double)) {
428  double D = as<double>();
429  if (LLVM_LIKELY(std::modf(D, &D) == 0.0 &&
430  D >= double(std::numeric_limits<int64_t>::min()) &&
431  D <= double(std::numeric_limits<int64_t>::max())))
432  return D;
433  }
434  return llvm::None;
435  }
437  if (Type == T_UINT64)
438  return as<uint64_t>();
439  else if (Type == T_Integer) {
440  int64_t N = as<int64_t>();
441  if (N >= 0)
442  return as<uint64_t>();
443  }
444  return llvm::None;
445  }
447  if (Type == T_String)
448  return llvm::StringRef(as<std::string>());
449  if (LLVM_LIKELY(Type == T_StringRef))
450  return as<llvm::StringRef>();
451  return llvm::None;
452  }
453  const json::Object *getAsObject() const {
454  return LLVM_LIKELY(Type == T_Object) ? &as<json::Object>() : nullptr;
455  }
457  return LLVM_LIKELY(Type == T_Object) ? &as<json::Object>() : nullptr;
458  }
459  const json::Array *getAsArray() const {
460  return LLVM_LIKELY(Type == T_Array) ? &as<json::Array>() : nullptr;
461  }
463  return LLVM_LIKELY(Type == T_Array) ? &as<json::Array>() : nullptr;
464  }
465 
466 private:
467  void destroy();
468  void copyFrom(const Value &M);
469  // We allow moving from *const* Values, by marking all members as mutable!
470  // This hack is needed to support initializer-list syntax efficiently.
471  // (std::initializer_list<T> is a container of const T).
472  void moveFrom(const Value &&M);
473  friend class Array;
474  friend class Object;
475 
476  template <typename T, typename... U> void create(U &&... V) {
477  new (reinterpret_cast<T *>(&Union)) T(std::forward<U>(V)...);
478  }
479  template <typename T> T &as() const {
480  // Using this two-step static_cast via void * instead of reinterpret_cast
481  // silences a -Wstrict-aliasing false positive from GCC6 and earlier.
482  void *Storage = static_cast<void *>(&Union);
483  return *static_cast<T *>(Storage);
484  }
485 
486  friend class OStream;
487 
488  enum ValueType : char16_t {
489  T_Null,
490  T_Boolean,
491  T_Double,
492  T_Integer,
493  T_UINT64,
494  T_StringRef,
495  T_String,
496  T_Object,
497  T_Array,
498  };
499  // All members mutable, see moveFrom().
500  mutable ValueType Type;
501  mutable llvm::AlignedCharArrayUnion<bool, double, int64_t, uint64_t,
502  llvm::StringRef, std::string, json::Array,
503  json::Object>
504  Union;
505  friend bool operator==(const Value &, const Value &);
506 };
507 
508 bool operator==(const Value &, const Value &);
509 inline bool operator!=(const Value &L, const Value &R) { return !(L == R); }
510 
511 // Array Methods
512 inline Value &Array::operator[](size_t I) { return V[I]; }
513 inline const Value &Array::operator[](size_t I) const { return V[I]; }
514 inline Value &Array::front() { return V.front(); }
515 inline const Value &Array::front() const { return V.front(); }
516 inline Value &Array::back() { return V.back(); }
517 inline const Value &Array::back() const { return V.back(); }
518 inline Value *Array::data() { return V.data(); }
519 inline const Value *Array::data() const { return V.data(); }
520 
521 inline typename Array::iterator Array::begin() { return V.begin(); }
522 inline typename Array::const_iterator Array::begin() const { return V.begin(); }
523 inline typename Array::iterator Array::end() { return V.end(); }
524 inline typename Array::const_iterator Array::end() const { return V.end(); }
525 
526 inline bool Array::empty() const { return V.empty(); }
527 inline size_t Array::size() const { return V.size(); }
528 inline void Array::reserve(size_t S) { V.reserve(S); }
529 
530 inline void Array::clear() { V.clear(); }
531 inline void Array::push_back(const Value &E) { V.push_back(E); }
532 inline void Array::push_back(Value &&E) { V.push_back(std::move(E)); }
533 template <typename... Args> inline void Array::emplace_back(Args &&...A) {
534  V.emplace_back(std::forward<Args>(A)...);
535 }
536 inline void Array::pop_back() { V.pop_back(); }
537 inline typename Array::iterator Array::insert(iterator P, const Value &E) {
538  return V.insert(P, E);
539 }
541  return V.insert(P, std::move(E));
542 }
543 template <typename It>
544 inline typename Array::iterator Array::insert(iterator P, It A, It Z) {
545  return V.insert(P, A, Z);
546 }
547 template <typename... Args>
549  return V.emplace(P, std::forward<Args>(A)...);
550 }
551 inline bool operator==(const Array &L, const Array &R) { return L.V == R.V; }
552 
553 /// ObjectKey is a used to capture keys in Object. Like Value but:
554 /// - only strings are allowed
555 /// - it's optimized for the string literal case (Owned == nullptr)
556 /// Like Value, strings must be UTF-8. See isUTF8 documentation for details.
557 class ObjectKey {
558 public:
559  ObjectKey(const char *S) : ObjectKey(StringRef(S)) {}
560  ObjectKey(std::string S) : Owned(new std::string(std::move(S))) {
561  if (LLVM_UNLIKELY(!isUTF8(*Owned))) {
562  assert(false && "Invalid UTF-8 in value used as JSON");
563  *Owned = fixUTF8(std::move(*Owned));
564  }
565  Data = *Owned;
566  }
568  if (LLVM_UNLIKELY(!isUTF8(Data))) {
569  assert(false && "Invalid UTF-8 in value used as JSON");
570  *this = ObjectKey(fixUTF8(S));
571  }
572  }
574  : ObjectKey(std::string(V.begin(), V.end())) {}
576 
577  ObjectKey(const ObjectKey &C) { *this = C; }
578  ObjectKey(ObjectKey &&C) : ObjectKey(static_cast<const ObjectKey &&>(C)) {}
580  if (C.Owned) {
581  Owned.reset(new std::string(*C.Owned));
582  Data = *Owned;
583  } else {
584  Data = C.Data;
585  }
586  return *this;
587  }
588  ObjectKey &operator=(ObjectKey &&) = default;
589 
590  operator llvm::StringRef() const { return Data; }
591  std::string str() const { return Data.str(); }
592 
593 private:
594  // FIXME: this is unneccesarily large (3 pointers). Pointer + length + owned
595  // could be 2 pointers at most.
596  std::unique_ptr<std::string> Owned;
597  llvm::StringRef Data;
598 };
599 
600 inline bool operator==(const ObjectKey &L, const ObjectKey &R) {
601  return llvm::StringRef(L) == llvm::StringRef(R);
602 }
603 inline bool operator!=(const ObjectKey &L, const ObjectKey &R) {
604  return !(L == R);
605 }
606 inline bool operator<(const ObjectKey &L, const ObjectKey &R) {
607  return StringRef(L) < StringRef(R);
608 }
609 
610 struct Object::KV {
613 };
614 
615 inline Object::Object(std::initializer_list<KV> Properties) {
616  for (const auto &P : Properties) {
617  auto R = try_emplace(P.K, nullptr);
618  if (R.second)
619  R.first->getSecond().moveFrom(std::move(P.V));
620  }
621 }
622 inline std::pair<Object::iterator, bool> Object::insert(KV E) {
623  return try_emplace(std::move(E.K), std::move(E.V));
624 }
625 inline bool Object::erase(StringRef K) {
626  return M.erase(ObjectKey(K));
627 }
628 
629 /// A "cursor" marking a position within a Value.
630 /// The Value is a tree, and this is the path from the root to the current node.
631 /// This is used to associate errors with particular subobjects.
632 class Path {
633 public:
634  class Root;
635 
636  /// Records that the value at the current path is invalid.
637  /// Message is e.g. "expected number" and becomes part of the final error.
638  /// This overwrites any previously written error message in the root.
639  void report(llvm::StringLiteral Message);
640 
641  /// The root may be treated as a Path.
642  Path(Root &R) : Parent(nullptr), Seg(&R) {}
643  /// Derives a path for an array element: this[Index]
644  Path index(unsigned Index) const { return Path(this, Segment(Index)); }
645  /// Derives a path for an object field: this.Field
646  Path field(StringRef Field) const { return Path(this, Segment(Field)); }
647 
648 private:
649  /// One element in a JSON path: an object field (.foo) or array index [27].
650  /// Exception: the root Path encodes a pointer to the Path::Root.
651  class Segment {
652  uintptr_t Pointer;
653  unsigned Offset;
654 
655  public:
656  Segment() = default;
657  Segment(Root *R) : Pointer(reinterpret_cast<uintptr_t>(R)) {}
658  Segment(llvm::StringRef Field)
659  : Pointer(reinterpret_cast<uintptr_t>(Field.data())),
660  Offset(static_cast<unsigned>(Field.size())) {}
661  Segment(unsigned Index) : Pointer(0), Offset(Index) {}
662 
663  bool isField() const { return Pointer != 0; }
664  StringRef field() const {
665  return StringRef(reinterpret_cast<const char *>(Pointer), Offset);
666  }
667  unsigned index() const { return Offset; }
668  Root *root() const { return reinterpret_cast<Root *>(Pointer); }
669  };
670 
671  const Path *Parent;
672  Segment Seg;
673 
674  Path(const Path *Parent, Segment S) : Parent(Parent), Seg(S) {}
675 };
676 
677 /// The root is the trivial Path to the root value.
678 /// It also stores the latest reported error and the path where it occurred.
679 class Path::Root {
680  llvm::StringRef Name;
681  llvm::StringLiteral ErrorMessage;
682  std::vector<Path::Segment> ErrorPath; // Only valid in error state. Reversed.
683 
684  friend void Path::report(llvm::StringLiteral Message);
685 
686 public:
687  Root(llvm::StringRef Name = "") : Name(Name), ErrorMessage("") {}
688  // No copy/move allowed as there are incoming pointers.
689  Root(Root &&) = delete;
690  Root &operator=(Root &&) = delete;
691  Root(const Root &) = delete;
692  Root &operator=(const Root &) = delete;
693 
694  /// Returns the last error reported, or else a generic error.
695  Error getError() const;
696  /// Print the root value with the error shown inline as a comment.
697  /// Unrelated parts of the value are elided for brevity, e.g.
698  /// {
699  /// "id": 42,
700  /// "name": /* expected string */ null,
701  /// "properties": { ... }
702  /// }
703  void printErrorContext(const Value &, llvm::raw_ostream &) const;
704 };
705 
706 // Standard deserializers are provided for primitive types.
707 // See comments on Value.
708 inline bool fromJSON(const Value &E, std::string &Out, Path P) {
709  if (auto S = E.getAsString()) {
710  Out = std::string(*S);
711  return true;
712  }
713  P.report("expected string");
714  return false;
715 }
716 inline bool fromJSON(const Value &E, int &Out, Path P) {
717  if (auto S = E.getAsInteger()) {
718  Out = *S;
719  return true;
720  }
721  P.report("expected integer");
722  return false;
723 }
724 inline bool fromJSON(const Value &E, int64_t &Out, Path P) {
725  if (auto S = E.getAsInteger()) {
726  Out = *S;
727  return true;
728  }
729  P.report("expected integer");
730  return false;
731 }
732 inline bool fromJSON(const Value &E, double &Out, Path P) {
733  if (auto S = E.getAsNumber()) {
734  Out = *S;
735  return true;
736  }
737  P.report("expected number");
738  return false;
739 }
740 inline bool fromJSON(const Value &E, bool &Out, Path P) {
741  if (auto S = E.getAsBoolean()) {
742  Out = *S;
743  return true;
744  }
745  P.report("expected boolean");
746  return false;
747 }
748 inline bool fromJSON(const Value &E, uint64_t &Out, Path P) {
749  if (auto S = E.getAsUINT64()) {
750  Out = *S;
751  return true;
752  }
753  P.report("expected uint64_t");
754  return false;
755 }
756 inline bool fromJSON(const Value &E, std::nullptr_t &Out, Path P) {
757  if (auto S = E.getAsNull()) {
758  Out = *S;
759  return true;
760  }
761  P.report("expected null");
762  return false;
763 }
764 template <typename T>
765 bool fromJSON(const Value &E, llvm::Optional<T> &Out, Path P) {
766  if (E.getAsNull()) {
767  Out = llvm::None;
768  return true;
769  }
770  T Result;
771  if (!fromJSON(E, Result, P))
772  return false;
773  Out = std::move(Result);
774  return true;
775 }
776 template <typename T>
777 bool fromJSON(const Value &E, std::vector<T> &Out, Path P) {
778  if (auto *A = E.getAsArray()) {
779  Out.clear();
780  Out.resize(A->size());
781  for (size_t I = 0; I < A->size(); ++I)
782  if (!fromJSON((*A)[I], Out[I], P.index(I)))
783  return false;
784  return true;
785  }
786  P.report("expected array");
787  return false;
788 }
789 template <typename T>
790 bool fromJSON(const Value &E, std::map<std::string, T> &Out, Path P) {
791  if (auto *O = E.getAsObject()) {
792  Out.clear();
793  for (const auto &KV : *O)
794  if (!fromJSON(KV.second, Out[std::string(llvm::StringRef(KV.first))],
795  P.field(KV.first)))
796  return false;
797  return true;
798  }
799  P.report("expected object");
800  return false;
801 }
802 
803 // Allow serialization of Optional<T> for supported T.
804 template <typename T> Value toJSON(const llvm::Optional<T> &Opt) {
805  return Opt ? Value(*Opt) : Value(nullptr);
806 }
807 
808 /// Helper for mapping JSON objects onto protocol structs.
809 ///
810 /// Example:
811 /// \code
812 /// bool fromJSON(const Value &E, MyStruct &R, Path P) {
813 /// ObjectMapper O(E, P);
814 /// // When returning false, error details were already reported.
815 /// return O && O.map("mandatory_field", R.MandatoryField) &&
816 /// O.mapOptional("optional_field", R.OptionalField);
817 /// }
818 /// \endcode
820 public:
821  /// If O is not an object, this mapper is invalid and an error is reported.
822  ObjectMapper(const Value &E, Path P) : O(E.getAsObject()), P(P) {
823  if (!O)
824  P.report("expected object");
825  }
826 
827  /// True if the expression is an object.
828  /// Must be checked before calling map().
829  operator bool() const { return O; }
830 
831  /// Maps a property to a field.
832  /// If the property is missing or invalid, reports an error.
833  template <typename T> bool map(StringLiteral Prop, T &Out) {
834  assert(*this && "Must check this is an object before calling map()");
835  if (const Value *E = O->get(Prop))
836  return fromJSON(*E, Out, P.field(Prop));
837  P.field(Prop).report("missing value");
838  return false;
839  }
840 
841  /// Maps a property to a field, if it exists.
842  /// If the property exists and is invalid, reports an error.
843  /// (Optional requires special handling, because missing keys are OK).
844  template <typename T> bool map(StringLiteral Prop, llvm::Optional<T> &Out) {
845  assert(*this && "Must check this is an object before calling map()");
846  if (const Value *E = O->get(Prop))
847  return fromJSON(*E, Out, P.field(Prop));
848  Out = llvm::None;
849  return true;
850  }
851 
852  /// Maps a property to a field, if it exists.
853  /// If the property exists and is invalid, reports an error.
854  /// If the property does not exist, Out is unchanged.
855  template <typename T> bool mapOptional(StringLiteral Prop, T &Out) {
856  assert(*this && "Must check this is an object before calling map()");
857  if (const Value *E = O->get(Prop))
858  return fromJSON(*E, Out, P.field(Prop));
859  return true;
860  }
861 
862 private:
863  const Object *O;
864  Path P;
865 };
866 
867 /// Parses the provided JSON source, or returns a ParseError.
868 /// The returned Value is self-contained and owns its strings (they do not refer
869 /// to the original source).
871 
872 class ParseError : public llvm::ErrorInfo<ParseError> {
873  const char *Msg;
874  unsigned Line, Column, Offset;
875 
876 public:
877  static char ID;
878  ParseError(const char *Msg, unsigned Line, unsigned Column, unsigned Offset)
879  : Msg(Msg), Line(Line), Column(Column), Offset(Offset) {}
880  void log(llvm::raw_ostream &OS) const override {
881  OS << llvm::formatv("[{0}:{1}, byte={2}]: {3}", Line, Column, Offset, Msg);
882  }
883  std::error_code convertToErrorCode() const override {
885  }
886 };
887 
888 /// Version of parse() that converts the parsed value to the type T.
889 /// RootName describes the root object and is used in error messages.
890 template <typename T>
891 Expected<T> parse(const llvm::StringRef &JSON, const char *RootName = "") {
892  auto V = parse(JSON);
893  if (!V)
894  return V.takeError();
895  Path::Root R(RootName);
896  T Result;
897  if (fromJSON(*V, Result, R))
898  return std::move(Result);
899  return R.getError();
900 }
901 
902 /// json::OStream allows writing well-formed JSON without materializing
903 /// all structures as json::Value ahead of time.
904 /// It's faster, lower-level, and less safe than OS << json::Value.
905 /// It also allows emitting more constructs, such as comments.
906 ///
907 /// Only one "top-level" object can be written to a stream.
908 /// Simplest usage involves passing lambdas (Blocks) to fill in containers:
909 ///
910 /// json::OStream J(OS);
911 /// J.array([&]{
912 /// for (const Event &E : Events)
913 /// J.object([&] {
914 /// J.attribute("timestamp", int64_t(E.Time));
915 /// J.attributeArray("participants", [&] {
916 /// for (const Participant &P : E.Participants)
917 /// J.value(P.toString());
918 /// });
919 /// });
920 /// });
921 ///
922 /// This would produce JSON like:
923 ///
924 /// [
925 /// {
926 /// "timestamp": 19287398741,
927 /// "participants": [
928 /// "King Kong",
929 /// "Miley Cyrus",
930 /// "Cleopatra"
931 /// ]
932 /// },
933 /// ...
934 /// ]
935 ///
936 /// The lower level begin/end methods (arrayBegin()) are more flexible but
937 /// care must be taken to pair them correctly:
938 ///
939 /// json::OStream J(OS);
940 // J.arrayBegin();
941 /// for (const Event &E : Events) {
942 /// J.objectBegin();
943 /// J.attribute("timestamp", int64_t(E.Time));
944 /// J.attributeBegin("participants");
945 /// for (const Participant &P : E.Participants)
946 /// J.value(P.toString());
947 /// J.attributeEnd();
948 /// J.objectEnd();
949 /// }
950 /// J.arrayEnd();
951 ///
952 /// If the call sequence isn't valid JSON, asserts will fire in debug mode.
953 /// This can be mismatched begin()/end() pairs, trying to emit attributes inside
954 /// an array, and so on.
955 /// With asserts disabled, this is undefined behavior.
956 class OStream {
957  public:
958  using Block = llvm::function_ref<void()>;
959  // If IndentSize is nonzero, output is pretty-printed.
960  explicit OStream(llvm::raw_ostream &OS, unsigned IndentSize = 0)
961  : OS(OS), IndentSize(IndentSize) {
962  Stack.emplace_back();
963  }
965  assert(Stack.size() == 1 && "Unmatched begin()/end()");
966  assert(Stack.back().Ctx == Singleton);
967  assert(Stack.back().HasValue && "Did not write top-level value");
968  }
969 
970  /// Flushes the underlying ostream. OStream does not buffer internally.
971  void flush() { OS.flush(); }
972 
973  // High level functions to output a value.
974  // Valid at top-level (exactly once), in an attribute value (exactly once),
975  // or in an array (any number of times).
976 
977  /// Emit a self-contained value (number, string, vector<string> etc).
978  void value(const Value &V);
979  /// Emit an array whose elements are emitted in the provided Block.
980  void array(Block Contents) {
981  arrayBegin();
982  Contents();
983  arrayEnd();
984  }
985  /// Emit an object whose elements are emitted in the provided Block.
986  void object(Block Contents) {
987  objectBegin();
988  Contents();
989  objectEnd();
990  }
991  /// Emit an externally-serialized value.
992  /// The caller must write exactly one valid JSON value to the provided stream.
993  /// No validation or formatting of this value occurs.
994  void rawValue(llvm::function_ref<void(raw_ostream &)> Contents) {
995  rawValueBegin();
996  Contents(OS);
997  rawValueEnd();
998  }
999  void rawValue(llvm::StringRef Contents) {
1000  rawValue([&](raw_ostream &OS) { OS << Contents; });
1001  }
1002  /// Emit a JavaScript comment associated with the next printed value.
1003  /// The string must be valid until the next attribute or value is emitted.
1004  /// Comments are not part of standard JSON, and many parsers reject them!
1005  void comment(llvm::StringRef);
1006 
1007  // High level functions to output object attributes.
1008  // Valid only within an object (any number of times).
1009 
1010  /// Emit an attribute whose value is self-contained (number, vector<int> etc).
1011  void attribute(llvm::StringRef Key, const Value& Contents) {
1012  attributeImpl(Key, [&] { value(Contents); });
1013  }
1014  /// Emit an attribute whose value is an array with elements from the Block.
1016  attributeImpl(Key, [&] { array(Contents); });
1017  }
1018  /// Emit an attribute whose value is an object with attributes from the Block.
1020  attributeImpl(Key, [&] { object(Contents); });
1021  }
1022 
1023  // Low-level begin/end functions to output arrays, objects, and attributes.
1024  // Must be correctly paired. Allowed contexts are as above.
1025 
1026  void arrayBegin();
1027  void arrayEnd();
1028  void objectBegin();
1029  void objectEnd();
1031  void attributeEnd();
1033  void rawValueEnd();
1034 
1035 private:
1036  void attributeImpl(llvm::StringRef Key, Block Contents) {
1038  Contents();
1039  attributeEnd();
1040  }
1041 
1042  void valueBegin();
1043  void flushComment();
1044  void newline();
1045 
1046  enum Context {
1047  Singleton, // Top level, or object attribute.
1048  Array,
1049  Object,
1050  RawValue, // External code writing a value to OS directly.
1051  };
1052  struct State {
1053  Context Ctx = Singleton;
1054  bool HasValue = false;
1055  };
1056  llvm::SmallVector<State, 16> Stack; // Never empty.
1057  llvm::StringRef PendingComment;
1058  llvm::raw_ostream &OS;
1059  unsigned IndentSize;
1060  unsigned Indent = 0;
1061 };
1062 
1063 /// Serializes this Value to JSON, writing it to the provided stream.
1064 /// The formatting is compact (no extra whitespace) and deterministic.
1065 /// For pretty-printing, use the formatv() format_provider below.
1067  OStream(OS).value(V);
1068  return OS;
1069 }
1070 } // namespace json
1071 
1072 /// Allow printing json::Value with formatv().
1073 /// The default style is basic/compact formatting, like operator<<.
1074 /// A format string like formatv("{0:2}", Value) pretty-prints with indent 2.
1075 template <> struct format_provider<llvm::json::Value> {
1076  static void format(const llvm::json::Value &, raw_ostream &, StringRef);
1077 };
1078 } // namespace llvm
1079 
1080 #endif
llvm::json::Array::operator[]
Value & operator[](size_t I)
Definition: JSON.h:512
llvm::json::Object::Object
Object()=default
llvm::json::Object::erase
bool erase(StringRef K)
Definition: JSON.h:625
const_iterator
llvm::json::OStream::comment
void comment(llvm::StringRef)
Emit a JavaScript comment associated with the next printed value.
Definition: JSON.cpp:804
llvm::json::OStream::attributeBegin
void attributeBegin(llvm::StringRef Key)
Definition: JSON.cpp:879
llvm::json::Path::Root
The root is the trivial Path to the root value.
Definition: JSON.h:679
as
compiles conv shl5 shl ret i32 or10 it would be better as
Definition: README.txt:615
llvm::json::Value
A Value is an JSON value of unknown type.
Definition: JSON.h:283
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
M
We currently emits eax Perhaps this is what we really should generate is Is imull three or four cycles eax eax The current instruction priority is based on pattern complexity The former is more complex because it folds a load so the latter will not be emitted Perhaps we should use AddedComplexity to give LEA32r a higher priority We should always try to match LEA first since the LEA matching code does some estimate to determine whether the match is profitable if we care more about code then imull is better It s two bytes shorter than movl leal On a Pentium M
Definition: README.txt:252
llvm::json::Value::Value
Value(std::nullptr_t)
Definition: JSON.h:330
llvm::json::Array::end
iterator end()
Definition: JSON.h:523
llvm::json::Value::kind
Kind kind() const
Definition: JSON.h:382
llvm::json::Array::back
Value & back()
Definition: JSON.h:516
llvm::json::Value::Value
Value(const char *V)
Definition: JSON.h:329
llvm::json::Value::Value
Value(T I)
Definition: JSON.h:353
llvm::json::OStream::~OStream
~OStream()
Definition: JSON.h:964
llvm::format_provider
Definition: FormatVariadicDetails.h:19
llvm::json::Value::Boolean
@ Boolean
Definition: JSON.h:287
llvm::json::Value::Object
friend class Object
Definition: JSON.h:474
llvm::json::Array::empty
bool empty() const
Definition: JSON.h:526
StringRef.h
P
This currently compiles esp xmm0 movsd esp eax eax esp ret We should use not the dag combiner This is because dagcombine2 needs to be able to see through the X86ISD::Wrapper which DAGCombine can t really do The code for turning x load into a single vector load is target independent and should be moved to the dag combiner The code for turning x load into a vector load can only handle a direct load from a global or a direct load from the stack It should be generalized to handle any load from P
Definition: README-SSE.txt:411
llvm::json::OStream::attributeEnd
void attributeEnd()
Definition: JSON.cpp:899
llvm::json::Object::find
const_iterator find(StringRef K) const
Definition: JSON.h:131
double
into xmm2 addss xmm2 xmm1 xmm3 addss xmm3 movaps xmm0 unpcklps xmm0 ret seems silly when it could just be one addps Expand libm rounding functions main should enable SSE DAZ mode and other fast SSE modes Think about doing i64 math in SSE regs on x86 This testcase should have no SSE instructions in and only one load from a constant double
Definition: README-SSE.txt:85
llvm::SmallVector< State, 16 >
llvm::json::Array::emplace_back
void emplace_back(Args &&...A)
Definition: JSON.h:533
llvm::json::Value::Value
Value(T V)
Definition: JSON.h:344
Error.h
llvm::json::Value::operator==
friend bool operator==(const Value &, const Value &)
Definition: JSON.cpp:182
llvm::json::Value::getAsNull
llvm::Optional< std::nullptr_t > getAsNull() const
Definition: JSON.h:404
llvm::DenseMapBase::erase
bool erase(const KeyT &Val)
Definition: DenseMap.h:302
llvm::json::ObjectKey::ObjectKey
ObjectKey(const char *S)
Definition: JSON.h:559
llvm::DenseMapIterator
Definition: DenseMap.h:57
llvm::json::OStream::Block
llvm::function_ref< void()> Block
Definition: JSON.h:958
llvm::Type
The instances of the Type class are immutable: once they are created, they are never changed.
Definition: Type.h:45
DenseMap.h
llvm::json::Array::begin
iterator begin()
Definition: JSON.h:521
llvm::sys::path::end
const_iterator end(StringRef path)
Get end iterator over path.
Definition: Path.cpp:235
llvm::sys::path::begin
const_iterator begin(StringRef path, Style style=Style::native)
Get begin iterator over path.
Definition: Path.cpp:226
llvm::json::Path::Root::printErrorContext
void printErrorContext(const Value &, llvm::raw_ostream &) const
Print the root value with the error shown inline as a comment.
Definition: JSON.cpp:308
llvm::json::OStream::attributeArray
void attributeArray(llvm::StringRef Key, Block Contents)
Emit an attribute whose value is an array with elements from the Block.
Definition: JSON.h:1015
llvm::json::ObjectMapper::ObjectMapper
ObjectMapper(const Value &E, Path P)
If O is not an object, this mapper is invalid and an error is reported.
Definition: JSON.h:822
llvm::Optional
Definition: APInt.h:33
llvm::json::Value::Null
@ Null
Definition: JSON.h:286
T
#define T
Definition: Mips16ISelLowering.cpp:341
llvm::json::ObjectMapper::map
bool map(StringLiteral Prop, T &Out)
Maps a property to a field.
Definition: JSON.h:833
llvm::json::Object::erase
void erase(iterator I)
Definition: JSON.h:128
llvm::max
Expected< ExpressionValue > max(const ExpressionValue &Lhs, const ExpressionValue &Rhs)
Definition: FileCheck.cpp:337
llvm::json::Value::getAsNumber
llvm::Optional< double > getAsNumber() const
Definition: JSON.h:414
llvm::Expected
Tagged union holding either a T or a Error.
Definition: APFloat.h:41
RHS
Value * RHS
Definition: X86PartialReduction.cpp:76
llvm::json::ParseError::log
void log(llvm::raw_ostream &OS) const override
Print an error message to an output stream.
Definition: JSON.h:880
llvm::json::OStream::rawValue
void rawValue(llvm::StringRef Contents)
Definition: JSON.h:999
llvm::AlignedCharArrayUnion
A suitably aligned and sized character array member which can hold elements of any type.
Definition: AlignOf.h:27
llvm::codeview::PointerMode::Pointer
@ Pointer
llvm::json::Array::operator==
friend bool operator==(const Array &L, const Array &R)
Definition: JSON.h:551
llvm::json::Array::push_back
void push_back(const Value &E)
Definition: JSON.h:531
llvm::detail::DenseMapPair< ObjectKey, Value >
llvm::json::ObjectMapper::map
bool map(StringLiteral Prop, llvm::Optional< T > &Out)
Maps a property to a field, if it exists.
Definition: JSON.h:844
llvm::json::Path::report
void report(llvm::StringLiteral Message)
Records that the value at the current path is invalid.
Definition: JSON.cpp:208
llvm::json::Array::const_iterator
std::vector< Value >::const_iterator const_iterator
Definition: JSON.h:164
new
Common register allocation spilling lr str ldr sxth r3 ldr mla r4 can lr mov lr str ldr sxth r3 mla r4 and then merge mul and lr str ldr sxth r3 mla r4 It also increase the likelihood the store may become dead bb27 Successors according to LLVM ID Predecessors according to mbb< bb27, 0x8b0a7c0 > Note ADDri is not a two address instruction its result reg1037 is an operand of the PHI node in bb76 and its operand reg1039 is the result of the PHI node We should treat it as a two address code and make sure the ADDri is scheduled after any node that reads reg1039 Use info(i.e. register scavenger) to assign it a free register to allow reuse the collector could move the objects and invalidate the derived pointer This is bad enough in the first but safe points can crop up unpredictably **array_addr i32 n y store obj * new
Definition: README.txt:125
llvm::RISCVFenceField::R
@ R
Definition: RISCVBaseInfo.h:265
Context
LLVMContext & Context
Definition: NVVMIntrRange.cpp:66
llvm::DenseMapBase< DenseMap< ObjectKey, Value, llvm::DenseMapInfo< StringRef >, llvm::detail::DenseMapPair< ObjectKey, Value > >, ObjectKey, Value, llvm::DenseMapInfo< StringRef >, llvm::detail::DenseMapPair< ObjectKey, Value > >::const_iterator
DenseMapIterator< ObjectKey, Value, llvm::DenseMapInfo< StringRef >, llvm::detail::DenseMapPair< ObjectKey, Value >, true > const_iterator
Definition: DenseMap.h:73
llvm::json::operator==
bool operator==(const Object &LHS, const Object &RHS)
Definition: JSON.cpp:84
LHS
Value * LHS
Definition: X86PartialReduction.cpp:75
llvm::formatv
auto formatv(const char *Fmt, Ts &&... Vals) -> formatv_object< decltype(std::make_tuple(detail::build_format_adapter(std::forward< Ts >(Vals))...))>
Definition: FormatVariadic.h:251
llvm::json::ParseError::ParseError
ParseError(const char *Msg, unsigned Line, unsigned Column, unsigned Offset)
Definition: JSON.h:878
llvm::StringLiteral
A wrapper around a string literal that serves as a proxy for constructing global tables of StringRefs...
Definition: StringRef.h:842
llvm::json::Object::begin
const_iterator begin() const
Definition: JSON.h:110
llvm::json::Object::getString
llvm::Optional< llvm::StringRef > getString(StringRef K) const
Definition: JSON.cpp:59
llvm::json::Value::Value
Value(const Value &M)
Definition: JSON.h:297
llvm::json::Value::Value
Value(std::string V)
Definition: JSON.h:311
llvm::json::Value::Value
Value(const llvm::formatv_object_base &V)
Definition: JSON.h:320
E
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
llvm::json::OStream::object
void object(Block Contents)
Emit an object whose elements are emitted in the provided Block.
Definition: JSON.h:986
C
(vector float) vec_cmpeq(*A, *B) C
Definition: README_ALTIVEC.txt:86
llvm::json::OStream::array
void array(Block Contents)
Emit an array whose elements are emitted in the provided Block.
Definition: JSON.h:980
llvm::json::Path::Root::Root
Root(llvm::StringRef Name="")
Definition: JSON.h:687
llvm::json::Object::KV::V
Value V
Definition: JSON.h:612
llvm::json::Object::getObject
const json::Object * getObject(StringRef K) const
Definition: JSON.cpp:64
llvm::AMDGPU::PALMD::Key
Key
PAL metadata keys.
Definition: AMDGPUMetadata.h:486
llvm::json::ObjectMapper::mapOptional
bool mapOptional(StringLiteral Prop, T &Out)
Maps a property to a field, if it exists.
Definition: JSON.h:855
llvm::dwarf::Index
Index
Definition: Dwarf.h:472
B
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
llvm::json::Value::operator=
Value & operator=(Value &&M)
Definition: JSON.h:375
llvm::json::Value::Number
@ Number
Number values can store both int64s and doubles at full precision, depending on what they were constr...
Definition: JSON.h:290
llvm::json::Value::Array
friend class Array
Definition: JSON.h:473
llvm::json::Array
An Array is a JSON array, which contains heterogeneous JSON values.
Definition: JSON.h:158
llvm::raw_ostream
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:52
llvm::json::Value::Object
@ Object
Definition: JSON.h:293
llvm::raw_ostream::flush
void flush()
Definition: raw_ostream.h:185
STLFunctionalExtras.h
llvm::json::Value::Value
Value(json::Array &&Elements)
Definition: JSON.h:300
llvm::json::parse
llvm::Expected< Value > parse(llvm::StringRef JSON)
Parses the provided JSON source, or returns a ParseError.
Definition: JSON.cpp:683
llvm::json::Object::KV
Definition: JSON.h:610
llvm::json::Object::try_emplace
std::pair< iterator, bool > try_emplace(const ObjectKey &K, Ts &&... Args)
Definition: JSON.h:120
FormatVariadic.h
llvm::None
const NoneType None
Definition: None.h:24
llvm::json::OStream::objectEnd
void objectEnd()
Definition: JSON.cpp:868
llvm::json::Array::size
size_t size() const
Definition: JSON.h:527
llvm::json::Value::Value
Value(T D)
Definition: JSON.h:360
llvm::json::Object::getNumber
llvm::Optional< double > getNumber(StringRef K) const
Definition: JSON.cpp:49
llvm::json::ObjectKey::ObjectKey
ObjectKey(const llvm::formatv_object_base &V)
Definition: JSON.h:575
llvm::json::Value::Value
Value(StringRef V)
Definition: JSON.h:322
llvm::function_ref
An efficient, type-erasing, non-owning reference to a callable.
Definition: STLFunctionalExtras.h:36
llvm::json::ObjectKey::ObjectKey
ObjectKey(std::string S)
Definition: JSON.h:560
llvm::json::Object::try_emplace
std::pair< iterator, bool > try_emplace(ObjectKey &&K, Ts &&... Args)
Definition: JSON.h:124
llvm::json::Object::find
iterator find(StringRef K)
Definition: JSON.h:130
llvm::json::Value::getAsArray
json::Array * getAsArray()
Definition: JSON.h:462
llvm::RISCVFenceField::O
@ O
Definition: RISCVBaseInfo.h:264
llvm::json::Value::getAsArray
const json::Array * getAsArray() const
Definition: JSON.h:459
llvm::json::OStream::rawValueEnd
void rawValueEnd()
Definition: JSON.cpp:914
llvm::json::fromJSON
bool fromJSON(const Value &E, std::string &Out, Path P)
Definition: JSON.h:708
llvm::json::OStream
json::OStream allows writing well-formed JSON without materializing all structures as json::Value ahe...
Definition: JSON.h:956
llvm::AMDGPU::Hwreg::Offset
Offset
Definition: SIDefines.h:416
llvm::json::Object::get
Value * get(StringRef K)
Definition: JSON.cpp:27
Index
uint32_t Index
Definition: ELFObjHandler.cpp:82
uint64_t
D
static GCRegistry::Add< StatepointGC > D("statepoint-example", "an example strategy for statepoint")
const
aarch64 promote const
Definition: AArch64PromoteConstant.cpp:232
llvm::DenseMapBase< DenseMap< ObjectKey, Value, llvm::DenseMapInfo< StringRef >, llvm::detail::DenseMapPair< ObjectKey, Value > >, ObjectKey, Value, llvm::DenseMapInfo< StringRef >, llvm::detail::DenseMapPair< ObjectKey, Value > >::value_type
llvm::detail::DenseMapPair< ObjectKey, Value > value_type
Definition: DenseMap.h:69
move
compiles ldr LCPI1_0 ldr ldr mov lsr tst moveq r1 ldr LCPI1_1 and r0 bx lr It would be better to do something like to fold the shift into the conditional move
Definition: README.txt:546
llvm::json::OStream::arrayBegin
void arrayBegin()
Definition: JSON.cpp:841
llvm::DenseMap< ObjectKey, Value, llvm::DenseMapInfo< StringRef > >
llvm::json::Object::operator[]
Value & operator[](const ObjectKey &K)
Definition: JSON.cpp:21
llvm::json::ParseError
Definition: JSON.h:872
llvm::json::Value::getAsInteger
llvm::Optional< int64_t > getAsInteger() const
Definition: JSON.h:424
I
#define I(x, y, z)
Definition: MD5.cpp:58
llvm::json::Array::data
Value * data()
Definition: JSON.h:518
llvm::json::Path::index
Path index(unsigned Index) const
Derives a path for an array element: this[Index].
Definition: JSON.h:644
llvm::json::operator!=
bool operator!=(const Object &LHS, const Object &RHS)
Definition: JSON.h:152
TemplateParamKind::Type
@ Type
llvm::AMDGPU::HSAMD::ValueType
ValueType
Value types.
Definition: AMDGPUMetadata.h:100
assert
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
llvm::move
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
Definition: STLExtras.h:1666
llvm::json::ObjectKey::ObjectKey
ObjectKey(llvm::StringRef S)
Definition: JSON.h:567
llvm::json::fixUTF8
std::string fixUTF8(llvm::StringRef S)
Replaces invalid UTF-8 sequences in S with the replacement character (U+FFFD).
Definition: JSON.cpp:708
llvm::json::Object::empty
bool empty() const
Definition: JSON.h:114
llvm::ErrorInfo
Base class for user error types.
Definition: Error.h:347
llvm::json::Array::Array
Array()=default
llvm::size
auto size(R &&Range, std::enable_if_t< std::is_base_of< std::random_access_iterator_tag, typename std::iterator_traits< decltype(Range.begin())>::iterator_category >::value, void > *=nullptr)
Get the size of a range.
Definition: STLExtras.h:1571
llvm::json::ParseError::convertToErrorCode
std::error_code convertToErrorCode() const override
Convert this error to a std::error_code.
Definition: JSON.h:883
llvm::json::Value::getAsBoolean
llvm::Optional< bool > getAsBoolean() const
Definition: JSON.h:409
llvm::json::Array::iterator
std::vector< Value >::iterator iterator
Definition: JSON.h:163
llvm::json::Array::pop_back
void pop_back()
Definition: JSON.h:536
llvm::json::Value::getAsUINT64
llvm::Optional< uint64_t > getAsUINT64() const
Definition: JSON.h:436
llvm::min
Expected< ExpressionValue > min(const ExpressionValue &Lhs, const ExpressionValue &Rhs)
Definition: FileCheck.cpp:357
llvm::json::Object::size
size_t size() const
Definition: JSON.h:115
llvm::json::ObjectKey::ObjectKey
ObjectKey(const ObjectKey &C)
Definition: JSON.h:577
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:50
llvm::json::Object::getInteger
llvm::Optional< int64_t > getInteger(StringRef K) const
Definition: JSON.cpp:54
llvm::json::Object::end
iterator end()
Definition: JSON.h:111
llvm_unreachable
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
Definition: ErrorHandling.h:143
A
* A
Definition: README_ALTIVEC.txt:89
llvm::json::Path::field
Path field(StringRef Field) const
Derives a path for an object field: this.Field.
Definition: JSON.h:646
llvm::json::Value::Value
Value(const llvm::SmallVectorImpl< char > &V)
Definition: JSON.h:318
S
add sub stmia L5 ldr r0 bl L_printf $stub Instead of a and a wouldn t it be better to do three moves *Return an aggregate type is even return S
Definition: README.txt:210
llvm::json::Array::reserve
void reserve(size_t S)
Definition: JSON.h:528
llvm::json::Object::clear
void clear()
Definition: JSON.h:117
llvm::json::toJSON
Value toJSON(const llvm::Optional< T > &Opt)
Definition: JSON.h:804
llvm::json::ObjectKey::operator=
ObjectKey & operator=(const ObjectKey &C)
Definition: JSON.h:579
llvm::json::Object::end
const_iterator end() const
Definition: JSON.h:112
llvm::format
format_object< Ts... > format(const char *Fmt, const Ts &... Vals)
These are helper functions used to produce formatted output.
Definition: Format.h:124
llvm::json::Array::emplace
iterator emplace(const_iterator P, Args &&...A)
Definition: JSON.h:548
llvm::json::ParseError::ID
static char ID
Definition: JSON.h:877
llvm::json::Value::~Value
~Value()
Definition: JSON.h:380
llvm::PointerUnion< const Value *, const PseudoSourceValue * >
llvm::json::Array::front
Value & front()
Definition: JSON.h:514
llvm::json::Path::Root::getError
Error getError() const
Returns the last error reported, or else a generic error.
Definition: JSON.cpp:223
llvm::json::Value::Value
Value(T B)
Definition: JSON.h:336
std
Definition: BitVector.h:851
llvm::inconvertibleErrorCode
std::error_code inconvertibleErrorCode()
The value returned by this function can be returned from convertToErrorCode for Error values where no...
Definition: Error.cpp:79
llvm::json::Value::getAsObject
const json::Object * getAsObject() const
Definition: JSON.h:453
llvm::json::Value::Value
Value(const std::map< std::string, Elt > &C)
Definition: JSON.h:309
llvm::Error
Lightweight error class with error context and mandatory checking.
Definition: Error.h:155
llvm::json::ObjectKey::str
std::string str() const
Definition: JSON.h:591
llvm::json::Array::insert
iterator insert(iterator P, const Value &E)
Definition: JSON.h:537
llvm::TargetStackID::Value
Value
Definition: TargetFrameLowering.h:27
llvm::ARCCC::Z
@ Z
Definition: ARCInfo.h:41
llvm::json::OStream::value
void value(const Value &V)
Emit a self-contained value (number, string, vector<string> etc).
Definition: JSON.cpp:755
llvm::json::Object::getArray
const json::Array * getArray(StringRef K) const
Definition: JSON.cpp:74
llvm::HasValue
detail::ValueMatchesPoly< M > HasValue(M Matcher)
Definition: Error.h:221
llvm::json::operator<<
llvm::raw_ostream & operator<<(llvm::raw_ostream &OS, const Value &V)
Serializes this Value to JSON, writing it to the provided stream.
Definition: JSON.h:1066
llvm::json::Value::String
@ String
Definition: JSON.h:291
llvm::json::Path::Path
Path(Root &R)
The root may be treated as a Path.
Definition: JSON.h:642
llvm::json::ObjectKey::ObjectKey
ObjectKey(const llvm::SmallVectorImpl< char > &V)
Definition: JSON.h:573
llvm::DenseMapBase< DenseMap< ObjectKey, Value, llvm::DenseMapInfo< StringRef >, llvm::detail::DenseMapPair< ObjectKey, Value > >, ObjectKey, Value, llvm::DenseMapInfo< StringRef >, llvm::detail::DenseMapPair< ObjectKey, Value > >::iterator
DenseMapIterator< ObjectKey, Value, llvm::DenseMapInfo< StringRef >, llvm::detail::DenseMapPair< ObjectKey, Value > > iterator
Definition: DenseMap.h:71
SmallVector.h
llvm::json::Value::Array
@ Array
Definition: JSON.h:292
llvm::json::Value::Value
Value(Value &&M)
Definition: JSON.h:298
llvm::json::Value::Value
Value(const std::vector< Elt > &C)
Definition: JSON.h:304
N
#define N
P
#define P(N)
llvm::json::OStream::arrayEnd
void arrayEnd()
Definition: JSON.cpp:849
llvm::json::Value::getAsObject
json::Object * getAsObject()
Definition: JSON.h:456
LLVM_LIKELY
#define LLVM_LIKELY(EXPR)
Definition: Compiler.h:209
llvm::json::Array::Array
Array(const Collection &C)
Definition: JSON.h:168
llvm::SmallVectorImpl< char >
llvm::json::Value::Value
Value(json::Object &&Properties)
Definition: JSON.h:305
llvm::json::OStream::attributeObject
void attributeObject(llvm::StringRef Key, Block Contents)
Emit an attribute whose value is an object with attributes from the Block.
Definition: JSON.h:1019
llvm::json::Value::Kind
Kind
Definition: JSON.h:285
llvm::StringRef::str
std::string str() const
str - Get the contents as an std::string.
Definition: StringRef.h:221
llvm::json::Value::Value
Value(const T &V)
Definition: JSON.h:368
llvm::formatv_object_base
Definition: FormatVariadic.h:66
llvm::json::isUTF8
bool isUTF8(llvm::StringRef S, size_t *ErrOffset=nullptr)
Returns true if S is valid UTF-8, which is required for use as JSON.
Definition: JSON.cpp:694
llvm::OptimizedStructLayoutField
A field in a structure.
Definition: OptimizedStructLayout.h:45
llvm::json::ObjectKey
ObjectKey is a used to capture keys in Object.
Definition: JSON.h:557
llvm::json::ObjectKey::ObjectKey
ObjectKey(ObjectKey &&C)
Definition: JSON.h:578
llvm::AMDGPU::HSAMD::Kernel::Key::Args
constexpr char Args[]
Key for Kernel::Metadata::mArgs.
Definition: AMDGPUMetadata.h:394
llvm::json::OStream::attribute
void attribute(llvm::StringRef Key, const Value &Contents)
Emit an attribute whose value is self-contained (number, vector<int> etc).
Definition: JSON.h:1011
LLVM_UNLIKELY
#define LLVM_UNLIKELY(EXPR)
Definition: Compiler.h:210
raw_ostream.h
llvm::json::Object
An Object is a JSON object, which maps strings to heterogenous JSON values.
Definition: JSON.h:92
llvm::json::Value::getAsString
llvm::Optional< llvm::StringRef > getAsString() const
Definition: JSON.h:446
llvm::json::Object::insert
std::pair< iterator, bool > insert(KV E)
Definition: JSON.h:622
llvm::json::Object::KV::K
ObjectKey K
Definition: JSON.h:611
llvm::json::OStream::rawValueBegin
raw_ostream & rawValueBegin()
Definition: JSON.cpp:907
llvm::json::Object::getBoolean
llvm::Optional< bool > getBoolean(StringRef K) const
Definition: JSON.cpp:44
llvm::json::Array::clear
void clear()
Definition: JSON.h:530
llvm::json::OStream::objectBegin
void objectBegin()
Definition: JSON.cpp:860
llvm::json::Path
A "cursor" marking a position within a Value.
Definition: JSON.h:632
llvm::Value
LLVM Value Representation.
Definition: Value.h:74
llvm::json::OStream::OStream
OStream(llvm::raw_ostream &OS, unsigned IndentSize=0)
Definition: JSON.h:960
llvm::json::OStream::flush
void flush()
Flushes the underlying ostream. OStream does not buffer internally.
Definition: JSON.h:971
SpecialSubKind::string
@ string
llvm::json::Path::Root::operator=
Root & operator=(Root &&)=delete
llvm::json::ObjectMapper
Helper for mapping JSON objects onto protocol structs.
Definition: JSON.h:819
llvm::json::Object::begin
iterator begin()
Definition: JSON.h:109
llvm::SmallVectorImpl::emplace_back
reference emplace_back(ArgTypes &&... Args)
Definition: SmallVector.h:923
llvm::json::OStream::rawValue
void rawValue(llvm::function_ref< void(raw_ostream &)> Contents)
Emit an externally-serialized value.
Definition: JSON.h:994
llvm::json::operator<
bool operator<(const ObjectKey &L, const ObjectKey &R)
Definition: JSON.h:606
llvm::json::Object::getNull
llvm::Optional< std::nullptr_t > getNull(StringRef K) const
Definition: JSON.cpp:39
llvm::json::Value::operator=
Value & operator=(const Value &M)
Definition: JSON.h:370