# HG changeset patch # User Emmanuel Gil Peyrot # Date 1464663545 -3600 # Node ID f27a4aee9dfaea0efe8319a2369e493f99f35532 # Parent 326d7f2a94d4ddc5d3f5d8ec80924bb6a3784f6b Add ast.Attribute. diff --git a/example/class.py b/example/class.py --- a/example/class.py +++ b/example/class.py @@ -5,3 +5,9 @@ class A: class B(A): def b(self): print('b') + +a = A() +b = B() +a.a() +b.b() +b.a() diff --git a/src/ast_convert.rs b/src/ast_convert.rs --- a/src/ast_convert.rs +++ b/src/ast_convert.rs @@ -80,6 +80,7 @@ fn parse_expr(py: Python, ast: PyObject) let arg_type = ast_module.get(py, "arg").unwrap(); let bin_op_type = ast_module.get(py, "BinOp").unwrap(); let name_constant_type = ast_module.get(py, "NameConstant").unwrap(); + let attribute_type = ast_module.get(py, "Attribute").unwrap(); let name_type = ast_module.get(py, "Name").unwrap(); let num_type = ast_module.get(py, "Num").unwrap(); let str_type = ast_module.get(py, "Str").unwrap(); @@ -93,6 +94,14 @@ fn parse_expr(py: Python, ast: PyObject) let arg = ast.getattr(py, "arg").unwrap(); let arg = get_str(py, arg); Expr::Name(arg) + } else if is_instance(&ast, &attribute_type) { + let value = ast.getattr(py, "value").unwrap(); + let attr = ast.getattr(py, "attr").unwrap(); + + let value = parse_expr(py, value); + let attr = get_str(py, attr); + + Expr::Attribute(Box::new(value), attr) } else if is_instance(&ast, &name_type) { let id = ast.getattr(py, "id").unwrap(); let id = get_str(py, id); diff --git a/src/ast_dump.rs b/src/ast_dump.rs --- a/src/ast_dump.rs +++ b/src/ast_dump.rs @@ -51,6 +51,7 @@ impl Expr { Some(asname) => format!("{} as {}", name, asname) } } + Expr::Attribute(lhs, rhs) => format!("{}.{}", lhs.to_string(), rhs), Expr::Name(name) => format!("{}", name), Expr::NameConstant(name) => format!("{}", name), Expr::Str(s) => format!("\"{}\"", s), diff --git a/src/ast_type.rs b/src/ast_type.rs --- a/src/ast_type.rs +++ b/src/ast_type.rs @@ -177,6 +177,11 @@ impl Visitor for Typing { } }, Expr::Alias(_, _) => Type::Bottom, + Expr::Attribute(lhs, rhs) => { + let type_left = self.visit_expr(*lhs); + println!("coucou {:?}", type_left); + Type::Bottom + }, Expr::Name(id) => { let env = match self.environment.pop() { Some(env) => env, diff --git a/src/python_ast.rs b/src/python_ast.rs --- a/src/python_ast.rs +++ b/src/python_ast.rs @@ -23,6 +23,7 @@ pub enum Expr { Compare(Box, Vec, Vec), Call(Box, Vec), Alias(String, Option), + Attribute(Box, String), Name(String), NameConstant(String), Str(String),