Skip to content

Commit

Permalink
Fix parsing complex address types in transitions.
Browse files Browse the repository at this point in the history
  • Loading branch information
saeed-zil committed Nov 21, 2024
1 parent 7ace646 commit 2e10080
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 24 deletions.
54 changes: 32 additions & 22 deletions src/simplified_representation/emitter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -283,38 +283,48 @@ impl AstConverting for SrEmitter {
}
fn emit_address_type_field(
&mut self,
_mode: TreeTraversalMode,
mode: TreeTraversalMode,
node: &NodeAddressTypeField,
) -> Result<TraversalResult, String> {
if let NodeVariableIdentifier::VariableName(n) = &node.identifier.node {
node.type_name.visit(self)?;
let typename = self.pop_type_definition()?;
let s = StackObject::VariableDeclaration(Field::new(&n.node, typename.into()));
self.stack.push(s);
match mode {
TreeTraversalMode::Enter => {
if let NodeVariableIdentifier::VariableName(n) = &node.identifier.node {
node.type_name.visit(self)?;
let typename = self.pop_type_definition()?;
let s = StackObject::VariableDeclaration(Field::new(&n.node, typename.into()));
self.stack.push(s);
}
}
TreeTraversalMode::Exit => (),
}
Ok(TraversalResult::SkipChildren)
}
fn emit_address_type(
&mut self,
_mode: TreeTraversalMode,
mode: TreeTraversalMode,
node: &NodeAddressType,
) -> Result<TraversalResult, String> {
node.identifier.visit(self)?;
let identifier = self.pop_ir_identifier()?;
self.stack
.push(StackObject::TypeDefinition(identifier.into()));
let mut main_type = self.pop_type_definition()?;
let mut fields = vec![];
for field in &node.address_fields {
field.visit(self)?;
let field = self.pop_variable_declaration()?;
fields.push(field);
match mode {
TreeTraversalMode::Enter => {
node.identifier.visit(self)?;
let identifier = self.pop_ir_identifier()?;
self.stack
.push(StackObject::TypeDefinition(identifier.into()));
let mut main_type = self.pop_type_definition()?;
let mut fields = vec![];
for field in &node.address_fields {
field.visit(self)?;
let field = self.pop_variable_declaration()?;
fields.push(field);
}
main_type.address_type = Some(AddressType {
type_name: node.type_name.node.clone(),
fields: FieldList(fields),
});
self.stack.push(StackObject::TypeDefinition(main_type));
}
TreeTraversalMode::Exit => (),
}
main_type.address_type = Some(AddressType {
type_name: node.type_name.node.clone(),
fields: FieldList(fields),
});
self.stack.push(StackObject::TypeDefinition(main_type));
Ok(TraversalResult::SkipChildren)
}

Expand Down
6 changes: 5 additions & 1 deletion tests/contracts/ByStr.scilla
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,8 @@ contract AllByStrVariants
field balances : Map ByStr20 Uint128,
field total_supply : Uint128
end
)
)

transition ArbitrageFromXCAD
(token : ByStr20 with contract field balances : Map ByStr20 Uint128 end)
end
14 changes: 13 additions & 1 deletion tests/full_contract_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,19 @@ fn test_bystr_contract_parse() {
)
]),
fields: FieldList::default(),
transitions: TransitionList::default(),
transitions: TransitionList(vec![Transition::new(
"ArbitrageFromXCAD",
FieldList(vec![Field::new(
"token",
Type::ByStr20With {
type_name: "contract".to_string(),
fields: FieldList(vec![Field::new(
"balances",
Type::Map(Box::new(Type::ByStr20), Box::new(Type::Uint128))
),],),
},
)]),
)])
}
);
}
Expand Down

0 comments on commit 2e10080

Please sign in to comment.