| 1 | // _gen/data_lang/pretty.asdl.h is generated by asdl_main.py
|
| 2 |
|
| 3 | #ifndef PRETTY_ASDL
|
| 4 | #define PRETTY_ASDL
|
| 5 |
|
| 6 | #include <cstdint>
|
| 7 |
|
| 8 | #include "mycpp/runtime.h"
|
| 9 | #include "_gen/asdl/hnode.asdl.h"
|
| 10 | using hnode_asdl::hnode_t;
|
| 11 |
|
| 12 | namespace pretty_asdl {
|
| 13 |
|
| 14 | // use struct instead of namespace so 'using' works consistently
|
| 15 | #define ASDL_NAMES struct
|
| 16 |
|
| 17 | class MeasuredDoc;
|
| 18 | class Measure;
|
| 19 | class doc_t;
|
| 20 | class DocFragment;
|
| 21 |
|
| 22 | ASDL_NAMES doc_e {
|
| 23 | enum no_name {
|
| 24 | Break = 1,
|
| 25 | Text = 2,
|
| 26 | Indent = 3,
|
| 27 | Concat = 4,
|
| 28 | Group = 5,
|
| 29 | IfFlat = 6,
|
| 30 | };
|
| 31 | };
|
| 32 |
|
| 33 | BigStr* doc_str(int tag, bool dot = true);
|
| 34 |
|
| 35 | class doc_t {
|
| 36 | protected:
|
| 37 | doc_t() {
|
| 38 | }
|
| 39 | public:
|
| 40 | int tag() const {
|
| 41 | return ObjHeader::FromObject(this)->type_tag;
|
| 42 | }
|
| 43 | hnode_t* PrettyTree(Dict<int, bool>* seen = nullptr);
|
| 44 | DISALLOW_COPY_AND_ASSIGN(doc_t)
|
| 45 | };
|
| 46 |
|
| 47 | class doc__Break : public doc_t {
|
| 48 | public:
|
| 49 | doc__Break(BigStr* string)
|
| 50 | : string(string) {
|
| 51 | }
|
| 52 |
|
| 53 | static doc__Break* CreateNull(bool alloc_lists = false) {
|
| 54 | return Alloc<doc__Break>(kEmptyString);
|
| 55 | }
|
| 56 |
|
| 57 | hnode_t* PrettyTree(Dict<int, bool>* seen = nullptr);
|
| 58 |
|
| 59 | static constexpr ObjHeader obj_header() {
|
| 60 | return ObjHeader::AsdlClass(static_cast<uint16_t>(doc_e::Break), 1);
|
| 61 | }
|
| 62 |
|
| 63 | BigStr* string;
|
| 64 |
|
| 65 | DISALLOW_COPY_AND_ASSIGN(doc__Break)
|
| 66 | };
|
| 67 |
|
| 68 | class doc__Text : public doc_t {
|
| 69 | public:
|
| 70 | doc__Text(BigStr* string)
|
| 71 | : string(string) {
|
| 72 | }
|
| 73 |
|
| 74 | static doc__Text* CreateNull(bool alloc_lists = false) {
|
| 75 | return Alloc<doc__Text>(kEmptyString);
|
| 76 | }
|
| 77 |
|
| 78 | hnode_t* PrettyTree(Dict<int, bool>* seen = nullptr);
|
| 79 |
|
| 80 | static constexpr ObjHeader obj_header() {
|
| 81 | return ObjHeader::AsdlClass(static_cast<uint16_t>(doc_e::Text), 1);
|
| 82 | }
|
| 83 |
|
| 84 | BigStr* string;
|
| 85 |
|
| 86 | DISALLOW_COPY_AND_ASSIGN(doc__Text)
|
| 87 | };
|
| 88 |
|
| 89 | class doc__Indent : public doc_t {
|
| 90 | public:
|
| 91 | doc__Indent(int indent, MeasuredDoc* mdoc)
|
| 92 | : mdoc(mdoc),
|
| 93 | indent(indent) {
|
| 94 | }
|
| 95 |
|
| 96 | static doc__Indent* CreateNull(bool alloc_lists = false) {
|
| 97 | return Alloc<doc__Indent>(-1, nullptr);
|
| 98 | }
|
| 99 |
|
| 100 | hnode_t* PrettyTree(Dict<int, bool>* seen = nullptr);
|
| 101 |
|
| 102 | static constexpr ObjHeader obj_header() {
|
| 103 | return ObjHeader::AsdlClass(static_cast<uint16_t>(doc_e::Indent), 1);
|
| 104 | }
|
| 105 |
|
| 106 | MeasuredDoc* mdoc;
|
| 107 | int indent;
|
| 108 |
|
| 109 | DISALLOW_COPY_AND_ASSIGN(doc__Indent)
|
| 110 | };
|
| 111 |
|
| 112 | class doc__Concat : public doc_t {
|
| 113 | public:
|
| 114 | doc__Concat(List<MeasuredDoc*>* mdocs)
|
| 115 | : mdocs(mdocs) {
|
| 116 | }
|
| 117 |
|
| 118 | static doc__Concat* CreateNull(bool alloc_lists = false) {
|
| 119 | return Alloc<doc__Concat>(alloc_lists ? Alloc<List<MeasuredDoc*>>() :
|
| 120 | nullptr);
|
| 121 | }
|
| 122 |
|
| 123 | hnode_t* PrettyTree(Dict<int, bool>* seen = nullptr);
|
| 124 |
|
| 125 | static constexpr ObjHeader obj_header() {
|
| 126 | return ObjHeader::AsdlClass(static_cast<uint16_t>(doc_e::Concat), 1);
|
| 127 | }
|
| 128 |
|
| 129 | List<MeasuredDoc*>* mdocs;
|
| 130 |
|
| 131 | DISALLOW_COPY_AND_ASSIGN(doc__Concat)
|
| 132 | };
|
| 133 |
|
| 134 | class doc__Group : public doc_t {
|
| 135 | public:
|
| 136 | doc__Group(MeasuredDoc* mdoc)
|
| 137 | : mdoc(mdoc) {
|
| 138 | }
|
| 139 |
|
| 140 | static doc__Group* CreateNull(bool alloc_lists = false) {
|
| 141 | return Alloc<doc__Group>(nullptr);
|
| 142 | }
|
| 143 |
|
| 144 | hnode_t* PrettyTree(Dict<int, bool>* seen = nullptr);
|
| 145 |
|
| 146 | static constexpr ObjHeader obj_header() {
|
| 147 | return ObjHeader::AsdlClass(static_cast<uint16_t>(doc_e::Group), 1);
|
| 148 | }
|
| 149 |
|
| 150 | MeasuredDoc* mdoc;
|
| 151 |
|
| 152 | DISALLOW_COPY_AND_ASSIGN(doc__Group)
|
| 153 | };
|
| 154 |
|
| 155 | class doc__IfFlat : public doc_t {
|
| 156 | public:
|
| 157 | doc__IfFlat(MeasuredDoc* flat_mdoc, MeasuredDoc* nonflat_mdoc)
|
| 158 | : flat_mdoc(flat_mdoc),
|
| 159 | nonflat_mdoc(nonflat_mdoc) {
|
| 160 | }
|
| 161 |
|
| 162 | static doc__IfFlat* CreateNull(bool alloc_lists = false) {
|
| 163 | return Alloc<doc__IfFlat>(nullptr, nullptr);
|
| 164 | }
|
| 165 |
|
| 166 | hnode_t* PrettyTree(Dict<int, bool>* seen = nullptr);
|
| 167 |
|
| 168 | static constexpr ObjHeader obj_header() {
|
| 169 | return ObjHeader::AsdlClass(static_cast<uint16_t>(doc_e::IfFlat), 2);
|
| 170 | }
|
| 171 |
|
| 172 | MeasuredDoc* flat_mdoc;
|
| 173 | MeasuredDoc* nonflat_mdoc;
|
| 174 |
|
| 175 | DISALLOW_COPY_AND_ASSIGN(doc__IfFlat)
|
| 176 | };
|
| 177 |
|
| 178 | ASDL_NAMES doc {
|
| 179 | typedef doc__Break Break;
|
| 180 | typedef doc__Text Text;
|
| 181 | typedef doc__Indent Indent;
|
| 182 | typedef doc__Concat Concat;
|
| 183 | typedef doc__Group Group;
|
| 184 | typedef doc__IfFlat IfFlat;
|
| 185 | };
|
| 186 |
|
| 187 | class MeasuredDoc {
|
| 188 | public:
|
| 189 | MeasuredDoc(doc_t* doc, Measure* measure)
|
| 190 | : doc(doc),
|
| 191 | measure(measure) {
|
| 192 | }
|
| 193 |
|
| 194 | static MeasuredDoc* CreateNull(bool alloc_lists = false) {
|
| 195 | return Alloc<MeasuredDoc>(nullptr, nullptr);
|
| 196 | }
|
| 197 |
|
| 198 | hnode_t* PrettyTree(Dict<int, bool>* seen = nullptr);
|
| 199 |
|
| 200 | static constexpr ObjHeader obj_header() {
|
| 201 | return ObjHeader::AsdlClass(64, 2);
|
| 202 | }
|
| 203 |
|
| 204 | doc_t* doc;
|
| 205 | Measure* measure;
|
| 206 |
|
| 207 | DISALLOW_COPY_AND_ASSIGN(MeasuredDoc)
|
| 208 | };
|
| 209 |
|
| 210 | class Measure {
|
| 211 | public:
|
| 212 | Measure(int flat, int nonflat)
|
| 213 | : flat(flat),
|
| 214 | nonflat(nonflat) {
|
| 215 | }
|
| 216 |
|
| 217 | static Measure* CreateNull(bool alloc_lists = false) {
|
| 218 | return Alloc<Measure>(-1, -1);
|
| 219 | }
|
| 220 |
|
| 221 | hnode_t* PrettyTree(Dict<int, bool>* seen = nullptr);
|
| 222 |
|
| 223 | static constexpr ObjHeader obj_header() {
|
| 224 | return ObjHeader::AsdlClass(65, 0);
|
| 225 | }
|
| 226 |
|
| 227 | int flat;
|
| 228 | int nonflat;
|
| 229 |
|
| 230 | DISALLOW_COPY_AND_ASSIGN(Measure)
|
| 231 | };
|
| 232 |
|
| 233 | class DocFragment {
|
| 234 | public:
|
| 235 | DocFragment(MeasuredDoc* mdoc, int indent, bool is_flat, Measure* measure)
|
| 236 | : mdoc(mdoc),
|
| 237 | measure(measure),
|
| 238 | indent(indent),
|
| 239 | is_flat(is_flat) {
|
| 240 | }
|
| 241 |
|
| 242 | static DocFragment* CreateNull(bool alloc_lists = false) {
|
| 243 | return Alloc<DocFragment>(nullptr, -1, false, nullptr);
|
| 244 | }
|
| 245 |
|
| 246 | hnode_t* PrettyTree(Dict<int, bool>* seen = nullptr);
|
| 247 |
|
| 248 | static constexpr ObjHeader obj_header() {
|
| 249 | return ObjHeader::AsdlClass(66, 2);
|
| 250 | }
|
| 251 |
|
| 252 | MeasuredDoc* mdoc;
|
| 253 | Measure* measure;
|
| 254 | int indent;
|
| 255 | bool is_flat;
|
| 256 |
|
| 257 | DISALLOW_COPY_AND_ASSIGN(DocFragment)
|
| 258 | };
|
| 259 |
|
| 260 |
|
| 261 | } // namespace pretty_asdl
|
| 262 |
|
| 263 | #endif // PRETTY_ASDL
|