Allow user-defined types as mapping keys in parser and restrict to contracts during type checking.

This commit is contained in:
Daniel Kirchner
2020-02-04 17:22:03 +01:00
parent 7a194ffdab
commit d3cbfb0c5c
25 changed files with 808 additions and 18 deletions
+227
View File
@@ -0,0 +1,227 @@
{
"absolutePath": "a",
"exportedSymbols":
{
"C":
[
17
]
},
"id": 18,
"nodeType": "SourceUnit",
"nodes":
[
{
"abstract": false,
"baseContracts": [],
"contractDependencies": [],
"contractKind": "contract",
"documentation": null,
"fullyImplemented": true,
"id": 17,
"linearizedBaseContracts":
[
17
],
"name": "C",
"nodeType": "ContractDefinition",
"nodes":
[
{
"canonicalName": "C.E",
"id": 4,
"members":
[
{
"id": 1,
"name": "A",
"nodeType": "EnumValue",
"src": "26:1:1"
},
{
"id": 2,
"name": "B",
"nodeType": "EnumValue",
"src": "29:1:1"
},
{
"id": 3,
"name": "C",
"nodeType": "EnumValue",
"src": "32:1:1"
}
],
"name": "E",
"nodeType": "EnumDefinition",
"src": "17:18:1"
},
{
"constant": false,
"id": 8,
"name": "a",
"nodeType": "VariableDeclaration",
"overrides": null,
"scope": 17,
"src": "40:20:1",
"stateVariable": true,
"storageLocation": "default",
"typeDescriptions":
{
"typeIdentifier": "t_mapping$_t_contract$_C_$17_$_t_bool_$",
"typeString": "mapping(contract C => bool)"
},
"typeName":
{
"id": 7,
"keyType":
{
"contractScope": null,
"id": 5,
"name": "C",
"nodeType": "UserDefinedTypeName",
"referencedDeclaration": 17,
"src": "48:1:1",
"typeDescriptions":
{
"typeIdentifier": "t_contract$_C_$17",
"typeString": "contract C"
}
},
"nodeType": "Mapping",
"src": "40:18:1",
"typeDescriptions":
{
"typeIdentifier": "t_mapping$_t_contract$_C_$17_$_t_bool_$",
"typeString": "mapping(contract C => bool)"
},
"valueType":
{
"id": 6,
"name": "bool",
"nodeType": "ElementaryTypeName",
"src": "53:4:1",
"typeDescriptions":
{
"typeIdentifier": "t_bool",
"typeString": "bool"
}
}
},
"value": null,
"visibility": "internal"
},
{
"constant": false,
"id": 12,
"name": "b",
"nodeType": "VariableDeclaration",
"overrides": null,
"scope": 17,
"src": "66:26:1",
"stateVariable": true,
"storageLocation": "default",
"typeDescriptions":
{
"typeIdentifier": "t_mapping$_t_address_$_t_bool_$",
"typeString": "mapping(address => bool)"
},
"typeName":
{
"id": 11,
"keyType":
{
"id": 9,
"name": "address",
"nodeType": "ElementaryTypeName",
"src": "74:7:1",
"typeDescriptions":
{
"typeIdentifier": "t_address",
"typeString": "address"
}
},
"nodeType": "Mapping",
"src": "66:24:1",
"typeDescriptions":
{
"typeIdentifier": "t_mapping$_t_address_$_t_bool_$",
"typeString": "mapping(address => bool)"
},
"valueType":
{
"id": 10,
"name": "bool",
"nodeType": "ElementaryTypeName",
"src": "85:4:1",
"typeDescriptions":
{
"typeIdentifier": "t_bool",
"typeString": "bool"
}
}
},
"value": null,
"visibility": "internal"
},
{
"constant": false,
"id": 16,
"name": "c",
"nodeType": "VariableDeclaration",
"overrides": null,
"scope": 17,
"src": "98:20:1",
"stateVariable": true,
"storageLocation": "default",
"typeDescriptions":
{
"typeIdentifier": "t_mapping$_t_enum$_E_$4_$_t_bool_$",
"typeString": "mapping(enum C.E => bool)"
},
"typeName":
{
"id": 15,
"keyType":
{
"contractScope": null,
"id": 13,
"name": "E",
"nodeType": "UserDefinedTypeName",
"referencedDeclaration": 4,
"src": "106:1:1",
"typeDescriptions":
{
"typeIdentifier": "t_enum$_E_$4",
"typeString": "enum C.E"
}
},
"nodeType": "Mapping",
"src": "98:18:1",
"typeDescriptions":
{
"typeIdentifier": "t_mapping$_t_enum$_E_$4_$_t_bool_$",
"typeString": "mapping(enum C.E => bool)"
},
"valueType":
{
"id": 14,
"name": "bool",
"nodeType": "ElementaryTypeName",
"src": "111:4:1",
"typeDescriptions":
{
"typeIdentifier": "t_bool",
"typeString": "bool"
}
}
},
"value": null,
"visibility": "internal"
}
],
"scope": 18,
"src": "0:121:1"
}
],
"src": "0:122:1"
}
+8
View File
@@ -0,0 +1,8 @@
contract C {
enum E { A, B, C }
mapping(C => bool) a;
mapping(address => bool) b;
mapping(E => bool) c;
}
// ----
@@ -0,0 +1,248 @@
{
"attributes":
{
"absolutePath": "a",
"exportedSymbols":
{
"C":
[
17
]
}
},
"children":
[
{
"attributes":
{
"abstract": false,
"baseContracts":
[
null
],
"contractDependencies":
[
null
],
"contractKind": "contract",
"documentation": null,
"fullyImplemented": true,
"linearizedBaseContracts":
[
17
],
"name": "C",
"scope": 18
},
"children":
[
{
"attributes":
{
"canonicalName": "C.E",
"name": "E"
},
"children":
[
{
"attributes":
{
"name": "A"
},
"id": 1,
"name": "EnumValue",
"src": "26:1:1"
},
{
"attributes":
{
"name": "B"
},
"id": 2,
"name": "EnumValue",
"src": "29:1:1"
},
{
"attributes":
{
"name": "C"
},
"id": 3,
"name": "EnumValue",
"src": "32:1:1"
}
],
"id": 4,
"name": "EnumDefinition",
"src": "17:18:1"
},
{
"attributes":
{
"constant": false,
"name": "a",
"overrides": null,
"scope": 17,
"stateVariable": true,
"storageLocation": "default",
"type": "mapping(contract C => bool)",
"value": null,
"visibility": "internal"
},
"children":
[
{
"attributes":
{
"type": "mapping(contract C => bool)"
},
"children":
[
{
"attributes":
{
"contractScope": null,
"name": "C",
"referencedDeclaration": 17,
"type": "contract C"
},
"id": 5,
"name": "UserDefinedTypeName",
"src": "48:1:1"
},
{
"attributes":
{
"name": "bool",
"type": "bool"
},
"id": 6,
"name": "ElementaryTypeName",
"src": "53:4:1"
}
],
"id": 7,
"name": "Mapping",
"src": "40:18:1"
}
],
"id": 8,
"name": "VariableDeclaration",
"src": "40:20:1"
},
{
"attributes":
{
"constant": false,
"name": "b",
"overrides": null,
"scope": 17,
"stateVariable": true,
"storageLocation": "default",
"type": "mapping(address => bool)",
"value": null,
"visibility": "internal"
},
"children":
[
{
"attributes":
{
"type": "mapping(address => bool)"
},
"children":
[
{
"attributes":
{
"name": "address",
"type": "address"
},
"id": 9,
"name": "ElementaryTypeName",
"src": "74:7:1"
},
{
"attributes":
{
"name": "bool",
"type": "bool"
},
"id": 10,
"name": "ElementaryTypeName",
"src": "85:4:1"
}
],
"id": 11,
"name": "Mapping",
"src": "66:24:1"
}
],
"id": 12,
"name": "VariableDeclaration",
"src": "66:26:1"
},
{
"attributes":
{
"constant": false,
"name": "c",
"overrides": null,
"scope": 17,
"stateVariable": true,
"storageLocation": "default",
"type": "mapping(enum C.E => bool)",
"value": null,
"visibility": "internal"
},
"children":
[
{
"attributes":
{
"type": "mapping(enum C.E => bool)"
},
"children":
[
{
"attributes":
{
"contractScope": null,
"name": "E",
"referencedDeclaration": 4,
"type": "enum C.E"
},
"id": 13,
"name": "UserDefinedTypeName",
"src": "106:1:1"
},
{
"attributes":
{
"name": "bool",
"type": "bool"
},
"id": 14,
"name": "ElementaryTypeName",
"src": "111:4:1"
}
],
"id": 15,
"name": "Mapping",
"src": "98:18:1"
}
],
"id": 16,
"name": "VariableDeclaration",
"src": "98:20:1"
}
],
"id": 17,
"name": "ContractDefinition",
"src": "0:121:1"
}
],
"id": 18,
"name": "SourceUnit",
"src": "0:122:1"
}