nac3parser: add comment support #68
|
@ -186,7 +186,7 @@ pub fn gen_while<'ctx, 'a, G: CodeGenerator + ?Sized>(
|
|||
ctx: &mut CodeGenContext<'ctx, 'a>,
|
||||
stmt: &Stmt<Option<Type>>,
|
||||
) {
|
||||
if let StmtKind::While { test, body, orelse } = &stmt.node {
|
||||
if let StmtKind::While { test, body, orelse, .. } = &stmt.node {
|
||||
let current = ctx.builder.get_insert_block().unwrap().get_parent().unwrap();
|
||||
let test_bb = ctx.ctx.append_basic_block(current, "test");
|
||||
let body_bb = ctx.ctx.append_basic_block(current, "body");
|
||||
|
@ -228,7 +228,7 @@ pub fn gen_if<'ctx, 'a, G: CodeGenerator + ?Sized>(
|
|||
ctx: &mut CodeGenContext<'ctx, 'a>,
|
||||
stmt: &Stmt<Option<Type>>,
|
||||
) -> bool {
|
||||
if let StmtKind::If { test, body, orelse } = &stmt.node {
|
||||
if let StmtKind::If { test, body, orelse, .. } = &stmt.node {
|
||||
let current = ctx.builder.get_insert_block().unwrap().get_parent().unwrap();
|
||||
let test_bb = ctx.ctx.append_basic_block(current, "test");
|
||||
let body_bb = ctx.ctx.append_basic_block(current, "body");
|
||||
|
@ -306,11 +306,11 @@ pub fn gen_stmt<'ctx, 'a, G: CodeGenerator + ?Sized>(
|
|||
stmt: &Stmt<Option<Type>>,
|
||||
) -> bool {
|
||||
match &stmt.node {
|
||||
StmtKind::Pass => {}
|
||||
StmtKind::Expr { value } => {
|
||||
StmtKind::Pass { .. } => {}
|
||||
StmtKind::Expr { value, .. } => {
|
||||
generator.gen_expr(ctx, value);
|
||||
}
|
||||
StmtKind::Return { value } => {
|
||||
StmtKind::Return { value, .. } => {
|
||||
let value = value.as_ref().map(|v| generator.gen_expr(ctx, v).unwrap());
|
||||
let value = value.as_ref().map(|v| v as &dyn BasicValue);
|
||||
ctx.builder.build_return(value);
|
||||
|
@ -328,11 +328,11 @@ pub fn gen_stmt<'ctx, 'a, G: CodeGenerator + ?Sized>(
|
|||
generator.gen_assign(ctx, target, value);
|
||||
}
|
||||
}
|
||||
StmtKind::Continue => {
|
||||
StmtKind::Continue { .. } => {
|
||||
ctx.builder.build_unconditional_branch(ctx.loop_bb.unwrap().0);
|
||||
return true;
|
||||
}
|
||||
StmtKind::Break => {
|
||||
StmtKind::Break { .. }=> {
|
||||
ctx.builder.build_unconditional_branch(ctx.loop_bb.unwrap().1);
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -1395,8 +1395,8 @@ impl TopLevelComposer {
|
|||
return Err("unsupported statement type in class definition body".into());
|
||||
}
|
||||
}
|
||||
ast::StmtKind::Pass => {}
|
||||
ast::StmtKind::Expr { value: _ } => {} // typically a docstring; ignoring all expressions matches CPython behavior
|
||||
ast::StmtKind::Pass { .. } => {}
|
||||
ast::StmtKind::Expr { value: _, .. } => {} // typically a docstring; ignoring all expressions matches CPython behavior
|
||||
_ => return Err("unsupported statement type in class definition body".into()),
|
||||
}
|
||||
}
|
||||
|
|
|
@ -337,7 +337,7 @@ impl TopLevelComposer {
|
|||
ast::StmtKind::With { body, .. } => {
|
||||
result.extend(Self::get_all_assigned_field(body.as_slice())?);
|
||||
}
|
||||
ast::StmtKind::Pass => {}
|
||||
ast::StmtKind::Pass { .. } => {}
|
||||
ast::StmtKind::Assert { .. } => {}
|
||||
ast::StmtKind::Expr { .. } => {}
|
||||
|
||||
|
|
|
@ -196,7 +196,7 @@ impl<'a> Inferencer<'a> {
|
|||
}
|
||||
Ok(false)
|
||||
}
|
||||
StmtKind::If { test, body, orelse } => {
|
||||
StmtKind::If { test, body, orelse, .. } => {
|
||||
self.check_expr(test, defined_identifiers)?;
|
||||
self.should_have_value(test)?;
|
||||
let mut body_identifiers = defined_identifiers.clone();
|
||||
|
@ -211,7 +211,7 @@ impl<'a> Inferencer<'a> {
|
|||
}
|
||||
Ok(body_returned && orelse_returned)
|
||||
}
|
||||
StmtKind::While { test, body, orelse } => {
|
||||
StmtKind::While { test, body, orelse, .. } => {
|
||||
self.check_expr(test, defined_identifiers)?;
|
||||
self.should_have_value(test)?;
|
||||
let mut defined_identifiers = defined_identifiers.clone();
|
||||
|
@ -230,7 +230,7 @@ impl<'a> Inferencer<'a> {
|
|||
self.check_block(body, &mut new_defined_identifiers)?;
|
||||
Ok(false)
|
||||
}
|
||||
StmtKind::Expr { value } => {
|
||||
StmtKind::Expr { value, .. } => {
|
||||
self.check_expr(value, defined_identifiers)?;
|
||||
Ok(false)
|
||||
}
|
||||
|
@ -250,7 +250,7 @@ impl<'a> Inferencer<'a> {
|
|||
}
|
||||
Ok(false)
|
||||
}
|
||||
StmtKind::Return { value } => {
|
||||
StmtKind::Return { value, .. } => {
|
||||
if let Some(value) = value {
|
||||
self.check_expr(value, defined_identifiers)?;
|
||||
self.should_have_value(value)?;
|
||||
|
|
|
@ -80,7 +80,7 @@ impl<'a> fold::Fold<()> for Inferencer<'a> {
|
|||
fn fold_stmt(&mut self, node: ast::Stmt<()>) -> Result<ast::Stmt<Self::TargetU>, Self::Error> {
|
||||
let stmt = match node.node {
|
||||
// we don't want fold over type annotation
|
||||
ast::StmtKind::AnnAssign { target, annotation, value, simple } => {
|
||||
ast::StmtKind::AnnAssign { target, annotation, value, simple, config_comment } => {
|
||||
self.infer_pattern(&target)?;
|
||||
let target = Box::new(self.fold_expr(*target)?);
|
||||
let value = if let Some(v) = value {
|
||||
|
@ -105,14 +105,14 @@ impl<'a> fold::Fold<()> for Inferencer<'a> {
|
|||
Located {
|
||||
location: node.location,
|
||||
custom: None,
|
||||
node: ast::StmtKind::AnnAssign { target, annotation, value, simple },
|
||||
node: ast::StmtKind::AnnAssign { target, annotation, value, simple, config_comment },
|
||||
}
|
||||
}
|
||||
ast::StmtKind::For { ref target, .. } => {
|
||||
self.infer_pattern(target)?;
|
||||
fold::fold_stmt(self, node)?
|
||||
}
|
||||
ast::StmtKind::Assign { ref targets, .. } => {
|
||||
ast::StmtKind::Assign { ref targets, ref config_comment, .. } => {
|
||||
if targets.iter().all(|t| matches!(t.node, ast::ExprKind::Name { .. })) {
|
||||
if let ast::StmtKind::Assign { targets, value, .. } = node.node {
|
||||
let value = self.fold_expr(*value)?;
|
||||
|
@ -158,6 +158,7 @@ impl<'a> fold::Fold<()> for Inferencer<'a> {
|
|||
targets,
|
||||
value: Box::new(value),
|
||||
type_comment: None,
|
||||
config_comment: config_comment.clone()
|
||||
},
|
||||
custom: None,
|
||||
});
|
||||
|
@ -198,7 +199,7 @@ impl<'a> fold::Fold<()> for Inferencer<'a> {
|
|||
}
|
||||
}
|
||||
ast::StmtKind::AnnAssign { .. } | ast::StmtKind::Expr { .. } => {}
|
||||
ast::StmtKind::Break | ast::StmtKind::Continue | ast::StmtKind::Pass => {}
|
||||
ast::StmtKind::Break { .. } | ast::StmtKind::Continue { .. } | ast::StmtKind::Pass { .. } => {}
|
||||
ast::StmtKind::With { items, .. } => {
|
||||
for item in items.iter() {
|
||||
let ty = item.context_expr.custom.unwrap();
|
||||
|
@ -272,7 +273,7 @@ impl<'a> fold::Fold<()> for Inferencer<'a> {
|
|||
}
|
||||
}
|
||||
}
|
||||
ast::StmtKind::Return { value } => match (value, self.function_data.return_type) {
|
||||
ast::StmtKind::Return { value, .. } => match (value, self.function_data.return_type) {
|
||||
(Some(v), Some(v1)) => {
|
||||
self.unify(v.custom.unwrap(), v1, &v.location)?;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue