1use serde::Deserialize;
2use serde::Serialize;
3use strum::Display;
4
5use mago_span::HasSpan;
6use mago_span::Span;
7
8use crate::ast::argument::ArgumentList;
9use crate::ast::class_like::member::ClassLikeMemberSelector;
10use crate::ast::expression::Expression;
11
12#[derive(Debug, Clone, Eq, PartialEq, Hash, Serialize, Deserialize, PartialOrd, Ord, Display)]
13#[serde(tag = "type", content = "value")]
14#[repr(C, u8)]
15pub enum Call {
16 Function(FunctionCall),
17 Method(MethodCall),
18 NullSafeMethod(NullSafeMethodCall),
19 StaticMethod(StaticMethodCall),
20}
21
22#[derive(Debug, Clone, Eq, PartialEq, Hash, Serialize, Deserialize, PartialOrd, Ord)]
23#[repr(C)]
24pub struct FunctionCall {
25 pub function: Box<Expression>,
26 pub argument_list: ArgumentList,
27}
28
29#[derive(Debug, Clone, Eq, PartialEq, Hash, Serialize, Deserialize, PartialOrd, Ord)]
30#[repr(C)]
31pub struct MethodCall {
32 pub object: Box<Expression>,
33 pub arrow: Span,
34 pub method: ClassLikeMemberSelector,
35 pub argument_list: ArgumentList,
36}
37
38#[derive(Debug, Clone, Eq, PartialEq, Hash, Serialize, Deserialize, PartialOrd, Ord)]
39#[repr(C)]
40pub struct NullSafeMethodCall {
41 pub object: Box<Expression>,
42 pub question_mark_arrow: Span,
43 pub method: ClassLikeMemberSelector,
44 pub argument_list: ArgumentList,
45}
46
47#[derive(Debug, Clone, Eq, PartialEq, Hash, Serialize, Deserialize, PartialOrd, Ord)]
48#[repr(C)]
49pub struct StaticMethodCall {
50 pub class: Box<Expression>,
51 pub double_colon: Span,
52 pub method: ClassLikeMemberSelector,
53 pub argument_list: ArgumentList,
54}
55
56impl Call {
57 #[inline]
58 pub fn get_argument_list(&self) -> &ArgumentList {
59 match self {
60 Call::Function(f) => &f.argument_list,
61 Call::Method(m) => &m.argument_list,
62 Call::NullSafeMethod(n) => &n.argument_list,
63 Call::StaticMethod(s) => &s.argument_list,
64 }
65 }
66}
67
68impl HasSpan for Call {
69 fn span(&self) -> Span {
70 match self {
71 Call::Function(f) => f.span(),
72 Call::Method(m) => m.span(),
73 Call::NullSafeMethod(n) => n.span(),
74 Call::StaticMethod(s) => s.span(),
75 }
76 }
77}
78
79impl HasSpan for FunctionCall {
80 fn span(&self) -> Span {
81 self.function.span().join(self.argument_list.span())
82 }
83}
84
85impl HasSpan for MethodCall {
86 fn span(&self) -> Span {
87 self.object.span().join(self.argument_list.span())
88 }
89}
90
91impl HasSpan for NullSafeMethodCall {
92 fn span(&self) -> Span {
93 self.object.span().join(self.argument_list.span())
94 }
95}
96
97impl HasSpan for StaticMethodCall {
98 fn span(&self) -> Span {
99 self.class.span().join(self.argument_list.span())
100 }
101}