1051 lines
29 KiB
Rust
1051 lines
29 KiB
Rust
use crate::ast::node::call_expression::*;
|
|
use crate::ast::node::class::*;
|
|
use crate::ast::node::closure::*;
|
|
use crate::ast::node::compilation_unit::*;
|
|
use crate::ast::node::d_string::*;
|
|
use crate::ast::node::expression::*;
|
|
use crate::ast::node::function::*;
|
|
use crate::ast::node::generics::*;
|
|
use crate::ast::node::implements_list::*;
|
|
use crate::ast::node::interface::*;
|
|
use crate::ast::node::level::*;
|
|
use crate::ast::node::literal::*;
|
|
use crate::ast::node::module::*;
|
|
use crate::ast::node::names::*;
|
|
use crate::ast::node::object_access::*;
|
|
use crate::ast::node::statement::*;
|
|
use crate::ast::node::tuple_arguments::*;
|
|
use crate::ast::node::type_use::*;
|
|
use crate::ast::node::use_statement::*;
|
|
|
|
pub enum NodeRef<'a> {
|
|
Identifier(&'a Identifier),
|
|
FullyQualifiedName(&'a FullyQualifiedName),
|
|
TypeUse(&'a TypeUse),
|
|
PrimitiveTypeUse(&'a PrimitiveTypeUse),
|
|
InterfaceOrClassTypeUse(&'a InterfaceOrClassTypeUse),
|
|
TupleTypeUse(&'a TupleTypeUse),
|
|
FunctionTypeUse(&'a FunctionTypeUse),
|
|
GenericArguments(&'a GenericArguments),
|
|
GenericParameters(&'a GenericParameters),
|
|
TupleArguments(&'a TupleArguments),
|
|
ImplementsList(&'a ImplementsList),
|
|
Parameters(&'a Parameters),
|
|
Parameter(&'a Parameter),
|
|
ReturnType(&'a ReturnType),
|
|
References(&'a References),
|
|
CompilationUnit(&'a CompilationUnit),
|
|
UseStatement(&'a UseStatement),
|
|
ModuleLevelDeclaration(&'a ModuleLevelDeclaration),
|
|
InterfaceLevelDeclaration(&'a InterfaceLevelDeclaration),
|
|
ClassLevelDeclaration(&'a ClassLevelDeclaration),
|
|
ModuleDeclaration(&'a ModuleDeclaration),
|
|
InterfaceDeclaration(&'a InterfaceDeclaration),
|
|
ClassDeclaration(&'a ClassDeclaration),
|
|
FunctionDefinition(&'a FunctionDefinition),
|
|
OperatorFunctionDefinition(&'a OperatorFunctionDefinition),
|
|
PlatformFunctionDeclaration(&'a PlatformFunctionDeclaration),
|
|
InterfaceFunctionDeclaration(&'a InterfaceFunctionDeclaration),
|
|
InterfaceOperatorFunctionDeclaration(&'a InterfaceOperatorFunctionDeclaration),
|
|
FunctionBody(&'a FunctionBody),
|
|
ClassConstructor(&'a ClassConstructor),
|
|
ClassConstructorParameter(&'a ClassConstructorParameter),
|
|
PropertyDeclaration(&'a PropertyDeclaration),
|
|
FieldDeclaration(&'a FieldDeclaration),
|
|
BlockStatement(&'a BlockStatement),
|
|
Statement(&'a Statement),
|
|
VariableDeclarationStatement(&'a VariableDeclarationStatement),
|
|
AssignStatement(&'a AssignStatement),
|
|
CallStatement(&'a CallStatement),
|
|
ReturnStatement(&'a ReturnStatement),
|
|
IfStatement(&'a IfStatement),
|
|
IfElseStatement(&'a IfElseStatement),
|
|
ElseIfs(&'a ElseIfs),
|
|
ElseBlock(&'a ElseBlock),
|
|
WhileStatement(&'a WhileStatement),
|
|
ForStatement(&'a ForStatement),
|
|
Expression(&'a Expression),
|
|
TernaryExpression(&'a TernaryExpression),
|
|
BinaryExpression(&'a BinaryExpression),
|
|
PrefixExpression(&'a PrefixExpression),
|
|
SuffixExpression(&'a SuffixExpression),
|
|
CallExpression(&'a CallExpression),
|
|
TurboFish(&'a TurboFish),
|
|
CallArguments(&'a CallArguments),
|
|
CallArgument(&'a CallArgument),
|
|
Closure(&'a Closure),
|
|
ClosureCaptures(&'a ClosureCaptures),
|
|
ClosureCapture(&'a ClosureCapture),
|
|
ClosureParameters(&'a ClosureParameters),
|
|
ClosureParameter(&'a ClosureParameter),
|
|
ObjectAccess(&'a ObjectAccess),
|
|
ObjectNavigations(&'a ObjectNavigations),
|
|
ObjectNavigation(&'a ObjectNavigation),
|
|
Literal(&'a Literal),
|
|
DString(&'a DString),
|
|
DStringPart(&'a DStringPart),
|
|
}
|
|
|
|
pub trait NodeInner {
|
|
fn children(&self) -> Vec<NodeRef>;
|
|
|
|
fn as_node_ref(&self) -> NodeRef;
|
|
}
|
|
|
|
impl NodeInner for Identifier {
|
|
fn children(&self) -> Vec<NodeRef> {
|
|
vec![]
|
|
}
|
|
|
|
fn as_node_ref(&self) -> NodeRef {
|
|
NodeRef::Identifier(self)
|
|
}
|
|
}
|
|
|
|
impl NodeInner for FullyQualifiedName {
|
|
fn children(&self) -> Vec<NodeRef> {
|
|
self.identifiers()
|
|
.iter()
|
|
.map(|id| NodeRef::Identifier(*id))
|
|
.collect()
|
|
}
|
|
|
|
fn as_node_ref(&self) -> NodeRef {
|
|
NodeRef::FullyQualifiedName(self)
|
|
}
|
|
}
|
|
|
|
impl NodeInner for TypeUse {
|
|
fn children(&self) -> Vec<NodeRef> {
|
|
match self {
|
|
TypeUse::Primitive(primitive_type_use) => primitive_type_use.children(),
|
|
TypeUse::InterfaceOrClass(interface_or_class_type_use) => {
|
|
interface_or_class_type_use.children()
|
|
}
|
|
TypeUse::Tuple(tuple_type_use) => tuple_type_use.children(),
|
|
TypeUse::Function(function_type_use) => function_type_use.children(),
|
|
}
|
|
}
|
|
|
|
fn as_node_ref(&self) -> NodeRef {
|
|
NodeRef::TypeUse(self)
|
|
}
|
|
}
|
|
|
|
impl NodeInner for PrimitiveTypeUse {
|
|
fn children(&self) -> Vec<NodeRef> {
|
|
match self {
|
|
PrimitiveTypeUse::Array(generics) => {
|
|
if let Some(generics) = generics {
|
|
vec![NodeRef::GenericArguments(&generics)]
|
|
} else {
|
|
vec![]
|
|
}
|
|
}
|
|
_ => vec![],
|
|
}
|
|
}
|
|
|
|
fn as_node_ref(&self) -> NodeRef {
|
|
NodeRef::PrimitiveTypeUse(self)
|
|
}
|
|
}
|
|
|
|
impl NodeInner for InterfaceOrClassTypeUse {
|
|
fn children(&self) -> Vec<NodeRef> {
|
|
let mut children = vec![];
|
|
children.push(NodeRef::FullyQualifiedName(self.fqn()));
|
|
children.push(NodeRef::GenericArguments(self.generics()));
|
|
children
|
|
}
|
|
|
|
fn as_node_ref(&self) -> NodeRef {
|
|
NodeRef::InterfaceOrClassTypeUse(self)
|
|
}
|
|
}
|
|
|
|
impl NodeInner for TupleTypeUse {
|
|
fn children(&self) -> Vec<NodeRef> {
|
|
vec![NodeRef::TupleArguments(self.arguments())]
|
|
}
|
|
|
|
fn as_node_ref(&self) -> NodeRef {
|
|
NodeRef::TupleTypeUse(self)
|
|
}
|
|
}
|
|
|
|
impl NodeInner for FunctionTypeUse {
|
|
fn children(&self) -> Vec<NodeRef> {
|
|
vec![
|
|
NodeRef::GenericParameters(self.generics()),
|
|
NodeRef::Parameters(self.parameters()),
|
|
NodeRef::ReturnType(self.return_type()),
|
|
]
|
|
}
|
|
|
|
fn as_node_ref(&self) -> NodeRef {
|
|
NodeRef::FunctionTypeUse(self)
|
|
}
|
|
}
|
|
|
|
impl NodeInner for GenericArguments {
|
|
fn children(&self) -> Vec<NodeRef> {
|
|
self.arguments()
|
|
.iter()
|
|
.map(|type_use| NodeRef::TypeUse(*type_use))
|
|
.collect()
|
|
}
|
|
|
|
fn as_node_ref(&self) -> NodeRef {
|
|
NodeRef::GenericArguments(self)
|
|
}
|
|
}
|
|
|
|
impl NodeInner for GenericParameters {
|
|
fn children(&self) -> Vec<NodeRef> {
|
|
self.identifiers()
|
|
.iter()
|
|
.map(|id| NodeRef::Identifier(*id))
|
|
.collect()
|
|
}
|
|
|
|
fn as_node_ref(&self) -> NodeRef {
|
|
NodeRef::GenericParameters(self)
|
|
}
|
|
}
|
|
|
|
impl NodeInner for TupleArguments {
|
|
fn children(&self) -> Vec<NodeRef> {
|
|
self.type_uses()
|
|
.iter()
|
|
.map(|type_use| NodeRef::TypeUse(*type_use))
|
|
.collect()
|
|
}
|
|
|
|
fn as_node_ref(&self) -> NodeRef {
|
|
NodeRef::TupleArguments(self)
|
|
}
|
|
}
|
|
|
|
impl NodeInner for ImplementsList {
|
|
fn children(&self) -> Vec<NodeRef> {
|
|
self.type_uses()
|
|
.iter()
|
|
.map(|type_use| NodeRef::TypeUse(*type_use))
|
|
.collect()
|
|
}
|
|
|
|
fn as_node_ref(&self) -> NodeRef {
|
|
NodeRef::ImplementsList(self)
|
|
}
|
|
}
|
|
|
|
impl NodeInner for Parameters {
|
|
fn children(&self) -> Vec<NodeRef> {
|
|
self.parameters()
|
|
.iter()
|
|
.map(|parameter| NodeRef::Parameter(*parameter))
|
|
.collect()
|
|
}
|
|
|
|
fn as_node_ref(&self) -> NodeRef {
|
|
NodeRef::Parameters(self)
|
|
}
|
|
}
|
|
|
|
impl NodeInner for Parameter {
|
|
fn children(&self) -> Vec<NodeRef> {
|
|
vec![
|
|
NodeRef::Identifier(self.identifier()),
|
|
NodeRef::TypeUse(self.type_use()),
|
|
]
|
|
}
|
|
|
|
fn as_node_ref(&self) -> NodeRef {
|
|
NodeRef::Parameter(self)
|
|
}
|
|
}
|
|
|
|
impl NodeInner for ReturnType {
|
|
fn children(&self) -> Vec<NodeRef> {
|
|
vec![
|
|
NodeRef::TypeUse(self.declared_type()),
|
|
NodeRef::References(self.references()),
|
|
]
|
|
}
|
|
|
|
fn as_node_ref(&self) -> NodeRef {
|
|
NodeRef::ReturnType(self)
|
|
}
|
|
}
|
|
|
|
impl NodeInner for References {
|
|
fn children(&self) -> Vec<NodeRef> {
|
|
self.identifiers()
|
|
.iter()
|
|
.map(|identifier| NodeRef::Identifier(*identifier))
|
|
.collect()
|
|
}
|
|
|
|
fn as_node_ref(&self) -> NodeRef {
|
|
NodeRef::References(self)
|
|
}
|
|
}
|
|
|
|
impl NodeInner for CompilationUnit {
|
|
fn children(&self) -> Vec<NodeRef> {
|
|
let mut children = vec![];
|
|
if let Some(namespace) = self.namespace() {
|
|
children.push(NodeRef::FullyQualifiedName(namespace));
|
|
}
|
|
children.extend(
|
|
self.use_statements()
|
|
.iter()
|
|
.map(|use_statement| NodeRef::UseStatement(*use_statement)),
|
|
);
|
|
children.extend(
|
|
self.declarations()
|
|
.iter()
|
|
.map(|declaration| NodeRef::ModuleLevelDeclaration(*declaration)),
|
|
);
|
|
children
|
|
}
|
|
|
|
fn as_node_ref(&self) -> NodeRef {
|
|
NodeRef::CompilationUnit(self)
|
|
}
|
|
}
|
|
|
|
impl NodeInner for UseStatement {
|
|
fn children(&self) -> Vec<NodeRef> {
|
|
let mut children = vec![];
|
|
match self {
|
|
UseStatement::Concrete(concrete_use_statement) => children.extend(
|
|
concrete_use_statement
|
|
.identifiers()
|
|
.iter()
|
|
.map(|identifier| NodeRef::Identifier(*identifier))
|
|
),
|
|
UseStatement::Star(_) => {}
|
|
}
|
|
children
|
|
}
|
|
|
|
fn as_node_ref(&self) -> NodeRef {
|
|
NodeRef::UseStatement(self)
|
|
}
|
|
}
|
|
|
|
impl NodeInner for ModuleLevelDeclaration {
|
|
fn children(&self) -> Vec<NodeRef> {
|
|
use crate::ast::node::level::ModuleLevelDeclaration::*;
|
|
match self {
|
|
Module(module_declaration) => module_declaration.children(),
|
|
Interface(interface_declaration) => interface_declaration.children(),
|
|
Class(class_declaration) => class_declaration.children(),
|
|
Function(function_definition) => function_definition.children(),
|
|
PlatformFunction(platform_function_declaration) => {
|
|
platform_function_declaration.children()
|
|
}
|
|
}
|
|
}
|
|
|
|
fn as_node_ref(&self) -> NodeRef {
|
|
NodeRef::ModuleLevelDeclaration(self)
|
|
}
|
|
}
|
|
|
|
impl NodeInner for InterfaceLevelDeclaration {
|
|
fn children(&self) -> Vec<NodeRef> {
|
|
use crate::ast::node::level::InterfaceLevelDeclaration::*;
|
|
match self {
|
|
Module(module_declaration) => module_declaration.children(),
|
|
Interface(interface_declaration) => interface_declaration.children(),
|
|
Class(class_declaration) => class_declaration.children(),
|
|
Function(function_declaration) => function_declaration.children(),
|
|
OperatorFunction(operator_function_declaration) => {
|
|
operator_function_declaration.children()
|
|
}
|
|
}
|
|
}
|
|
|
|
fn as_node_ref(&self) -> NodeRef {
|
|
NodeRef::InterfaceLevelDeclaration(self)
|
|
}
|
|
}
|
|
|
|
impl NodeInner for ClassLevelDeclaration {
|
|
fn children(&self) -> Vec<NodeRef> {
|
|
use crate::ast::node::level::ClassLevelDeclaration::*;
|
|
match self {
|
|
Module(module_declaration) => module_declaration.children(),
|
|
Interface(interface_declaration) => interface_declaration.children(),
|
|
Class(class_declaration) => class_declaration.children(),
|
|
Function(function_definition) => function_definition.children(),
|
|
OperatorFunction(operator_function_definition) => {
|
|
operator_function_definition.children()
|
|
}
|
|
PlatformFunction(platform_function_declaration) => {
|
|
platform_function_declaration.children()
|
|
}
|
|
Property(property_declaration) => property_declaration.children(),
|
|
Field(field_declaration) => field_declaration.children(),
|
|
}
|
|
}
|
|
|
|
fn as_node_ref(&self) -> NodeRef {
|
|
NodeRef::ClassLevelDeclaration(self)
|
|
}
|
|
}
|
|
|
|
impl NodeInner for ModuleDeclaration {
|
|
fn children(&self) -> Vec<NodeRef> {
|
|
let mut children = vec![];
|
|
children.push(NodeRef::Identifier(self.identifier()));
|
|
children.extend(
|
|
self.declarations()
|
|
.iter()
|
|
.map(|declaration| NodeRef::ModuleLevelDeclaration(*declaration)),
|
|
);
|
|
children
|
|
}
|
|
|
|
fn as_node_ref(&self) -> NodeRef {
|
|
NodeRef::ModuleDeclaration(self)
|
|
}
|
|
}
|
|
|
|
impl NodeInner for InterfaceDeclaration {
|
|
fn children(&self) -> Vec<NodeRef> {
|
|
let mut children = vec![];
|
|
children.push(NodeRef::Identifier(self.identifier()));
|
|
children.push(NodeRef::GenericParameters(self.generics()));
|
|
children.push(NodeRef::ImplementsList(self.implements()));
|
|
children.extend(
|
|
self.declarations()
|
|
.iter()
|
|
.map(|declaration| NodeRef::InterfaceLevelDeclaration(*declaration)),
|
|
);
|
|
children
|
|
}
|
|
|
|
fn as_node_ref(&self) -> NodeRef {
|
|
NodeRef::InterfaceDeclaration(self)
|
|
}
|
|
}
|
|
|
|
impl NodeInner for ClassDeclaration {
|
|
fn children(&self) -> Vec<NodeRef> {
|
|
let mut children = vec![];
|
|
children.push(NodeRef::Identifier(self.identifier()));
|
|
children.push(NodeRef::GenericParameters(self.generics()));
|
|
if let Some(class_constructor) = self.class_constructor() {
|
|
children.push(NodeRef::ClassConstructor(class_constructor));
|
|
}
|
|
children.push(NodeRef::ImplementsList(self.implements()));
|
|
children.extend(
|
|
self.declarations()
|
|
.iter()
|
|
.map(|declaration| NodeRef::ClassLevelDeclaration(*declaration)),
|
|
);
|
|
children
|
|
}
|
|
|
|
fn as_node_ref(&self) -> NodeRef {
|
|
NodeRef::ClassDeclaration(self)
|
|
}
|
|
}
|
|
|
|
impl NodeInner for FunctionDefinition {
|
|
fn children(&self) -> Vec<NodeRef> {
|
|
vec![
|
|
NodeRef::GenericParameters(self.generics()),
|
|
NodeRef::Identifier(self.identifier()),
|
|
NodeRef::Parameters(self.parameters()),
|
|
NodeRef::ReturnType(self.return_type()),
|
|
NodeRef::FunctionBody(self.body()),
|
|
]
|
|
}
|
|
|
|
fn as_node_ref(&self) -> NodeRef {
|
|
NodeRef::FunctionDefinition(self)
|
|
}
|
|
}
|
|
|
|
impl NodeInner for OperatorFunctionDefinition {
|
|
fn children(&self) -> Vec<NodeRef> {
|
|
vec![
|
|
NodeRef::GenericParameters(self.generics()),
|
|
NodeRef::Parameters(self.parameters()),
|
|
NodeRef::ReturnType(self.return_type()),
|
|
NodeRef::FunctionBody(self.body()),
|
|
]
|
|
}
|
|
|
|
fn as_node_ref(&self) -> NodeRef {
|
|
NodeRef::OperatorFunctionDefinition(self)
|
|
}
|
|
}
|
|
|
|
impl NodeInner for PlatformFunctionDeclaration {
|
|
fn children(&self) -> Vec<NodeRef> {
|
|
vec![
|
|
NodeRef::GenericParameters(self.generics()),
|
|
NodeRef::Identifier(self.identifier()),
|
|
NodeRef::Parameters(self.parameters()),
|
|
NodeRef::ReturnType(self.return_type()),
|
|
]
|
|
}
|
|
|
|
fn as_node_ref(&self) -> NodeRef {
|
|
NodeRef::PlatformFunctionDeclaration(self)
|
|
}
|
|
}
|
|
|
|
impl NodeInner for InterfaceFunctionDeclaration {
|
|
fn children(&self) -> Vec<NodeRef> {
|
|
let mut children = vec![
|
|
NodeRef::GenericParameters(self.generics()),
|
|
NodeRef::Identifier(self.identifier()),
|
|
NodeRef::Parameters(self.parameters()),
|
|
NodeRef::ReturnType(self.return_type()),
|
|
];
|
|
if let Some(body) = self.body() {
|
|
children.push(NodeRef::FunctionBody(body))
|
|
}
|
|
children
|
|
}
|
|
|
|
fn as_node_ref(&self) -> NodeRef {
|
|
NodeRef::InterfaceFunctionDeclaration(self)
|
|
}
|
|
}
|
|
|
|
impl NodeInner for InterfaceOperatorFunctionDeclaration {
|
|
fn children(&self) -> Vec<NodeRef> {
|
|
let mut children = vec![
|
|
NodeRef::GenericParameters(self.generics()),
|
|
NodeRef::Parameters(self.parameters()),
|
|
NodeRef::ReturnType(self.return_type()),
|
|
];
|
|
if let Some(body) = self.body() {
|
|
children.push(NodeRef::FunctionBody(body))
|
|
}
|
|
children
|
|
}
|
|
|
|
fn as_node_ref(&self) -> NodeRef {
|
|
NodeRef::InterfaceOperatorFunctionDeclaration(self)
|
|
}
|
|
}
|
|
|
|
impl NodeInner for FunctionBody {
|
|
fn children(&self) -> Vec<NodeRef> {
|
|
match self {
|
|
Self::Equals(expression) => expression.children(),
|
|
Self::Block(block_statement) => block_statement.children(),
|
|
Self::Alias(identifier) => vec![NodeRef::Identifier(identifier.as_ref())],
|
|
}
|
|
}
|
|
|
|
fn as_node_ref(&self) -> NodeRef {
|
|
NodeRef::FunctionBody(self)
|
|
}
|
|
}
|
|
|
|
impl NodeInner for ClassConstructor {
|
|
fn children(&self) -> Vec<NodeRef> {
|
|
self.parameters()
|
|
.iter()
|
|
.map(|parameter| NodeRef::ClassConstructorParameter(*parameter))
|
|
.collect()
|
|
}
|
|
|
|
fn as_node_ref(&self) -> NodeRef {
|
|
NodeRef::ClassConstructor(self)
|
|
}
|
|
}
|
|
|
|
impl NodeInner for ClassConstructorParameter {
|
|
fn children(&self) -> Vec<NodeRef> {
|
|
match self {
|
|
Self::Property(property_declaration) => property_declaration.children(),
|
|
Self::Field(field_declaration) => field_declaration.children(),
|
|
}
|
|
}
|
|
|
|
fn as_node_ref(&self) -> NodeRef {
|
|
NodeRef::ClassConstructorParameter(self)
|
|
}
|
|
}
|
|
|
|
impl NodeInner for PropertyDeclaration {
|
|
fn children(&self) -> Vec<NodeRef> {
|
|
vec![
|
|
NodeRef::Identifier(self.identifier()),
|
|
NodeRef::TypeUse(self.declared_type()),
|
|
]
|
|
}
|
|
|
|
fn as_node_ref(&self) -> NodeRef {
|
|
NodeRef::PropertyDeclaration(self)
|
|
}
|
|
}
|
|
|
|
impl NodeInner for FieldDeclaration {
|
|
fn children(&self) -> Vec<NodeRef> {
|
|
vec![
|
|
NodeRef::Identifier(self.identifier()),
|
|
NodeRef::TypeUse(self.declared_type()),
|
|
]
|
|
}
|
|
|
|
fn as_node_ref(&self) -> NodeRef {
|
|
NodeRef::FieldDeclaration(self)
|
|
}
|
|
}
|
|
|
|
impl NodeInner for BlockStatement {
|
|
fn children(&self) -> Vec<NodeRef> {
|
|
let mut children = vec![];
|
|
children.extend(
|
|
self.statements()
|
|
.iter()
|
|
.map(|statement| NodeRef::Statement(statement)),
|
|
);
|
|
if let Some(expression) = self.expression() {
|
|
children.push(NodeRef::Expression(expression));
|
|
}
|
|
children
|
|
}
|
|
|
|
fn as_node_ref(&self) -> NodeRef {
|
|
NodeRef::BlockStatement(self)
|
|
}
|
|
}
|
|
|
|
impl NodeInner for Statement {
|
|
fn children(&self) -> Vec<NodeRef> {
|
|
use crate::ast::node::statement::Statement::*;
|
|
match self {
|
|
BlockStatement(block_statement) => block_statement.children(),
|
|
VariableDeclarationStatement(variable_declaration_statement) => {
|
|
variable_declaration_statement.children()
|
|
}
|
|
AssignStatement(assign_statement) => assign_statement.children(),
|
|
CallStatement(call_statement) => call_statement.children(),
|
|
ReturnStatement(return_statement) => return_statement.children(),
|
|
IfStatement(if_statement) => if_statement.children(),
|
|
IfElseStatement(if_else_statement) => if_else_statement.children(),
|
|
WhileStatement(while_statement) => while_statement.children(),
|
|
ForStatement(for_statement) => for_statement.children(),
|
|
}
|
|
}
|
|
|
|
fn as_node_ref(&self) -> NodeRef {
|
|
NodeRef::Statement(self)
|
|
}
|
|
}
|
|
|
|
impl NodeInner for VariableDeclarationStatement {
|
|
fn children(&self) -> Vec<NodeRef> {
|
|
let mut children = vec![];
|
|
children.push(NodeRef::Identifier(self.identifier()));
|
|
if let Some(declared_type) = self.declared_type() {
|
|
children.push(NodeRef::TypeUse(declared_type));
|
|
}
|
|
if let Some(initializer) = self.initializer() {
|
|
children.push(NodeRef::Expression(initializer));
|
|
}
|
|
children
|
|
}
|
|
|
|
fn as_node_ref(&self) -> NodeRef {
|
|
NodeRef::VariableDeclarationStatement(self)
|
|
}
|
|
}
|
|
|
|
impl NodeInner for AssignStatement {
|
|
fn children(&self) -> Vec<NodeRef> {
|
|
vec![
|
|
NodeRef::Expression(self.lhs()),
|
|
NodeRef::Expression(self.rhs()),
|
|
]
|
|
}
|
|
|
|
fn as_node_ref(&self) -> NodeRef {
|
|
NodeRef::AssignStatement(self)
|
|
}
|
|
}
|
|
|
|
impl NodeInner for CallStatement {
|
|
fn children(&self) -> Vec<NodeRef> {
|
|
vec![NodeRef::Expression(self.expression())]
|
|
}
|
|
|
|
fn as_node_ref(&self) -> NodeRef {
|
|
NodeRef::CallStatement(self)
|
|
}
|
|
}
|
|
|
|
impl NodeInner for ReturnStatement {
|
|
fn children(&self) -> Vec<NodeRef> {
|
|
if let Some(expression) = self.expression() {
|
|
vec![NodeRef::Expression(expression)]
|
|
} else {
|
|
vec![]
|
|
}
|
|
}
|
|
|
|
fn as_node_ref(&self) -> NodeRef {
|
|
NodeRef::ReturnStatement(self)
|
|
}
|
|
}
|
|
|
|
impl NodeInner for IfStatement {
|
|
fn children(&self) -> Vec<NodeRef> {
|
|
vec![
|
|
NodeRef::Expression(self.condition()),
|
|
NodeRef::BlockStatement(self.then_block()),
|
|
]
|
|
}
|
|
|
|
fn as_node_ref(&self) -> NodeRef {
|
|
NodeRef::IfStatement(self)
|
|
}
|
|
}
|
|
|
|
impl NodeInner for IfElseStatement {
|
|
fn children(&self) -> Vec<NodeRef> {
|
|
let mut children = vec![];
|
|
children.push(NodeRef::IfStatement(self.if_statement()));
|
|
children.push(NodeRef::ElseIfs(self.else_ifs()));
|
|
if let Some(else_block) = self.else_block() {
|
|
children.push(NodeRef::ElseBlock(else_block));
|
|
}
|
|
children
|
|
}
|
|
|
|
fn as_node_ref(&self) -> NodeRef {
|
|
NodeRef::IfElseStatement(self)
|
|
}
|
|
}
|
|
|
|
impl NodeInner for ElseIfs {
|
|
fn children(&self) -> Vec<NodeRef> {
|
|
self.if_statements()
|
|
.iter()
|
|
.map(|statement| NodeRef::IfStatement(statement))
|
|
.collect()
|
|
}
|
|
|
|
fn as_node_ref(&self) -> NodeRef {
|
|
NodeRef::ElseIfs(self)
|
|
}
|
|
}
|
|
|
|
impl NodeInner for ElseBlock {
|
|
fn children(&self) -> Vec<NodeRef> {
|
|
vec![NodeRef::BlockStatement(self.block_statement())]
|
|
}
|
|
|
|
fn as_node_ref(&self) -> NodeRef {
|
|
NodeRef::ElseBlock(self)
|
|
}
|
|
}
|
|
|
|
impl NodeInner for WhileStatement {
|
|
fn children(&self) -> Vec<NodeRef> {
|
|
vec![
|
|
NodeRef::Expression(self.condition()),
|
|
NodeRef::BlockStatement(self.body()),
|
|
]
|
|
}
|
|
|
|
fn as_node_ref(&self) -> NodeRef {
|
|
NodeRef::WhileStatement(self)
|
|
}
|
|
}
|
|
|
|
impl NodeInner for ForStatement {
|
|
fn children(&self) -> Vec<NodeRef> {
|
|
vec![
|
|
NodeRef::Identifier(self.variable()),
|
|
NodeRef::Expression(self.iterator()),
|
|
NodeRef::BlockStatement(self.body()),
|
|
]
|
|
}
|
|
|
|
fn as_node_ref(&self) -> NodeRef {
|
|
NodeRef::ForStatement(self)
|
|
}
|
|
}
|
|
|
|
impl NodeInner for Expression {
|
|
fn children(&self) -> Vec<NodeRef> {
|
|
use crate::ast::node::expression::Expression::*;
|
|
match self {
|
|
Ternary(ternary) => ternary.children(),
|
|
Binary(binary) => binary.children(),
|
|
UnaryPrefix(prefix) => prefix.children(),
|
|
UnarySuffix(suffix) => suffix.children(),
|
|
Call(call) => call.children(),
|
|
ObjectAccess(object_access) => object_access.children(),
|
|
Literal(literal) => literal.children(),
|
|
FullyQualifiedName(fully_qualified_name) => fully_qualified_name.children(),
|
|
Closure(closure) => closure.children(),
|
|
}
|
|
}
|
|
|
|
fn as_node_ref(&self) -> NodeRef {
|
|
NodeRef::Expression(self)
|
|
}
|
|
}
|
|
|
|
impl NodeInner for TernaryExpression {
|
|
fn children(&self) -> Vec<NodeRef> {
|
|
vec![
|
|
NodeRef::Expression(self.condition()),
|
|
NodeRef::Expression(self.true_expression()),
|
|
NodeRef::Expression(self.false_expression()),
|
|
]
|
|
}
|
|
|
|
fn as_node_ref(&self) -> NodeRef {
|
|
NodeRef::TernaryExpression(self)
|
|
}
|
|
}
|
|
|
|
impl NodeInner for BinaryExpression {
|
|
fn children(&self) -> Vec<NodeRef> {
|
|
vec![
|
|
NodeRef::Expression(self.left()),
|
|
NodeRef::Expression(self.right()),
|
|
]
|
|
}
|
|
|
|
fn as_node_ref(&self) -> NodeRef {
|
|
NodeRef::BinaryExpression(self)
|
|
}
|
|
}
|
|
|
|
impl NodeInner for PrefixExpression {
|
|
fn children(&self) -> Vec<NodeRef> {
|
|
vec![NodeRef::Expression(self.expression())]
|
|
}
|
|
|
|
fn as_node_ref(&self) -> NodeRef {
|
|
NodeRef::PrefixExpression(self)
|
|
}
|
|
}
|
|
|
|
impl NodeInner for SuffixExpression {
|
|
fn children(&self) -> Vec<NodeRef> {
|
|
vec![NodeRef::Expression(self.expression())]
|
|
}
|
|
|
|
fn as_node_ref(&self) -> NodeRef {
|
|
NodeRef::SuffixExpression(self)
|
|
}
|
|
}
|
|
|
|
impl NodeInner for CallExpression {
|
|
fn children(&self) -> Vec<NodeRef> {
|
|
let mut children = vec![];
|
|
children.push(NodeRef::Expression(self.callee()));
|
|
if let Some(turbo_fish) = self.turbo_fish() {
|
|
children.push(NodeRef::TurboFish(turbo_fish));
|
|
}
|
|
children.push(NodeRef::CallArguments(self.arguments()));
|
|
children
|
|
}
|
|
|
|
fn as_node_ref(&self) -> NodeRef {
|
|
NodeRef::CallExpression(self)
|
|
}
|
|
}
|
|
|
|
impl NodeInner for TurboFish {
|
|
fn children(&self) -> Vec<NodeRef> {
|
|
vec![NodeRef::GenericArguments(self.generics())]
|
|
}
|
|
|
|
fn as_node_ref(&self) -> NodeRef {
|
|
NodeRef::TurboFish(self)
|
|
}
|
|
}
|
|
|
|
impl NodeInner for CallArguments {
|
|
fn children(&self) -> Vec<NodeRef> {
|
|
self.arguments()
|
|
.iter()
|
|
.map(|argument| NodeRef::CallArgument(*argument))
|
|
.collect()
|
|
}
|
|
|
|
fn as_node_ref(&self) -> NodeRef {
|
|
NodeRef::CallArguments(self)
|
|
}
|
|
}
|
|
|
|
impl NodeInner for CallArgument {
|
|
fn children(&self) -> Vec<NodeRef> {
|
|
vec![NodeRef::Expression(self.expression())]
|
|
}
|
|
|
|
fn as_node_ref(&self) -> NodeRef {
|
|
NodeRef::CallArgument(self)
|
|
}
|
|
}
|
|
|
|
impl NodeInner for Closure {
|
|
fn children(&self) -> Vec<NodeRef> {
|
|
let mut children = vec![];
|
|
children.push(NodeRef::ClosureCaptures(self.captures()));
|
|
children.push(NodeRef::ClosureParameters(self.parameters()));
|
|
children.extend(
|
|
self.statements()
|
|
.iter()
|
|
.map(|statement| NodeRef::Statement(statement)),
|
|
);
|
|
if let Some(expression) = self.expression() {
|
|
children.push(NodeRef::Expression(expression));
|
|
}
|
|
children
|
|
}
|
|
|
|
fn as_node_ref(&self) -> NodeRef {
|
|
NodeRef::Closure(self)
|
|
}
|
|
}
|
|
|
|
impl NodeInner for ClosureCaptures {
|
|
fn children(&self) -> Vec<NodeRef> {
|
|
self.captures()
|
|
.iter()
|
|
.map(|capture| NodeRef::ClosureCapture(*capture))
|
|
.collect()
|
|
}
|
|
|
|
fn as_node_ref(&self) -> NodeRef {
|
|
NodeRef::ClosureCaptures(self)
|
|
}
|
|
}
|
|
|
|
impl NodeInner for ClosureCapture {
|
|
fn children(&self) -> Vec<NodeRef> {
|
|
vec![NodeRef::Identifier(self.identifier())]
|
|
}
|
|
|
|
fn as_node_ref(&self) -> NodeRef {
|
|
NodeRef::ClosureCapture(self)
|
|
}
|
|
}
|
|
|
|
impl NodeInner for ClosureParameters {
|
|
fn children(&self) -> Vec<NodeRef> {
|
|
self.parameters()
|
|
.iter()
|
|
.map(|parameter| NodeRef::ClosureParameter(*parameter))
|
|
.collect()
|
|
}
|
|
|
|
fn as_node_ref(&self) -> NodeRef {
|
|
NodeRef::ClosureParameters(self)
|
|
}
|
|
}
|
|
|
|
impl NodeInner for ClosureParameter {
|
|
fn children(&self) -> Vec<NodeRef> {
|
|
let mut children = vec![];
|
|
children.push(NodeRef::Identifier(self.identifier()));
|
|
if let Some(type_use) = self.type_use() {
|
|
children.push(NodeRef::TypeUse(type_use));
|
|
}
|
|
children
|
|
}
|
|
|
|
fn as_node_ref(&self) -> NodeRef {
|
|
NodeRef::ClosureParameter(self)
|
|
}
|
|
}
|
|
|
|
impl NodeInner for ObjectAccess {
|
|
fn children(&self) -> Vec<NodeRef> {
|
|
vec![
|
|
NodeRef::Expression(self.receiver()),
|
|
NodeRef::ObjectNavigations(self.navigations()),
|
|
]
|
|
}
|
|
|
|
fn as_node_ref(&self) -> NodeRef {
|
|
NodeRef::ObjectAccess(self)
|
|
}
|
|
}
|
|
|
|
impl NodeInner for ObjectNavigations {
|
|
fn children(&self) -> Vec<NodeRef> {
|
|
self.navigations()
|
|
.iter()
|
|
.map(|navigation| NodeRef::ObjectNavigation(*navigation))
|
|
.collect()
|
|
}
|
|
|
|
fn as_node_ref(&self) -> NodeRef {
|
|
NodeRef::ObjectNavigations(self)
|
|
}
|
|
}
|
|
|
|
impl NodeInner for ObjectNavigation {
|
|
fn children(&self) -> Vec<NodeRef> {
|
|
vec![match self {
|
|
ObjectNavigation::Identifier(identifier) => NodeRef::Identifier(identifier),
|
|
ObjectNavigation::Index(index_expression) => NodeRef::Expression(index_expression),
|
|
}]
|
|
}
|
|
|
|
fn as_node_ref(&self) -> NodeRef {
|
|
NodeRef::ObjectNavigation(self)
|
|
}
|
|
}
|
|
|
|
impl NodeInner for Literal {
|
|
fn children(&self) -> Vec<NodeRef> {
|
|
match self {
|
|
Literal::DString(d_string) => vec![NodeRef::DString(d_string)],
|
|
Literal::BacktickString(d_string) => vec![NodeRef::DString(d_string)],
|
|
_ => vec![],
|
|
}
|
|
}
|
|
|
|
fn as_node_ref(&self) -> NodeRef {
|
|
NodeRef::Literal(self)
|
|
}
|
|
}
|
|
|
|
impl NodeInner for DString {
|
|
fn children(&self) -> Vec<NodeRef> {
|
|
self.parts()
|
|
.iter()
|
|
.map(|part| NodeRef::DStringPart(*part))
|
|
.collect()
|
|
}
|
|
|
|
fn as_node_ref(&self) -> NodeRef {
|
|
NodeRef::DString(self)
|
|
}
|
|
}
|
|
|
|
impl NodeInner for DStringPart {
|
|
fn children(&self) -> Vec<NodeRef> {
|
|
match self {
|
|
DStringPart::Expression(expression) => vec![NodeRef::Expression(expression)],
|
|
_ => vec![],
|
|
}
|
|
}
|
|
|
|
fn as_node_ref(&self) -> NodeRef {
|
|
NodeRef::DStringPart(self)
|
|
}
|
|
}
|