Skip to content
This repository has been archived by the owner on Mar 26, 2020. It is now read-only.

Commit

Permalink
Separate constant_enum to `constant_enum.djinni (#385)
Browse files Browse the repository at this point in the history
Separate constant_enum to constant_enum.djinni, to exclude it from
common.djinni, so that it wouldn’t be picked up by Python in
python branch.

Otherwise it causes failure in python branch since constant enum feature is
not implemented for Python.
  • Loading branch information
Xianwen Chen committed Jul 17, 2018
1 parent f207582 commit 2ab4b4e
Show file tree
Hide file tree
Showing 40 changed files with 479 additions and 56 deletions.
1 change: 1 addition & 0 deletions test-suite/djinni/all.djinni
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
@import "common.djinni"

@import "enum_flags.djinni"
@import "constant_enum.djinni"

@import "vendor/third-party/date.djinni"
@import "third-party/duration.djinni"
15 changes: 15 additions & 0 deletions test-suite/djinni/constant_enum.djinni
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# enum for use in constants
constant_enum = enum {
some_value;
some_other_value;
}

# Record containing enum constant
constant_with_enum = record {
const const_enum: constant_enum = constant_enum::some_value;
}

# Interface containing enum constant
constant_interface_with_enum = interface +c {
const const_enum: constant_enum = constant_enum::some_value;
}
10 changes: 0 additions & 10 deletions test-suite/djinni/constants.djinni
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
# enum for use in constants
constant_enum = enum {
some_value;
some_other_value;
}

# Record for use in constants
constant_record = record {
some_integer: i32;
Expand All @@ -24,8 +18,6 @@ constants = record {
# Indented third line of multi-line documentation.)
const f64_constant: f64 = 5.0;

const const_enum: constant_enum = constant_enum::some_value;

const opt_bool_constant: optional<bool> = true;
const opt_i8_constant: optional<i8> = 1;
# opt_i16_constant has documentation.
Expand Down Expand Up @@ -67,8 +59,6 @@ constants_interface = interface +c {
const f32_constant: f32 = 5.0;
const f64_constant: f64 = 5.0;

const const_enum: constant_enum = constant_enum::some_value;

const opt_bool_constant: optional<bool> = true;
const opt_i8_constant: optional<i8> = 1;
# opt_i16_constant has documentation.
Expand Down
2 changes: 1 addition & 1 deletion test-suite/generated-src/cpp/constant_enum.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// AUTOGENERATED FILE - DO NOT MODIFY!
// This file generated by Djinni from constants.djinni
// This file generated by Djinni from constant_enum.djinni

#pragma once

Expand Down
11 changes: 11 additions & 0 deletions test-suite/generated-src/cpp/constant_interface_with_enum.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// AUTOGENERATED FILE - DO NOT MODIFY!
// This file generated by Djinni from constant_enum.djinni

#include "constant_interface_with_enum.hpp" // my header
#include "constant_enum.hpp"

namespace testsuite {

constant_enum const ConstantInterfaceWithEnum::CONST_ENUM = constant_enum::SOME_VALUE;

} // namespace testsuite
18 changes: 18 additions & 0 deletions test-suite/generated-src/cpp/constant_interface_with_enum.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// AUTOGENERATED FILE - DO NOT MODIFY!
// This file generated by Djinni from constant_enum.djinni

#pragma once

namespace testsuite {

enum class constant_enum;

/** Interface containing enum constant */
class ConstantInterfaceWithEnum {
public:
virtual ~ConstantInterfaceWithEnum() {}

static constant_enum const CONST_ENUM;
};

} // namespace testsuite
10 changes: 10 additions & 0 deletions test-suite/generated-src/cpp/constant_with_enum.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// AUTOGENERATED FILE - DO NOT MODIFY!
// This file generated by Djinni from constant_enum.djinni

#include "constant_with_enum.hpp" // my header

namespace testsuite {

constant_enum const ConstantWithEnum::CONST_ENUM = constant_enum::SOME_VALUE;

} // namespace testsuite
17 changes: 17 additions & 0 deletions test-suite/generated-src/cpp/constant_with_enum.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// AUTOGENERATED FILE - DO NOT MODIFY!
// This file generated by Djinni from constant_enum.djinni

#pragma once

#include "constant_enum.hpp"
#include <utility>

namespace testsuite {

/** Record containing enum constant */
struct ConstantWithEnum final {

static constant_enum const CONST_ENUM;
};

} // namespace testsuite
2 changes: 0 additions & 2 deletions test-suite/generated-src/cpp/constants.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ float const Constants::F32_CONSTANT;

double const Constants::F64_CONSTANT;

constant_enum const Constants::CONST_ENUM = constant_enum::SOME_VALUE;

std::experimental::optional<bool> const Constants::OPT_BOOL_CONSTANT = true;

std::experimental::optional<int8_t> const Constants::OPT_I8_CONSTANT = 1;
Expand Down
3 changes: 0 additions & 3 deletions test-suite/generated-src/cpp/constants.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
#pragma once

#include "../../handwritten-src/cpp/optional.hpp"
#include "constant_enum.hpp"
#include "constant_record.hpp"
#include <cstdint>
#include <string>
Expand Down Expand Up @@ -35,8 +34,6 @@ struct Constants final {
*/
static constexpr double F64_CONSTANT = 5.0;

static constant_enum const CONST_ENUM;

static std::experimental::optional<bool> const OPT_BOOL_CONSTANT;

static std::experimental::optional<int8_t> const OPT_I8_CONSTANT;
Expand Down
3 changes: 0 additions & 3 deletions test-suite/generated-src/cpp/constants_interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// This file generated by Djinni from constants.djinni

#include "constants_interface.hpp" // my header
#include "constant_enum.hpp"
#include "constant_record.hpp"

namespace testsuite {
Expand All @@ -21,8 +20,6 @@ float const ConstantsInterface::F32_CONSTANT;

double const ConstantsInterface::F64_CONSTANT;

constant_enum const ConstantsInterface::CONST_ENUM = constant_enum::SOME_VALUE;

std::experimental::optional<bool> const ConstantsInterface::OPT_BOOL_CONSTANT = true;

std::experimental::optional<int8_t> const ConstantsInterface::OPT_I8_CONSTANT = 1;
Expand Down
3 changes: 0 additions & 3 deletions test-suite/generated-src/cpp/constants_interface.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

namespace testsuite {

enum class constant_enum;
struct ConstantRecord;

/** Interface containing constants */
Expand Down Expand Up @@ -37,8 +36,6 @@ class ConstantsInterface {

static constexpr double F64_CONSTANT = 5.0;

static constant_enum const CONST_ENUM;

static std::experimental::optional<bool> const OPT_BOOL_CONSTANT;

static std::experimental::optional<int8_t> const OPT_I8_CONSTANT;
Expand Down
1 change: 1 addition & 0 deletions test-suite/generated-src/inFileList.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ djinni/extended_record.djinni
djinni/varnames.djinni
djinni/relative_paths.djinni
djinni/enum_flags.djinni
djinni/constant_enum.djinni
djinni/vendor/third-party/date.djinni
djinni/vendor/third-party/date.yaml
djinni/vendor/third-party/duration.djinni
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// AUTOGENERATED FILE - DO NOT MODIFY!
// This file generated by Djinni from constants.djinni
// This file generated by Djinni from constant_enum.djinni

package com.dropbox.djinni.test;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// AUTOGENERATED FILE - DO NOT MODIFY!
// This file generated by Djinni from constant_enum.djinni

package com.dropbox.djinni.test;

import java.util.concurrent.atomic.AtomicBoolean;
import javax.annotation.CheckForNull;
import javax.annotation.Nonnull;

/** Interface containing enum constant */
public abstract class ConstantInterfaceWithEnum {
@Nonnull
public static final ConstantEnum CONST_ENUM = ConstantEnum.SOME_VALUE;


private static final class CppProxy extends ConstantInterfaceWithEnum
{
private final long nativeRef;
private final AtomicBoolean destroyed = new AtomicBoolean(false);

private CppProxy(long nativeRef)
{
if (nativeRef == 0) throw new RuntimeException("nativeRef is zero");
this.nativeRef = nativeRef;
}

private native void nativeDestroy(long nativeRef);
public void destroy()
{
boolean destroyed = this.destroyed.getAndSet(true);
if (!destroyed) nativeDestroy(this.nativeRef);
}
protected void finalize() throws java.lang.Throwable
{
destroy();
super.finalize();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// AUTOGENERATED FILE - DO NOT MODIFY!
// This file generated by Djinni from constant_enum.djinni

package com.dropbox.djinni.test;

import javax.annotation.CheckForNull;
import javax.annotation.Nonnull;

/** Record containing enum constant */
public class ConstantWithEnum {

@Nonnull
public static final ConstantEnum CONST_ENUM = ConstantEnum.SOME_VALUE;


public ConstantWithEnum(
) {
}

@Override
public String toString() {
return "ConstantWithEnum{" +
"}";
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,6 @@ public class Constants {
*/
public static final double F64_CONSTANT = 5.0;

@Nonnull
public static final ConstantEnum CONST_ENUM = ConstantEnum.SOME_VALUE;

@CheckForNull
public static final Boolean OPT_BOOL_CONSTANT = true;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,6 @@ public abstract class ConstantsInterface {

public static final double F64_CONSTANT = 5.0;

@Nonnull
public static final ConstantEnum CONST_ENUM = ConstantEnum.SOME_VALUE;

@CheckForNull
public static final Boolean OPT_BOOL_CONSTANT = true;

Expand Down
2 changes: 1 addition & 1 deletion test-suite/generated-src/jni/NativeConstantEnum.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// AUTOGENERATED FILE - DO NOT MODIFY!
// This file generated by Djinni from constants.djinni
// This file generated by Djinni from constant_enum.djinni

#pragma once

Expand Down
22 changes: 22 additions & 0 deletions test-suite/generated-src/jni/NativeConstantInterfaceWithEnum.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// AUTOGENERATED FILE - DO NOT MODIFY!
// This file generated by Djinni from constant_enum.djinni

#include "NativeConstantInterfaceWithEnum.hpp" // my header
#include "NativeConstantEnum.hpp"

namespace djinni_generated {

NativeConstantInterfaceWithEnum::NativeConstantInterfaceWithEnum() : ::djinni::JniInterface<::testsuite::ConstantInterfaceWithEnum, NativeConstantInterfaceWithEnum>("com/dropbox/djinni/test/ConstantInterfaceWithEnum$CppProxy") {}

NativeConstantInterfaceWithEnum::~NativeConstantInterfaceWithEnum() = default;


CJNIEXPORT void JNICALL Java_com_dropbox_djinni_test_ConstantInterfaceWithEnum_00024CppProxy_nativeDestroy(JNIEnv* jniEnv, jobject /*this*/, jlong nativeRef)
{
try {
DJINNI_FUNCTION_PROLOGUE1(jniEnv, nativeRef);
delete reinterpret_cast<::djinni::CppProxyHandle<::testsuite::ConstantInterfaceWithEnum>*>(nativeRef);
} JNI_TRANSLATE_EXCEPTIONS_RETURN(jniEnv, )
}

} // namespace djinni_generated
32 changes: 32 additions & 0 deletions test-suite/generated-src/jni/NativeConstantInterfaceWithEnum.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// AUTOGENERATED FILE - DO NOT MODIFY!
// This file generated by Djinni from constant_enum.djinni

#pragma once

#include "constant_interface_with_enum.hpp"
#include "djinni_support.hpp"

namespace djinni_generated {

class NativeConstantInterfaceWithEnum final : ::djinni::JniInterface<::testsuite::ConstantInterfaceWithEnum, NativeConstantInterfaceWithEnum> {
public:
using CppType = std::shared_ptr<::testsuite::ConstantInterfaceWithEnum>;
using CppOptType = std::shared_ptr<::testsuite::ConstantInterfaceWithEnum>;
using JniType = jobject;

using Boxed = NativeConstantInterfaceWithEnum;

~NativeConstantInterfaceWithEnum();

static CppType toCpp(JNIEnv* jniEnv, JniType j) { return ::djinni::JniClass<NativeConstantInterfaceWithEnum>::get()._fromJava(jniEnv, j); }
static ::djinni::LocalRef<JniType> fromCppOpt(JNIEnv* jniEnv, const CppOptType& c) { return {jniEnv, ::djinni::JniClass<NativeConstantInterfaceWithEnum>::get()._toJava(jniEnv, c)}; }
static ::djinni::LocalRef<JniType> fromCpp(JNIEnv* jniEnv, const CppType& c) { return fromCppOpt(jniEnv, c); }

private:
NativeConstantInterfaceWithEnum();
friend ::djinni::JniClass<NativeConstantInterfaceWithEnum>;
friend ::djinni::JniInterface<::testsuite::ConstantInterfaceWithEnum, NativeConstantInterfaceWithEnum>;

};

} // namespace djinni_generated
27 changes: 27 additions & 0 deletions test-suite/generated-src/jni/NativeConstantWithEnum.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// AUTOGENERATED FILE - DO NOT MODIFY!
// This file generated by Djinni from constant_enum.djinni

#include "NativeConstantWithEnum.hpp" // my header

namespace djinni_generated {

NativeConstantWithEnum::NativeConstantWithEnum() = default;

NativeConstantWithEnum::~NativeConstantWithEnum() = default;

auto NativeConstantWithEnum::fromCpp(JNIEnv* jniEnv, const CppType& c) -> ::djinni::LocalRef<JniType> {
(void)c; // Suppress warnings in release builds for empty records
const auto& data = ::djinni::JniClass<NativeConstantWithEnum>::get();
auto r = ::djinni::LocalRef<JniType>{jniEnv->NewObject(data.clazz.get(), data.jconstructor)};
::djinni::jniExceptionCheck(jniEnv);
return r;
}

auto NativeConstantWithEnum::toCpp(JNIEnv* jniEnv, JniType j) -> CppType {
::djinni::JniLocalScope jscope(jniEnv, 1);
assert(j != nullptr);
(void)j; // Suppress warnings in release builds for empty records
return {};
}

} // namespace djinni_generated
Loading

0 comments on commit 2ab4b4e

Please sign in to comment.