src/share/vm/adlc/filebuff.hpp

Tue, 09 Dec 2008 12:41:26 -0800

author
jrose
date
Tue, 09 Dec 2008 12:41:26 -0800
changeset 910
284d0af00d53
parent 850
4d9884b01ba6
child 923
569b3b226089
permissions
-rw-r--r--

6771309: debugging AD files is difficult without #line directives in generated code
Summary: more and better #line and #define directives in the generated code; ADLC itself accepts #line directives
Reviewed-by: never, kvn

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

mercurial