Struct rtlola_parser::ast::NodeId
source · Expand description
Every node in the Ast gets a unique id, represented by a 32bit unsigned integer. They are used in the later analysis phases to store information about Ast nodes.
Fields§
§id: u32The actual unique id.
prime_counter: u32Counter to track transformations on this node. Increased during syntactic sugar removal.
Implementations§
source§impl NodeId
impl NodeId
sourcepub fn primed(&self) -> Self
pub fn primed(&self) -> Self
Creates a copy NodeId with incremented prime counter, which indicates a applied transformation for desugarization.
Examples found in repository?
src/syntactic_sugar/last.rs (line 21)
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
fn apply<'a>(&self, expr: &Expression, ast: &'a RtLolaAst) -> ChangeSet {
match &expr.kind {
ExpressionKind::Method(base, name, _types, arguments) => {
if "last(or:)" != name.to_string() {
return ChangeSet::empty();
};
let target_stream = base.clone();
assert_eq!(arguments.len(), 1);
let default = arguments[0].clone();
let new_id = expr.id.primed();
let new_access = Expression {
kind: ExpressionKind::Offset(target_stream, Offset::Discrete(-1)),
id: new_id,
span: expr.span.clone(),
};
let new_expr = Expression {
kind: ExpressionKind::Default(Box::new(new_access), Box::new(default)),
id: ast.next_id(),
span: expr.span.clone(),
};
ChangeSet::replace_current_expression(new_expr)
},
_ => ChangeSet::empty(),
}
}More examples
src/syntactic_sugar/aggregation_method.rs (line 31)
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
fn apply(&self, expr: &Expression) -> ChangeSet {
match &expr.kind {
ExpressionKind::Method(base, name, _types, arguments) => {
let op = match name.name.name.as_ref() {
"count" => WindowOperation::Count,
"min" => WindowOperation::Min,
"max" => WindowOperation::Max,
"sum" => WindowOperation::Sum,
"avg" => WindowOperation::Average,
"integral" => WindowOperation::Integral,
"var" => WindowOperation::Variance,
"cov" => WindowOperation::Covariance,
"sd" => WindowOperation::StandardDeviation,
"med" => WindowOperation::NthPercentile(50),
_ => return ChangeSet::empty(),
};
let target_stream = base.clone();
let wait = false;
let duration = Box::new(arguments[0].clone());
let new_id = expr.id.primed();
let new_expr = Expression {
kind: ExpressionKind::SlidingWindowAggregation {
expr: target_stream,
duration,
wait,
aggregation: op,
},
id: new_id,
span: expr.span.clone(),
};
ChangeSet::replace_current_expression(new_expr)
},
_ => ChangeSet::empty(),
}
}src/syntactic_sugar/mirror.rs (line 55)
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
fn apply<'a>(&self, stream: &'a AstMirror, ast: &'a RtLolaAst) -> ChangeSet {
let AstMirror {
name,
target,
filter,
span,
id: mirror_id,
} = stream.clone();
let target = ast.outputs.iter().find(|o| o.name.name == target.name);
let target = target.expect("mirror stream refers to a stream that does not exist");
let target = (**target).clone();
let target_eval_specs = target.eval.clone();
let filter_span = &filter.span;
let new_eval_specs = target_eval_specs
.into_iter()
.map(|e| {
let EvalSpec {
annotated_pacing: t_annotated_pacing,
condition: t_filter,
eval_expression: t_eval,
id: t_id,
span: t_span,
} = e;
let new_filter = match t_filter {
Some(old_f) => {
Expression {
id: ast.next_id(),
span: Span::Indirect(Box::new(filter_span.clone())),
kind: crate::ast::ExpressionKind::Binary(
BinOp::And,
Box::new(old_f),
Box::new(filter.clone()),
),
}
},
None => filter.clone(),
};
EvalSpec {
condition: Some(new_filter),
id: t_id.primed(),
span: Span::Indirect(Box::new(t_span)),
annotated_pacing: t_annotated_pacing,
eval_expression: t_eval,
}
})
.collect();
let output = Output {
name,
eval: new_eval_specs,
id: ast.next_id(),
span: Span::Indirect(Box::new(span)),
..target
};
ChangeSet::replace_stream(mirror_id, output)
}src/syntactic_sugar/delta.rs (line 34)
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
fn apply<'a>(&self, expr: &Expression, ast: &'a RtLolaAst) -> ChangeSet {
match &expr.kind {
// Function(FunctionName, Vec<Type>, Vec<Expression>),
ExpressionKind::Function(name, _types, args) => {
let f_name = name.name.name.clone();
/* currently not parsable but intended: , "δ", "Δ" */
if !["delta"].contains(&f_name.as_str()) {
return ChangeSet::empty();
}
let arg_names = name.arg_names.clone();
if arg_names.len() != 2 {
return ChangeSet::empty();
}
if arg_names[0].is_some() || arg_names[1].is_none() {
return ChangeSet::empty();
}
if !["dft", "default", "or"].contains(&arg_names[1].as_ref().unwrap().name.as_str()) {
return ChangeSet::empty();
}
let target_stream = args[0].clone();
let new_id = expr.id.primed();
let indirect_span = Span::Indirect(Box::new(expr.span.clone()));
let sync = Expression {
kind: ExpressionKind::StreamAccess(Box::new(target_stream.clone()), StreamAccessKind::Sync),
id: ast.next_id(),
span: expr.span.clone(),
};
let offset = Expression {
kind: ExpressionKind::Offset(Box::new(target_stream), Offset::Discrete(-1)),
id: new_id,
span: expr.span.clone(),
};
let default_expr = args[1].clone();
let default = Expression {
kind: ExpressionKind::Default(Box::new(offset), Box::new(default_expr)),
id: ast.next_id(),
span: indirect_span.clone(),
};
let res = Expression {
kind: ExpressionKind::Binary(BinOp::Sub, Box::new(sync), Box::new(default)),
id: new_id,
span: indirect_span,
};
ChangeSet::replace_current_expression(res)
},
_ => ChangeSet::empty(),
}
}Trait Implementations§
source§impl<'de> Deserialize<'de> for NodeId
impl<'de> Deserialize<'de> for NodeId
source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
source§impl Ord for NodeId
impl Ord for NodeId
source§impl PartialEq<NodeId> for NodeId
impl PartialEq<NodeId> for NodeId
source§impl PartialOrd<NodeId> for NodeId
impl PartialOrd<NodeId> for NodeId
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for
self and other) and is used by the <=
operator. Read more