Tighten up reduced_ast code a bit
This commit is contained in:
parent
845461e2b3
commit
2609dd404a
@ -178,9 +178,8 @@ impl<'a> Reducer<'a> {
|
||||
}
|
||||
|
||||
fn value(&mut self, qualified_name: &QualifiedName) -> Expr {
|
||||
let symbol_table = self.symbol_table;
|
||||
let ref id = qualified_name.id;
|
||||
let ref sym_name = match symbol_table.get_fqsn_from_id(id) {
|
||||
let ref sym_name = match self.symbol_table.get_fqsn_from_id(id) {
|
||||
Some(fqsn) => fqsn,
|
||||
None => return Expr::ReductionError(format!("FQSN lookup for Value {:?} failed", qualified_name)),
|
||||
};
|
||||
@ -189,7 +188,7 @@ impl<'a> Reducer<'a> {
|
||||
let FullyQualifiedSymbolName(ref v) = sym_name;
|
||||
let name = v.last().unwrap().name.clone();
|
||||
|
||||
let Symbol { local_name, spec, .. } = match symbol_table.lookup_by_fqsn(&sym_name) {
|
||||
let Symbol { local_name, spec, .. } = match self.symbol_table.lookup_by_fqsn(&sym_name) {
|
||||
Some(s) => s,
|
||||
//None => return Expr::ReductionError(format!("Symbol {:?} not found", sym_name)),
|
||||
None => return Expr::Sym(name.clone())
|
||||
@ -218,15 +217,14 @@ impl<'a> Reducer<'a> {
|
||||
}
|
||||
|
||||
fn reduce_named_struct(&mut self, name: &QualifiedName, fields: &Vec<(Rc<String>, Expression)>) -> Expr {
|
||||
let symbol_table = self.symbol_table;
|
||||
let ref sym_name = match symbol_table.get_fqsn_from_id(&name.id) {
|
||||
let ref sym_name = match self.symbol_table.get_fqsn_from_id(&name.id) {
|
||||
Some(fqsn) => fqsn,
|
||||
None => return Expr::ReductionError(format!("FQSN lookup for name {:?} failed", name)),
|
||||
};
|
||||
|
||||
let FullyQualifiedSymbolName(ref v) = sym_name;
|
||||
let ref name = v.last().unwrap().name;
|
||||
let (type_name, index, members_from_table) = match symbol_table.lookup_by_fqsn(&sym_name) {
|
||||
let (type_name, index, members_from_table) = match self.symbol_table.lookup_by_fqsn(&sym_name) {
|
||||
Some(Symbol { spec: SymbolSpec::RecordConstructor { members, type_name, index }, .. }) => (type_name.clone(), index, members),
|
||||
_ => return Expr::ReductionError("Not a record constructor".to_string()),
|
||||
};
|
||||
@ -254,7 +252,6 @@ impl<'a> Reducer<'a> {
|
||||
}
|
||||
|
||||
fn reduce_if_expression(&mut self, discriminator: Option<&Expression>, body: &IfExpressionBody) -> Expr {
|
||||
let symbol_table = self.symbol_table;
|
||||
let cond = Box::new(match discriminator {
|
||||
Some(expr) => self.expression(expr),
|
||||
None => return Expr::ReductionError(format!("blank cond if-expr not supported")),
|
||||
@ -277,7 +274,7 @@ impl<'a> Reducer<'a> {
|
||||
};
|
||||
|
||||
let alternatives = vec![
|
||||
pattern.to_alternative(then_clause, symbol_table),
|
||||
pattern.to_alternative(then_clause, self.symbol_table),
|
||||
Alternative {
|
||||
matchable: Subpattern {
|
||||
tag: None,
|
||||
@ -303,7 +300,7 @@ impl<'a> Reducer<'a> {
|
||||
},
|
||||
Condition::Pattern(ref p) => {
|
||||
let item = self.block(&arm.body);
|
||||
let alt = p.to_alternative(item, symbol_table);
|
||||
let alt = p.to_alternative(item, self.symbol_table);
|
||||
alternatives.push(alt);
|
||||
},
|
||||
Condition::TruncatedOp(_, _) => {
|
||||
|
Loading…
Reference in New Issue
Block a user