Skip to content

Commit

Permalink
Restore unsigned shift, named ALL flags
Browse files Browse the repository at this point in the history
  • Loading branch information
mutagene committed Nov 19, 2023
1 parent e0c0dce commit 988e931
Show file tree
Hide file tree
Showing 10 changed files with 31 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
enum class MyFlags : unsigned {
NO_FLAGS = 0,
/** flag option comment */
FLAG1 = 1 << 0,
FLAG2 = 1 << 1,
FLAG3 = 1 << 2,
ALL_FLAGS = 0 | (1 << 0) | (1 << 1) | (1 << 2),
FLAG1 = 1u << 0,
FLAG2 = 1u << 1,
FLAG3 = 1u << 2,
ALL_FLAGS = 0 | FLAG1 | FLAG2 | FLAG3,
};
constexpr MyFlags operator|(MyFlags lhs, MyFlags rhs) noexcept {
return static_cast<MyFlags>(static_cast<unsigned>(lhs) | static_cast<unsigned>(rhs));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
*/
enum class [[deprecated("Use someother flags")]] MyFlags : unsigned {
/** @deprecated Use someother flag */
FLAG1 = 1 << 0,
FLAG1 = 1u << 0,
/** not deprecated */
FLAG2 = 1 << 1,
FLAG2 = 1u << 1,
};
constexpr MyFlags operator|(MyFlags lhs, MyFlags rhs) noexcept {
return static_cast<MyFlags>(static_cast<unsigned>(lhs) | static_cast<unsigned>(rhs));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
typedef NS_OPTIONS(NSUInteger, ITMyFlags)
{
/** @deprecated Use someother flag */
ITMyFlagsFlag1 = 1 << 0,
ITMyFlagsFlag1 = 1u << 0,
/** not deprecated */
ITMyFlagsFlag2 = 1 << 1,
ITMyFlagsFlag2 = 1u << 1,
};
8 changes: 4 additions & 4 deletions src/it/resources/expected/my_flags/cpp-headers/my_flags.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
enum class MyFlags : unsigned {
NO_FLAGS = 0,
/** flag option comment */
FLAG1 = 1 << 0,
FLAG2 = 1 << 1,
FLAG3 = 1 << 2,
ALL_FLAGS = 0 | (1 << 0) | (1 << 1) | (1 << 2),
FLAG1 = 1u << 0,
FLAG2 = 1u << 1,
FLAG3 = 1u << 2,
ALL_FLAGS = 0 | FLAG1 | FLAG2 | FLAG3,
};
constexpr MyFlags operator|(MyFlags lhs, MyFlags rhs) noexcept {
return static_cast<MyFlags>(static_cast<unsigned>(lhs) | static_cast<unsigned>(rhs));
Expand Down
8 changes: 4 additions & 4 deletions src/it/resources/expected/my_flags/cppcli/MyFlags.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
public enum class MyFlags {
NoFlags = 0,
/** flag option comment */
Flag1 = 1 << 0,
Flag2 = 1 << 1,
Flag3 = 1 << 2,
AllFlags = 0 | (1 << 0) | (1 << 1) | (1 << 2),
Flag1 = 1u << 0,
Flag2 = 1u << 1,
Flag3 = 1u << 2,
AllFlags = 0 | Flag1 | Flag2 | Flag3,
};
8 changes: 4 additions & 4 deletions src/it/resources/expected/my_flags/objc-headers/ITMyFlags.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ typedef NS_OPTIONS(NSUInteger, ITMyFlags)
{
ITMyFlagsNoFlags = 0,
/** flag option comment */
ITMyFlagsFlag1 = 1 << 0,
ITMyFlagsFlag2 = 1 << 1,
ITMyFlagsFlag3 = 1 << 2,
ITMyFlagsAllFlags = 0 | (1 << 0) | (1 << 1) | (1 << 2),
ITMyFlagsFlag1 = 1u << 0,
ITMyFlagsFlag2 = 1u << 1,
ITMyFlagsFlag3 = 1u << 2,
ITMyFlagsAllFlags = 0 | ITMyFlagsFlag1 | ITMyFlagsFlag2 | ITMyFlagsFlag3,
};
2 changes: 1 addition & 1 deletion src/main/scala/djinni/CppCliGenerator.scala
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ class CppCliGenerator(spec: Spec) extends Generator(spec) {
if (e.flags) w.wl("[System::Flags]")
w.w(s"public enum class ${marshal.typename(ident, e)}").bracedSemi {
writeEnumOptionNone(w, e, idCs.enum(_))
writeEnumOptions(w, e, idCs.enum(_))
writeEnumOptions(w, e, idCs.enum(_), "=", "u")
writeEnumOptionAll(w, e, idCs.enum(_))
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/scala/djinni/CppGenerator.scala
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ class CppGenerator(spec: Spec) extends Generator(spec) {
writeDoc(w, doc)
w.w(s"enum class${deprecatedType} $self : $underlyingType").bracedSemi {
writeEnumOptionNone(w, e, idCpp.enum)
writeEnumOptions(w, e, idCpp.enum)
writeEnumOptions(w, e, idCpp.enum, "=", "u")
writeEnumOptionAll(w, e, idCpp.enum)
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/scala/djinni/ObjcGenerator.scala
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ class ObjcGenerator(spec: Spec) extends BaseObjcGenerator(spec) {
})
w.bracedSemi {
writeEnumOptionNone(w, e, self + idObjc.enum(_))
writeEnumOptions(w, e, self + idObjc.enum(_))
writeEnumOptions(w, e, self + idObjc.enum(_), "=", "u")
writeEnumOptionAll(w, e, self + idObjc.enum(_))
}
}
Expand Down
15 changes: 8 additions & 7 deletions src/main/scala/djinni/generator.scala
Original file line number Diff line number Diff line change
Expand Up @@ -772,13 +772,14 @@ abstract class Generator(spec: Spec) {
w: IndentWriter,
e: Enum,
ident: IdentConverter,
delim: String = "="
delim: String = "=",
optionSuffix: String = ""
): Unit = {
var shift = 0
for (o <- normalEnumOptions(e)) {
writeDoc(w, o.doc)
w.wl(
ident(o.ident.name) + (if (e.flags) s" $delim 1 << $shift"
ident(o.ident.name) + (if (e.flags) s" $delim 1$optionSuffix << $shift"
else s" $delim $shift") + ","
)
shift += 1
Expand All @@ -796,11 +797,11 @@ abstract class Generator(spec: Spec) {
) {
writeDoc(w, o.doc)
w.w(ident(o.ident.name) + s" $delim ")
w.w(
normalEnumOptions(e).zipWithIndex
.map { case (o, i) => s"(1 << $i)" }
.fold("0")((acc, o) => acc + " | " + o)
)
val all =
if (delim == "=") normalEnumOptions(e).map(o => ident(o.ident.name))
else
normalEnumOptions(e).zipWithIndex.map { case (o, i) => s"(1 << $i)" }
w.w(all.fold("0")((acc, o) => acc + " | " + o))
w.wl(",")
}
}
Expand Down

0 comments on commit 988e931

Please sign in to comment.