forked from M-Labs/nac3
proper constant handling
This commit is contained in:
parent
03712e3762
commit
95789ec303
@ -7,6 +7,7 @@ use rustpython_parser::ast::{
|
||||
UnaryOperator,
|
||||
};
|
||||
use std::collections::HashMap;
|
||||
use std::convert::TryInto;
|
||||
use std::rc::Rc;
|
||||
|
||||
type SymTable<'a> = HashMap<&'a str, Rc<Type>>;
|
||||
@ -48,6 +49,7 @@ pub fn parse_expr(ctx: &GlobalContext, sym_table: &SymTable, expr: &Expression)
|
||||
}
|
||||
_ => Err("only list comprehension is supported".into()),
|
||||
},
|
||||
ExpressionType::True | ExpressionType::False => Ok(Some(PrimitiveType(BOOL_TYPE).into())),
|
||||
_ => Err("not supported".into()),
|
||||
}
|
||||
}
|
||||
@ -59,16 +61,18 @@ fn parse_constant(
|
||||
) -> ParserResult {
|
||||
use rustpython_parser::ast::Number;
|
||||
match value {
|
||||
Number::Integer { .. } => {
|
||||
// not check the range now
|
||||
Ok(Some(PrimitiveType(INT32_TYPE).into()))
|
||||
// if i32::try_from(&value).is_ok() {
|
||||
// Ok(PrimitiveType(INT32_TYPE).into())
|
||||
// } else if i64::try_from(&value).is_ok() {
|
||||
// Ok(PrimitiveType(INT64_TYPE).into())
|
||||
// } else {
|
||||
// Err("integer out of range".into())
|
||||
// }
|
||||
Number::Integer { value } => {
|
||||
let int32: Result<i32, _> = value.try_into();
|
||||
if int32.is_ok() {
|
||||
Ok(Some(PrimitiveType(INT32_TYPE).into()))
|
||||
} else {
|
||||
let int64: Result<i64, _> = value.try_into();
|
||||
if int64.is_ok() {
|
||||
Ok(Some(PrimitiveType(INT64_TYPE).into()))
|
||||
} else {
|
||||
Err("integer out of range".into())
|
||||
}
|
||||
}
|
||||
}
|
||||
Number::Float { .. } => Ok(Some(PrimitiveType(FLOAT_TYPE).into())),
|
||||
_ => Err("not supported".into()),
|
||||
|
Loading…
Reference in New Issue
Block a user