mirror of
https://github.com/erg-lang/erg.git
synced 2025-09-30 21:01:10 +00:00
Add Expr::Dummy
This commit is contained in:
parent
3841b9f676
commit
e1c8bb415b
9 changed files with 34 additions and 9 deletions
|
@ -2495,6 +2495,7 @@ impl PyCodeGenerator {
|
|||
self.emit_expr(*tasc.expr);
|
||||
}
|
||||
Expr::Import(acc) => self.emit_import(acc),
|
||||
Expr::Dummy(_) => {}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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(_) => {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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(_) => {}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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}"),
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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(),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue