Skip to content

Fixes for obj properties#1136

Merged
gmaurel merged 1 commit intouncrustify:masterfrom
Krizai:fixes_for_objc_properties
May 8, 2017
Merged

Fixes for obj properties#1136
gmaurel merged 1 commit intouncrustify:masterfrom
Krizai:fixes_for_objc_properties

Conversation

@Krizai
Copy link
Copy Markdown
Contributor

@Krizai Krizai commented May 5, 2017

Based on the comments to #765:

Added missing properties
Fixed work of mod_sort_oc_properties with sp_after_comma

@Krizai Krizai force-pushed the fixes_for_objc_properties branch 2 times, most recently from 3acbc72 to b7fc860 Compare May 5, 2017 14:37
@CDanU
Copy link
Copy Markdown
Collaborator

CDanU commented May 5, 2017

Thanks for the fixes, the build currently fails because your changes have not been formatted according to this repos style format. Please use Uncrustify on the changed files with the forUncrustifySources.cfg config.

I will look into adding git hooks to prevent such issues in the future, most likely it will be a modification of https://github.com/githubbrowser/Pre-commit-hooks

@Krizai
Copy link
Copy Markdown
Contributor Author

Krizai commented May 5, 2017

@CDanU Thank you. Now it's complaining about the output of Test_more_Options.sh script. I can't find information about the purpose of this script and the best way to make it happy. Can you help me with this ?

@CDanU
Copy link
Copy Markdown
Collaborator

CDanU commented May 5, 2017

This script tests if the command line options work.

Here is the script itself: Test_more_Options.sh

It operates on the files in scripts/Config, scripts/Output, scripts/Input and scripts/More_Options_to_Test/

You have changed/added some option descriptions and added new option so you need to edit

  • ./scripts/More_Options_to_Test/help.txt
  • ./scripts/More_Options_to_Test/show_config.txt
  • ./scripts/Output/mini_d_uc.txt
  • ./scripts/Output/mini_nd_uc.txt
  • ./scripts/Output/mini_d_ucwd.txt
  • ./scripts/Output/mini_nd_ucwd.txt

@Krizai Krizai force-pushed the fixes_for_objc_properties branch from b7fc860 to 50e2bc9 Compare May 5, 2017 19:27
@CDanU
Copy link
Copy Markdown
Collaborator

CDanU commented May 5, 2017

Ohh, I forgot: You need to remove the version strings in the mentioned files

# Uncrustify-0.64-592-b7fc860-dirty

They are already removed via sed in the generated results files.

@Krizai Krizai force-pushed the fixes_for_objc_properties branch 2 times, most recently from ca0fc00 to 996e218 Compare May 5, 2017 19:50
Copy link
Copy Markdown
Collaborator

@CDanU CDanU left a comment

Choose a reason for hiding this comment

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

Ok, after the scripts had their nitpicking now it's my turn, keep in mind that I never had to deal with obj-C.

src/combine.cpp Outdated
chunkGroup.push_back(next);
nullability_chunks.push_back(chunkGroup);
}
else if (chunk_is_str(next, "null_unspecified", 16))
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This could be combined with the previous else if statement.

src/newlines.cpp Outdated
// identifier - the name of the enumeration that's being declared
// enum-base(C++11) - colon (:), followed by a type-specifier-seq


Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This two newlines should be removed.


void cleanup_objc_property_with_parens(chunk_t *start);
void mark_selectors_in_property(chunk_t *start);
void mark_attributes_in_property(chunk_t *start);
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Some documentation here would be nice.

{
chunk_t *next = chunk_get_next_ncnl(start);

set_chunk_parent(next, start->type);
Copy link
Copy Markdown
Collaborator

@CDanU CDanU May 5, 2017

Choose a reason for hiding this comment

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

This looks like it could need a nullptr check for next and start.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

next should exist otherwise this method makes no sense, I'll put assert here

void mark_selectors_in_property(chunk_t *start)
{
chunk_t *tmp = chunk_get_next_type(start, CT_PAREN_OPEN, start->level);

Copy link
Copy Markdown
Collaborator

@CDanU CDanU May 5, 2017

Choose a reason for hiding this comment

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

This looks like it could need a nullptr check for tmp and start.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

paren open chunk should exist for calling this method. Will put assert

if (tmp->type == CT_WORD &&
(memcmp(tmp->str.c_str(), "setter", 6) == 0 ||
memcmp(tmp->str.c_str(), "getter", 6) == 0)
&& tmp->next->type == CT_ASSIGN)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I am not entirely sure, but this looks like it could need a nullptr check for next.
Does obj-C allow comments/newlines in between the setter and the assign ? Something like setter /* blub */ =?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes, will add.
Comments - never tried, but theoretically yes.

Copy link
Copy Markdown
Collaborator

@CDanU CDanU May 5, 2017

Choose a reason for hiding this comment

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

Ok, see if chunk_get_next_ncnl() is a better fit for such cases

Gets the next non-NEWLINE and non-comment chunk

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good one, thank you, will think about

memcmp(tmp->str.c_str(), "getter", 6) == 0)
&& tmp->next->type == CT_ASSIGN)
{
tmp = tmp->next->next;
Copy link
Copy Markdown
Collaborator

@CDanU CDanU May 5, 2017

Choose a reason for hiding this comment

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

One of both next can be nullptr or comment/newline

void mark_attributes_in_property(chunk_t *start)
{
chunk_t *tmp = chunk_get_next_type(start, CT_PAREN_OPEN, start->level);

Copy link
Copy Markdown
Collaborator

@CDanU CDanU May 5, 2017

Choose a reason for hiding this comment

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

nullptr check for tmp and start

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

paren open chunk should exist for calling this method. Will put assert

while (tmp->type != CT_PAREN_CLOSE)
{
if ((tmp->type == CT_COMMA || tmp->type == CT_PAREN_OPEN) &&
tmp->next->type == CT_WORD)
Copy link
Copy Markdown
Collaborator

@CDanU CDanU May 5, 2017

Choose a reason for hiding this comment

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

Also nullptr check and the in between comment/ newline problem for next

if ((tmp->type == CT_COMMA || tmp->type == CT_PAREN_OPEN) &&
tmp->next->type == CT_WORD)
{
tmp->next->type = CT_OC_PROPERTY_ATTR;
Copy link
Copy Markdown
Collaborator

@CDanU CDanU May 5, 2017

Choose a reason for hiding this comment

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

nullptr check for next

@Krizai Krizai force-pushed the fixes_for_objc_properties branch from d660ea4 to 13e0a80 Compare May 6, 2017 10:10
@Krizai
Copy link
Copy Markdown
Contributor Author

Krizai commented May 6, 2017

@CDanU Updated

Copy link
Copy Markdown
Collaborator

@CDanU CDanU left a comment

Choose a reason for hiding this comment

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

Ok, thanks again for the fixes, some new problems are there:


void cleanup_objc_property(chunk_t *start)
{
chunk_t *open_paren = chunk_get_next_type(start, CT_PAREN_OPEN, start->level);
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This will need a nullptr check for start.

{
chunk_t *tmp = open_paren;

assert(open_paren->type == CT_PAREN_OPEN);
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

You made sure that open_paren is not a nullptr in cleanup_objc_property(), but this function could be used somewhere else in the future where that is not going to be guaranteed anymore. A nullptr check for open_paren is needed here.

{
chunk_t *tmp = open_paren;

assert(open_paren->type == CT_PAREN_OPEN);
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

You made sure that open_paren is not a nullptr in cleanup_objc_property(), but this function could be used somewhere else in the future where that is not guaranteed anymore. A nullptr check for open_paren is needed here.

@CDanU
Copy link
Copy Markdown
Collaborator

CDanU commented May 6, 2017

Ok so far the code looks ok. Could you squash your commits into one commit?
I need to check if those asserts are not causing too much mess in there. This could potentially lead to problems if --no-backup is used.

@mihaipopescu could you also have a look on the changes?

@Krizai Krizai force-pushed the fixes_for_objc_properties branch from 3899d70 to 99a8ba6 Compare May 6, 2017 16:47
@Krizai
Copy link
Copy Markdown
Contributor Author

Krizai commented May 6, 2017

Asserts are only to detect wrong usage of the methods. They will never be executed with the current code.

Copy link
Copy Markdown
Collaborator

@mihaipopescu mihaipopescu left a comment

Choose a reason for hiding this comment

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

Very good changes! Few remarks on the PR.

enable_processing_cmt and disable_processing_cmt).

There are currently 581 options and minimal documentation.
There are currently 582 options and minimal documentation.
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Not related to this PR but generated files should never be under revision control.

while (next != nullptr && next->type != CT_PAREN_CLOSE)
{
if (next->type == CT_WORD)
if (next->type == CT_OC_PROPERTY_ATTR)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Is guarded for OC only ? Can't really tell on my phone.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes. It's part of the method handle_oc_property_decl, which will be called only for CT_OC_PROPERTY

{
if (chunk_is_str(next, "atomic", 6))
if (chunk_is_str(next, "atomic", 6) ||
chunk_is_str(next, "nonatomic", 9))
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Not related to this PR but why do we have to pass strlen all the time instead of having a template function ?

while (tmp && tmp->type != CT_PAREN_CLOSE)
{
if (tmp->type == CT_WORD &&
(memcmp(tmp->str.c_str(), "setter", 6) == 0 ||
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I think we have other string comparison functions.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

true. Will change

if ((tmp->type == CT_COMMA || tmp->type == CT_PAREN_OPEN) &&
tmp->next && tmp->next->type == CT_WORD)
{
tmp->next->type = CT_OC_PROPERTY_ATTR;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

You don't want to break the loop here ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

No, I want to do it for every attribute ( there can be several)

Fixed work of mod_sort_oc_properties with sp_after_comma
@Krizai Krizai force-pushed the fixes_for_objc_properties branch from 99a8ba6 to 4891533 Compare May 6, 2017 22:16
@Krizai
Copy link
Copy Markdown
Contributor Author

Krizai commented May 6, 2017

Incorporated all the comments, except for the once unrelated to this PR.

chunk_is_str(next, "nonnull", 7) ||
chunk_is_str(next, "null_resettable", 15) ||
chunk_is_str(next, "null_unspecified", 16)
)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

@gmaurel do we need a new rule in forUncrustifySources.cfg? I think that this paren should not be on a new line.

Copy link
Copy Markdown
Collaborator

@gmaurel gmaurel May 8, 2017

Choose a reason for hiding this comment

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

Yes, we need! look at #1139
I found some more:

grep -n "   )$" *
combine.cpp:2995:                        )
indent.cpp:1526:               )
newlines.cpp:2168:                )

@gmaurel gmaurel merged commit 79ba971 into uncrustify:master May 8, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants