-
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
Implicit Predicate Atom #12
Changes from all commits
4cbaa89
94cfb68
d02a65d
38ee52e
543e85b
c6b520a
e1f5e45
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
(in-ns 'atom-finder.classifier) | ||
(import '(org.eclipse.cdt.core.dom.ast IASTIfStatement IASTForStatement IASTWhileStatement IASTDoStatement IASTBinaryExpression IASTUnaryExpression)) | ||
|
||
(def implicit-types #{IASTIfStatement IASTForStatement IASTWhileStatement IASTDoStatement IASTConditionalExpression}) | ||
; If statement as an implicit type: C99 6.8.4.1/1 | ||
; For/While/Do statements as implicit types: C99 6.8.5/2 | ||
; Ternary operator as an implicit type: C99 6.5.15/1 | ||
|
||
(declare implicit-expression?) | ||
|
||
(defn remove-parentheses | ||
[expr] | ||
(cond | ||
(== IASTUnaryExpression/op_not (.getOperator expr)) true | ||
(== IASTUnaryExpression/op_bracketedPrimary (.getOperator expr)) | ||
(not (implicit-expression? (.getOperand expr))) | ||
:else false)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It doesn't look like this function removes parentheses, it looks like applies heuristics to unary operators. If instead you made it actually remove parentheses then you wouldn't need the cyclic reference either, you could just do something like: (->> node remove-parentheses implicit-expression?) Also, fix your indentation. |
||
|
||
(defn implicit-expression? | ||
"Does this expression have a logical operator in it?" | ||
[expr] | ||
(not (cond | ||
(instance? IASTBinaryExpression expr) | ||
(contains? logical-operators (.getOperator expr)) | ||
(instance? IASTUnaryExpression expr) | ||
(remove-parentheses expr) | ||
:else false))) | ||
|
||
(defn implicit-predicate-atom? | ||
"Does this AST node have an implicit predicate atom" | ||
[node] | ||
(cond | ||
(instance? IASTForStatement node) (implicit-expression? (.getConditionExpression node)) | ||
(instance? IASTIfStatement node) (implicit-expression? (.getConditionExpression node)) | ||
(instance? IASTWhileStatement node) (implicit-expression? (.getCondition node)) | ||
(instance? IASTDoStatement node) (implicit-expression? (.getCondition node)) | ||
(instance? IASTConditionalExpression node) (implicit-expression? (.getLogicalConditionExpression node)) | ||
:else false)) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
int main() | ||
{ | ||
int y = 5; | ||
|
||
(y == 5) ? y = 5 : y == 7; | ||
|
||
for (int x = 4; 4 != 4; x++); | ||
|
||
for (int x = 5; 4 - 4; x++); // <true> | ||
|
||
for (int x = 4; 4 == 4; x++); | ||
|
||
(y = 4) ? y : y++; // <true> | ||
|
||
for (int x = 4; 8 * 9 + 4; x++); // <true> | ||
|
||
if (3 < 6) | ||
if (3 | 6); // <true> | ||
|
||
if (6 & 8) // <true> | ||
if (2 ^ 9); // <true> | ||
|
||
if (3 > 6); | ||
|
||
((y != 5)) ? y : y; | ||
|
||
if (sizeof(34)); // <true> | ||
|
||
if ((y >= 6)); | ||
|
||
while (y || 3) | ||
while (y); // <true> | ||
|
||
while (y <= 34); | ||
|
||
(((y = 2))) ? 4 : 5; // <true> | ||
|
||
while (!(y && y)); | ||
|
||
if (!(5 == y)); | ||
|
||
return; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -151,3 +151,7 @@ | |
(deftest test-assignment-as-value-atom? | ||
(testing "assignment-as-value-atom? finds all atoms in snippet study code" | ||
(test-atom-lines "assignment-as-value.c" "<true>" (default-finder assignment-as-value-atom?)))) | ||
|
||
(deftest test-implicit-predicate-atom? | ||
(testing "implicit-predicate-atom? finds all atoms in sample code") | ||
(test-atom-lines "implicit-predicate.c" "<true>" (default-finder implicit-predicate-atom?))) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you add individual tests to test at the node (not line) level? See for example: https://github.com/dgopstein/atom-finder/blob/master/test/atom_finder/classifier_test.clj#L14 Then add a few tests. For example I'm curious what your code says for |
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.
Why are you changing this?