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