comparison src/share/vm/adlc/filebuff.hpp @ 0:a61af66fc99e jdk7-b24

Initial load
author duke
date Sat, 01 Dec 2007 00:00:00 +0000
parents
children 3e82d72933d0
comparison
equal deleted inserted replaced
-1:000000000000 0:a61af66fc99e
1 /*
2 * Copyright 1997-2004 Sun Microsystems, Inc. All Rights Reserved.
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 *
19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
20 * CA 95054 USA or visit www.sun.com if you need additional information or
21 * have any questions.
22 *
23 */
24
25 // FILEBUFF.HPP - Definitions for parser file buffering routines
26
27 #if _MSC_VER >= 1300 // Visual C++ 7.0 or later
28 #include <iostream>
29 #else
30 #include <iostream.h>
31 #endif
32
33 // STRUCTURE FOR HANDLING INPUT AND OUTPUT FILES
34 typedef struct {
35 const char *_name;
36 FILE *_fp;
37 } BufferedFile;
38
39 class ArchDesc;
40
41 //------------------------------FileBuff--------------------------------------
42 // This class defines a nicely behaved buffer of text. Entire file of text
43 // is read into buffer at creation, with sentinals at start and end.
44 class FileBuff {
45 friend class FileBuffRegion;
46 private:
47 long _bufferSize; // Size of text holding buffer.
48 long _offset; // Expected filepointer offset.
49 long _bufoff; // Start of buffer file offset
50
51 char *_buf; // The buffer itself.
52 char *_bigbuf; // The buffer plus sentinals; actual heap area
53 char *_bufmax; // A pointer to the buffer end sentinal
54 char *_bufeol; // A pointer to the last complete line end
55
56 int _err; // Error flag for file seek/read operations
57 long _filepos; // Current offset from start of file
58
59 ArchDesc& _AD; // Reference to Architecture Description
60
61 // Error reporting function
62 void file_error(int flag, int linenum, const char *fmt, ...);
63
64 public:
65 const BufferedFile *_fp; // File to be buffered
66
67 FileBuff(BufferedFile *fp, ArchDesc& archDesc); // Constructor
68 ~FileBuff(); // Destructor
69
70 // This returns a pointer to the start of the current line in the buffer,
71 // and increments bufeol and filepos to point at the end of that line.
72 char *get_line(void);
73
74 // This converts a pointer into the buffer to a file offset. It only works
75 // when the pointer is valid (i.e. just obtained from getline()).
76 int getoff(const char *s) { return _bufoff+(int)(s-_buf); }
77 };
78
79 //------------------------------FileBuffRegion---------------------------------
80 // A buffer region is really a region of some file, specified as a linked list
81 // of offsets and lengths. These regions can be merged; overlapping regions
82 // will coalesce.
83 class FileBuffRegion {
84 public: // Workaround dev-studio friend/private bug
85 FileBuffRegion *_next; // Linked list of regions sorted by offset.
86 private:
87 FileBuff *_bfr; // The Buffer of the file
88 int _offset, _length; // The file area
89 int _sol; // Start of line where the file area starts
90 int _line; // First line of region
91
92 public:
93 FileBuffRegion(FileBuff*, int sol, int line, int offset, int len);
94 ~FileBuffRegion();
95
96 FileBuffRegion *copy(); // Deep copy
97 FileBuffRegion *merge(FileBuffRegion*); // Merge 2 regions; delete input
98
99 // void print(std::ostream&);
100 // friend std::ostream& operator<< (std::ostream&, FileBuffRegion&);
101 void print(ostream&);
102 friend ostream& operator<< (ostream&, FileBuffRegion&);
103 };