110 lines
3.1 KiB
Rust
110 lines
3.1 KiB
Rust
use crate::name_analysis::symbol::parameter_symbol::ParameterSymbol;
|
|
use crate::name_analysis::symbol::source_definition::SourceDefinition;
|
|
use crate::name_analysis::symbol::type_symbol::TypeSymbol;
|
|
use crate::name_analysis::symbol::Symbol;
|
|
use crate::name_analysis::util::join_fqn_parts;
|
|
use std::cell::RefCell;
|
|
use std::fmt::{Debug, Formatter};
|
|
use std::rc::Rc;
|
|
|
|
pub struct FunctionSymbol {
|
|
fqn_parts: Vec<Rc<str>>,
|
|
is_public: bool,
|
|
is_platform: bool,
|
|
source_definition: Option<SourceDefinition>,
|
|
parameters: Vec<Rc<RefCell<ParameterSymbol>>>,
|
|
return_type: Option<TypeSymbol>,
|
|
}
|
|
|
|
impl FunctionSymbol {
|
|
pub fn new(
|
|
fqn_parts: &[Rc<str>],
|
|
is_public: bool,
|
|
is_platform: bool,
|
|
source_definition: Option<SourceDefinition>,
|
|
) -> FunctionSymbol {
|
|
FunctionSymbol {
|
|
fqn_parts: fqn_parts.to_vec(),
|
|
is_public,
|
|
is_platform,
|
|
source_definition,
|
|
parameters: Vec::new(),
|
|
return_type: None,
|
|
}
|
|
}
|
|
|
|
pub fn with_parameters_and_return_type(
|
|
fqn_parts: &[Rc<str>],
|
|
is_public: bool,
|
|
is_platform: bool,
|
|
source_definition: Option<SourceDefinition>,
|
|
parameters: &[Rc<RefCell<ParameterSymbol>>],
|
|
return_type: Option<TypeSymbol>,
|
|
) -> Self {
|
|
Self {
|
|
fqn_parts: fqn_parts.to_vec(),
|
|
is_public,
|
|
is_platform,
|
|
source_definition,
|
|
parameters: parameters.to_vec(),
|
|
return_type,
|
|
}
|
|
}
|
|
|
|
pub fn fqn_parts_owned(&self) -> Vec<Rc<str>> {
|
|
self.fqn_parts.to_vec()
|
|
}
|
|
|
|
pub fn declared_name(&self) -> &str {
|
|
self.fqn_parts.last().unwrap().as_ref()
|
|
}
|
|
|
|
pub fn declared_name_owned(&self) -> Rc<str> {
|
|
self.fqn_parts.last().unwrap().clone()
|
|
}
|
|
|
|
pub fn is_public(&self) -> bool {
|
|
self.is_public
|
|
}
|
|
|
|
pub fn is_platform(&self) -> bool {
|
|
self.is_platform
|
|
}
|
|
|
|
pub fn parameter_symbols(&self) -> &[Rc<RefCell<ParameterSymbol>>] {
|
|
&self.parameters
|
|
}
|
|
|
|
pub fn set_parameter_symbols(&mut self, parameter_symbols: Vec<Rc<RefCell<ParameterSymbol>>>) {
|
|
self.parameters = parameter_symbols;
|
|
}
|
|
|
|
pub fn return_type(&self) -> Option<&TypeSymbol> {
|
|
self.return_type.as_ref()
|
|
}
|
|
|
|
pub fn set_return_type(&mut self, type_symbol: TypeSymbol) {
|
|
self.return_type = Some(type_symbol);
|
|
}
|
|
}
|
|
|
|
impl Symbol for FunctionSymbol {
|
|
fn source_definition(&self) -> Option<&SourceDefinition> {
|
|
self.source_definition.as_ref()
|
|
}
|
|
}
|
|
|
|
impl Debug for FunctionSymbol {
|
|
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
|
f.debug_struct("FunctionSymbol")
|
|
.field("fqn", &join_fqn_parts(&self.fqn_parts))
|
|
.field("declared_name", &self.declared_name())
|
|
.field("is_public", &self.is_public)
|
|
.field("is_platform", &self.is_platform)
|
|
.field("parameters", &self.parameters)
|
|
.field("return_type", &self.return_type)
|
|
.field("source_definition", &self.source_definition)
|
|
.finish()
|
|
}
|
|
}
|