def _assert_table_contains(put: unittest.TestCase, table: sut.SymbolTable, expected_symbol: NameAndValue): put.assertTrue(table.contains(expected_symbol.name), 'table SHOULD contain the value') put.assertIn(expected_symbol.name, table.names_set, 'names set should contain the value') put.assertIs(expected_symbol.value, table.lookup(expected_symbol.name), 'lookup should fins the value')
def _assert_table_contains(put: unittest.TestCase, table: sut.SymbolTable, expected_symbol: NameAndValue[ASymbolTableValue]): put.assertTrue(table.contains(expected_symbol.name), 'table SHOULD contain the value') put.assertIn(expected_symbol.name, table.names_set, 'names set should contain the value') put.assertIs(expected_symbol.value, table.lookup(expected_symbol.name), 'lookup should fins the value')
def _validate_symbol_reference(symbol_table: SymbolTable, reference: su.SymbolReference, ) -> Optional[PartialInstructionControlledFailureInfo]: assert isinstance(reference, su.SymbolReference) if not symbol_table.contains(reference.name): error_message = error_messages.undefined_symbol(reference) return PartialInstructionControlledFailureInfo( PartialControlledFailureEnum.VALIDATION_ERROR, error_message) else: err_msg = _validate_reference(reference, symbol_table) if err_msg is not None: return PartialInstructionControlledFailureInfo(PartialControlledFailureEnum.VALIDATION_ERROR, err_msg) return None
def _validate_symbol_reference( symbol_table: SymbolTable, reference: SymbolReference, ) -> Optional[PartialInstructionControlledFailureInfo]: assert isinstance(reference, SymbolReference) if not symbol_table.contains(reference.name): return PartialInstructionControlledFailureInfo( PartialControlledFailureEnum.VALIDATION_ERROR, error_messages.undefined_symbol(reference)) else: err_msg = _validate_reference(reference, symbol_table) if err_msg is not None: return PartialInstructionControlledFailureInfo( PartialControlledFailureEnum.VALIDATION_ERROR, err_msg) return None
def _validate_symbol_definition(symbol_table: SymbolTable, definition: su.SymbolDefinition, ) -> Optional[PartialInstructionControlledFailureInfo]: if symbol_table.contains(definition.name): already_defined_resolver_container = symbol_table.lookup(definition.name) assert isinstance(already_defined_resolver_container, SymbolContainer), \ 'Value in SymTbl must be ResolverContainer' return PartialInstructionControlledFailureInfo( PartialControlledFailureEnum.VALIDATION_ERROR, error_messages.duplicate_symbol_definition(already_defined_resolver_container.source_location, definition.name)) else: for referenced_value in definition.references: failure_info = validate_symbol_usage(referenced_value, symbol_table) if failure_info is not None: return failure_info symbol_table.add(definition.symbol_table_entry) return None
def _validate_symbol_definition( symbol_table: SymbolTable, definition: SymbolDefinition, ) -> Optional[PartialInstructionControlledFailureInfo]: if symbol_table.contains(definition.name): already_defined_sdv_container = symbol_table.lookup(definition.name) assert isinstance(already_defined_sdv_container, SymbolContainer), \ 'Value in SymTbl must be ResolverContainer' return PartialInstructionControlledFailureInfo( PartialControlledFailureEnum.VALIDATION_ERROR, error_messages.duplicate_symbol_definition( already_defined_sdv_container.source_location, definition.name)) else: for referenced_value in definition.references: failure_info = validate_symbol_usage(referenced_value, symbol_table) if failure_info is not None: return failure_info symbol_table.add(definition.symbol_table_entry) return None