hotspot/src/share/vm/adlc/filebuff.hpp
author xlu
Thu, 26 Jun 2008 14:15:01 -0700
changeset 775 d9c9b9cd55fb
parent 1 489c9b5090e2
child 1495 128fe18951ed
permissions -rw-r--r--
6718830: Hotspot fails to build with gcc 4.3 Summary: Fixed linux make file and couple adlc code to meet the changes of gcc 4.3 Reviewed-by: kamg, igor
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
489c9b5090e2 Initial load
duke
parents:
diff changeset
     2
 * Copyright 1997-2004 Sun Microsystems, Inc.  All Rights Reserved.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     4
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
489c9b5090e2 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
489c9b5090e2 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     8
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
489c9b5090e2 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
489c9b5090e2 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
489c9b5090e2 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
489c9b5090e2 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
489c9b5090e2 Initial load
duke
parents:
diff changeset
    14
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
489c9b5090e2 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    18
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    19
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    20
 * CA 95054 USA or visit www.sun.com if you need additional information or
489c9b5090e2 Initial load
duke
parents:
diff changeset
    21
 * have any questions.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    22
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    23
 */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    24
489c9b5090e2 Initial load
duke
parents:
diff changeset
    25
// FILEBUFF.HPP - Definitions for parser file buffering routines
775
d9c9b9cd55fb 6718830: Hotspot fails to build with gcc 4.3
xlu
parents: 1
diff changeset
    26
#include <iostream>
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    27
775
d9c9b9cd55fb 6718830: Hotspot fails to build with gcc 4.3
xlu
parents: 1
diff changeset
    28
using namespace std;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    29
// STRUCTURE FOR HANDLING INPUT AND OUTPUT FILES
489c9b5090e2 Initial load
duke
parents:
diff changeset
    30
typedef struct {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    31
  const char *_name;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    32
  FILE *_fp;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    33
} BufferedFile;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
class ArchDesc;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
//------------------------------FileBuff--------------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
// This class defines a nicely behaved buffer of text.  Entire file of text
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
// is read into buffer at creation, with sentinals at start and end.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
class FileBuff {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
  friend class FileBuffRegion;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
 private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
  long  _bufferSize;            // Size of text holding buffer.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
  long  _offset;                // Expected filepointer offset.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
  long  _bufoff;                // Start of buffer file offset
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
  char *_buf;                   // The buffer itself.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
  char *_bigbuf;                // The buffer plus sentinals; actual heap area
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
  char *_bufmax;                // A pointer to the buffer end sentinal
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
  char *_bufeol;                // A pointer to the last complete line end
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
  int   _err;                   // Error flag for file seek/read operations
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
  long  _filepos;               // Current offset from start of file
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
  ArchDesc& _AD;                // Reference to Architecture Description
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
  // Error reporting function
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
  void file_error(int flag, int linenum, const char *fmt, ...);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
  const BufferedFile *_fp;           // File to be buffered
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
  FileBuff(BufferedFile *fp, ArchDesc& archDesc); // Constructor
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
  ~FileBuff();                  // Destructor
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
  // This returns a pointer to the start of the current line in the buffer,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
  // and increments bufeol and filepos to point at the end of that line.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
  char *get_line(void);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
  // This converts a pointer into the buffer to a file offset.  It only works
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
  // when the pointer is valid (i.e. just obtained from getline()).
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
  int getoff(const char *s) { return _bufoff+(int)(s-_buf); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
//------------------------------FileBuffRegion---------------------------------
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
// A buffer region is really a region of some file, specified as a linked list
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
// of offsets and lengths.  These regions can be merged; overlapping regions
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
// will coalesce.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
class FileBuffRegion {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
 public:                        // Workaround dev-studio friend/private bug
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
  FileBuffRegion *_next;        // Linked list of regions sorted by offset.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
 private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
  FileBuff       *_bfr;         // The Buffer of the file
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
  int _offset, _length;         // The file area
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
  int             _sol;         // Start of line where the file area starts
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
  int             _line;        // First line of region
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
  FileBuffRegion(FileBuff*, int sol, int line, int offset, int len);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
  ~FileBuffRegion();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
  FileBuffRegion *copy();                   // Deep copy
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
  FileBuffRegion *merge(FileBuffRegion*); // Merge 2 regions; delete input
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
//  void print(std::ostream&);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
//  friend std::ostream& operator<< (std::ostream&, FileBuffRegion&);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
  void print(ostream&);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
  friend ostream& operator<< (ostream&, FileBuffRegion&);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
};