Mercurial > hg > truffle
comparison src/share/vm/adlc/filebuff.cpp @ 614:3db67f76d308
Merge
author | acorn |
---|---|
date | Thu, 05 Mar 2009 22:07:29 -0500 |
parents | 98cb887364d3 |
children | c18cbe5936b8 |
comparison
equal
deleted
inserted
replaced
613:5caef2219893 | 614:3db67f76d308 |
---|---|
1 /* | 1 /* |
2 * Copyright 1997-2008 Sun Microsystems, Inc. All Rights Reserved. | 2 * Copyright 1997-2009 Sun Microsystems, Inc. All Rights Reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * | 4 * |
5 * This code is free software; you can redistribute it and/or modify it | 5 * This code is free software; you can redistribute it and/or modify it |
6 * under the terms of the GNU General Public License version 2 only, as | 6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. | 7 * published by the Free Software Foundation. |
22 * | 22 * |
23 */ | 23 */ |
24 | 24 |
25 // FILEBUFF.CPP - Routines for handling a parser file buffer | 25 // FILEBUFF.CPP - Routines for handling a parser file buffer |
26 #include "adlc.hpp" | 26 #include "adlc.hpp" |
27 | |
28 using namespace std; | |
27 | 29 |
28 //------------------------------FileBuff--------------------------------------- | 30 //------------------------------FileBuff--------------------------------------- |
29 // Create a new parsing buffer | 31 // Create a new parsing buffer |
30 FileBuff::FileBuff( BufferedFile *fptr, ArchDesc& archDesc) : _fp(fptr), _AD(archDesc) { | 32 FileBuff::FileBuff( BufferedFile *fptr, ArchDesc& archDesc) : _fp(fptr), _AD(archDesc) { |
31 _err = fseek(_fp->_fp, 0, SEEK_END); // Seek to end of file | 33 _err = fseek(_fp->_fp, 0, SEEK_END); // Seek to end of file |
46 _bigbuf = new char[_bufferSize]; // Create buffer to hold text for parser | 48 _bigbuf = new char[_bufferSize]; // Create buffer to hold text for parser |
47 if( !_bigbuf ) { | 49 if( !_bigbuf ) { |
48 file_error(SEMERR, 0, "Buffer allocation failed\n"); | 50 file_error(SEMERR, 0, "Buffer allocation failed\n"); |
49 exit(1); // Exit on allocation failure | 51 exit(1); // Exit on allocation failure |
50 } | 52 } |
51 *_bigbuf = '\n'; // Lead with a sentinal newline | 53 *_bigbuf = '\n'; // Lead with a sentinel newline |
52 _buf = _bigbuf+1; // Skip sentinal | 54 _buf = _bigbuf+1; // Skip sentinel |
53 _bufmax = _buf; // Buffer is empty | 55 _bufmax = _buf; // Buffer is empty |
54 _bufeol = _bigbuf; // _bufeol points at sentinal | 56 _bufeol = _bigbuf; // _bufeol points at sentinel |
55 _filepos = -1; // filepos is in sync with _bufeol | 57 _filepos = -1; // filepos is in sync with _bufeol |
56 _bufoff = _offset = 0L; // Offset at file start | 58 _bufoff = _offset = 0L; // Offset at file start |
57 | 59 |
58 _bufmax += fread(_buf, 1, _bufferSize-2, _fp->_fp); // Fill buffer & set end value | 60 _bufmax += fread(_buf, 1, _bufferSize-2, _fp->_fp); // Fill buffer & set end value |
59 if (_bufmax == _buf) { | 61 if (_bufmax == _buf) { |
60 file_error(SEMERR, 0, "File read error, no input read\n"); | 62 file_error(SEMERR, 0, "File read error, no input read\n"); |
61 exit(1); // Exit on read error | 63 exit(1); // Exit on read error |
62 } | 64 } |
63 *_bufmax = '\n'; // End with a sentinal new-line | 65 *_bufmax = '\n'; // End with a sentinel new-line |
64 *(_bufmax+1) = '\0'; // Then end with a sentinal NULL | 66 *(_bufmax+1) = '\0'; // Then end with a sentinel NULL |
65 } | 67 } |
66 | 68 |
67 //------------------------------~FileBuff-------------------------------------- | 69 //------------------------------~FileBuff-------------------------------------- |
68 // Nuke the FileBuff | 70 // Nuke the FileBuff |
69 FileBuff::~FileBuff() { | 71 FileBuff::~FileBuff() { |
77 // Check for end of file & return NULL | 79 // Check for end of file & return NULL |
78 if (_bufeol >= _bufmax) return NULL; | 80 if (_bufeol >= _bufmax) return NULL; |
79 | 81 |
80 _linenum++; | 82 _linenum++; |
81 retval = ++_bufeol; // return character following end of previous line | 83 retval = ++_bufeol; // return character following end of previous line |
82 if (*retval == '\0') return NULL; // Check for EOF sentinal | 84 if (*retval == '\0') return NULL; // Check for EOF sentinel |
83 // Search for newline character which must end each line | 85 // Search for newline character which must end each line |
84 for(_filepos++; *_bufeol != '\n'; _bufeol++) | 86 for(_filepos++; *_bufeol != '\n'; _bufeol++) |
85 _filepos++; // keep filepos in sync with _bufeol | 87 _filepos++; // keep filepos in sync with _bufeol |
86 // _bufeol & filepos point at end of current line, so return pointer to start | 88 // _bufeol & filepos point at end of current line, so return pointer to start |
87 return retval; | 89 return retval; |
215 int i; | 217 int i; |
216 for( i=1; i<len; i++ ) // Underline just what's needed | 218 for( i=1; i<len; i++ ) // Underline just what's needed |
217 off = expandtab(os,off,*s++,'-','-'); | 219 off = expandtab(os,off,*s++,'-','-'); |
218 if( i == len ) os << '^'; // Mark end of region | 220 if( i == len ) os << '^'; // Mark end of region |
219 os << '\n'; // End of marked line | 221 os << '\n'; // End of marked line |
220 return 0L; // All done | 222 return 0; // All done |
221 } | 223 } |
222 | 224 |
223 //------------------------------print------------------------------------------ | 225 //------------------------------print------------------------------------------ |
224 //std::ostream& operator<< ( std::ostream& os, FileBuffRegion &br ) { | 226 //std::ostream& operator<< ( std::ostream& os, FileBuffRegion &br ) { |
225 ostream& operator<< ( ostream& os, FileBuffRegion &br ) { | 227 ostream& operator<< ( ostream& os, FileBuffRegion &br ) { |