authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-08-21 20:50:03-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-08-21 20:50:03-04:00
logb2917e6be09138adcf7cfdab51a1909a30eec320
tree63c0f2fbcf313b5316b29444365304d62287aaf9
parent937b822fa90181bf59f1c2ac45faab09342a183f

Revert "Merge branch 'mtn-translate-c-enum-vals'"

This reverts commit 937b822fa90181bf59f1c2ac45faab09342a183f, reversing changes made to dd4b13ac0326aeb6c2c197bfac49f9e931ccee37. Tests failing on Windows. Re-opens #1360

2 files changed, 2 insertions(+), 62 deletions(-)

src/translate_c.cpp+2-8
...@@ -458,15 +458,9 @@ static const char *decl_name(const Decl *decl) {...@@ -458,15 +458,9 @@ static const char *decl_name(const Decl *decl) {
458static AstNode *trans_create_node_apint(Context *c, const llvm::APSInt &aps_int) {458static AstNode *trans_create_node_apint(Context *c, const llvm::APSInt &aps_int) {
459 AstNode *node = trans_create_node(c, NodeTypeIntLiteral);459 AstNode *node = trans_create_node(c, NodeTypeIntLiteral);
460 node->data.int_literal.bigint = allocate<BigInt>(1);460 node->data.int_literal.bigint = allocate<BigInt>(1);
461 bool is_negative = aps_int.isNegative();461 bigint_init_data(node->data.int_literal.bigint, aps_int.getRawData(), aps_int.getNumWords(), aps_int.isNegative());
462 // ACHTUNG: llvm::APSInt stores an int's sign inside of its getRawData;
463 // Internally to Zig we store an integer's sign outside of getRawData!
464 // ++(~aps_int) calls .flip() internally on the raw data to match Zig.
465 bigint_init_data( node->data.int_literal.bigint
466 , (is_negative ? (++(~aps_int)) : aps_int).getRawData()
467 , aps_int.getNumWords()
468 , is_negative );
469 return node;462 return node;
463
470}464}
471465
472static const Type *qual_type_canon(QualType qt) {466static const Type *qual_type_canon(QualType qt) {
test/translate_c.zig-54
...@@ -1358,58 +1358,4 @@ pub fn addCases(cases: *tests.TranslateCContext) void {...@@ -1358,58 +1358,4 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
1358 \\ }1358 \\ }
1359 \\}1359 \\}
1360 );1360 );
1361
1362 cases.add("correctly translate enum init values",
1363 \\enum EnumWithInits {
1364 \\ VAL01 = 0,
1365 \\ VAL02 = 1,
1366 \\ VAL03 = 2,
1367 \\ VAL04 = 3,
1368 \\ VAL05 = -1,
1369 \\ VAL06 = -2,
1370 \\ VAL07 = -3,
1371 \\ VAL08 = -4,
1372 \\ VAL09 = VAL02 + VAL08,
1373 \\ VAL10 = -1000012000,
1374 \\ VAL11 = -1000161000,
1375 \\ VAL12 = -1000174001,
1376 \\ VAL13 = VAL09,
1377 \\ VAL14 = VAL10,
1378 \\ VAL15 = VAL11,
1379 \\ VAL16 = VAL13,
1380 \\ VAL17 = (VAL16 - VAL10 + 1),
1381 \\ VAL18 = 0x1000000000000000L,
1382 \\ VAL19 = VAL18 + VAL18 + VAL18 - 1,
1383 \\ VAL20 = VAL19 + VAL19,
1384 \\ VAL21 = VAL20 + 0xFFFFFFFFFFFFFFFF,
1385 \\ VAL22 = 0xFFFFFFFFFFFFFFFF + 1,
1386 \\ VAL23 = 0xFFFFFFFFFFFFFFFF,
1387 \\};
1388 ,
1389 \\pub const enum_EnumWithInits = extern enum(c_longlong) {
1390 \\ VAL01 = 0,
1391 \\ VAL02 = 1,
1392 \\ VAL03 = 2,
1393 \\ VAL04 = 3,
1394 \\ VAL05 = -1,
1395 \\ VAL06 = -2,
1396 \\ VAL07 = -3,
1397 \\ VAL08 = -4,
1398 \\ VAL09 = -3,
1399 \\ VAL10 = -1000012000,
1400 \\ VAL11 = -1000161000,
1401 \\ VAL12 = -1000174001,
1402 \\ VAL13 = -3,
1403 \\ VAL14 = -1000012000,
1404 \\ VAL15 = -1000161000,
1405 \\ VAL16 = -3,
1406 \\ VAL17 = 1000011998,
1407 \\ VAL18 = 1152921504606846976,
1408 \\ VAL19 = 3458764513820540927,
1409 \\ VAL20 = 6917529027641081854,
1410 \\ VAL21 = 6917529027641081853,
1411 \\ VAL22 = 0,
1412 \\ VAL23 = -1,
1413 \\};
1414 );
1415}1361}