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

Fix old cast style use in generated file and support lib. #453

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

canatella
Copy link

Fixes LLVM warning: use of old-style cast [-Wold-style-cast]

@artwyman
Copy link
Contributor

Can you please re-generate the code for the example and test cases to show the impact of the generator changes? Also please ensure the tests build and pass. You can run make all from the root which will do everything, if you're on a Mac).

@canatella canatella force-pushed the fix-old-cast-style-use branch from d73142c to 06326d1 Compare October 20, 2019 15:32
@canatella
Copy link
Author

There you go! Test are passing now and generated code looks ok.

Copy link
Contributor

@artwyman artwyman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for updating. Note that Djinni is on minimal maintenance, bugfixes-only, so don't expect a fast turnaround on reviews. I'm willing to merge this in some form, though. See my inline comments for some suggestsions, though. The current implementation feels messy.

Note that if you want this merged you'll also need to sign the CLA here: https://opensource.dropbox.com/cla/individual/

::djinni::Optional<std::experimental::optional, ::djinni::I64>::toCpp(jniEnv, jniEnv->GetObjectField(j, data.field_mOSixtyfour)),
::djinni::Optional<std::experimental::optional, ::djinni::F32>::toCpp(jniEnv, jniEnv->GetObjectField(j, data.field_mOFthirtytwo)),
::djinni::Optional<std::experimental::optional, ::djinni::F64>::toCpp(jniEnv, jniEnv->GetObjectField(j, data.field_mOFsixtyfour))};
return {::djinni::Bool::toCpp(jniEnv, (jniEnv->GetBooleanField(j, data.field_mB))),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems to be generating a lot of extra parens, as in this line. Can you make that conditional so they're only generated when necessary as part of generating a cast expression, not always?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Due to the problem with the closing parentheses (see my following comments), it would means that toJniCall should also return a value saying if there is a need to add the closing parentheses or not which starts to get things more complicated than they should be I think. If you have an idea on how to fix all those problems, I'll gladly give it a shot.

case p: MPrimitive => f(if (needRef) "Object" else IdentStyle.camelUpper(p.jName))
case MString => "(jstring)" + f("Object")
case p: MPrimitive => "(" + f(if (needRef) "Object" else IdentStyle.camelUpper(p.jName))
case MString => "reinterpret_cast<jstring>(" + f("Object")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generating the open-paren and close-paren at widely-separated places in the code seems confusing, and likely to miss some cases. Why can't the close-paren be generated here so it's directly part of the cast expression?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem lies in JNIGenerator.scala:288 where the expression to be casted is not entirely passed to the toJniCall method. I could add a function to generate the whole expression to be casted and then send that to toJniCall. It was not a problem before with c-style cast of course.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So after looking at it again, it does not really make sense to try to do that. Line 288 generates the first line of the call: something like

auto jret = reinterpret_cast<jstring>(jniEnv->CallObjectMethod(

Then on line 294 it uses that string length to generate properly aligned method call so it means the output of toJniCall should depends on the length of its output... Hoping I am clear here ;)

@artwyman
Copy link
Contributor

Thanks for your effort! This repo is no longer supported by Dropbox and about to be archived. I'm not going to try to merge this PR at the last minute, but I'll leave it open for reference by anyone who encounters the same problem.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants