From patchwork Sun Sep 12 06:32:58 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: 64544 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 EAB7AB70A8 for ; Sun, 12 Sep 2010 16:33:12 +1000 (EST) Received: (qmail 26278 invoked by alias); 12 Sep 2010 06:33:10 -0000 Received: (qmail 26269 invoked by uid 22791); 12 Sep 2010 06:33:09 -0000 X-SWARE-Spam-Status: No, hits=-2.2 required=5.0 tests=AWL, BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, SPF_HELO_PASS, TW_CC, 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) (216.239.44.51) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Sun, 12 Sep 2010 06:33:04 +0000 Received: from wpaz5.hot.corp.google.com (wpaz5.hot.corp.google.com [172.24.198.69]) by smtp-out.google.com with ESMTP id o8C6X2Jx019379 for ; Sat, 11 Sep 2010 23:33:02 -0700 Received: from pxi7 (pxi7.prod.google.com [10.243.27.7]) by wpaz5.hot.corp.google.com with ESMTP id o8C6X1cj024080 for ; Sat, 11 Sep 2010 23:33:01 -0700 Received: by pxi7 with SMTP id 7so4637807pxi.11 for ; Sat, 11 Sep 2010 23:33:00 -0700 (PDT) Received: by 10.142.233.16 with SMTP id f16mr1743553wfh.339.1284273180828; Sat, 11 Sep 2010 23:33:00 -0700 (PDT) Received: from coign.google.com (adsl-71-133-8-30.dsl.pltn13.pacbell.net [71.133.8.30]) by mx.google.com with ESMTPS id t11sm6299240wfc.10.2010.09.11.23.32.59 (version=TLSv1/SSLv3 cipher=RC4-MD5); Sat, 11 Sep 2010 23:33:00 -0700 (PDT) From: Ian Lance Taylor To: gcc-patches@gcc.gnu.org, gofrontend-dev@googlegroups.com Subject: [gccgo] Support //line comments Date: Sat, 11 Sep 2010 23:32:58 -0700 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 By convention, a Go comment of the form //line FILE:LINENO is the equivalent of a C #line comment. This patch implements that for gccgo. Committed to gccgo branch. Ian diff -r 54b04d338c19 go/lex.cc --- a/go/lex.cc Fri Sep 10 16:18:13 2010 -0700 +++ b/go/lex.cc Sat Sep 11 23:29:35 2010 -0700 @@ -448,7 +448,6 @@ Lex::~Lex() { delete[] this->linebuf_; - linemap_add(line_table, LC_LEAVE, 0, NULL, 0); } // Read a new line from the file. @@ -1579,6 +1578,44 @@ { const char* p = this->linebuf_ + this->lineoff_; const char* pend = this->linebuf_ + this->linesize_; + + // By convention, a C++ comment at the start of the line of the form + // //line FILE:LINENO + // is interpreted as setting the file name and line number of the + // next source line. + + if (this->lineoff_ == 2 + && pend - p > 5 + && memcmp(p, "line ", 5) == 0) + { + p += 5; + while (p < pend && *p == ' ') + ++p; + const char* pcolon = static_cast(memchr(p, ':', pend - p)); + if (pcolon != NULL + && pcolon[1] >= '0' + && pcolon[1] <= '9') + { + char* plend; + long lineno = strtol(pcolon + 1, &plend, 10); + if (plend > pcolon + 1 + && (plend == pend + || *plend < '0' + || *plend > '9')) + { + unsigned int filelen = pcolon - p; + char* file = new char[filelen + 1]; + memcpy(file, p, filelen); + file[filelen] = '\0'; + + linemap_add(line_table, LC_ENTER, 0, file, lineno); + this->lineno_ = lineno - 1; + + p = plend; + } + } + } + while (p < pend) { this->lineoff_ = p - this->linebuf_;