- int start = 0;
- int end = xbt_dynar_length(scope->variables) - 1;
- while(start <= end){
- int cursor = (start + end) / 2;
- dw_variable_t current_var = (dw_variable_t)xbt_dynar_get_as(scope->variables, cursor, dw_variable_t);
-
- int compare = strcmp(current_var->name, var_name);
- if(compare == 0){
- xbt_dynar_remove_at(scope->variables, cursor, NULL);
- start = 0;
- end = xbt_dynar_length(scope->variables) - 1;
- }else if(compare < 0){
- start = cursor + 1;
- }else{
- end = cursor - 1;
+
+ // If the current subprogram matche the given name:
+ if(subprogram_name==NULL || strcmp(subprogram_name, subprogram->name)==0) {
+
+ // Try to find the variable and remove it:
+ int start = 0;
+ int end = xbt_dynar_length(scope->variables) - 1;
+
+ // Dichotomic search:
+ while(start <= end){
+ int cursor = (start + end) / 2;
+ dw_variable_t current_var = (dw_variable_t)xbt_dynar_get_as(scope->variables, cursor, dw_variable_t);
+
+ int compare = strcmp(current_var->name, var_name);
+ if(compare == 0){
+ // Variable found, remove it:
+ xbt_dynar_remove_at(scope->variables, cursor, NULL);
+
+ // and start again:
+ start = 0;
+ end = xbt_dynar_length(scope->variables) - 1;
+ }else if(compare < 0){
+ start = cursor + 1;
+ }else{
+ end = cursor - 1;
+ }