Tue, 06 May 2014 09:56:55 -0400
8041620: Solaris Studio 12.4 C++ 5.13 change in behavior for placing friend declarations within surrounding scope.
Summary: Remove adlc's unused class FileBuffRegion.
Reviewed-by: coleenp, dholmes, kvn
duke@435 | 1 | /* |
lfoltan@9816 | 2 | * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved. |
duke@435 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
duke@435 | 4 | * |
duke@435 | 5 | * This code is free software; you can redistribute it and/or modify it |
duke@435 | 6 | * under the terms of the GNU General Public License version 2 only, as |
duke@435 | 7 | * published by the Free Software Foundation. |
duke@435 | 8 | * |
duke@435 | 9 | * This code is distributed in the hope that it will be useful, but WITHOUT |
duke@435 | 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
duke@435 | 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
duke@435 | 12 | * version 2 for more details (a copy is included in the LICENSE file that |
duke@435 | 13 | * accompanied this code). |
duke@435 | 14 | * |
duke@435 | 15 | * You should have received a copy of the GNU General Public License version |
duke@435 | 16 | * 2 along with this work; if not, write to the Free Software Foundation, |
duke@435 | 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
duke@435 | 18 | * |
trims@1907 | 19 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
trims@1907 | 20 | * or visit www.oracle.com if you need additional information or have any |
trims@1907 | 21 | * questions. |
duke@435 | 22 | * |
duke@435 | 23 | */ |
duke@435 | 24 | |
duke@435 | 25 | // FILEBUFF.CPP - Routines for handling a parser file buffer |
duke@435 | 26 | #include "adlc.hpp" |
duke@435 | 27 | |
twisti@1038 | 28 | using namespace std; |
twisti@1038 | 29 | |
duke@435 | 30 | //------------------------------FileBuff--------------------------------------- |
duke@435 | 31 | // Create a new parsing buffer |
duke@435 | 32 | FileBuff::FileBuff( BufferedFile *fptr, ArchDesc& archDesc) : _fp(fptr), _AD(archDesc) { |
duke@435 | 33 | _err = fseek(_fp->_fp, 0, SEEK_END); // Seek to end of file |
duke@435 | 34 | if (_err) { |
duke@435 | 35 | file_error(SEMERR, 0, "File seek error reading input file"); |
duke@435 | 36 | exit(1); // Exit on seek error |
duke@435 | 37 | } |
duke@435 | 38 | _filepos = ftell(_fp->_fp); // Find offset of end of file |
duke@435 | 39 | _bufferSize = _filepos + 5; // Filepos points to last char, so add padding |
duke@435 | 40 | _err = fseek(_fp->_fp, 0, SEEK_SET); // Reset to beginning of file |
duke@435 | 41 | if (_err) { |
duke@435 | 42 | file_error(SEMERR, 0, "File seek error reading input file\n"); |
duke@435 | 43 | exit(1); // Exit on seek error |
duke@435 | 44 | } |
duke@435 | 45 | _filepos = ftell(_fp->_fp); // Reset current file position |
never@850 | 46 | _linenum = 0; |
duke@435 | 47 | |
duke@435 | 48 | _bigbuf = new char[_bufferSize]; // Create buffer to hold text for parser |
duke@435 | 49 | if( !_bigbuf ) { |
duke@435 | 50 | file_error(SEMERR, 0, "Buffer allocation failed\n"); |
duke@435 | 51 | exit(1); // Exit on allocation failure |
duke@435 | 52 | } |
twisti@1040 | 53 | *_bigbuf = '\n'; // Lead with a sentinel newline |
twisti@1040 | 54 | _buf = _bigbuf+1; // Skip sentinel |
duke@435 | 55 | _bufmax = _buf; // Buffer is empty |
twisti@1040 | 56 | _bufeol = _bigbuf; // _bufeol points at sentinel |
duke@435 | 57 | _filepos = -1; // filepos is in sync with _bufeol |
duke@435 | 58 | _bufoff = _offset = 0L; // Offset at file start |
duke@435 | 59 | |
duke@435 | 60 | _bufmax += fread(_buf, 1, _bufferSize-2, _fp->_fp); // Fill buffer & set end value |
duke@435 | 61 | if (_bufmax == _buf) { |
duke@435 | 62 | file_error(SEMERR, 0, "File read error, no input read\n"); |
duke@435 | 63 | exit(1); // Exit on read error |
duke@435 | 64 | } |
twisti@1040 | 65 | *_bufmax = '\n'; // End with a sentinel new-line |
twisti@1040 | 66 | *(_bufmax+1) = '\0'; // Then end with a sentinel NULL |
duke@435 | 67 | } |
duke@435 | 68 | |
duke@435 | 69 | //------------------------------~FileBuff-------------------------------------- |
duke@435 | 70 | // Nuke the FileBuff |
duke@435 | 71 | FileBuff::~FileBuff() { |
duke@435 | 72 | delete _bigbuf; |
duke@435 | 73 | } |
duke@435 | 74 | |
duke@435 | 75 | //------------------------------get_line---------------------------------------- |
duke@435 | 76 | char *FileBuff::get_line(void) { |
duke@435 | 77 | char *retval; |
duke@435 | 78 | |
duke@435 | 79 | // Check for end of file & return NULL |
duke@435 | 80 | if (_bufeol >= _bufmax) return NULL; |
duke@435 | 81 | |
never@850 | 82 | _linenum++; |
duke@435 | 83 | retval = ++_bufeol; // return character following end of previous line |
twisti@1040 | 84 | if (*retval == '\0') return NULL; // Check for EOF sentinel |
duke@435 | 85 | // Search for newline character which must end each line |
duke@435 | 86 | for(_filepos++; *_bufeol != '\n'; _bufeol++) |
duke@435 | 87 | _filepos++; // keep filepos in sync with _bufeol |
duke@435 | 88 | // _bufeol & filepos point at end of current line, so return pointer to start |
duke@435 | 89 | return retval; |
duke@435 | 90 | } |
duke@435 | 91 | |
duke@435 | 92 | //------------------------------file_error------------------------------------- |
duke@435 | 93 | void FileBuff::file_error(int flag, int linenum, const char *fmt, ...) |
duke@435 | 94 | { |
duke@435 | 95 | va_list args; |
duke@435 | 96 | |
duke@435 | 97 | va_start(args, fmt); |
duke@435 | 98 | switch (flag) { |
duke@435 | 99 | case 0: _AD._warnings += _AD.emit_msg(0, flag, linenum, fmt, args); |
duke@435 | 100 | case 1: _AD._syntax_errs += _AD.emit_msg(0, flag, linenum, fmt, args); |
duke@435 | 101 | case 2: _AD._semantic_errs += _AD.emit_msg(0, flag, linenum, fmt, args); |
duke@435 | 102 | default: assert(0, ""); break; |
duke@435 | 103 | } |
duke@435 | 104 | va_end(args); |
duke@435 | 105 | _AD._no_output = 1; |
duke@435 | 106 | } |