From patchwork Sun Oct 8 22:58:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Malcolm X-Patchwork-Id: 149781 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:a888:0:b0:403:3b70:6f57 with SMTP id x8csp1560204vqo; Sun, 8 Oct 2023 16:00:52 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFwYD71Jc41aQ+D4r+HcyO/net/2HWmNDp5Ov45891SMHPgjiZGOmFRgu/8Dm/DNzixbVUG X-Received: by 2002:a17:906:29a:b0:9b2:b750:4a67 with SMTP id 26-20020a170906029a00b009b2b7504a67mr12863707ejf.67.1696806052093; Sun, 08 Oct 2023 16:00:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696806052; cv=none; d=google.com; s=arc-20160816; b=uE70ZpajypX84zXa8Pg41FBkKB/mtnbNiJZXSsWQtdLNMqEf0wVW2yqtcuJbHJ5itA V075whkNHhBQzXCEw/AhcKwLsErUJdRY0RzVDWF+7JbuzMYQOtrh7u+AMqy4X1HkrT7k LCbDRxEH6r4FqQKtoHVGmGHvrgbH6WCZ6OS8ubnWfktKWeCyOAN3jeIV1H1xzYQQ1hvG qSXzOZhWq80XIMiUxyCSAjwMSapRCDm6ZYFtNjDMKjGlapQ9dWUbxueeUyh+Ank8uwIa bk3D7DoHICRoHCC7lLy2Y8EdsVUtGDDkAmVWi2UBRrNlbAwjHoV8T0zx5ZLAjAw0gSNi 0Bpg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:message-id:date:subject:cc:to:from:dkim-signature :dmarc-filter:delivered-to; bh=xudFF+aLPvJv9nOq/bpgobRH1K58RQ68qrqnq4vbwXM=; fh=NXemEfxTRbZtBxUkxR2ehQUaYlcDfMdzPkO8MChVQE4=; b=A/KN2t35kPsq+Gw5iZ5JO7K7TGTJQ2Wrq2GHEZWCjKVYkOrEzW62U9n/sE3ki87FlB 8ZLQ1/1Xrway4ZnQlXw24W05K0l4Flv7VBIakIriPtXy/TC96Gyo4ohofCpjHSPPal+L 0H/3DBJlLGxIcL+upLgIZgPtDPjVaJ7WQ68nvyJzSPj0zy9W7R1Xhjnb08WiYawX+0tX IVqy23hN6ghEZjC18zKmoN7MkJmlah/KyiVeEpZl3VsxsweQ5xD0fNI6Bg/r8TEyUhQf IfdxtCNfPIv3OsgIHaxifW0u3hdO2Xdu3kNJoPOV44hg6mmyWUwHFEmFIGIofPUBtaAI X9jg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="gtA//p4V"; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from server2.sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id sd22-20020a170906ce3600b009b9581342e8si4090590ejb.969.2023.10.08.16.00.51 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 08 Oct 2023 16:00:52 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="gtA//p4V"; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id BDD4D386190F for ; Sun, 8 Oct 2023 22:59:33 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id 7FD62385841D for ; Sun, 8 Oct 2023 22:58:53 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 7FD62385841D Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1696805933; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=xudFF+aLPvJv9nOq/bpgobRH1K58RQ68qrqnq4vbwXM=; b=gtA//p4Vp2IG4zUybxHLVmlrlhm2LiJ7Z1zFUcwb6SpHfuRJXCASVfBADHcVdOf1xpmBEr EyHrpjAXg53yauaYJPAQ73ZoMx+zKdFZsBDaJCcfZSFgq5YfxuDfyAPbJMSx260iNAvFY1 cneafgUUldnC/E8i/6TBfUXYl1IgAuE= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-116-vrSuVa7zOy2pAeAvN7EXFg-1; Sun, 08 Oct 2023 18:58:51 -0400 X-MC-Unique: vrSuVa7zOy2pAeAvN7EXFg-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 6242E101A529 for ; Sun, 8 Oct 2023 22:58:51 +0000 (UTC) Received: from t14s.localdomain.com (unknown [10.22.18.119]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0C29D170E4; Sun, 8 Oct 2023 22:58:49 +0000 (UTC) From: David Malcolm To: gcc-patches@gcc.gnu.org Cc: David Malcolm Subject: [pushed] libcpp: eliminate COMBINE_LOCATION_DATA Date: Sun, 8 Oct 2023 18:58:48 -0400 Message-Id: <20231008225848.783654-1-dmalcolm@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.5 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-11.4 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1779230102805239891 X-GMAIL-MSGID: 1779230102805239891 This patch eliminates the function "COMBINE_LOCATION_DATA" (which hasn't been a macro since r6-739-g0501dbd932a7e9) and the function "get_combined_adhoc_loc" in favor of a new line_maps::get_or_create_combined_loc member function. No functional change intended. Successfully bootstrapped & regrtested on x86_64-pc-linux-gnu. Pushed to trunk as r14-4476-g1f68a3e8727f36. gcc/cp/ChangeLog: * module.cc (module_state::read_location): Update for renaming of get_combined_adhoc_loc. gcc/ChangeLog: * genmatch.cc (main): Update for "m_" prefix of some fields of line_maps. * input.cc (make_location): Update for removal of COMBINE_LOCATION_DATA. (dump_line_table_statistics): Update for "m_" prefix of some fields of line_maps. (location_with_discriminator): Update for removal of COMBINE_LOCATION_DATA. (line_table_test::line_table_test): Update for "m_" prefix of some fields of line_maps. * toplev.cc (general_init): Likewise. * tree.cc (set_block): Update for removal of COMBINE_LOCATION_DATA. (set_source_range): Likewise. libcpp/ChangeLog: * include/line-map.h (line_maps::reallocator): Rename to... (line_maps::m_reallocator): ...this. (line_maps::round_alloc_size): Rename to... (line_maps::m_round_alloc_size): ...this. (line_maps::location_adhoc_data_map): Rename to... (line_maps::m_location_adhoc_data_map): ...this. (line_maps::num_optimized_ranges): Rename to... (line_maps::m_num_optimized_ranges): ..this. (line_maps::num_unoptimized_ranges): Rename to... (line_maps::m_num_unoptimized_ranges): ...this. (get_combined_adhoc_loc): Delete decl. (COMBINE_LOCATION_DATA): Delete. * lex.cc (get_location_for_byte_range_in_cur_line): Update for removal of COMBINE_LOCATION_DATA. (warn_about_normalization): Likewise. (_cpp_lex_direct): Likewise. * line-map.cc (line_maps::~line_maps): Update for "m_" prefix of some fields of line_maps. (rebuild_location_adhoc_htab): Likewise. (can_be_stored_compactly_p): Convert to... (line_maps::can_be_stored_compactly_p): ...this private member function. (get_combined_adhoc_loc): Convert to... (line_maps::get_or_create_combined_loc): ...this public member function. (line_maps::make_location): Update for removal of COMBINE_LOCATION_DATA. (get_data_from_adhoc_loc): Update for "m_" prefix of some fields of line_maps. (get_discriminator_from_adhoc_loc): Likewise. (get_location_from_adhoc_loc): Likewise. (get_range_from_adhoc_loc): Convert to... (line_maps::get_range_from_adhoc_loc): ...this private member function. (line_maps::get_range_from_loc): Update for conversion of get_range_from_adhoc_loc to a member function. (linemap_init): Update for "m_" prefix of some fields of line_maps. (line_map_new_raw): Likewise. (linemap_enter_macro): Likewise. (linemap_get_statistics): Likewise. --- gcc/cp/module.cc | 3 +- gcc/genmatch.cc | 4 +- gcc/input.cc | 26 ++++---- gcc/toplev.cc | 4 +- gcc/tree.cc | 12 ++-- libcpp/include/line-map.h | 40 ++++++------ libcpp/lex.cc | 20 +++--- libcpp/line-map.cc | 128 ++++++++++++++++++-------------------- 8 files changed, 118 insertions(+), 119 deletions(-) diff --git a/gcc/cp/module.cc b/gcc/cp/module.cc index 77c9edcbc04..e3fb2299d93 100644 --- a/gcc/cp/module.cc +++ b/gcc/cp/module.cc @@ -15969,7 +15969,8 @@ module_state::read_location (bytes_in &sec) const range.m_finish = read_location (sec); unsigned discriminator = sec.u (); if (locus != loc && range.m_start != loc && range.m_finish != loc) - locus = get_combined_adhoc_loc (line_table, locus, range, NULL, discriminator); + locus = line_table->get_or_create_combined_loc (locus, range, + nullptr, discriminator); } break; diff --git a/gcc/genmatch.cc b/gcc/genmatch.cc index 03d325efdf6..e9d7afa7728 100644 --- a/gcc/genmatch.cc +++ b/gcc/genmatch.cc @@ -5458,8 +5458,8 @@ main (int argc, char **argv) line_table = XCNEW (class line_maps); linemap_init (line_table, 0); - line_table->reallocator = xrealloc; - line_table->round_alloc_size = round_alloc_size; + line_table->m_reallocator = xrealloc; + line_table->m_round_alloc_size = round_alloc_size; r = cpp_create_reader (CLK_GNUC99, NULL, line_table); cpp_callbacks *cb = cpp_get_callbacks (r); diff --git a/gcc/input.cc b/gcc/input.cc index a0e7cb17455..fd09fccb0e3 100644 --- a/gcc/input.cc +++ b/gcc/input.cc @@ -1231,7 +1231,8 @@ location_t make_location (location_t caret, source_range src_range) { location_t pure_loc = get_pure_location (caret); - return COMBINE_LOCATION_DATA (line_table, pure_loc, src_range, NULL, 0); + return line_table->get_or_create_combined_loc (pure_loc, src_range, + nullptr, 0); } /* An expanded_location stores the column in byte units. This function @@ -1313,9 +1314,9 @@ dump_line_table_statistics (void) fprintf (stderr, "Ad-hoc table entries used: " PRsa (5) "\n", SIZE_AMOUNT (s.adhoc_table_entries_used)); fprintf (stderr, "optimized_ranges: " PRsa (5) "\n", - SIZE_AMOUNT (line_table->num_optimized_ranges)); + SIZE_AMOUNT (line_table->m_num_optimized_ranges)); fprintf (stderr, "unoptimized_ranges: " PRsa (5) "\n", - SIZE_AMOUNT (line_table->num_unoptimized_ranges)); + SIZE_AMOUNT (line_table->m_num_unoptimized_ranges)); fprintf (stderr, "\n"); } @@ -1917,7 +1918,8 @@ location_with_discriminator (location_t locus, int discriminator) if (locus == UNKNOWN_LOCATION) return locus; - return COMBINE_LOCATION_DATA (line_table, locus, src_range, block, discriminator); + return line_table->get_or_create_combined_loc (locus, src_range, block, + discriminator); } /* Return TRUE if LOCUS represents a location with a discriminator. */ @@ -2099,10 +2101,10 @@ line_table_test::line_table_test () saved_line_table = line_table; line_table = ggc_alloc (); linemap_init (line_table, BUILTINS_LOCATION); - gcc_assert (saved_line_table->reallocator); - line_table->reallocator = saved_line_table->reallocator; - gcc_assert (saved_line_table->round_alloc_size); - line_table->round_alloc_size = saved_line_table->round_alloc_size; + gcc_assert (saved_line_table->m_reallocator); + line_table->m_reallocator = saved_line_table->m_reallocator; + gcc_assert (saved_line_table->m_round_alloc_size); + line_table->m_round_alloc_size = saved_line_table->m_round_alloc_size; line_table->default_range_bits = 0; } @@ -2115,10 +2117,10 @@ line_table_test::line_table_test (const line_table_case &case_) saved_line_table = line_table; line_table = ggc_alloc (); linemap_init (line_table, BUILTINS_LOCATION); - gcc_assert (saved_line_table->reallocator); - line_table->reallocator = saved_line_table->reallocator; - gcc_assert (saved_line_table->round_alloc_size); - line_table->round_alloc_size = saved_line_table->round_alloc_size; + gcc_assert (saved_line_table->m_reallocator); + line_table->m_reallocator = saved_line_table->m_reallocator; + gcc_assert (saved_line_table->m_round_alloc_size); + line_table->m_round_alloc_size = saved_line_table->m_round_alloc_size; line_table->default_range_bits = case_.m_default_range_bits; if (case_.m_base_location) { diff --git a/gcc/toplev.cc b/gcc/toplev.cc index 626cc435c8b..8af9bf5090e 100644 --- a/gcc/toplev.cc +++ b/gcc/toplev.cc @@ -1082,8 +1082,8 @@ general_init (const char *argv0, bool init_signals) input_location = UNKNOWN_LOCATION; line_table = ggc_alloc (); linemap_init (line_table, BUILTINS_LOCATION); - line_table->reallocator = realloc_for_line_map; - line_table->round_alloc_size = ggc_round_alloc_size; + line_table->m_reallocator = realloc_for_line_map; + line_table->m_round_alloc_size = ggc_round_alloc_size; line_table->default_range_bits = 5; init_ttree (); diff --git a/gcc/tree.cc b/gcc/tree.cc index 54ca5e750df..850a4dec022 100644 --- a/gcc/tree.cc +++ b/gcc/tree.cc @@ -14505,7 +14505,8 @@ set_block (location_t loc, tree block) location_t pure_loc = get_pure_location (loc); source_range src_range = get_range_from_loc (line_table, loc); unsigned discriminator = get_discriminator_from_loc (line_table, loc); - return COMBINE_LOCATION_DATA (line_table, pure_loc, src_range, block, discriminator); + return line_table->get_or_create_combined_loc (pure_loc, src_range, block, + discriminator); } location_t @@ -14526,11 +14527,10 @@ set_source_range (tree expr, source_range src_range) location_t expr_location = EXPR_LOCATION (expr); location_t pure_loc = get_pure_location (expr_location); unsigned discriminator = get_discriminator_from_loc (expr_location); - location_t adhoc = COMBINE_LOCATION_DATA (line_table, - pure_loc, - src_range, - NULL, - discriminator); + location_t adhoc = line_table->get_or_create_combined_loc (pure_loc, + src_range, + nullptr, + discriminator); SET_EXPR_LOCATION (expr, adhoc); return adhoc; } diff --git a/libcpp/include/line-map.h b/libcpp/include/line-map.h index 9e1b11da194..b353df45209 100644 --- a/libcpp/include/line-map.h +++ b/libcpp/include/line-map.h @@ -802,7 +802,21 @@ public: location_t make_location (location_t caret, location_t start, location_t finish); - + + location_t + get_or_create_combined_loc (location_t locus, + source_range src_range, + void *data, + unsigned discriminator); + + private: + bool can_be_stored_compactly_p (location_t locus, + source_range src_range, + void *data, + unsigned discriminator) const; + source_range get_range_from_adhoc_loc (location_t loc) const; + + public: maps_info_ordinary info_ordinary; maps_info_macro info_macro; @@ -827,13 +841,13 @@ public: unsigned int max_column_hint; /* The allocator to use when resizing 'maps', defaults to xrealloc. */ - line_map_realloc GTY((callback)) reallocator; + line_map_realloc GTY((callback)) m_reallocator; /* The allocators' function used to know the actual size it allocated, for a certain allocation size requested. */ - line_map_round_alloc_size_func GTY((callback)) round_alloc_size; + line_map_round_alloc_size_func GTY((callback)) m_round_alloc_size; - struct location_adhoc_data_map location_adhoc_data_map; + struct location_adhoc_data_map m_location_adhoc_data_map; /* The special location value that is used as spelling location for built-in tokens. */ @@ -842,8 +856,8 @@ public: /* The default value of range_bits in ordinary line maps. */ unsigned int default_range_bits; - unsigned int num_optimized_ranges; - unsigned int num_unoptimized_ranges; + unsigned int m_num_optimized_ranges; + unsigned int m_num_unoptimized_ranges; }; /* Returns the number of allocated maps so far. MAP_KIND shall be TRUE @@ -1052,8 +1066,6 @@ LINEMAPS_LAST_ALLOCATED_MACRO_MAP (const line_maps *set) return (line_map_macro *)LINEMAPS_LAST_ALLOCATED_MAP (set, true); } -extern location_t get_combined_adhoc_loc (line_maps *, location_t, - source_range, void *, unsigned); extern void *get_data_from_adhoc_loc (const line_maps *, location_t); extern unsigned get_discriminator_from_adhoc_loc (const line_maps *, location_t); extern location_t get_location_from_adhoc_loc (const line_maps *, @@ -1073,18 +1085,6 @@ pure_location_p (const line_maps *set, location_t loc); extern location_t get_pure_location (const line_maps *set, location_t loc); -/* Combine LOC and BLOCK, giving a combined adhoc location. */ - -inline location_t -COMBINE_LOCATION_DATA (class line_maps *set, - location_t loc, - source_range src_range, - void *block, - unsigned discriminator) -{ - return get_combined_adhoc_loc (set, loc, src_range, block, discriminator); -} - extern void rebuild_location_adhoc_htab (class line_maps *); /* Initialize a line map set. SET is the line map set to initialize diff --git a/libcpp/lex.cc b/libcpp/lex.cc index 8dea4d3d4eb..ce8ff614dd6 100644 --- a/libcpp/lex.cc +++ b/libcpp/lex.cc @@ -1362,11 +1362,11 @@ get_location_for_byte_range_in_cur_line (cpp_reader *pfile, source_range src_range; src_range.m_start = start_loc; src_range.m_finish = end_loc; - location_t combined_loc = COMBINE_LOCATION_DATA (pfile->line_table, - start_loc, - src_range, - NULL, - 0); + location_t combined_loc + = pfile->line_table->get_or_create_combined_loc (start_loc, + src_range, + nullptr, + 0); return combined_loc; } @@ -2032,8 +2032,8 @@ warn_about_normalization (cpp_reader *pfile, = linemap_position_for_column (pfile->line_table, CPP_BUF_COLUMN (pfile->buffer, pfile->buffer->cur)); - loc = COMBINE_LOCATION_DATA (pfile->line_table, - loc, tok_range, NULL, 0); + loc = pfile->line_table->get_or_create_combined_loc (loc, tok_range, + nullptr, 0); } encoding_rich_location rich_loc (pfile, loc); @@ -4333,9 +4333,9 @@ _cpp_lex_direct (cpp_reader *pfile) = linemap_position_for_column (pfile->line_table, CPP_BUF_COLUMN (buffer, buffer->cur)); - result->src_loc = COMBINE_LOCATION_DATA (pfile->line_table, - result->src_loc, - tok_range, NULL, 0); + result->src_loc + = pfile->line_table->get_or_create_combined_loc (result->src_loc, + tok_range, nullptr, 0); } return result; diff --git a/libcpp/line-map.cc b/libcpp/line-map.cc index 8b9f3e33688..5b67a70429f 100644 --- a/libcpp/line-map.cc +++ b/libcpp/line-map.cc @@ -53,8 +53,8 @@ extern unsigned num_macro_tokens_counter; line_maps::~line_maps () { - if (location_adhoc_data_map.htab) - htab_delete (location_adhoc_data_map.htab); + if (m_location_adhoc_data_map.htab) + htab_delete (m_location_adhoc_data_map.htab); } /* Hash function for location_adhoc_data hashtable. */ @@ -109,14 +109,14 @@ location_adhoc_data_update (void **slot_v, void *param_v) void rebuild_location_adhoc_htab (line_maps *set) { - set->location_adhoc_data_map.htab = + set->m_location_adhoc_data_map.htab = htab_create (100, location_adhoc_data_hash, location_adhoc_data_eq, NULL); - for (auto p = set->location_adhoc_data_map.data, - end = p + set->location_adhoc_data_map.curr_loc; + for (auto p = set->m_location_adhoc_data_map.data, + end = p + set->m_location_adhoc_data_map.curr_loc; p != end; ++p) { const auto slot = reinterpret_cast - (htab_find_slot (set->location_adhoc_data_map.htab, p, INSERT)); + (htab_find_slot (set->m_location_adhoc_data_map.htab, p, INSERT)); *slot = p; } } @@ -125,12 +125,11 @@ rebuild_location_adhoc_htab (line_maps *set) Can the given LOCUS + SRC_RANGE and DATA pointer be stored compactly within a location_t, without needing to use an ad-hoc location. */ -static bool -can_be_stored_compactly_p (const line_maps *set, - location_t locus, - source_range src_range, - void *data, - unsigned discriminator) +bool +line_maps::can_be_stored_compactly_p (location_t locus, + source_range src_range, + void *data, + unsigned discriminator) const { /* If there's an ad-hoc pointer, we can't store it directly in the location_t, we need the lookaside. */ @@ -156,7 +155,7 @@ can_be_stored_compactly_p (const line_maps *set, /* All 3 locations must be within ordinary maps, typically, the same ordinary map. */ - location_t lowest_macro_loc = LINEMAPS_MACRO_LOWEST_LOCATION (set); + location_t lowest_macro_loc = LINEMAPS_MACRO_LOWEST_LOCATION (this); if (locus >= lowest_macro_loc) return false; if (src_range.m_start >= lowest_macro_loc) @@ -171,17 +170,16 @@ can_be_stored_compactly_p (const line_maps *set, /* Combine LOCUS and DATA to a combined adhoc loc. */ location_t -get_combined_adhoc_loc (line_maps *set, - location_t locus, - source_range src_range, - void *data, - unsigned discriminator) +line_maps::get_or_create_combined_loc (location_t locus, + source_range src_range, + void *data, + unsigned discriminator) { struct location_adhoc_data lb; struct location_adhoc_data **slot; if (IS_ADHOC_LOC (locus)) - locus = get_location_from_adhoc_loc (set, locus); + locus = get_location_from_adhoc_loc (this, locus); if (locus == 0 && data == NULL) return 0; @@ -189,22 +187,22 @@ get_combined_adhoc_loc (line_maps *set, compressed ranges. */ linemap_assert (locus < RESERVED_LOCATION_COUNT || locus >= LINE_MAP_MAX_LOCATION_WITH_PACKED_RANGES - || locus >= LINEMAPS_MACRO_LOWEST_LOCATION (set) - || pure_location_p (set, locus)); + || locus >= LINEMAPS_MACRO_LOWEST_LOCATION (this) + || pure_location_p (locus)); /* Consider short-range optimization. */ - if (can_be_stored_compactly_p (set, locus, src_range, data, discriminator)) + if (can_be_stored_compactly_p (locus, src_range, data, discriminator)) { /* The low bits ought to be clear. */ - linemap_assert (pure_location_p (set, locus)); - const line_map *map = linemap_lookup (set, locus); + linemap_assert (pure_location_p (locus)); + const line_map *map = linemap_lookup (this, locus); const line_map_ordinary *ordmap = linemap_check_ordinary (map); unsigned int int_diff = src_range.m_finish - src_range.m_start; unsigned int col_diff = (int_diff >> ordmap->m_range_bits); if (col_diff < (1U << ordmap->m_range_bits)) { location_t packed = locus | col_diff; - set->num_optimized_ranges++; + m_num_optimized_ranges++; return packed; } } @@ -217,47 +215,47 @@ get_combined_adhoc_loc (line_maps *set, return locus; if (!data && discriminator == 0) - set->num_unoptimized_ranges++; + m_num_unoptimized_ranges++; lb.locus = locus; lb.src_range = src_range; lb.data = data; lb.discriminator = discriminator; slot = (struct location_adhoc_data **) - htab_find_slot (set->location_adhoc_data_map.htab, &lb, INSERT); + htab_find_slot (m_location_adhoc_data_map.htab, &lb, INSERT); if (*slot == NULL) { - if (set->location_adhoc_data_map.curr_loc >= - set->location_adhoc_data_map.allocated) + if (m_location_adhoc_data_map.curr_loc >= + m_location_adhoc_data_map.allocated) { - const auto orig_data = set->location_adhoc_data_map.data; + const auto orig_data = m_location_adhoc_data_map.data; /* Cast away extern "C" from the type of xrealloc. */ - line_map_realloc reallocator = (set->reallocator - ? set->reallocator + line_map_realloc reallocator = (m_reallocator + ? m_reallocator : (line_map_realloc) xrealloc); - if (set->location_adhoc_data_map.allocated == 0) - set->location_adhoc_data_map.allocated = 128; + if (m_location_adhoc_data_map.allocated == 0) + m_location_adhoc_data_map.allocated = 128; else - set->location_adhoc_data_map.allocated *= 2; - set->location_adhoc_data_map.data = (struct location_adhoc_data *) - reallocator (set->location_adhoc_data_map.data, - set->location_adhoc_data_map.allocated + m_location_adhoc_data_map.allocated *= 2; + m_location_adhoc_data_map.data = (struct location_adhoc_data *) + reallocator (m_location_adhoc_data_map.data, + m_location_adhoc_data_map.allocated * sizeof (struct location_adhoc_data)); - if (set->location_adhoc_data_map.allocated > 128) + if (m_location_adhoc_data_map.allocated > 128) { location_adhoc_data *param[2] - = {orig_data, set->location_adhoc_data_map.data}; - htab_traverse (set->location_adhoc_data_map.htab, + = {orig_data, m_location_adhoc_data_map.data}; + htab_traverse (m_location_adhoc_data_map.htab, location_adhoc_data_update, param); } } - *slot = set->location_adhoc_data_map.data - + set->location_adhoc_data_map.curr_loc; - set->location_adhoc_data_map.data[set->location_adhoc_data_map.curr_loc++] + *slot = m_location_adhoc_data_map.data + + m_location_adhoc_data_map.curr_loc; + m_location_adhoc_data_map.data[m_location_adhoc_data_map.curr_loc++] = lb; } - return ((*slot) - set->location_adhoc_data_map.data) | 0x80000000; + return ((*slot) - m_location_adhoc_data_map.data) | 0x80000000; } /* Construct a location with caret at CARET, ranging from START to @@ -283,11 +281,10 @@ line_maps::make_location (location_t caret, location_t start, location_t finish) source_range src_range; src_range.m_start = get_start (start); src_range.m_finish = get_finish (finish); - location_t combined_loc = COMBINE_LOCATION_DATA (this, - pure_loc, - src_range, - NULL, - 0); + location_t combined_loc = get_or_create_combined_loc (pure_loc, + src_range, + nullptr, + 0); return combined_loc; } @@ -297,14 +294,14 @@ void * get_data_from_adhoc_loc (const line_maps *set, location_t loc) { linemap_assert (IS_ADHOC_LOC (loc)); - return set->location_adhoc_data_map.data[loc & MAX_LOCATION_T].data; + return set->m_location_adhoc_data_map.data[loc & MAX_LOCATION_T].data; } unsigned get_discriminator_from_adhoc_loc (const line_maps *set, location_t loc) { linemap_assert (IS_ADHOC_LOC (loc)); - return set->location_adhoc_data_map.data[loc & MAX_LOCATION_T].discriminator; + return set->m_location_adhoc_data_map.data[loc & MAX_LOCATION_T].discriminator; } /* Return the location for the adhoc loc. */ @@ -313,16 +310,16 @@ location_t get_location_from_adhoc_loc (const line_maps *set, location_t loc) { linemap_assert (IS_ADHOC_LOC (loc)); - return set->location_adhoc_data_map.data[loc & MAX_LOCATION_T].locus; + return set->m_location_adhoc_data_map.data[loc & MAX_LOCATION_T].locus; } /* Return the source_range for adhoc location LOC. */ -static source_range -get_range_from_adhoc_loc (const line_maps *set, location_t loc) +source_range +line_maps::get_range_from_adhoc_loc (location_t loc) const { linemap_assert (IS_ADHOC_LOC (loc)); - return set->location_adhoc_data_map.data[loc & MAX_LOCATION_T].src_range; + return m_location_adhoc_data_map.data[loc & MAX_LOCATION_T].src_range; } /* Get the source_range of location LOC, either from the ad-hoc @@ -332,7 +329,7 @@ source_range line_maps::get_range_from_loc (location_t loc) const { if (IS_ADHOC_LOC (loc)) - return get_range_from_adhoc_loc (this, loc); + return get_range_from_adhoc_loc (loc); /* For ordinary maps, extract packed range. */ if (loc >= RESERVED_LOCATION_COUNT @@ -433,10 +430,10 @@ linemap_init (line_maps *set, new (set) line_maps(); #endif /* Set default reallocator (used for initial alloc too). */ - set->reallocator = xrealloc; + set->m_reallocator = xrealloc; set->highest_location = RESERVED_LOCATION_COUNT - 1; set->highest_line = RESERVED_LOCATION_COUNT - 1; - set->location_adhoc_data_map.htab = + set->m_location_adhoc_data_map.htab = htab_create (100, location_adhoc_data_hash, location_adhoc_data_eq, NULL); set->builtin_location = builtin_location; } @@ -502,13 +499,13 @@ line_map_new_raw (line_maps *set, bool macro_p, unsigned num) allocator may well be larger than what we ask for. Use this hook to find what that size is. */ size_t alloc_size - = set->round_alloc_size (num_maps_allocated * size_of_a_map); + = set->m_round_alloc_size (num_maps_allocated * size_of_a_map); /* Now alloc_size contains the exact memory size we would get if we have asked for the initial alloc_size amount of memory. Let's get back to the number of map that amounts to. */ unsigned num_maps = alloc_size / size_of_a_map; - buffer = set->reallocator (buffer, num_maps * size_of_a_map); + buffer = set->m_reallocator (buffer, num_maps * size_of_a_map); memset ((char *)buffer + num_maps_used * size_of_a_map, 0, (num_maps - num_maps_used) * size_of_a_map); if (macro_p) @@ -783,9 +780,8 @@ linemap_enter_macro (class line_maps *set, struct cpp_hashnode *macro_node, map->macro = macro_node; map->n_tokens = num_tokens; map->macro_locations - = (location_t*) set->reallocator (NULL, - 2 * num_tokens - * sizeof (location_t)); + = (location_t*) set->m_reallocator (nullptr, + 2 * num_tokens * sizeof (location_t)); map->expansion = expansion; memset (MACRO_MAP_LOCATIONS (map), 0, 2 * num_tokens * sizeof (location_t)); @@ -2115,9 +2111,9 @@ linemap_get_statistics (const line_maps *set, s->macro_maps_used_size = macro_maps_used_size; s->duplicated_macro_maps_locations_size = duplicated_macro_maps_locations_size; - s->adhoc_table_size = (set->location_adhoc_data_map.allocated + s->adhoc_table_size = (set->m_location_adhoc_data_map.allocated * sizeof (struct location_adhoc_data)); - s->adhoc_table_entries_used = set->location_adhoc_data_map.curr_loc; + s->adhoc_table_entries_used = set->m_location_adhoc_data_map.curr_loc; }