Add Expr::Dummy

This commit is contained in:
Shunsuke Shibayama 2022-12-11 18:28:20 +09:00
parent 3841b9f676
commit e1c8bb415b
9 changed files with 34 additions and 9 deletions

View file

@ -2495,6 +2495,7 @@ impl PyCodeGenerator {
self.emit_expr(*tasc.expr);
}
Expr::Import(acc) => self.emit_import(acc),
Expr::Dummy(_) => {}
}
}

View file

@ -621,7 +621,7 @@ impl Context {
fn resolve_expr_t(&self, expr: &mut hir::Expr) -> SingleTyCheckResult<()> {
match expr {
hir::Expr::Lit(_) => Ok(()),
hir::Expr::Lit(_) | hir::Expr::Dummy(_) => Ok(()),
hir::Expr::Accessor(acc) => {
let loc = acc.loc();
let t = acc.ref_mut_t();

View file

@ -191,7 +191,11 @@ impl SideEffectChecker {
self.path_stack.pop();
self.block_stack.pop();
}
other => todo!("{other}"),
Expr::AttrDef(_)
| Expr::Code(_)
| Expr::Compound(_)
| Expr::Import(_)
| Expr::Dummy(_) => {}
}
}
log!(info "the side-effects checking process has completed, found errors: {}{RESET}", self.errs.len());
@ -275,6 +279,7 @@ impl SideEffectChecker {
/// ```
fn check_expr(&mut self, expr: &Expr) {
match expr {
Expr::Lit(_) => {}
Expr::Def(def) => {
self.check_def(def);
}
@ -399,7 +404,11 @@ impl SideEffectChecker {
));
}
}
_ => {}
Expr::AttrDef(_)
| Expr::Code(_)
| Expr::Compound(_)
| Expr::Import(_)
| Expr::Dummy(_) => {}
}
}
}

View file

@ -2225,13 +2225,14 @@ pub enum Expr {
Code(Block), // code object
Compound(Block), // compound statement
Import(Accessor),
Dummy(Block), // for mapping to Python AST
}
impl_nested_display_for_chunk_enum!(Expr; Lit, Accessor, Array, Tuple, Dict, Record, BinOp, UnaryOp, Call, Lambda, Def, ClassDef, PatchDef, AttrDef, Code, Compound, TypeAsc, Set, Import);
impl_no_type_display_for_enum!(Expr; Lit, Accessor, Array, Tuple, Dict, Record, BinOp, UnaryOp, Call, Lambda, Def, ClassDef, PatchDef, AttrDef, Code, Compound, TypeAsc, Set, Import);
impl_nested_display_for_chunk_enum!(Expr; Lit, Accessor, Array, Tuple, Dict, Record, BinOp, UnaryOp, Call, Lambda, Def, ClassDef, PatchDef, AttrDef, Code, Compound, TypeAsc, Set, Import, Dummy);
impl_no_type_display_for_enum!(Expr; Lit, Accessor, Array, Tuple, Dict, Record, BinOp, UnaryOp, Call, Lambda, Def, ClassDef, PatchDef, AttrDef, Code, Compound, TypeAsc, Set, Import, Dummy);
impl_display_from_nested!(Expr);
impl_locational_for_enum!(Expr; Lit, Accessor, Array, Tuple, Dict, Record, BinOp, UnaryOp, Call, Lambda, Def, ClassDef, PatchDef, AttrDef, Code, Compound, TypeAsc, Set, Import);
impl_t_for_enum!(Expr; Lit, Accessor, Array, Tuple, Dict, Record, BinOp, UnaryOp, Call, Lambda, Def, ClassDef, PatchDef, AttrDef, Code, Compound, TypeAsc, Set, Import);
impl_locational_for_enum!(Expr; Lit, Accessor, Array, Tuple, Dict, Record, BinOp, UnaryOp, Call, Lambda, Def, ClassDef, PatchDef, AttrDef, Code, Compound, TypeAsc, Set, Import, Dummy);
impl_t_for_enum!(Expr; Lit, Accessor, Array, Tuple, Dict, Record, BinOp, UnaryOp, Call, Lambda, Def, ClassDef, PatchDef, AttrDef, Code, Compound, TypeAsc, Set, Import, Dummy);
impl Default for Expr {
fn default() -> Self {

View file

@ -158,6 +158,7 @@ impl<'a> Linker<'a> {
}
}
Expr::Import(_) => unreachable!(),
Expr::Dummy(_) => {}
}
}
@ -279,6 +280,7 @@ impl<'a> Linker<'a> {
}
}
Expr::Import(_) => unreachable!(),
Expr::Dummy(_) => {}
}
}

View file

@ -1765,6 +1765,8 @@ impl ASTLowerer {
ast::Expr::PatchDef(defs) => Ok(hir::Expr::PatchDef(self.lower_patch_def(defs)?)),
ast::Expr::AttrDef(adef) => Ok(hir::Expr::AttrDef(self.lower_attr_def(adef)?)),
ast::Expr::TypeAsc(tasc) => Ok(hir::Expr::TypeAsc(self.lower_type_asc(tasc)?)),
// Checking is also performed for expressions in Dummy. However, it has no meaning in code generation
ast::Expr::Dummy(dummy) => Ok(hir::Expr::Dummy(self.lower_block(dummy)?)),
other => todo!("{other}"),
}
}

View file

@ -411,6 +411,7 @@ impl ScriptGenerator {
}
Expr::TypeAsc(tasc) => self.transpile_expr(*tasc.expr),
Expr::Code(_) => todo!("transpiling importing user-defined code"),
Expr::Dummy(_) => "".to_string(),
}
}

View file

@ -3527,11 +3527,13 @@ pub enum Expr {
ClassDef(ClassDef),
PatchDef(PatchDef),
AttrDef(AttrDef),
/// for mapping to Python AST
Dummy(Block),
}
impl_nested_display_for_chunk_enum!(Expr; Lit, Accessor, Array, Tuple, Dict, Set, Record, BinOp, UnaryOp, Call, DataPack, Lambda, TypeAsc, Def, Methods, ClassDef, PatchDef, AttrDef);
impl_nested_display_for_chunk_enum!(Expr; Lit, Accessor, Array, Tuple, Dict, Set, Record, BinOp, UnaryOp, Call, DataPack, Lambda, TypeAsc, Def, Methods, ClassDef, PatchDef, AttrDef, Dummy);
impl_display_from_nested!(Expr);
impl_locational_for_enum!(Expr; Lit, Accessor, Array, Tuple, Dict, Set, Record, BinOp, UnaryOp, Call, DataPack, Lambda, TypeAsc, Def, Methods, ClassDef, PatchDef, AttrDef);
impl_locational_for_enum!(Expr; Lit, Accessor, Array, Tuple, Dict, Set, Record, BinOp, UnaryOp, Call, DataPack, Lambda, TypeAsc, Def, Methods, ClassDef, PatchDef, AttrDef, Dummy);
impl Expr {
pub fn is_match_call(&self) -> bool {

View file

@ -296,6 +296,13 @@ impl Desugarer {
Expr::Methods(Methods::new(method_defs.class, method_defs.vis, new_attrs))
}
Expr::Accessor(acc) => Expr::Accessor(Self::perform_desugar_acc(desugar, acc)),
Expr::Dummy(exprs) => {
let mut chunks = vec![];
for chunk in exprs.into_iter() {
chunks.push(desugar(chunk));
}
Expr::Dummy(Block::new(chunks))
}
}
}