Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
a84649f4b225437ba494550b0b3e887ee177435d
[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.h"
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 char* surf_parsed_filename = nullptr; // to locate parse error messages
27
28 std::vector<simgrid::surf::LinkImpl*> parsed_link_list; /* temporary store of current list link of a route */
29
30 /*
31  * Helping functions
32  */
33 void surf_parse_assert(bool cond, std::string msg)
34 {
35   if (not cond) {
36     int lineno = surf_parse_lineno;
37     cleanup();
38     XBT_ERROR("Parse error at %s:%d: %s", surf_parsed_filename, lineno, msg.c_str());
39     surf_exit();
40     xbt_die("Exiting now");
41   }
42 }
43
44 void surf_parse_error(std::string msg)
45 {
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 void surf_parse_assert_netpoint(std::string hostname, std::string pre, std::string post)
54 {
55   if (sg_netpoint_by_name_or_null(hostname.c_str()) != nullptr) // found
56     return;
57
58   std::string msg = pre + hostname + post + " Existing netpoints: \n";
59
60   std::vector<simgrid::kernel::routing::NetPoint*> list;
61   simgrid::s4u::Engine::getInstance()->getNetpointList(&list);
62   std::sort(list.begin(), list.end(),
63       [](simgrid::kernel::routing::NetPoint* a, simgrid::kernel::routing::NetPoint* b) {
64       return a->name() < b->name();
65   });
66   bool first = true;
67   for (auto const& np : list) {
68     if (np->isNetZone())
69       continue;
70
71     if (not first)
72       msg += ",";
73     first = false;
74     msg += "'" + np->name() + "'";
75     if (msg.length() > 4096) {
76       msg.pop_back(); // remove trailing quote
77       msg += "...(list truncated)......";
78       break;
79     }
80   }
81   surf_parse_error(msg);
82 }
83
84 void surf_parse_warn(std::string msg)
85 {
86   XBT_WARN("%s:%d: %s", surf_parsed_filename, surf_parse_lineno, msg.c_str());
87 }
88
89 double surf_parse_get_double(std::string s)
90 {
91   try {
92     return std::stod(s);
93   } catch (std::invalid_argument& ia) {
94     surf_parse_error(s + " is not a double");
95     return -1;
96   }
97 }
98
99 int surf_parse_get_int(std::string s)
100 {
101   try {
102     return std::stoi(s);
103   } catch (std::invalid_argument& ia) {
104     surf_parse_error(s + " is not a double");
105     return -1;
106   }
107 }
108
109 /* Turn something like "1-4,6,9-11" into the vector {1,2,3,4,6,9,10,11} */
110 static std::vector<int>* explodesRadical(std::string radicals)
111 {
112   std::vector<int>* exploded = new std::vector<int>();
113
114   // Make all hosts
115   std::vector<std::string> radical_elements;
116   boost::split(radical_elements, radicals, boost::is_any_of(","));
117   for (auto const& group : radical_elements) {
118     std::vector<std::string> radical_ends;
119     boost::split(radical_ends, group, boost::is_any_of("-"));
120     int start = surf_parse_get_int(radical_ends.front());
121     int end   = 0;
122
123     switch (radical_ends.size()) {
124       case 1:
125         end = start;
126         break;
127       case 2:
128         end = surf_parse_get_int(radical_ends.back());
129         break;
130       default:
131         surf_parse_error(std::string("Malformed radical: ") + group);
132         break;
133     }
134     for (int i = start; i <= end; i++)
135       exploded->push_back(i);
136   }
137
138   return exploded;
139 }
140
141 struct unit_scale {
142   const char *unit;
143   double scale;
144 };
145
146 /* Note: field `unit' for the last element of parameter `units' should be nullptr. */
147 static double surf_parse_get_value_with_unit(const char* string, const unit_scale* units, const char* entity_kind,
148                                              std::string name, const char* error_msg, const char* default_unit)
149 {
150   char* ptr;
151   int i;
152   errno = 0;
153   double res   = strtod(string, &ptr);
154   if (errno == ERANGE)
155     surf_parse_error(std::string("value out of range: ") + string);
156   if (ptr == string)
157     surf_parse_error(std::string("cannot parse number:") + string);
158   if (ptr[0] == '\0') {
159     if (res == 0)
160       return res; // Ok, 0 can be unit-less
161
162     XBT_WARN("Deprecated unit-less value '%s' for %s %s. %s", string, entity_kind, name.c_str(), error_msg);
163     ptr = (char*)default_unit;
164   }
165   for (i = 0; units[i].unit != nullptr && strcmp(ptr, units[i].unit) != 0; i++);
166
167   if (units[i].unit != nullptr)
168     res *= units[i].scale;
169   else
170     surf_parse_error(std::string("unknown unit: ") + ptr);
171   return res;
172 }
173
174 double surf_parse_get_time(const char* string, const char* entity_kind, std::string name)
175 {
176   const unit_scale units[] = {{"w", 7 * 24 * 60 * 60},
177                               {"d", 24 * 60 * 60},
178                               {"h", 60 * 60},
179                               {"m", 60},
180                               {"s", 1.0},
181                               {"ms", 1e-3},
182                               {"us", 1e-6},
183                               {"ns", 1e-9},
184                               {"ps", 1e-12},
185                               {nullptr, 0}};
186   return surf_parse_get_value_with_unit(string, units, entity_kind, name,
187       "Append 's' to your time to get seconds", "s");
188 }
189
190 double surf_parse_get_size(const char* string, const char* entity_kind, std::string name)
191 {
192   const unit_scale units[] = {{"EiB", pow(1024, 6)},
193                               {"PiB", pow(1024, 5)},
194                               {"TiB", pow(1024, 4)},
195                               {"GiB", pow(1024, 3)},
196                               {"MiB", pow(1024, 2)},
197                               {"KiB", 1024},
198                               {"EB", 1e18},
199                               {"PB", 1e15},
200                               {"TB", 1e12},
201                               {"GB", 1e9},
202                               {"MB", 1e6},
203                               {"kB", 1e3},
204                               {"B", 1.0},
205                               {"Eib", 0.125 * pow(1024, 6)},
206                               {"Pib", 0.125 * pow(1024, 5)},
207                               {"Tib", 0.125 * pow(1024, 4)},
208                               {"Gib", 0.125 * pow(1024, 3)},
209                               {"Mib", 0.125 * pow(1024, 2)},
210                               {"Kib", 0.125 * 1024},
211                               {"Eb", 0.125 * 1e18},
212                               {"Pb", 0.125 * 1e15},
213                               {"Tb", 0.125 * 1e12},
214                               {"Gb", 0.125 * 1e9},
215                               {"Mb", 0.125 * 1e6},
216                               {"kb", 0.125 * 1e3},
217                               {"b", 0.125},
218                               {nullptr, 0}};
219   return surf_parse_get_value_with_unit(string, units, entity_kind, name,
220       "Append 'B' to get bytes (or 'b' for bits but 1B = 8b).", "B");
221 }
222
223 double surf_parse_get_bandwidth(const char* string, const char* entity_kind, std::string name)
224 {
225   const unit_scale units[] = {{"EiBps", pow(1024, 6)},
226                               {"PiBps", pow(1024, 5)},
227                               {"TiBps", pow(1024, 4)},
228                               {"GiBps", pow(1024, 3)},
229                               {"MiBps", pow(1024, 2)},
230                               {"KiBps", 1024},
231                               {"EBps", 1e18},
232                               {"PBps", 1e15},
233                               {"TBps", 1e12},
234                               {"GBps", 1e9},
235                               {"MBps", 1e6},
236                               {"kBps", 1e3},
237                               {"Bps", 1.0},
238                               {"Eibps", 0.125 * pow(1024, 6)},
239                               {"Pibps", 0.125 * pow(1024, 5)},
240                               {"Tibps", 0.125 * pow(1024, 4)},
241                               {"Gibps", 0.125 * pow(1024, 3)},
242                               {"Mibps", 0.125 * pow(1024, 2)},
243                               {"Kibps", 0.125 * 1024},
244                               {"Tbps", 0.125 * 1e12},
245                               {"Gbps", 0.125 * 1e9},
246                               {"Mbps", 0.125 * 1e6},
247                               {"kbps", 0.125 * 1e3},
248                               {"bps", 0.125},
249                               {nullptr, 0}};
250   return surf_parse_get_value_with_unit(string, units, entity_kind, name,
251       "Append 'Bps' to get bytes per second (or 'bps' for bits but 1Bps = 8bps)", "Bps");
252 }
253
254 double surf_parse_get_speed(const char* string, const char* entity_kind, std::string name)
255 {
256   const unit_scale units[] = {{"yottaflops", 1e24}, {"Yf", 1e24}, {"zettaflops", 1e21}, {"Zf", 1e21},
257                               {"exaflops", 1e18},   {"Ef", 1e18}, {"petaflops", 1e15},  {"Pf", 1e15},
258                               {"teraflops", 1e12},  {"Tf", 1e12}, {"gigaflops", 1e9},   {"Gf", 1e9},
259                               {"megaflops", 1e6},   {"Mf", 1e6},  {"kiloflops", 1e3},   {"kf", 1e3},
260                               {"flops", 1.0},       {"f", 1.0},   {nullptr, 0}};
261   return surf_parse_get_value_with_unit(string, units, entity_kind, name,
262       "Append 'f' or 'flops' to your speed to get flop per second", "f");
263 }
264
265 static std::vector<double> surf_parse_get_all_speeds(char* speeds, const char* entity_kind, std::string id)
266 {
267
268   std::vector<double> speed_per_pstate;
269
270   if (strchr(speeds, ',') == nullptr){
271     double speed = surf_parse_get_speed(speeds, entity_kind, id);
272     speed_per_pstate.push_back(speed);
273   } else {
274     std::vector<std::string> pstate_list;
275     boost::split(pstate_list, speeds, boost::is_any_of(","));
276     for (auto speed_str : pstate_list) {
277       boost::trim(speed_str);
278       double speed = surf_parse_get_speed(speed_str.c_str(), entity_kind, id);
279       speed_per_pstate.push_back(speed);
280       XBT_DEBUG("Speed value: %f", speed);
281     }
282   }
283   return speed_per_pstate;
284 }
285
286 /*
287  * All the callback lists that can be overridden anywhere.
288  * (this list should probably be reduced to the bare minimum to allow the models to work)
289  */
290
291 /* make sure these symbols are defined as strong ones in this file so that the linker can resolve them */
292
293 /* The default current property receiver. Setup in the corresponding opening callbacks. */
294 std::map<std::string, std::string>* current_property_set       = nullptr;
295 std::map<std::string, std::string>* current_model_property_set = nullptr;
296 int ZONE_TAG                            = 0; // Whether we just opened a zone tag (to see what to do with the properties)
297
298 YY_BUFFER_STATE surf_input_buffer;
299 FILE *surf_file_to_parse = nullptr;
300
301 /* Stuff relative to storage */
302 void STag_surfxml_storage()
303 {
304   ZONE_TAG = 0;
305   XBT_DEBUG("STag_surfxml_storage");
306   xbt_assert(current_property_set == nullptr, "Someone forgot to reset the property set to nullptr in its closing tag (or XML malformed)");
307 }
308
309 void ETag_surfxml_storage()
310 {
311   StorageCreationArgs storage;
312
313   storage.properties   = current_property_set;
314   current_property_set = nullptr;
315
316   storage.id           = A_surfxml_storage_id;
317   storage.type_id      = A_surfxml_storage_typeId;
318   storage.content      = A_surfxml_storage_content;
319   storage.attach       = A_surfxml_storage_attach;
320
321   sg_platf_new_storage(&storage);
322 }
323 void STag_surfxml_storage___type()
324 {
325   ZONE_TAG = 0;
326   XBT_DEBUG("STag_surfxml_storage___type");
327   xbt_assert(current_property_set == nullptr, "Someone forgot to reset the property set to nullptr in its closing tag (or XML malformed)");
328   xbt_assert(current_model_property_set == nullptr, "Someone forgot to reset the model property set to nullptr in its closing tag (or XML malformed)");
329 }
330 void ETag_surfxml_storage___type()
331 {
332   StorageTypeCreationArgs storage_type;
333
334   storage_type.properties = current_property_set;
335   current_property_set    = nullptr;
336
337   storage_type.model_properties = current_model_property_set;
338   current_model_property_set    = nullptr;
339
340   storage_type.content = A_surfxml_storage___type_content;
341   storage_type.id      = A_surfxml_storage___type_id;
342   storage_type.model   = A_surfxml_storage___type_model;
343   storage_type.size =
344       surf_parse_get_size(A_surfxml_storage___type_size, "size of storage type", storage_type.id.c_str());
345   sg_platf_new_storage_type(&storage_type);
346 }
347
348 void STag_surfxml_mount()
349 {
350   XBT_DEBUG("STag_surfxml_mount");
351 }
352
353 void ETag_surfxml_mount()
354 {
355   MountCreationArgs mount;
356
357   mount.name      = A_surfxml_mount_name;
358   mount.storageId = A_surfxml_mount_storageId;
359   sg_platf_new_mount(&mount);
360 }
361
362 /*
363  * Stuff relative to the <include> tag
364  */
365 static std::vector<YY_BUFFER_STATE> surf_input_buffer_stack;
366 static std::vector<FILE*> surf_file_to_parse_stack;
367 static std::vector<char*> surf_parsed_filename_stack;
368
369 void STag_surfxml_include()
370 {
371   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).");
372   parse_after_config();
373   XBT_DEBUG("STag_surfxml_include '%s'",A_surfxml_include_file);
374   surf_parsed_filename_stack.push_back(surf_parsed_filename); // save old file name
375   surf_parsed_filename = xbt_strdup(A_surfxml_include_file);
376
377   surf_file_to_parse_stack.push_back(surf_file_to_parse); // save old file descriptor
378
379   surf_file_to_parse = surf_fopen(A_surfxml_include_file, "r"); // read new file descriptor
380   xbt_assert((surf_file_to_parse), "Unable to open \"%s\"\n", A_surfxml_include_file);
381
382   surf_input_buffer_stack.push_back(surf_input_buffer);
383   surf_input_buffer = surf_parse__create_buffer(surf_file_to_parse, YY_BUF_SIZE);
384   surf_parse_push_buffer_state(surf_input_buffer);
385
386   fflush(nullptr);
387 }
388
389 void ETag_surfxml_include() {
390 /* Nothing to do when done with reading the include tag.
391  * Instead, the handling should be deferred until the EOF of current buffer -- see below */
392 }
393
394 /** @brief When reaching EOF, check whether we are in an include tag, and behave accordingly if yes
395  *
396  * This function is called automatically by sedding the parser in tools/cmake/MaintainerMode.cmake
397  * Every FAIL on "Premature EOF" is preceded by a call to this function, which role is to restore the
398  * previous buffer if we reached the EOF /of an include file/. Its return code is used to avoid the
399  * error message in that case.
400  *
401  * Yeah, that's terribly hackish, but it works. A better solution should be dealed with in flexml
402  * directly: a command line flag could instruct it to do the correct thing when the include directive is encountered
403  * on a line. One day maybe, if the maya allow it.
404  */
405 int ETag_surfxml_include_state()
406 {
407   fflush(nullptr);
408   XBT_DEBUG("ETag_surfxml_include_state '%s'",A_surfxml_include_file);
409
410   if (surf_input_buffer_stack.empty()) // nope, that's a true premature EOF. Let the parser die verbosely.
411     return 0;
412
413   // Yeah, we were in an <include> Restore state and proceed.
414   fclose(surf_file_to_parse);
415   surf_file_to_parse_stack.pop_back();
416   surf_parse_pop_buffer_state();
417   surf_input_buffer_stack.pop_back();
418
419   // Restore the filename for error messages
420   free(surf_parsed_filename);
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   }
823
824   sg_platf_new_route(&ASroute);
825   delete ASroute.link_list;
826 }
827
828 void ETag_surfxml_bypassRoute(){
829   s_sg_platf_route_cbarg_t route;
830   memset(&route,0,sizeof(route));
831
832   route.src         = sg_netpoint_by_name_or_null(A_surfxml_bypassRoute_src); // tested to not be nullptr in start tag
833   route.dst         = sg_netpoint_by_name_or_null(A_surfxml_bypassRoute_dst); // tested to not be nullptr in start tag
834   route.gw_src = nullptr;
835   route.gw_dst = nullptr;
836   route.symmetrical = false;
837   route.link_list   = new std::vector<simgrid::surf::LinkImpl*>();
838
839   for (auto const& link : parsed_link_list)
840     route.link_list->push_back(link);
841   parsed_link_list.clear();
842
843   sg_platf_new_bypassRoute(&route);
844   delete route.link_list;
845 }
846
847 void ETag_surfxml_bypassASroute()
848 {
849   AX_surfxml_bypassZoneRoute_src = AX_surfxml_bypassASroute_src;
850   AX_surfxml_bypassZoneRoute_dst = AX_surfxml_bypassASroute_dst;
851   AX_surfxml_bypassZoneRoute_gw___src = AX_surfxml_bypassASroute_gw___src;
852   AX_surfxml_bypassZoneRoute_gw___dst = AX_surfxml_bypassASroute_gw___dst;
853   ETag_surfxml_bypassZoneRoute();
854 }
855 void ETag_surfxml_bypassZoneRoute()
856 {
857   s_sg_platf_route_cbarg_t ASroute;
858   memset(&ASroute,0,sizeof(ASroute));
859
860   ASroute.src         = sg_netpoint_by_name_or_null(A_surfxml_bypassZoneRoute_src);
861   ASroute.dst         = sg_netpoint_by_name_or_null(A_surfxml_bypassZoneRoute_dst);
862   ASroute.link_list   = new std::vector<simgrid::surf::LinkImpl*>();
863   for (auto const& link : parsed_link_list)
864     ASroute.link_list->push_back(link);
865   parsed_link_list.clear();
866
867   ASroute.symmetrical = false;
868
869   ASroute.gw_src = sg_netpoint_by_name_or_null(A_surfxml_bypassZoneRoute_gw___src);
870   ASroute.gw_dst = sg_netpoint_by_name_or_null(A_surfxml_bypassZoneRoute_gw___dst);
871
872   sg_platf_new_bypassRoute(&ASroute);
873   delete ASroute.link_list;
874 }
875
876 void ETag_surfxml_trace(){
877   TraceCreationArgs trace;
878
879   trace.id = A_surfxml_trace_id;
880   trace.file = A_surfxml_trace_file;
881   trace.periodicity = surf_parse_get_double(A_surfxml_trace_periodicity);
882   trace.pc_data = surfxml_pcdata;
883
884   sg_platf_new_trace(&trace);
885 }
886
887 void STag_surfxml_trace___connect()
888 {
889   parse_after_config();
890   TraceConnectCreationArgs trace_connect;
891
892   trace_connect.element = A_surfxml_trace___connect_element;
893   trace_connect.trace = A_surfxml_trace___connect_trace;
894
895   switch (A_surfxml_trace___connect_kind) {
896   case AU_surfxml_trace___connect_kind:
897   case A_surfxml_trace___connect_kind_SPEED:
898     trace_connect.kind =  SURF_TRACE_CONNECT_KIND_SPEED;
899     break;
900   case A_surfxml_trace___connect_kind_BANDWIDTH:
901     trace_connect.kind =  SURF_TRACE_CONNECT_KIND_BANDWIDTH;
902     break;
903   case A_surfxml_trace___connect_kind_HOST___AVAIL:
904     trace_connect.kind =  SURF_TRACE_CONNECT_KIND_HOST_AVAIL;
905     break;
906   case A_surfxml_trace___connect_kind_LATENCY:
907     trace_connect.kind =  SURF_TRACE_CONNECT_KIND_LATENCY;
908     break;
909   case A_surfxml_trace___connect_kind_LINK___AVAIL:
910     trace_connect.kind =  SURF_TRACE_CONNECT_KIND_LINK_AVAIL;
911     break;
912   default:
913     surf_parse_error("Invalid trace kind");
914     break;
915   }
916   sg_platf_trace_connect(&trace_connect);
917 }
918
919 void STag_surfxml_AS()
920 {
921   AX_surfxml_zone_id = AX_surfxml_AS_id;
922   AX_surfxml_zone_routing = (AT_surfxml_zone_routing)AX_surfxml_AS_routing;
923   STag_surfxml_zone();
924 }
925
926 void ETag_surfxml_AS()
927 {
928   ETag_surfxml_zone();
929 }
930
931 void STag_surfxml_zone()
932 {
933   parse_after_config();
934   ZONE_TAG                 = 1;
935   ZoneCreationArgs zone;
936   zone.id      = A_surfxml_zone_id;
937   zone.routing = static_cast<int>(A_surfxml_zone_routing);
938
939   sg_platf_new_Zone_begin(&zone);
940 }
941
942 void ETag_surfxml_zone()
943 {
944   sg_platf_new_Zone_seal();
945 }
946
947 void STag_surfxml_config()
948 {
949   ZONE_TAG = 0;
950   xbt_assert(current_property_set == nullptr,
951              "Someone forgot to reset the property set to nullptr in its closing tag (or XML malformed)");
952   XBT_DEBUG("START configuration name = %s",A_surfxml_config_id);
953   if (_sg_cfg_init_status == 2) {
954     surf_parse_error("All <config> tags must be given before any platform elements (such as <zone>, <host>, <cluster>, "
955                      "<link>, etc).");
956   }
957 }
958
959 void ETag_surfxml_config()
960 {
961   for (auto const& elm : *current_property_set) {
962     if (xbt_cfg_is_default_value(elm.first.c_str())) {
963       std::string cfg = elm.first + ":" + elm.second;
964       xbt_cfg_set_parse(cfg.c_str());
965     } else
966       XBT_INFO("The custom configuration '%s' is already defined by user!", elm.first.c_str());
967   }
968   XBT_DEBUG("End configuration name = %s",A_surfxml_config_id);
969
970   delete current_property_set;
971   current_property_set = nullptr;
972 }
973
974 static int argc;
975 static char **argv;
976
977 void STag_surfxml_process()
978 {
979   AX_surfxml_actor_function = AX_surfxml_process_function;
980   STag_surfxml_actor();
981 }
982
983 void STag_surfxml_actor()
984 {
985   ZONE_TAG  = 0;
986   argc    = 1;
987   argv    = xbt_new(char *, 1);
988   argv[0] = xbt_strdup(A_surfxml_actor_function);
989   xbt_assert(current_property_set == nullptr, "Someone forgot to reset the property set to nullptr in its closing tag (or XML malformed)");
990 }
991
992 void ETag_surfxml_process()
993 {
994   AX_surfxml_actor_host = AX_surfxml_process_host;
995   AX_surfxml_actor_function = AX_surfxml_process_function;
996   AX_surfxml_actor_start___time = AX_surfxml_process_start___time;
997   AX_surfxml_actor_kill___time = AX_surfxml_process_kill___time;
998   AX_surfxml_actor_on___failure = (AT_surfxml_actor_on___failure)AX_surfxml_process_on___failure;
999   ETag_surfxml_actor();
1000 }
1001
1002 void ETag_surfxml_actor()
1003 {
1004   s_sg_platf_process_cbarg_t actor;
1005   memset(&actor,0,sizeof(actor));
1006
1007   actor.properties     = current_property_set;
1008   current_property_set = nullptr;
1009
1010   actor.argc       = argc;
1011   actor.argv       = (const char **)argv;
1012   actor.host       = A_surfxml_actor_host;
1013   actor.function   = A_surfxml_actor_function;
1014   actor.start_time = surf_parse_get_double(A_surfxml_actor_start___time);
1015   actor.kill_time  = surf_parse_get_double(A_surfxml_actor_kill___time);
1016
1017   switch (A_surfxml_actor_on___failure) {
1018   case AU_surfxml_actor_on___failure:
1019   case A_surfxml_actor_on___failure_DIE:
1020     actor.on_failure =  SURF_ACTOR_ON_FAILURE_DIE;
1021     break;
1022   case A_surfxml_actor_on___failure_RESTART:
1023     actor.on_failure =  SURF_ACTOR_ON_FAILURE_RESTART;
1024     break;
1025   default:
1026     surf_parse_error("Invalid on failure behavior");
1027     break;
1028   }
1029
1030   sg_platf_new_process(&actor);
1031
1032   for (int i = 0; i != argc; ++i)
1033     xbt_free(argv[i]);
1034   xbt_free(argv);
1035   argv = nullptr;
1036 }
1037
1038 void STag_surfxml_argument(){
1039   argc++;
1040   argv = (char**)xbt_realloc(argv, (argc) * sizeof(char **));
1041   argv[(argc) - 1] = xbt_strdup(A_surfxml_argument_value);
1042 }
1043
1044 void STag_surfxml_model___prop(){
1045   if (not current_model_property_set)
1046     current_model_property_set = new std::map<std::string, std::string>();
1047
1048   current_model_property_set->insert({A_surfxml_model___prop_id, A_surfxml_model___prop_value});
1049 }
1050
1051 void ETag_surfxml_prop(){/* Nothing to do */}
1052 void STag_surfxml_random(){/* Nothing to do */}
1053 void ETag_surfxml_random(){/* Nothing to do */}
1054 void ETag_surfxml_trace___connect(){/* Nothing to do */}
1055 void STag_surfxml_trace(){parse_after_config();}
1056 void ETag_surfxml_router(){/*Nothing to do*/}
1057 void ETag_surfxml_host___link(){/* Nothing to do */}
1058 void ETag_surfxml_cabinet(){/* Nothing to do */}
1059 void ETag_surfxml_peer(){/* Nothing to do */}
1060 void STag_surfxml_backbone(){/* Nothing to do */}
1061 void ETag_surfxml_link___ctn(){/* Nothing to do */}
1062 void ETag_surfxml_argument(){/* Nothing to do */}
1063 void ETag_surfxml_model___prop(){/* Nothing to do */}
1064
1065 /* Open and Close parse file */
1066 void surf_parse_open(const char *file)
1067 {
1068   xbt_assert(file, "Cannot parse the nullptr file. Bypassing the parser is strongly deprecated nowadays.");
1069
1070   surf_parsed_filename = xbt_strdup(file);
1071   char* dir            = xbt_dirname(file);
1072   surf_path.push_back(std::string(dir));
1073   xbt_free(dir);
1074
1075   surf_file_to_parse = surf_fopen(file, "r");
1076   if (surf_file_to_parse == nullptr)
1077     xbt_die("Unable to open '%s'\n", file);
1078   surf_input_buffer = surf_parse__create_buffer(surf_file_to_parse, YY_BUF_SIZE);
1079   surf_parse__switch_to_buffer(surf_input_buffer);
1080   surf_parse_lineno = 1;
1081 }
1082
1083 void surf_parse_close()
1084 {
1085   if (surf_parsed_filename) {
1086     surf_path.pop_back();
1087   }
1088
1089   free(surf_parsed_filename);
1090   surf_parsed_filename = nullptr;
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 }