Dumper - Handle property getters/setters
This commit is contained in:
parent
ddb2c94ae5
commit
f2637fb319
1 changed files with 33 additions and 1 deletions
|
@ -1,7 +1,9 @@
|
||||||
use std::fmt::Write;
|
use std::fmt::Write;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
ast::{BinaryExpr, ClassMemberDecl, ExprNode, FunDecl, ProgramNode, StmtNode},
|
ast::{
|
||||||
|
BinaryExpr, ClassMemberDecl, ExprNode, FunDecl, ProgramNode, PropertyAccessor, StmtNode,
|
||||||
|
},
|
||||||
tokens::Token,
|
tokens::Token,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -58,6 +60,24 @@ fn dump_method(dumper: &mut Dumper, method: &FunDecl, is_static: bool) {
|
||||||
dumper.add_line("}".to_owned());
|
dumper.add_line("}".to_owned());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn dump_accessor(
|
||||||
|
dumper: &mut Dumper,
|
||||||
|
accessor: &PropertyAccessor,
|
||||||
|
is_setter: bool,
|
||||||
|
is_static: bool,
|
||||||
|
) {
|
||||||
|
dumper.add_line(format!(
|
||||||
|
"{}{} {} {{",
|
||||||
|
if is_static { "static " } else { "" },
|
||||||
|
accessor.name.lexeme,
|
||||||
|
if is_setter { "<" } else { ">" },
|
||||||
|
));
|
||||||
|
dumper.depth += 1;
|
||||||
|
dump_statement_list(dumper, &accessor.body);
|
||||||
|
dumper.depth -= 1;
|
||||||
|
dumper.add_line("}".to_owned());
|
||||||
|
}
|
||||||
|
|
||||||
fn dump_statement(dumper: &mut Dumper, stmt: &StmtNode) {
|
fn dump_statement(dumper: &mut Dumper, stmt: &StmtNode) {
|
||||||
match stmt {
|
match stmt {
|
||||||
StmtNode::VarDecl(name, Some(expr)) => {
|
StmtNode::VarDecl(name, Some(expr)) => {
|
||||||
|
@ -94,6 +114,18 @@ fn dump_statement(dumper: &mut Dumper, stmt: &StmtNode) {
|
||||||
match &member {
|
match &member {
|
||||||
ClassMemberDecl::Method(method) => dump_method(dumper, method, false),
|
ClassMemberDecl::Method(method) => dump_method(dumper, method, false),
|
||||||
ClassMemberDecl::StaticMethod(method) => dump_method(dumper, method, true),
|
ClassMemberDecl::StaticMethod(method) => dump_method(dumper, method, true),
|
||||||
|
ClassMemberDecl::PropertyGetter(accessor) => {
|
||||||
|
dump_accessor(dumper, accessor, false, false)
|
||||||
|
}
|
||||||
|
ClassMemberDecl::PropertySetter(accessor) => {
|
||||||
|
dump_accessor(dumper, accessor, true, false)
|
||||||
|
}
|
||||||
|
ClassMemberDecl::StaticPropertyGetter(accessor) => {
|
||||||
|
dump_accessor(dumper, accessor, false, true)
|
||||||
|
}
|
||||||
|
ClassMemberDecl::StaticPropertySetter(accessor) => {
|
||||||
|
dump_accessor(dumper, accessor, true, true)
|
||||||
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
dumper.depth -= 1;
|
dumper.depth -= 1;
|
||||||
|
|
Loading…
Reference in a new issue