diff --git a/src/protocol/ast.rs b/src/protocol/ast.rs index 1a8b15815835a0aa5b320791193ad9cfa98942d1..ca6efe6af2637d61f1d1d50fa3cd87285916d4d0 100644 --- a/src/protocol/ast.rs +++ b/src/protocol/ast.rs @@ -340,6 +340,15 @@ pub struct Identifier { pub value: StringRef<'static>, } +impl Identifier { + pub(crate) fn new_empty(span: InputSpan) -> Identifier { + return Identifier{ + span, + value: StringRef::new_empty(), + }; + } +} + impl PartialEq for Identifier { fn eq(&self, other: &Self) -> bool { return self.value == other.value @@ -1432,7 +1441,7 @@ pub enum ExpressionParent { Return(ReturnStatementId), New(NewStatementId), ExpressionStmt(ExpressionStatementId), - Expression(ExpressionId, u32) // index within expression (e.g LHS or RHS of expression) + Expression(ExpressionId, u32) // index within expression (e.g LHS or RHS of expression, or index in array literal, etc.) } impl ExpressionParent { @@ -1530,6 +1539,23 @@ impl Expression { } } + pub fn parent_mut(&mut self) -> &mut ExpressionParent { + match self { + Expression::Assignment(expr) => &mut expr.parent, + Expression::Binding(expr) => &mut expr.parent, + Expression::Conditional(expr) => &mut expr.parent, + Expression::Binary(expr) => &mut expr.parent, + Expression::Unary(expr) => &mut expr.parent, + Expression::Indexing(expr) => &mut expr.parent, + Expression::Slicing(expr) => &mut expr.parent, + Expression::Select(expr) => &mut expr.parent, + Expression::Literal(expr) => &mut expr.parent, + Expression::Cast(expr) => &mut expr.parent, + Expression::Call(expr) => &mut expr.parent, + Expression::Variable(expr) => &mut expr.parent, + } + } + pub fn parent_expr_id(&self) -> Option { if let ExpressionParent::Expression(id, _) = self.parent() { Some(*id) @@ -1875,5 +1901,5 @@ pub struct VariableExpression { pub declaration: Option, pub used_as_binding_target: bool, pub parent: ExpressionParent, - pub unique_id_in_definition: i32, + pub unique_id_in_definition: i32, // used to index into type table after all types are determined } \ No newline at end of file