102 lines
2.9 KiB
Rust
102 lines
2.9 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::ConcreteTypeSymbol;
|
|
use std::fmt::{Debug, Formatter};
|
|
|
|
#[derive(Clone)]
|
|
pub struct FunctionSymbol {
|
|
fqn: String,
|
|
declared_name: String,
|
|
is_public: bool,
|
|
is_platform: bool,
|
|
source_definition: Option<SourceDefinition>,
|
|
parameters: Vec<ParameterSymbol>,
|
|
return_type: Option<ConcreteTypeSymbol>, // todo: can we use TypeSymbol?
|
|
}
|
|
|
|
impl FunctionSymbol {
|
|
pub fn without_parameters_or_return_type(
|
|
fqn: &str,
|
|
declared_name: &str,
|
|
is_public: bool,
|
|
is_platform: bool,
|
|
source_definition: Option<SourceDefinition>,
|
|
) -> FunctionSymbol {
|
|
FunctionSymbol {
|
|
fqn: fqn.to_string(),
|
|
declared_name: declared_name.to_string(),
|
|
is_public,
|
|
is_platform,
|
|
source_definition,
|
|
parameters: Vec::new(),
|
|
return_type: None,
|
|
}
|
|
}
|
|
|
|
pub fn with_parameters(self, parameters: Vec<ParameterSymbol>) -> Self {
|
|
Self {
|
|
fqn: self.fqn,
|
|
declared_name: self.declared_name,
|
|
is_public: self.is_public,
|
|
is_platform: self.is_platform,
|
|
source_definition: self.source_definition,
|
|
parameters,
|
|
return_type: self.return_type,
|
|
}
|
|
}
|
|
|
|
pub fn with_return_type(self, return_type: ConcreteTypeSymbol) -> Self {
|
|
Self {
|
|
fqn: self.fqn,
|
|
declared_name: self.declared_name,
|
|
is_public: self.is_public,
|
|
is_platform: self.is_platform,
|
|
source_definition: self.source_definition,
|
|
parameters: self.parameters,
|
|
return_type: Some(return_type),
|
|
}
|
|
}
|
|
|
|
pub fn fqn(&self) -> &str {
|
|
&self.fqn
|
|
}
|
|
|
|
pub fn declared_name(&self) -> &str {
|
|
&self.declared_name
|
|
}
|
|
|
|
pub fn is_public(&self) -> bool {
|
|
self.is_public
|
|
}
|
|
|
|
pub fn is_platform(&self) -> bool {
|
|
self.is_platform
|
|
}
|
|
|
|
pub fn source_definition(&self) -> Option<&SourceDefinition> {
|
|
self.source_definition.as_ref()
|
|
}
|
|
|
|
pub fn parameters(&self) -> &[ParameterSymbol] {
|
|
&self.parameters
|
|
}
|
|
|
|
pub fn return_type(&self) -> Option<&ConcreteTypeSymbol> {
|
|
self.return_type.as_ref()
|
|
}
|
|
}
|
|
|
|
impl Debug for FunctionSymbol {
|
|
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
|
f.debug_struct("FunctionSymbol")
|
|
.field("fqn", &self.fqn)
|
|
.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()
|
|
}
|
|
}
|