forked from ldc-developers/ldc
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Better anonymous enum support, by mapping their members to manifest c…
…onstants. Add enum.d test.
- Loading branch information
Showing
3 changed files
with
134 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// RUN: %ldc -cpp-args -std=c++11 -cpp-cachedir=%t.cache -of %t %s | ||
// RUN: %t > %t.out | ||
// RUN: FileCheck %s < %t.out | ||
|
||
pragma (cppmap, "enum.h"); | ||
|
||
import std.stdio, std.conv, std.traits; | ||
import (C++) *; | ||
|
||
void main() | ||
{ | ||
// CHECK: fullname of AAA_1 = ℂcpp.EnumAAA.EnumAAA.AAA_1 | ||
writeln("fullname of AAA_1 = ", fullyQualifiedName!AAA_1); | ||
|
||
enum E5121 = BBB_5; | ||
// CHECK: typeof(E5121) = EnumBBB | ||
writeln("typeof(E5121) = ", typeof(E5121).stringof); | ||
|
||
// CHECK: Anon_2 = 4444 | ||
writeln("Anon_2 = ", Anon_2); | ||
// CHECK: EnumClass.EC_1 = EC_1 | ||
writeln("EnumClass.EC_1 = ", EnumClass.EC_1); | ||
static assert(!__traits(compiles, EC_2)); | ||
|
||
EnumTypedef tdef = TDEF_1; | ||
tdef = EnumTypedef.TDEF_2; | ||
// CHECK: tdef = TDEF_2 | ||
writeln("tdef = ", tdef); | ||
|
||
// CH_CK: test:: members => [] | ||
writeln("test:: members => ", [ __traits(allMembers, test) ]); | ||
|
||
// CHECK: Struct.AnonInStruct_2 = 1 | ||
writeln("Struct.AnonInStruct_2 = ", Struct.AnonInStruct_2); | ||
|
||
// CH_CK: Struct2 members => [] | ||
writeln("Struct2 members => ", [ __traits(allMembers, Struct2) ]); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
#pragma once | ||
|
||
enum EnumAAA | ||
{ | ||
AAA_1, | ||
AAA_2 = 512, | ||
AAA_3 = 8192, | ||
}; | ||
|
||
enum EnumBBB : char | ||
{ | ||
BBB_1 = 'a', | ||
BBB_2, | ||
BBB_3, | ||
BBB_4, | ||
BBB_5, | ||
}; | ||
|
||
enum | ||
{ | ||
Anon_1 = 2222, | ||
Anon_2 = 4444 | ||
}; | ||
|
||
enum class EnumClass | ||
{ | ||
EC_1, | ||
EC_2, | ||
EC_3 | ||
}; | ||
|
||
typedef enum | ||
{ | ||
TDEF_1, | ||
TDEF_2 | ||
} EnumTypedef; | ||
|
||
namespace test | ||
{ | ||
enum EnumInner | ||
{ | ||
EInn_1, | ||
EInn_2, | ||
EInn_3 | ||
}; | ||
|
||
enum class EnumClassInner | ||
{ | ||
CI_1, | ||
CI_2, | ||
CI_3 | ||
}; | ||
} | ||
|
||
struct Struct | ||
{ | ||
enum | ||
{ | ||
AnonInStruct_1, | ||
AnonInStruct_2 | ||
}; | ||
}; | ||
|
||
struct Struct2 | ||
{ | ||
enum | ||
{ | ||
AIS_1, | ||
AIS_2 | ||
}; | ||
}; |