Skip to content

Commit

Permalink
Adding code for detecting collisions in parameter names
Browse files Browse the repository at this point in the history
  • Loading branch information
ambiguousname committed Oct 29, 2024
1 parent b49d63e commit e684a3c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
16 changes: 15 additions & 1 deletion tool/src/demo_gen/terminus.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::collections::BTreeSet;
use std::collections::{BTreeSet, HashMap};

use diplomat_core::hir::{
self, DemoInfo, Method, OpaqueDef, StructDef, StructPath, TyPosition, Type, TypeContext,
Expand Down Expand Up @@ -172,6 +172,20 @@ impl<'ctx, 'tcx> RenderTerminusContext<'ctx, 'tcx> {
self.relative_import_path.clone(),
);

let mut param_collision_dict : HashMap<String, i32> = HashMap::new();

for out_param in &mut self.terminus_info.out_params {
if param_collision_dict.contains_key(&out_param.param_name) {
let num = param_collision_dict.get(&out_param.param_name).unwrap();

out_param.param_name = format!("{}_{}", out_param.param_name, num);

param_collision_dict.insert(out_param.param_name.clone(), num + 1);
} else {
param_collision_dict.insert(out_param.param_name.clone(), 1);
}
}

self.terminus_info.imports.insert(format);
}

Expand Down
4 changes: 2 additions & 2 deletions tool/templates/demo_gen/terminus.js.jinja
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export function {{function_name}}(
{%- if typescript %}{%- for param in out_params -%}
{%- for param in out_params -%}
{{param.param_name}}{% if typescript %}: {{param.type_name}}{% endif %}{% if !loop.last %}, {% endif %}
{%- endfor -%}{% endif -%}
{%- endfor -%}
){% if typescript %};{% else %} {
var terminusArgs = arguments;
return {{node_call_stack|indent(4)}};
Expand Down

0 comments on commit e684a3c

Please sign in to comment.