Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Three Classifiers #7

Merged
merged 11 commits into from
Mar 18, 2017
Merged

Three Classifiers #7

merged 11 commits into from
Mar 18, 2017

Conversation

Normand-1024
Copy link
Contributor

@Normand-1024 Normand-1024 commented Mar 17, 2017

Comma, assignment-as-values and omitted-curly-braces classifiers with their related tests

Shared functions: paren-node? value-consuming-children and remove-wrapper moved from post-increment to classifier-util.clj

Assignment-as-values and omitted-curly-braces tests use sets instead of vectors to compare line numbers due to the new filter-tree function. It hinders the ability to locate multiple atoms on the same line.

@dgopstein
Copy link
Owner

This commit is great! There are only 3 minor things you should fix though, before we merge:

  1. I added a failing test for curly braces. You test explicitly for ExpressionStatements and NullStatements, but maybe it makes more sense to test for Not CompoundStatement??
  2. Please switch the tests over from listing line numbers to using the <true>/<false> convention. If you need an example take a look at the tests for post-*crement-atom?
  3. Please rename atoms: curly-brace-atom? makes it sound like curly braces are bad, but instead omitting the curly braces is what's bad.

P.S.
I fixed filter tree so it's sequential again, but I still think listing a whole bunch of line numbers in a test is hard to read...


printf("%d %d %d\n", V1, V2, V3);
}

Copy link
Owner

Choose a reason for hiding this comment

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

Can you please use the <true>/<false> convention here, so that tests and their expected outcomes are in the same place? As it is, I can't see what's supposed to happen for each of these liens. Also, it lets you change the test file without having to update a list of 20 indexes that all get offset when add a new line.

(filter-tree assignment-as-value-atom?)
(map loc)
(map :line)
((partial into #{})))]
Copy link
Owner

Choose a reason for hiding this comment

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

((paritial into #{})) -> (into #{})

(let [omittable-types [IASTForStatement IASTIfStatement IASTWhileStatement IASTDoStatement ICPPASTRangeBasedForStatement]]
(cond
(some #(instance? % node) omittable-types)
(some #(omitted-curly-brace? %) (children node))
Copy link
Owner

Choose a reason for hiding this comment

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

#(omitted-curly-brace? %) -> omitted-curly-brace?

@@ -49,6 +49,9 @@
(ValidatedAtom :reversed-subscript reversed-subscript-atom? (default-finder reversed-subscript-atom?))
(ValidatedAtom :literal-encoding literal-encoding-atom? (default-finder literal-encoding-atom?))
(ValidatedAtom :post-increment post-*crement-atom? (default-finder post-*crement-atom?))
(ValidatedAtom :comma comma-atom? (default-finder comma-atom?))
(ValidatedAtom :curly-braces curly-braces-atom? (default-finder curly-braces-atom?))
Copy link
Owner

Choose a reason for hiding this comment

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

can you rename the functions to match the atom names? comma -> comma-operator and curly-braces -> omitted-curly-braces

(some #(omitted-curly-brace? %) (children node))

(instance? IASTSwitchStatement node) (not(->> node
((partial get-in-tree [1]))
Copy link
Owner

Choose a reason for hiding this comment

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

In general, you should never have to use (partial) inside of a (->>), since they kinda do the same thing.
((partial get-in-tree [1])) -> (get-in-tree [1])

@Normand-1024
Copy link
Contributor Author

Normand-1024 commented Mar 18, 2017

-Adjusted some codes based on your comments

-I adjusted the curly braces logic based on your fail tests
-For your fail test at line 106, the else actually follows the second if statement at line 105, which is interesting

-I added a function in util.clj called print-node, sample code:
(->> "omitted-curly-braces.c" resource-path tu (filter-tree omitted-curly-braces-atom?) (map print-node))
Hopefully you find the idea helpful. There's definitely room to improve to make the function more versatile and useful

@@ -404,3 +403,18 @@
(binding [*out* *err*] (println s)))

(defn all-preprocessor [node] (.getAllPreprocessorStatements (root-ancestor node)))

(defn print-node
Copy link
Owner

Choose a reason for hiding this comment

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

Awesome! This is great :)

(map loc)
(map :line))]

(is (= lines [8 10 12 12 14 16 20 22 30 32 36 38 42 48 50 52 52 56 58 60 62])))))
Copy link
Owner

Choose a reason for hiding this comment

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

Before when I mentioned the <true>/<false> test thing, I was talking about the test-atom-lines macro. You call it like this:

(test-atom-lines "type-conversion.c" "<true>" (default-finder type-conversion-atom?)))

What it does is it parses the file in the first argument (in this case type-conversion.c), and it finds every line that has a pattern in it (in this case <true>), and it makes sure that the atom returns true for each of those lines. It's the same as doing (is (= lines [8 10 12 ...])) except that the list of lines is built automatically based on which lines in your C file have <true> written on them.

Please swap out this test to use test-atom-lines. You can see a full example in type_conversion_test.clj.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

For some reason cider says unable to resolve symbol when I try to user test-atom-lines in repl.

Copy link
Contributor Author

@Normand-1024 Normand-1024 Mar 18, 2017

Choose a reason for hiding this comment

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

Also do you just type //<true> <true> if two atoms are expected in the same line

Copy link
Owner

Choose a reason for hiding this comment

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

Hmm, not sure about the two atoms on same line, you might actually have to update the macro to get that to work since none of my previous atoms had that behavior.

Sometimes with cider you need to go to the file where the function/macro is defined in (I think it's test_util.clj) and eval (run) the definition. If that doesn't work, also try eval'ing the (ns) call at the top of the file in classifiers.clj and at the top of the file you're working in.

@dgopstein
Copy link
Owner

P.S. I just resolved some conflicts between your branch and the one I just pushed, please make sure to pull before going and making any changes!

@dgopstein
Copy link
Owner

Your code looks great, as far as I'm concerned it's ready to ship. Do you know why the build is failing though??

@Normand-1024
Copy link
Contributor Author

Works on my end. So I'm not really sure, if it works on your machines, then I don't think it'll be a problem?

@dgopstein
Copy link
Owner

I don't know, I haven't pulled your branch yet (working on something else). We can't leave the build server broken or else its useless. If it's working fine on your end it might be an issue with the travis.cfg? I'll take a look...

@dgopstein dgopstein merged commit 79a169a into dgopstein:master Mar 18, 2017
@dgopstein
Copy link
Owner

Your tests were in fact broken. I fixed them for you, but next please make sure to run lein test when the build breaks. Travis-CI is there to let you know you have a problem.

@Normand-1024
Copy link
Contributor Author

I did run lein test before every commit and all the tests were find on my machine. Can you explain what was the problem?

@dgopstein
Copy link
Owner

You can see the fixes here: a42a227

Basically both the .c files you specified had spaces at the end of their strings. See for example: a42a227#diff-f4f175e02cf25ead54beaa240dc4bc16L179

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.

2 participants