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

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into kkaye/include-paths
Browse files Browse the repository at this point in the history
  • Loading branch information
GreatCall-KayeK committed Dec 9, 2016
2 parents d6ce638 + 96d8b44 commit 3af6aaf
Show file tree
Hide file tree
Showing 166 changed files with 4,174 additions and 460 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ example_ios: ./build_ios/example/libtextsort.xcodeproj
-scheme TextSort \
-configuration 'Debug' \
-sdk iphonesimulator \
-destination 'platform=iOS Simulator,name=iPhone 6s,OS=9.3'
-destination 'platform=iOS Simulator,name=iPhone 6s,OS=10.1'

# this target implicitly depends on GypAndroid.mk since gradle will try to make it
example_android: GypAndroid.mk
Expand Down
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,6 @@ Run `make test` to invoke the test suite, found in the test-suite subdirectory.
* [Slides](https://bit.ly/djinnitalk2) and [video](https://bit.ly/djinnivideo2) from the CppCon 2015 about Djinni implementatino techniques, and the addition of Python.
* You can see a [CppCon 2014 talk](https://www.youtube.com/watch?v=5AZMEm3rZ2Y) by app developers at Dropbox about their cross-platform experiences.


## Authors
- Kannan Goundan
- Tony Grue
Expand All @@ -439,5 +438,5 @@ Run `make test` to invoke the test suite, found in the test-suite subdirectory.
- Andrew Twyman

## Contacts
- Jacob Potter - `[email protected]`
- Andrew Twyman - `[email protected]`
- Jacob Potter - `[email protected]`
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import javax.annotation.CheckForNull;
import javax.annotation.Nonnull;

public final class ItemList {
/*package*/ final class ItemList {


/*package*/ final ArrayList<String> mItems;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import javax.annotation.CheckForNull;
import javax.annotation.Nonnull;

public abstract class SortItems {
/*package*/ abstract class SortItems {
/** For the iOS / Android demo */
public abstract void sort(@Nonnull SortOrder order, @Nonnull ItemList items);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import javax.annotation.CheckForNull;
import javax.annotation.Nonnull;

public enum SortOrder {
/*package*/ enum SortOrder {
ASCENDING,
DESCENDING,
RANDOM,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@
import javax.annotation.CheckForNull;
import javax.annotation.Nonnull;

public abstract class TextboxListener {
/*package*/ abstract class TextboxListener {
public abstract void update(@Nonnull ItemList items);
}
1 change: 0 additions & 1 deletion example/generated-src/jni/NativeSortItems.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

#include "NativeSortItems.hpp" // my header
#include "NativeItemList.hpp"
#include "NativeSortItems.hpp"
#include "NativeSortOrder.hpp"
#include "NativeTextboxListener.hpp"

Expand Down
12 changes: 6 additions & 6 deletions example/generated-src/objc/TXSSortItems+Private.mm
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
#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 <stdexcept>
#include <utility>

static_assert(__has_feature(objc_arc), "Djinni requires ARC to be enabled for this file");
Expand Down Expand Up @@ -42,15 +42,15 @@ - (void)sort:(TXSSortOrder)order

+ (nullable TXSSortItems *)createWithListener:(nullable id<TXSTextboxListener>)listener {
try {
auto r = ::textsort::SortItems::create_with_listener(::djinni_generated::TextboxListener::toCpp(listener));
return ::djinni_generated::SortItems::fromCpp(r);
auto objcpp_result_ = ::textsort::SortItems::create_with_listener(::djinni_generated::TextboxListener::toCpp(listener));
return ::djinni_generated::SortItems::fromCpp(objcpp_result_);
} DJINNI_TRANSLATE_EXCEPTIONS()
}

+ (nonnull TXSItemList *)runSort:(nonnull TXSItemList *)items {
try {
auto r = ::textsort::SortItems::run_sort(::djinni_generated::ItemList::toCpp(items));
return ::djinni_generated::ItemList::fromCpp(r);
auto objcpp_result_ = ::textsort::SortItems::run_sort(::djinni_generated::ItemList::toCpp(items));
return ::djinni_generated::ItemList::fromCpp(objcpp_result_);
} DJINNI_TRANSLATE_EXCEPTIONS()
}

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"

1 change: 1 addition & 0 deletions example/generated-src/objc/TXSTextboxListener+Private.mm
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#import "TXSTextboxListener.h"
#import "DJIObjcWrapperCache+Private.h"
#import "TXSItemList+Private.h"
#include <stdexcept>

static_assert(__has_feature(objc_arc), "Djinni requires ARC to be enabled for this file");

Expand Down
1 change: 1 addition & 0 deletions example/run_djinni.sh
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ fi
"$base_dir/../src/run-assume-built" \
--java-out "$temp_out/java" \
--java-package $java_package \
--java-class-access-modifier "package" \
--java-nullable-annotation "javax.annotation.CheckForNull" \
--java-nonnull-annotation "javax.annotation.Nonnull" \
--ident-java-field mFooBar \
Expand Down
22 changes: 19 additions & 3 deletions intellij-plugin/META-INF/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,28 @@
-->
<idea-plugin version="2">
<id>com.dropbox.djinni.ideaplugin</id>
<name>Djinni interface definition language file support</name>
<name>Djinni IDL file support</name>
<version>0.8</version>
<vendor email="[email protected]" url="http://www.dropbox.com">Dropbox</vendor>
<vendor url="https://github.com/dropbox/djinni">Dropbox Djinni Github Project</vendor>

<description><![CDATA[
Add some basic navigation, code-completion and error highlighting support to .djinni files.
<h4>License</h4>
Copyright 2015-2016 Dropbox, Inc.<br/>
<br/>
Licensed under the Apache License, Version 2.0 (the "License");<br/>
you may not use this file except in compliance with the License.<br/>
You may obtain a copy of the License at<br/>
<br/>
&nbsp;&nbsp;<a href="http://www.apache.org/licenses/LICENSE-2.0">http://www.apache.org/licenses/LICENSE-2.0</a><br/>
<br/>
Unless required by applicable law or agreed to in writing, software<br/>
distributed under the License is distributed on an "AS IS" BASIS,<br/>
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.<br/>
See the License for the specific language governing permissions and<br/>
limitations under the License.
]]></description>

<change-notes><![CDATA[
Expand All @@ -29,7 +45,7 @@
</change-notes>

<!-- please see https://confluence.jetbrains.com/display/IDEADEV/Build+Number+Ranges for description -->
<idea-version since-build="131"/>
<idea-version since-build="139"/>

<!-- please see https://confluence.jetbrains.com/display/IDEADEV/Plugin+Compatibility+with+IntelliJ+Platform+Products
on how to target different products -->
Expand Down
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.

25 changes: 14 additions & 11 deletions src/source/CppMarshal.scala
Original file line number Diff line number Diff line change
Expand Up @@ -59,18 +59,18 @@ class CppMarshal(spec: Spec) extends Marshal(spec) {
case MList => List(ImportRef("<vector>"))
case MSet => List(ImportRef("<unordered_set>"))
case MMap => List(ImportRef("<unordered_map>"))
case d: MDef => d.defType match {
case DRecord =>
case d: MDef => d.body match {
case r: Record =>
if (d.name != exclude) {
if (forwardDeclareOnly) {
List(DeclRef(s"struct ${typename(d.name, d.body)};", Some(spec.cppNamespace)))
} else {
List(ImportRef(include(d.name)))
List(ImportRef(include(d.name, r.ext.cpp)))
}
} else {
List()
}
case DEnum =>
case e: Enum =>
if (d.name != exclude) {
if (forwardDeclareOnly) {
List(DeclRef(s"enum class ${typename(d.name, d.body)};", Some(spec.cppNamespace)))
Expand All @@ -80,7 +80,7 @@ class CppMarshal(spec: Spec) extends Marshal(spec) {
} else {
List()
}
case DInterface =>
case i: Interface =>
val base = if (d.name != exclude) {
List(ImportRef("<memory>"), DeclRef(s"class ${typename(d.name, d.body)};", Some(spec.cppNamespace)))
} else {
Expand All @@ -106,14 +106,14 @@ class CppMarshal(spec: Spec) extends Marshal(spec) {
List()
} else {
m match {
case d: MDef => d.defType match {
case DRecord =>
case d: MDef => d.body match {
case r: Record =>
if (d.name != exclude) {
List(ImportRef(include(d.name)))
List(ImportRef(include(d.name, r.ext.cpp)))
} else {
List()
}
case DEnum =>
case e: Enum =>
if (d.name != exclude) {
List(ImportRef(include(d.name)))
} else {
Expand All @@ -126,7 +126,10 @@ class CppMarshal(spec: Spec) extends Marshal(spec) {
}
}

def include(ident: String): String = q(spec.cppIncludePrefix + spec.cppFileIdentStyle(ident) + "." + spec.cppHeaderExt)
def include(ident: String, isExtendedRecord: Boolean = false): String = {
val prefix = if (isExtendedRecord) spec.cppExtendedRecordIncludePrefix else spec.cppIncludePrefix
q(prefix + spec.cppFileIdentStyle (ident) + "." + spec.cppHeaderExt)
}

private def toCppType(ty: TypeRef, namespace: Option[String] = None, scopeSymbols: Seq[String] = Seq()): String =
toCppType(ty.resolved, namespace, scopeSymbols)
Expand All @@ -145,7 +148,7 @@ class CppMarshal(spec: Spec) extends Marshal(spec) {
}
def base(m: Meta): String = m match {
case p: MPrimitive => p.cName
case MString => "std::string"
case MString => if (spec.cppUseWideStrings) "std::wstring" else "std::string"
case MDate => "std::chrono::system_clock::time_point"
case MBinary => "std::vector<uint8_t>"
case MOptional => spec.cppOptionalTemplate
Expand Down
12 changes: 9 additions & 3 deletions src/source/JNIGenerator.scala
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,12 @@ class JNIGenerator(spec: Spec) extends Generator(spec) {
def writeJniHppFile(name: String, origin: String, includes: Iterable[String], fwds: Iterable[String], f: IndentWriter => Unit, f2: IndentWriter => Unit = (w => {})) =
writeHppFileGeneric(spec.jniHeaderOutFolder.get, spec.jniNamespace, spec.jniFileIdentStyle)(name, origin, includes, fwds, f, f2)

class JNIRefs(name: String) {
class JNIRefs(name: String, cppPrefixOverride: Option[String]=None) {
var jniHpp = mutable.TreeSet[String]()
var jniCpp = mutable.TreeSet[String]()

jniHpp.add("#include " + q(spec.jniIncludeCppPrefix + spec.cppFileIdentStyle(name) + "." + spec.cppHeaderExt))
val cppPrefix = cppPrefixOverride.getOrElse(spec.jniIncludeCppPrefix)
jniHpp.add("#include " + q(cppPrefix + spec.cppFileIdentStyle(name) + "." + spec.cppHeaderExt))
jniHpp.add("#include " + q(spec.jniBaseLibIncludePrefix + "djinni_support.hpp"))
spec.cppNnHeader match {
case Some(nnHdr) => jniHpp.add("#include " + nnHdr)
Expand Down Expand Up @@ -82,7 +83,12 @@ class JNIGenerator(spec: Spec) extends Generator(spec) {
}

override def generateRecord(origin: String, ident: Ident, doc: Doc, params: Seq[TypeParam], r: Record) {
val refs = new JNIRefs(ident.name)
val prefixOverride: Option[String] = if (r.ext.cpp) {
Some(spec.cppExtendedRecordIncludePrefix)
} else {
None
}
val refs = new JNIRefs(ident.name, prefixOverride)
r.fields.foreach(f => refs.find(f.ty))

val jniHelper = jniMarshal.helperClass(ident)
Expand Down
2 changes: 1 addition & 1 deletion src/source/JNIMarshal.scala
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ class JNIMarshal(spec: Spec) extends Marshal(spec) {
}
case MOptional => "Optional"
case MBinary => "Binary"
case MString => "String"
case MString => if (spec.cppUseWideStrings) "WString" else "String"
case MDate => "Date"
case MList => "List"
case MSet => "Set"
Expand Down
9 changes: 5 additions & 4 deletions src/source/JavaGenerator.scala
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class JavaGenerator(spec: Spec) extends Generator(spec) {
val javaAnnotationHeader = spec.javaAnnotation.map(pkg => '@' + pkg.split("\\.").last)
val javaNullableAnnotation = spec.javaNullableAnnotation.map(pkg => '@' + pkg.split("\\.").last)
val javaNonnullAnnotation = spec.javaNonnullAnnotation.map(pkg => '@' + pkg.split("\\.").last)
val javaClassAccessModifierString = JavaAccessModifier.getCodeGenerationString(spec.javaClassAccessModifier)
val marshal = new JavaMarshal(spec)

class JavaRefs() {
Expand Down Expand Up @@ -109,7 +110,7 @@ class JavaGenerator(spec: Spec) extends Generator(spec) {
writeJavaFile(ident, origin, refs.java, w => {
writeDoc(w, doc)
javaAnnotationHeader.foreach(w.wl)
w.w(s"public enum ${marshal.typename(ident, e)}").braced {
w.w(s"${javaClassAccessModifierString}enum ${marshal.typename(ident, e)}").braced {
for (o <- e.options) {
writeDoc(w, o.doc)
w.wl(idJava.enum(o.ident) + ",")
Expand Down Expand Up @@ -139,7 +140,7 @@ class JavaGenerator(spec: Spec) extends Generator(spec) {
writeDoc(w, doc)

javaAnnotationHeader.foreach(w.wl)
w.w(s"public abstract class $javaClass$typeParamList").braced {
w.w(s"${javaClassAccessModifierString}abstract class $javaClass$typeParamList").braced {
val skipFirst = SkipFirst()
generateJavaConstants(w, i.consts)

Expand Down Expand Up @@ -212,7 +213,7 @@ class JavaGenerator(spec: Spec) extends Generator(spec) {
r.fields.foreach(f => refs.find(f.ty))

val javaName = if (r.ext.java) (ident.name + "_base") else ident.name
val javaFinal = if (!r.ext.java && spec.javaUseFinalForRecord) " final" else ""
val javaFinal = if (!r.ext.java && spec.javaUseFinalForRecord) "final " else ""

writeJavaFile(javaName, origin, refs.java, w => {
writeDoc(w, doc)
Expand All @@ -225,7 +226,7 @@ class JavaGenerator(spec: Spec) extends Generator(spec) {
} else {
""
}
w.w(s"public$javaFinal class ${self + javaTypeParams(params)}$comparableFlag").braced {
w.w(s"${javaClassAccessModifierString}${javaFinal}class ${self + javaTypeParams(params)}$comparableFlag").braced {
w.wl
generateJavaConstants(w, r.consts)
// Field definitions.
Expand Down
Loading

0 comments on commit 3af6aaf

Please sign in to comment.