Logo AND Algorithmique Numérique Distribuée

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