| 1 | // _gen/data_lang/pretty.asdl.cc is generated by asdl_main.py
 | 
| 2 | 
 | 
| 3 | #include "_gen/data_lang/pretty.asdl.h"
 | 
| 4 | #include <assert.h>
 | 
| 5 | #include "prebuilt/asdl/runtime.mycpp.h"  // generated code uses wrappers here
 | 
| 6 | 
 | 
| 7 | // Generated code uses these types
 | 
| 8 | using hnode_asdl::hnode;
 | 
| 9 | using hnode_asdl::Field;
 | 
| 10 | using hnode_asdl::color_e;
 | 
| 11 | 
 | 
| 12 | 
 | 
| 13 | namespace pretty_asdl {
 | 
| 14 | 
 | 
| 15 | 
 | 
| 16 | hnode_t* MeasuredDoc::PrettyTree(Dict<int, bool>* seen) {
 | 
| 17 |   seen = seen ? seen : Alloc<Dict<int, bool>>();
 | 
| 18 |   int heap_id = ObjectId(this);
 | 
| 19 |   if (dict_contains(seen, heap_id)) {
 | 
| 20 |     return Alloc<hnode::AlreadySeen>(heap_id);
 | 
| 21 |   }
 | 
| 22 |   seen->set(heap_id, true);
 | 
| 23 |   hnode::Record* out_node = runtime::NewRecord(StrFromC("MeasuredDoc"));
 | 
| 24 |   List<Field*>* L = out_node->fields;
 | 
| 25 | 
 | 
| 26 |   hnode_t* x0 = this->doc->PrettyTree(seen);
 | 
| 27 |   L->append(Alloc<Field>(StrFromC("doc"), x0));
 | 
| 28 | 
 | 
| 29 |   hnode_t* x1 = this->measure->PrettyTree(seen);
 | 
| 30 |   L->append(Alloc<Field>(StrFromC("measure"), x1));
 | 
| 31 | 
 | 
| 32 |   return out_node;
 | 
| 33 | }
 | 
| 34 | 
 | 
| 35 | 
 | 
| 36 | hnode_t* Measure::PrettyTree(Dict<int, bool>* seen) {
 | 
| 37 |   seen = seen ? seen : Alloc<Dict<int, bool>>();
 | 
| 38 |   int heap_id = ObjectId(this);
 | 
| 39 |   if (dict_contains(seen, heap_id)) {
 | 
| 40 |     return Alloc<hnode::AlreadySeen>(heap_id);
 | 
| 41 |   }
 | 
| 42 |   seen->set(heap_id, true);
 | 
| 43 |   hnode::Record* out_node = runtime::NewRecord(StrFromC("Measure"));
 | 
| 44 |   List<Field*>* L = out_node->fields;
 | 
| 45 | 
 | 
| 46 |   hnode_t* x0 = Alloc<hnode::Leaf>(str(this->flat), color_e::OtherConst);
 | 
| 47 |   L->append(Alloc<Field>(StrFromC("flat"), x0));
 | 
| 48 | 
 | 
| 49 |   hnode_t* x1 = Alloc<hnode::Leaf>(str(this->nonflat), color_e::OtherConst);
 | 
| 50 |   L->append(Alloc<Field>(StrFromC("nonflat"), x1));
 | 
| 51 | 
 | 
| 52 |   return out_node;
 | 
| 53 | }
 | 
| 54 | 
 | 
| 55 | BigStr* doc_str(int tag, bool dot) {
 | 
| 56 |   char buf[32];
 | 
| 57 |   const char* v = nullptr;
 | 
| 58 |   switch (tag) {
 | 
| 59 |   case doc_e::Break:
 | 
| 60 |     v = "Break"; break;
 | 
| 61 |   case doc_e::Text:
 | 
| 62 |     v = "Text"; break;
 | 
| 63 |   case doc_e::Indent:
 | 
| 64 |     v = "Indent"; break;
 | 
| 65 |   case doc_e::Concat:
 | 
| 66 |     v = "Concat"; break;
 | 
| 67 |   case doc_e::Group:
 | 
| 68 |     v = "Group"; break;
 | 
| 69 |   case doc_e::IfFlat:
 | 
| 70 |     v = "IfFlat"; break;
 | 
| 71 |   case doc_e::Flat:
 | 
| 72 |     v = "Flat"; break;
 | 
| 73 |   default:
 | 
| 74 |     assert(0);
 | 
| 75 |   }
 | 
| 76 |   if (dot) {
 | 
| 77 |     snprintf(buf, 32, "doc.%s", v);
 | 
| 78 |     return StrFromC(buf);
 | 
| 79 |   } else {
 | 
| 80 |     return StrFromC(v);
 | 
| 81 |   }
 | 
| 82 | }
 | 
| 83 | 
 | 
| 84 | hnode_t* doc__Break::PrettyTree(Dict<int, bool>* seen) {
 | 
| 85 |   seen = seen ? seen : Alloc<Dict<int, bool>>();
 | 
| 86 |   int heap_id = ObjectId(this);
 | 
| 87 |   if (dict_contains(seen, heap_id)) {
 | 
| 88 |     return Alloc<hnode::AlreadySeen>(heap_id);
 | 
| 89 |   }
 | 
| 90 |   seen->set(heap_id, true);
 | 
| 91 |   hnode::Record* out_node = runtime::NewRecord(doc_str(this->tag()));
 | 
| 92 |   List<Field*>* L = out_node->fields;
 | 
| 93 | 
 | 
| 94 |   hnode_t* x0 = runtime::NewLeaf(this->string, color_e::StringConst);
 | 
| 95 |   L->append(Alloc<Field>(StrFromC("string"), x0));
 | 
| 96 | 
 | 
| 97 |   return out_node;
 | 
| 98 | }
 | 
| 99 | 
 | 
| 100 | 
 | 
| 101 | hnode_t* doc__Text::PrettyTree(Dict<int, bool>* seen) {
 | 
| 102 |   seen = seen ? seen : Alloc<Dict<int, bool>>();
 | 
| 103 |   int heap_id = ObjectId(this);
 | 
| 104 |   if (dict_contains(seen, heap_id)) {
 | 
| 105 |     return Alloc<hnode::AlreadySeen>(heap_id);
 | 
| 106 |   }
 | 
| 107 |   seen->set(heap_id, true);
 | 
| 108 |   hnode::Record* out_node = runtime::NewRecord(doc_str(this->tag()));
 | 
| 109 |   List<Field*>* L = out_node->fields;
 | 
| 110 | 
 | 
| 111 |   hnode_t* x0 = runtime::NewLeaf(this->string, color_e::StringConst);
 | 
| 112 |   L->append(Alloc<Field>(StrFromC("string"), x0));
 | 
| 113 | 
 | 
| 114 |   return out_node;
 | 
| 115 | }
 | 
| 116 | 
 | 
| 117 | 
 | 
| 118 | hnode_t* doc__Indent::PrettyTree(Dict<int, bool>* seen) {
 | 
| 119 |   seen = seen ? seen : Alloc<Dict<int, bool>>();
 | 
| 120 |   int heap_id = ObjectId(this);
 | 
| 121 |   if (dict_contains(seen, heap_id)) {
 | 
| 122 |     return Alloc<hnode::AlreadySeen>(heap_id);
 | 
| 123 |   }
 | 
| 124 |   seen->set(heap_id, true);
 | 
| 125 |   hnode::Record* out_node = runtime::NewRecord(doc_str(this->tag()));
 | 
| 126 |   List<Field*>* L = out_node->fields;
 | 
| 127 | 
 | 
| 128 |   hnode_t* x0 = Alloc<hnode::Leaf>(str(this->indent), color_e::OtherConst);
 | 
| 129 |   L->append(Alloc<Field>(StrFromC("indent"), x0));
 | 
| 130 | 
 | 
| 131 |   hnode_t* x1 = this->mdoc->PrettyTree(seen);
 | 
| 132 |   L->append(Alloc<Field>(StrFromC("mdoc"), x1));
 | 
| 133 | 
 | 
| 134 |   return out_node;
 | 
| 135 | }
 | 
| 136 | 
 | 
| 137 | 
 | 
| 138 | hnode_t* doc__Concat::PrettyTree(Dict<int, bool>* seen) {
 | 
| 139 |   seen = seen ? seen : Alloc<Dict<int, bool>>();
 | 
| 140 |   int heap_id = ObjectId(this);
 | 
| 141 |   if (dict_contains(seen, heap_id)) {
 | 
| 142 |     return Alloc<hnode::AlreadySeen>(heap_id);
 | 
| 143 |   }
 | 
| 144 |   seen->set(heap_id, true);
 | 
| 145 |   hnode::Record* out_node = runtime::NewRecord(doc_str(this->tag()));
 | 
| 146 |   List<Field*>* L = out_node->fields;
 | 
| 147 | 
 | 
| 148 |   if (this->mdocs != nullptr) {  // List
 | 
| 149 |     hnode::Array* x0 = Alloc<hnode::Array>(Alloc<List<hnode_t*>>());
 | 
| 150 |     for (ListIter<MeasuredDoc*> it(this->mdocs); !it.Done(); it.Next()) {
 | 
| 151 |       MeasuredDoc* i0 = it.Value();
 | 
| 152 |       hnode_t* h = (i0 == nullptr) ? Alloc<hnode::Leaf>(StrFromC("_"),
 | 
| 153 |                     color_e::OtherConst) : i0->PrettyTree(seen);
 | 
| 154 |       x0->children->append(h);
 | 
| 155 |     }
 | 
| 156 |     L->append(Alloc<Field>(StrFromC("mdocs"), x0));
 | 
| 157 |   }
 | 
| 158 | 
 | 
| 159 |   return out_node;
 | 
| 160 | }
 | 
| 161 | 
 | 
| 162 | 
 | 
| 163 | hnode_t* doc__Group::PrettyTree(Dict<int, bool>* seen) {
 | 
| 164 |   seen = seen ? seen : Alloc<Dict<int, bool>>();
 | 
| 165 |   int heap_id = ObjectId(this);
 | 
| 166 |   if (dict_contains(seen, heap_id)) {
 | 
| 167 |     return Alloc<hnode::AlreadySeen>(heap_id);
 | 
| 168 |   }
 | 
| 169 |   seen->set(heap_id, true);
 | 
| 170 |   hnode::Record* out_node = runtime::NewRecord(doc_str(this->tag()));
 | 
| 171 |   List<Field*>* L = out_node->fields;
 | 
| 172 | 
 | 
| 173 |   hnode_t* x0 = this->mdoc->PrettyTree(seen);
 | 
| 174 |   L->append(Alloc<Field>(StrFromC("mdoc"), x0));
 | 
| 175 | 
 | 
| 176 |   return out_node;
 | 
| 177 | }
 | 
| 178 | 
 | 
| 179 | 
 | 
| 180 | hnode_t* doc__IfFlat::PrettyTree(Dict<int, bool>* seen) {
 | 
| 181 |   seen = seen ? seen : Alloc<Dict<int, bool>>();
 | 
| 182 |   int heap_id = ObjectId(this);
 | 
| 183 |   if (dict_contains(seen, heap_id)) {
 | 
| 184 |     return Alloc<hnode::AlreadySeen>(heap_id);
 | 
| 185 |   }
 | 
| 186 |   seen->set(heap_id, true);
 | 
| 187 |   hnode::Record* out_node = runtime::NewRecord(doc_str(this->tag()));
 | 
| 188 |   List<Field*>* L = out_node->fields;
 | 
| 189 | 
 | 
| 190 |   hnode_t* x0 = this->flat_mdoc->PrettyTree(seen);
 | 
| 191 |   L->append(Alloc<Field>(StrFromC("flat_mdoc"), x0));
 | 
| 192 | 
 | 
| 193 |   hnode_t* x1 = this->nonflat_mdoc->PrettyTree(seen);
 | 
| 194 |   L->append(Alloc<Field>(StrFromC("nonflat_mdoc"), x1));
 | 
| 195 | 
 | 
| 196 |   return out_node;
 | 
| 197 | }
 | 
| 198 | 
 | 
| 199 | 
 | 
| 200 | hnode_t* doc__Flat::PrettyTree(Dict<int, bool>* seen) {
 | 
| 201 |   seen = seen ? seen : Alloc<Dict<int, bool>>();
 | 
| 202 |   int heap_id = ObjectId(this);
 | 
| 203 |   if (dict_contains(seen, heap_id)) {
 | 
| 204 |     return Alloc<hnode::AlreadySeen>(heap_id);
 | 
| 205 |   }
 | 
| 206 |   seen->set(heap_id, true);
 | 
| 207 |   hnode::Record* out_node = runtime::NewRecord(doc_str(this->tag()));
 | 
| 208 |   List<Field*>* L = out_node->fields;
 | 
| 209 | 
 | 
| 210 |   hnode_t* x0 = this->mdoc->PrettyTree(seen);
 | 
| 211 |   L->append(Alloc<Field>(StrFromC("mdoc"), x0));
 | 
| 212 | 
 | 
| 213 |   return out_node;
 | 
| 214 | }
 | 
| 215 | 
 | 
| 216 | 
 | 
| 217 | hnode_t* doc_t::PrettyTree(Dict<int, bool>* seen) {
 | 
| 218 |   switch (this->tag()) {
 | 
| 219 |   case doc_e::Break: {
 | 
| 220 |     doc__Break* obj = static_cast<doc__Break*>(this);
 | 
| 221 |     return obj->PrettyTree(seen);
 | 
| 222 |   }
 | 
| 223 |   case doc_e::Text: {
 | 
| 224 |     doc__Text* obj = static_cast<doc__Text*>(this);
 | 
| 225 |     return obj->PrettyTree(seen);
 | 
| 226 |   }
 | 
| 227 |   case doc_e::Indent: {
 | 
| 228 |     doc__Indent* obj = static_cast<doc__Indent*>(this);
 | 
| 229 |     return obj->PrettyTree(seen);
 | 
| 230 |   }
 | 
| 231 |   case doc_e::Concat: {
 | 
| 232 |     doc__Concat* obj = static_cast<doc__Concat*>(this);
 | 
| 233 |     return obj->PrettyTree(seen);
 | 
| 234 |   }
 | 
| 235 |   case doc_e::Group: {
 | 
| 236 |     doc__Group* obj = static_cast<doc__Group*>(this);
 | 
| 237 |     return obj->PrettyTree(seen);
 | 
| 238 |   }
 | 
| 239 |   case doc_e::IfFlat: {
 | 
| 240 |     doc__IfFlat* obj = static_cast<doc__IfFlat*>(this);
 | 
| 241 |     return obj->PrettyTree(seen);
 | 
| 242 |   }
 | 
| 243 |   case doc_e::Flat: {
 | 
| 244 |     doc__Flat* obj = static_cast<doc__Flat*>(this);
 | 
| 245 |     return obj->PrettyTree(seen);
 | 
| 246 |   }
 | 
| 247 |   default:
 | 
| 248 |     assert(0);
 | 
| 249 |   }
 | 
| 250 | }
 | 
| 251 | 
 | 
| 252 | hnode_t* DocFragment::PrettyTree(Dict<int, bool>* seen) {
 | 
| 253 |   seen = seen ? seen : Alloc<Dict<int, bool>>();
 | 
| 254 |   int heap_id = ObjectId(this);
 | 
| 255 |   if (dict_contains(seen, heap_id)) {
 | 
| 256 |     return Alloc<hnode::AlreadySeen>(heap_id);
 | 
| 257 |   }
 | 
| 258 |   seen->set(heap_id, true);
 | 
| 259 |   hnode::Record* out_node = runtime::NewRecord(StrFromC("DocFragment"));
 | 
| 260 |   List<Field*>* L = out_node->fields;
 | 
| 261 | 
 | 
| 262 |   hnode_t* x0 = this->mdoc->PrettyTree(seen);
 | 
| 263 |   L->append(Alloc<Field>(StrFromC("mdoc"), x0));
 | 
| 264 | 
 | 
| 265 |   hnode_t* x1 = Alloc<hnode::Leaf>(str(this->indent), color_e::OtherConst);
 | 
| 266 |   L->append(Alloc<Field>(StrFromC("indent"), x1));
 | 
| 267 | 
 | 
| 268 |   hnode_t* x2 = Alloc<hnode::Leaf>(this->is_flat ? runtime::TRUE_STR :
 | 
| 269 |                                    runtime::FALSE_STR, color_e::OtherConst);
 | 
| 270 |   L->append(Alloc<Field>(StrFromC("is_flat"), x2));
 | 
| 271 | 
 | 
| 272 |   hnode_t* x3 = this->measure->PrettyTree(seen);
 | 
| 273 |   L->append(Alloc<Field>(StrFromC("measure"), x3));
 | 
| 274 | 
 | 
| 275 |   return out_node;
 | 
| 276 | }
 | 
| 277 | 
 | 
| 278 | 
 | 
| 279 | }  // namespace pretty_asdl
 |