Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
tiny doc update and cosmetics
[simgrid.git] / src / surf / xml / surfxml_sax_cb.cpp
index 466f8d2..ac88aa5 100644 (file)
@@ -31,7 +31,7 @@ std::vector<simgrid::surf::LinkImpl*> parsed_link_list; /* temporary store of cu
  * Helping functions
  */
 void surf_parse_assert(bool cond, const char *fmt, ...) {
-  if (!cond ) {
+  if (not cond) {
     va_list va;
     va_start(va,fmt);
     int lineno = surf_parse_lineno;
@@ -315,7 +315,7 @@ void ETag_surfxml_storage()
   storage.id           = A_surfxml_storage_id;
   storage.type_id      = A_surfxml_storage_typeId;
   storage.content      = A_surfxml_storage_content;
-  storage.content_type = A_surfxml_storage_content___type;
+
   storage.attach       = A_surfxml_storage_attach;
   sg_platf_new_storage(&storage);
 }
@@ -338,7 +338,6 @@ void ETag_surfxml_storage___type()
   current_model_property_set    = nullptr;
 
   storage_type.content          = A_surfxml_storage___type_content;
-  storage_type.content_type     = A_surfxml_storage___type_content___type;
   storage_type.id               = A_surfxml_storage___type_id;
   storage_type.model            = A_surfxml_storage___type_model;
   storage_type.size             = surf_parse_get_size(A_surfxml_storage___type_size,
@@ -446,16 +445,30 @@ void STag_surfxml_platform() {
       "Use simgrid_update_xml to update your file automatically. "
       "This program is installed automatically with SimGrid, or "
       "available in the tools/ directory of the source archive.");
-  xbt_assert((version >= 4.0), "******* FILE %s IS TOO OLD (v:%.1f) *********\n "
-      "Changes introduced in SimGrid 3.13:\n"
-      "  - 'power' attribute of hosts (and others) got renamed to 'speed'.\n"
-      "  - In <trace_connect>, attribute kind=\"POWER\" is now kind=\"SPEED\".\n"
-      "  - DOCTYPE now point to the rignt URL: http://simgrid.gforge.inria.fr/simgrid/simgrid.dtd\n"
-      "  - speed, bandwidth and latency attributes now MUST have an explicit unit (f, Bps, s by default)"
-      "\n\n"
-      "Use simgrid_update_xml to update your file automatically. "
-      "This program is installed automatically with SimGrid, or "
-      "available in the tools/ directory of the source archive.",surf_parsed_filename, version);
+  xbt_assert((version >= 4.0),
+             "******* FILE %s IS TOO OLD (v:%.1f) *********\n "
+             "Changes introduced in SimGrid 3.13:\n"
+             "  - 'power' attribute of hosts (and others) got renamed to 'speed'.\n"
+             "  - In <trace_connect>, attribute kind=\"POWER\" is now kind=\"SPEED\".\n"
+             "  - DOCTYPE now point to the rignt URL: http://simgrid.gforge.inria.fr/simgrid/simgrid.dtd\n"
+             "  - speed, bandwidth and latency attributes now MUST have an explicit unit (f, Bps, s by default)"
+             "\n\n"
+             "Use simgrid_update_xml to update your file automatically. "
+             "This program is installed automatically with SimGrid, or "
+             "available in the tools/ directory of the source archive.",
+             surf_parsed_filename, version);
+  if (version < 4.1) {
+    XBT_INFO("You're using a v%.1f XML file (%s) while the current standard is v4.1 "
+             "That's fine, the new version is backward compatible. \n\n"
+             "Use simgrid_update_xml to update your file automatically. "
+             "This program is installed automatically with SimGrid, or "
+             "available in the tools/ directory of the source archive.",
+             version, surf_parsed_filename);
+  }
+  xbt_assert(version <= 4.1, "******* FILE %s COMES FROM THE FUTURE (v:%.1f) *********\n "
+                             "The most recent formalism that this version of SimGrid understands is v4.1.\n"
+                             "Please update your code, or use another, more adapted, file.",
+             surf_parsed_filename, version);
 
   sg_platf_begin();
 }
@@ -471,13 +484,13 @@ void STag_surfxml_host(){
 void STag_surfxml_prop()
 {
   if (ZONE_TAG) { // We need to retrieve the most recently opened zone
-    XBT_DEBUG("Set Zone property %s -> %s", A_surfxml_prop_id, A_surfxml_prop_value);
-    simgrid::s4u::NetZone* netzone = simgrid::s4u::Engine::instance()->netzoneByNameOrNull(A_surfxml_AS_id);
+    XBT_DEBUG("Set zone property %s -> %s", A_surfxml_prop_id, A_surfxml_prop_value);
+    simgrid::s4u::NetZone* netzone = simgrid::s4u::Engine::instance()->netzoneByNameOrNull(A_surfxml_zone_id);
 
     netzone->setProperty(A_surfxml_prop_id, A_surfxml_prop_value);
   }
   else{
-    if (!current_property_set)
+    if (not current_property_set)
       current_property_set = xbt_dict_new_homogeneous(&xbt_free_f); // Maybe, it should raise an error
     xbt_dict_set(current_property_set, A_surfxml_prop_id, xbt_strdup(A_surfxml_prop_value), nullptr);
     XBT_DEBUG("add prop %s=%s into current property set %p", A_surfxml_prop_id, A_surfxml_prop_value,
@@ -689,6 +702,9 @@ void STag_surfxml_link___ctn(){
     link_name = bprintf("%s_DOWN", A_surfxml_link___ctn_id);
     link      = simgrid::surf::LinkImpl::byName(link_name);
     break;
+  default:
+    surf_parse_error("Invalid direction for link %s", link_name);
+    break;
   }
   xbt_free(link_name); // no-op if it's already nullptr
 
@@ -897,7 +913,8 @@ void ETag_surfxml_trace(){
   sg_platf_new_trace(&trace);
 }
 
-void STag_surfxml_trace___connect(){
+void STag_surfxml_trace___connect()
+{
   parse_after_config();
   s_sg_platf_trace_connect_cbarg_t trace_connect;
   memset(&trace_connect,0,sizeof(trace_connect));
@@ -922,46 +939,59 @@ void STag_surfxml_trace___connect(){
   case A_surfxml_trace___connect_kind_LINK___AVAIL:
     trace_connect.kind =  SURF_TRACE_CONNECT_KIND_LINK_AVAIL;
     break;
+  default:
+    surf_parse_error("Invalid trace kind");
+    break;
   }
   sg_platf_trace_connect(&trace_connect);
 }
 
-void STag_surfxml_AS(){
+void STag_surfxml_AS()
+{
   AX_surfxml_zone_id = AX_surfxml_AS_id;
   AX_surfxml_zone_routing = (AT_surfxml_zone_routing)AX_surfxml_AS_routing;
   STag_surfxml_zone();
 }
-void ETag_surfxml_AS(){
+
+void ETag_surfxml_AS()
+{
   ETag_surfxml_zone();
 }
-void STag_surfxml_zone(){
+
+void STag_surfxml_zone()
+{
   parse_after_config();
-  ZONE_TAG                   = 1;
-  s_sg_platf_AS_cbarg_t AS = { A_surfxml_zone_id, (int)A_surfxml_zone_routing};
+  ZONE_TAG                 = 1;
+  s_sg_platf_AS_cbarg_t AS = {A_surfxml_zone_id, (int)A_surfxml_zone_routing};
 
   sg_platf_new_AS_begin(&AS);
 }
-void ETag_surfxml_zone(){
+
+void ETag_surfxml_zone()
+{
   sg_platf_new_AS_seal();
 }
 
-void STag_surfxml_config(){
+void STag_surfxml_config()
+{
   ZONE_TAG = 0;
   xbt_assert(current_property_set == nullptr, "Someone forgot to reset the property set to nullptr in its closing tag (or XML malformed)");
   XBT_DEBUG("START configuration name = %s",A_surfxml_config_id);
   if (_sg_cfg_init_status == 2) {
-    surf_parse_error("All <config> tags must be given before any platform elements (such as <AS>, <host>, <cluster>, <link>, etc).");
+    surf_parse_error("All <config> tags must be given before any platform elements (such as <zone>, <host>, <cluster>, "
+                     "<link>, etc).");
   }
 }
-void ETag_surfxml_config(){
+
+void ETag_surfxml_config()
+{
   xbt_dict_cursor_t cursor = nullptr;
   char *key;
   char *elem;
   xbt_dict_foreach(current_property_set, cursor, key, elem) {
     if (xbt_cfg_is_default_value(key)) {
-      char* cfg = bprintf("%s:%s", key, elem);
-      xbt_cfg_set_parse(cfg);
-      free(cfg);
+      std::string cfg = std::string(key) + ":" + elem;
+      xbt_cfg_set_parse(cfg.c_str());
     } else
       XBT_INFO("The custom configuration '%s' is already defined by user!",key);
   }
@@ -1018,6 +1048,9 @@ void ETag_surfxml_actor()
   case A_surfxml_actor_on___failure_RESTART:
     actor.on_failure =  SURF_ACTOR_ON_FAILURE_RESTART;
     break;
+  default:
+    surf_parse_error("Invalid on failure behavior");
+    break;
   }
 
   sg_platf_new_process(&actor);
@@ -1037,7 +1070,7 @@ void STag_surfxml_argument(){
 }
 
 void STag_surfxml_model___prop(){
-  if (!current_model_property_set)
+  if (not current_model_property_set)
     current_model_property_set = new std::map<std::string, std::string>();
 
   current_model_property_set->insert(
@@ -1069,7 +1102,7 @@ void surf_parse_open(const char *file)
   xbt_free(dir);
 
   surf_file_to_parse = surf_fopen(file, "r");
-  xbt_assert((surf_file_to_parse), "Unable to open \"%s\"\n", file);
+  xbt_assert(surf_file_to_parse != nullptr, "Unable to open '%s'\n", file);
   surf_input_buffer = surf_parse__create_buffer(surf_file_to_parse, YY_BUF_SIZE);
   surf_parse__switch_to_buffer(surf_input_buffer);
   surf_parse_lineno = 1;
@@ -1096,6 +1129,6 @@ static int _surf_parse() {
   return surf_parse_lex();
 }
 
-int_f_void_t surf_parse = _surf_parse;
+int_f_void_t surf_parse = &_surf_parse;
 
 SG_END_DECL()