comparison src/ast_scope.rs @ 12:0e96c5bc401d

Remove the need for a Box in BlockStatement.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Thu, 02 Jun 2016 03:14:01 +0100
parents 5c169d5807b5
children 38b0d63697b1
comparison
equal deleted inserted replaced
11:5c169d5807b5 12:0e96c5bc401d
1 use python_ast::{Module, Statement, Expr}; 1 use python_ast::{Module, Statement, Expr};
2 2
3 use std::collections::HashMap; 3 use std::collections::HashMap;
4 4
5 #[derive(Debug)] 5 #[derive(Debug)]
6 struct BlockStatement {
7 statement: Statement,
8 block: Option<Block>
9 }
10
11 #[derive(Debug)]
6 struct Block { 12 struct Block {
7 statements: Vec<(Statement, Option<Box<Block>>)>, 13 statements: Vec<BlockStatement>,
8 bindings: Vec<String> 14 bindings: Vec<String>
9 } 15 }
10 16
11 #[derive(Debug)] 17 #[derive(Debug)]
12 pub struct Scoping { 18 pub struct Scoping {
33 block.bindings.push(name.clone()); 39 block.bindings.push(name.clone());
34 let mut function_block = Block{statements: vec!(), bindings: args.clone()}; 40 let mut function_block = Block{statements: vec!(), bindings: args.clone()};
35 for statement in statements { 41 for statement in statements {
36 scope_statement(statement, &mut function_block); 42 scope_statement(statement, &mut function_block);
37 } 43 }
38 Some(Box::new(function_block)) 44 Some(function_block)
39 }, 45 },
40 Statement::ImportFrom(module, names) => { 46 Statement::ImportFrom(module, names) => {
41 for name in names { 47 for name in names {
42 let name = match name { 48 let name = match name {
43 Expr::Alias(name, asname) => (name, asname), 49 Expr::Alias(name, asname) => (name, asname),
52 } 58 }
53 None 59 None
54 }, 60 },
55 _ => None 61 _ => None
56 }; 62 };
57 block.statements.push((statement, new_block)); 63 block.statements.push(BlockStatement{statement: statement, block: new_block});
58 } 64 }
59 65
60 #[allow(dead_code)] 66 #[allow(dead_code)]
61 pub fn scope_ast(modules: Vec<Module>) -> Scoping { 67 pub fn scope_ast(modules: Vec<Module>) -> Scoping {
62 let mut scoping = Scoping{modules: HashMap::new()}; 68 let mut scoping = Scoping{modules: HashMap::new()};