118 lines
3.1 KiB
Rust
118 lines
3.1 KiB
Rust
|
use full_moon::ast::*;
|
||
|
|
||
|
use crate::visitor::Visitor;
|
||
|
|
||
|
struct VariableValue {}
|
||
|
|
||
|
// value: Literal | String | Module | ReducedExpression
|
||
|
struct Variable {
|
||
|
name: String,
|
||
|
value: VariableValue
|
||
|
}
|
||
|
|
||
|
pub struct ConstantFolder {
|
||
|
locals: Vec<Variable>
|
||
|
}
|
||
|
|
||
|
impl ConstantFolder {
|
||
|
/// Return `Name` struct for a valid standard library name/function
|
||
|
///
|
||
|
/// Lua has standard library modules like `math.max`, `math.min`
|
||
|
/// This function returns a Name if the given argument are valid
|
||
|
/// This is to disambiguate between Var.Name
|
||
|
///
|
||
|
/// # Arguments
|
||
|
///
|
||
|
/// * `module` - Standard library model
|
||
|
/// * `name` - The module
|
||
|
///
|
||
|
fn name_from_standard_library(name: &str) -> Option<&str> {
|
||
|
let standard_library_names = vec![
|
||
|
"math", "string", "table", "bit"
|
||
|
];
|
||
|
if standard_library_names.contains(&name) {
|
||
|
Some(name)
|
||
|
} else {
|
||
|
None
|
||
|
}
|
||
|
}
|
||
|
|
||
|
fn visit_expression<'a>(&mut self, expression: Expression<'a>) {
|
||
|
match expression {
|
||
|
Expression::BinaryOperator {
|
||
|
lhs,
|
||
|
rhs,
|
||
|
binop
|
||
|
} => {
|
||
|
}
|
||
|
Expression::Parentheses {
|
||
|
contained,
|
||
|
expression,
|
||
|
} => {}
|
||
|
Expression::UnaryOperator {
|
||
|
unop,
|
||
|
expression,
|
||
|
} => {}
|
||
|
Expression::Value {
|
||
|
value
|
||
|
} => {}
|
||
|
_ => {}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
impl Visitor for ConstantFolder {
|
||
|
fn visit_assignment<'a>(&mut self, assignment: &Assignment<'a>) {
|
||
|
println!("visit assignment {}", assignment);
|
||
|
}
|
||
|
|
||
|
fn visit_do<'a>(&mut self, do_: &Do<'a>) {
|
||
|
println!("visit do {}", do_);
|
||
|
}
|
||
|
|
||
|
fn visit_function_call<'a>(&mut self, function_call: &FunctionCall<'a>) {
|
||
|
println!("visit function_call {}", function_call);
|
||
|
}
|
||
|
|
||
|
fn visit_function_declaration<'a>(&mut self, function_declaration: &FunctionDeclaration<'a>) {
|
||
|
println!("visit function_declaration {}", function_declaration);
|
||
|
}
|
||
|
|
||
|
fn visit_generic_for<'a>(&mut self, generic_for: &GenericFor<'a>) {
|
||
|
println!("visit generic_for {}", generic_for);
|
||
|
}
|
||
|
|
||
|
fn visit_if<'a>(&mut self, if_: &If<'a>) {
|
||
|
println!("visit if {}", if_);
|
||
|
}
|
||
|
|
||
|
fn visit_local_assignment<'a>(&mut self, local_assignment: &LocalAssignment<'a>) {
|
||
|
println!("visit local_assignment {}", local_assignment);
|
||
|
}
|
||
|
|
||
|
fn visit_local_function<'a>(&mut self, local_function: &LocalFunction<'a>) {
|
||
|
println!("visit local_function {}", local_function);
|
||
|
}
|
||
|
|
||
|
fn visit_numeric_for<'a>(&mut self, numeric_for: &NumericFor<'a>) {
|
||
|
println!("visit numeric_for {}", numeric_for);
|
||
|
}
|
||
|
|
||
|
fn visit_repeat<'a>(&mut self, repeat: &Repeat<'a>) {
|
||
|
println!("visit repeat {}", repeat);
|
||
|
}
|
||
|
|
||
|
fn visit_while<'a>(&mut self, while_: &While<'a>) {
|
||
|
println!("visit while {}", while_);
|
||
|
}
|
||
|
|
||
|
fn visit_goto<'a>(&mut self, goto: &lua52::Goto<'a>) {
|
||
|
println!("visit goto {}", goto);
|
||
|
}
|
||
|
|
||
|
fn visit_label<'a>(&mut self, label: &lua52::Label<'a>) {
|
||
|
println!("visit label {}", label);
|
||
|
}
|
||
|
|
||
|
}
|