6#ifndef IR_JSON_PARSER_H_
7#define IR_JSON_PARSER_H_
15#include "lib/big_int_util.h"
16#include "lib/castable.h"
17#include "lib/cstring.h"
18#include "lib/string_map.h"
23 std::streamoff start = -1, finish = -1;
27 JsonData(
const JsonData &) =
default;
28 JsonData(JsonData &&) =
default;
29 JsonData &operator=(
const JsonData &) =
default;
30 JsonData &operator=(JsonData &&) =
default;
33 virtual ~JsonData() =
default;
36 friend std::istream &operator>>(std::istream &in, std::unique_ptr<JsonData> &
json);
37 struct error :
public std::runtime_error {
38 const JsonData *data =
nullptr;
39 std::streamoff loc = -1;
40 error(
const std::string_view what, std::streamoff l)
41 : runtime_error(std::string(what)), loc(l) {}
42 error(
const std::string_view what,
const JsonData *d)
43 : runtime_error(std::string(what)), data(d), loc(data->start) {}
49 std::streamoff scanned = 0;
50 std::map<std::streamoff, int> line;
52 LocationInfo(std::string n, std::istream &i) : name(n), in(i) {
55 std::pair<int, int> loc(std::streamoff l);
56 std::string desc(std::streamoff l);
57 std::string desc(
const JsonData &d);
58 std::string desc(
const error &e);
61 DECLARE_TYPEINFO(JsonData);
64class JsonNumber :
public JsonData {
66 explicit JsonNumber(big_int v) : val(v) {}
67 operator int()
const {
return int(val); }
70 DECLARE_TYPEINFO(JsonNumber, JsonData);
73class JsonBoolean :
public JsonData {
75 JsonBoolean(
bool v) : val(v) {}
76 operator bool()
const {
return val; }
79 DECLARE_TYPEINFO(JsonBoolean, JsonData);
82class JsonString :
public JsonData,
public std::string {
85 explicit JsonString(std::string_view s) : std::string(s) {}
86 JsonString(
const JsonString &) =
default;
87 JsonString(JsonString &&) =
default;
88 JsonString &operator=(
const JsonString &) & =
default;
89 JsonString &operator=(JsonString &&) & =
default;
92 DECLARE_TYPEINFO(JsonString, JsonData);
95class JsonVector :
public JsonData,
public std::vector<std::unique_ptr<JsonData>> {
98 explicit JsonVector(std::vector<std::unique_ptr<JsonData>> &&v)
99 : std::vector<std::unique_ptr<JsonData>>(std::move(v)) {}
100 JsonVector &operator=(
const JsonVector &) =
delete;
101 JsonVector &operator=(JsonVector &&) =
default;
103 DECLARE_TYPEINFO(JsonVector, JsonData);
106class JsonObject :
public JsonData,
public string_map<std::unique_ptr<JsonData>> {
109 JsonObject(
const JsonObject &obj) =
delete;
110 JsonObject &operator=(JsonObject &&) =
default;
111 explicit JsonObject(string_map<std::unique_ptr<JsonData>> &&v)
112 : string_map<std::unique_ptr<JsonData>>(std::move(v)) {}
114 DECLARE_TYPEINFO(JsonObject, JsonData);
118 DECLARE_TYPEINFO(
JsonNull, JsonData);
121std::string getIndent(
int l);
123std::ostream &operator<<(std::ostream &out,
const JsonData *
json);
124inline std::ostream &operator<<(std::ostream &out,
const JsonData &
json) {
return out << &
json; }
125std::istream &operator>>(std::istream &in, std::unique_ptr<JsonData> &
json);
Definition json_parser.h:22
Definition json_parser.h:117
TODO: this is not really specific to BMV2, it should reside somewhere else.
Definition applyOptionsPragmas.cpp:13
Definition json_parser.h:37