Logo AND Algorithmique Numérique Distribuée

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