src/share/vm/adlc/filebuff.hpp

changeset 0
f90c822e73f8
child 6876
710a3c8b516e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/share/vm/adlc/filebuff.hpp	Wed Apr 27 01:25:04 2016 +0800
     1.3 @@ -0,0 +1,110 @@
     1.4 +/*
     1.5 + * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved.
     1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     1.7 + *
     1.8 + * This code is free software; you can redistribute it and/or modify it
     1.9 + * under the terms of the GNU General Public License version 2 only, as
    1.10 + * published by the Free Software Foundation.
    1.11 + *
    1.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
    1.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    1.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    1.15 + * version 2 for more details (a copy is included in the LICENSE file that
    1.16 + * accompanied this code).
    1.17 + *
    1.18 + * You should have received a copy of the GNU General Public License version
    1.19 + * 2 along with this work; if not, write to the Free Software Foundation,
    1.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    1.21 + *
    1.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    1.23 + * or visit www.oracle.com if you need additional information or have any
    1.24 + * questions.
    1.25 + *
    1.26 + */
    1.27 +
    1.28 +#ifndef SHARE_VM_ADLC_FILEBUFF_HPP
    1.29 +#define SHARE_VM_ADLC_FILEBUFF_HPP
    1.30 +
    1.31 +// FILEBUFF.HPP - Definitions for parser file buffering routines
    1.32 +#include <iostream>
    1.33 +
    1.34 +using namespace std;
    1.35 +
    1.36 +// STRUCTURE FOR HANDLING INPUT AND OUTPUT FILES
    1.37 +
    1.38 +class BufferedFile {
    1.39 + public:
    1.40 +  const char *_name;
    1.41 +  FILE *_fp;
    1.42 +  inline BufferedFile() { _name = NULL; _fp = NULL; };
    1.43 +  inline ~BufferedFile() {};
    1.44 +};
    1.45 +
    1.46 +class ArchDesc;
    1.47 +
    1.48 +//------------------------------FileBuff--------------------------------------
    1.49 +// This class defines a nicely behaved buffer of text.  Entire file of text
    1.50 +// is read into buffer at creation, with sentinels at start and end.
    1.51 +class FileBuff {
    1.52 +  friend class FileBuffRegion;
    1.53 + private:
    1.54 +  long  _bufferSize;            // Size of text holding buffer.
    1.55 +  long  _offset;                // Expected filepointer offset.
    1.56 +  long  _bufoff;                // Start of buffer file offset
    1.57 +
    1.58 +  char *_buf;                   // The buffer itself.
    1.59 +  char *_bigbuf;                // The buffer plus sentinels; actual heap area
    1.60 +  char *_bufmax;                // A pointer to the buffer end sentinel
    1.61 +  char *_bufeol;                // A pointer to the last complete line end
    1.62 +
    1.63 +  int   _err;                   // Error flag for file seek/read operations
    1.64 +  long  _filepos;               // Current offset from start of file
    1.65 +  int   _linenum;
    1.66 +
    1.67 +  ArchDesc& _AD;                // Reference to Architecture Description
    1.68 +
    1.69 +  // Error reporting function
    1.70 +  void file_error(int flag, int linenum, const char *fmt, ...);
    1.71 +
    1.72 + public:
    1.73 +  const BufferedFile *_fp;           // File to be buffered
    1.74 +
    1.75 +  FileBuff(BufferedFile *fp, ArchDesc& archDesc); // Constructor
    1.76 +  ~FileBuff();                  // Destructor
    1.77 +
    1.78 +  // This returns a pointer to the start of the current line in the buffer,
    1.79 +  // and increments bufeol and filepos to point at the end of that line.
    1.80 +  char *get_line(void);
    1.81 +  int linenum() const { return _linenum; }
    1.82 +  void set_linenum(int line) { _linenum = line; }
    1.83 +
    1.84 +  // This converts a pointer into the buffer to a file offset.  It only works
    1.85 +  // when the pointer is valid (i.e. just obtained from getline()).
    1.86 +  long getoff(const char* s) { return _bufoff + (long)(s - _buf); }
    1.87 +};
    1.88 +
    1.89 +//------------------------------FileBuffRegion---------------------------------
    1.90 +// A buffer region is really a region of some file, specified as a linked list
    1.91 +// of offsets and lengths.  These regions can be merged; overlapping regions
    1.92 +// will coalesce.
    1.93 +class FileBuffRegion {
    1.94 + public:                        // Workaround dev-studio friend/private bug
    1.95 +  FileBuffRegion *_next;        // Linked list of regions sorted by offset.
    1.96 + private:
    1.97 +  FileBuff       *_bfr;         // The Buffer of the file
    1.98 +  int _offset, _length;         // The file area
    1.99 +  int             _sol;         // Start of line where the file area starts
   1.100 +  int             _line;        // First line of region
   1.101 +
   1.102 + public:
   1.103 +  FileBuffRegion(FileBuff*, int sol, int line, int offset, int len);
   1.104 +  ~FileBuffRegion();
   1.105 +
   1.106 +  FileBuffRegion *copy();                   // Deep copy
   1.107 +  FileBuffRegion *merge(FileBuffRegion*); // Merge 2 regions; delete input
   1.108 +
   1.109 +  void print(ostream&);
   1.110 +  friend ostream& operator<< (ostream&, FileBuffRegion&);
   1.111 +};
   1.112 +
   1.113 +#endif // SHARE_VM_ADLC_FILEBUFF_HPP

mercurial