Skip to content

Commit

Permalink
Renames FieldSource to FieldExpr
Browse files Browse the repository at this point in the history
  • Loading branch information
zslayton committed Dec 17, 2024
1 parent 64615df commit 8bf5fec
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 49 deletions.
26 changes: 13 additions & 13 deletions src/lazy/decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ impl<D: Decoder> HasRange for LazyRawFieldExpr<'_, D> {
// function while also preventing users from seeing or depending on it.
pub(crate) mod private {
use crate::lazy::expanded::macro_evaluator::{MacroExpr, RawEExpression};
use crate::lazy::expanded::r#struct::FieldSource;
use crate::lazy::expanded::r#struct::FieldExpr;
use crate::lazy::expanded::EncodingContextRef;
use crate::{try_next, try_or_some_err, IonResult, LazyExpandedValue, LazyRawFieldName};

Expand All @@ -398,41 +398,41 @@ pub(crate) mod private {
/// Creates an iterator that converts each raw struct field into an `UnexpandedField`, a
/// common representation for both raw fields and template fields that is used in the
/// expansion process.
fn unexpanded_fields(
fn field_exprs(
&self,
context: EncodingContextRef<'top>,
) -> RawStructFieldSourceIterator<'top, D>;
) -> RawStructFieldExprIterator<'top, D>;
}

pub struct RawStructFieldSourceIterator<'top, D: Decoder> {
pub struct RawStructFieldExprIterator<'top, D: Decoder> {
context: EncodingContextRef<'top>,
raw_fields: <D::Struct<'top> as LazyRawStruct<'top, D>>::Iterator,
}

impl<'top, D: Decoder> RawStructFieldSourceIterator<'top, D> {
impl<'top, D: Decoder> RawStructFieldExprIterator<'top, D> {
pub fn context(&self) -> EncodingContextRef<'top> {
self.context
}
}

impl<'top, D: Decoder> Iterator for RawStructFieldSourceIterator<'top, D> {
type Item = IonResult<FieldSource<'top, D>>;
impl<'top, D: Decoder> Iterator for RawStructFieldExprIterator<'top, D> {
type Item = IonResult<FieldExpr<'top, D>>;

fn next(&mut self) -> Option<Self::Item> {
let field: LazyRawFieldExpr<'top, D> = try_next!(self.raw_fields.next());
use LazyRawFieldExpr::*;
let unexpanded_field = match field {
NameValue(name, value) => FieldSource::NameValue(
NameValue(name, value) => FieldExpr::NameValue(
name.resolve(self.context),
LazyExpandedValue::from_literal(self.context, value),
),
NameEExp(name, raw_eexp) => {
let eexp = try_or_some_err!(raw_eexp.resolve(self.context));
FieldSource::NameMacro(name.resolve(self.context), MacroExpr::from_eexp(eexp))
FieldExpr::NameMacro(name.resolve(self.context), MacroExpr::from_eexp(eexp))
}
EExp(raw_eexp) => {
let eexp = try_or_some_err!(raw_eexp.resolve(self.context));
FieldSource::Macro(MacroExpr::from_eexp(eexp))
FieldExpr::Macro(MacroExpr::from_eexp(eexp))
}
};
Some(Ok(unexpanded_field))
Expand All @@ -443,12 +443,12 @@ pub(crate) mod private {
where
S: LazyRawStruct<'top, D>,
{
fn unexpanded_fields(
fn field_exprs(
&self,
context: EncodingContextRef<'top>,
) -> RawStructFieldSourceIterator<'top, D> {
) -> RawStructFieldExprIterator<'top, D> {
let raw_fields = <Self as LazyRawStruct<'top, D>>::iter(self);
RawStructFieldSourceIterator {
RawStructFieldExprIterator {
context,
raw_fields,
}
Expand Down
54 changes: 27 additions & 27 deletions src/lazy/expanded/struct.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
use crate::element::iterators::SymbolsIterator;
use crate::lazy::decoder::private::{LazyRawStructPrivate, RawStructFieldSourceIterator};
use crate::lazy::decoder::private::{LazyRawStructPrivate, RawStructFieldExprIterator};
use crate::lazy::decoder::{Decoder, LazyRawFieldName, LazyRawStruct};
use crate::lazy::expanded::macro_evaluator::{
MacroEvaluator, MacroExpr, MacroExprArgsIterator, ValueExpr,
};
use crate::lazy::expanded::r#struct::tooling::FieldSourceIterator;
use crate::lazy::expanded::r#struct::tooling::FieldExprIterator;

Check failure on line 7 in src/lazy/expanded/struct.rs

View workflow job for this annotation

GitHub Actions / Build and Test (al2-x86, default)

unresolved import `crate::lazy::expanded::r#struct::tooling`

Check failure on line 7 in src/lazy/expanded/struct.rs

View workflow job for this annotation

GitHub Actions / Build and Test (al2-arm, default)

unresolved import `crate::lazy::expanded::r#struct::tooling`

Check failure on line 7 in src/lazy/expanded/struct.rs

View workflow job for this annotation

GitHub Actions / Build and Test (al2-x86, experimental-ion-hash)

unresolved import `crate::lazy::expanded::r#struct::tooling`

Check failure on line 7 in src/lazy/expanded/struct.rs

View workflow job for this annotation

GitHub Actions / Build and Test (ubuntu, experimental-ion-hash)

unresolved import `crate::lazy::expanded::r#struct::tooling`

Check failure on line 7 in src/lazy/expanded/struct.rs

View workflow job for this annotation

GitHub Actions / Build and Test (ubuntu, default)

unresolved import `crate::lazy::expanded::r#struct::tooling`

Check failure on line 7 in src/lazy/expanded/struct.rs

View workflow job for this annotation

GitHub Actions / Build and Test (macos, default)

unresolved import `crate::lazy::expanded::r#struct::tooling`

Check failure on line 7 in src/lazy/expanded/struct.rs

View workflow job for this annotation

GitHub Actions / Build and Test (al2-arm, experimental-ion-hash)

unresolved import `crate::lazy::expanded::r#struct::tooling`

Check failure on line 7 in src/lazy/expanded/struct.rs

View workflow job for this annotation

GitHub Actions / Build and Test (macos, experimental-ion-hash)

unresolved import `crate::lazy::expanded::r#struct::tooling`

Check failure on line 7 in src/lazy/expanded/struct.rs

View workflow job for this annotation

GitHub Actions / Build and Test (windows, experimental-ion-hash)

unresolved import `crate::lazy::expanded::r#struct::tooling`

Check failure on line 7 in src/lazy/expanded/struct.rs

View workflow job for this annotation

GitHub Actions / Build and Test (windows, default)

unresolved import `crate::lazy::expanded::r#struct::tooling`
use crate::lazy::expanded::sequence::Environment;
use crate::lazy::expanded::template::{
TemplateElement, TemplateMacroRef, TemplateStructFieldSourceIterator, TemplateStructIndex,
TemplateElement, TemplateMacroRef, TemplateStructFieldExprIterator, TemplateStructIndex,
};
use crate::lazy::expanded::{
EncodingContextRef, ExpandedAnnotationsIterator, ExpandedAnnotationsSource, ExpandedValueRef,
Expand All @@ -19,11 +19,11 @@ use crate::{try_next, try_or_some_err, IonResult, RawSymbolRef, SymbolRef};
/// A unified type embodying all possible field representations coming from both input data
/// (i.e. raw structs of some encoding) and template bodies.
// LazyRawStruct implementations have a `unexpanded_fields` method that lifts its raw fields into
// `FieldSource` instances. Similarly, the `TemplateStructFieldSourceIterator` turns a
// template's struct body into `FieldSource` instances. The `ExpandedStructIterator` unpacks
// `FieldExpr` instances. Similarly, the `TemplateStructFieldExprIterator` turns a
// template's struct body into `FieldExpr` instances. The `ExpandedStructIterator` unpacks
// and expands the field as part of its iteration process.
#[derive(Debug, Clone, Copy)]
pub enum FieldSource<'top, D: Decoder> {
pub enum FieldExpr<'top, D: Decoder> {
NameValue(LazyExpandedFieldName<'top, D>, LazyExpandedValue<'top, D>),
NameMacro(LazyExpandedFieldName<'top, D>, MacroExpr<'top, D>),
Macro(MacroExpr<'top, D>),
Expand All @@ -50,8 +50,8 @@ impl<'top, D: Decoder> LazyExpandedField<'top, D> {
self.name
}

pub fn to_field_source(&self) -> FieldSource<'top, D> {
FieldSource::NameValue(self.name(), self.value())
pub fn to_field_source(&self) -> FieldExpr<'top, D> {
FieldExpr::NameValue(self.name(), self.value())
}
}

Expand Down Expand Up @@ -208,14 +208,14 @@ impl<'top, D: Decoder> LazyExpandedStruct<'top, D> {
let source = match &self.source {
ValueLiteral(raw_struct) => ExpandedStructIteratorSource::ValueLiteral(
evaluator,
raw_struct.unexpanded_fields(self.context),
raw_struct.field_exprs(self.context),
),
Template(environment, element, _index) => {
evaluator.set_root_environment(*environment);
let template = element.template();
ExpandedStructIteratorSource::Template(
evaluator,
TemplateStructFieldSourceIterator::new(
TemplateStructFieldExprIterator::new(
self.context,
*environment,
template,
Expand Down Expand Up @@ -244,12 +244,12 @@ impl<'top, D: Decoder> LazyExpandedStruct<'top, D> {
}

#[cfg(feature = "experimental-tooling-apis")]
fn field_source_iter(&self) -> FieldSourceIterator<'top, D> {
fn field_source_iter(&self) -> FieldExprIterator<'top, D> {
// The field source iterator has the same data as the regular iterator, it just uses it differently.
// Since the regular iterator's initialization process is non-trivial, we'll just make a regular iterator
// and use it for parts.
let ExpandedStructIterator { source, state } = self.iter();
FieldSourceIterator { source, state }
FieldExprIterator { source, state }
}

fn environment(&self) -> Environment<'top, D> {
Expand Down Expand Up @@ -328,13 +328,13 @@ pub enum ExpandedStructIteratorSource<'top, D: Decoder> {
// Giving the struct iterator its own evaluator means that we can abandon the iterator
// at any time without impacting the evaluation state of its parent container.
&'top mut MacroEvaluator<'top, D>,
RawStructFieldSourceIterator<'top, D>,
RawStructFieldExprIterator<'top, D>,
),
// The struct we're iterating over is a value in a TDL template. It may contain macro
// invocations that need to be evaluated.
Template(
&'top mut MacroEvaluator<'top, D>,
TemplateStructFieldSourceIterator<'top, D>,
TemplateStructFieldExprIterator<'top, D>,
),
MakeField(Option<LazyExpandedField<'top, D>>),
MakeStruct(
Expand All @@ -348,7 +348,7 @@ pub enum ExpandedStructIteratorSource<'top, D: Decoder> {
}

impl<'top, D: Decoder> ExpandedStructIteratorSource<'top, D> {
fn next_field(&mut self) -> Option<IonResult<FieldSource<'top, D>>> {
fn next_field(&mut self) -> Option<IonResult<FieldExpr<'top, D>>> {
// Get the next unexpanded field from our source's iterator.
match self {
ExpandedStructIteratorSource::Template(_, template_iterator) => {
Expand Down Expand Up @@ -493,7 +493,7 @@ impl<'top, D: Decoder> ExpandedStructIterator<'top, D> {
// This is the initial state. We're reading a field expression from our source
// iterator.
ReadingFieldFromSource => {
use FieldSource::*;
use FieldExpr::*;
match try_or_some_err!(source.next_field()?) {
NameValue(name, value) => {
return Some(Ok(LazyExpandedField::new(name, value)))
Expand Down Expand Up @@ -643,18 +643,18 @@ mod tooling {
/// An `ExpandedStructIterator` would yield a `LazyExpandedField` representing each
/// of the name/values pairs in the expansion: `(bar, 1)`, `(bar, 2)`, and `(bar, 3)`.
///
/// In contrast, the `FieldSourceIterator` would yield a `FieldSource` for the name/macro
/// field expression (`NameMacro("foo", MacroExpr)`) followed by a `FieldSource` for each of
/// In contrast, the `FieldExprIterator` would yield a `FieldExpr` for the name/macro
/// field expression (`NameMacro("foo", MacroExpr)`) followed by a `FieldExpr` for each of
/// the fields in the expansion `NameValue(bar, 1)`, `NameValue(bar, 2)`, and `NameValue(bar, 3)`.
pub struct FieldSourceIterator<'top, D: Decoder> {
pub struct FieldExprIterator<'top, D: Decoder> {
// Each variant of 'source' below holds its own encoding context reference
pub(crate) source: ExpandedStructIteratorSource<'top, D>,
// Stores information about any operations that are still in progress.
pub(crate) state: ExpandedStructIteratorState<'top, D>,
}

impl<'top, D: Decoder> Iterator for FieldSourceIterator<'top, D> {
type Item = IonResult<FieldSource<'top, D>>;
impl<'top, D: Decoder> Iterator for FieldExprIterator<'top, D> {
type Item = IonResult<FieldExpr<'top, D>>;

fn next(&mut self) -> Option<Self::Item> {
let Self {
Expand All @@ -668,7 +668,7 @@ mod tooling {
// This is the initial state. We're reading a field expression from our source
// iterator.
ReadingFieldFromSource => {
use FieldSource::*;
use FieldExpr::*;
let field = try_or_some_err!(source.next_field()?);
match field {
// It's a regular field, no special handling required.
Expand Down Expand Up @@ -735,7 +735,7 @@ mod tooling {
}
// We got another value from the macro we're evaluating. Emit
// it as another field using the same field_name.
return Some(Ok(FieldSource::NameValue(field_name, next_value)));
return Some(Ok(FieldExpr::NameValue(field_name, next_value)));
}
None => {
// The macro in the value position is no longer emitting values. Switch
Expand Down Expand Up @@ -778,7 +778,7 @@ mod tooling {
let fields = &mut struct_.expanded_struct.field_source_iter();

fn expect_name_value<'top, D: Decoder>(
fields: &mut impl Iterator<Item = IonResult<FieldSource<'top, D>>>,
fields: &mut impl Iterator<Item = IonResult<FieldExpr<'top, D>>>,
expected_name: &str,
expected_value: impl Into<Element>,
) -> IonResult<()> {
Expand All @@ -787,7 +787,7 @@ mod tooling {
assert!(
matches!(
field,
FieldSource::NameValue(name, value)
FieldExpr::NameValue(name, value)
if name.read()?.text() == Some(expected_name)
&& Element::try_from(value.read_resolved()?)? == expected_value,
),
Expand All @@ -799,15 +799,15 @@ mod tooling {
expect_name_value(fields, "foo", 0)?;
assert!(matches!(
fields.next().unwrap()?,
FieldSource::NameMacro(name, invocation)
FieldExpr::NameMacro(name, invocation)
if name.read()?.text() == Some("bar") && matches!(invocation.kind(), MacroExprKind::EExp(eexp) if eexp.invoked_macro.name() == Some("three_values"))
));
expect_name_value(fields, "bar", 1)?;
expect_name_value(fields, "bar", 2)?;
expect_name_value(fields, "bar", 3)?;
assert!(matches!(
fields.next().unwrap()?,
FieldSource::Macro(invocation)
FieldExpr::Macro(invocation)
if matches!(invocation.kind(), MacroExprKind::EExp(eexp) if eexp.invoked_macro.name() == Some("three_structs"))
));
expect_name_value(fields, "dog", 1)?;
Expand Down
18 changes: 9 additions & 9 deletions src/lazy/expanded/template.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use crate::lazy::decoder::Decoder;
use crate::lazy::expanded::compiler::ExpansionAnalysis;
use crate::lazy::expanded::macro_evaluator::{AnnotateExpansion, MacroEvaluator, MacroExpansion, MacroExpansionKind, MacroExpr, MacroExprArgsIterator, TemplateExpansion, ValueExpr, ExprGroupExpansion, MakeTextExpansion, FlattenExpansion, ConditionalExpansion, MakeStructExpansion, MakeFieldExpansion};
use crate::lazy::expanded::macro_table::{Macro, MacroKind};
use crate::lazy::expanded::r#struct::FieldSource;
use crate::lazy::expanded::r#struct::FieldExpr;
use crate::lazy::expanded::sequence::Environment;
use crate::lazy::expanded::{
EncodingContextRef, LazyExpandedValue, TemplateVariableReference,
Expand Down Expand Up @@ -527,24 +527,24 @@ impl<'top, D: Decoder> Iterator for TemplateSequenceIterator<'top, D> {
}
}

/// An iterator that pulls expressions from a template body and wraps them in a [`FieldSource`] to
/// An iterator that pulls expressions from a template body and wraps them in a [`FieldExpr`] to
/// mimic reading them from input. The [`LazyExpandedStruct`](crate::lazy::expanded::struct::LazyExpandedStruct) handles
/// evaluating any macro invocations that this yields.
pub struct TemplateStructFieldSourceIterator<'top, D: Decoder> {
pub struct TemplateStructFieldExprIterator<'top, D: Decoder> {
context: EncodingContextRef<'top>,
environment: Environment<'top, D>,
template: TemplateMacroRef<'top>,
nested_expressions: &'top [TemplateBodyExpr],
index: usize,
}

impl<'top, D: Decoder> TemplateStructFieldSourceIterator<'top, D> {
impl<'top, D: Decoder> TemplateStructFieldExprIterator<'top, D> {
pub fn context(&self) -> EncodingContextRef<'top> {
self.context
}
}

impl<'top, D: Decoder> TemplateStructFieldSourceIterator<'top, D> {
impl<'top, D: Decoder> TemplateStructFieldExprIterator<'top, D> {
pub fn new(
context: EncodingContextRef<'top>,
environment: Environment<'top, D>,
Expand All @@ -561,8 +561,8 @@ impl<'top, D: Decoder> TemplateStructFieldSourceIterator<'top, D> {
}
}

impl<'top, D: Decoder> Iterator for TemplateStructFieldSourceIterator<'top, D> {
type Item = IonResult<FieldSource<'top, D>>;
impl<'top, D: Decoder> Iterator for TemplateStructFieldExprIterator<'top, D> {
type Item = IonResult<FieldExpr<'top, D>>;

fn next(&mut self) -> Option<Self::Item> {
let name_expr_address = self.index;
Expand All @@ -585,11 +585,11 @@ impl<'top, D: Decoder> Iterator for TemplateStructFieldSourceIterator<'top, D> {
let field_name = LazyExpandedFieldName::TemplateName(self.template, name);
let value_expr = field_value_tdl_expr.to_value_expr(self.context, self.environment, self.template);
let unexpanded_field = match value_expr {
ValueExpr::ValueLiteral(lazy_expanded_value) => FieldSource::NameValue(
ValueExpr::ValueLiteral(lazy_expanded_value) => FieldExpr::NameValue(
field_name,
lazy_expanded_value
),
ValueExpr::MacroInvocation(invocation) => FieldSource::NameMacro(
ValueExpr::MacroInvocation(invocation) => FieldExpr::NameMacro(
field_name,
invocation,
),
Expand Down

0 comments on commit 8bf5fec

Please sign in to comment.