From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from gnu.wildebeest.org (wildebeest.demon.nl [212.238.236.112]) by sourceware.org (Postfix) with ESMTPS id 341DE3857C48 for ; Sun, 4 Jul 2021 22:10:24 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 341DE3857C48 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=klomp.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=klomp.org Received: from reform (deer0x01.wildebeest.org [172.31.17.131]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by gnu.wildebeest.org (Postfix) with ESMTPSA id DF8DE302FBA7; Mon, 5 Jul 2021 00:10:22 +0200 (CEST) Received: by reform (Postfix, from userid 1000) id C7C132E80FB4; Mon, 5 Jul 2021 00:10:22 +0200 (CEST) From: Mark Wielaard To: gcc-rust@gcc.gnu.org Cc: Mark Wielaard Subject: [PATCH 2/2] Remove has_shebang flag from AST and HIR Crate classes Date: Mon, 5 Jul 2021 00:09:59 +0200 Message-Id: <20210704220959.85580-3-mark@klomp.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210704220959.85580-1-mark@klomp.org> References: <20210704220959.85580-1-mark@klomp.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-10.8 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gcc-rust@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: gcc-rust mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 04 Jul 2021 22:10:27 -0000 The lexer deals with the shebang and the parser cannot detect whether there is or isn't a shebang line. The flag isn't relevant or useful in the AST and HIR Crate classes. --- gcc/rust/ast/rust-ast-full-test.cc | 5 +---- gcc/rust/ast/rust-ast.h | 13 +++++-------- gcc/rust/hir/rust-ast-lower.cc | 3 +-- gcc/rust/hir/tree/rust-hir-full-test.cc | 6 +----- gcc/rust/hir/tree/rust-hir.h | 14 +++++--------- gcc/rust/parse/rust-parse-impl.h | 12 +++++------- 6 files changed, 18 insertions(+), 35 deletions(-) diff --git a/gcc/rust/ast/rust-ast-full-test.cc b/gcc/rust/ast/rust-ast-full-test.cc index 3d339ad1aed..12ef255bcbf 100644 --- a/gcc/rust/ast/rust-ast-full-test.cc +++ b/gcc/rust/ast/rust-ast-full-test.cc @@ -172,13 +172,10 @@ Crate::as_string () const rust_debug ("beginning crate recursive as-string"); std::string str ("Crate: "); - // add utf8bom and shebang + // add utf8bom if (has_utf8bom) str += "\n has utf8bom"; - if (has_shebang) - str += "\n has shebang"; - // inner attributes str += append_attributes (inner_attrs, INNER); diff --git a/gcc/rust/ast/rust-ast.h b/gcc/rust/ast/rust-ast.h index 0e25de2be5c..ce55e1beb5e 100644 --- a/gcc/rust/ast/rust-ast.h +++ b/gcc/rust/ast/rust-ast.h @@ -1551,7 +1551,6 @@ protected: struct Crate { bool has_utf8bom; - bool has_shebang; std::vector inner_attrs; // dodgy spacing required here @@ -1564,17 +1563,16 @@ struct Crate public: // Constructor Crate (std::vector > items, - std::vector inner_attrs, bool has_utf8bom = false, - bool has_shebang = false) - : has_utf8bom (has_utf8bom), has_shebang (has_shebang), - inner_attrs (std::move (inner_attrs)), items (std::move (items)), + std::vector inner_attrs, bool has_utf8bom = false) + : has_utf8bom (has_utf8bom), inner_attrs (std::move (inner_attrs)), + items (std::move (items)), node_id (Analysis::Mappings::get ()->get_next_node_id ()) {} // Copy constructor with vector clone Crate (Crate const &other) - : has_utf8bom (other.has_utf8bom), has_shebang (other.has_shebang), - inner_attrs (other.inner_attrs), node_id (other.node_id) + : has_utf8bom (other.has_utf8bom), inner_attrs (other.inner_attrs), + node_id (other.node_id) { items.reserve (other.items.size ()); for (const auto &e : other.items) @@ -1587,7 +1585,6 @@ public: Crate &operator= (Crate const &other) { inner_attrs = other.inner_attrs; - has_shebang = other.has_shebang; has_utf8bom = other.has_utf8bom; node_id = other.node_id; diff --git a/gcc/rust/hir/rust-ast-lower.cc b/gcc/rust/hir/rust-ast-lower.cc index c7222e2e998..0f3c86dc7bf 100644 --- a/gcc/rust/hir/rust-ast-lower.cc +++ b/gcc/rust/hir/rust-ast-lower.cc @@ -41,7 +41,6 @@ ASTLowering::go () { std::vector > items; bool has_utf8bom = false; - bool has_shebang = false; for (auto it = astCrate.items.begin (); it != astCrate.items.end (); it++) { @@ -57,7 +56,7 @@ ASTLowering::go () UNKNOWN_LOCAL_DEFID); return HIR::Crate (std::move (items), astCrate.get_inner_attrs (), mapping, - has_utf8bom, has_shebang); + has_utf8bom); } // rust-ast-lower-block.h diff --git a/gcc/rust/hir/tree/rust-hir-full-test.cc b/gcc/rust/hir/tree/rust-hir-full-test.cc index 261b3af672a..051ba8736ad 100644 --- a/gcc/rust/hir/tree/rust-hir-full-test.cc +++ b/gcc/rust/hir/tree/rust-hir-full-test.cc @@ -73,15 +73,11 @@ std::string Crate::as_string () const { std::string str ("HIR::Crate: "); - // add utf8bom and shebang + // add utf8bom if (has_utf8bom) { str += "\n has utf8bom"; } - if (has_shebang) - { - str += "\n has shebang"; - } // inner attributes str += "\n inner attributes: "; diff --git a/gcc/rust/hir/tree/rust-hir.h b/gcc/rust/hir/tree/rust-hir.h index 35dc71ae1df..f918f2dc106 100644 --- a/gcc/rust/hir/tree/rust-hir.h +++ b/gcc/rust/hir/tree/rust-hir.h @@ -679,7 +679,6 @@ public: struct Crate { bool has_utf8bom; - bool has_shebang; AST::AttrVec inner_attrs; // dodgy spacing required here @@ -692,17 +691,15 @@ struct Crate public: // Constructor Crate (std::vector > items, AST::AttrVec inner_attrs, - Analysis::NodeMapping mappings, bool has_utf8bom = false, - bool has_shebang = false) - : has_utf8bom (has_utf8bom), has_shebang (has_shebang), - inner_attrs (std::move (inner_attrs)), items (std::move (items)), - mappings (mappings) + Analysis::NodeMapping mappings, bool has_utf8bom = false) + : has_utf8bom (has_utf8bom), inner_attrs (std::move (inner_attrs)), + items (std::move (items)), mappings (mappings) {} // Copy constructor with vector clone Crate (Crate const &other) - : has_utf8bom (other.has_utf8bom), has_shebang (other.has_shebang), - inner_attrs (other.inner_attrs), mappings (other.mappings) + : has_utf8bom (other.has_utf8bom), inner_attrs (other.inner_attrs), + mappings (other.mappings) { items.reserve (other.items.size ()); for (const auto &e : other.items) @@ -715,7 +712,6 @@ public: Crate &operator= (Crate const &other) { inner_attrs = other.inner_attrs; - has_shebang = other.has_shebang; has_utf8bom = other.has_utf8bom; mappings = other.mappings; diff --git a/gcc/rust/parse/rust-parse-impl.h b/gcc/rust/parse/rust-parse-impl.h index 9f8282b3639..136b34371f1 100644 --- a/gcc/rust/parse/rust-parse-impl.h +++ b/gcc/rust/parse/rust-parse-impl.h @@ -393,12 +393,11 @@ template AST::Crate Parser::parse_crate () { - /* TODO: determine if has utf8bom and shebang. Currently, they are eliminated - * by the lexing phase. Neither are useful for the compiler anyway, so maybe a + /* TODO: determine if has utf8bom. Currently, is eliminated + * by the lexing phase. Not useful for the compiler anyway, so maybe a * better idea would be to eliminate - * the has_utf8bom and has_shebang variables from the crate data structure. */ + * the has_utf8bom variable from the crate data structure. */ bool has_utf8bom = false; - bool has_shebang = false; // parse inner attributes AST::AttrVec inner_attrs = parse_inner_attributes (); @@ -430,8 +429,7 @@ Parser::parse_crate () for (const auto &error : error_table) error.emit_error (); - return AST::Crate (std::move (items), std::move (inner_attrs), has_utf8bom, - has_shebang); + return AST::Crate (std::move (items), std::move (inner_attrs), has_utf8bom); } // Parse a contiguous block of inner attributes. @@ -484,7 +482,7 @@ Parser::parse_inner_attribute () if (lexer.peek_token ()->get_id () != EXCLAM) { Error error (lexer.peek_token ()->get_locus (), - "expected % or %<[%> for inner attribute or shebang"); + "expected % or %<[%> for inner attribute"); add_error (std::move (error)); return AST::Attribute::create_empty (); -- 2.32.0