{"action":"created","comment":{"url":"https://api.github.com/repos/crabtw/rust-bindgen/pulls/comments/55859292","id":55859292,"diff_hunk":"@@ -764,6 +764,72 @@ fn cenum_value_to_int_lit(\n     }\n }\n \n+fn cenum_is_bitflags(items: &[EnumItem]) -> bool {\n+    if items.len() < 2 {\n+        return false;\n+    }\n+\n+    let all_pow_two = items.iter().all(|ref item| {\n+        let is_pos = item.val > 0;\n+        let is_pow_two = (item.val & (item.val - 1)) == 0;\n+        is_pos && is_pow_two\n+    });\n+\n+    let items_uniq = {\n+        let mut v = items.to_vec();\n+        v.sort_by_key(|x| x.val);\n+        v.dedup();\n+        v\n+    };\n+    let all_differents = items_uniq.len() == items.len();\n+\n+    all_pow_two && all_differents\n+}\n+\n+fn try_cenum_to_bitflags(ctx: &mut GenCtx, name: &String, items: &[EnumItem]) -> Option<Vec<P<ast::Item>>> {\n+    use syntax::ext::quote::rt::ExtParseUtils;\n+    // TODO: not sure : all spans\n+    if !cenum_is_bitflags(items) {\n+        return None;\n+    }\n+\n+    let path = ctx.ext_cx.path(ctx.span, [\"bitflags\", \"bitflags\"].iter().map(|item| ctx.ext_cx.ident_of(item)).collect());\n+\n+    let flags = items.iter()\n+        .map(|ref item| format!(\"const {name} = {value}\",\n+                             name = item.name,\n+                             value = item.val.to_string()))\n+        .fold(String::new(),\n+              |acc, ref item| format!(\"{} {},\", acc, item));\n+\n+    let tokens = ctx.ext_cx.parse_tts(format!(\n+            \"flags {name}: {ctype} {{\n+                {flags}\n+            }}\",\n+            name = name,\n+            // TODO: use proper type\n+            ctype = \"u32\",","path":"src/gen.rs","position":48,"original_position":48,"commit_id":"3198915bbfbccbe1e411e6ba48e9b51dec27f180","original_commit_id":"3198915bbfbccbe1e411e6ba48e9b51dec27f180","user":{"login":"nox","id":123095,"avatar_url":"https://avatars.githubusercontent.com/u/123095?v=3","gravatar_id":"","url":"https://api.github.com/users/nox","html_url":"https://github.com/nox","followers_url":"https://api.github.com/users/nox/followers","following_url":"https://api.github.com/users/nox/following{/other_user}","gists_url":"https://api.github.com/users/nox/gists{/gist_id}","starred_url":"https://api.github.com/users/nox/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nox/subscriptions","organizations_url":"https://api.github.com/users/nox/orgs","repos_url":"https://api.github.com/users/nox/repos","events_url":"https://api.github.com/users/nox/events{/privacy}","received_events_url":"https://api.github.com/users/nox/received_events","type":"User","site_admin":false},"body":"Cf. `enum_size_to_rust_type_name`, though not all cases are needed here.","created_at":"2016-03-11T17:19:33Z","updated_at":"2016-03-11T17:19:33Z","html_url":"https://github.com/crabtw/rust-bindgen/pull/284#discussion_r55859292","pull_request_url":"https://api.github.com/repos/crabtw/rust-bindgen/pulls/284","_links":{"self":{"href":"https://api.github.com/repos/crabtw/rust-bindgen/pulls/comments/55859292"},"html":{"href":"https://github.com/crabtw/rust-bindgen/pull/284#discussion_r55859292"},"pull_request":{"href":"https://api.github.com/repos/crabtw/rust-bindgen/pulls/284"}}},"pull_request":{"url":"https://api.github.com/repos/crabtw/rust-bindgen/pulls/284","id":62539643,"html_url":"https://github.com/crabtw/rust-bindgen/pull/284","diff_url":"https://github.com/crabtw/rust-bindgen/pull/284.diff","patch_url":"https://github.com/crabtw/rust-bindgen/pull/284.patch","issue_url":"https://api.github.com/repos/crabtw/rust-bindgen/issues/284","number":284,"state":"open","locked":false,"title":"[WIP] Use bitflags! for typesafe bit flags.","user":{"login":"Yamakaky","id":1327378,"avatar_url":"https://avatars.githubusercontent.com/u/1327378?v=3","gravatar_id":"","url":"https://api.github.com/users/Yamakaky","html_url":"https://github.com/Yamakaky","followers_url":"https://api.github.com/users/Yamakaky/followers","following_url":"https://api.github.com/users/Yamakaky/following{/other_user}","gists_url":"https://api.github.com/users/Yamakaky/gists{/gist_id}","starred_url":"https://api.github.com/users/Yamakaky/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Yamakaky/subscriptions","organizations_url":"https://api.github.com/users/Yamakaky/orgs","repos_url":"https://api.github.com/users/Yamakaky/repos","events_url":"https://api.github.com/users/Yamakaky/events{/privacy}","received_events_url":"https://api.github.com/users/Yamakaky/received_events","type":"User","site_admin":false},"body":"Missing:\r\n- extern crate\r\n- tests\r\n- path vs ident","created_at":"2016-03-11T12:58:33Z","updated_at":"2016-03-11T17:19:33Z","closed_at":null,"merged_at":null,"merge_commit_sha":"94c34203c5c2e3182e900de571ae71c1fcb875e8","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/crabtw/rust-bindgen/pulls/284/commits","review_comments_url":"https://api.github.com/repos/crabtw/rust-bindgen/pulls/284/comments","review_comment_url":"https://api.github.com/repos/crabtw/rust-bindgen/pulls/comments{/number}","comments_url":"https://api.github.com/repos/crabtw/rust-bindgen/issues/284/comments","statuses_url":"https://api.github.com/repos/crabtw/rust-bindgen/statuses/3198915bbfbccbe1e411e6ba48e9b51dec27f180","head":{"label":"crabtw:bitflags","ref":"bitflags","sha":"3198915bbfbccbe1e411e6ba48e9b51dec27f180","user":{"login":"crabtw","id":36015,"avatar_url":"https://avatars.githubusercontent.com/u/36015?v=3","gravatar_id":"","url":"https://api.github.com/users/crabtw","html_url":"https://github.com/crabtw","followers_url":"https://api.github.com/users/crabtw/followers","following_url":"https://api.github.com/users/crabtw/following{/other_user}","gists_url":"https://api.github.com/users/crabtw/gists{/gist_id}","starred_url":"https://api.github.com/users/crabtw/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/crabtw/subscriptions","organizations_url":"https://api.github.com/users/crabtw/orgs","repos_url":"https://api.github.com/users/crabtw/repos","events_url":"https://api.github.com/users/crabtw/events{/privacy}","received_events_url":"https://api.github.com/users/crabtw/received_events","type":"User","site_admin":false},"repo":{"id":3579003,"name":"rust-bindgen","full_name":"crabtw/rust-bindgen","owner":{"login":"crabtw","id":36015,"avatar_url":"https://avatars.githubusercontent.com/u/36015?v=3","gravatar_id":"","url":"https://api.github.com/users/crabtw","html_url":"https://github.com/crabtw","followers_url":"https://api.github.com/users/crabtw/followers","following_url":"https://api.github.com/users/crabtw/following{/other_user}","gists_url":"https://api.github.com/users/crabtw/gists{/gist_id}","starred_url":"https://api.github.com/users/crabtw/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/crabtw/subscriptions","organizations_url":"https://api.github.com/users/crabtw/orgs","repos_url":"https://api.github.com/users/crabtw/repos","events_url":"https://api.github.com/users/crabtw/events{/privacy}","received_events_url":"https://api.github.com/users/crabtw/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/crabtw/rust-bindgen","description":"binding generator for rust language","fork":false,"url":"https://api.github.com/repos/crabtw/rust-bindgen","forks_url":"https://api.github.com/repos/crabtw/rust-bindgen/forks","keys_url":"https://api.github.com/repos/crabtw/rust-bindgen/keys{/key_id}","collaborators_url":"https://api.github.com/repos/crabtw/rust-bindgen/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/crabtw/rust-bindgen/teams","hooks_url":"https://api.github.com/repos/crabtw/rust-bindgen/hooks","issue_events_url":"https://api.github.com/repos/crabtw/rust-bindgen/issues/events{/number}","events_url":"https://api.github.com/repos/crabtw/rust-bindgen/events","assignees_url":"https://api.github.com/repos/crabtw/rust-bindgen/assignees{/user}","branches_url":"https://api.github.com/repos/crabtw/rust-bindgen/branches{/branch}","tags_url":"https://api.github.com/repos/crabtw/rust-bindgen/tags","blobs_url":"https://api.github.com/repos/crabtw/rust-bindgen/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/crabtw/rust-bindgen/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/crabtw/rust-bindgen/git/refs{/sha}","trees_url":"https://api.github.com/repos/crabtw/rust-bindgen/git/trees{/sha}","statuses_url":"https://api.github.com/repos/crabtw/rust-bindgen/statuses/{sha}","languages_url":"https://api.github.com/repos/crabtw/rust-bindgen/languages","stargazers_url":"https://api.github.com/repos/crabtw/rust-bindgen/stargazers","contributors_url":"https://api.github.com/repos/crabtw/rust-bindgen/contributors","subscribers_url":"https://api.github.com/repos/crabtw/rust-bindgen/subscribers","subscription_url":"https://api.github.com/repos/crabtw/rust-bindgen/subscription","commits_url":"https://api.github.com/repos/crabtw/rust-bindgen/commits{/sha}","git_commits_url":"https://api.github.com/repos/crabtw/rust-bindgen/git/commits{/sha}","comments_url":"https://api.github.com/repos/crabtw/rust-bindgen/comments{/number}","issue_comment_url":"https://api.github.com/repos/crabtw/rust-bindgen/issues/comments{/number}","contents_url":"https://api.github.com/repos/crabtw/rust-bindgen/contents/{+path}","compare_url":"https://api.github.com/repos/crabtw/rust-bindgen/compare/{base}...{head}","merges_url":"https://api.github.com/repos/crabtw/rust-bindgen/merges","archive_url":"https://api.github.com/repos/crabtw/rust-bindgen/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/crabtw/rust-bindgen/downloads","issues_url":"https://api.github.com/repos/crabtw/rust-bindgen/issues{/number}","pulls_url":"https://api.github.com/repos/crabtw/rust-bindgen/pulls{/number}","milestones_url":"https://api.github.com/repos/crabtw/rust-bindgen/milestones{/number}","notifications_url":"https://api.github.com/repos/crabtw/rust-bindgen/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/crabtw/rust-bindgen/labels{/name}","releases_url":"https://api.github.com/repos/crabtw/rust-bindgen/releases{/id}","deployments_url":"https://api.github.com/repos/crabtw/rust-bindgen/deployments","created_at":"2012-02-29T05:46:19Z","updated_at":"2016-03-11T07:30:12Z","pushed_at":"2016-03-11T14:27:32Z","git_url":"git://github.com/crabtw/rust-bindgen.git","ssh_url":"git@github.com:crabtw/rust-bindgen.git","clone_url":"https://github.com/crabtw/rust-bindgen.git","svn_url":"https://github.com/crabtw/rust-bindgen","homepage":"","size":1071,"stargazers_count":471,"watchers_count":471,"language":"Rust","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":100,"mirror_url":null,"open_issues_count":45,"forks":100,"open_issues":45,"watchers":471,"default_branch":"master"}},"base":{"label":"crabtw:master","ref":"master","sha":"5affca0477f87e0e8411b67757716e6d16321929","user":{"login":"crabtw","id":36015,"avatar_url":"https://avatars.githubusercontent.com/u/36015?v=3","gravatar_id":"","url":"https://api.github.com/users/crabtw","html_url":"https://github.com/crabtw","followers_url":"https://api.github.com/users/crabtw/followers","following_url":"https://api.github.com/users/crabtw/following{/other_user}","gists_url":"https://api.github.com/users/crabtw/gists{/gist_id}","starred_url":"https://api.github.com/users/crabtw/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/crabtw/subscriptions","organizations_url":"https://api.github.com/users/crabtw/orgs","repos_url":"https://api.github.com/users/crabtw/repos","events_url":"https://api.github.com/users/crabtw/events{/privacy}","received_events_url":"https://api.github.com/users/crabtw/received_events","type":"User","site_admin":false},"repo":{"id":3579003,"name":"rust-bindgen","full_name":"crabtw/rust-bindgen","owner":{"login":"crabtw","id":36015,"avatar_url":"https://avatars.githubusercontent.com/u/36015?v=3","gravatar_id":"","url":"https://api.github.com/users/crabtw","html_url":"https://github.com/crabtw","followers_url":"https://api.github.com/users/crabtw/followers","following_url":"https://api.github.com/users/crabtw/following{/other_user}","gists_url":"https://api.github.com/users/crabtw/gists{/gist_id}","starred_url":"https://api.github.com/users/crabtw/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/crabtw/subscriptions","organizations_url":"https://api.github.com/users/crabtw/orgs","repos_url":"https://api.github.com/users/crabtw/repos","events_url":"https://api.github.com/users/crabtw/events{/privacy}","received_events_url":"https://api.github.com/users/crabtw/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/crabtw/rust-bindgen","description":"binding generator for rust language","fork":false,"url":"https://api.github.com/repos/crabtw/rust-bindgen","forks_url":"https://api.github.com/repos/crabtw/rust-bindgen/forks","keys_url":"https://api.github.com/repos/crabtw/rust-bindgen/keys{/key_id}","collaborators_url":"https://api.github.com/repos/crabtw/rust-bindgen/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/crabtw/rust-bindgen/teams","hooks_url":"https://api.github.com/repos/crabtw/rust-bindgen/hooks","issue_events_url":"https://api.github.com/repos/crabtw/rust-bindgen/issues/events{/number}","events_url":"https://api.github.com/repos/crabtw/rust-bindgen/events","assignees_url":"https://api.github.com/repos/crabtw/rust-bindgen/assignees{/user}","branches_url":"https://api.github.com/repos/crabtw/rust-bindgen/branches{/branch}","tags_url":"https://api.github.com/repos/crabtw/rust-bindgen/tags","blobs_url":"https://api.github.com/repos/crabtw/rust-bindgen/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/crabtw/rust-bindgen/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/crabtw/rust-bindgen/git/refs{/sha}","trees_url":"https://api.github.com/repos/crabtw/rust-bindgen/git/trees{/sha}","statuses_url":"https://api.github.com/repos/crabtw/rust-bindgen/statuses/{sha}","languages_url":"https://api.github.com/repos/crabtw/rust-bindgen/languages","stargazers_url":"https://api.github.com/repos/crabtw/rust-bindgen/stargazers","contributors_url":"https://api.github.com/repos/crabtw/rust-bindgen/contributors","subscribers_url":"https://api.github.com/repos/crabtw/rust-bindgen/subscribers","subscription_url":"https://api.github.com/repos/crabtw/rust-bindgen/subscription","commits_url":"https://api.github.com/repos/crabtw/rust-bindgen/commits{/sha}","git_commits_url":"https://api.github.com/repos/crabtw/rust-bindgen/git/commits{/sha}","comments_url":"https://api.github.com/repos/crabtw/rust-bindgen/comments{/number}","issue_comment_url":"https://api.github.com/repos/crabtw/rust-bindgen/issues/comments{/number}","contents_url":"https://api.github.com/repos/crabtw/rust-bindgen/contents/{+path}","compare_url":"https://api.github.com/repos/crabtw/rust-bindgen/compare/{base}...{head}","merges_url":"https://api.github.com/repos/crabtw/rust-bindgen/merges","archive_url":"https://api.github.com/repos/crabtw/rust-bindgen/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/crabtw/rust-bindgen/downloads","issues_url":"https://api.github.com/repos/crabtw/rust-bindgen/issues{/number}","pulls_url":"https://api.github.com/repos/crabtw/rust-bindgen/pulls{/number}","milestones_url":"https://api.github.com/repos/crabtw/rust-bindgen/milestones{/number}","notifications_url":"https://api.github.com/repos/crabtw/rust-bindgen/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/crabtw/rust-bindgen/labels{/name}","releases_url":"https://api.github.com/repos/crabtw/rust-bindgen/releases{/id}","deployments_url":"https://api.github.com/repos/crabtw/rust-bindgen/deployments","created_at":"2012-02-29T05:46:19Z","updated_at":"2016-03-11T07:30:12Z","pushed_at":"2016-03-11T14:27:32Z","git_url":"git://github.com/crabtw/rust-bindgen.git","ssh_url":"git@github.com:crabtw/rust-bindgen.git","clone_url":"https://github.com/crabtw/rust-bindgen.git","svn_url":"https://github.com/crabtw/rust-bindgen","homepage":"","size":1071,"stargazers_count":471,"watchers_count":471,"language":"Rust","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":100,"mirror_url":null,"open_issues_count":45,"forks":100,"open_issues":45,"watchers":471,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/crabtw/rust-bindgen/pulls/284"},"html":{"href":"https://github.com/crabtw/rust-bindgen/pull/284"},"issue":{"href":"https://api.github.com/repos/crabtw/rust-bindgen/issues/284"},"comments":{"href":"https://api.github.com/repos/crabtw/rust-bindgen/issues/284/comments"},"review_comments":{"href":"https://api.github.com/repos/crabtw/rust-bindgen/pulls/284/comments"},"review_comment":{"href":"https://api.github.com/repos/crabtw/rust-bindgen/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/crabtw/rust-bindgen/pulls/284/commits"},"statuses":{"href":"https://api.github.com/repos/crabtw/rust-bindgen/statuses/3198915bbfbccbe1e411e6ba48e9b51dec27f180"}}}}