X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/3203ed1f4fb6f4617e94d5351661ba07e8b8f833..756df47074b2d7b0721f234077f5ef8d75e13932:/src/mc/ObjectInformation.cpp diff --git a/src/mc/ObjectInformation.cpp b/src/mc/ObjectInformation.cpp index 62b793e827..9d66b0ebb4 100644 --- a/src/mc/ObjectInformation.cpp +++ b/src/mc/ObjectInformation.cpp @@ -1,3 +1,9 @@ +/* Copyright (c) 2014-2015. The SimGrid Team. + * All rights reserved. */ + +/* This program is free software; you can redistribute it and/or modify it + * under the terms of the license (GNU LGPL) which comes with this package. */ + #include "src/mc/Frame.hpp" #include "src/mc/ObjectInformation.hpp" #include "src/mc/Variable.hpp" @@ -94,5 +100,110 @@ simgrid::mc::Variable* ObjectInformation::find_variable(const char* name) const return nullptr; } +void ObjectInformation::remove_global_variable(const char* name) +{ + typedef std::vector::size_type size_type; + + if (this->global_variables.empty()) + return; + + // Binary search: + size_type start = 0; + size_type end = this->global_variables.size() - 1; + + while (start <= end) { + size_type cursor = start + (end - start) / 2; + simgrid::mc::Variable& current_var = this->global_variables[cursor]; + int cmp = current_var.name.compare(name); + + if (cmp == 0) { + // Find the whole range: + start = cursor; + while (start != 0 && this->global_variables[start - 1].name == name) + start--; + size_type size = this->global_variables.size(); + end = cursor; + while (end != size - 1 && this->global_variables[end + 1].name == name) + end++; + // Remove the whole range: + this->global_variables.erase( + this->global_variables.begin() + cursor, + this->global_variables.begin() + end + 1); + return; + } else if (cmp < 0) + start = cursor + 1; + else if (cursor != 0) + end = cursor - 1; + else + break; + } +} + +/** \brief Ignore a local variable in a scope + * + * Ignore all instances of variables with a given name in + * any (possibly inlined) subprogram with a given namespaced + * name. + * + * \param var_name Name of the local variable (or parameter to ignore) + * \param subprogram_name Name of the subprogram fo ignore (NULL for any) + * \param subprogram (possibly inlined) Subprogram of the scope + * \param scope Current scope + */ +static void remove_local_variable(simgrid::mc::Frame& scope, + const char *var_name, + const char *subprogram_name, + simgrid::mc::Frame const& subprogram) +{ + typedef std::vector::size_type size_type; + + // If the current subprogram matches the given name: + if ((subprogram_name == nullptr || + (!subprogram.name.empty() + && subprogram.name == subprogram_name)) + && !scope.variables.empty()) { + + // Try to find the variable and remove it: + size_type start = 0; + size_type end = scope.variables.size() - 1; + + // Binary search: + while (start <= end) { + size_type cursor = start + (end - start) / 2; + simgrid::mc::Variable& current_var = scope.variables[cursor]; + int compare = current_var.name.compare(var_name); + if (compare == 0) { + // Variable found, remove it: + scope.variables.erase(scope.variables.begin() + cursor); + break; + } else if (compare < 0) + start = cursor + 1; + else if (cursor != 0) + end = cursor - 1; + else + break; + } + } + + // And recursive processing in nested scopes: + for (simgrid::mc::Frame& nested_scope : scope.scopes) { + // The new scope may be an inlined subroutine, in this case we want to use its + // namespaced name in recursive calls: + simgrid::mc::Frame const& nested_subprogram = + nested_scope.tag == + DW_TAG_inlined_subroutine ? nested_scope : subprogram; + remove_local_variable(nested_scope, var_name, subprogram_name, + nested_subprogram); + } +} + +void ObjectInformation::remove_local_variable( + const char* var_name, const char* subprogram_name) +{ + for (auto& entry : this->subprograms) + simgrid::mc::remove_local_variable(entry.second, + var_name, subprogram_name, entry.second); +} + } } \ No newline at end of file