From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1643) id B3FC03857B81; Tue, 9 Aug 2022 20:38:44 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B3FC03857B81 Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Thomas Schwinge To: gcc-cvs@gcc.gnu.org Subject: [gcc/devel/rust/master] session-manager: Produce a fatal error if multiple files are specified X-Act-Checkin: gcc X-Git-Author: Arthur Cohen X-Git-Refname: refs/heads/devel/rust/master X-Git-Oldrev: 237be3f618dfae396944c601c295eb182d32e54e X-Git-Newrev: 0ec8f938272b6dce9e133f98a199fd5123aa553f Message-Id: <20220809203844.B3FC03857B81@sourceware.org> Date: Tue, 9 Aug 2022 20:38:44 +0000 (GMT) X-BeenThere: gcc-cvs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 09 Aug 2022 20:38:44 -0000 https://gcc.gnu.org/g:0ec8f938272b6dce9e133f98a199fd5123aa553f commit 0ec8f938272b6dce9e133f98a199fd5123aa553f Author: Arthur Cohen Date: Thu Jul 28 16:53:50 2022 +0200 session-manager: Produce a fatal error if multiple files are specified Diff: --- gcc/rust/rust-lang.cc | 36 ++---------------------------------- gcc/rust/rust-session-manager.cc | 23 +++++++++++------------ gcc/rust/rust-session-manager.h | 4 ++-- 3 files changed, 15 insertions(+), 48 deletions(-) diff --git a/gcc/rust/rust-lang.cc b/gcc/rust/rust-lang.cc index dd8c608789a..95c92f8092b 100644 --- a/gcc/rust/rust-lang.cc +++ b/gcc/rust/rust-lang.cc @@ -69,13 +69,11 @@ // Language-dependent contents of a type. GTY() mark used for garbage collector. struct GTY (()) lang_type { - char dummy; }; // Language-dependent contents of a decl. struct GTY (()) lang_decl { - char dummy; }; // Language-dependent contents of an identifier. This must include a @@ -100,7 +98,6 @@ union GTY (( // We don't use language_function. struct GTY (()) language_function { - int dummy; }; // has to be in same compilation unit as session, so here for now @@ -172,7 +169,7 @@ grs_langhook_parse_file (void) { rust_debug ("Preparing to parse files. "); - Rust::Session::get_instance ().parse_files (num_in_fnames, in_fnames); + Rust::Session::get_instance ().handle_input_files (num_in_fnames, in_fnames); } /* Seems to get the exact type for a specific type - e.g. for scalar float with @@ -280,32 +277,10 @@ grs_langhook_handle_option ( { // Convert integer code to lang.opt enum codes with names. enum opt_code code = (enum opt_code) scode; - // used to store whether results of various stuff are successful - // bool ret = true; - // delegate to session manager + // Delegate to session manager return Rust::Session::get_instance ().handle_option (code, arg, value, kind, loc, handlers); - - // Handles options as listed in lang.opt. - /*switch (code) { - case OPT_I: - // TODO: add search path - break; - case OPT_L: - // TODO: add library link path or something - break; - case OPT_frust_dump: - // enable dump and return whether this was successful - ret = rust_enable_dump(arg) ? true : false; - break; - // no option handling for -o - default: - // return 1 to indicate option is valid - break; - } - - return ret;*/ } /* Run after parsing options. */ @@ -447,17 +422,10 @@ rust_localize_identifier (const char *ident) namespace selftest { -static void -simple_assert () -{ - ASSERT_TRUE (true); -} - void run_rust_tests () { // Call tests for the rust frontend here - simple_assert (); rust_cfg_parser_test (); rust_privacy_ctx_test (); rust_crate_name_validation_test (); diff --git a/gcc/rust/rust-session-manager.cc b/gcc/rust/rust-session-manager.cc index 6a2c1b6dd62..a7317247e07 100644 --- a/gcc/rust/rust-session-manager.cc +++ b/gcc/rust/rust-session-manager.cc @@ -574,13 +574,16 @@ Session::enable_dump (std::string arg) /* Actual main entry point for front-end. Called from langhook to parse files. */ void -Session::parse_files (int num_files, const char **files) +Session::handle_input_files (int num_files, const char **files) { + if (num_files != 1) + rust_fatal_error (Location (), + "only one file may be specified on the command line"); + + const auto &file = files[0]; + if (options.crate_name.empty ()) { - /* HACK: We use the first file to infer the crate name, which might be - * incorrect: since rustc only allows one file to be supplied in the - * command-line */ auto filename = "-"; if (num_files > 0) filename = files[0]; @@ -594,13 +597,9 @@ Session::parse_files (int num_files, const char **files) CrateNum crate_num = mappings->get_next_crate_num (options.get_crate_name ()); mappings->set_current_crate (crate_num); - for (int i = 0; i < num_files; i++) - { - rust_debug ("Attempting to parse file: %s", files[i]); - parse_file (files[i]); - } - /* TODO: should semantic analysis be dealed with here? or per file? for now, - * per-file. */ + + rust_debug ("Attempting to parse file: %s", file); + compile_crate (file); } void @@ -656,7 +655,7 @@ Session::handle_crate_name (const AST::Crate &parsed_crate) // Parses a single file with filename filename. void -Session::parse_file (const char *filename) +Session::compile_crate (const char *filename) { RAIIFile file_wrap (filename); if (!file_wrap.ok ()) diff --git a/gcc/rust/rust-session-manager.h b/gcc/rust/rust-session-manager.h index 24a15f55393..2432de70592 100644 --- a/gcc/rust/rust-session-manager.h +++ b/gcc/rust/rust-session-manager.h @@ -298,7 +298,7 @@ public: bool handle_option (enum opt_code code, const char *arg, HOST_WIDE_INT value, int kind, location_t loc, const struct cl_option_handlers *handlers); - void parse_files (int num_files, const char **files); + void handle_input_files (int num_files, const char **files); void init_options (); void handle_crate_name (const AST::Crate &parsed_crate); @@ -314,7 +314,7 @@ public: NodeId load_extern_crate (const std::string &crate_name, Location locus); private: - void parse_file (const char *filename); + void compile_crate (const char *filename); bool enable_dump (std::string arg); void dump_lex (Parser &parser) const;