mirror of
https://github.com/erg-lang/erg.git
synced 2025-08-04 02:39:20 +00:00
method_name: Option<Token> -> Option<Identifier>
This commit is contained in:
parent
892ab6df2f
commit
7a682db817
6 changed files with 55 additions and 25 deletions
|
@ -1024,7 +1024,7 @@ impl CodeGenerator {
|
|||
}
|
||||
}
|
||||
|
||||
fn emit_call_method(&mut self, obj: Expr, method_name: Token, args: Args) {
|
||||
fn emit_call_method(&mut self, obj: Expr, method_name: Identifier, args: Args) {
|
||||
log!(info "entered {}", fn_name!());
|
||||
if &method_name.inspect()[..] == "update!" {
|
||||
return self.emit_call_update(obj, args);
|
||||
|
@ -1035,7 +1035,7 @@ impl CodeGenerator {
|
|||
self.emit_load_method_instr(
|
||||
&class,
|
||||
uniq_obj_name.as_ref().map(|s| &s[..]),
|
||||
method_name.content,
|
||||
method_name.name.into_token().content,
|
||||
)
|
||||
.unwrap_or_else(|err| {
|
||||
self.errs.push(err);
|
||||
|
|
|
@ -11,7 +11,7 @@ use erg_common::{enum_unwrap, fmt_option, fmt_slice, log, set};
|
|||
use Type::*;
|
||||
|
||||
use ast::VarName;
|
||||
use erg_parser::ast;
|
||||
use erg_parser::ast::{self, Identifier};
|
||||
use erg_parser::token::Token;
|
||||
|
||||
use erg_type::constructors::{func, mono, mono_proj, poly, ref_, ref_mut, refinement, subr_t};
|
||||
|
@ -332,7 +332,7 @@ impl Context {
|
|||
fn search_callee_t(
|
||||
&self,
|
||||
obj: &hir::Expr,
|
||||
method_name: &Option<Token>,
|
||||
method_name: &Option<Identifier>,
|
||||
namespace: &Str,
|
||||
) -> TyCheckResult<Type> {
|
||||
if let Some(method_name) = method_name.as_ref() {
|
||||
|
@ -592,7 +592,7 @@ impl Context {
|
|||
fn substitute_call(
|
||||
&self,
|
||||
obj: &hir::Expr,
|
||||
method_name: &Option<Token>,
|
||||
method_name: &Option<Identifier>,
|
||||
instance: &Type,
|
||||
pos_args: &[hir::PosArg],
|
||||
kw_args: &[hir::KwArg],
|
||||
|
@ -605,8 +605,12 @@ impl Context {
|
|||
self.substitute_call(obj, method_name, &refine.t, pos_args, kw_args)
|
||||
}
|
||||
Type::Subr(subr) => {
|
||||
let callee = if let Some(name) = method_name {
|
||||
let attr = hir::Attribute::new(obj.clone(), name.clone(), Type::Uninited);
|
||||
let callee = if let Some(ident) = method_name {
|
||||
let attr = hir::Attribute::new(
|
||||
obj.clone(),
|
||||
ident.name.clone().into_token(),
|
||||
Type::Uninited,
|
||||
);
|
||||
let acc = hir::Expr::Accessor(hir::Accessor::Attr(attr));
|
||||
acc
|
||||
} else {
|
||||
|
@ -829,7 +833,7 @@ impl Context {
|
|||
pub(crate) fn get_call_t(
|
||||
&self,
|
||||
obj: &hir::Expr,
|
||||
method_name: &Option<Token>,
|
||||
method_name: &Option<Identifier>,
|
||||
pos_args: &[hir::PosArg],
|
||||
kw_args: &[hir::KwArg],
|
||||
namespace: &Str,
|
||||
|
@ -843,7 +847,7 @@ impl Context {
|
|||
let found = self.search_callee_t(obj, method_name, namespace)?;
|
||||
log!(
|
||||
"Found:\ncallee: {obj}{}\nfound: {found}",
|
||||
fmt_option!(pre ".", method_name.as_ref().map(|t| &t.content))
|
||||
fmt_option!(pre ".", method_name.as_ref().map(|ident| &ident.name))
|
||||
);
|
||||
let instance = self.instantiate(found, obj)?;
|
||||
log!(
|
||||
|
|
|
@ -937,7 +937,7 @@ impl UnaryOp {
|
|||
#[derive(Debug, Clone)]
|
||||
pub struct Call {
|
||||
pub obj: Box<Expr>,
|
||||
pub method_name: Option<Token>,
|
||||
pub method_name: Option<Identifier>,
|
||||
pub args: Args,
|
||||
/// 全体の型(引数自体の型は関係ない)、e.g. `abs(-1)` -> `Neg -> Nat`
|
||||
pub sig_t: Type,
|
||||
|
@ -949,7 +949,7 @@ impl NestedDisplay for Call {
|
|||
f,
|
||||
"({}){} (: {}):",
|
||||
self.obj,
|
||||
fmt_option!(pre ".", self.method_name.as_ref().map(|t| t.inspect())),
|
||||
fmt_option!(self.method_name),
|
||||
self.sig_t
|
||||
)?;
|
||||
self.args.fmt_nest(f, level + 1)
|
||||
|
@ -992,7 +992,7 @@ impl Locational for Call {
|
|||
}
|
||||
|
||||
impl Call {
|
||||
pub fn new(obj: Expr, method_name: Option<Token>, args: Args, sig_t: Type) -> Self {
|
||||
pub fn new(obj: Expr, method_name: Option<Identifier>, args: Args, sig_t: Type) -> Self {
|
||||
Self {
|
||||
obj: Box::new(obj),
|
||||
method_name,
|
||||
|
|
|
@ -384,11 +384,19 @@ impl ASTLowerer {
|
|||
let class = self.lower_expr(*pack.class)?;
|
||||
let args = self.lower_record(pack.args)?;
|
||||
let args = vec![hir::PosArg::new(hir::Expr::Record(args))];
|
||||
let method_name = Token::new(
|
||||
TokenKind::Symbol,
|
||||
Str::rc("new"),
|
||||
pack.connector.lineno,
|
||||
pack.connector.col_begin,
|
||||
let method_name = ast::Identifier::new(
|
||||
Some(Token::new(
|
||||
TokenKind::Dot,
|
||||
Str::ever("."),
|
||||
pack.connector.lineno,
|
||||
pack.connector.col_begin,
|
||||
)),
|
||||
ast::VarName::new(Token::new(
|
||||
TokenKind::Symbol,
|
||||
Str::ever("new"),
|
||||
pack.connector.lineno,
|
||||
pack.connector.col_begin,
|
||||
)),
|
||||
);
|
||||
let sig_t = self.ctx.get_call_t(
|
||||
&class,
|
||||
|
|
|
@ -856,7 +856,7 @@ impl UnaryOp {
|
|||
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
|
||||
pub struct Call {
|
||||
pub obj: Box<Expr>,
|
||||
pub method_name: Option<Token>,
|
||||
pub method_name: Option<Identifier>,
|
||||
pub args: Args,
|
||||
}
|
||||
|
||||
|
@ -864,7 +864,7 @@ impl NestedDisplay for Call {
|
|||
fn fmt_nest(&self, f: &mut std::fmt::Formatter<'_>, level: usize) -> std::fmt::Result {
|
||||
write!(f, "({})", self.obj)?;
|
||||
if let Some(method_name) = self.method_name.as_ref() {
|
||||
write!(f, ".{}", method_name.content)?;
|
||||
write!(f, "{}", method_name)?;
|
||||
}
|
||||
writeln!(f, ":")?;
|
||||
self.args.fmt_nest(f, level + 1)
|
||||
|
@ -884,7 +884,7 @@ impl Locational for Call {
|
|||
}
|
||||
|
||||
impl Call {
|
||||
pub fn new(obj: Expr, method_name: Option<Token>, args: Args) -> Self {
|
||||
pub fn new(obj: Expr, method_name: Option<Identifier>, args: Args) -> Self {
|
||||
Self {
|
||||
obj: Box::new(obj),
|
||||
method_name,
|
||||
|
@ -1777,7 +1777,7 @@ impl fmt::Display for Identifier {
|
|||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
match &self.dot {
|
||||
Some(_dot) => write!(f, ".{}", self.name),
|
||||
None => write!(f, "{}", self.name),
|
||||
None => write!(f, "::{}", self.name),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -980,7 +980,8 @@ impl Parser {
|
|||
.transpose()
|
||||
.map_err(|_| self.stack_dec())?
|
||||
{
|
||||
let call = Call::new(obj, Some(symbol), args);
|
||||
let ident = Identifier::new(None, VarName::new(symbol));
|
||||
let call = Call::new(obj, Some(ident), args);
|
||||
stack.push(ExprOrOp::Expr(Expr::Call(call)));
|
||||
} else {
|
||||
let acc = Accessor::attr(obj, vis, Local::new(symbol));
|
||||
|
@ -1038,7 +1039,8 @@ impl Parser {
|
|||
.transpose()
|
||||
.map_err(|_| self.stack_dec())?
|
||||
{
|
||||
let call = Call::new(obj, Some(symbol), args);
|
||||
let ident = Identifier::new(Some(vis), VarName::new(symbol));
|
||||
let call = Call::new(obj, Some(ident), args);
|
||||
stack.push(ExprOrOp::Expr(Expr::Call(call)));
|
||||
} else {
|
||||
let acc = Accessor::attr(obj, vis, Local::new(symbol));
|
||||
|
@ -1192,7 +1194,8 @@ impl Parser {
|
|||
.transpose()
|
||||
.map_err(|_| self.stack_dec())?
|
||||
{
|
||||
let call = Call::new(obj, Some(symbol), args);
|
||||
let ident = Identifier::new(Some(vis), VarName::new(symbol));
|
||||
let call = Call::new(obj, Some(ident), args);
|
||||
stack.push(ExprOrOp::Expr(Expr::Call(call)));
|
||||
} else {
|
||||
let acc = Accessor::attr(obj, vis, Local::new(symbol));
|
||||
|
@ -1382,7 +1385,22 @@ impl Parser {
|
|||
if let Some(res) = self.opt_reduce_args() {
|
||||
let args = res.map_err(|_| self.stack_dec())?;
|
||||
let (obj, method_name) = match acc {
|
||||
Accessor::Attr(attr) => (*attr.obj, Some(attr.name.symbol)),
|
||||
Accessor::Attr(attr) => {
|
||||
if attr.vis.is(Dot) {
|
||||
(
|
||||
*attr.obj,
|
||||
Some(Identifier::new(
|
||||
Some(attr.vis),
|
||||
VarName::new(attr.name.symbol),
|
||||
)),
|
||||
)
|
||||
} else {
|
||||
(
|
||||
*attr.obj,
|
||||
Some(Identifier::new(None, VarName::new(attr.name.symbol))),
|
||||
)
|
||||
}
|
||||
}
|
||||
Accessor::Local(local) => (Expr::Accessor(Accessor::Local(local)), None),
|
||||
_ => todo!(),
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue