Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Save a couple of strdup/free.
[simgrid.git] / src / surf / xml / surfxml_sax_cb.cpp
1 /* Copyright (c) 2006-2017. The SimGrid Team. All rights reserved.          */
2
3 /* This program is free software; you can redistribute it and/or modify it
4  * under the terms of the license (GNU LGPL) which comes with this package. */
5
6 #include "simgrid/s4u/Engine.hpp"
7 #include "simgrid/sg_config.h"
8 #include "src/kernel/routing/NetPoint.hpp"
9 #include "src/surf/network_interface.hpp"
10 #include "xbt/file.hpp"
11
12 #include "src/surf/xml/platf_private.hpp"
13 #include <boost/algorithm/string.hpp>
14 #include <boost/algorithm/string/classification.hpp>
15 #include <boost/algorithm/string/split.hpp>
16 #include <string>
17
18 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_parse, surf, "Logging specific to the SURF parsing module");
19
20 extern "C" {
21
22 int ETag_surfxml_include_state();
23
24 #include "simgrid_dtd.c"
25
26 /*
27  * Stuff relative to the <include> tag
28  */
29 static std::vector<YY_BUFFER_STATE> surf_input_buffer_stack;
30 static std::vector<FILE*> surf_file_to_parse_stack;
31 static std::vector<std::string> surf_parsed_filename_stack;
32
33 static inline const char* surf_parsed_filename() // to locate parse error messages
34 {
35   return surf_parsed_filename_stack.empty() ? nullptr : surf_parsed_filename_stack.back().c_str();
36 }
37
38 std::vector<simgrid::surf::LinkImpl*> parsed_link_list; /* temporary store of current list link of a route */
39
40 /*
41  * Helping functions
42  */
43 void surf_parse_assert(bool cond, std::string msg)
44 {
45   if (not cond) {
46     int lineno = surf_parse_lineno;
47     cleanup();
48     XBT_ERROR("Parse error at %s:%d: %s", surf_parsed_filename(), lineno, msg.c_str());
49     surf_exit();
50     xbt_die("Exiting now");
51   }
52 }
53
54 void surf_parse_error(std::string msg)
55 {
56   int lineno = surf_parse_lineno;
57   cleanup();
58   XBT_ERROR("Parse error at %s:%d: %s", surf_parsed_filename(), lineno, msg.c_str());
59   surf_exit();
60   xbt_die("Exiting now");
61 }
62
63 void surf_parse_assert_netpoint(std::string hostname, std::string pre, std::string post)
64 {
65   if (sg_netpoint_by_name_or_null(hostname.c_str()) != nullptr) // found
66     return;
67
68   std::string msg = pre + hostname + post + " Existing netpoints: \n";
69
70   std::vector<simgrid::kernel::routing::NetPoint*> list;
71   simgrid::s4u::Engine::getInstance()->getNetpointList(&list);
72   std::sort(list.begin(), list.end(), [](simgrid::kernel::routing::NetPoint* a, simgrid::kernel::routing::NetPoint* b) {
73     return a->getName() < b->getName();
74   });
75   bool first = true;
76   for (auto const& np : list) {
77     if (np->isNetZone())
78       continue;
79
80     if (not first)
81       msg += ",";
82     first = false;
83     msg += "'" + np->getName() + "'";
84     if (msg.length() > 4096) {
85       msg.pop_back(); // remove trailing quote
86       msg += "...(list truncated)......";
87       break;
88     }
89   }
90   surf_parse_error(msg);
91 }
92
93 void surf_parse_warn(std::string msg)
94 {
95   XBT_WARN("%s:%d: %s", surf_parsed_filename(), surf_parse_lineno, msg.c_str());
96 }
97
98 double surf_parse_get_double(std::string s)
99 {
100   try {
101     return std::stod(s);
102   } catch (std::invalid_argument& ia) {
103     surf_parse_error(s + " is not a double");
104     return -1;
105   }
106 }
107
108 int surf_parse_get_int(std::string s)
109 {
110   try {
111     return std::stoi(s);
112   } catch (std::invalid_argument& ia) {
113     surf_parse_error(s + " is not a double");
114     return -1;
115   }
116 }
117
118 /* Turn something like "1-4,6,9-11" into the vector {1,2,3,4,6,9,10,11} */
119 static std::vector<int>* explodesRadical(std::string radicals)
120 {
121   std::vector<int>* exploded = new std::vector<int>();
122
123   // Make all hosts
124   std::vector<std::string> radical_elements;
125   boost::split(radical_elements, radicals, boost::is_any_of(","));
126   for (auto const& group : radical_elements) {
127     std::vector<std::string> radical_ends;
128     boost::split(radical_ends, group, boost::is_any_of("-"));
129     int start = surf_parse_get_int(radical_ends.front());
130     int end   = 0;
131
132     switch (radical_ends.size()) {
133       case 1:
134         end = start;
135         break;
136       case 2:
137         end = surf_parse_get_int(radical_ends.back());
138         break;
139       default:
140         surf_parse_error(std::string("Malformed radical: ") + group);
141         break;
142     }
143     for (int i = start; i <= end; i++)
144       exploded->push_back(i);
145   }
146
147   return exploded;
148 }
149
150 struct unit_scale {
151   const char *unit;
152   double scale;
153 };
154
155 /* Note: field `unit' for the last element of parameter `units' should be nullptr. */
156 static double surf_parse_get_value_with_unit(const char* string, const unit_scale* units, const char* entity_kind,
157                                              std::string name, const char* error_msg, const char* default_unit)
158 {
159   char* ptr;
160   int i;
161   errno = 0;
162   double res   = strtod(string, &ptr);
163   if (errno == ERANGE)
164     surf_parse_error(std::string("value out of range: ") + string);
165   if (ptr == string)
166     surf_parse_error(std::string("cannot parse number:") + string);
167   if (ptr[0] == '\0') {
168     if (res == 0)
169       return res; // Ok, 0 can be unit-less
170
171     XBT_WARN("Deprecated unit-less value '%s' for %s %s. %s", string, entity_kind, name.c_str(), error_msg);
172     ptr = (char*)default_unit;
173   }
174   for (i = 0; units[i].unit != nullptr && strcmp(ptr, units[i].unit) != 0; i++);
175
176   if (units[i].unit != nullptr)
177     res *= units[i].scale;
178   else
179     surf_parse_error(std::string("unknown unit: ") + ptr);
180   return res;
181 }
182
183 double surf_parse_get_time(const char* string, const char* entity_kind, std::string name)
184 {
185   const unit_scale units[] = {{"w", 7 * 24 * 60 * 60},
186                               {"d", 24 * 60 * 60},
187                               {"h", 60 * 60},
188                               {"m", 60},
189                               {"s", 1.0},
190                               {"ms", 1e-3},
191                               {"us", 1e-6},
192                               {"ns", 1e-9},
193                               {"ps", 1e-12},
194                               {nullptr, 0}};
195   return surf_parse_get_value_with_unit(string, units, entity_kind, name,
196       "Append 's' to your time to get seconds", "s");
197 }
198
199 double surf_parse_get_size(const char* string, const char* entity_kind, std::string name)
200 {
201   const unit_scale units[] = {{"EiB", pow(1024, 6)},
202                               {"PiB", pow(1024, 5)},
203                               {"TiB", pow(1024, 4)},
204                               {"GiB", pow(1024, 3)},
205                               {"MiB", pow(1024, 2)},
206                               {"KiB", 1024},
207                               {"EB", 1e18},
208                               {"PB", 1e15},
209                               {"TB", 1e12},
210                               {"GB", 1e9},
211                               {"MB", 1e6},
212                               {"kB", 1e3},
213                               {"B", 1.0},
214                               {"Eib", 0.125 * pow(1024, 6)},
215                               {"Pib", 0.125 * pow(1024, 5)},
216                               {"Tib", 0.125 * pow(1024, 4)},
217                               {"Gib", 0.125 * pow(1024, 3)},
218                               {"Mib", 0.125 * pow(1024, 2)},
219                               {"Kib", 0.125 * 1024},
220                               {"Eb", 0.125 * 1e18},
221                               {"Pb", 0.125 * 1e15},
222                               {"Tb", 0.125 * 1e12},
223                               {"Gb", 0.125 * 1e9},
224                               {"Mb", 0.125 * 1e6},
225                               {"kb", 0.125 * 1e3},
226                               {"b", 0.125},
227                               {nullptr, 0}};
228   return surf_parse_get_value_with_unit(string, units, entity_kind, name,
229       "Append 'B' to get bytes (or 'b' for bits but 1B = 8b).", "B");
230 }
231
232 double surf_parse_get_bandwidth(const char* string, const char* entity_kind, std::string name)
233 {
234   const unit_scale units[] = {{"EiBps", pow(1024, 6)},
235                               {"PiBps", pow(1024, 5)},
236                               {"TiBps", pow(1024, 4)},
237                               {"GiBps", pow(1024, 3)},
238                               {"MiBps", pow(1024, 2)},
239                               {"KiBps", 1024},
240                               {"EBps", 1e18},
241                               {"PBps", 1e15},
242                               {"TBps", 1e12},
243                               {"GBps", 1e9},
244                               {"MBps", 1e6},
245                               {"kBps", 1e3},
246                               {"Bps", 1.0},
247                               {"Eibps", 0.125 * pow(1024, 6)},
248                               {"Pibps", 0.125 * pow(1024, 5)},
249                               {"Tibps", 0.125 * pow(1024, 4)},
250                               {"Gibps", 0.125 * pow(1024, 3)},
251                               {"Mibps", 0.125 * pow(1024, 2)},
252                               {"Kibps", 0.125 * 1024},
253                               {"Tbps", 0.125 * 1e12},
254                               {"Gbps", 0.125 * 1e9},
255                               {"Mbps", 0.125 * 1e6},
256                               {"kbps", 0.125 * 1e3},
257                               {"bps", 0.125},
258                               {nullptr, 0}};
259   return surf_parse_get_value_with_unit(string, units, entity_kind, name,
260       "Append 'Bps' to get bytes per second (or 'bps' for bits but 1Bps = 8bps)", "Bps");
261 }
262
263 double surf_parse_get_speed(const char* string, const char* entity_kind, std::string name)
264 {
265   const unit_scale units[] = {{"yottaflops", 1e24}, {"Yf", 1e24}, {"zettaflops", 1e21}, {"Zf", 1e21},
266                               {"exaflops", 1e18},   {"Ef", 1e18}, {"petaflops", 1e15},  {"Pf", 1e15},
267                               {"teraflops", 1e12},  {"Tf", 1e12}, {"gigaflops", 1e9},   {"Gf", 1e9},
268                               {"megaflops", 1e6},   {"Mf", 1e6},  {"kiloflops", 1e3},   {"kf", 1e3},
269                               {"flops", 1.0},       {"f", 1.0},   {nullptr, 0}};
270   return surf_parse_get_value_with_unit(string, units, entity_kind, name,
271       "Append 'f' or 'flops' to your speed to get flop per second", "f");
272 }
273
274 static std::vector<double> surf_parse_get_all_speeds(char* speeds, const char* entity_kind, std::string id)
275 {
276
277   std::vector<double> speed_per_pstate;
278
279   if (strchr(speeds, ',') == nullptr){
280     double speed = surf_parse_get_speed(speeds, entity_kind, id);
281     speed_per_pstate.push_back(speed);
282   } else {
283     std::vector<std::string> pstate_list;
284     boost::split(pstate_list, speeds, boost::is_any_of(","));
285     for (auto speed_str : pstate_list) {
286       boost::trim(speed_str);
287       double speed = surf_parse_get_speed(speed_str.c_str(), entity_kind, id);
288       speed_per_pstate.push_back(speed);
289       XBT_DEBUG("Speed value: %f", speed);
290     }
291   }
292   return speed_per_pstate;
293 }
294
295 /*
296  * All the callback lists that can be overridden anywhere.
297  * (this list should probably be reduced to the bare minimum to allow the models to work)
298  */
299
300 /* make sure these symbols are defined as strong ones in this file so that the linker can resolve them */
301
302 /* The default current property receiver. Setup in the corresponding opening callbacks. */
303 std::map<std::string, std::string>* current_property_set       = nullptr;
304 std::map<std::string, std::string>* current_model_property_set = nullptr;
305 int ZONE_TAG                            = 0; // Whether we just opened a zone tag (to see what to do with the properties)
306
307 YY_BUFFER_STATE surf_input_buffer;
308 FILE *surf_file_to_parse = nullptr;
309
310 /* Stuff relative to storage */
311 void STag_surfxml_storage()
312 {
313   ZONE_TAG = 0;
314   XBT_DEBUG("STag_surfxml_storage");
315   xbt_assert(current_property_set == nullptr, "Someone forgot to reset the property set to nullptr in its closing tag (or XML malformed)");
316 }
317
318 void ETag_surfxml_storage()
319 {
320   StorageCreationArgs storage;
321
322   storage.properties   = current_property_set;
323   current_property_set = nullptr;
324
325   storage.id           = A_surfxml_storage_id;
326   storage.type_id      = A_surfxml_storage_typeId;
327   storage.content      = A_surfxml_storage_content;
328   storage.attach       = A_surfxml_storage_attach;
329
330   sg_platf_new_storage(&storage);
331 }
332 void STag_surfxml_storage___type()
333 {
334   ZONE_TAG = 0;
335   XBT_DEBUG("STag_surfxml_storage___type");
336   xbt_assert(current_property_set == nullptr, "Someone forgot to reset the property set to nullptr in its closing tag (or XML malformed)");
337   xbt_assert(current_model_property_set == nullptr, "Someone forgot to reset the model property set to nullptr in its closing tag (or XML malformed)");
338 }
339 void ETag_surfxml_storage___type()
340 {
341   StorageTypeCreationArgs storage_type;
342
343   storage_type.properties = current_property_set;
344   current_property_set    = nullptr;
345
346   storage_type.model_properties = current_model_property_set;
347   current_model_property_set    = nullptr;
348
349   storage_type.content = A_surfxml_storage___type_content;
350   storage_type.id      = A_surfxml_storage___type_id;
351   storage_type.model   = A_surfxml_storage___type_model;
352   storage_type.size =
353       surf_parse_get_size(A_surfxml_storage___type_size, "size of storage type", storage_type.id.c_str());
354   sg_platf_new_storage_type(&storage_type);
355 }
356
357 void STag_surfxml_mount()
358 {
359   XBT_DEBUG("STag_surfxml_mount");
360 }
361
362 void ETag_surfxml_mount()
363 {
364   MountCreationArgs mount;
365
366   mount.name      = A_surfxml_mount_name;
367   mount.storageId = A_surfxml_mount_storageId;
368   sg_platf_new_mount(&mount);
369 }
370
371 void STag_surfxml_include()
372 {
373   XBT_ERROR("<include> tag is deprecated, and will be removed in SimGrid v3.18. Please stop using it now (or tell us why you need it).");
374   parse_after_config();
375   XBT_DEBUG("STag_surfxml_include '%s'",A_surfxml_include_file);
376   surf_parsed_filename_stack.emplace_back(A_surfxml_include_file); // save file name
377
378   surf_file_to_parse_stack.push_back(surf_file_to_parse); // save old file descriptor
379
380   surf_file_to_parse = surf_fopen(A_surfxml_include_file, "r"); // read new file descriptor
381   xbt_assert((surf_file_to_parse), "Unable to open \"%s\"\n", A_surfxml_include_file);
382
383   surf_input_buffer_stack.push_back(surf_input_buffer);
384   surf_input_buffer = surf_parse__create_buffer(surf_file_to_parse, YY_BUF_SIZE);
385   surf_parse_push_buffer_state(surf_input_buffer);
386
387   fflush(nullptr);
388 }
389
390 void ETag_surfxml_include() {
391 /* Nothing to do when done with reading the include tag.
392  * Instead, the handling should be deferred until the EOF of current buffer -- see below */
393 }
394
395 /** @brief When reaching EOF, check whether we are in an include tag, and behave accordingly if yes
396  *
397  * This function is called automatically by sedding the parser in tools/cmake/MaintainerMode.cmake
398  * Every FAIL on "Premature EOF" is preceded by a call to this function, which role is to restore the
399  * previous buffer if we reached the EOF /of an include file/. Its return code is used to avoid the
400  * error message in that case.
401  *
402  * Yeah, that's terribly hackish, but it works. A better solution should be dealed with in flexml
403  * directly: a command line flag could instruct it to do the correct thing when the include directive is encountered
404  * on a line. One day maybe, if the maya allow it.
405  */
406 int ETag_surfxml_include_state()
407 {
408   fflush(nullptr);
409   XBT_DEBUG("ETag_surfxml_include_state '%s'",A_surfxml_include_file);
410
411   if (surf_input_buffer_stack.empty()) // nope, that's a true premature EOF. Let the parser die verbosely.
412     return 0;
413
414   // Yeah, we were in an <include> Restore state and proceed.
415   fclose(surf_file_to_parse);
416   surf_file_to_parse_stack.pop_back();
417   surf_parse_pop_buffer_state();
418   surf_input_buffer_stack.pop_back();
419
420   // Restore the filename for error messages
421   surf_parsed_filename_stack.pop_back();
422
423   return 1;
424 }
425
426 /* Stag and Etag parse functions */
427
428 void STag_surfxml_platform() {
429   XBT_ATTRIB_UNUSED double version = surf_parse_get_double(A_surfxml_platform_version);
430
431   xbt_assert((version >= 1.0), "******* BIG FAT WARNING *********\n "
432       "You're using an ancient XML file.\n"
433       "Since SimGrid 3.1, units are Bytes, Flops, and seconds "
434       "instead of MBytes, MFlops and seconds.\n"
435
436       "Use simgrid_update_xml to update your file automatically. "
437       "This program is installed automatically with SimGrid, or "
438       "available in the tools/ directory of the source archive.\n"
439
440       "Please check also out the SURF section of the ChangeLog for "
441       "the 3.1 version for more information. \n"
442
443       "Last, do not forget to also update your values for "
444       "the calls to MSG_task_create (if any).");
445   xbt_assert((version >= 3.0), "******* BIG FAT WARNING *********\n "
446       "You're using an old XML file.\n"
447       "Use simgrid_update_xml to update your file automatically. "
448       "This program is installed automatically with SimGrid, or "
449       "available in the tools/ directory of the source archive.");
450   xbt_assert((version >= 4.0),
451              "******* FILE %s IS TOO OLD (v:%.1f) *********\n "
452              "Changes introduced in SimGrid 3.13:\n"
453              "  - 'power' attribute of hosts (and others) got renamed to 'speed'.\n"
454              "  - In <trace_connect>, attribute kind=\"POWER\" is now kind=\"SPEED\".\n"
455              "  - DOCTYPE now point to the rignt URL: http://simgrid.gforge.inria.fr/simgrid/simgrid.dtd\n"
456              "  - speed, bandwidth and latency attributes now MUST have an explicit unit (f, Bps, s by default)"
457              "\n\n"
458              "Use simgrid_update_xml to update your file automatically. "
459              "This program is installed automatically with SimGrid, or "
460              "available in the tools/ directory of the source archive.",
461              surf_parsed_filename(), version);
462   if (version < 4.1) {
463     XBT_INFO("You're using a v%.1f XML file (%s) while the current standard is v4.1 "
464              "That's fine, the new version is backward compatible. \n\n"
465              "Use simgrid_update_xml to update your file automatically. "
466              "This program is installed automatically with SimGrid, or "
467              "available in the tools/ directory of the source archive.",
468              version, surf_parsed_filename());
469   }
470   xbt_assert(version <= 4.1, "******* FILE %s COMES FROM THE FUTURE (v:%.1f) *********\n "
471                              "The most recent formalism that this version of SimGrid understands is v4.1.\n"
472                              "Please update your code, or use another, more adapted, file.",
473              surf_parsed_filename(), version);
474
475   sg_platf_begin();
476 }
477 void ETag_surfxml_platform(){
478   sg_platf_end();
479 }
480
481 void STag_surfxml_host(){
482   ZONE_TAG = 0;
483   xbt_assert(current_property_set == nullptr, "Someone forgot to reset the property set to nullptr in its closing tag (or XML malformed)");
484 }
485
486 void STag_surfxml_prop()
487 {
488   if (ZONE_TAG) { // We need to retrieve the most recently opened zone
489     XBT_DEBUG("Set zone property %s -> %s", A_surfxml_prop_id, A_surfxml_prop_value);
490     simgrid::s4u::NetZone* netzone = simgrid::s4u::Engine::getInstance()->getNetzoneByNameOrNull(A_surfxml_zone_id);
491
492     netzone->setProperty(A_surfxml_prop_id, A_surfxml_prop_value);
493   } else {
494     if (not current_property_set)
495       current_property_set = new std::map<std::string, std::string>; // Maybe, it should raise an error
496     current_property_set->insert({A_surfxml_prop_id, A_surfxml_prop_value});
497     XBT_DEBUG("add prop %s=%s into current property set %p", A_surfxml_prop_id, A_surfxml_prop_value,
498               current_property_set);
499   }
500 }
501
502 void ETag_surfxml_host()    {
503   s_sg_platf_host_cbarg_t host;
504   memset(&host,0,sizeof(host));
505
506   host.properties = current_property_set;
507   current_property_set = nullptr;
508
509   host.id = A_surfxml_host_id;
510
511   host.speed_per_pstate = surf_parse_get_all_speeds(A_surfxml_host_speed, "speed of host", host.id);
512
513   XBT_DEBUG("pstate: %s", A_surfxml_host_pstate);
514   host.core_amount = surf_parse_get_int(A_surfxml_host_core);
515   host.speed_trace = A_surfxml_host_availability___file[0] ? tmgr_trace_new_from_file(A_surfxml_host_availability___file) : nullptr;
516   host.state_trace = A_surfxml_host_state___file[0] ? tmgr_trace_new_from_file(A_surfxml_host_state___file) : nullptr;
517   host.pstate      = surf_parse_get_int(A_surfxml_host_pstate);
518   host.coord       = A_surfxml_host_coordinates;
519
520   sg_platf_new_host(&host);
521 }
522
523 void STag_surfxml_host___link(){
524   XBT_DEBUG("Create a Host_link for %s",A_surfxml_host___link_id);
525   HostLinkCreationArgs host_link;
526
527   host_link.id        = A_surfxml_host___link_id;
528   host_link.link_up   = A_surfxml_host___link_up;
529   host_link.link_down = A_surfxml_host___link_down;
530   sg_platf_new_hostlink(&host_link);
531 }
532
533 void STag_surfxml_router(){
534   sg_platf_new_router(A_surfxml_router_id, A_surfxml_router_coordinates);
535 }
536
537 void ETag_surfxml_cluster(){
538   ClusterCreationArgs cluster;
539   cluster.properties   = current_property_set;
540   current_property_set = nullptr;
541
542   cluster.id          = A_surfxml_cluster_id;
543   cluster.prefix      = A_surfxml_cluster_prefix;
544   cluster.suffix      = A_surfxml_cluster_suffix;
545   cluster.radicals    = explodesRadical(A_surfxml_cluster_radical);
546   cluster.speeds      = surf_parse_get_all_speeds(A_surfxml_cluster_speed, "speed of cluster", cluster.id);
547   cluster.core_amount = surf_parse_get_int(A_surfxml_cluster_core);
548   cluster.bw          = surf_parse_get_bandwidth(A_surfxml_cluster_bw, "bw of cluster", cluster.id);
549   cluster.lat         = surf_parse_get_time(A_surfxml_cluster_lat, "lat of cluster", cluster.id);
550   if(strcmp(A_surfxml_cluster_bb___bw,""))
551     cluster.bb_bw = surf_parse_get_bandwidth(A_surfxml_cluster_bb___bw, "bb_bw of cluster", cluster.id);
552   if(strcmp(A_surfxml_cluster_bb___lat,""))
553     cluster.bb_lat = surf_parse_get_time(A_surfxml_cluster_bb___lat, "bb_lat of cluster", cluster.id);
554   if(strcmp(A_surfxml_cluster_limiter___link,""))
555     cluster.limiter_link = surf_parse_get_bandwidth(A_surfxml_cluster_limiter___link, "limiter_link of cluster", cluster.id);
556   if(strcmp(A_surfxml_cluster_loopback___bw,""))
557     cluster.loopback_bw = surf_parse_get_bandwidth(A_surfxml_cluster_loopback___bw, "loopback_bw of cluster", cluster.id);
558   if(strcmp(A_surfxml_cluster_loopback___lat,""))
559     cluster.loopback_lat = surf_parse_get_time(A_surfxml_cluster_loopback___lat, "loopback_lat of cluster", cluster.id);
560
561   switch(AX_surfxml_cluster_topology){
562   case A_surfxml_cluster_topology_FLAT:
563     cluster.topology= SURF_CLUSTER_FLAT ;
564     break;
565   case A_surfxml_cluster_topology_TORUS:
566     cluster.topology= SURF_CLUSTER_TORUS ;
567     break;
568   case A_surfxml_cluster_topology_FAT___TREE:
569     cluster.topology = SURF_CLUSTER_FAT_TREE;
570     break;
571   case A_surfxml_cluster_topology_DRAGONFLY:
572     cluster.topology= SURF_CLUSTER_DRAGONFLY ;
573     break;
574   default:
575     surf_parse_error(std::string("Invalid cluster topology for cluster ") + cluster.id);
576     break;
577   }
578   cluster.topo_parameters = A_surfxml_cluster_topo___parameters;
579   cluster.router_id = A_surfxml_cluster_router___id;
580
581   switch (AX_surfxml_cluster_sharing___policy) {
582   case A_surfxml_cluster_sharing___policy_SHARED:
583     cluster.sharing_policy = SURF_LINK_SHARED;
584     break;
585   case A_surfxml_cluster_sharing___policy_FULLDUPLEX:
586     cluster.sharing_policy = SURF_LINK_FULLDUPLEX;
587     break;
588   case A_surfxml_cluster_sharing___policy_FATPIPE:
589     cluster.sharing_policy = SURF_LINK_FATPIPE;
590     break;
591   default:
592     surf_parse_error(std::string("Invalid cluster sharing policy for cluster ") + cluster.id);
593     break;
594   }
595   switch (AX_surfxml_cluster_bb___sharing___policy) {
596   case A_surfxml_cluster_bb___sharing___policy_FATPIPE:
597     cluster.bb_sharing_policy = SURF_LINK_FATPIPE;
598     break;
599   case A_surfxml_cluster_bb___sharing___policy_SHARED:
600     cluster.bb_sharing_policy = SURF_LINK_SHARED;
601     break;
602   default:
603     surf_parse_error(std::string("Invalid bb sharing policy in cluster ") + cluster.id);
604     break;
605   }
606
607   sg_platf_new_cluster(&cluster);
608 }
609
610 void STag_surfxml_cluster(){
611   ZONE_TAG = 0;
612   parse_after_config();
613   xbt_assert(current_property_set == nullptr, "Someone forgot to reset the property set to nullptr in its closing tag (or XML malformed)");
614 }
615
616 void STag_surfxml_cabinet(){
617   parse_after_config();
618   CabinetCreationArgs cabinet;
619   cabinet.id      = A_surfxml_cabinet_id;
620   cabinet.prefix  = A_surfxml_cabinet_prefix;
621   cabinet.suffix  = A_surfxml_cabinet_suffix;
622   cabinet.speed    = surf_parse_get_speed(A_surfxml_cabinet_speed, "speed of cabinet", cabinet.id.c_str());
623   cabinet.bw       = surf_parse_get_bandwidth(A_surfxml_cabinet_bw, "bw of cabinet", cabinet.id.c_str());
624   cabinet.lat      = surf_parse_get_time(A_surfxml_cabinet_lat, "lat of cabinet", cabinet.id.c_str());
625   cabinet.radicals = explodesRadical(A_surfxml_cabinet_radical);
626
627   sg_platf_new_cabinet(&cabinet);
628 }
629
630 void STag_surfxml_peer(){
631   parse_after_config();
632   PeerCreationArgs peer;
633
634   peer.id          = std::string(A_surfxml_peer_id);
635   peer.speed       = surf_parse_get_speed(A_surfxml_peer_speed, "speed of peer", peer.id.c_str());
636   peer.bw_in       = surf_parse_get_bandwidth(A_surfxml_peer_bw___in, "bw_in of peer", peer.id.c_str());
637   peer.bw_out      = surf_parse_get_bandwidth(A_surfxml_peer_bw___out, "bw_out of peer", peer.id.c_str());
638   peer.coord       = A_surfxml_peer_coordinates;
639   peer.speed_trace = A_surfxml_peer_availability___file[0] ? tmgr_trace_new_from_file(A_surfxml_peer_availability___file) : nullptr;
640   peer.state_trace = A_surfxml_peer_state___file[0] ? tmgr_trace_new_from_file(A_surfxml_peer_state___file) : nullptr;
641
642   if (A_surfxml_peer_lat[0] != '\0')
643     XBT_WARN("The latency parameter in <peer> is now deprecated. Use the z coordinate instead of '%s'.",
644              A_surfxml_peer_lat);
645
646   sg_platf_new_peer(&peer);
647 }
648
649 void STag_surfxml_link(){
650   ZONE_TAG = 0;
651   xbt_assert(current_property_set == nullptr, "Someone forgot to reset the property set to nullptr in its closing tag (or XML malformed)");
652 }
653
654 void ETag_surfxml_link(){
655   LinkCreationArgs link;
656
657   link.properties          = current_property_set;
658   current_property_set     = nullptr;
659
660   link.id                  = std::string(A_surfxml_link_id);
661   link.bandwidth           = surf_parse_get_bandwidth(A_surfxml_link_bandwidth, "bandwidth of link", link.id.c_str());
662   link.bandwidth_trace     = A_surfxml_link_bandwidth___file[0] ? tmgr_trace_new_from_file(A_surfxml_link_bandwidth___file) : nullptr;
663   link.latency             = surf_parse_get_time(A_surfxml_link_latency, "latency of link", link.id.c_str());
664   link.latency_trace       = A_surfxml_link_latency___file[0] ? tmgr_trace_new_from_file(A_surfxml_link_latency___file) : nullptr;
665   link.state_trace         = A_surfxml_link_state___file[0] ? tmgr_trace_new_from_file(A_surfxml_link_state___file):nullptr;
666
667   switch (A_surfxml_link_sharing___policy) {
668   case A_surfxml_link_sharing___policy_SHARED:
669     link.policy = SURF_LINK_SHARED;
670     break;
671   case A_surfxml_link_sharing___policy_FATPIPE:
672      link.policy = SURF_LINK_FATPIPE;
673      break;
674   case A_surfxml_link_sharing___policy_FULLDUPLEX:
675      link.policy = SURF_LINK_FULLDUPLEX;
676      break;
677   default:
678     surf_parse_error(std::string("Invalid sharing policy in link ") + link.id);
679     break;
680   }
681
682   sg_platf_new_link(&link);
683 }
684
685 void STag_surfxml_link___ctn()
686 {
687   simgrid::surf::LinkImpl* link = nullptr;
688   switch (A_surfxml_link___ctn_direction) {
689   case AU_surfxml_link___ctn_direction:
690   case A_surfxml_link___ctn_direction_NONE:
691     link = simgrid::surf::LinkImpl::byName(A_surfxml_link___ctn_id);
692     break;
693   case A_surfxml_link___ctn_direction_UP:
694     link = simgrid::surf::LinkImpl::byName(std::string(A_surfxml_link___ctn_id) + "_UP");
695     break;
696   case A_surfxml_link___ctn_direction_DOWN:
697     link = simgrid::surf::LinkImpl::byName(std::string(A_surfxml_link___ctn_id) + "_DOWN");
698     break;
699   default:
700     surf_parse_error(std::string("Invalid direction for link ") + A_surfxml_link___ctn_id);
701     break;
702   }
703
704   const char* dirname = "";
705   switch (A_surfxml_link___ctn_direction) {
706     case A_surfxml_link___ctn_direction_UP:
707       dirname = " (upward)";
708       break;
709     case A_surfxml_link___ctn_direction_DOWN:
710       dirname = " (downward)";
711       break;
712     default:
713       dirname = "";
714   }
715   surf_parse_assert(link != nullptr, std::string("No such link: '") + A_surfxml_link___ctn_id + "'" + dirname);
716   parsed_link_list.push_back(link);
717 }
718
719 void ETag_surfxml_backbone(){
720   LinkCreationArgs link;
721
722   link.properties = nullptr;
723   link.id = std::string(A_surfxml_backbone_id);
724   link.bandwidth = surf_parse_get_bandwidth(A_surfxml_backbone_bandwidth, "bandwidth of backbone", link.id.c_str());
725   link.latency = surf_parse_get_time(A_surfxml_backbone_latency, "latency of backbone", link.id.c_str());
726   link.policy = SURF_LINK_SHARED;
727
728   sg_platf_new_link(&link);
729   routing_cluster_add_backbone(simgrid::surf::LinkImpl::byName(A_surfxml_backbone_id));
730 }
731
732 void STag_surfxml_route(){
733   surf_parse_assert_netpoint(A_surfxml_route_src, "Route src='", "' does name a node.");
734   surf_parse_assert_netpoint(A_surfxml_route_dst, "Route dst='", "' does name a node.");
735 }
736
737 void STag_surfxml_ASroute(){
738   surf_parse_assert_netpoint(A_surfxml_ASroute_src, "ASroute src='", "' does name a node.");
739   surf_parse_assert_netpoint(A_surfxml_ASroute_dst, "ASroute dst='", "' does name a node.");
740
741   surf_parse_assert_netpoint(A_surfxml_ASroute_gw___src, "ASroute gw_src='", "' does name a node.");
742   surf_parse_assert_netpoint(A_surfxml_ASroute_gw___dst, "ASroute gw_dst='", "' does name a node.");
743 }
744 void STag_surfxml_zoneRoute(){
745   surf_parse_assert_netpoint(A_surfxml_zoneRoute_src, "zoneRoute src='", "' does name a node.");
746   surf_parse_assert_netpoint(A_surfxml_zoneRoute_dst, "zoneRoute dst='", "' does name a node.");
747   surf_parse_assert_netpoint(A_surfxml_zoneRoute_gw___src, "zoneRoute gw_src='", "' does name a node.");
748   surf_parse_assert_netpoint(A_surfxml_zoneRoute_gw___dst, "zoneRoute gw_dst='", "' does name a node.");
749 }
750
751 void STag_surfxml_bypassRoute(){
752   surf_parse_assert_netpoint(A_surfxml_bypassRoute_src, "bypassRoute src='", "' does name a node.");
753   surf_parse_assert_netpoint(A_surfxml_bypassRoute_dst, "bypassRoute dst='", "' does name a node.");
754 }
755
756 void STag_surfxml_bypassASroute(){
757   surf_parse_assert_netpoint(A_surfxml_bypassASroute_src, "bypassASroute src='", "' does name a node.");
758   surf_parse_assert_netpoint(A_surfxml_bypassASroute_dst, "bypassASroute dst='", "' does name a node.");
759   surf_parse_assert_netpoint(A_surfxml_bypassASroute_gw___src, "bypassASroute gw_src='", "' does name a node.");
760   surf_parse_assert_netpoint(A_surfxml_bypassASroute_gw___dst, "bypassASroute gw_dst='", "' does name a node.");
761 }
762 void STag_surfxml_bypassZoneRoute(){
763   surf_parse_assert_netpoint(A_surfxml_bypassZoneRoute_src, "bypassZoneRoute src='", "' does name a node.");
764   surf_parse_assert_netpoint(A_surfxml_bypassZoneRoute_dst, "bypassZoneRoute dst='", "' does name a node.");
765   surf_parse_assert_netpoint(A_surfxml_bypassZoneRoute_gw___src, "bypassZoneRoute gw_src='", "' does name a node.");
766   surf_parse_assert_netpoint(A_surfxml_bypassZoneRoute_gw___dst, "bypassZoneRoute gw_dst='", "' does name a node.");
767 }
768
769 void ETag_surfxml_route(){
770   s_sg_platf_route_cbarg_t route;
771   memset(&route,0,sizeof(route));
772
773   route.src         = sg_netpoint_by_name_or_null(A_surfxml_route_src); // tested to not be nullptr in start tag
774   route.dst         = sg_netpoint_by_name_or_null(A_surfxml_route_dst); // tested to not be nullptr in start tag
775   route.gw_src    = nullptr;
776   route.gw_dst    = nullptr;
777   route.link_list   = new std::vector<simgrid::surf::LinkImpl*>();
778   route.symmetrical = (A_surfxml_route_symmetrical == A_surfxml_route_symmetrical_YES);
779
780   for (auto const& link : parsed_link_list)
781     route.link_list->push_back(link);
782   parsed_link_list.clear();
783
784   sg_platf_new_route(&route);
785   delete route.link_list;
786 }
787
788 void ETag_surfxml_ASroute()
789 {
790   AX_surfxml_zoneRoute_src = AX_surfxml_ASroute_src;
791   AX_surfxml_zoneRoute_dst = AX_surfxml_ASroute_dst;
792   AX_surfxml_zoneRoute_gw___src = AX_surfxml_ASroute_gw___src;
793   AX_surfxml_zoneRoute_gw___dst = AX_surfxml_ASroute_gw___dst;
794   AX_surfxml_zoneRoute_symmetrical = (AT_surfxml_zoneRoute_symmetrical)AX_surfxml_ASroute_symmetrical;
795   ETag_surfxml_zoneRoute();
796 }
797 void ETag_surfxml_zoneRoute()
798 {
799   s_sg_platf_route_cbarg_t ASroute;
800   memset(&ASroute,0,sizeof(ASroute));
801
802   ASroute.src = sg_netpoint_by_name_or_null(A_surfxml_zoneRoute_src); // tested to not be nullptr in start tag
803   ASroute.dst = sg_netpoint_by_name_or_null(A_surfxml_zoneRoute_dst); // tested to not be nullptr in start tag
804
805   ASroute.gw_src = sg_netpoint_by_name_or_null(A_surfxml_zoneRoute_gw___src); // tested to not be nullptr in start tag
806   ASroute.gw_dst = sg_netpoint_by_name_or_null(A_surfxml_zoneRoute_gw___dst); // tested to not be nullptr in start tag
807
808   ASroute.link_list = new std::vector<simgrid::surf::LinkImpl*>();
809
810   for (auto const& link : parsed_link_list)
811     ASroute.link_list->push_back(link);
812   parsed_link_list.clear();
813
814   switch (A_surfxml_zoneRoute_symmetrical) {
815   case AU_surfxml_zoneRoute_symmetrical:
816   case A_surfxml_zoneRoute_symmetrical_YES:
817     ASroute.symmetrical = true;
818     break;
819   case A_surfxml_zoneRoute_symmetrical_NO:
820     ASroute.symmetrical = false;
821     break;
822   default:
823     THROW_IMPOSSIBLE;
824   }
825
826   sg_platf_new_route(&ASroute);
827   delete ASroute.link_list;
828 }
829
830 void ETag_surfxml_bypassRoute(){
831   s_sg_platf_route_cbarg_t route;
832   memset(&route,0,sizeof(route));
833
834   route.src         = sg_netpoint_by_name_or_null(A_surfxml_bypassRoute_src); // tested to not be nullptr in start tag
835   route.dst         = sg_netpoint_by_name_or_null(A_surfxml_bypassRoute_dst); // tested to not be nullptr in start tag
836   route.gw_src = nullptr;
837   route.gw_dst = nullptr;
838   route.symmetrical = false;
839   route.link_list   = new std::vector<simgrid::surf::LinkImpl*>();
840
841   for (auto const& link : parsed_link_list)
842     route.link_list->push_back(link);
843   parsed_link_list.clear();
844
845   sg_platf_new_bypassRoute(&route);
846   delete route.link_list;
847 }
848
849 void ETag_surfxml_bypassASroute()
850 {
851   AX_surfxml_bypassZoneRoute_src = AX_surfxml_bypassASroute_src;
852   AX_surfxml_bypassZoneRoute_dst = AX_surfxml_bypassASroute_dst;
853   AX_surfxml_bypassZoneRoute_gw___src = AX_surfxml_bypassASroute_gw___src;
854   AX_surfxml_bypassZoneRoute_gw___dst = AX_surfxml_bypassASroute_gw___dst;
855   ETag_surfxml_bypassZoneRoute();
856 }
857 void ETag_surfxml_bypassZoneRoute()
858 {
859   s_sg_platf_route_cbarg_t ASroute;
860   memset(&ASroute,0,sizeof(ASroute));
861
862   ASroute.src         = sg_netpoint_by_name_or_null(A_surfxml_bypassZoneRoute_src);
863   ASroute.dst         = sg_netpoint_by_name_or_null(A_surfxml_bypassZoneRoute_dst);
864   ASroute.link_list   = new std::vector<simgrid::surf::LinkImpl*>();
865   for (auto const& link : parsed_link_list)
866     ASroute.link_list->push_back(link);
867   parsed_link_list.clear();
868
869   ASroute.symmetrical = false;
870
871   ASroute.gw_src = sg_netpoint_by_name_or_null(A_surfxml_bypassZoneRoute_gw___src);
872   ASroute.gw_dst = sg_netpoint_by_name_or_null(A_surfxml_bypassZoneRoute_gw___dst);
873
874   sg_platf_new_bypassRoute(&ASroute);
875   delete ASroute.link_list;
876 }
877
878 void ETag_surfxml_trace(){
879   TraceCreationArgs trace;
880
881   trace.id = A_surfxml_trace_id;
882   trace.file = A_surfxml_trace_file;
883   trace.periodicity = surf_parse_get_double(A_surfxml_trace_periodicity);
884   trace.pc_data = surfxml_pcdata;
885
886   sg_platf_new_trace(&trace);
887 }
888
889 void STag_surfxml_trace___connect()
890 {
891   parse_after_config();
892   TraceConnectCreationArgs trace_connect;
893
894   trace_connect.element = A_surfxml_trace___connect_element;
895   trace_connect.trace = A_surfxml_trace___connect_trace;
896
897   switch (A_surfxml_trace___connect_kind) {
898   case AU_surfxml_trace___connect_kind:
899   case A_surfxml_trace___connect_kind_SPEED:
900     trace_connect.kind =  SURF_TRACE_CONNECT_KIND_SPEED;
901     break;
902   case A_surfxml_trace___connect_kind_BANDWIDTH:
903     trace_connect.kind =  SURF_TRACE_CONNECT_KIND_BANDWIDTH;
904     break;
905   case A_surfxml_trace___connect_kind_HOST___AVAIL:
906     trace_connect.kind =  SURF_TRACE_CONNECT_KIND_HOST_AVAIL;
907     break;
908   case A_surfxml_trace___connect_kind_LATENCY:
909     trace_connect.kind =  SURF_TRACE_CONNECT_KIND_LATENCY;
910     break;
911   case A_surfxml_trace___connect_kind_LINK___AVAIL:
912     trace_connect.kind =  SURF_TRACE_CONNECT_KIND_LINK_AVAIL;
913     break;
914   default:
915     surf_parse_error("Invalid trace kind");
916     break;
917   }
918   sg_platf_trace_connect(&trace_connect);
919 }
920
921 void STag_surfxml_AS()
922 {
923   AX_surfxml_zone_id = AX_surfxml_AS_id;
924   AX_surfxml_zone_routing = (AT_surfxml_zone_routing)AX_surfxml_AS_routing;
925   STag_surfxml_zone();
926 }
927
928 void ETag_surfxml_AS()
929 {
930   ETag_surfxml_zone();
931 }
932
933 void STag_surfxml_zone()
934 {
935   parse_after_config();
936   ZONE_TAG                 = 1;
937   ZoneCreationArgs zone;
938   zone.id      = A_surfxml_zone_id;
939   zone.routing = static_cast<int>(A_surfxml_zone_routing);
940
941   sg_platf_new_Zone_begin(&zone);
942 }
943
944 void ETag_surfxml_zone()
945 {
946   sg_platf_new_Zone_seal();
947 }
948
949 void STag_surfxml_config()
950 {
951   ZONE_TAG = 0;
952   xbt_assert(current_property_set == nullptr,
953              "Someone forgot to reset the property set to nullptr in its closing tag (or XML malformed)");
954   XBT_DEBUG("START configuration name = %s",A_surfxml_config_id);
955   if (_sg_cfg_init_status == 2) {
956     surf_parse_error("All <config> tags must be given before any platform elements (such as <zone>, <host>, <cluster>, "
957                      "<link>, etc).");
958   }
959 }
960
961 void ETag_surfxml_config()
962 {
963   for (auto const& elm : *current_property_set) {
964     if (xbt_cfg_is_default_value(elm.first.c_str())) {
965       std::string cfg = elm.first + ":" + elm.second;
966       xbt_cfg_set_parse(cfg.c_str());
967     } else
968       XBT_INFO("The custom configuration '%s' is already defined by user!", elm.first.c_str());
969   }
970   XBT_DEBUG("End configuration name = %s",A_surfxml_config_id);
971
972   delete current_property_set;
973   current_property_set = nullptr;
974 }
975
976 static int argc;
977 static char **argv;
978
979 void STag_surfxml_process()
980 {
981   AX_surfxml_actor_function = AX_surfxml_process_function;
982   STag_surfxml_actor();
983 }
984
985 void STag_surfxml_actor()
986 {
987   ZONE_TAG  = 0;
988   argc    = 1;
989   argv    = xbt_new(char *, 1);
990   argv[0] = xbt_strdup(A_surfxml_actor_function);
991   xbt_assert(current_property_set == nullptr, "Someone forgot to reset the property set to nullptr in its closing tag (or XML malformed)");
992 }
993
994 void ETag_surfxml_process()
995 {
996   AX_surfxml_actor_host = AX_surfxml_process_host;
997   AX_surfxml_actor_function = AX_surfxml_process_function;
998   AX_surfxml_actor_start___time = AX_surfxml_process_start___time;
999   AX_surfxml_actor_kill___time = AX_surfxml_process_kill___time;
1000   AX_surfxml_actor_on___failure = (AT_surfxml_actor_on___failure)AX_surfxml_process_on___failure;
1001   ETag_surfxml_actor();
1002 }
1003
1004 void ETag_surfxml_actor()
1005 {
1006   s_sg_platf_process_cbarg_t actor;
1007   memset(&actor,0,sizeof(actor));
1008
1009   actor.properties     = current_property_set;
1010   current_property_set = nullptr;
1011
1012   actor.argc       = argc;
1013   actor.argv       = (const char **)argv;
1014   actor.host       = A_surfxml_actor_host;
1015   actor.function   = A_surfxml_actor_function;
1016   actor.start_time = surf_parse_get_double(A_surfxml_actor_start___time);
1017   actor.kill_time  = surf_parse_get_double(A_surfxml_actor_kill___time);
1018
1019   switch (A_surfxml_actor_on___failure) {
1020   case AU_surfxml_actor_on___failure:
1021   case A_surfxml_actor_on___failure_DIE:
1022     actor.on_failure =  SURF_ACTOR_ON_FAILURE_DIE;
1023     break;
1024   case A_surfxml_actor_on___failure_RESTART:
1025     actor.on_failure =  SURF_ACTOR_ON_FAILURE_RESTART;
1026     break;
1027   default:
1028     surf_parse_error("Invalid on failure behavior");
1029     break;
1030   }
1031
1032   sg_platf_new_process(&actor);
1033
1034   for (int i = 0; i != argc; ++i)
1035     xbt_free(argv[i]);
1036   xbt_free(argv);
1037   argv = nullptr;
1038 }
1039
1040 void STag_surfxml_argument(){
1041   argc++;
1042   argv = (char**)xbt_realloc(argv, (argc) * sizeof(char **));
1043   argv[(argc) - 1] = xbt_strdup(A_surfxml_argument_value);
1044 }
1045
1046 void STag_surfxml_model___prop(){
1047   if (not current_model_property_set)
1048     current_model_property_set = new std::map<std::string, std::string>();
1049
1050   current_model_property_set->insert({A_surfxml_model___prop_id, A_surfxml_model___prop_value});
1051 }
1052
1053 void ETag_surfxml_prop(){/* Nothing to do */}
1054 void STag_surfxml_random(){/* Nothing to do */}
1055 void ETag_surfxml_random(){/* Nothing to do */}
1056 void ETag_surfxml_trace___connect(){/* Nothing to do */}
1057 void STag_surfxml_trace(){parse_after_config();}
1058 void ETag_surfxml_router(){/*Nothing to do*/}
1059 void ETag_surfxml_host___link(){/* Nothing to do */}
1060 void ETag_surfxml_cabinet(){/* Nothing to do */}
1061 void ETag_surfxml_peer(){/* Nothing to do */}
1062 void STag_surfxml_backbone(){/* Nothing to do */}
1063 void ETag_surfxml_link___ctn(){/* Nothing to do */}
1064 void ETag_surfxml_argument(){/* Nothing to do */}
1065 void ETag_surfxml_model___prop(){/* Nothing to do */}
1066
1067 /* Open and Close parse file */
1068 void surf_parse_open(const char *file)
1069 {
1070   xbt_assert(file, "Cannot parse the nullptr file. Bypassing the parser is strongly deprecated nowadays.");
1071
1072   surf_parsed_filename_stack.emplace_back(file);
1073   std::string dir      = simgrid::xbt::Path(file).getDirname();
1074   surf_path.push_back(dir);
1075
1076   surf_file_to_parse = surf_fopen(file, "r");
1077   if (surf_file_to_parse == nullptr)
1078     xbt_die("Unable to open '%s'\n", file);
1079   surf_input_buffer = surf_parse__create_buffer(surf_file_to_parse, YY_BUF_SIZE);
1080   surf_parse__switch_to_buffer(surf_input_buffer);
1081   surf_parse_lineno = 1;
1082 }
1083
1084 void surf_parse_close()
1085 {
1086   if (surf_parsed_filename()) {
1087     surf_path.pop_back();
1088   }
1089
1090   surf_parsed_filename_stack.pop_back();
1091
1092   if (surf_file_to_parse) {
1093     surf_parse__delete_buffer(surf_input_buffer);
1094     fclose(surf_file_to_parse);
1095     surf_file_to_parse = nullptr; //Must be reset for Bypass
1096   }
1097 }
1098
1099 /* Call the lexer to parse the currently opened file */
1100 int surf_parse()
1101 {
1102   return surf_parse_lex();
1103 }
1104 }