Skip to content

Commit

Permalink
Merge pull request dropbox#259 from dropbox/AT/WIP/EnumFix
Browse files Browse the repository at this point in the history
Fix enum compile issue in C++11
  • Loading branch information
artwyman authored Aug 5, 2016
2 parents f4ce760 + 22fb016 commit 3a24d6f
Show file tree
Hide file tree
Showing 46 changed files with 1,879 additions and 290 deletions.
2 changes: 1 addition & 1 deletion example/generated-src/objc/TXSSortItems+Private.mm
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
#import "TXSSortItems.h"
#import "DJICppWrapperCache+Private.h"
#import "DJIError.h"
#import "DJIMarshal+Private.h"
#import "TXSItemList+Private.h"
#import "TXSSortItems+Private.h"
#import "TXSSortOrder+Private.h"
#import "TXSTextboxListener+Private.h"
#include <exception>
#include <utility>
Expand Down
6 changes: 6 additions & 0 deletions example/generated-src/objc/TXSSortOrder+Private.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// AUTOGENERATED FILE - DO NOT MODIFY!
// This file generated by Djinni from example.djinni

#include "sort_order.hpp"
#import "DJIMarshal+Private.h"

7 changes: 4 additions & 3 deletions src/.idea/encodings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions src/.idea/sbt.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion src/.idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion src/source/ObjcppGenerator.scala
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,11 @@ class ObjcppGenerator(spec: Spec) extends BaseObjcGenerator(spec) {
private def arcAssert(w: IndentWriter) = w.wl("static_assert(__has_feature(objc_arc), " + q("Djinni requires ARC to be enabled for this file") + ");")

override def generateEnum(origin: String, ident: Ident, doc: Doc, e: Enum) {
// No generation required
var imports = mutable.TreeSet[String]()
imports.add("#import " + q(spec.objcBaseLibIncludePrefix + "DJIMarshal+Private.h"))
imports.add("!#include " + q(spec.objcppIncludeCppPrefix + spec.cppFileIdentStyle(ident) + "." + spec.cppHeaderExt))

writeObjcFile(objcppMarshal.privateHeaderName(ident.name), origin, imports, w => {} )
}

def headerName(ident: String): String = idObjc.ty(ident) + "." + spec.objcHeaderExt
Expand Down
9 changes: 2 additions & 7 deletions src/source/ObjcppMarshal.scala
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,7 @@ class ObjcppMarshal(spec: Spec) extends Marshal(spec) {
case o: MOpaque =>
List(ImportRef(q(spec.objcBaseLibIncludePrefix + "DJIMarshal+Private.h")))
case d: MDef => d.defType match {
case DEnum =>
List(ImportRef(q(spec.objcBaseLibIncludePrefix + "DJIMarshal+Private.h")))
case DInterface =>
case DEnum | DInterface =>
List(ImportRef(include(m)))
case DRecord =>
val r = d.body.asInstanceOf[Record]
Expand All @@ -48,10 +46,7 @@ class ObjcppMarshal(spec: Spec) extends Marshal(spec) {
}

def include(m: Meta) = m match {
case d: MDef => d.defType match {
case DEnum => q(spec.objcBaseLibIncludePrefix + "DJIMarshal+Private.h")
case _ => q(spec.objcppIncludePrefix + privateHeaderName(d.name))
}
case d: MDef => q(spec.objcppIncludePrefix + privateHeaderName(d.name))
case _ => throw new AssertionError("not applicable")
}

Expand Down
16 changes: 14 additions & 2 deletions test-suite/djinni/enum.djinni
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,18 @@ color = enum {
violet;
}

opt_color_record = record {
my_color: optional<color>;
enum_usage_record = record {
e: color;
o: optional<color>;
l: list<color>;
s: set<color>;
m: map<color, color>;
}

enum_usage_interface = interface +c +j +o {
e(e: color): color;
o(o: optional<color>): optional<color>;
l(l: list<color>): list<color>;
s(s: set<color>): set<color>;
m(m: map<color, color>): map<color, color>;
}
2 changes: 1 addition & 1 deletion test-suite/generated-src/cpp/assorted_primitives.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

#pragma once

#include "../../handwritten-src/cpp/optional.hpp"
#include <cstdint>
#include <experimental/optional>
#include <utility>

namespace testsuite {
Expand Down
2 changes: 1 addition & 1 deletion test-suite/generated-src/cpp/client_interface.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

#pragma once

#include "../../handwritten-src/cpp/optional.hpp"
#include <cstdint>
#include <experimental/optional>
#include <memory>
#include <string>
#include <vector>
Expand Down
2 changes: 1 addition & 1 deletion test-suite/generated-src/cpp/client_returned_record.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

#pragma once

#include "../../handwritten-src/cpp/optional.hpp"
#include <cstdint>
#include <experimental/optional>
#include <string>
#include <utility>

Expand Down
2 changes: 1 addition & 1 deletion test-suite/generated-src/cpp/constants.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@

#pragma once

#include "../../handwritten-src/cpp/optional.hpp"
#include "constant_record.hpp"
#include <cstdint>
#include <experimental/optional>
#include <string>
#include <utility>

Expand Down
2 changes: 1 addition & 1 deletion test-suite/generated-src/cpp/constants_interface.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

#pragma once

#include "../../handwritten-src/cpp/optional.hpp"
#include <cstdint>
#include <experimental/optional>
#include <string>

namespace testsuite {
Expand Down
30 changes: 30 additions & 0 deletions test-suite/generated-src/cpp/enum_usage_interface.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// AUTOGENERATED FILE - DO NOT MODIFY!
// This file generated by Djinni from enum.djinni

#pragma once

#include "../../handwritten-src/cpp/optional.hpp"
#include <unordered_map>
#include <unordered_set>
#include <vector>

namespace testsuite {

enum class color;

class EnumUsageInterface {
public:
virtual ~EnumUsageInterface() {}

virtual color e(color e) = 0;

virtual std::experimental::optional<color> o(std::experimental::optional<color> o) = 0;

virtual std::vector<color> l(const std::vector<color> & l) = 0;

virtual std::unordered_set<color> s(const std::unordered_set<color> & s) = 0;

virtual std::unordered_map<color, color> m(const std::unordered_map<color, color> & m) = 0;
};

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

#pragma once

#include "../../handwritten-src/cpp/optional.hpp"
#include "color.hpp"
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

namespace testsuite {

struct EnumUsageRecord final {
color e;
std::experimental::optional<color> o;
std::vector<color> l;
std::unordered_set<color> s;
std::unordered_map<color, color> m;

EnumUsageRecord(color e_,
std::experimental::optional<color> o_,
std::vector<color> l_,
std::unordered_set<color> s_,
std::unordered_map<color, color> m_)
: e(std::move(e_))
, o(std::move(o_))
, l(std::move(l_))
, s(std::move(s_))
, m(std::move(m_))
{}
};

} // namespace testsuite
20 changes: 0 additions & 20 deletions test-suite/generated-src/cpp/opt_color_record.hpp

This file was deleted.

2 changes: 1 addition & 1 deletion test-suite/generated-src/cpp/reverse_client_interface.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

#pragma once

#include <experimental/optional>
#include "../../handwritten-src/cpp/optional.hpp"
#include <memory>
#include <string>

Expand Down
2 changes: 1 addition & 1 deletion test-suite/generated-src/cpp/test_duration.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@

#pragma once

#include "../../handwritten-src/cpp/optional.hpp"
#include <chrono>
#include <cstdint>
#include <experimental/optional>
#include <string>

namespace testsuite {
Expand Down
2 changes: 1 addition & 1 deletion test-suite/generated-src/cpp/test_helpers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

#pragma once

#include "../../handwritten-src/cpp/optional.hpp"
#include <cstdint>
#include <experimental/optional>
#include <memory>
#include <string>
#include <unordered_map>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
// AUTOGENERATED FILE - DO NOT MODIFY!
// This file generated by Djinni from enum.djinni

package com.dropbox.djinni.test;

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

public abstract class EnumUsageInterface {
@Nonnull
public abstract Color e(@Nonnull Color e);

@CheckForNull
public abstract Color o(@CheckForNull Color o);

@Nonnull
public abstract ArrayList<Color> l(@Nonnull ArrayList<Color> l);

@Nonnull
public abstract HashSet<Color> s(@Nonnull HashSet<Color> s);

@Nonnull
public abstract HashMap<Color, Color> m(@Nonnull HashMap<Color, Color> m);

private static final class CppProxy extends EnumUsageInterface
{
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();
}

@Override
public Color e(Color e)
{
assert !this.destroyed.get() : "trying to use a destroyed object";
return native_e(this.nativeRef, e);
}
private native Color native_e(long _nativeRef, Color e);

@Override
public Color o(Color o)
{
assert !this.destroyed.get() : "trying to use a destroyed object";
return native_o(this.nativeRef, o);
}
private native Color native_o(long _nativeRef, Color o);

@Override
public ArrayList<Color> l(ArrayList<Color> l)
{
assert !this.destroyed.get() : "trying to use a destroyed object";
return native_l(this.nativeRef, l);
}
private native ArrayList<Color> native_l(long _nativeRef, ArrayList<Color> l);

@Override
public HashSet<Color> s(HashSet<Color> s)
{
assert !this.destroyed.get() : "trying to use a destroyed object";
return native_s(this.nativeRef, s);
}
private native HashSet<Color> native_s(long _nativeRef, HashSet<Color> s);

@Override
public HashMap<Color, Color> m(HashMap<Color, Color> m)
{
assert !this.destroyed.get() : "trying to use a destroyed object";
return native_m(this.nativeRef, m);
}
private native HashMap<Color, Color> native_m(long _nativeRef, HashMap<Color, Color> m);
}
}
Loading

0 comments on commit 3a24d6f

Please sign in to comment.