36 lines
1022 B
Rust
36 lines
1022 B
Rust
use super::ast::{Expression, Program, TopLevel};
|
|
use internment::ArcIntern;
|
|
use std::collections::HashSet;
|
|
|
|
impl<T> Program<T> {
|
|
/// Get the complete list of strings used within the program.
|
|
///
|
|
/// For the purposes of this function, strings are the variables used in
|
|
/// `print` statements.
|
|
pub fn strings(&self) -> HashSet<ArcIntern<String>> {
|
|
let mut result = HashSet::new();
|
|
|
|
for stmt in self.items.iter() {
|
|
stmt.register_strings(&mut result);
|
|
}
|
|
|
|
result
|
|
}
|
|
}
|
|
|
|
impl<T> TopLevel<T> {
|
|
fn register_strings(&self, string_set: &mut HashSet<ArcIntern<String>>) {
|
|
match self {
|
|
TopLevel::Function(_, _, _, body) => body.register_strings(string_set),
|
|
TopLevel::Statement(stmt) => stmt.register_strings(string_set),
|
|
}
|
|
}
|
|
}
|
|
|
|
impl<T> Expression<T> {
|
|
fn register_strings(&self, _string_set: &mut HashSet<ArcIntern<String>>) {
|
|
// nothing has a string in here, at the moment
|
|
unimplemented!()
|
|
}
|
|
}
|