diff --git a/src/simplified_representation/emitter.rs b/src/simplified_representation/emitter.rs index c650f6b..f4a32e5 100644 --- a/src/simplified_representation/emitter.rs +++ b/src/simplified_representation/emitter.rs @@ -167,6 +167,9 @@ impl AstConverting for SrEmitter { NodeTypeMapKey::EnclosedAddressMapKeyType(key) => key.visit(self)?, NodeTypeMapKey::AddressMapKeyType(key) => key.visit(self)?, }; + let identifier = self.pop_ir_identifier()?; + self.stack + .push(StackObject::TypeDefinition(identifier.into())); Ok(TraversalResult::SkipChildren) } fn emit_type_map_value( @@ -179,39 +182,26 @@ impl AstConverting for SrEmitter { match node { NodeTypeMapValue::MapValueTypeOrEnumLikeIdentifier(value) => { value.visit(self)?; - let value = self.pop_ir_identifier()?; - let key = self.pop_ir_identifier()?; - let map = SrType { - main_type: "Map".to_string(), - sub_types: vec![key.into(), value.into()], - address_type: None, - }; - self.stack.push(StackObject::TypeDefinition(map)); + let identifier = self.pop_ir_identifier()?; + self.stack + .push(StackObject::TypeDefinition(identifier.into())); } NodeTypeMapValue::MapKeyValue(value) => { value.visit(self)?; - } - NodeTypeMapValue::MapValueParenthesizedType(value) => { - value.visit(self)?; let value = self.pop_type_definition()?; - let key = self.pop_ir_identifier()?; + let key = self.pop_type_definition()?; let map = SrType { main_type: "Map".to_string(), - sub_types: vec![key.into(), value], + sub_types: vec![key, value], address_type: None, }; self.stack.push(StackObject::TypeDefinition(map)); } + NodeTypeMapValue::MapValueParenthesizedType(value) => { + value.visit(self)?; + } NodeTypeMapValue::MapValueAddressType(value) => { value.visit(self)?; - let value = self.pop_type_definition()?; - let key = self.pop_ir_identifier()?; - let map = SrType { - main_type: "Map".to_string(), - sub_types: vec![key.into(), value], - address_type: None, - }; - self.stack.push(StackObject::TypeDefinition(map)); } }; } @@ -270,6 +260,14 @@ impl AstConverting for SrEmitter { NodeScillaType::MapType(key, value) => { let _ = key.visit(self)?; let _ = value.visit(self)?; + let value = self.pop_type_definition()?; + let key = self.pop_type_definition()?; + let map = SrType { + main_type: "Map".to_string(), + sub_types: vec![key, value], + address_type: None, + }; + self.stack.push(StackObject::TypeDefinition(map)); } NodeScillaType::FunctionType(_a, _b) => { unimplemented!() @@ -666,7 +664,9 @@ impl AstConverting for SrEmitter { match mode { TreeTraversalMode::Enter => { match node { - NodeTypeMapValueArguments::EnclosedTypeMapValue(_) => todo!(), + NodeTypeMapValueArguments::EnclosedTypeMapValue(n) => { + n.visit(self)?; + } NodeTypeMapValueArguments::GenericMapValueArgument(g) => { g.visit(self)?; let identifier = self.pop_ir_identifier()?; diff --git a/tests/contracts/Map.scilla b/tests/contracts/Map.scilla new file mode 100644 index 0000000..fb3a0e4 --- /dev/null +++ b/tests/contracts/Map.scilla @@ -0,0 +1,10 @@ +scilla_version 0 +contract DifferentMaps +() + +field first_map: Map String BNum + = Emp String BNum +field status3days: Map String (Pair (ByStr20) (BNum)) + = Emp String (Pair (ByStr20) (BNum)) +field reward_pairs : Map ByStr20 (List Uint128) + = Emp (ByStr20) (List Uint128) \ No newline at end of file diff --git a/tests/full_contract_tests.rs b/tests/full_contract_tests.rs index 596d599..5c07faa 100644 --- a/tests/full_contract_tests.rs +++ b/tests/full_contract_tests.rs @@ -16,6 +16,40 @@ fn test_parse() -> Result<(), Box> { Ok(()) } +#[test] +fn test_map_contract_parse() { + let contract_path = PathBuf::from("tests/contracts/Map.scilla"); + let contract = Contract::parse(&contract_path).unwrap(); + assert_eq!( + contract, + Contract { + name: "DifferentMaps".to_string(), + init_params: FieldList::default(), + fields: FieldList(vec![ + Field::new( + "first_map", + Type::Map(Box::new(Type::String), Box::new(Type::BNum)) + ), + Field::new( + "status3days", + Type::Map( + Box::new(Type::String), + Box::new(Type::Pair(Box::new(Type::ByStr20), Box::new(Type::BNum))) + ) + ), + Field::new( + "reward_pairs", + Type::Map( + Box::new(Type::ByStr20), + Box::new(Type::List(Box::new(Type::Uint128))) + ) + ) + ]), + transitions: TransitionList::default() + } + ); +} + #[test] fn test_bystr_contract_parse() { let contract_path = PathBuf::from("tests/contracts/ByStr.scilla");