From patchwork Tue Oct 15 12:02:02 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nathan Sidwell X-Patchwork-Id: 1176975 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-511010-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=acm.org Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="Thqa0wVP"; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="qGM+NLnL"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 46svDy17Hlz9sP6 for ; Tue, 15 Oct 2019 23:02:24 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:to :from:subject:message-id:date:mime-version:content-type; q=dns; s=default; b=Y2FsX+aq3xGNei6+tdJKdO+5c5YHBgf0Lg+Mc/BH1AlihTg8UU RVyLTXZqhoompcV4OYgoAsLGxJC71u/iUc2kpKD4BJ6l2w/+CXzHcu731nLZZ0Ai g/wOKvmh3vbSq3grT7wxvsxIoHKjI9JL6RGpDPZ+3xYv+CKtabhtaz21o= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:to :from:subject:message-id:date:mime-version:content-type; s= default; bh=99hbXXpeNmVlZ07ZE+fYEA99I0w=; b=Thqa0wVPTRU+17uj3WLl CYK3UEu2YHR2+9MGhNB9/ejursMdYPO5mEblL3LNDPiWzKidhMeeDac5RPns+W/W f0QydPRWJoioQfvDF84AuFLk5S282BxTuPG3qGwBKga4NvH8M7kyctfq4cWk1AlC allKJTGuqn6JIKUPW0LJFoM= Received: (qmail 70558 invoked by alias); 15 Oct 2019 12:02:17 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 70547 invoked by uid 89); 15 Oct 2019 12:02:17 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-16.1 required=5.0 tests=BAYES_00, FREEMAIL_FROM, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_ASCII_DIVIDERS, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.1 spammy=lin, maps X-HELO: mail-qk1-f170.google.com Received: from mail-qk1-f170.google.com (HELO mail-qk1-f170.google.com) (209.85.222.170) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 15 Oct 2019 12:02:11 +0000 Received: by mail-qk1-f170.google.com with SMTP id f16so18856433qkl.9 for ; Tue, 15 Oct 2019 05:02:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:to:from:subject:message-id:date:user-agent:mime-version :content-language; bh=SOCs9+1nxG9wviTw1nk2Jy4xAdZ4ZI/bAODfBtlsPOs=; b=qGM+NLnLeEkn3GwrYMNJe+v8rxtp8RQhe4gEkXn7OelYCL45YlIPH2GNd9AOlexfwj HwqNasVs7n0ODSi74Vd64stS4/DnjyyhiP2PuTGdJqVrNc7m10vC0TzPwbJI6AEZ7O6m cnkYngVqQeocBIeu8t6AtWkE+7qc5gV4LNrhb63JHjc+mD2L65qKRpo6lICYEB1nmpJh HDh7EnEgzjJLURiB+XLLaK22knYsOOYnN99eiCu3zft1rtJUIT7oGtV9Q4p7Bhz0+cgo uE8caAhyT6Rorop7Z4Ix4VQpyylqPdpBPemDaPiW1TEehvl30elGROjh/VZQwmn/KZMT pzVw== Received: from ?IPv6:2620:10d:c0a3:1407:f888:8672:b7f1:b6cf? ([2620:10d:c091:500::1:ca40]) by smtp.googlemail.com with ESMTPSA id t199sm9438118qke.36.2019.10.15.05.02.03 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 15 Oct 2019 05:02:03 -0700 (PDT) To: GCC Patches From: Nathan Sidwell Subject: [linemap PATCH] Constify lookup Message-ID: Date: Tue, 15 Oct 2019 08:02:02 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.1.1 MIME-Version: 1.0 looking up a line map takes a non-constant line_maps object, which is confusing. This makes the caching fields mutable, so permits a constant object, as one might expect for a lookup. The linemaps_info_{ordinary,macro} structures are crying out to be templatized, but that kind of turns into a rathole cleaning up the C-era accessors and like. I punted. committing to trunk nathan 2019-10-15 Nathan Sidwell * include/line-map.h (struct maps_info_ordinary): Make cache mutable. (struct maps_info_macro): Likewise. (LINEMAPS_CACHE): Remove non-ref accessor. Constify ref accessor. (LINEMAPS_ORDINARY_CACHE, LINEMAPS_MACRO_CACHE): Likewise. (LINEMAPS_ORDINARY_MAP_AT, LINEMAPS_MACRO_MAP_AT): Use LINEMAPS_USED and LINEMAPS_MAP_AT. (linemap_lookup): Constify line_map arg. linemap.c (linemap_ordinary_map_lookup, linemap_macro_map_lookup): Constify line_map arg. Index: include/line-map.h =================================================================== --- include/line-map.h (revision 276991) +++ include/line-map.h (working copy) @@ -725,5 +725,5 @@ struct GTY(()) maps_info_ordinary { unsigned int used; - unsigned int cache; + mutable unsigned int cache; }; @@ -740,5 +740,5 @@ struct GTY(()) maps_info_macro { unsigned int used; - unsigned int cache; + mutable unsigned int cache; }; @@ -866,17 +866,6 @@ LINEMAPS_USED (line_maps *set, bool map_ linemap_lookup. MAP_KIND shall be TRUE if we are interested in macro maps, FALSE otherwise. */ -inline unsigned int -LINEMAPS_CACHE (const line_maps *set, bool map_kind) -{ - if (map_kind) - return set->info_macro.cache; - else - return set->info_ordinary.cache; -} - -/* As above, but by reference (e.g. as an lvalue). */ - inline unsigned int & -LINEMAPS_CACHE (line_maps *set, bool map_kind) +LINEMAPS_CACHE (const line_maps *set, bool map_kind) { if (map_kind) @@ -928,7 +917,7 @@ inline line_map_ordinary * LINEMAPS_ORDINARY_MAP_AT (const line_maps *set, int index) { - linemap_assert (index >= 0); - linemap_assert ((unsigned int)index < set->info_ordinary.used); - return &set->info_ordinary.maps[index]; + linemap_assert (index >= 0 + && (unsigned int)index < LINEMAPS_USED (set, false)); + return (line_map_ordinary *)LINEMAPS_MAP_AT (set, false, index); } @@ -950,14 +939,6 @@ LINEMAPS_ORDINARY_USED (const line_maps /* Return the index of the last ordinary map that was looked up with linemap_lookup. */ -inline unsigned int -LINEMAPS_ORDINARY_CACHE (const line_maps *set) -{ - return LINEMAPS_CACHE (set, false); -} - -/* As above, but by reference (e.g. as an lvalue). */ - inline unsigned int & -LINEMAPS_ORDINARY_CACHE (line_maps *set) +LINEMAPS_ORDINARY_CACHE (const line_maps *set) { return LINEMAPS_CACHE (set, false); @@ -992,7 +973,7 @@ inline line_map_macro * LINEMAPS_MACRO_MAP_AT (const line_maps *set, int index) { - linemap_assert (index >= 0); - linemap_assert ((unsigned int)index < set->info_macro.used); - return &set->info_macro.maps[index]; + linemap_assert (index >= 0 + && (unsigned int)index < LINEMAPS_USED (set, true)); + return (line_map_macro *)LINEMAPS_MAP_AT (set, true, index); } @@ -1012,16 +993,8 @@ LINEMAPS_MACRO_USED (const line_maps *se } -/* Returns the index of the last macro map looked up with +/* Return the index of the last macro map that was looked up with linemap_lookup. */ -inline unsigned int -LINEMAPS_MACRO_CACHE (const line_maps *set) -{ - return LINEMAPS_CACHE (set, true); -} - -/* As above, but by reference (e.g. as an lvalue). */ - inline unsigned int & -LINEMAPS_MACRO_CACHE (line_maps *set) +LINEMAPS_MACRO_CACHE (const line_maps *set) { return LINEMAPS_CACHE (set, true); @@ -1131,5 +1104,5 @@ extern const line_map *linemap_add function returns NULL. */ extern const line_map *linemap_lookup - (class line_maps *, location_t); + (const line_maps *, location_t); /* Returns TRUE if the line table set tracks token locations across Index: line-map.c =================================================================== --- line-map.c (revision 276991) +++ line-map.c (working copy) @@ -28,7 +28,7 @@ along with this program; see the file CO static void trace_include (const line_maps *, const line_map_ordinary *); -static const line_map_ordinary * linemap_ordinary_map_lookup (line_maps *, +static const line_map_ordinary * linemap_ordinary_map_lookup (const line_maps *, location_t); -static const line_map_macro* linemap_macro_map_lookup (line_maps *, +static const line_map_macro* linemap_macro_map_lookup (const line_maps *, location_t); static location_t linemap_macro_map_loc_to_def_point @@ -938,5 +938,5 @@ linemap_position_for_loc_and_offset (lin const struct line_map* -linemap_lookup (line_maps *set, location_t line) +linemap_lookup (const line_maps *set, location_t line) { if (IS_ADHOC_LOC (line)) @@ -953,5 +953,5 @@ linemap_lookup (line_maps *set, location static const line_map_ordinary * -linemap_ordinary_map_lookup (line_maps *set, location_t line) +linemap_ordinary_map_lookup (const line_maps *set, location_t line) { unsigned int md, mn, mx; @@ -966,5 +966,5 @@ linemap_ordinary_map_lookup (line_maps * mn = LINEMAPS_ORDINARY_CACHE (set); mx = LINEMAPS_ORDINARY_USED (set); - + cached = LINEMAPS_ORDINARY_MAP_AT (set, mn); /* We should get a segfault if no line_maps have been added yet. */ @@ -1001,5 +1001,5 @@ linemap_ordinary_map_lookup (line_maps * static const line_map_macro * -linemap_macro_map_lookup (line_maps *set, location_t line) +linemap_macro_map_lookup (const line_maps *set, location_t line) { unsigned int md, mn, mx;