From patchwork Tue Dec 21 18:51:48 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Lance Taylor X-Patchwork-Id: 76315 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) by ozlabs.org (Postfix) with SMTP id BA95BB6F10 for ; Wed, 22 Dec 2010 05:52:10 +1100 (EST) Received: (qmail 21866 invoked by alias); 21 Dec 2010 18:52:03 -0000 Received: (qmail 21848 invoked by uid 22791); 21 Dec 2010 18:52:01 -0000 X-SWARE-Spam-Status: No, hits=-2.9 required=5.0 tests=AWL, BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, SPF_HELO_PASS, T_RP_MATCHES_RCVD, T_TVD_MIME_NO_HEADERS X-Spam-Check-By: sourceware.org Received: from smtp-out.google.com (HELO smtp-out.google.com) (74.125.121.67) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Tue, 21 Dec 2010 18:51:55 +0000 Received: from kpbe18.cbf.corp.google.com (kpbe18.cbf.corp.google.com [172.25.105.82]) by smtp-out.google.com with ESMTP id oBLIpqS8008425 for ; Tue, 21 Dec 2010 10:51:52 -0800 Received: from pzk37 (pzk37.prod.google.com [10.243.19.165]) by kpbe18.cbf.corp.google.com with ESMTP id oBLIpo4M001442 for ; Tue, 21 Dec 2010 10:51:51 -0800 Received: by pzk37 with SMTP id 37so1291806pzk.12 for ; Tue, 21 Dec 2010 10:51:50 -0800 (PST) Received: by 10.142.232.9 with SMTP id e9mr4839533wfh.153.1292957510813; Tue, 21 Dec 2010 10:51:50 -0800 (PST) Received: from coign.google.com (dhcp-172-22-122-207.mtv.corp.google.com [172.22.122.207]) by mx.google.com with ESMTPS id e14sm7914055wfg.8.2010.12.21.10.51.49 (version=TLSv1/SSLv3 cipher=RC4-MD5); Tue, 21 Dec 2010 10:51:50 -0800 (PST) From: Ian Lance Taylor To: gcc-patches@gcc.gnu.org, gofrontend-dev@googlegroups.com Subject: Go patch committed: Correct exponent lexing Date: Tue, 21 Dec 2010 10:51:48 -0800 Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) MIME-Version: 1.0 X-System-Of-Record: true X-IsSubscribed: yes 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 This patch to the Go frontend corrects the lexing of exponents in floating point numbers. An exponent requires at least one decimal digit after an optional sign. Bootstrapped and ran Go testsuite on x86_64-unknown-linux-gnu. Committed to mainline. Ian diff -r 5e30b192004f go/lex.cc --- a/go/lex.cc Tue Dec 21 10:30:04 2010 -0800 +++ b/go/lex.cc Tue Dec 21 10:48:10 2010 -0800 @@ -931,6 +931,25 @@ || (c >= 'a' && c <= 'f')); } +// Return whether an exponent could start at P. + +bool +Lex::could_be_exponent(const char* p, const char* pend) +{ + if (*p != 'e' && *p != 'E') + return false; + ++p; + if (p >= pend) + return false; + if (*p == '+' || *p == '-') + { + ++p; + if (p >= pend) + return false; + } + return *p >= '0' && *p <= '9'; +} + // Pick up a number. Token @@ -980,7 +999,7 @@ } } - if (*p != '.' && *p != 'e' && *p != 'E' && *p != 'i') + if (*p != '.' && *p != 'i' && !Lex::could_be_exponent(p, pend)) { std::string s(pnum, p - pnum); mpz_t val; @@ -1004,7 +1023,7 @@ ++p; } - if (*p != '.' && *p != 'E' && *p != 'e' && *p != 'i') + if (*p != '.' && *p != 'i' && !Lex::could_be_exponent(p, pend)) { std::string s(pnum, p - pnum); mpz_t val; @@ -1039,7 +1058,7 @@ ++p; } - if (dot && (*p == 'E' || *p == 'e')) + if (dot && Lex::could_be_exponent(p, pend)) { ++p; if (*p == '+' || *p == '-') diff -r 5e30b192004f go/lex.h --- a/go/lex.h Tue Dec 21 10:30:04 2010 -0800 +++ b/go/lex.h Tue Dec 21 10:48:10 2010 -0800 @@ -379,6 +379,9 @@ Token gather_identifier(); + static bool + could_be_exponent(const char*, const char*); + Token gather_number();