-
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
Operator Precedence Atom Finder #16
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -78,7 +78,9 @@ | |
(order-insensitive-opt-combination (sort combination)) | ||
|
||
;;SPECIAL CASE 1: Comma operator in any combination; | ||
(some (partial = :comma) combination))) | ||
(some (partial = :comma) combination) | ||
;SPECIAL CASE 2: note that the pair name is not [:bitwise_bin :bitwise-bin] | ||
(= [:bitwise--bin :bitwise--bin] combination))) | ||
|
||
(defn operator-group-pair? | ||
[node] | ||
|
@@ -105,12 +107,18 @@ | |
|
||
(defn group-pairs-in-node | ||
"Returns all operator group pairs in a node" | ||
[node child-groups] | ||
(let [node-group (operator-group node)] | ||
[node child-nodes] | ||
(let [node-group (operator-group node) child-groups (map operator-group child-nodes)] | ||
(cond | ||
(instance? IASTUnaryExpression node) | ||
[[node-group (safe-nth child-groups 0)]] | ||
|
||
;;SPECIAL CASE 2: Two bitwise_bins that are not the same, note that the group pair name is not [:bitwise_bin and bitwise_bin] | ||
(and (and (= :bitwise_bin node-group) | ||
(= :bitwise_bin (safe-nth child-groups 1))) | ||
(not (= (.getOperator node) (.getOperator (safe-nth child-nodes 1))))) | ||
[[:bitwise--bin :bitwise--bin]] | ||
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. Ok, now I understand, but its still confusing. What about renaming these to like |
||
|
||
(instance? IASTBinaryExpression node) | ||
(-> node | ||
unary-before-binary-pairs | ||
|
@@ -129,16 +137,14 @@ | |
|
||
([node collection] | ||
(->> collection | ||
(map operator-group) | ||
(group-pairs-in-node node) | ||
(remove (partial some nil?))))) | ||
|
||
(defn operator-precedence-atom? | ||
"Is this node an operator-precedence-atom?" | ||
[node] | ||
(and | ||
(operator-group-pair? node) | ||
(and (operator-group-pair? node) | ||
|
||
(not (= :assign (operator-group node))) | ||
(not (= :assign (operator-group node))) | ||
|
||
(some confusing-operator-combination? (group-pair node)))) | ||
(some confusing-operator-combination? (group-pair node)))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
(ns atom-finder.questions.redundant-parentheses | ||
(:require | ||
[clj-jgit.internal :as giti] | ||
[clj-jgit.porcelain :as gitp] | ||
[clj-jgit.querying :as gitq] | ||
[atom-finder.patch :refer :all] | ||
[atom-finder.atom-patch :refer :all] | ||
[atom-finder.constants :refer :all] | ||
[atom-finder.util :refer :all] | ||
[atom-finder.classifier :refer [operator-group confusing-operator-combination? | ||
operator-precedence-atom?]] | ||
[clojure.pprint :refer [pprint]] | ||
[clojure.string :as string] | ||
) | ||
(:import | ||
[org.eclipse.cdt.core.dom.ast IASTBinaryExpression] | ||
[org.eclipse.cdt.internal.core.dom.parser.cpp CPPASTConditionalExpression] | ||
)) | ||
|
||
(defn paren-in-children | ||
[node] | ||
(find-first paren-node? (children node))) | ||
|
||
(defn redundant-paren? | ||
[node] | ||
(when-let* [paren-test (paren-node? node) | ||
parent-level (precedence-level (safe-parent node)) | ||
children-level (precedence-level(first (children node)))] | ||
(or (< children-level parent-level) | ||
(and (= children-level parent-level) | ||
(= node (first (children (safe-parent node)))))))) | ||
|
||
(defn atom-without-paren? | ||
"Given a parenthesis node, would this be an operator-precedence-atom without the parentheses?" | ||
[node] | ||
(when-let* [parent-node (safe-parent node) | ||
parent-group (operator-group parent-node) | ||
child-group (operator-group (first (children node))) | ||
opt-group-combination [parent-group child-group]] | ||
|
||
(cond | ||
|
||
(and (and (= :bitwise_bin parent-group) | ||
(= parent-group child-group)) | ||
(not (= (.getOperator parent-node) (.getOperator (first (children node)))))) | ||
[:bitwise_bin :bitwise_bin] | ||
|
||
|
||
(and (or (instance? IASTBinaryExpression parent-node) | ||
(instance? CPPASTConditionalExpression parent-node)) | ||
(= node (first (children parent-node)))) | ||
(confusing-operator-combination? (reverse opt-group-combination)) | ||
|
||
:else(confusing-operator-combination? opt-group-combination)))) | ||
|
||
; | ||
;========GENERAL TESTING============== | ||
; | ||
(->> "(fclose(f1a) | EOF) & (fclose(f1b) | EOF)" parse-expr | ||
;print-tree | ||
(get-in-tree [0]) | ||
;print-tree | ||
;redundant-paren? | ||
atom-without-paren? | ||
) | ||
|
||
(->> "a | b & c" parse-expr | ||
;(get-in-tree [0]) | ||
operator-precedence-atom? | ||
) | ||
|
||
(def codebase_name "wcdb") | ||
|
||
; | ||
;=======CODEBASE DATA GATHERING========== | ||
; | ||
(->> (str "d:/Codebases/" codebase_name) | ||
(pmap-dir-trees (fn [root] (filter-tree | ||
redundant-paren? | ||
;#(and (redundant-paren? %)(atom-without-paren? %)) | ||
;operator-precedence-atom? | ||
root))) | ||
flatten | ||
(remove nil?) | ||
;(map safe-parent) | ||
;(map write-ast) | ||
;(map #(spit "underclas-atom-without.txt" (str % "\r\n") :append true)) | ||
;(take 100) | ||
|
||
;((fn [a] (prn (count a)) a)) | ||
(map atom-without-paren?) | ||
;(map operator-precedence-atom?) | ||
(remove (fn [input] (or (nil? input) (false? input)))) | ||
frequencies | ||
(sort-by last) | ||
(map #(spit (str "c:/Users/Henry/Desktop/stuff/would-be-atoms/" (str codebase_name "-rpa.txt")) (str % "\r\n") :append true)) | ||
|
||
count | ||
prn | ||
dorun | ||
time-mins) | ||
|
||
;IASTNode total: 31886519 | ||
|
||
;redundant-total: 392166 | ||
|
||
;Underclassify: | ||
;would-be-atom: 66037 | ||
|
||
;Overclassify: | ||
;would-be-atom: 75855 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
{ | ||
:gcc-path "~/opt/src/gcc", | ||
:ag-path "~/opt/src/the_silver_searcher", | ||
:github-top-c "~/opt/src/github-top-c" | ||
:gcc-path "d:/Codebases/gcc/opt/src/gcc", | ||
:ag-path "d:/Codebases/gcc/opt/src/the_silver_searcher", | ||
:github-top-c "d:/Codebases/gcc/opt/src/github-top-c" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -166,4 +166,7 @@ int main(){ | |
|
||
~str++;//<true> | ||
--~str; | ||
|
||
a = a << 1 << 2; //<false>, underclassify | ||
a = a | 2 & 3; //<true> | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
I'm glad you put a comment here, but what does it mean. What's the difference between bitwise_bin, bitwise-bin, and bitwise--bin?