Path: blob/master/src/hotspot/share/adlc/filebuff.hpp
41144 views
/*1* Copyright (c) 1997, 2019, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*22*/2324#ifndef SHARE_ADLC_FILEBUFF_HPP25#define SHARE_ADLC_FILEBUFF_HPP2627// FILEBUFF.HPP - Definitions for parser file buffering routines2829// STRUCTURE FOR HANDLING INPUT AND OUTPUT FILES3031class BufferedFile {32public:33const char *_name;34FILE *_fp;35inline BufferedFile() { _name = NULL; _fp = NULL; };36inline ~BufferedFile() {};37};3839class ArchDesc;4041//------------------------------FileBuff--------------------------------------42// This class defines a nicely behaved buffer of text. Entire file of text43// is read into buffer at creation, with sentinels at start and end.44class FileBuff {45private:46long _bufferSize; // Size of text holding buffer.47long _offset; // Expected filepointer offset.48long _bufoff; // Start of buffer file offset4950char *_buf; // The buffer itself.51char *_bigbuf; // The buffer plus sentinels; actual heap area52char *_bufmax; // A pointer to the buffer end sentinel53char *_bufeol; // A pointer to the last complete line end5455int _err; // Error flag for file seek/read operations56long _filepos; // Current offset from start of file57int _linenum;5859ArchDesc& _AD; // Reference to Architecture Description6061// Error reporting function62void file_error(int flag, int linenum, const char *fmt, ...);6364public:65const BufferedFile *_fp; // File to be buffered6667FileBuff(BufferedFile *fp, ArchDesc& archDesc); // Constructor68~FileBuff(); // Destructor6970// 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.72char *get_line(void);73int linenum() const { return _linenum; }74void set_linenum(int line) { _linenum = line; }7576// This converts a pointer into the buffer to a file offset. It only works77// when the pointer is valid (i.e. just obtained from getline()).78long getoff(const char* s) { return _bufoff + (long)(s - _buf); }79};80#endif // SHARE_ADLC_FILEBUFF_HPP818283