diff --git a/src/protocol/ast.rs b/src/protocol/ast.rs index 9459e99d1b75e09768d4dbc41f496a118eb4f801..0301c6def68c4e66c022f36102e4b3c9e2ebaccd 100644 --- a/src/protocol/ast.rs +++ b/src/protocol/ast.rs @@ -8,12 +8,16 @@ use super::arena::{Arena, Id}; // TODO: @cleanup, transform wrapping types into type aliases where possible use crate::protocol::inputsource::*; +/// Helper macro that defines a type alias for a AST element ID. In this case +/// only used to alias the `Id` types. macro_rules! define_aliased_ast_id { ($name:ident, $parent:ty) => { - type $name = $parent; + pub type $name = $parent; } } +/// Helper macro that defines a subtype for a particular variant of an AST +/// element ID. macro_rules! define_new_ast_id { ($name:ident, $parent:ty) => { #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, serde::Serialize, serde::Deserialize)] @@ -77,7 +81,7 @@ define_new_ast_id!(ConstantExpressionId, ExpressionId); define_new_ast_id!(CallExpressionId, ExpressionId); define_new_ast_id!(VariableExpressionId, ExpressionId); -define_new_ast_id!(DeclarationId, ExpressionId); // TODO: @cleanup +define_aliased_ast_id!(DeclarationId, Id); // TODO: @cleanup define_new_ast_id!(DefinedDeclarationId, DeclarationId); define_new_ast_id!(ImportedDeclarationId, DeclarationId); @@ -332,514 +336,512 @@ impl Heap { &mut self, f: impl FnOnce(SynchronousStatementId) -> SynchronousStatement, ) -> SynchronousStatementId { - SynchronousStatementId(StatementId(self.statements.alloc_with_id(|id| { - Statement::Synchronous(f(SynchronousStatementId(StatementId(id)))) - }))) + SynchronousStatementId(self.statements.alloc_with_id(|id| { + Statement::Synchronous(f(SynchronousStatementId(id))) + })) } pub fn alloc_end_synchronous_statement( &mut self, f: impl FnOnce(EndSynchronousStatementId) -> EndSynchronousStatement, ) -> EndSynchronousStatementId { - EndSynchronousStatementId(StatementId(self.statements.alloc_with_id(|id| { - Statement::EndSynchronous(f(EndSynchronousStatementId(StatementId(id)))) - }))) + EndSynchronousStatementId(self.statements.alloc_with_id(|id| { + Statement::EndSynchronous(f(EndSynchronousStatementId(id))) + })) } pub fn alloc_return_statement( &mut self, f: impl FnOnce(ReturnStatementId) -> ReturnStatement, ) -> ReturnStatementId { - ReturnStatementId(StatementId( + ReturnStatementId( self.statements - .alloc_with_id(|id| Statement::Return(f(ReturnStatementId(StatementId(id))))), - )) + .alloc_with_id(|id| Statement::Return(f(ReturnStatementId(id)))), + ) } pub fn alloc_assert_statement( &mut self, f: impl FnOnce(AssertStatementId) -> AssertStatement, ) -> AssertStatementId { - AssertStatementId(StatementId( + AssertStatementId( self.statements - .alloc_with_id(|id| Statement::Assert(f(AssertStatementId(StatementId(id))))), - )) + .alloc_with_id(|id| Statement::Assert(f(AssertStatementId(id)))), + ) } pub fn alloc_goto_statement( &mut self, f: impl FnOnce(GotoStatementId) -> GotoStatement, ) -> GotoStatementId { - GotoStatementId(StatementId( + GotoStatementId( self.statements - .alloc_with_id(|id| Statement::Goto(f(GotoStatementId(StatementId(id))))), - )) + .alloc_with_id(|id| Statement::Goto(f(GotoStatementId(id)))), + ) } pub fn alloc_new_statement( &mut self, f: impl FnOnce(NewStatementId) -> NewStatement, ) -> NewStatementId { - NewStatementId(StatementId( - self.statements.alloc_with_id(|id| Statement::New(f(NewStatementId(StatementId(id))))), - )) + NewStatementId( + self.statements.alloc_with_id(|id| Statement::New(f(NewStatementId(id)))), + ) } pub fn alloc_put_statement( &mut self, f: impl FnOnce(PutStatementId) -> PutStatement, ) -> PutStatementId { - PutStatementId(StatementId( - self.statements.alloc_with_id(|id| Statement::Put(f(PutStatementId(StatementId(id))))), - )) + PutStatementId( + self.statements.alloc_with_id(|id| Statement::Put(f(PutStatementId(id)))), + ) } pub fn alloc_labeled_statement( &mut self, f: impl FnOnce(LabeledStatementId) -> LabeledStatement, ) -> LabeledStatementId { - LabeledStatementId(StatementId( + LabeledStatementId( self.statements - .alloc_with_id(|id| Statement::Labeled(f(LabeledStatementId(StatementId(id))))), - )) + .alloc_with_id(|id| Statement::Labeled(f(LabeledStatementId(id)))), + ) } pub fn alloc_expression_statement( &mut self, f: impl FnOnce(ExpressionStatementId) -> ExpressionStatement, ) -> ExpressionStatementId { - ExpressionStatementId(StatementId( + ExpressionStatementId( self.statements.alloc_with_id(|id| { - Statement::Expression(f(ExpressionStatementId(StatementId(id)))) + Statement::Expression(f(ExpressionStatementId(id))) }), - )) + ) } pub fn alloc_struct_definition(&mut self, f: impl FnOnce(StructId) -> StructDefinition) -> StructId { - StructId(DefinitionId(self.definitions.alloc_with_id(|id| { - Definition::Struct(f(StructId(DefinitionId(id)))) - }))) + StructId(self.definitions.alloc_with_id(|id| { + Definition::Struct(f(StructId(id))) + })) } pub fn alloc_enum_definition(&mut self, f: impl FnOnce(EnumId) -> EnumDefinition) -> EnumId { - EnumId(DefinitionId(self.definitions.alloc_with_id(|id| { - Definition::Enum(f(EnumId(DefinitionId(id)))) - }))) + EnumId(self.definitions.alloc_with_id(|id| { + Definition::Enum(f(EnumId(id))) + })) } pub fn alloc_component(&mut self, f: impl FnOnce(ComponentId) -> Component) -> ComponentId { - ComponentId(DefinitionId(self.definitions.alloc_with_id(|id| { - Definition::Component(f(ComponentId( - DefinitionId(id), - ))) - }))) + ComponentId(self.definitions.alloc_with_id(|id| { + Definition::Component(f(ComponentId(id))) + })) } pub fn alloc_function(&mut self, f: impl FnOnce(FunctionId) -> Function) -> FunctionId { - FunctionId(DefinitionId( + FunctionId( self.definitions - .alloc_with_id(|id| Definition::Function(f(FunctionId(DefinitionId(id))))), - )) + .alloc_with_id(|id| Definition::Function(f(FunctionId(id)))), + ) } pub fn alloc_pragma(&mut self, f: impl FnOnce(PragmaId) -> Pragma) -> PragmaId { - PragmaId(self.pragmas.alloc_with_id(|id| f(PragmaId(id)))) + self.pragmas.alloc_with_id(|id| f(id)) } pub fn alloc_import(&mut self, f: impl FnOnce(ImportId) -> Import) -> ImportId { - ImportId(self.imports.alloc_with_id(|id| f(ImportId(id)))) + self.imports.alloc_with_id(|id| f(id)) } pub fn alloc_protocol_description(&mut self, f: impl FnOnce(RootId) -> Root) -> RootId { - RootId(self.protocol_descriptions.alloc_with_id(|id| f(RootId(id)))) + self.protocol_descriptions.alloc_with_id(|id| f(id)) } pub fn alloc_imported_declaration( &mut self, f: impl FnOnce(ImportedDeclarationId) -> ImportedDeclaration, ) -> ImportedDeclarationId { - ImportedDeclarationId(DeclarationId(self.declarations.alloc_with_id(|id| { - Declaration::Imported(f(ImportedDeclarationId(DeclarationId(id)))) - }))) + ImportedDeclarationId(self.declarations.alloc_with_id(|id| { + Declaration::Imported(f(ImportedDeclarationId(id))) + })) } pub fn alloc_defined_declaration( &mut self, f: impl FnOnce(DefinedDeclarationId) -> DefinedDeclaration, ) -> DefinedDeclarationId { - DefinedDeclarationId(DeclarationId( + DefinedDeclarationId( self.declarations.alloc_with_id(|id| { - Declaration::Defined(f(DefinedDeclarationId(DeclarationId(id)))) + Declaration::Defined(f(DefinedDeclarationId(id))) }), - )) + ) } } impl Index for Heap { type Output = Root; fn index(&self, index: RootId) -> &Self::Output { - &self.protocol_descriptions[index.0] + &self.protocol_descriptions[index] } } impl IndexMut for Heap { fn index_mut(&mut self, index: RootId) -> &mut Self::Output { - &mut self.protocol_descriptions[index.0] + &mut self.protocol_descriptions[index] } } impl Index for Heap { type Output = Pragma; fn index(&self, index: PragmaId) -> &Self::Output { - &self.pragmas[index.0] + &self.pragmas[index] } } impl Index for Heap { type Output = Import; fn index(&self, index: ImportId) -> &Self::Output { - &self.imports[index.0] + &self.imports[index] } } impl IndexMut for Heap { fn index_mut(&mut self, index: ImportId) -> &mut Self::Output { - &mut self.imports[index.0] + &mut self.imports[index] } } impl Index for Heap { type Output = TypeAnnotation; fn index(&self, index: TypeAnnotationId) -> &Self::Output { - &self.type_annotations[index.0] + &self.type_annotations[index] } } impl Index for Heap { type Output = Variable; fn index(&self, index: VariableId) -> &Self::Output { - &self.variables[index.0] + &self.variables[index] } } impl Index for Heap { type Output = Parameter; fn index(&self, index: ParameterId) -> &Self::Output { - &self.variables[(index.0).0].as_parameter() + &self.variables[index.0].as_parameter() } } impl Index for Heap { type Output = Local; fn index(&self, index: LocalId) -> &Self::Output { - &self.variables[(index.0).0].as_local() + &self.variables[index.0].as_local() } } impl IndexMut for Heap { fn index_mut(&mut self, index: LocalId) -> &mut Self::Output { - self.variables[index.0.0].as_local_mut() + self.variables[index.0].as_local_mut() } } impl Index for Heap { type Output = Definition; fn index(&self, index: DefinitionId) -> &Self::Output { - &self.definitions[index.0] + &self.definitions[index] } } impl Index for Heap { type Output = Component; fn index(&self, index: ComponentId) -> &Self::Output { - &self.definitions[(index.0).0].as_component() + &self.definitions[index.0].as_component() } } impl Index for Heap { type Output = Function; fn index(&self, index: FunctionId) -> &Self::Output { - &self.definitions[(index.0).0].as_function() + &self.definitions[index.0].as_function() } } impl Index for Heap { type Output = Statement; fn index(&self, index: StatementId) -> &Self::Output { - &self.statements[index.0] + &self.statements[index] } } impl IndexMut for Heap { fn index_mut(&mut self, index: StatementId) -> &mut Self::Output { - &mut self.statements[index.0] + &mut self.statements[index] } } impl Index for Heap { type Output = BlockStatement; fn index(&self, index: BlockStatementId) -> &Self::Output { - &self.statements[(index.0).0].as_block() + &self.statements[index.0].as_block() } } impl IndexMut for Heap { fn index_mut(&mut self, index: BlockStatementId) -> &mut Self::Output { - (&mut self.statements[(index.0).0]).as_block_mut() + (&mut self.statements[index.0]).as_block_mut() } } impl Index for Heap { type Output = LocalStatement; fn index(&self, index: LocalStatementId) -> &Self::Output { - &self.statements[(index.0).0].as_local() + &self.statements[index.0].as_local() } } impl Index for Heap { type Output = MemoryStatement; fn index(&self, index: MemoryStatementId) -> &Self::Output { - &self.statements[((index.0).0).0].as_memory() + &self.statements[index.0.0].as_memory() } } impl Index for Heap { type Output = ChannelStatement; fn index(&self, index: ChannelStatementId) -> &Self::Output { - &self.statements[((index.0).0).0].as_channel() + &self.statements[index.0.0].as_channel() } } impl Index for Heap { type Output = SkipStatement; fn index(&self, index: SkipStatementId) -> &Self::Output { - &self.statements[(index.0).0].as_skip() + &self.statements[index.0].as_skip() } } impl Index for Heap { type Output = LabeledStatement; fn index(&self, index: LabeledStatementId) -> &Self::Output { - &self.statements[(index.0).0].as_labeled() + &self.statements[index.0].as_labeled() } } impl IndexMut for Heap { fn index_mut(&mut self, index: LabeledStatementId) -> &mut Self::Output { - (&mut self.statements[(index.0).0]).as_labeled_mut() + (&mut self.statements[index.0]).as_labeled_mut() } } impl Index for Heap { type Output = IfStatement; fn index(&self, index: IfStatementId) -> &Self::Output { - &self.statements[(index.0).0].as_if() + &self.statements[index.0].as_if() } } impl IndexMut for Heap { fn index_mut(&mut self, index: IfStatementId) -> &mut Self::Output { - self.statements[(index.0).0].as_if_mut() + self.statements[index.0].as_if_mut() } } impl Index for Heap { type Output = EndIfStatement; fn index(&self, index: EndIfStatementId) -> &Self::Output { - &self.statements[(index.0).0].as_end_if() + &self.statements[index.0].as_end_if() } } impl Index for Heap { type Output = WhileStatement; fn index(&self, index: WhileStatementId) -> &Self::Output { - &self.statements[(index.0).0].as_while() + &self.statements[index.0].as_while() } } impl IndexMut for Heap { fn index_mut(&mut self, index: WhileStatementId) -> &mut Self::Output { - (&mut self.statements[(index.0).0]).as_while_mut() + (&mut self.statements[index.0]).as_while_mut() } } impl Index for Heap { type Output = BreakStatement; fn index(&self, index: BreakStatementId) -> &Self::Output { - &self.statements[(index.0).0].as_break() + &self.statements[index.0].as_break() } } impl IndexMut for Heap { fn index_mut(&mut self, index: BreakStatementId) -> &mut Self::Output { - (&mut self.statements[(index.0).0]).as_break_mut() + (&mut self.statements[index.0]).as_break_mut() } } impl Index for Heap { type Output = ContinueStatement; fn index(&self, index: ContinueStatementId) -> &Self::Output { - &self.statements[(index.0).0].as_continue() + &self.statements[index.0].as_continue() } } impl IndexMut for Heap { fn index_mut(&mut self, index: ContinueStatementId) -> &mut Self::Output { - (&mut self.statements[(index.0).0]).as_continue_mut() + (&mut self.statements[index.0]).as_continue_mut() } } impl Index for Heap { type Output = SynchronousStatement; fn index(&self, index: SynchronousStatementId) -> &Self::Output { - &self.statements[(index.0).0].as_synchronous() + &self.statements[index.0].as_synchronous() } } impl IndexMut for Heap { fn index_mut(&mut self, index: SynchronousStatementId) -> &mut Self::Output { - (&mut self.statements[(index.0).0]).as_synchronous_mut() + (&mut self.statements[index.0]).as_synchronous_mut() } } impl Index for Heap { type Output = EndSynchronousStatement; fn index(&self, index: EndSynchronousStatementId) -> &Self::Output { - &self.statements[(index.0).0].as_end_synchronous() + &self.statements[index.0].as_end_synchronous() } } impl Index for Heap { type Output = ReturnStatement; fn index(&self, index: ReturnStatementId) -> &Self::Output { - &self.statements[(index.0).0].as_return() + &self.statements[index.0].as_return() } } impl Index for Heap { type Output = AssertStatement; fn index(&self, index: AssertStatementId) -> &Self::Output { - &self.statements[(index.0).0].as_assert() + &self.statements[index.0].as_assert() } } impl Index for Heap { type Output = GotoStatement; fn index(&self, index: GotoStatementId) -> &Self::Output { - &self.statements[(index.0).0].as_goto() + &self.statements[index.0].as_goto() } } impl IndexMut for Heap { fn index_mut(&mut self, index: GotoStatementId) -> &mut Self::Output { - (&mut self.statements[(index.0).0]).as_goto_mut() + (&mut self.statements[index.0]).as_goto_mut() } } impl Index for Heap { type Output = NewStatement; fn index(&self, index: NewStatementId) -> &Self::Output { - &self.statements[(index.0).0].as_new() + &self.statements[index.0].as_new() } } impl Index for Heap { type Output = PutStatement; fn index(&self, index: PutStatementId) -> &Self::Output { - &self.statements[(index.0).0].as_put() + &self.statements[index.0].as_put() } } impl Index for Heap { type Output = ExpressionStatement; fn index(&self, index: ExpressionStatementId) -> &Self::Output { - &self.statements[(index.0).0].as_expression() + &self.statements[index.0].as_expression() } } impl Index for Heap { type Output = Expression; fn index(&self, index: ExpressionId) -> &Self::Output { - &self.expressions[index.0] + &self.expressions[index] } } impl Index for Heap { type Output = AssignmentExpression; fn index(&self, index: AssignmentExpressionId) -> &Self::Output { - &self.expressions[(index.0).0].as_assignment() + &self.expressions[index.0].as_assignment() } } impl Index for Heap { type Output = ConditionalExpression; fn index(&self, index: ConditionalExpressionId) -> &Self::Output { - &self.expressions[(index.0).0].as_conditional() + &self.expressions[index.0].as_conditional() } } impl Index for Heap { type Output = BinaryExpression; fn index(&self, index: BinaryExpressionId) -> &Self::Output { - &self.expressions[(index.0).0].as_binary() + &self.expressions[index.0].as_binary() } } impl Index for Heap { type Output = UnaryExpression; fn index(&self, index: UnaryExpressionId) -> &Self::Output { - &self.expressions[(index.0).0].as_unary() + &self.expressions[index.0].as_unary() } } impl Index for Heap { type Output = IndexingExpression; fn index(&self, index: IndexingExpressionId) -> &Self::Output { - &self.expressions[(index.0).0].as_indexing() + &self.expressions[index.0].as_indexing() } } impl Index for Heap { type Output = SlicingExpression; fn index(&self, index: SlicingExpressionId) -> &Self::Output { - &self.expressions[(index.0).0].as_slicing() + &self.expressions[index.0].as_slicing() } } impl Index for Heap { type Output = SelectExpression; fn index(&self, index: SelectExpressionId) -> &Self::Output { - &self.expressions[(index.0).0].as_select() + &self.expressions[index.0].as_select() } } impl Index for Heap { type Output = ArrayExpression; fn index(&self, index: ArrayExpressionId) -> &Self::Output { - &self.expressions[(index.0).0].as_array() + &self.expressions[index.0].as_array() } } impl Index for Heap { type Output = ConstantExpression; fn index(&self, index: ConstantExpressionId) -> &Self::Output { - &self.expressions[(index.0).0].as_constant() + &self.expressions[index.0].as_constant() } } impl Index for Heap { type Output = CallExpression; fn index(&self, index: CallExpressionId) -> &Self::Output { - &self.expressions[(index.0).0].as_call() + &self.expressions[index.0].as_call() } } impl IndexMut for Heap { fn index_mut(&mut self, index: CallExpressionId) -> &mut Self::Output { - (&mut self.expressions[(index.0).0]).as_call_mut() + (&mut self.expressions[index.0]).as_call_mut() } } impl Index for Heap { type Output = VariableExpression; fn index(&self, index: VariableExpressionId) -> &Self::Output { - &self.expressions[(index.0).0].as_variable() + &self.expressions[index.0].as_variable() } } impl IndexMut for Heap { fn index_mut(&mut self, index: VariableExpressionId) -> &mut Self::Output { - (&mut self.expressions[(index.0).0]).as_variable_mut() + (&mut self.expressions[index.0]).as_variable_mut() } } impl Index for Heap { type Output = Declaration; fn index(&self, index: DeclarationId) -> &Self::Output { - &self.declarations[index.0] + &self.declarations[index] } } @@ -1167,7 +1169,7 @@ impl Display for Type { write!( f, "Symbolic({}, id: {})", String::from_utf8_lossy(&data.identifier.value), - id.0.index + id.index )?; } else { write!( diff --git a/src/protocol/ast_printer.rs b/src/protocol/ast_printer.rs index bba45c7d5962fbd59898c2641c97a304d85fa979..84ca2c509b5c34e2a88e560859b7b9e403161cd9 100644 --- a/src/protocol/ast_printer.rs +++ b/src/protocol/ast_printer.rs @@ -191,7 +191,7 @@ impl ASTWriter { //-------------------------------------------------------------------------- fn write_module(&mut self, heap: &Heap, root_id: RootId) { - self.kv(0).with_id(PREFIX_ROOT_ID, root_id.0.index) + self.kv(0).with_id(PREFIX_ROOT_ID, root_id.index) .with_s_key("Module"); let root = &heap[root_id]; @@ -214,12 +214,12 @@ impl ASTWriter { fn write_pragma(&mut self, heap: &Heap, pragma_id: PragmaId, indent: usize) { match &heap[pragma_id] { Pragma::Version(pragma) => { - self.kv(indent).with_id(PREFIX_PRAGMA_ID, pragma.this.0.index) + self.kv(indent).with_id(PREFIX_PRAGMA_ID, pragma.this.index) .with_s_key("PragmaVersion") .with_disp_val(&pragma.version); }, Pragma::Module(pragma) => { - self.kv(indent).with_id(PREFIX_PRAGMA_ID, pragma.this.0.index) + self.kv(indent).with_id(PREFIX_PRAGMA_ID, pragma.this.index) .with_s_key("PragmaModule") .with_ascii_val(&pragma.value); } @@ -232,21 +232,21 @@ impl ASTWriter { match import { Import::Module(import) => { - self.kv(indent).with_id(PREFIX_IMPORT_ID, import.this.0.index) + self.kv(indent).with_id(PREFIX_IMPORT_ID, import.this.index) .with_s_key("ImportModule"); self.kv(indent2).with_s_key("Name").with_ascii_val(&import.module_name); self.kv(indent2).with_s_key("Alias").with_ascii_val(&import.alias); self.kv(indent2).with_s_key("Target") - .with_opt_disp_val(import.module_id.as_ref().map(|v| &v.0.index)); + .with_opt_disp_val(import.module_id.as_ref().map(|v| &v.index)); }, Import::Symbols(import) => { - self.kv(indent).with_id(PREFIX_IMPORT_ID, import.this.0.index) + self.kv(indent).with_id(PREFIX_IMPORT_ID, import.this.index) .with_s_key("ImportSymbol"); self.kv(indent2).with_s_key("Name").with_ascii_val(&import.module_name); self.kv(indent2).with_s_key("Target") - .with_opt_disp_val(import.module_id.as_ref().map(|v| &v.0.index)); + .with_opt_disp_val(import.module_id.as_ref().map(|v| &v.index)); self.kv(indent2).with_s_key("Symbols"); @@ -257,7 +257,7 @@ impl ASTWriter { self.kv(indent4).with_s_key("Name").with_ascii_val(&symbol.name); self.kv(indent4).with_s_key("Alias").with_ascii_val(&symbol.alias); self.kv(indent4).with_s_key("Definition") - .with_opt_disp_val(symbol.definition_id.as_ref().map(|v| &v.0.index)); + .with_opt_disp_val(symbol.definition_id.as_ref().map(|v| &v.index)); } } } @@ -277,7 +277,7 @@ impl ASTWriter { Definition::Enum(_) => todo!("implement Definition::Enum"), Definition::Function(_) => todo!("implement Definition::Function"), Definition::Component(def) => { - self.kv(indent).with_id(PREFIX_COMPONENT_ID,def.this.0.0.index) + self.kv(indent).with_id(PREFIX_COMPONENT_ID,def.this.0.index) .with_s_key("DefinitionComponent"); self.kv(indent2).with_s_key("Name").with_ascii_val(&def.identifier.value); @@ -286,7 +286,7 @@ impl ASTWriter { self.kv(indent2).with_s_key("Parameters"); for param_id in &def.parameters { let param = &heap[*param_id]; - self.kv(indent3).with_id(PREFIX_PARAMETER_ID, param_id.0.0.index) + self.kv(indent3).with_id(PREFIX_PARAMETER_ID, param_id.0.index) .with_s_key("Parameter"); self.kv(indent4).with_s_key("Name").with_ascii_val(¶m.identifier.value); @@ -306,7 +306,7 @@ impl ASTWriter { match stmt { Statement::Block(stmt) => { - self.kv(indent).with_id(PREFIX_BLOCK_STMT_ID, stmt.this.0.0.index) + self.kv(indent).with_id(PREFIX_BLOCK_STMT_ID, stmt.this.0.index) .with_s_key("Block"); for stmt_id in &stmt.statements { @@ -316,7 +316,7 @@ impl ASTWriter { Statement::Local(stmt) => { match stmt { LocalStatement::Channel(stmt) => { - self.kv(indent).with_id(PREFIX_CHANNEL_STMT_ID, stmt.this.0.0.0.index) + self.kv(indent).with_id(PREFIX_CHANNEL_STMT_ID, stmt.this.0.0.index) .with_s_key("LocalChannel"); self.kv(indent2).with_s_key("From"); @@ -324,10 +324,10 @@ impl ASTWriter { self.kv(indent2).with_s_key("To"); self.write_local(heap, stmt.to, indent3); self.kv(indent2).with_s_key("Next") - .with_opt_disp_val(stmt.next.as_ref().map(|v| &v.0.index)); + .with_opt_disp_val(stmt.next.as_ref().map(|v| &v.index)); }, LocalStatement::Memory(stmt) => { - self.kv(indent).with_id(PREFIX_MEM_STMT_ID, stmt.this.0.0.0.index) + self.kv(indent).with_id(PREFIX_MEM_STMT_ID, stmt.this.0.0.index) .with_s_key("LocalMemory"); self.kv(indent2).with_s_key("Variable"); @@ -335,18 +335,18 @@ impl ASTWriter { self.kv(indent2).with_s_key("initial"); self.write_expr(heap, stmt.initial, indent3); self.kv(indent2).with_s_key("Next") - .with_opt_disp_val(stmt.next.as_ref().map(|v| &v.0.index)); + .with_opt_disp_val(stmt.next.as_ref().map(|v| &v.index)); } } }, Statement::Skip(stmt) => { - self.kv(indent).with_id(PREFIX_SKIP_STMT_ID, stmt.this.0.0.index) + self.kv(indent).with_id(PREFIX_SKIP_STMT_ID, stmt.this.0.index) .with_s_key("Skip"); self.kv(indent2).with_s_key("Next") - .with_opt_disp_val(stmt.next.as_ref().map(|v| &v.0.index)); + .with_opt_disp_val(stmt.next.as_ref().map(|v| &v.index)); }, Statement::Labeled(stmt) => { - self.kv(indent).with_id(PREFIX_LABELED_STMT_ID, stmt.this.0.0.index) + self.kv(indent).with_id(PREFIX_LABELED_STMT_ID, stmt.this.0.index) .with_s_key("Labeled"); self.kv(indent2).with_s_key("Label").with_ascii_val(&stmt.label.value); @@ -354,11 +354,11 @@ impl ASTWriter { self.write_stmt(heap, stmt.body, indent3); }, Statement::If(stmt) => { - self.kv(indent).with_id(PREFIX_IF_STMT_ID, stmt.this.0.0.index) + self.kv(indent).with_id(PREFIX_IF_STMT_ID, stmt.this.0.index) .with_s_key("If"); self.kv(indent2).with_s_key("EndIf") - .with_opt_disp_val(stmt.end_if.as_ref().map(|v| &v.0.0.index)); + .with_opt_disp_val(stmt.end_if.as_ref().map(|v| &v.0.index)); self.kv(indent2).with_s_key("Condition"); self.write_expr(heap, stmt.test, indent3); @@ -370,108 +370,108 @@ impl ASTWriter { self.write_stmt(heap, stmt.false_body, indent3); }, Statement::EndIf(stmt) => { - self.kv(indent).with_id(PREFIX_ENDIF_STMT_ID, stmt.this.0.0.index) + self.kv(indent).with_id(PREFIX_ENDIF_STMT_ID, stmt.this.0.index) .with_s_key("EndIf"); - self.kv(indent2).with_s_key("StartIf").with_disp_val(&stmt.start_if.0.0.index); + self.kv(indent2).with_s_key("StartIf").with_disp_val(&stmt.start_if.0.index); self.kv(indent2).with_s_key("Next") - .with_opt_disp_val(stmt.next.as_ref().map(|v| &v.0.index)); + .with_opt_disp_val(stmt.next.as_ref().map(|v| &v.index)); }, Statement::While(stmt) => { - self.kv(indent).with_id(PREFIX_WHILE_STMT_ID, stmt.this.0.0.index) + self.kv(indent).with_id(PREFIX_WHILE_STMT_ID, stmt.this.0.index) .with_s_key("While"); self.kv(indent2).with_s_key("EndWhile") - .with_opt_disp_val(stmt.end_while.as_ref().map(|v| &v.0.0.index)); + .with_opt_disp_val(stmt.end_while.as_ref().map(|v| &v.0.index)); self.kv(indent2).with_s_key("InSync") - .with_opt_disp_val(stmt.in_sync.as_ref().map(|v| &v.0.0.index)); + .with_opt_disp_val(stmt.in_sync.as_ref().map(|v| &v.0.index)); self.kv(indent2).with_s_key("Condition"); self.write_expr(heap, stmt.test, indent3); self.kv(indent2).with_s_key("Body"); self.write_stmt(heap, stmt.body, indent3); }, Statement::EndWhile(stmt) => { - self.kv(indent).with_id(PREFIX_ENDWHILE_STMT_ID, stmt.this.0.0.index) + self.kv(indent).with_id(PREFIX_ENDWHILE_STMT_ID, stmt.this.0.index) .with_s_key("EndWhile"); - self.kv(indent2).with_s_key("StartWhile").with_disp_val(&stmt.start_while.0.0.index); + self.kv(indent2).with_s_key("StartWhile").with_disp_val(&stmt.start_while.0.index); self.kv(indent2).with_s_key("Next") - .with_opt_disp_val(stmt.next.as_ref().map(|v| &v.0.index)); + .with_opt_disp_val(stmt.next.as_ref().map(|v| &v.index)); }, Statement::Break(stmt) => { - self.kv(indent).with_id(PREFIX_BREAK_STMT_ID, stmt.this.0.0.index) + self.kv(indent).with_id(PREFIX_BREAK_STMT_ID, stmt.this.0.index) .with_s_key("Break"); self.kv(indent2).with_s_key("Label") .with_opt_ascii_val(stmt.label.as_ref().map(|v| v.value.as_slice())); self.kv(indent2).with_s_key("Target") - .with_opt_disp_val(stmt.target.as_ref().map(|v| &v.0.0.index)); + .with_opt_disp_val(stmt.target.as_ref().map(|v| &v.0.index)); }, Statement::Continue(stmt) => { - self.kv(indent).with_id(PREFIX_CONTINUE_STMT_ID, stmt.this.0.0.index) + self.kv(indent).with_id(PREFIX_CONTINUE_STMT_ID, stmt.this.0.index) .with_s_key("Continue"); self.kv(indent2).with_s_key("Label") .with_opt_ascii_val(stmt.label.as_ref().map(|v| v.value.as_slice())); self.kv(indent2).with_s_key("Target") - .with_opt_disp_val(stmt.target.as_ref().map(|v| &v.0.0.index)); + .with_opt_disp_val(stmt.target.as_ref().map(|v| &v.0.index)); }, Statement::Synchronous(stmt) => { - self.kv(indent).with_id(PREFIX_SYNC_STMT_ID, stmt.this.0.0.index) + self.kv(indent).with_id(PREFIX_SYNC_STMT_ID, stmt.this.0.index) .with_s_key("Synchronous"); self.kv(indent2).with_s_key("EndSync") - .with_opt_disp_val(stmt.end_sync.as_ref().map(|v| &v.0.0.index)); + .with_opt_disp_val(stmt.end_sync.as_ref().map(|v| &v.0.index)); self.kv(indent2).with_s_key("Body"); self.write_stmt(heap, stmt.body, indent3); }, Statement::EndSynchronous(stmt) => { - self.kv(indent).with_id(PREFIX_ENDSYNC_STMT_ID, stmt.this.0.0.index) + self.kv(indent).with_id(PREFIX_ENDSYNC_STMT_ID, stmt.this.0.index) .with_s_key("EndSynchronous"); - self.kv(indent2).with_s_key("StartSync").with_disp_val(&stmt.start_sync.0.0.index); + self.kv(indent2).with_s_key("StartSync").with_disp_val(&stmt.start_sync.0.index); self.kv(indent2).with_s_key("Next") - .with_opt_disp_val(stmt.next.as_ref().map(|v| &v.0.index)); + .with_opt_disp_val(stmt.next.as_ref().map(|v| &v.index)); }, Statement::Return(stmt) => { - self.kv(indent).with_id(PREFIX_RETURN_STMT_ID, stmt.this.0.0.index) + self.kv(indent).with_id(PREFIX_RETURN_STMT_ID, stmt.this.0.index) .with_s_key("Return"); self.kv(indent2).with_s_key("Expression"); self.write_expr(heap, stmt.expression, indent3); }, Statement::Assert(stmt) => { - self.kv(indent).with_id(PREFIX_ASSERT_STMT_ID, stmt.this.0.0.index) + self.kv(indent).with_id(PREFIX_ASSERT_STMT_ID, stmt.this.0.index) .with_s_key("Assert"); self.kv(indent2).with_s_key("Expression"); self.write_expr(heap, stmt.expression, indent3); self.kv(indent2).with_s_key("Next") - .with_opt_disp_val(stmt.next.as_ref().map(|v| &v.0.index)); + .with_opt_disp_val(stmt.next.as_ref().map(|v| &v.index)); }, Statement::Goto(stmt) => { - self.kv(indent).with_id(PREFIX_GOTO_STMT_ID, stmt.this.0.0.index) + self.kv(indent).with_id(PREFIX_GOTO_STMT_ID, stmt.this.0.index) .with_s_key("Goto"); self.kv(indent2).with_s_key("Label").with_ascii_val(&stmt.label.value); self.kv(indent2).with_s_key("Target") - .with_opt_disp_val(stmt.target.as_ref().map(|v| &v.0.0.index)); + .with_opt_disp_val(stmt.target.as_ref().map(|v| &v.0.index)); }, Statement::New(stmt) => { - self.kv(indent).with_id(PREFIX_NEW_STMT_ID, stmt.this.0.0.index) + self.kv(indent).with_id(PREFIX_NEW_STMT_ID, stmt.this.0.index) .with_s_key("New"); self.kv(indent2).with_s_key("Expression"); self.write_expr(heap, stmt.expression.upcast(), indent3); self.kv(indent2).with_s_key("Next") - .with_opt_disp_val(stmt.next.as_ref().map(|v| &v.0.index)); + .with_opt_disp_val(stmt.next.as_ref().map(|v| &v.index)); }, Statement::Put(stmt) => { - self.kv(indent).with_id(PREFIX_PUT_STMT_ID, stmt.this.0.0.index) + self.kv(indent).with_id(PREFIX_PUT_STMT_ID, stmt.this.0.index) .with_s_key("Put"); self.kv(indent2).with_s_key("Port"); self.write_expr(heap, stmt.port, indent3); self.kv(indent2).with_s_key("Message"); self.write_expr(heap, stmt.message, indent3); self.kv(indent2).with_s_key("Next") - .with_opt_disp_val(stmt.next.as_ref().map(|v| &v.0.index)); + .with_opt_disp_val(stmt.next.as_ref().map(|v| &v.index)); }, Statement::Expression(stmt) => { - self.kv(indent).with_id(PREFIX_EXPR_STMT_ID, stmt.this.0.0.index) + self.kv(indent).with_id(PREFIX_EXPR_STMT_ID, stmt.this.0.index) .with_s_key("ExpressionStatement"); self.write_expr(heap, stmt.expression, indent2); self.kv(indent2).with_s_key("Next") - .with_opt_disp_val(stmt.next.as_ref().map(|v| &v.0.index)); + .with_opt_disp_val(stmt.next.as_ref().map(|v| &v.index)); } } } @@ -483,7 +483,7 @@ impl ASTWriter { match expr { Expression::Assignment(expr) => { - self.kv(indent).with_id(PREFIX_ASSIGNMENT_EXPR_ID, expr.this.0.0.index) + self.kv(indent).with_id(PREFIX_ASSIGNMENT_EXPR_ID, expr.this.0.index) .with_s_key("AssignmentExpr"); self.kv(indent2).with_s_key("Operation").with_debug_val(&expr.operation); self.kv(indent2).with_s_key("Left"); @@ -492,7 +492,7 @@ impl ASTWriter { self.write_expr(heap, expr.right, indent3); }, Expression::Conditional(expr) => { - self.kv(indent).with_id(PREFIX_CONDITIONAL_EXPR_ID, expr.this.0.0.index) + self.kv(indent).with_id(PREFIX_CONDITIONAL_EXPR_ID, expr.this.0.index) .with_s_key("ConditionalExpr"); self.kv(indent2).with_s_key("Condition"); self.write_expr(heap, expr.test, indent3); @@ -502,7 +502,7 @@ impl ASTWriter { self.write_expr(heap, expr.false_expression, indent3); }, Expression::Binary(expr) => { - self.kv(indent).with_id(PREFIX_BINARY_EXPR_ID, expr.this.0.0.index) + self.kv(indent).with_id(PREFIX_BINARY_EXPR_ID, expr.this.0.index) .with_s_key("BinaryExpr"); self.kv(indent2).with_s_key("Operation").with_debug_val(&expr.operation); self.kv(indent2).with_s_key("Left"); @@ -511,14 +511,14 @@ impl ASTWriter { self.write_expr(heap, expr.right, indent3); }, Expression::Unary(expr) => { - self.kv(indent).with_id(PREFIX_UNARY_EXPR_ID, expr.this.0.0.index) + self.kv(indent).with_id(PREFIX_UNARY_EXPR_ID, expr.this.0.index) .with_s_key("UnaryExpr"); self.kv(indent2).with_s_key("Operation").with_debug_val(&expr.operation); self.kv(indent2).with_s_key("Argument"); self.write_expr(heap, expr.expression, indent3); }, Expression::Indexing(expr) => { - self.kv(indent).with_id(PREFIX_INDEXING_EXPR_ID, expr.this.0.0.index) + self.kv(indent).with_id(PREFIX_INDEXING_EXPR_ID, expr.this.0.index) .with_s_key("IndexingExpr"); self.kv(indent2).with_s_key("Subject"); self.write_expr(heap, expr.subject, indent3); @@ -526,7 +526,7 @@ impl ASTWriter { self.write_expr(heap, expr.index, indent3); }, Expression::Slicing(expr) => { - self.kv(indent).with_id(PREFIX_SLICING_EXPR_ID, expr.this.0.0.index) + self.kv(indent).with_id(PREFIX_SLICING_EXPR_ID, expr.this.0.index) .with_s_key("SlicingExpr"); self.kv(indent2).with_s_key("Subject"); self.write_expr(heap, expr.subject, indent3); @@ -536,7 +536,7 @@ impl ASTWriter { self.write_expr(heap, expr.to_index, indent3); }, Expression::Select(expr) => { - self.kv(indent).with_id(PREFIX_SELECT_EXPR_ID, expr.this.0.0.index) + self.kv(indent).with_id(PREFIX_SELECT_EXPR_ID, expr.this.0.index) .with_s_key("SelectExpr"); self.kv(indent2).with_s_key("Subject"); self.write_expr(heap, expr.subject, indent3); @@ -551,7 +551,7 @@ impl ASTWriter { } }, Expression::Array(expr) => { - self.kv(indent).with_id(PREFIX_ARRAY_EXPR_ID, expr.this.0.0.index) + self.kv(indent).with_id(PREFIX_ARRAY_EXPR_ID, expr.this.0.index) .with_s_key("ArrayExpr"); self.kv(indent2).with_s_key("Elements"); for expr_id in &expr.elements { @@ -559,7 +559,7 @@ impl ASTWriter { } }, Expression::Constant(expr) => { - self.kv(indent).with_id(PREFIX_CONST_EXPR_ID, expr.this.0.0.index) + self.kv(indent).with_id(PREFIX_CONST_EXPR_ID, expr.this.0.index) .with_s_key("ConstantExpr"); let val = self.kv(indent2).with_s_key("Value"); @@ -572,7 +572,7 @@ impl ASTWriter { } }, Expression::Call(expr) => { - self.kv(indent).with_id(PREFIX_CALL_EXPR_ID, expr.this.0.0.index) + self.kv(indent).with_id(PREFIX_CALL_EXPR_ID, expr.this.0.index) .with_s_key("CallExpr"); // Method @@ -585,7 +585,7 @@ impl ASTWriter { method.with_s_val("symbolic"); self.kv(indent3).with_s_key("Name").with_ascii_val(&symbolic.identifier.value); self.kv(indent3).with_s_key("Definition") - .with_opt_disp_val(symbolic.definition.as_ref().map(|v| &v.0.index)); + .with_opt_disp_val(symbolic.definition.as_ref().map(|v| &v.index)); } } @@ -596,11 +596,11 @@ impl ASTWriter { } }, Expression::Variable(expr) => { - self.kv(indent).with_id(PREFIX_VARIABLE_EXPR_ID, expr.this.0.0.index) + self.kv(indent).with_id(PREFIX_VARIABLE_EXPR_ID, expr.this.0.index) .with_s_key("VariableExpr"); self.kv(indent2).with_s_key("Name").with_ascii_val(&expr.identifier.value); self.kv(indent2).with_s_key("Definition") - .with_opt_disp_val(expr.declaration.as_ref().map(|v| &v.0.index)); + .with_opt_disp_val(expr.declaration.as_ref().map(|v| &v.index)); } } } @@ -609,7 +609,7 @@ impl ASTWriter { let local = &heap[local_id]; let indent2 = indent + 1; - self.kv(indent).with_id(PREFIX_LOCAL_ID, local_id.0.0.index) + self.kv(indent).with_id(PREFIX_LOCAL_ID, local_id.0.index) .with_s_key("Local"); self.kv(indent2).with_s_key("Name").with_ascii_val(&local.identifier.value); @@ -651,7 +651,7 @@ fn write_type(target: &mut String, t: &TypeAnnotation) { PrimitiveType::Long => target.write_str("long"), PrimitiveType::Symbolic(symbolic) => { let mut temp = String::new(); - write_option(&mut temp, symbolic.definition.map(|v| v.0.index)); + write_option(&mut temp, symbolic.definition.map(|v| v.index)); write!(target, "Symbolic(name: {}, target: {})", String::from_utf8_lossy(&symbolic.identifier.value), &temp) } }; diff --git a/src/protocol/parser/symbol_table.rs b/src/protocol/parser/symbol_table.rs index d9b70b2bbb2e6fd06b023fca297ece83aa1cc62e..e194388b17347616e7e9cf1dd74957b2b71143a1 100644 --- a/src/protocol/parser/symbol_table.rs +++ b/src/protocol/parser/symbol_table.rs @@ -77,7 +77,7 @@ impl SymbolTable { if cfg!(debug_assertions) { for (index, module) in modules.iter().enumerate() { debug_assert_eq!( - index, module.root_id.0.index as usize, + index, module.root_id.index as usize, "module RootId does not correspond to LexedModule index" ) } @@ -205,7 +205,7 @@ impl SymbolTable { &format!("Imported symbol '{}' is already defined", String::from_utf8_lossy(&identifier.value)) ) .with_postfixed_info( - &modules[target_root_id.0.index as usize].source, + &modules[target_root_id.index as usize].source, definition.position(), "The imported symbol is defined here" ) diff --git a/src/protocol/parser/type_table.rs b/src/protocol/parser/type_table.rs index 1c54fc3dde40c4d9dd7e6009ce1e2b8cd1d39932..5a451562852a60bea1170283f5fa32e25cfea099 100644 --- a/src/protocol/parser/type_table.rs +++ b/src/protocol/parser/type_table.rs @@ -131,7 +131,7 @@ impl TypeTable { ) -> Result { if cfg!(debug_assertions) { for (index, module) in modules.iter().enumerate() { - debug_assert_eq!(index, module.root_id.0.index as usize) + debug_assert_eq!(index, module.root_id.index as usize) } } @@ -188,7 +188,7 @@ impl TypeTable { if is_cyclic { let mut error = ParseError2::new_error( - &all_modules[new_root_id.0.index as usize].source, + &all_modules[new_root_id.index as usize].source, heap[new_definition_id].position(), "Evaluating this definition results in a a cyclic dependency" ); @@ -205,7 +205,7 @@ impl TypeTable { Breadcrumb::Jumping((root_id, definition_id)) => { debug_assert!(index > 0); error = error.with_postfixed_info( - &all_modules[root_id.0.index as usize].source, + &all_modules[root_id.index as usize].source, heap[*definition_id].position(), "Which depends on this definition" ) @@ -251,7 +251,7 @@ impl TypeTable { (module, definition_id) }, Breadcrumb::Jumping((root_id, definition_id)) => { - let module = &modules[root_id.0.index as usize]; + let module = &modules[root_id.index as usize]; debug_assert_eq!(module.root_id, *root_id); (module, *definition_id) } diff --git a/src/protocol/parser/visitor_linker.rs b/src/protocol/parser/visitor_linker.rs index 8a05332e0e5a85283b79e376d602260dcb788b86..3831aad78e31d5b2fcdbc31d8c7d9225ced3e7e1 100644 --- a/src/protocol/parser/visitor_linker.rs +++ b/src/protocol/parser/visitor_linker.rs @@ -698,7 +698,7 @@ impl ValidityAndLinkerVisitor { // the traversal of the block's statements. let body = &mut ctx.heap[id]; body.parent_scope = self.cur_scope.clone(); - println!("DEBUG: Assigning relative {} to block {}", self.relative_pos_in_block, id.0.0.index); + println!("DEBUG: Assigning relative {} to block {}", self.relative_pos_in_block, id.0.index); body.relative_pos_in_parent = self.relative_pos_in_block; let old_scope = self.cur_scope.replace(match hint {