-
Notifications
You must be signed in to change notification settings - Fork 4
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
Conversation
This commit is great! There are only 3 minor things you should fix though, before we merge:
P.S. |
|
||
printf("%d %d %d\n", V1, V2, V3); | ||
} | ||
|
There was a problem hiding this comment.
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.
test/atom_finder/classifier_test.clj
Outdated
(filter-tree assignment-as-value-atom?) | ||
(map loc) | ||
(map :line) | ||
((partial into #{})))] |
There was a problem hiding this comment.
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)) |
There was a problem hiding this comment.
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?
src/atom_finder/classifier.clj
Outdated
@@ -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?)) |
There was a problem hiding this comment.
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])) |
There was a problem hiding this comment.
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])
-Adjusted some codes based on your comments -I adjusted the curly braces logic based on your fail tests -I added a function in util.clj called print-node, sample code: |
@@ -404,3 +403,18 @@ | |||
(binding [*out* *err*] (println s))) | |||
|
|||
(defn all-preprocessor [node] (.getAllPreprocessorStatements (root-ancestor node))) | |||
|
|||
(defn print-node |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome! This is great :)
test/atom_finder/classifier_test.clj
Outdated
(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]))))) |
There was a problem hiding this comment.
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
.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
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! |
Your code looks great, as far as I'm concerned it's ready to ship. Do you know why the build is failing though?? |
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? |
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... |
Your tests were in fact broken. I fixed them for you, but next please make sure to run |
I did run |
You can see the fixes here: a42a227 Basically both the |
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.