1#ifndef IR_JSON_PARSER_H_
2#define IR_JSON_PARSER_H_
10#include "lib/big_int_util.h"
11#include "lib/castable.h"
12#include "lib/cstring.h"
13#include "lib/string_map.h"
18 std::streamoff start = -1, finish = -1;
22 JsonData(
const JsonData &) =
default;
23 JsonData(JsonData &&) =
default;
24 JsonData &operator=(
const JsonData &) =
default;
25 JsonData &operator=(JsonData &&) =
default;
28 virtual ~JsonData() =
default;
31 friend std::istream &operator>>(std::istream &in, std::unique_ptr<JsonData> &
json);
32 struct error :
public std::runtime_error {
33 const JsonData *data =
nullptr;
34 std::streamoff loc = -1;
35 error(
const std::string_view what, std::streamoff l)
36 : runtime_error(std::string(what)), loc(l) {}
37 error(
const std::string_view what,
const JsonData *d)
38 : runtime_error(std::string(what)), data(d) {}
44 std::streamoff scanned = 0;
45 std::map<std::streamoff, int> line;
47 LocationInfo(std::string n, std::istream &i) : name(n), in(i) {
50 std::pair<int, int> loc(std::streamoff l);
51 std::string desc(std::streamoff l);
52 std::string desc(
const JsonData &d);
53 std::string desc(
const error &e);
56 DECLARE_TYPEINFO(JsonData);
59class JsonNumber :
public JsonData {
61 explicit JsonNumber(big_int v) : val(v) {}
62 operator int()
const {
return int(val); }
65 DECLARE_TYPEINFO(JsonNumber, JsonData);
68class JsonBoolean :
public JsonData {
70 JsonBoolean(
bool v) : val(v) {}
71 operator bool()
const {
return val; }
74 DECLARE_TYPEINFO(JsonBoolean, JsonData);
77class JsonString :
public JsonData,
public std::string {
80 explicit JsonString(std::string_view s) : std::string(s) {}
81 JsonString(
const JsonString &) =
default;
82 JsonString(JsonString &&) =
default;
83 JsonString &operator=(
const JsonString &) & =
default;
84 JsonString &operator=(JsonString &&) & =
default;
87 DECLARE_TYPEINFO(JsonString, JsonData);
90class JsonVector :
public JsonData,
public std::vector<std::unique_ptr<JsonData>> {
93 explicit JsonVector(std::vector<std::unique_ptr<JsonData>> &&v)
94 : std::vector<std::unique_ptr<JsonData>>(std::move(v)) {}
95 JsonVector &operator=(
const JsonVector &) =
delete;
96 JsonVector &operator=(JsonVector &&) =
default;
98 DECLARE_TYPEINFO(JsonVector, JsonData);
101class JsonObject :
public JsonData,
public string_map<std::unique_ptr<JsonData>> {
104 JsonObject(
const JsonObject &obj) =
delete;
105 JsonObject &operator=(JsonObject &&) =
default;
106 explicit JsonObject(string_map<std::unique_ptr<JsonData>> &&v)
107 : string_map<std::unique_ptr<JsonData>>(std::move(v)) {}
109 DECLARE_TYPEINFO(JsonObject, JsonData);
113 DECLARE_TYPEINFO(
JsonNull, JsonData);
116std::string getIndent(
int l);
118std::ostream &operator<<(std::ostream &out,
const JsonData *
json);
119inline std::ostream &operator<<(std::ostream &out,
const JsonData &
json) {
return out << &
json; }
120std::istream &operator>>(std::istream &in, std::unique_ptr<JsonData> &
json);
Definition json_parser.h:17
Definition json_parser.h:112
TODO: this is not really specific to BMV2, it should reside somewhere else.
Definition applyOptionsPragmas.cpp:24
Definition json_parser.h:32