updated lifetime

signature
pca006132 2021-01-15 14:37:55 +08:00
parent d466b7bc2b
commit 5fce6cf069
1 changed files with 11 additions and 9 deletions

View File

@ -5,7 +5,9 @@ use super::typedef::*;
use rustpython_parser::ast::{ExpressionType, Statement, StatementType, StringGroup};
use std::collections::HashMap;
fn typename_from_expr<'b: 'a, 'a>(typenames: &mut Vec<&'a str>, expr: &'b ExpressionType) {
// TODO: fix condition checking, return error message instead of panic...
fn typename_from_expr<'a>(typenames: &mut Vec<&'a str>, expr: &'a ExpressionType) {
match expr {
ExpressionType::Identifier { name } => typenames.push(&name),
ExpressionType::String { value } => match value {
@ -20,7 +22,7 @@ fn typename_from_expr<'b: 'a, 'a>(typenames: &mut Vec<&'a str>, expr: &'b Expres
}
}
fn typename_from_fn<'b: 'a, 'a>(typenames: &mut Vec<&'a str>, fun: &'b StatementType) {
fn typename_from_fn<'a>(typenames: &mut Vec<&'a str>, fun: &'a StatementType) {
match fun {
StatementType::FunctionDef { args, returns, .. } => {
for arg in args.args.iter() {
@ -36,7 +38,7 @@ fn typename_from_fn<'b: 'a, 'a>(typenames: &mut Vec<&'a str>, fun: &'b Statement
}
}
fn name_from_expr<'b: 'a, 'a>(expr: &'b ExpressionType) -> &'a str {
fn name_from_expr<'a>(expr: &'a ExpressionType) -> &'a str {
match &expr {
ExpressionType::Identifier { name } => &name,
ExpressionType::String { value } => match value {
@ -47,9 +49,9 @@ fn name_from_expr<'b: 'a, 'a>(expr: &'b ExpressionType) -> &'a str {
}
}
fn type_from_expr<'b: 'a, 'a>(
fn type_from_expr<'a>(
ctx: &'a TopLevelContext,
expr: &'b ExpressionType,
expr: &'a ExpressionType,
) -> Result<Type, String> {
match expr {
ExpressionType::Identifier { name } => {
@ -90,7 +92,7 @@ fn type_from_expr<'b: 'a, 'a>(
}
}
pub fn get_typenames<'b: 'a, 'a>(stmts: &'b [Statement]) -> (Vec<&'a str>, Vec<&'a str>) {
pub fn get_typenames<'a>(stmts: &'a [Statement]) -> (Vec<&'a str>, Vec<&'a str>) {
let mut classes = Vec::new();
let mut typenames = Vec::new();
for stmt in stmts.iter() {
@ -134,9 +136,9 @@ pub fn get_typenames<'b: 'a, 'a>(stmts: &'b [Statement]) -> (Vec<&'a str>, Vec<&
(classes, unknowns)
}
fn resolve_function<'b: 'a, 'a>(
fn resolve_function<'a>(
ctx: &'a TopLevelContext,
fun: &'b StatementType,
fun: &'a StatementType,
method: bool,
) -> Result<FnDef, String> {
if let StatementType::FunctionDef { args, returns, .. } = &fun {
@ -159,7 +161,7 @@ fn resolve_function<'b: 'a, 'a>(
}
}
pub fn resolve_signatures<'b: 'a, 'a>(ctx: &mut TopLevelContext<'a>, stmts: &'b [Statement]) {
pub fn resolve_signatures<'a>(ctx: &mut TopLevelContext<'a>, stmts: &'a [Statement]) {
for stmt in stmts.iter() {
match &stmt.node {
StatementType::ClassDef {