From patchwork Thu Mar 13 01:14:17 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Malcolm X-Patchwork-Id: 107805 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 8F3443858427 for ; Thu, 13 Mar 2025 01:15:10 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 8F3443858427 Authentication-Results: sourceware.org; dkim=pass (1024-bit key, unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=d9K5kOce 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 ESMTP id 2E8D13858D33 for ; Thu, 13 Mar 2025 01:14:26 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 2E8D13858D33 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 2E8D13858D33 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1741828466; cv=none; b=NEnuSFbDUct6IIjQfzTUSzJBi8+DhwLxyByvaEC/PNecQjWqmtwFS6QeXSBXGDvAm6nTXgnRewu4By4kt8tMYPefwG5GlAzYNoBUiE9lef9N9RnmrpU9E3AWI5NlhgeMwxJlVOTdzA6i0D1YiSj++uXYSZa3JuqMCg2fvOKTYFw= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1741828466; c=relaxed/simple; bh=H5bfvDhmvHu+CQ//3A/chySBYfZcThGcXnHmwF9VIDQ=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=ruPua67f2Ng6xw/+xCYykH26HW7wevdEnpsdaFuOS0ID1hJAalVWCMT44Rdyow9FkSOhSkXDEzV5ZUBtHk1ExBRslLiojvvAYkuAlOJY73UmCG/uBjorGxe7WJiW2qTtDress8U7j+CvpGPVSwInqn8SuZvIwPmLS5827ZfaMqo= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 2E8D13858D33 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1741828465; 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: in-reply-to:in-reply-to:references:references; bh=SEVOwfTk3iMOQ2DPlvmw4WBwF1NQeKLZK2/lpGDGmSM=; b=d9K5kOceupUxAbxUyw+6UmINAFBYaqGSL5+bc7OWX+2Tg9WjICyFsPsEc3uQ0DVeLAKIrZ Ys9ZU5yFdVsnv+8nN/B23M7cOkrxJx7TqvYiV+MGfRy4Vc+YHh3Qklf1e7sv1pvvcFtR4x eSml+rsI3AzFRSEpU9laHmvLgJ0ZTKM= Received: from mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-594-H5Nu42zuMhWwMcyI0_ZIJA-1; Wed, 12 Mar 2025 21:14:22 -0400 X-MC-Unique: H5Nu42zuMhWwMcyI0_ZIJA-1 X-Mimecast-MFC-AGG-ID: H5Nu42zuMhWwMcyI0_ZIJA_1741828461 Received: from mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.40]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 1DF8F1956050; Thu, 13 Mar 2025 01:14:21 +0000 (UTC) Received: from t14s.localdomain.com (unknown [10.22.82.122]) by mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id D449019560AD; Thu, 13 Mar 2025 01:14:19 +0000 (UTC) From: David Malcolm To: gcc-patches@gcc.gnu.org, "James K . Lowden" , Robert Dubner Cc: David Malcolm Subject: [PATCH v2] cobol: capture source ranges for tokens, rather than just points (v2) Date: Wed, 12 Mar 2025 21:14:17 -0400 Message-ID: <20250313011417.1964184-1-dmalcolm@redhat.com> In-Reply-To: <20250311154722.1782308-1-dmalcolm@redhat.com> References: <20250311154722.1782308-1-dmalcolm@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.40 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: Db42YHSGfZXqSrNQCeEFrlRr7hKrrGfCaTwu9MQs7eg_1741828461 X-Mimecast-Originator: redhat.com content-type: text/plain; charset="US-ASCII"; x-default=true X-Spam-Status: No, score=-11.6 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_H2, 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~patchwork=sourceware.org@gcc.gnu.org Here's an updated version of this patch which adds a testcase to the DejaGnu test suite, using *<< and *>> for a multiline comment (used to express a fragment of the expected output on stderr). Successfully bootstrapped & regrtested on x86_64-pc-linux-gnu, but I *haven't* tested this patch with the NIST testsuite. OK for trunk? Blurb follows: This patch changes the output on the simple test I tried from: $ ./gcobol -B. hello.cob -S hello.cob:2:8: error: syntax error, unexpected NAME, expecting FUNCTION or PROGRAM-ID 2 | porgram-id. hello. | ^ cobol1: error: failed compiling hello.cob to: $ ./gcobol -B. hello.cob -S hello.cob:2:8: error: syntax error, unexpected NAME, expecting FUNCTION or PROGRAM-ID 2 | porgram-id. hello. | ^~~~~~~~~~~ cobol1: error: failed compiling hello.cob gcc/cobol/ChangeLog: * util.cc (gcc_location_set_impl): Capture the start and end of "loc" as a range, rather than just the (last_line, first_column). gcc/testsuite/ChangeLog: * cobol.dg/typo-1.cob: New test. --- gcc/cobol/util.cc | 16 ++++++++++++++-- gcc/testsuite/cobol.dg/typo-1.cob | 15 +++++++++++++++ 2 files changed, 29 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/cobol.dg/typo-1.cob diff --git a/gcc/cobol/util.cc b/gcc/cobol/util.cc index 6ade146b5dda..aba4a1003554 100644 --- a/gcc/cobol/util.cc +++ b/gcc/cobol/util.cc @@ -1857,11 +1857,23 @@ cobol_filename_restore() { static location_t token_location; +/* Update global token_location with a location_t expressing a source + range with start and caret at the first line/column of LOC, and + finishing at the last line/column of LOC. */ + template static void gcc_location_set_impl( const LOC& loc ) { - token_location = linemap_line_start( line_table, loc.last_line, 80 ); - token_location = linemap_position_for_column( line_table, loc.first_column); + const location_t start_line + = linemap_line_start( line_table, loc.first_line, 80 ); + const location_t token_start + = linemap_position_for_column( line_table, loc.first_column); + const location_t finish_line + = linemap_line_start( line_table, loc.last_line, 80 ); + const location_t token_finish + = linemap_position_for_column( line_table, loc.last_column); + token_location + = make_location (token_start, token_start, token_finish); location_dump(__func__, __LINE__, "parser", loc); } diff --git a/gcc/testsuite/cobol.dg/typo-1.cob b/gcc/testsuite/cobol.dg/typo-1.cob new file mode 100644 index 000000000000..a806863db190 --- /dev/null +++ b/gcc/testsuite/cobol.dg/typo-1.cob @@ -0,0 +1,15 @@ +*> { dg-options "-fdiagnostics-show-caret" } +*> { dg-do compile } + + identification division. + porgram-id. hello. *> { dg-error "8: syntax error, unexpected NAME, expecting FUNCTION or PROGRAM-ID" } + procedure division. + display "Hello World!". + stop run. + +*<< +{ dg-begin-multiline-output "" } + porgram-id. hello. + ^~~~~~~~~~~ +{ dg-end-multiline-output "" } +*>>