Renamed VariableName helper method

This commit is contained in:
Fredrik Dahlgren
2022-12-23 19:43:02 +01:00
parent 921cbb2aa8
commit 717861e3ac
7 changed files with 15 additions and 15 deletions

View File

@@ -159,9 +159,9 @@ mod tests {
}
"#;
let sources = [
VariableName::from_name("in"),
VariableName::from_name("out"),
VariableName::from_name("tmp"),
VariableName::from_string("in"),
VariableName::from_string("out"),
VariableName::from_string("tmp"),
];
let sinks = [2, 1, 1];
validate_constraints(src, &sources, &sinks);
@@ -178,9 +178,9 @@ mod tests {
}
"#;
let sources = [
VariableName::from_name("in"),
VariableName::from_name("out"),
VariableName::from_name("tmp"),
VariableName::from_string("in"),
VariableName::from_string("out"),
VariableName::from_string("tmp"),
];
let sinks = [2, 1, 1];
validate_constraints(src, &sources, &sinks);

View File

@@ -243,7 +243,7 @@ mod tests {
let taint_analysis = run_taint_analysis(&cfg);
for (source, expected_sinks) in taint_map {
let source = VariableName::from_name(source).with_version(0);
let source = VariableName::from_string(source).with_version(0);
let sinks = taint_analysis
.multi_step_taint(&source)
.iter()

View File

@@ -19,7 +19,7 @@ impl Parameters {
file_location: FileLocation,
) -> Parameters {
Parameters {
param_names: param_names.iter().map(VariableName::from_name).collect(),
param_names: param_names.iter().map(VariableName::from_string).collect(),
file_id,
file_location,
}

View File

@@ -1014,10 +1014,10 @@ mod tests {
use ExpressionInfixOpcode::*;
use ValueReduction::*;
let mut lhe = Number(Meta::default(), 7u64.into());
let mut rhe = Variable { meta: Meta::default(), name: VariableName::from_name("v") };
let mut rhe = Variable { meta: Meta::default(), name: VariableName::from_string("v") };
let constants = UsefulConstants::new(&Curve::default());
let mut env = ValueEnvironment::new(&constants);
env.add_variable(&VariableName::from_name("v"), &FieldElement { value: 3u64.into() });
env.add_variable(&VariableName::from_string("v"), &FieldElement { value: 3u64.into() });
lhe.propagate_values(&mut env);
rhe.propagate_values(&mut env);

View File

@@ -270,7 +270,7 @@ pub struct VariableName {
impl VariableName {
/// Returns a new variable name with the given name (without suffix or version).
#[must_use]
pub fn from_name<N: ToString>(name: N) -> VariableName {
pub fn from_string<N: ToString>(name: N) -> VariableName {
VariableName { name: name.to_string(), suffix: None, version: None }
}

View File

@@ -238,8 +238,8 @@ impl TryLift<&ast::Meta> for String {
// We assume that the input string uses '.' to separate the name from the suffix.
let tokens: Vec<_> = self.split('.').collect();
match tokens.len() {
1 => Ok(ir::VariableName::from_name(tokens[0])),
2 => Ok(ir::VariableName::from_name(tokens[0]).with_suffix(tokens[1])),
1 => Ok(ir::VariableName::from_string(tokens[0])),
2 => Ok(ir::VariableName::from_string(tokens[0]).with_suffix(tokens[1])),
// Either the original name from the AST contains `.`, or the suffix
// added when ensuring uniqueness contains `.`. Neither case should
// occur, so we return an error here instead of producing a report.

View File

@@ -528,8 +528,8 @@ fn lift(name: &str) -> VariableName {
// We assume that the input string uses '.' to separate the name from the suffix.
let tokens: Vec<_> = name.split('.').collect();
match tokens.len() {
1 => VariableName::from_name(tokens[0]),
2 => VariableName::from_name(tokens[0]).with_suffix(tokens[1]),
1 => VariableName::from_string(tokens[0]),
2 => VariableName::from_string(tokens[0]).with_suffix(tokens[1]),
_ => panic!("invalid variable name"),
}
}