Skip to content

Commit fcd50c6

Browse files
authored
Support implicit conversion in std::vector constructor (#102)
Previously, f39 was a hack to support implicit cast in constructing a vector over the more generic f37 rule. I changed f37 to support implicit casts so that can write: ```cpp uint32_t src[3] = {1, 2, 3}; std::vector<int> v2(src, src + 3); ```
1 parent 1ac73cc commit fcd50c6

10 files changed

Lines changed: 312 additions & 283 deletions

rules/vector/ir_refcount.json

Lines changed: 38 additions & 125 deletions
Original file line numberDiff line numberDiff line change
@@ -1235,12 +1235,43 @@
12351235
"method_call": {
12361236
"receiver": [
12371237
{
1238-
"text": "__a0"
1238+
"method_call": {
1239+
"receiver": [
1240+
{
1241+
"generic": 1
1242+
},
1243+
{
1244+
"text": "::try_from("
1245+
},
1246+
{
1247+
"method_call": {
1248+
"receiver": [
1249+
{
1250+
"text": "__a0"
1251+
}
1252+
],
1253+
"body": [
1254+
{
1255+
"text": ".read()"
1256+
}
1257+
]
1258+
}
1259+
},
1260+
{
1261+
"text": ")"
1262+
}
1263+
],
1264+
"body": [
1265+
{
1266+
"text": ".ok()"
1267+
}
1268+
]
1269+
}
12391270
}
12401271
],
12411272
"body": [
12421273
{
1243-
"text": ".read()"
1274+
"text": ".unwrap()"
12441275
}
12451276
]
12461277
}
@@ -1257,146 +1288,28 @@
12571288
],
12581289
"generics": {
12591290
"T1": [
1291+
"TryFrom<T2>"
1292+
],
1293+
"T2": [
12601294
"Clone",
12611295
"ByteRepr"
12621296
]
12631297
},
12641298
"multi_statement": true,
12651299
"params": {
12661300
"a0": {
1267-
"type": "Ptr<T1>",
1301+
"type": "Ptr<T2>",
12681302
"is_refcount_pointer": true
12691303
},
12701304
"a1": {
1271-
"type": "Ptr<T1>",
1305+
"type": "Ptr<T2>",
12721306
"is_refcount_pointer": true
12731307
}
12741308
},
12751309
"return_type": {
12761310
"type": "Vec<T1>"
12771311
}
12781312
},
1279-
"f39": {
1280-
"body": [
1281-
{
1282-
"text": "let mut __a0 = "
1283-
},
1284-
{
1285-
"method_call": {
1286-
"receiver": [
1287-
{
1288-
"placeholder": {
1289-
"arg": 0,
1290-
"access": "read"
1291-
}
1292-
}
1293-
],
1294-
"body": [
1295-
{
1296-
"text": ".clone()"
1297-
}
1298-
]
1299-
}
1300-
},
1301-
{
1302-
"text": ";\n let mut __out = Vec::with_capacity("
1303-
},
1304-
{
1305-
"method_call": {
1306-
"receiver": [
1307-
{
1308-
"placeholder": {
1309-
"arg": 1,
1310-
"access": "read"
1311-
}
1312-
}
1313-
],
1314-
"body": [
1315-
{
1316-
"text": ".get_offset()"
1317-
}
1318-
]
1319-
}
1320-
},
1321-
{
1322-
"text": " - "
1323-
},
1324-
{
1325-
"method_call": {
1326-
"receiver": [
1327-
{
1328-
"text": "__a0"
1329-
}
1330-
],
1331-
"body": [
1332-
{
1333-
"text": ".get_offset()"
1334-
}
1335-
]
1336-
}
1337-
},
1338-
{
1339-
"text": ");\n while __a0 != "
1340-
},
1341-
{
1342-
"placeholder": {
1343-
"arg": 1,
1344-
"access": "read"
1345-
}
1346-
},
1347-
{
1348-
"text": " {\n "
1349-
},
1350-
{
1351-
"method_call": {
1352-
"receiver": [
1353-
{
1354-
"text": "__out"
1355-
}
1356-
],
1357-
"body": [
1358-
{
1359-
"text": ".push("
1360-
},
1361-
{
1362-
"method_call": {
1363-
"receiver": [
1364-
{
1365-
"text": "__a0"
1366-
}
1367-
],
1368-
"body": [
1369-
{
1370-
"text": ".read()"
1371-
}
1372-
]
1373-
}
1374-
},
1375-
{
1376-
"text": " as i32)"
1377-
}
1378-
]
1379-
}
1380-
},
1381-
{
1382-
"text": ";\n __a0 += 1;\n }\n __out"
1383-
}
1384-
],
1385-
"multi_statement": true,
1386-
"params": {
1387-
"a0": {
1388-
"type": "Ptr<u32>",
1389-
"is_refcount_pointer": true
1390-
},
1391-
"a1": {
1392-
"type": "Ptr<u32>",
1393-
"is_refcount_pointer": true
1394-
}
1395-
},
1396-
"return_type": {
1397-
"type": "Vec<i32>"
1398-
}
1399-
},
14001313
"f40": {
14011314
"body": [
14021315
{

0 commit comments

Comments
 (0)