diff --git a/Cargo.lock b/Cargo.lock index 7a7dedd..9ae0e3f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1,117 +1,1051 @@ -[root] -name = "rainicorn" -version = "2.0.0" +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "annotate-snippets" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d78ea013094e5ea606b1c05fe35f1dd7ea1eb1ea259908d040b25bd5ec677ee5" + +[[package]] +name = "arrayvec" +version = "0.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8da52d66c7071e2e3fa2a1e5c6d088fec47b593032b254f5e980de8ea54454d6" + +[[package]] +name = "atty" +version = "0.2.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1803c647a3ec87095e7ae7acfca019e98de5ec9a7d01343f611cf3152ed71a90" dependencies = [ - "rustdt_util 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", - "syntex_errors 0.48.0 (registry+https://github.com/rust-lang/crates.io-index)", - "syntex_syntax 0.48.0 (registry+https://github.com/rust-lang/crates.io-index)", + "libc", + "winapi", ] +[[package]] +name = "autocfg" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" + [[package]] name = "bitflags" -version = "0.7.0" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693" + +[[package]] +name = "block-buffer" +version = "0.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0bf7fe51849ea569fd452f37822f606a5cabb684dc918707a0193fd4664ff324" +dependencies = [ + "generic-array", +] + +[[package]] +name = "cc" +version = "1.0.73" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2fff2a6927b3bb87f9595d67196a70493f627687a71d87a0d692242c33f58c11" + +[[package]] +name = "cfg-if" +version = "0.1.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822" + +[[package]] +name = "cfg-if" +version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] -name = "kernel32-sys" +name = "cpufeatures" version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "59a6001667ab124aebae2a495118e11d30984c3a653e99d86d58971708cf5e4b" +dependencies = [ + "libc", +] + +[[package]] +name = "crypto-common" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "57952ca27b5e3606ff4dd79b0020231aaf9d6aa76dc05fd30137538c50bd3ce8" +dependencies = [ + "generic-array", + "typenum", +] + +[[package]] +name = "digest" +version = "0.10.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f2fb860ca6fafa5552fb6d0e816a69c8e49f0908bf524e30a90d97c85892d506" +dependencies = [ + "block-buffer", + "crypto-common", +] + +[[package]] +name = "ena" +version = "0.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d7402b94a93c24e742487327a7cd839dc9d36fec9de9fb25b09f2dae459f36c3" +dependencies = [ + "log", +] + +[[package]] +name = "fastrand" +version = "1.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c3fcf0cee53519c866c09b5de1f6c56ff9d647101f81c1964fa632e148896cdf" +dependencies = [ + "instant", +] + +[[package]] +name = "fluent-bundle" +version = "0.15.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e242c601dec9711505f6d5bbff5bedd4b61b2469f2e8bb8e57ee7c9747a87ffd" +dependencies = [ + "fluent-langneg", + "fluent-syntax", + "intl-memoizer", + "intl_pluralrules", + "rustc-hash", + "self_cell", + "smallvec", + "unic-langid", +] + +[[package]] +name = "fluent-langneg" +version = "0.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2c4ad0989667548f06ccd0e306ed56b61bd4d35458d54df5ec7587c0e8ed5e94" +dependencies = [ + "unic-langid", +] + +[[package]] +name = "fluent-syntax" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c0abed97648395c902868fee9026de96483933faa54ea3b40d652f7dfe61ca78" +dependencies = [ + "thiserror", +] + +[[package]] +name = "generic-array" +version = "0.14.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fd48d33ec7f05fbfa152300fdad764757cbded343c1aa1cff2fbaf4134851803" +dependencies = [ + "typenum", + "version_check", +] + +[[package]] +name = "getopts" +version = "0.2.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "14dbbfd5c71d70241ecf9e6f13737f7b5ce823821063188d7e46c41d371eebd5" +dependencies = [ + "unicode-width", +] + +[[package]] +name = "getrandom" +version = "0.1.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e7db7ca94ed4cd01190ceee0d8a8052f08a247aa1b469a7f68c6a3b71afcf407" +dependencies = [ + "cfg-if 0.1.10", + "libc", + "wasi", +] + +[[package]] +name = "hashbrown" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ab5ef0d4909ef3724cc8cce6ccc8572c5c817592e9285f5464f8e86f8bd3726e" + +[[package]] +name = "indexmap" +version = "1.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0f647032dfaa1f8b6dc29bd3edb7bbef4861b8b8007ebb118d6db284fd59f6ee" +dependencies = [ + "autocfg", + "hashbrown", +] + +[[package]] +name = "instant" +version = "0.1.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a5bbe824c507c5da5956355e86a746d82e0e1464f65d862cc5e71da70e94b2c" +dependencies = [ + "cfg-if 1.0.0", +] + +[[package]] +name = "intl-memoizer" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c310433e4a310918d6ed9243542a6b83ec1183df95dff8f23f87bb88a264a66f" +dependencies = [ + "type-map", + "unic-langid", +] + +[[package]] +name = "intl_pluralrules" +version = "7.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b18f988384267d7066cc2be425e6faf352900652c046b6971d2e228d3b1c5ecf" +dependencies = [ + "tinystr", + "unic-langid", +] + +[[package]] +name = "jobserver" +version = "0.1.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f2b1d42ef453b30b7387e113da1c83ab1605d90c5b4e0eb8e96d016ed3b8c160" dependencies = [ - "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi-build 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", + "getrandom", + "libc", + "log", ] +[[package]] +name = "lazy_static" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" + [[package]] name = "libc" -version = "0.2.14" +version = "0.2.125" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5916d2ae698f6de9bfb891ad7a8d65c09d232dc58cc4ac433c7da3b2fd84bc2b" + +[[package]] +name = "lock_api" +version = "0.4.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "327fa5b6a6940e4699ec49a9beae1ea4845c6bab9314e4f84ac68742139d8c53" +dependencies = [ + "autocfg", + "scopeguard", +] [[package]] name = "log" -version = "0.3.6" +version = "0.4.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "14b6052be84e6b71ab17edffc2eeabf5c2c3ae1fdb464aae35ac50c67a44e1f7" +dependencies = [ + "cfg-if 0.1.10", +] + +[[package]] +name = "md-5" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "658646b21e0b72f7866c7038ab086d3d5e1cd6271f060fd37defb241949d0582" +dependencies = [ + "digest", +] + +[[package]] +name = "measureme" +version = "10.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bd460fad6e55ca82fa0cd9dab0d315294188fd9ec6efbf4105e5635d4872ef9c" +dependencies = [ + "log", + "memmap2", + "parking_lot", + "perf-event-open-sys", + "rustc-hash", + "smallvec", +] + +[[package]] +name = "memmap2" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "723e3ebdcdc5c023db1df315364573789f8857c11b631a2fdfad7c00f5c046b4" +dependencies = [ + "libc", +] + +[[package]] +name = "odht" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5a518809ac14b25b569624d0268eba1e88498f71615893dca57982bed7621abb" +dependencies = [ + "cfg-if 1.0.0", +] + +[[package]] +name = "parking_lot" +version = "0.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6d7744ac029df22dca6284efe4e898991d28e3085c706c972bcd7da4a27a15eb" +dependencies = [ + "instant", + "lock_api", + "parking_lot_core", +] + +[[package]] +name = "parking_lot_core" +version = "0.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fa7a782938e745763fe6907fc6ba86946d72f49fe7e21de074e08128a99fb018" +dependencies = [ + "cfg-if 1.0.0", + "instant", + "libc", + "redox_syscall", + "smallvec", + "winapi", +] + +[[package]] +name = "perf-event-open-sys" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ce9bedf5da2c234fdf2391ede2b90fabf585355f33100689bc364a3ea558561a" +dependencies = [ + "libc", +] + +[[package]] +name = "pin-project-lite" +version = "0.2.9" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e0a7ae3ac2f1173085d398531c705756c94a4c56843785df85a60c1a0afac116" [[package]] -name = "rustc-serialize" -version = "0.3.19" +name = "proc-macro-hack" +version = "0.5.19" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dbf0c48bc1d91375ae5c3cd81e3722dff1abcf81a30960240640d223f59fe0e5" + +[[package]] +name = "proc-macro2" +version = "1.0.36" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c7342d5883fbccae1cc37a2353b09c87c9b0f3afd73f5fb9bba687a1f733b029" +dependencies = [ + "unicode-xid", +] + +[[package]] +name = "psm" +version = "0.1.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "871372391786ccec00d3c5d3d6608905b3d4db263639cfe075d3b60a736d115a" +dependencies = [ + "cc", +] + +[[package]] +name = "quote" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "053a8c8bcc71fcce321828dc897a98ab9760bef03a4fc36693c231e5b3216cfe" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "rainicorn" +version = "3.0.0" +dependencies = [ + "rustc_ast", + "rustc_ast_pretty", + "rustc_data_structures", + "rustc_error_messages", + "rustc_errors", + "rustc_parse", + "rustc_session", + "rustc_span", + "rustdt_util", +] + +[[package]] +name = "redox_syscall" +version = "0.2.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "62f25bc4c7e55e0b0b7a1d43fb893f4fa1361d0abe38b9ce4f323c2adfe6ef42" +dependencies = [ + "bitflags", +] + +[[package]] +name = "remove_dir_all" +version = "0.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3acd125665422973a33ac9d3dd2df85edad0f4ae9b00dafb1a05e43a9f5ef8e7" +dependencies = [ + "winapi", +] + +[[package]] +name = "rustc-hash" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2" + +[[package]] +name = "rustc_arena" +version = "0.0.0" +source = "git+https://github.com/snuk182/rustc-syntax-tools#d8017548a66814a37014d6481637c3a082797e1e" +dependencies = [ + "smallvec", +] + +[[package]] +name = "rustc_ast" +version = "0.0.0" +source = "git+https://github.com/snuk182/rustc-syntax-tools#d8017548a66814a37014d6481637c3a082797e1e" +dependencies = [ + "bitflags", + "rustc_data_structures", + "rustc_index", + "rustc_lexer", + "rustc_macros", + "rustc_serialize", + "rustc_span", + "smallvec", + "tracing", +] + +[[package]] +name = "rustc_ast_pretty" +version = "0.0.0" +source = "git+https://github.com/snuk182/rustc-syntax-tools#d8017548a66814a37014d6481637c3a082797e1e" +dependencies = [ + "rustc_ast", + "rustc_span", +] + +[[package]] +name = "rustc_data_structures" +version = "0.0.0" +source = "git+https://github.com/snuk182/rustc-syntax-tools#d8017548a66814a37014d6481637c3a082797e1e" +dependencies = [ + "arrayvec", + "bitflags", + "cfg-if 0.1.10", + "ena", + "indexmap", + "jobserver", + "libc", + "measureme", + "memmap2", + "parking_lot", + "rustc-hash", + "rustc_graphviz", + "rustc_index", + "rustc_macros", + "rustc_serialize", + "smallvec", + "stable_deref_trait", + "stacker", + "tempfile", + "tracing", + "winapi", +] + +[[package]] +name = "rustc_error_messages" +version = "0.0.0" +source = "git+https://github.com/snuk182/rustc-syntax-tools#d8017548a66814a37014d6481637c3a082797e1e" +dependencies = [ + "fluent-bundle", + "fluent-syntax", + "intl-memoizer", + "rustc_data_structures", + "rustc_macros", + "rustc_serialize", + "rustc_span", + "tracing", + "unic-langid", +] + +[[package]] +name = "rustc_errors" +version = "0.0.0" +source = "git+https://github.com/snuk182/rustc-syntax-tools#d8017548a66814a37014d6481637c3a082797e1e" +dependencies = [ + "annotate-snippets", + "atty", + "rustc_data_structures", + "rustc_error_messages", + "rustc_lint_defs", + "rustc_macros", + "rustc_serialize", + "rustc_span", + "termcolor", + "termize", + "tracing", + "unicode-width", + "winapi", +] + +[[package]] +name = "rustc_feature" +version = "0.0.0" +source = "git+https://github.com/snuk182/rustc-syntax-tools#d8017548a66814a37014d6481637c3a082797e1e" +dependencies = [ + "rustc_data_structures", + "rustc_span", +] + +[[package]] +name = "rustc_fs_util" +version = "0.0.0" +source = "git+https://github.com/snuk182/rustc-syntax-tools#d8017548a66814a37014d6481637c3a082797e1e" + +[[package]] +name = "rustc_graphviz" +version = "0.0.0" +source = "git+https://github.com/snuk182/rustc-syntax-tools#d8017548a66814a37014d6481637c3a082797e1e" + +[[package]] +name = "rustc_hir" +version = "0.0.0" +source = "git+https://github.com/snuk182/rustc-syntax-tools#d8017548a66814a37014d6481637c3a082797e1e" +dependencies = [ + "odht", + "rustc_ast", + "rustc_data_structures", + "rustc_error_messages", + "rustc_feature", + "rustc_index", + "rustc_macros", + "rustc_serialize", + "rustc_span", + "rustc_target", + "smallvec", + "tracing", +] + +[[package]] +name = "rustc_index" +version = "0.0.0" +source = "git+https://github.com/snuk182/rustc-syntax-tools#d8017548a66814a37014d6481637c3a082797e1e" +dependencies = [ + "arrayvec", + "rustc_macros", + "rustc_serialize", + "smallvec", +] + +[[package]] +name = "rustc_lexer" +version = "0.1.0" +source = "git+https://github.com/snuk182/rustc-syntax-tools#d8017548a66814a37014d6481637c3a082797e1e" +dependencies = [ + "unic-emoji-char", + "unicode-xid", +] + +[[package]] +name = "rustc_lint_defs" +version = "0.0.0" +source = "git+https://github.com/snuk182/rustc-syntax-tools#d8017548a66814a37014d6481637c3a082797e1e" +dependencies = [ + "rustc_ast", + "rustc_data_structures", + "rustc_error_messages", + "rustc_hir", + "rustc_macros", + "rustc_serialize", + "rustc_span", + "rustc_target", +] + +[[package]] +name = "rustc_macros" +version = "0.1.0" +source = "git+https://github.com/snuk182/rustc-syntax-tools#d8017548a66814a37014d6481637c3a082797e1e" +dependencies = [ + "proc-macro2", + "quote", + "syn", + "synstructure", +] + +[[package]] +name = "rustc_parse" +version = "0.0.0" +source = "git+https://github.com/snuk182/rustc-syntax-tools#d8017548a66814a37014d6481637c3a082797e1e" +dependencies = [ + "bitflags", + "rustc_ast", + "rustc_ast_pretty", + "rustc_data_structures", + "rustc_errors", + "rustc_feature", + "rustc_lexer", + "rustc_macros", + "rustc_session", + "rustc_span", + "tracing", + "unicode-normalization", + "unicode-width", +] + +[[package]] +name = "rustc_serialize" +version = "0.0.0" +source = "git+https://github.com/snuk182/rustc-syntax-tools#d8017548a66814a37014d6481637c3a082797e1e" +dependencies = [ + "indexmap", + "smallvec", +] + +[[package]] +name = "rustc_session" +version = "0.0.0" +source = "git+https://github.com/snuk182/rustc-syntax-tools#d8017548a66814a37014d6481637c3a082797e1e" +dependencies = [ + "getopts", + "rustc_ast", + "rustc_data_structures", + "rustc_errors", + "rustc_feature", + "rustc_fs_util", + "rustc_hir", + "rustc_lint_defs", + "rustc_macros", + "rustc_serialize", + "rustc_span", + "rustc_target", + "tracing", +] + +[[package]] +name = "rustc_span" +version = "0.0.0" +source = "git+https://github.com/snuk182/rustc-syntax-tools#d8017548a66814a37014d6481637c3a082797e1e" +dependencies = [ + "cfg-if 0.1.10", + "md-5", + "rustc_arena", + "rustc_data_structures", + "rustc_index", + "rustc_macros", + "rustc_serialize", + "scoped-tls", + "sha-1", + "sha2", + "tracing", + "unicode-width", +] + +[[package]] +name = "rustc_target" +version = "0.0.0" +source = "git+https://github.com/snuk182/rustc-syntax-tools#d8017548a66814a37014d6481637c3a082797e1e" +dependencies = [ + "bitflags", + "rustc_data_structures", + "rustc_index", + "rustc_macros", + "rustc_serialize", + "rustc_span", + "tracing", +] [[package]] name = "rustdt_util" version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7cfffa8a89d8758be2dd5605c5fc62bce055af2491ebf3ce953d4d31512c59fd" + +[[package]] +name = "scoped-tls" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ea6a9290e3c9cf0f18145ef7ffa62d68ee0bf5fcd651017e586dc7fd5da448c2" + +[[package]] +name = "scopeguard" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" + +[[package]] +name = "self_cell" +version = "0.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1ef965a420fe14fdac7dd018862966a4c14094f900e1650bbc71ddd7d580c8af" + +[[package]] +name = "sha-1" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "028f48d513f9678cda28f6e4064755b3fbb2af6acd672f2c209b62323f7aea0f" +dependencies = [ + "cfg-if 1.0.0", + "cpufeatures", + "digest", +] [[package]] -name = "syntex_errors" -version = "0.48.0" +name = "sha2" +version = "0.10.2" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "55deaec60f81eefe3cce0dc50bda92d6d8e88f2a27df7c5033b42afeb1ed2676" dependencies = [ - "libc 0.2.14 (registry+https://github.com/rust-lang/crates.io-index)", - "log 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", - "rustc-serialize 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)", - "syntex_pos 0.48.0 (registry+https://github.com/rust-lang/crates.io-index)", - "term 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)", - "unicode-xid 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)", + "cfg-if 1.0.0", + "cpufeatures", + "digest", ] [[package]] -name = "syntex_pos" -version = "0.48.0" +name = "smallvec" +version = "1.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f2dd574626839106c320a323308629dcb1acfc96e32a8cba364ddc61ac23ee83" + +[[package]] +name = "stable_deref_trait" +version = "1.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dba1a27d3efae4351c8051072d619e3ade2820635c3958d826bfea39d59b54c8" + +[[package]] +name = "stacker" +version = "0.1.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "90939d5171a4420b3ff5fbc8954d641e7377335454c259dcb80786f3f21dc9b4" dependencies = [ - "rustc-serialize 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)", + "cc", + "cfg-if 1.0.0", + "libc", + "psm", + "winapi", ] [[package]] -name = "syntex_syntax" -version = "0.48.0" +name = "syn" +version = "1.0.93" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "04066589568b72ec65f42d65a1a52436e954b168773148893c020269563decf2" dependencies = [ - "bitflags 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.14 (registry+https://github.com/rust-lang/crates.io-index)", - "log 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", - "rustc-serialize 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)", - "syntex_errors 0.48.0 (registry+https://github.com/rust-lang/crates.io-index)", - "syntex_pos 0.48.0 (registry+https://github.com/rust-lang/crates.io-index)", - "term 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)", - "unicode-xid 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro2", + "quote", + "unicode-xid", ] [[package]] -name = "term" -version = "0.4.4" +name = "synstructure" +version = "0.12.2" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "575be94ccb86e8da37efb894a87e2b660be299b41d8ef347f9d6d79fbe61b1ba" dependencies = [ - "kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro2", + "quote", + "syn", + "unicode-xid", ] +[[package]] +name = "tempfile" +version = "3.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5cdb1ef4eaeeaddc8fbd371e5017057064af0911902ef36b39801f67cc6d79e4" +dependencies = [ + "cfg-if 1.0.0", + "fastrand", + "libc", + "redox_syscall", + "remove_dir_all", + "winapi", +] + +[[package]] +name = "termcolor" +version = "1.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "96d6098003bde162e4277c70665bd87c326f5a0c3f3fbfb285787fa482d54e6e" +dependencies = [ + "wincolor", +] + +[[package]] +name = "termize" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1706be6b564323ce7092f5f7e6b118a14c8ef7ed0e69c8c5329c914a9f101295" +dependencies = [ + "libc", + "winapi", +] + +[[package]] +name = "thiserror" +version = "1.0.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bd829fe32373d27f76265620b5309d0340cb8550f523c1dda251d6298069069a" +dependencies = [ + "thiserror-impl", +] + +[[package]] +name = "thiserror-impl" +version = "1.0.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0396bc89e626244658bef819e22d0cc459e795a5ebe878e6ec336d1674a8d79a" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "tinystr" +version = "0.3.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "29738eedb4388d9ea620eeab9384884fc3f06f586a2eddb56bedc5885126c7c1" + +[[package]] +name = "tinyvec" +version = "1.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87cc5ceb3875bb20c2890005a4e226a4651264a5c75edb2421b52861a0a0cb50" +dependencies = [ + "tinyvec_macros", +] + +[[package]] +name = "tinyvec_macros" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cda74da7e1a664f795bb1f8a87ec406fb89a02522cf6e50620d016add6dbbf5c" + +[[package]] +name = "tracing" +version = "0.1.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5d0ecdcb44a79f0fe9844f0c4f33a342cbcbb5117de8001e6ba0dc2351327d09" +dependencies = [ + "cfg-if 1.0.0", + "pin-project-lite", + "tracing-attributes", + "tracing-core", +] + +[[package]] +name = "tracing-attributes" +version = "0.1.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cc6b8ad3567499f98a1db7a752b07a7c8c7c7c34c332ec00effb2b0027974b7c" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "tracing-core" +version = "0.1.26" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f54c8ca710e81886d498c2fd3331b56c93aa248d49de2222ad2742247c60072f" +dependencies = [ + "lazy_static", +] + +[[package]] +name = "type-map" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6d3364c5e96cb2ad1603037ab253ddd34d7fb72a58bdddf4b7350760fc69a46" +dependencies = [ + "rustc-hash", +] + +[[package]] +name = "typenum" +version = "1.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dcf81ac59edc17cc8697ff311e8f5ef2d99fcbd9817b34cec66f90b6c3dfd987" + +[[package]] +name = "unic-char-property" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a8c57a407d9b6fa02b4795eb81c5b6652060a15a7903ea981f3d723e6c0be221" +dependencies = [ + "unic-char-range", +] + +[[package]] +name = "unic-char-range" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0398022d5f700414f6b899e10b8348231abf9173fa93144cbc1a43b9793c1fbc" + +[[package]] +name = "unic-common" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "80d7ff825a6a654ee85a63e80f92f054f904f21e7d12da4e22f9834a4aaa35bc" + +[[package]] +name = "unic-emoji-char" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b07221e68897210270a38bde4babb655869637af0f69407f96053a34f76494d" +dependencies = [ + "unic-char-property", + "unic-char-range", + "unic-ucd-version", +] + +[[package]] +name = "unic-langid" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "73328fcd730a030bdb19ddf23e192187a6b01cd98be6d3140622a89129459ce5" +dependencies = [ + "unic-langid-impl", + "unic-langid-macros", +] + +[[package]] +name = "unic-langid-impl" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1a4a8eeaf0494862c1404c95ec2f4c33a2acff5076f64314b465e3ddae1b934d" +dependencies = [ + "tinystr", +] + +[[package]] +name = "unic-langid-macros" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "18f980d6d87e8805f2836d64b4138cc95aa7986fa63b1f51f67d5fbff64dd6e5" +dependencies = [ + "proc-macro-hack", + "tinystr", + "unic-langid-impl", + "unic-langid-macros-impl", +] + +[[package]] +name = "unic-langid-macros-impl" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "29396ffd97e27574c3e01368b1a64267d3064969e4848e2e130ff668be9daa9f" +dependencies = [ + "proc-macro-hack", + "quote", + "syn", + "unic-langid-impl", +] + +[[package]] +name = "unic-ucd-version" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "96bd2f2237fe450fcd0a1d2f5f4e91711124f7857ba2e964247776ebeeb7b0c4" +dependencies = [ + "unic-common", +] + +[[package]] +name = "unicode-normalization" +version = "0.1.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d54590932941a9e9266f0832deed84ebe1bf2e4c9e4a3554d393d18f5e854bf9" +dependencies = [ + "tinyvec", +] + +[[package]] +name = "unicode-width" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7007dbd421b92cc6e28410fe7362e2e0a2503394908f417b68ec8d1c364c4e20" + [[package]] name = "unicode-xid" -version = "0.0.3" +version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "826e7639553986605ec5979c7dd957c7895e93eabed50ab2ffa7f6128a75097c" + +[[package]] +name = "version_check" +version = "0.9.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" + +[[package]] +name = "wasi" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b89c3ce4ce14bdc6fb6beaf9ec7928ca331de5df7e5ea278375642a2f478570d" [[package]] name = "winapi" -version = "0.2.8" +version = "0.3.8" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8093091eeb260906a183e6ae1abdba2ef5ef2257a21801128899c3fc699229c6" +dependencies = [ + "winapi-i686-pc-windows-gnu", + "winapi-x86_64-pc-windows-gnu", +] [[package]] -name = "winapi-build" -version = "0.1.1" +name = "winapi-i686-pc-windows-gnu" +version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" -[metadata] -"checksum bitflags 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "aad18937a628ec6abcd26d1489012cc0e18c21798210f491af69ded9b881106d" -"checksum kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7507624b29483431c0ba2d82aece8ca6cdba9382bff4ddd0f7490560c056098d" -"checksum libc 0.2.14 (registry+https://github.com/rust-lang/crates.io-index)" = "39dfaaa0f4da0f1a06876c5d94329d739ad0150868069cc235f1ddf80a0480e7" -"checksum log 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)" = "ab83497bf8bf4ed2a74259c1c802351fcd67a65baa86394b6ba73c36f4838054" -"checksum rustc-serialize 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)" = "6159e4e6e559c81bd706afe9c8fd68f547d3e851ce12e76b1de7914bab61691b" -"checksum rustdt_util 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "7cfffa8a89d8758be2dd5605c5fc62bce055af2491ebf3ce953d4d31512c59fd" -"checksum syntex_errors 0.48.0 (registry+https://github.com/rust-lang/crates.io-index)" = "0b2784ff2ca385a451f1f835dcb3926e5c61461c6468aac1e35edcbc4cd33808" -"checksum syntex_pos 0.48.0 (registry+https://github.com/rust-lang/crates.io-index)" = "25fadff25e4db9336cd715dea4bc7d4bf51d08cc39a1463b689661f1dea6893c" -"checksum syntex_syntax 0.48.0 (registry+https://github.com/rust-lang/crates.io-index)" = "0c3c7d1082d30f7042d1e7b00bd2ab0466daa84529fa13891e9312d8a32fd97e" -"checksum term 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)" = "3deff8a2b3b6607d6d7cc32ac25c0b33709453ca9cceac006caac51e963cf94a" -"checksum unicode-xid 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "36dff09cafb4ec7c8cf0023eb0b686cb6ce65499116a12201c9e11840ca01beb" -"checksum winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)" = "167dc9d6949a9b857f3451275e911c3f44255842c1f7a76f33c55103a909087a" -"checksum winapi-build 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "2d315eee3b34aca4797b2da6b13ed88266e6d612562a0c46390af8299fc699bc" +[[package]] +name = "winapi-util" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7168bab6e1daee33b4557efd0e95d5ca70a03706d39fa5f3fe7a236f584b03c9" +dependencies = [ + "winapi", +] + +[[package]] +name = "winapi-x86_64-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" + +[[package]] +name = "wincolor" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "96f5016b18804d24db43cebf3c77269e7569b8954a8464501c216cc5e070eaa9" +dependencies = [ + "winapi", + "winapi-util", +] diff --git a/Cargo.toml b/Cargo.toml index e36c4f2..fe6c10a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,14 +1,23 @@ [package] name = "rainicorn" -version = "2.0.0" +version = "3.0.0" +autobins = false +edition = "2018" [dependencies] -syntex_errors = "0.48.0" -syntex_syntax = "0.48.0" +rustc_errors = { git = "https://github.com/snuk182/rustc-syntax-tools" } +rustc_error_messages = { git = "https://github.com/snuk182/rustc-syntax-tools" } +rustc_data_structures = { git = "https://github.com/snuk182/rustc-syntax-tools" } +rustc_span = { git = "https://github.com/snuk182/rustc-syntax-tools" } +rustc_session = { git = "https://github.com/snuk182/rustc-syntax-tools" } +rustc_ast = { git = "https://github.com/snuk182/rustc-syntax-tools" } +rustc_ast_pretty = { git = "https://github.com/snuk182/rustc-syntax-tools" } +rustc_parse = { git = "https://github.com/snuk182/rustc-syntax-tools" } rustdt_util ="0.2.3" [[bin]] name = "parse_describe" +path = "src/main.rs" test = false [lib] diff --git a/rustfmt.toml b/rustfmt.toml new file mode 100644 index 0000000..34eb15b --- /dev/null +++ b/rustfmt.toml @@ -0,0 +1 @@ +max_width = 250 diff --git a/src/lib.rs b/src/lib.rs index dc6bc9e..9f8c1ce 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,11 +1,16 @@ #![allow(non_snake_case)] -extern crate syntex_syntax; -extern crate syntex_errors; -extern crate rustdt_util as util; +use rustdt_util as util; +use rustc_errors; +use rustc_data_structures; +use rustc_span; +use rustc_error_messages; +use rustc_session; +use rustc_ast; +use rustc_ast_pretty; +use rustc_parse; -pub mod token_writer; -pub mod source_model; pub mod parse_describe; +pub mod source_model; pub mod structure_visitor; - +pub mod token_writer; diff --git a/src/main.rs b/src/main.rs index 40297c7..8cd00ac 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,17 +1,15 @@ -extern crate rainicorn; - -use rainicorn::*; - -use std::io::{self, Read}; - -fn main() { - - let mut buffer = String::new(); - let result = io::stdin().read_to_string(&mut buffer); - - match result { - Err(err) => println!("Error: {}.", err), - Ok(_) => parse_describe::parse_analysis_for_Stdout(&buffer), - } - -} \ No newline at end of file +extern crate rainicorn; + +use rainicorn::*; + +use std::io::{self, Read}; + +fn main() { + let mut buffer = String::new(); + let result = io::stdin().read_to_string(&mut buffer); + + match result { + Err(err) => println!("Error: {}.", err), + Ok(_) => parse_describe::parse_analysis_for_Stdout(&buffer), + } +} diff --git a/src/parse_describe.rs b/src/parse_describe.rs index 338b6f9..d229db1 100644 --- a/src/parse_describe.rs +++ b/src/parse_describe.rs @@ -12,89 +12,84 @@ // See the License for the specific language governing permissions and // limitations under the License. -use util::core::*; -use util::string::*; -use source_model::*; - -use syntex_syntax::syntax::ast; -use syntex_syntax::parse::{ self, ParseSess }; -use syntex_syntax::visit; -use syntex_syntax::codemap::{ self, MultiSpan, CodeMap}; -use syntex_errors::{ Handler, Level, DiagnosticBuilder }; -use syntex_errors::emitter::{ self }; - +use crate::token_writer::TokenWriter; +use crate::source_model::*; + +use crate::util::core::*; +use crate::util::string::*; + +use crate::rustc_errors::emitter; +use crate::rustc_errors::{Diagnostic, Handler, Level, DiagnosticId, PResult, DiagnosticMessage, FluentBundle, LazyFallbackBundle, DEFAULT_LOCALE_RESOURCES, fallback_fluent_bundle}; +use crate::rustc_span::source_map::{self, SourceMap, FilePathMapping, FileName}; +use crate::rustc_error_messages::MultiSpan; +use crate::rustc_session::parse::{ParseSess}; +use crate::rustc_parse as parse; +use crate::rustc_ast::ast; +use crate::rustc_span::{SourceFileHashAlgorithm, RealFileName}; +use crate::rustc_ast::tokenstream::TokenStream; +use crate::rustc_ast::visit; +use crate::rustc_data_structures::sync::Lrc; use std::boxed::Box; use std::path::Path; -use token_writer::TokenWriter; - use std::cell::RefCell; -use std::rc::*; +use std::fmt; use std::io; use std::io::Write; -use std::fmt; -use std::path::PathBuf; -use std::env; - +use std::rc::*; /* ----------------- ----------------- */ -pub fn parse_analysis_for_Stdout(source : &str) { +pub fn parse_analysis_for_Stdout(source: &str) { parse_analysis(source, StdoutWrite(io::stdout())).ok(); println!(""); io::stdout().flush().ok(); } -pub fn parse_analysis(source : &str, out : T) -> GResult { +pub fn parse_analysis(source: &str, out: T) -> GResult { let (messages, elements) = parse_crate_with_messages(source); - + let outRc = Rc::new(RefCell::new(out)); - try!(write_parse_analysis_do(messages, elements, outRc.clone())); + write_parse_analysis_do(messages, elements, outRc.clone())?; let res = unwrap_Rc_RefCell(outRc); return Ok(res); } -use std::thread; use std::sync::{Arc, Mutex}; +use std::thread; pub fn parse_crate_with_messages(source: &str) -> (Vec, Vec) { - let messages = Arc::new(Mutex::new(vec![])); - let elements = - { - let source = String::from(source); + let elements = { + let source = String::from(source); let messages = messages.clone(); - - let worker_thread = thread::Builder::new().name("parser_thread".to_string()).spawn(move || { - parse_crate_with_messages_do(&source, messages) - }).unwrap(); - + + let worker_thread = thread::Builder::new().name("parser_thread".to_string()).spawn(move || parse_crate_with_messages_do(&source, messages)).unwrap(); + worker_thread.join().unwrap_or(vec![]) }; - - let messages : Mutex> = Arc::try_unwrap(messages).ok().unwrap(); - let messages : Vec = messages.into_inner().unwrap(); - + + let messages: Mutex> = Arc::try_unwrap(messages).ok().unwrap(); + let messages: Vec = messages.into_inner().unwrap(); + return (messages, elements); } -pub fn parse_crate_with_messages_do(source: &str, messages: Arc>>) - -> Vec -{ - use ::structure_visitor::StructureVisitor; - +pub fn parse_crate_with_messages_do(source: &str, messages: Arc>>) -> Vec { + use crate::structure_visitor::StructureVisitor; + let mut elements = vec![]; - + let fileLoader = Box::new(DummyFileLoader::new()); - let codemap = Rc::new(CodeMap::with_file_loader(fileLoader)); - + let codemap = Rc::new(SourceMap::with_file_loader_and_hash_kind(fileLoader, FilePathMapping::empty(), SourceFileHashAlgorithm::Md5)); + let krate = parse_crate(source, codemap.clone(), messages.clone()); - + if let Some(krate) = krate { - let mut visitor : StructureVisitor = StructureVisitor::new(&codemap); + let mut visitor: StructureVisitor = StructureVisitor::new(&codemap); visit::walk_crate(&mut visitor, &krate); - + elements = visitor.elements; } return elements; @@ -102,362 +97,331 @@ pub fn parse_crate_with_messages_do(source: &str, messages: Arc DummyFileLoader { - DummyFileLoader { modName : OsStr::new("mod.rs") } + DummyFileLoader { modName: OsStr::new("mod.rs") } } } -impl codemap::FileLoader for DummyFileLoader { +impl source_map::FileLoader for DummyFileLoader { fn file_exists(&self, path: &Path) -> bool { return path.file_name() == Some(self.modName); } - - fn abs_path(&self, path: &Path) -> Option { - if path.is_absolute() { - Some(path.to_path_buf()) - } else { - env::current_dir().ok().map(|cwd| cwd.join(path)) - } - } - + fn read_file(&self, _path: &Path) -> io::Result { Ok(String::new()) } } - struct MessagesHandler { - codemap : Rc, - messages : Arc>>, + codemap: Rc, + messages: Arc>>, + fallback_fluent_bundle: LazyFallbackBundle, } - -fn parse_crate<'a>(source: &str, codemap: Rc, messages: Arc>>) -> Option -{ +fn parse_crate<'a>(source: &str, codemap: Rc, messages: Arc>>) -> Option { let emitter = MessagesHandler::new(codemap.clone(), messages.clone()); - - let handler = Handler::with_emitter(true, false, Box::new(emitter)); + + let handler = Handler::with_emitter(true, None, Box::new(emitter)); let sess = ParseSess::with_span_handler(handler, codemap.clone()); - + let krate_result = parse_crate_do(source, &sess); - + return match krate_result { - Ok(_krate) => { - Some(_krate) - } - Err(mut db) => { + Ok(_krate) => Some(_krate), + Err(mut db) => { db.emit(); None } - } + }; } -pub fn parse_crate_do<'a>(source : &str, sess : &'a ParseSess) -> parse::PResult<'a, ast::Crate> -{ - let source = source.to_string(); +pub fn parse_crate_do<'a>(source: &str, sess: &'a ParseSess) -> PResult<'a, ast::Crate> { + use std::iter::FromIterator; + let source = source.to_string(); let name = "_file_module_".to_string(); -// We inlined: let mut parser = parse::new_parser_from_source_str(&sess, cfg, name, source); - - let filemap = sess.codemap().new_filemap(name, None, source); - - // filemap_to_tts but without a panic - let tts = - { - let srdr = parse::lexer::StringReader::new(&sess.span_diagnostic, filemap); - let mut p1 = parse::parser::Parser::new(sess, Box::new(srdr)); - - try!(p1.parse_all_token_trees()) + let tts = { + let mut p1 = parse::new_parser_from_source_str(sess, FileName::Real(RealFileName::LocalPath(name.into())), source); + p1.parse_all_token_trees()?.into_iter().map(|tt| tt.into()).collect::>() }; - - let trdr = parse::lexer::new_tt_reader(&sess.span_diagnostic, None, tts); - let mut parser = parse::parser::Parser::new(sess, Box::new(trdr)); - - return parser.parse_crate_mod(); -} - - + let mut parser = parse::parser::Parser::new(sess, TokenStream::from_iter(tts), true, None); + parser.parse_crate_mod() +} impl MessagesHandler { - - fn new(codemap: Rc, messages: Arc>>) -> MessagesHandler { - MessagesHandler { codemap : codemap, messages : messages } + fn new(codemap: Rc, messages: Arc>>) -> MessagesHandler { + MessagesHandler { codemap: codemap, messages: messages, fallback_fluent_bundle: fallback_fluent_bundle(DEFAULT_LOCALE_RESOURCES, false) } } - - fn write_message_handled(&mut self, sourcerange : Option, msg: &str, severity: Severity) { - - let msg = SourceMessage{ severity : severity , sourcerange : sourcerange, message : String::from(msg) }; - + + fn write_message_handled(&mut self, sourcerange: Option, msg: &str, severity: Severity) { + let msg = SourceMessage { + severity: severity, + sourcerange: sourcerange, + message: String::from(msg), + }; + let mut messages = self.messages.lock().unwrap(); messages.push(msg); } - } impl emitter::Emitter for MessagesHandler { - - fn emit(&mut self, db: &DiagnosticBuilder) { - let msg: &str = &db.message; - let code: Option<&String> = db.code.as_ref(); - let lvl: Level = db.level; - - let multispan : &MultiSpan = &db.span; - - if let Some(code) = code { - io::stderr().write_fmt(format_args!("Code: {}\n", code)).unwrap(); - panic!("What is code: Option<&str>??"); - } - - let sourceranges : Vec<_> = multispan.primary_spans().iter() - .map(|span| -> SourceRange { SourceRange::new(&self.codemap, *span)}) - .collect(); - - for sourcerange in sourceranges { - self.write_message_handled(Some(sourcerange), msg, level_to_status_level(lvl)); - } + fn emit_diagnostic(&mut self, db: &Diagnostic) { + for ref msg in db.message.as_slice() { + let msg = match &msg.0 { + DiagnosticMessage::Str(ref str) => str.clone(), + DiagnosticMessage::FluentIdentifier(id, _) => format!("FluentID: {}", id), + }; + let code: Option<&String> = db.code.as_ref().map(|c| match c { + DiagnosticId::Error(ref str) => str, + DiagnosticId::Lint {ref name, ..} => name, + }); + let lvl: Level = db.level(); + + let multispan: &MultiSpan = &db.span; + + if let Some(code) = code { + io::stderr().write_fmt(format_args!("Code: {}\n", code)).unwrap(); + panic!("What is code: Option<&str>??"); + } + + let sourceranges: Vec<_> = multispan.primary_spans().iter().map(|span| -> SourceRange { SourceRange::new(self.codemap.as_ref(), *span) }).collect(); + + for sourcerange in sourceranges { + self.write_message_handled(Some(sourcerange), msg.as_str(), level_to_status_level(lvl)); + } + } } -} -fn level_to_status_level(lvl: Level) -> Severity { - match lvl { - Level::PhaseFatal => panic!("Level::PhaseFatal"), - Level::Bug => panic!("Level::BUG"), - Level::Cancelled => panic!("Level::CANCELLED"), - Level::Help | Level::Note => Severity::INFO, - Level::Warning => Severity::WARNING, - Level::Error | Level::Fatal => Severity::ERROR, + fn fluent_bundle(&self) -> Option<&Lrc> { None } + + fn fallback_fluent_bundle(&self) -> &FluentBundle { + &**self.fallback_fluent_bundle + } + + fn source_map(&self) -> Option<&Lrc> { + Some(&self.codemap) } } -impl MessagesHandler { +fn level_to_status_level(lvl: Level) -> Severity { + match lvl { + Level::Bug | Level::DelayedBug => panic!("Level::BUG"), + Level::Help | Level::Note | Level::OnceNote | Level::Allow => Severity::INFO, + Level::Warning | Level::FailureNote | Level::Expect(_) => Severity::WARNING, + Level::Fatal => Severity::ERROR, + Level::Error {lint} => if lint {Severity::WARNING} else {Severity::ERROR} + } } +impl MessagesHandler {} /* ----------------- describe writting ----------------- */ -pub fn write_parse_analysis_do(messages: Vec, elements: Vec, - out : Rc>) -> Void { - - let mut tokenWriter = TokenWriter { out : out }; - - try!(tokenWriter.write_raw("RUST_PARSE_DESCRIBE 1.0 {\n")); - try!(write_parse_analysis_contents(messages, elements, &mut tokenWriter)); - try!(tokenWriter.write_raw("\n}")); - +pub fn write_parse_analysis_do(messages: Vec, elements: Vec, out: Rc>) -> Void { + let mut tokenWriter = TokenWriter { out: out }; + + tokenWriter.write_raw("RUST_PARSE_DESCRIBE 1.0 {\n")?; + write_parse_analysis_contents(messages, elements, &mut tokenWriter)?; + tokenWriter.write_raw("\n}")?; + Ok(()) } -pub fn write_parse_analysis_contents(messages: Vec, elements: Vec, - tokenWriter : &mut TokenWriter) -> Void { - - try!(tokenWriter.write_raw("MESSAGES {\n")); +pub fn write_parse_analysis_contents(messages: Vec, elements: Vec, tokenWriter: &mut TokenWriter) -> Void { + tokenWriter.write_raw("MESSAGES {\n")?; for msg in messages { - try!(output_message(tokenWriter, msg.sourcerange, &msg.message, &msg.severity)); + output_message(tokenWriter, msg.sourcerange, &msg.message, &msg.severity)?; } - try!(tokenWriter.write_raw("}\n")); - - + tokenWriter.write_raw("}\n")?; + for element in elements { - try!(write_structure_element(tokenWriter, &element, 0)); + write_structure_element(tokenWriter, &element, 0)?; } - + Ok(()) } -fn output_message(tokenWriter: &mut TokenWriter, opt_sr : Option, msg: & str, lvl: &Severity) - -> Void -{ - - try!(tokenWriter.write_raw("{ ")); - - try!(output_Level(&lvl, tokenWriter)); - - try!(output_opt_SourceRange(&opt_sr, tokenWriter)); - - try!(tokenWriter.write_string_token(msg)); - - try!(tokenWriter.write_raw("}\n")); - +fn output_message(tokenWriter: &mut TokenWriter, opt_sr: Option, msg: &str, lvl: &Severity) -> Void { + tokenWriter.write_raw("{ ")?; + + output_Level(&lvl, tokenWriter)?; + + output_opt_SourceRange(&opt_sr, tokenWriter)?; + + tokenWriter.write_string_token(msg)?; + + tokenWriter.write_raw("}\n")?; + Ok(()) } +pub fn output_Level(lvl: &Severity, writer: &mut TokenWriter) -> Void { + writer.write_raw_token(lvl.to_string())?; -pub fn output_Level(lvl : &Severity, writer : &mut TokenWriter) -> Void { - - try!(writer.write_raw_token(lvl.to_string())); - Ok(()) } -pub fn output_SourceRange(sr : &SourceRange, tw : &mut TokenWriter) -> Void { - try!(tw.write_raw("{ ")); +pub fn output_SourceRange(sr: &SourceRange, tw: &mut TokenWriter) -> Void { + tw.write_raw("{ ")?; { - let mut out = tw.get_output(); - try!(out.write_fmt(format_args!("{}:{} {}:{} ", - sr.start_pos.line-1, sr.start_pos.col.0, - sr.end_pos.line-1, sr.end_pos.col.0, - ))); + let mut out = tw.get_output(); + out.write_fmt(format_args!("{}:{} {}:{} ", sr.start_pos.line - 1, sr.start_pos.col.0, sr.end_pos.line - 1, sr.end_pos.col.0,))?; } - try!(tw.write_raw("}")); - + tw.write_raw("}")?; + Ok(()) } -pub fn output_opt_SourceRange(sr : &Option, writer : &mut TokenWriter) -> Void { - +pub fn output_opt_SourceRange(sr: &Option, writer: &mut TokenWriter) -> Void { match sr { - &None => try!(writer.write_raw("{ }")) , - &Some(ref sr) => try!(output_SourceRange(sr, writer)) , + &None => writer.write_raw("{ }")?, + &Some(ref sr) => output_SourceRange(sr, writer)?, } - - try!(writer.write_raw(" ")); - + + writer.write_raw(" ")?; + Ok(()) } - -pub fn write_indent(tokenWriter : &mut TokenWriter, level : u32) -> Void { - try!(writeNTimes(&mut *tokenWriter.get_output(), ' ', level * 2)); +pub fn write_indent(tokenWriter: &mut TokenWriter, level: u32) -> Void { + writeNTimes(&mut *tokenWriter.get_output(), ' ', level * 2)?; Ok(()) } -pub fn write_structure_element(tw : &mut TokenWriter, element: &StructureElement, level: u32) -> Void -{ - try!(tw.write_raw_token(element.kind.to_string())); - - try!(tw.write_raw("{ ")); - - try!(tw.write_string_token(&element.name)); - - try!(output_SourceRange(&element.sourcerange, tw)); - - try!(tw.get_output().write_str(" {}")); // name source range, Not Supported - - try!(tw.get_output().write_str(" ")); - try!(tw.write_string_token(&element.type_desc)); - - try!(tw.get_output().write_str("{}")); // attribs, Not Supported - +pub fn write_structure_element(tw: &mut TokenWriter, element: &StructureElement, level: u32) -> Void { + tw.write_raw_token(element.kind.to_string())?; + + tw.write_raw("{ ")?; + + tw.write_string_token(&element.name)?; + + output_SourceRange(&element.sourcerange, tw)?; + + tw.get_output().write_str(" {}")?; // name source range, Not Supported + + tw.get_output().write_str(" ")?; + tw.write_string_token(&element.type_desc)?; + + tw.get_output().write_str("{}")?; // attribs, Not Supported + if element.children.is_empty() { - try!(tw.get_output().write_str(" ")); + tw.get_output().write_str(" ")?; } else { let level = level + 1; - + for child in &element.children { - try!(tw.get_output().write_str("\n")); - try!(write_indent(tw, level)); - try!(write_structure_element(tw, child, level)); + tw.get_output().write_str("\n")?; + write_indent(tw, level)?; + write_structure_element(tw, child, level)?; } - - try!(tw.get_output().write_str("\n")); - try!(write_indent(tw, level-1)); + + tw.get_output().write_str("\n")?; + write_indent(tw, level - 1)?; } - - try!(tw.get_output().write_str("}")); - + + tw.get_output().write_str("}")?; + Ok(()) } - #[cfg(test)] mod parse_describe_tests { - - use parse_describe::*; - use source_model::*; - use token_writer::TokenWriter; - use util::core::*; - use util::tests::check_equal; - use util; - use std::rc::Rc; use std::cell::RefCell; - - fn test_write_structure_element(name : &str, kind : StructureElementKind, sr: SourceRange, type_desc : String, - expected : &str, - ) { - let stringRc = Rc::new(RefCell::new(String::new())); - { - let name = String::from(name); - let element = StructureElement { name: name, kind: kind, sourcerange: sr, type_desc: type_desc, - children: vec![]}; - let mut tw = TokenWriter { out : stringRc.clone() }; - - write_structure_element(&mut tw, &element, 0).ok(); - } - - assert_eq!(unwrap_Rc_RefCell(stringRc).trim(), expected); + use std::rc::Rc; + + use crate::parse_describe::*; + use crate::source_model::*; + use crate::token_writer::TokenWriter; + use crate::util; + use crate::util::core::*; + use crate::util::tests::check_equal; + + fn test_write_structure_element(name: &str, kind: StructureElementKind, sr: SourceRange, type_desc: String, expected: &str) { + let stringRc = Rc::new(RefCell::new(String::new())); + { + let name = String::from(name); + let element = StructureElement { + name: name, + kind: kind, + sourcerange: sr, + type_desc: type_desc, + children: vec![], + }; + let mut tw = TokenWriter { out: stringRc.clone() }; + + write_structure_element(&mut tw, &element, 0).ok(); } + assert_eq!(unwrap_Rc_RefCell(stringRc).trim(), expected); + } + #[test] fn write_structure_element__tests() { - test_write_structure_element("blah", StructureElementKind::Var, source_range(1, 0, 2, 5), "desc".to_string(), - r#"Var { "blah" { 0:0 1:5 } {} "desc" {} }"#); + test_write_structure_element("blah", StructureElementKind::Var, source_range(1, 0, 2, 5), "desc".to_string(), r#"Var { "blah" { 0:0 1:5 } {} "desc" {} }"#); } - - + #[test] fn parse_analysis__tests() { test_parse_analysis("", ""); - + test_parse_analysis(" #blah ", r#"{ ERROR { 0:2 0:6 } "expected `[`, found `blah`" }"#); - - test_parse_analysis("fn foo(\n blah", r#" + + test_parse_analysis( + "fn foo(\n blah", + r#" { ERROR { 1:6 1:6 } "this file contains an un-closed delimiter" } { ERROR { 1:6 1:6 } "expected one of `:` or `@`, found `)`" } { ERROR { 1:6 1:6 } "expected one of `->`, `where`, or `{`, found ``" } -"# +"#, ); - + // Test a lexer panic - test_parse_analysis("const a = '", - r#"{ ERROR { 0:10 0:11 } "character literal may only contain one codepoint: '" }"# - ); - + test_parse_analysis("const a = '", r#"{ ERROR { 0:10 0:11 } "character literal may only contain one codepoint: '" }"#); + // test `?` syntax shorthand for try: - test_parse_analysis("fn foo() { 123? }", - &("}\n".to_string() + r#"Function { "foo" { 0:0 0:17 } {} "()" {}"#) - ); + test_parse_analysis("fn foo() { 123? }", &("}\n".to_string() + r#"Function { "foo" { 0:0 0:17 } {} "()" {}"#)); } - - fn test_parse_analysis(source : &str, expected_msgs : &str) { + + fn test_parse_analysis(source: &str, expected_msgs: &str) { let result = parse_analysis(source, String::new()).ok().unwrap(); - let mut result : &str = &result; - + let mut result: &str = &result; + result = assert_surrounding_string("RUST_PARSE_DESCRIBE 1.0 {", result, "}"); - + result = assert_starts_with("MESSAGES {", result.trim()); expected_msgs.replace("\r\n", "\n"); result = assert_starts_with(expected_msgs.trim(), result.trim()); check_equal(result.trim(), "}"); } - - fn assert_surrounding_string<'a> (start : &str, string : &'a str, end : &str) -> &'a str { - let mut string : &str = string; - + + fn assert_surrounding_string<'a>(start: &str, string: &'a str, end: &str) -> &'a str { + let mut string: &str = string; + string = assert_starts_with(start, string); string = assert_ends_with(string, end); - + return string; } - - fn assert_starts_with<'a>(start : &str, string : &'a str) -> &'a str { + + fn assert_starts_with<'a>(start: &str, string: &'a str) -> &'a str { util::tests::assert_starts_with(string, start); - return &string[start.len() .. ]; + return &string[start.len()..]; } - - fn assert_ends_with<'a> (string : &'a str, end : &str) -> &'a str { + + fn assert_ends_with<'a>(string: &'a str, end: &str) -> &'a str { assert!(string.ends_with(end), "`{}` does not end with `{}`", string, end); - return &string[0 .. string.len() - end.len()]; + return &string[0..string.len() - end.len()]; } - -} \ No newline at end of file + +} diff --git a/src/source_model.rs b/src/source_model.rs index 869bc85..ca3422d 100644 --- a/src/source_model.rs +++ b/src/source_model.rs @@ -12,8 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -use ::syntex_syntax::codemap:: { Span, Loc, CodeMap, CharPos}; - +use crate::rustc_span::source_map::{CharPos, Loc, Span, SourceMap}; #[derive(Debug, Clone, Copy)] pub struct LineColumnPosition { @@ -21,40 +20,37 @@ pub struct LineColumnPosition { pub line: usize, /// The (0-based) column offset pub col: CharPos, - } #[derive(Debug, Clone, Copy)] pub struct SourceRange { - pub start_pos : LineColumnPosition, - pub end_pos : LineColumnPosition, + pub start_pos: LineColumnPosition, + pub end_pos: LineColumnPosition, } impl SourceRange { - pub fn new(codemap : &CodeMap, span : Span) -> SourceRange { - let startLoc = codemap.lookup_char_pos(span.lo); - let endLoc = codemap.lookup_char_pos(span.hi); - + pub fn new(codemap: &SourceMap, span: Span) -> SourceRange { + let startLoc = codemap.lookup_char_pos(span.lo()); + let endLoc = codemap.lookup_char_pos(span.hi()); + SourceRange::from_loc(startLoc, endLoc) } - - pub fn from_loc(startLoc : Loc, endLoc : Loc) -> SourceRange { - SourceRange{ - start_pos : LineColumnPosition{ line: startLoc.line, col : startLoc.col }, - end_pos : LineColumnPosition{ line: endLoc.line, col : endLoc.col }, + + pub fn from_loc(startLoc: Loc, endLoc: Loc) -> SourceRange { + SourceRange { + start_pos: LineColumnPosition { line: startLoc.line, col: startLoc.col }, + end_pos: LineColumnPosition { line: endLoc.line, col: endLoc.col }, } } - } -pub fn source_range(start_line : usize, start_col : usize, end_line : usize, end_col : usize) -> SourceRange { - SourceRange { - start_pos : LineColumnPosition { line : start_line, col : CharPos(start_col) }, - end_pos : LineColumnPosition { line : end_line, col : CharPos(end_col) }, +pub fn source_range(start_line: usize, start_col: usize, end_line: usize, end_col: usize) -> SourceRange { + SourceRange { + start_pos: LineColumnPosition { line: start_line, col: CharPos(start_col) }, + end_pos: LineColumnPosition { line: end_line, col: CharPos(end_col) }, } } - /* ----------------- ----------------- */ //use ::util::core::*; @@ -75,15 +71,15 @@ impl Severity { } } - pub struct SourceMessage { - pub severity : Severity, - pub sourcerange : Option, - pub message : String, + pub severity: Severity, + pub sourcerange: Option, + pub message: String, } /* ----------------- Model ----------------- */ +#[derive(Clone, Copy, Eq, PartialEq)] pub enum StructureElementKind { Var, Function, @@ -96,11 +92,12 @@ pub enum StructureElementKind { ExternCrate, Mod, Use, - MacroDef, // FIXME: not actually created at the moment + MacroDef, + OpaqueTy, + TraitAlias, TypeAlias, } - impl StructureElementKind { pub fn to_string(&self) -> &'static str { match *self { @@ -117,6 +114,8 @@ impl StructureElementKind { StructureElementKind::Use => "Use", StructureElementKind::MacroDef => "Macro", StructureElementKind::TypeAlias => "TypeAlias", + StructureElementKind::OpaqueTy => "OpaqueTy", + StructureElementKind::TraitAlias => "TraitAlias", } } } @@ -125,7 +124,7 @@ pub struct StructureElement { pub name: String, pub kind: StructureElementKind, pub sourcerange: SourceRange, - + pub type_desc: String, pub children: Vec, -} \ No newline at end of file +} diff --git a/src/structure_visitor.rs b/src/structure_visitor.rs index 6b6fc63..8e76584 100644 --- a/src/structure_visitor.rs +++ b/src/structure_visitor.rs @@ -12,288 +12,247 @@ // See the License for the specific language governing permissions and // limitations under the License. - //! //! Write a parse structure into a TokenWriter -//! +//! -use std; +use crate::source_model::*; +use crate::util::core::*; -use util::core::*; -use source_model::*; +use crate::rustc_ast::ast::*; +use crate::rustc_span::source_map::{SourceMap, Span}; +use crate::rustc_span::symbol::{Symbol, Ident}; +use crate::rustc_ast::visit::*; -use syntex_syntax::visit::*; -use syntex_syntax::ast::*; -use syntex_syntax::codemap:: { Span, CodeMap }; +use std::ops::Fn; pub struct StructureVisitor<'ps> { - pub codemap : & 'ps CodeMap, - pub parentIsStruct : bool, - pub parentIsUnion : bool, - pub elements : Vec, + pub codemap: &'ps SourceMap, + pub parentIsStruct: bool, + pub parentIsUnion: bool, + pub elements: Vec, } impl<'ps> StructureVisitor<'ps> { - - pub fn new(codemap : &'ps CodeMap) -> StructureVisitor<'ps> { - StructureVisitor { - codemap : codemap, parentIsStruct : false, parentIsUnion : false, elements : vec![] + pub fn new(codemap: &'ps SourceMap) -> StructureVisitor<'ps> { + StructureVisitor { + codemap: codemap, + parentIsStruct: false, + parentIsUnion: false, + elements: vec![], } } - - pub fn write_element_do( - &mut self, - ident: &str, - kind: StructureElementKind, - sourcerange: SourceRange, - type_desc: String, - walkFn: FN - ) -> Void - where FN : Fn(&mut Self) - { + fn visit_mac(&mut self, mac: &'ps MacCall) { + walk_mac(self, mac) + } + + pub fn write_element_do(&mut self, ident: &str, kind: StructureElementKind, sourcerange: SourceRange, type_desc: String, walkFn: FN) -> Void + where + FN: Fn(&mut Self), + { let mut siblings = vec![]; std::mem::swap(&mut self.elements, &mut siblings); - + walkFn(self); // self.elements now has children - + std::mem::swap(&mut self.elements, &mut siblings); let children = siblings; - - let element = StructureElement{ - name: String::from(ident), - kind: kind, - sourcerange: sourcerange , - type_desc : type_desc, - children : children + + let element = StructureElement { + name: String::from(ident), + kind: kind, + sourcerange: sourcerange, + type_desc: type_desc, + children: children, }; - + self.elements.push(element); Ok(()) } - - pub fn write_element_handled( - &mut self, - ident: &str, - kind : StructureElementKind, - sourceRange: SourceRange, - type_desc: String, - walkFn : FN) - where FN : Fn(&mut Self) + + pub fn write_element_handled(&mut self, ident: &str, kind: StructureElementKind, sourceRange: SourceRange, type_desc: String, walkFn: FN) + where + FN: Fn(&mut Self), { use std::io::Write; - - match - self.write_element_do(ident, kind, sourceRange, type_desc, walkFn) - { - Ok(ok) => { ok } - Err(error) => { - std::io::stderr().write_fmt(format_args!("Error writing element: {}", error)).ok(); + + match self.write_element_do(ident, kind, sourceRange, type_desc, walkFn) { + Ok(ok) => ok, + Err(error) => { + std::io::stderr().write_fmt(format_args!("Error writing element: {}", error)).ok(); } } } - - pub fn write_element_TODO( - &mut self, - ident: Ident, - kind : StructureElementKind, span: Span, - walkFn : FN - ) - where FN : Fn(&mut Self) + + pub fn write_element_TODO(&mut self, ident: Ident, kind: StructureElementKind, span: Span, walkFn: FN) + where + FN: Fn(&mut Self), { self.write_element(ident, kind, span, "".to_string(), walkFn); } - - pub fn write_element( - &mut self, - ident: Ident, - kind : StructureElementKind, - span: Span, - type_desc: String, walkFn : FN - ) - where FN : Fn(&mut Self) + + pub fn write_element(&mut self, ident: Ident, kind: StructureElementKind, span: Span, type_desc: String, walkFn: FN) + where + FN: Fn(&mut Self), { - self.write_element_handled(&*ident.name.as_str(), kind, SourceRange::new(self.codemap, span), - type_desc, walkFn) + self.write_element_handled(&*ident.name.as_str(), kind, SourceRange::new(self.codemap, span), type_desc, walkFn) } - + /* ----------------- ----------------- */ - - fn write_ItemUse(&mut self, vp : &ViewPath, span: Span) { - use syntex_syntax::print::pprust; - use syntex_syntax::ast; + + fn write_ItemUse(&mut self, tree: &UseTree) { use std::ops::Index; - + use crate::rustc_ast::ast; + use crate::rustc_ast_pretty::pprust; + let kind = StructureElementKind::Use; let mut useSpec = String::new(); - - fn writePath(outString : &mut String, path : &ast::Path) { + + fn writePath(outString: &mut String, path: &ast::Path) { outString.push_str(&pprust::path_to_string(path)); } - - match &vp.node { - &ViewPathSimple(ref ident, ref path) => { - writePath(&mut useSpec, path); - - let path : &ast::Path = path; + + match tree.kind { + UseTreeKind::Simple(ref ident, _ , _) => { + writePath(&mut useSpec, &tree.prefix); + + let path: &ast::Path = &tree.prefix; if path.segments.len() == 0 { return; } let lastSegment = path.segments.index(path.segments.len() - 1); - if &lastSegment.identifier != ident { - useSpec.push_str(&" as "); - useSpec.push_str(&*ident.name.as_str()); - } + if let Some(ident) = ident { + if &lastSegment.ident != ident { + useSpec.push_str(&" as "); + useSpec.push_str(&*ident.name.as_str()); + } + } } - &ViewPathGlob(ref path) => { - useSpec.push_str(&pprust::path_to_string(path)); + UseTreeKind::Glob => { + useSpec.push_str(&pprust::path_to_string(&tree.prefix)); useSpec.push_str(&"::*"); } - &ViewPathList(ref path, ref pathListItem) => { - writePath(&mut useSpec, path); - + UseTreeKind::Nested(ref trees) => { + writePath(&mut useSpec, &tree.prefix); + useSpec.push_str("::{ "); - for pitem in pathListItem { - let pitem : PathListItem_ = pitem.node; - - useSpec.push_str(&*pitem.name.name.as_str()); - if let Some(rename) = pitem.rename { - useSpec.push_str(" as "); - useSpec.push_str(&*rename.name.as_str()); - } - useSpec.push_str(", "); + for treenode in trees { + self.write_ItemUse(&treenode.0); } useSpec.push_str("}"); } } - self.write_element_handled(&useSpec, kind, SourceRange::new(self.codemap, span), "".to_string(), - &|_ : &mut Self| { }) + self.write_element_handled(&useSpec, kind, SourceRange::new(self.codemap, tree.span), "".to_string(), &|_: &mut Self| {}) } - + fn get_type_desc_from_fndecl(&mut self, fd: &FnDecl) -> String { - let mut type_desc = "".to_string(); - + type_desc.push('('); let mut needs_sep = false; - + for arg in &fd.inputs { - let arg : &Arg = arg; -// let pat : &Pat_ = &arg.pat.node; let pat_span = arg.pat.span; - + if needs_sep { type_desc.push_str(", "); } needs_sep = true; - + if let Ok(snippet) = self.codemap.span_to_snippet(arg.ty.span) { if !snippet.is_empty() { type_desc.push_str(&snippet); continue; } } - + if let Ok(snippet) = self.codemap.span_to_snippet(pat_span) { if snippet.ends_with("self") { type_desc.push_str(&snippet); continue; } } - }; + } type_desc.push_str(")"); - - if let FunctionRetTy::Ty(ref _ret) = fd.output { + + if let FnRetTy::Ty(ref _ret) = fd.output { if let Ok(ret_snippet) = self.codemap.span_to_snippet(fd.output.span()) { type_desc.push_str(" -> "); type_desc.push_str(&ret_snippet); } } - + type_desc } - - fn write_function_element(&mut self, ident: Ident, span: Span, fd: & FnDecl, walkFn : &Fn(&mut Self)) { + + fn write_function_element(&mut self, ident: Ident, span: Span, fd: &FnDecl, walkFn: &dyn Fn(&mut Self)) { let type_desc = self.get_type_desc_from_fndecl(&fd); - + self.write_element(ident, StructureElementKind::Function, span, type_desc, walkFn); } - } -impl<'v> Visitor for StructureVisitor<'v> { - - fn visit_name(&mut self, _span: Span, _name: Name) { +impl<'v> Visitor<'v> for StructureVisitor<'v> { + fn visit_name(&mut self, _span: Span, _name: Symbol) { // Nothing to do. } - fn visit_ident(&mut self, span: Span, ident: Ident) { - walk_ident(self, span, ident); + fn visit_ident(&mut self, ident: Ident) { + walk_ident(self, ident); } - - fn visit_mod(&mut self, m: &Mod, _span: Span, _nodeid: NodeId) { - -// let sr = &SourceRange::new(self.codemap, span); -// self.write_element_handled("_file_", StructureElementKind::File, sr, |_self : &mut Self| { -// walk_mod(_self, m); -// }) - walk_mod(self, m); - } - - fn visit_item(&mut self, item: &Item) { - + + fn visit_item(&mut self, item: &'v Item) { let kind; let mut type_desc = "".to_string(); - - let noop_walkFn = &|_self : &mut Self| { }; - - let walkFn : &Fn(&mut Self) = &|_self : &mut Self| { - walk_item(_self, item); + + let noop_walkFn = &|_self: &mut Self| {}; + + let walkFn: &dyn Fn(&mut Self) = &|_self: &mut Self| { + walk_item(_self, item); }; - - match item.node { + + match item.kind { + ItemKind::GlobalAsm(ref asm) => { + self.visit_inline_asm(asm); + return; + } + ItemKind::TraitAlias(ref _generics, ref _bounds) => { + kind = StructureElementKind::TraitAlias; + } ItemKind::ExternCrate(_opt_name) => { kind = StructureElementKind::ExternCrate; } ItemKind::Use(ref vp) => { - self.write_ItemUse(vp, item.span); + self.write_ItemUse(vp); return; } - ItemKind::Static(ref typ, _, ref _expr) | - ItemKind::Const(ref typ, ref _expr) => { - + ItemKind::Static(ref typ, _, ref _expr) | ItemKind::Const(_, ref typ, ref _expr) => { if let Ok(snippet) = self.codemap.span_to_snippet(typ.span) { type_desc.push_str(&snippet); } self.write_element(item.ident, StructureElementKind::Var, item.span, type_desc, noop_walkFn); return; } - ItemKind::Fn(ref declaration, unsafety, constness, abi, ref generics, ref body) => { - self.visit_fn(FnKind::ItemFn(item.ident, generics, unsafety, constness, abi, &item.vis), - declaration, - body, - item.span, - item.id); + ItemKind::Fn(ref fn1) => { + self.visit_fn(FnKind::Fn(FnCtxt::Free, item.ident, &fn1.sig, &item.vis, &fn1.generics, fn1.body.as_ref().map(|p| &**p)), item.span, item.id); return; } - ItemKind::Mod(ref _module) => { + ItemKind::Mod(_, _) => { kind = StructureElementKind::Mod; } ItemKind::ForeignMod(ref _foreign_module) => { kind = StructureElementKind::Mod; } - ItemKind::Ty(ref _typ, ref _type_parameters) => { + ItemKind::TyAlias(_) => { kind = StructureElementKind::TypeAlias; } ItemKind::Enum(ref _enum_definition, ref _type_parameters) => { kind = StructureElementKind::Enum; } - ItemKind::DefaultImpl(_, ref _trait_ref) => { + ItemKind::Impl(_) => { kind = StructureElementKind::Impl; } - ItemKind::Impl(_, _, ref _type_parameters, ref _opt_trait_reference, ref _typ, ref _impl_items) => { - kind = StructureElementKind::Impl; - } ItemKind::Struct(ref _struct_definition, ref _generics) => { // Go straight in self.parentIsStruct = true; @@ -305,29 +264,33 @@ impl<'v> Visitor for StructureVisitor<'v> { walk_item(self, item); return; } - ItemKind::Trait(_, ref _generics, ref _bounds, ref _methods) => { + ItemKind::Trait(_) => { kind = StructureElementKind::Trait; } - ItemKind::Mac(ref mac) => { + ItemKind::MacCall(ref mac) => { self.visit_mac(mac); return; } + ItemKind::MacroDef(ref macro_def) => { + self.visit_mac_def(macro_def, item.id); + return; + } } - + self.write_element(item.ident, kind, item.span, type_desc, walkFn); } - - fn visit_enum_def(&mut self, enum_def: &EnumDef, generics: &Generics, nodeid: NodeId, _span: Span) { + + fn visit_enum_def(&mut self, enum_def: &'v EnumDef, generics: &'v Generics, nodeid: NodeId, _span: Span) { // This element is covered by an item definition walk_enum_def(self, enum_def, generics, nodeid) } - - fn visit_variant(&mut self, v: &Variant, g: &Generics, nodeid: NodeId) { + + fn visit_variant(&mut self, v: &'v Variant) { // This element is covered by an enum_def call - walk_variant(self, v, g, nodeid); + walk_variant(self, v); } - - fn visit_variant_data(&mut self, s: &VariantData, ident: Ident, _: &Generics, _: NodeId, span: Span) { + + fn visit_variant_data(&mut self, s: &'v VariantData) { let mut kind = StructureElementKind::EnumVariant; if self.parentIsStruct { kind = StructureElementKind::Struct; @@ -337,278 +300,201 @@ impl<'v> Visitor for StructureVisitor<'v> { kind = StructureElementKind::Union; self.parentIsUnion = false; } - - self.write_element_TODO(ident, kind, span, |_self : &mut Self| { - walk_struct_def(_self, s); - }); - } - - fn visit_struct_field(&mut self, sf: &StructField) { - if let Some(ident) = sf.ident { - self.write_element_TODO(ident, StructureElementKind::Var, sf.span, |_self : &mut Self| { - walk_struct_field(_self, sf); - }); - } - } - - fn visit_trait_item(&mut self, ti: &TraitItem) { - let kind; - - match ti.node { - TraitItemKind::Const(ref _ty, ref _default) => { - kind = StructureElementKind::Var; - } - TraitItemKind::Method(ref sig, _) => { - self.write_function_element(ti.ident, ti.span, &sig.decl, &|_self : &mut Self| { - walk_trait_item(_self, ti); - }); - return; - } - TraitItemKind::Type(ref _bounds, ref _default) => { - kind = StructureElementKind::TypeAlias; - } - TraitItemKind::Macro(ref mac) => { - self.visit_mac(mac); - return; - } - } - - self.write_element_TODO(ti.ident, kind, ti.span, |_self : &mut Self| { - walk_trait_item(_self, ti); - }); - } - - fn visit_impl_item(&mut self, ii: &ImplItem) { - let kind; - - match ii.node { - ImplItemKind::Const(ref _ty, ref _default) => { - kind = StructureElementKind::Var; - } - ImplItemKind::Type(ref _type) => { - kind = StructureElementKind::TypeAlias; - } - ImplItemKind::Method(_, _) | - ImplItemKind::Macro(_) => { - walk_impl_item(self, ii); - return; - } - } - - self.write_element_TODO(ii.ident, kind, ii.span, |_self : &mut Self| { - walk_impl_item(_self, ii); - }); + match s { + VariantData::Struct(fields, _) | VariantData::Tuple(fields, _) => { + for field in fields { + self.write_element_TODO(field.ident.unwrap_or(Ident::empty()), kind, field.span, |_self: &mut Self| { + walk_struct_def(_self, s); + }); + } + }, + VariantData::Unit(_) => return, + }; } - + /* ----------------- Function ----------------- */ - - fn visit_fn(&mut self, fk: FnKind, fd: &FnDecl, b: &Block, span: Span, _nodeid: NodeId) { - - let ident : Ident; - + + fn visit_fn(&mut self, fk: FnKind<'v>, span: Span, _nodeid: NodeId) { + let ident: Ident; + match fk { - FnKind::Method(_ident, ref _MethodSig, _option) => { - ident = _ident; + FnKind::Fn(_, ident1, ref _MethodSig, _option, _b, _) => { + ident = ident1; } - FnKind::ItemFn(_ident, ref _Generics, _Unsafety, _Constness, _Abi, _Visibility) => { - ident = _ident; + FnKind::Closure(_, _) => { + return; } - FnKind::Closure => { return; } }; - - self.write_function_element(ident, span, fd, &|_self : &mut Self| { - walk_fn(_self, fk, fd, b, span); + + self.write_function_element(ident, span, fk.decl(), &|_self: &mut Self| { + walk_fn(_self, fk, span); }); } - - fn visit_foreign_item(&mut self, foreign_item: &ForeignItem) { + + fn visit_foreign_item(&mut self, foreign_item: &'v ForeignItem) { let kind; - - match foreign_item.node { - ForeignItemKind::Fn(ref _function_declaration, ref _generics) => { + + match foreign_item.kind { + ForeignItemKind::Fn(_) => { kind = StructureElementKind::Function; } - ForeignItemKind::Static(ref _typ, _) => { + ForeignItemKind::Static(ref _typ, _, _) => { kind = StructureElementKind::Var; } + ForeignItemKind::TyAlias(_) => { + kind = StructureElementKind::TypeAlias; + } + ForeignItemKind::MacCall(_) => { + kind = StructureElementKind::MacroDef; + } } - - self.write_element_TODO(foreign_item.ident, kind, foreign_item.span, |_self : &mut Self| { - walk_foreign_item(_self, foreign_item); + + self.write_element_TODO(foreign_item.ident, kind, foreign_item.span, |_self: &mut Self| { + walk_foreign_item(_self, foreign_item); }); } - - - fn visit_trait_ref(&mut self, t: &TraitRef) { - walk_trait_ref(self, t) - } - fn visit_ty_param_bound(&mut self, bounds: &TyParamBound) { - walk_ty_param_bound(self, bounds) + + fn visit_trait_ref(&mut self, t: &'v TraitRef) { + walk_trait_ref(self, t) } - fn visit_poly_trait_ref(&mut self, t: &PolyTraitRef, m: &TraitBoundModifier) { + fn visit_poly_trait_ref(&mut self, t: &'v PolyTraitRef, m: &'v TraitBoundModifier) { walk_poly_trait_ref(self, t, m) } - - fn visit_lifetime(&mut self, lifetime: &Lifetime) { + + fn visit_lifetime(&mut self, lifetime: &'v Lifetime) { walk_lifetime(self, lifetime) } - fn visit_lifetime_def(&mut self, lifetime: &LifetimeDef) { - walk_lifetime_def(self, lifetime) - } - fn visit_local(&mut self, l: &Local) { - walk_local(self, l) + fn visit_local(&mut self, l: &'v Local) { + walk_local(self, l) } - fn visit_block(&mut self, b: &Block) { - walk_block(self, b) + fn visit_block(&mut self, b: &'v Block) { + walk_block(self, b) } - fn visit_stmt(&mut self, s: &Stmt) { - walk_stmt(self, s) + fn visit_stmt(&mut self, s: &'v Stmt) { + walk_stmt(self, s) } - fn visit_arm(&mut self, a: &Arm) { - walk_arm(self, a) + fn visit_arm(&mut self, a: &'v Arm) { + walk_arm(self, a) } - fn visit_pat(&mut self, p: &Pat) { - walk_pat(self, p) + fn visit_pat(&mut self, p: &'v Pat) { + walk_pat(self, p) } fn visit_expr(&mut self, _ex: &Expr) { - // Comment, no need to visit node insinde expressions - //walk_expr(self, ex) - } - fn visit_expr_post(&mut self, _ex: &Expr) { + // Comment, no need to visit node insinde expressions + //walk_expr(self, ex) } - fn visit_ty(&mut self, t: &Ty) { - walk_ty(self, t) + fn visit_expr_post(&mut self, _ex: &Expr) {} + fn visit_ty(&mut self, t: &'v Ty) { + walk_ty(self, t) } - fn visit_generics(&mut self, g: &Generics) { - walk_generics(self, g) + fn visit_generics(&mut self, g: &'v Generics) { + walk_generics(self, g) } - - - fn visit_mac(&mut self, _mac: &Mac) { - //panic!("visit_mac disabled by default"); - - // NB: see note about macros above. - // if you really want a visitor that - // works on macros, use this - // definition in your trait impl: - // visit::walk_mac(self, _mac) - } - fn visit_path(&mut self, path: &Path, _id: NodeId) { + fn visit_path(&mut self, path: &'v Path, _id: NodeId) { walk_path(self, path) } - fn visit_path_list_item(&mut self, prefix: &Path, item: &PathListItem) { - walk_path_list_item(self, prefix, item) - } - fn visit_path_segment(&mut self, path_span: Span, path_segment: &PathSegment) { + fn visit_path_segment(&mut self, path_span: Span, path_segment: &'v PathSegment) { walk_path_segment(self, path_span, path_segment) } - fn visit_path_parameters(&mut self, path_span: Span, path_parameters: &PathParameters) { - walk_path_parameters(self, path_span, path_parameters) - } - fn visit_assoc_type_binding(&mut self, type_binding: &TypeBinding) { - walk_assoc_type_binding(self, type_binding) - } - fn visit_attribute(&mut self, _attr: &Attribute) { - } - fn visit_macro_def(&mut self, macro_def: &MacroDef) { - walk_macro_def(self, macro_def) - } - - fn visit_vis(&mut self, vis: &Visibility) { + fn visit_attribute(&mut self, _attr: &Attribute) {} + fn visit_vis(&mut self, vis: &'v Visibility) { walk_vis(self, vis) } } - - #[test] fn tests_describe_structure() { - - use std::rc::Rc; use std::cell::RefCell; - use parse_describe; - use token_writer::TokenWriter; - use util::tests::*; - + use std::rc::Rc; - fn test_describe_structure(source : &str, expected : &str) { + use crate::parse_describe; + use crate::token_writer::TokenWriter; + use crate::util::tests::*; + + fn test_describe_structure(source: &str, expected: &str) { let stringRc = Rc::new(RefCell::new(String::new())); - + { let (messages, elements) = parse_describe::parse_crate_with_messages(source); - - let mut tokenWriter = TokenWriter { out : stringRc.clone() }; + + let mut tokenWriter = TokenWriter { out: stringRc.clone() }; parse_describe::write_parse_analysis_contents(messages, elements, &mut tokenWriter).ok().unwrap(); } - - let expected : &str = &(String::from("MESSAGES {\n}") + - (if expected.is_empty() { "" } else { "\n" }) + expected); - + + let expected: &str = &(String::from("MESSAGES {\n}") + (if expected.is_empty() { "" } else { "\n" }) + expected); + let result = unwrap_Rc_RefCell(stringRc); let result = result.trim(); check_equal(result, expected); } - + test_describe_structure("extern crate xx;", r#"ExternCrate { "xx" { 0:0 0:16 } {} "" {} }"#); - + test_describe_structure("const xx : u32 = 1;", r#"Var { "xx" { 0:0 0:19 } {} "u32" {} }"#); - - + test_describe_structure("mod myMod ; ", r#"Mod { "myMod" { 0:0 0:13 } {} "" {} }"#); test_describe_structure("mod myMod { }", r#"Mod { "myMod" { 0:0 0:13 } {} "" {} }"#); - test_describe_structure("mod myMod { static xx : u32 = 2; }", -r#"Mod { "myMod" { 0:0 0:34 } {} "" {} + test_describe_structure( + "mod myMod { static xx : u32 = 2; }", + r#"Mod { "myMod" { 0:0 0:34 } {} "" {} Var { "xx" { 0:12 0:32 } {} "u32" {} } -}"# +}"#, ); - + test_describe_structure("fn xx() { }", r#"Function { "xx" { 0:0 0:11 } {} "()" {} }"#); - test_describe_structure("fn xx(a : &str) -> u32 { }", - r#"Function { "xx" { 0:0 0:26 } {} "(&str) -> u32" {} }"#); - test_describe_structure("fn xx(blah : Vec, x : &'v str) -> u32 { }", - r#"Function { "xx" { 0:0 0:46 } {} "(Vec, &'v str) -> u32" {} }"#); + test_describe_structure("fn xx(a : &str) -> u32 { }", r#"Function { "xx" { 0:0 0:26 } {} "(&str) -> u32" {} }"#); + test_describe_structure("fn xx(blah : Vec, x : &'v str) -> u32 { }", r#"Function { "xx" { 0:0 0:46 } {} "(Vec, &'v str) -> u32" {} }"#); // Test "deceiving" case - test_describe_structure("fn xx(my_self : &str) -> u32 { }", - r#"Function { "xx" { 0:0 0:32 } {} "(&str) -> u32" {} }"#); - + test_describe_structure("fn xx(my_self : &str) -> u32 { }", r#"Function { "xx" { 0:0 0:32 } {} "(&str) -> u32" {} }"#); + test_describe_structure("type MyType = &u32;", r#"TypeAlias { "MyType" { 0:0 0:24 } {} "" {} }"#); - - test_describe_structure("enum MyEnum { Alpha, Beta, } ", -r#"Enum { "MyEnum" { 0:0 0:28 } {} "" {} + + test_describe_structure( + "enum MyEnum { Alpha, Beta, } ", + r#"Enum { "MyEnum" { 0:0 0:28 } {} "" {} EnumVariant { "Alpha" { 0:14 0:19 } {} "" {} } EnumVariant { "Beta" { 0:21 0:25 } {} "" {} } -}"#); - test_describe_structure("enum MyEnum { Alpha(T), Beta(U), } ", -r#"Enum { "MyEnum" { 0:0 0:40 } {} "" {} +}"#, + ); + test_describe_structure( + "enum MyEnum { Alpha(T), Beta(U), } ", + r#"Enum { "MyEnum" { 0:0 0:40 } {} "" {} EnumVariant { "Alpha" { 0:20 0:28 } {} "" {} } EnumVariant { "Beta" { 0:30 0:37 } {} "" {} } -}"#); - - - test_describe_structure("struct MyStruct ( u32, blah ); ", -r#"Struct { "MyStruct" { 0:0 0:35 } {} "" {} }"#); - test_describe_structure("struct MyStruct { foo : u32, } ", -r#"Struct { "MyStruct" { 0:0 0:30 } {} "" {} +}"#, + ); + + test_describe_structure("struct MyStruct ( u32, blah ); ", r#"Struct { "MyStruct" { 0:0 0:35 } {} "" {} }"#); + test_describe_structure( + "struct MyStruct { foo : u32, } ", + r#"Struct { "MyStruct" { 0:0 0:30 } {} "" {} Var { "foo" { 0:18 0:27 } {} "" {} } -}"#); - test_describe_structure("union MyUnion { foo : u32, } ", -r#"Union { "MyUnion" { 0:0 0:28 } {} "" {} +}"#, + ); + test_describe_structure( + "union MyUnion { foo : u32, } ", + r#"Union { "MyUnion" { 0:0 0:28 } {} "" {} Var { "foo" { 0:16 0:25 } {} "" {} } -}"#); - +}"#, + ); + test_describe_structure("trait MyTrait { } ", r#"Trait { "MyTrait" { 0:0 0:17 } {} "" {} }"#); - test_describe_structure("trait MyTrait : Foo { fn xxx(); } ", -r#"Trait { "MyTrait" { 0:0 0:33 } {} "" {} + test_describe_structure( + "trait MyTrait : Foo { fn xxx(); } ", + r#"Trait { "MyTrait" { 0:0 0:33 } {} "" {} Function { "xxx" { 0:22 0:31 } {} "()" {} } -}"#); - test_describe_structure("trait MyTrait : Foo { type N: fmt::Display; fn xxx(&self); const foo :u32 = 3; } ", -r#"Trait { "MyTrait" { 0:0 0:80 } {} "" {} +}"#, + ); + test_describe_structure( + "trait MyTrait : Foo { type N: fmt::Display; fn xxx(&self); const foo :u32 = 3; } ", + r#"Trait { "MyTrait" { 0:0 0:80 } {} "" {} TypeAlias { "N" { 0:22 0:43 } {} "" {} } Function { "xxx" { 0:44 0:58 } {} "(&self)" {} } Var { "foo" { 0:59 0:78 } {} "" {} } -}"#); - +}"#, + ); + /* FIXME: review test_describe_structure("impl MyType { } ", r#"Impl { "MyType" { 0:0 0:15 } {} "" {} }"#); test_describe_structure("impl MyTrait for MyType { } ", r#"Impl { "MyType.MyTrait" { 0:0 0:27 } {} "" {} }"#); @@ -619,42 +505,41 @@ r#"Impl { "MyTrait" { 0:0 0:75 } {} "" {} Var { "foo" { 0:54 0:73 } {} "" {} } }"#); */ - - + test_describe_structure("use blah;", r#"Use { "blah" { 0:0 0:9 } {} "" {} }"#); test_describe_structure("use blah as foo;", r#"Use { "blah as foo" { 0:0 0:16 } {} "" {} }"#); // TODO: this is not printing the global path prefix, seems to be a limitation from libsyntax? test_describe_structure("use ::blah::foo as myfoo;", r#"Use { "::blah::foo as myfoo" { 0:0 0:25 } {} "" {} }"#); test_describe_structure("use ::blah::foo::*;", r#"Use { "::blah::foo::*" { 0:0 0:19 } {} "" {} }"#); - test_describe_structure("use blah::foo:: { One as OtherOne, self as Two };", - r#"Use { "blah::foo::{ One as OtherOne, self as Two, }" { 0:0 0:49 } {} "" {} }"#); - - + test_describe_structure("use blah::foo:: { One as OtherOne, self as Two };", r#"Use { "blah::foo::{ One as OtherOne, self as Two, }" { 0:0 0:49 } {} "" {} }"#); + test_describe_structure("my_macro!(asf); ", ""); - - // test: visit_mac! visit method + + // test: visit_mac! visit method test_describe_structure("fn foo() { my_macro!(asf); }", r#"Function { "foo" { 0:0 0:28 } {} "()" {} }"#); - + test_describe_structure("macro_rules! foo { (x => $e:expr) => (); }", r#""#); // TODO: macro definitions, unfortunately can't get that info easily from syntax_syntex -// test_describe_structure("macro_rules! five_times { ($x:expr) => (5 * $x); }", -// r#"Macro { "foo" { 0:0 0:28 } {} "" {} }"#); - + // test_describe_structure("macro_rules! five_times { ($x:expr) => (5 * $x); }", + // r#"Macro { "foo" { 0:0 0:28 } {} "" {} }"#); + // Test pub extern - test_describe_structure("pub extern crate my_crate;", - r#"ExternCrate { "my_crate" { 0:0 0:26 } {} "" {} }"# - ); - - test_describe_structure("extern { fn ext(p : u32); }", -r#"Mod { "" { 0:0 0:27 } {} "" {} + test_describe_structure("pub extern crate my_crate;", r#"ExternCrate { "my_crate" { 0:0 0:26 } {} "" {} }"#); + + test_describe_structure( + "extern { fn ext(p : u32); }", + r#"Mod { "" { 0:0 0:27 } {} "" {} Function { "ext" { 0:9 0:25 } {} "" {} } -}"#); - test_describe_structure("extern { fn ext(p : u32); \n static extVar: u8; }", -r#"Mod { "" { 0:0 1:21 } {} "" {} +}"#, + ); + test_describe_structure( + "extern { fn ext(p : u32); \n static extVar: u8; }", + r#"Mod { "" { 0:0 1:21 } {} "" {} Function { "ext" { 0:9 0:25 } {} "" {} } Var { "extVar" { 1:1 1:19 } {} "" {} } -}"#); - - // Test with a lexer error, -// test_describe_structure("const xx : u32 = '", r#"Var { "xx" { 1 0 1 19 } {} {} {} }"#); -} \ No newline at end of file +}"#, + ); + + // Test with a lexer error, + // test_describe_structure("const xx : u32 = '", r#"Var { "xx" { 1 0 1 19 } {} {} {} }"#); +} diff --git a/src/token_writer.rs b/src/token_writer.rs index 188b9c7..5f2ccd0 100644 --- a/src/token_writer.rs +++ b/src/token_writer.rs @@ -12,76 +12,66 @@ // See the License for the specific language governing permissions and // limitations under the License. -use util::core::*; +use crate::util::core::*; -use std::result; use std::fmt; +use std::result; -pub use std::cell::{ RefCell , RefMut }; -pub use std::rc::{ Rc }; +pub use std::cell::{RefCell, RefMut}; +pub use std::rc::Rc; /// Write a parse structure into a serialized format pub struct TokenWriter { - pub out : Rc>, + pub out: Rc>, } impl fmt::Debug for TokenWriter { - - fn fmt(&self, fmt : &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { fmt.write_str("[TokenWriter]") } - } impl TokenWriter { - - pub fn get_output(&self) -> RefMut { + pub fn get_output(&self) -> RefMut { self.out.borrow_mut() } - - pub fn write_raw(&mut self, string : &str) -> result::Result<(), fmt::Error> { + + pub fn write_raw(&mut self, string: &str) -> result::Result<(), fmt::Error> { self.get_output().write_str(string) } - - pub fn write_string_token(&mut self, string : &str) -> result::Result<(), fmt::Error> { - try!(write_escaped_string(string, &mut* self.get_output())); - + + pub fn write_string_token(&mut self, string: &str) -> result::Result<(), fmt::Error> { + write_escaped_string(string, &mut *self.get_output())?; + self.get_output().write_char(' ') } - - pub fn write_raw_token(&mut self, string : &str) -> Void { - + + pub fn write_raw_token(&mut self, string: &str) -> Void { for ch in string.chars() { - if ch.is_whitespace() - || ch == '{' || ch == '}' - || ch == '(' || ch == ')' - || ch == '[' || ch == ']' - { + if ch.is_whitespace() || ch == '{' || ch == '}' || ch == '(' || ch == ')' || ch == '[' || ch == ']' { return Err("Cannot write raw token".into()); } } - - try!(self.get_output().write_str(string)); - try!(self.get_output().write_char(' ')); - + + self.get_output().write_str(string)?; + self.get_output().write_char(' ')?; + Ok(()) } - } #[test] fn test__write_raw_token() { - - fn write_raw_token_toString(string : &str) -> GResult { - let outRc : Rc> = Rc::new(RefCell::new(String::new())); - + fn write_raw_token_toString(string: &str) -> GResult { + let outRc: Rc> = Rc::new(RefCell::new(String::new())); + let result = TokenWriter { out: outRc.clone() }.write_raw_token(string); match result { Ok(_) => Ok(unwrap_Rc_RefCell(outRc)), Err(error) => Err(error), } } - + assert_eq!(write_raw_token_toString("blah").ok().unwrap(), r#"blah "#); write_raw_token_toString("bl ah").unwrap_err(); write_raw_token_toString("bl{ah").unwrap_err(); @@ -89,38 +79,32 @@ fn test__write_raw_token() { /* ----------------- some parser/serialize utils ----------------- */ -pub fn write_escaped_string(string : &str, out : &mut OUT) - -> fmt::Result +pub fn write_escaped_string(string: &str, out: &mut OUT) -> fmt::Result //pub fn write_string_token>(string : &str, out : &mut OUT) -// -> result::Result<(), ERR> +// -> result::Result<(), ERR> { - - try!(out.write_char('"')); - + out.write_char('"')?; + for ch in string.chars() { - if ch == '"' || ch == '\\' { - try!(out.write_char('\\')); + out.write_char('\\')?; } - try!(out.write_char(ch)); - + out.write_char(ch)?; } - - try!(out.write_char('"')); - + + out.write_char('"')?; + Ok(()) } - #[test] fn test__write_escaped_string() { - - fn write_string_token_toString(string : &str) -> String { + fn write_string_token_toString(string: &str) -> String { let mut result = String::new(); write_escaped_string(string, &mut result).unwrap(); result } - + assert_eq!(write_string_token_toString(""), r#""""#); assert_eq!(write_string_token_toString("abc"), r#""abc""#); assert_eq!(write_string_token_toString(r#"-"-"#), r#""-\"-""#); @@ -128,4 +112,4 @@ fn test__write_escaped_string() { assert_eq!(write_string_token_toString(r#"\"#), r#""\\""#); assert_eq!(write_string_token_toString(r#"--\"-"#), r#""--\\\"-""#); assert_eq!(write_string_token_toString(r#"---\"#), r#""---\\""#); -} \ No newline at end of file +}