make fields not public

This commit is contained in:
gluax 2022-04-07 11:18:58 -07:00
parent 8482430299
commit 016b669a8d
4 changed files with 31 additions and 12 deletions

View File

@ -44,14 +44,33 @@ impl fmt::Display for ParamMode {
pub struct FunctionInputVariable {
/// The name the parameter is accessible as in the function's body.
pub identifier: Identifier,
/// Is it a const parameter?
pub mode: ParamMode,
/// The mode of the function parameter.
mode: ParamMode,
/// What's the parameter's type?
pub type_: Type,
type_: Type,
/// The parameters span from any annotations to its type.
pub span: Span,
}
impl FunctionInputVariable {
pub fn new(identifier: Identifier, mode: ParamMode, type_: Type, span: Span) -> Self {
Self {
identifier,
mode,
type_,
span,
}
}
pub fn mode(&self) -> ParamMode {
self.mode
}
pub fn type_(&self) -> Type {
self.type_.clone()
}
}
impl FunctionInputVariable {
fn format(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{} ", self.mode)?;

View File

@ -282,7 +282,7 @@ impl<R: ReconstructingReducer> ReconstructingDirector<R> {
variable: &FunctionInputVariable,
) -> Result<FunctionInputVariable> {
let identifier = self.reduce_identifier(&variable.identifier)?;
let type_ = self.reduce_type(&variable.type_, &variable.span)?;
let type_ = self.reduce_type(&variable.type_(), &variable.span)?;
self.reducer.reduce_function_input_variable(variable, identifier, type_)
}

View File

@ -272,12 +272,12 @@ pub trait ReconstructingReducer {
identifier: Identifier,
type_: Type,
) -> Result<FunctionInputVariable> {
Ok(FunctionInputVariable {
Ok(FunctionInputVariable::new(
identifier,
mode: variable.mode,
variable.mode(),
type_,
span: variable.span.clone(),
})
variable.span.clone(),
))
}
fn reduce_function_input(&mut self, _input: &FunctionInput, new: FunctionInput) -> Result<FunctionInput> {

View File

@ -91,12 +91,12 @@ impl ParserContext<'_> {
self.expect(Token::Colon)?;
let type_ = self.parse_type()?.0;
Ok(FunctionInput::Variable(FunctionInputVariable {
Ok(FunctionInput::Variable(FunctionInputVariable::new(
name.clone(),
mode,
type_,
span: name.span.clone(),
identifier: name,
}))
name.span,
)))
}
/// Returns an [`(Identifier, Function)`] AST node if the next tokens represent a function name