Main Page   Namespace List   Class Hierarchy   Compound List   File List   Compound Members   File Members  

buffer.h

Go to the documentation of this file.
00001 /*
00002   Copyright (C) 1997-2001 Shigeru Chiba, Tokyo Institute of Technology.
00003 
00004   Permission to use, copy, distribute and modify this software and   
00005   its documentation for any purpose is hereby granted without fee,        
00006   provided that the above copyright notice appear in all copies and that 
00007   both that copyright notice and this permission notice appear in 
00008   supporting documentation.
00009 
00010   Shigeru Chiba makes no representations about the suitability of this 
00011   software for any purpose.  It is provided "as is" without express or
00012   implied warranty.
00013 */
00014 
00015 /*
00016   Copyright (c) 1995, 1996 Xerox Corporation.
00017   All Rights Reserved.
00018 
00019   Use and copying of this software and preparation of derivative works
00020   based upon this software are permitted. Any copy of this software or
00021   of any derivative work must include the above copyright notice of
00022   Xerox Corporation, this paragraph and the one after it.  Any
00023   distribution of this software or derivative works must comply with all
00024   applicable United States export control laws.
00025 
00026   This software is made available AS IS, and XEROX CORPORATION DISCLAIMS
00027   ALL WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION THE
00028   IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
00029   PURPOSE, AND NOTWITHSTANDING ANY OTHER PROVISION CONTAINED HEREIN, ANY
00030   LIABILITY FOR DAMAGES RESULTING FROM THE SOFTWARE OR ITS USE IS
00031   EXPRESSLY DISCLAIMED, WHETHER ARISING IN CONTRACT, TORT (INCLUDING
00032   NEGLIGENCE) OR STRICT LIABILITY, EVEN IF XEROX CORPORATION IS ADVISED
00033   OF THE POSSIBILITY OF SUCH DAMAGES.
00034 */
00035 
00036 #ifndef _buffer_h
00037 #define _buffer_h
00038 
00039 #include <fstream.h>
00040 #include "types.h"
00041 
00042 class Ptree;
00043 
00044 class Program : public Object {
00045 public:
00046     Program(char *name) {
00047         replacement = nil;
00048         defaultname = name;
00049     }
00050 
00051     virtual ~Program() {}
00052 
00053     void Rewind() { index = 0; }
00054     void Rewind(uint i) { index = i; }
00055     uint GetSize() { return size; }
00056     void Unget() { --index; }
00057 
00058     char Ref(uint position) { return buf[position]; }
00059     void Set(char c, uint position) { buf[position] = c; }
00060 
00061     /* The location of the last character obtained by Get(). */
00062     uint GetCurPos() { return index - 1; }
00063 
00064     /* The location of the next character obtained by Get(). */
00065     uint GetNextPos() { return index; }
00066 
00067     /* The result of Read() must be the same for each call. */
00068     const char* Read(uint p) { return &buf[p]; }
00069 
00070     virtual char Get();
00071 
00072     void Subst(Ptree* newtext, Ptree* oldtext);
00073     void Insert(Ptree* pos, Ptree* before_text, Ptree* after_text);
00074     void Replace(char*, char*, Ptree*);
00075     void MinimumSubst(Ptree* newtext, Ptree* oldtext);
00076 
00077     uint LineNumber(char*, char*&, int&);
00078 
00079     void Write(ostream&, const char*);
00080     sint ReadLineDirective(uint, sint, uint&, int&);
00081 
00082 private:
00083     bool MinimumSubst2(Ptree* newtext, Ptree* oldtext);
00084 
00085 protected:
00086     char*       buf;
00087     uint        size, index;
00088     char        *defaultname;
00089 
00090 private:
00091     class Replacement : public LightObject {
00092     public:
00093         Replacement(Replacement*, uint, uint, Ptree*);
00094         Replacement* next;
00095         uint startpos;
00096         uint endpos;
00097         Ptree* text;
00098     };
00099 
00100     Replacement* replacement;
00101 };
00102 
00103 class ProgramFile : public Program {
00104 public:
00105     ProgramFile(ifstream&, char *filename = "unknown");
00106     ~ProgramFile();
00107 };
00108 
00109 class ProgramFromStdin : public Program {
00110 public:
00111     ProgramFromStdin();
00112     ~ProgramFromStdin();
00113     char Get();
00114 
00115 protected:
00116     uint buf_size;
00117 };
00118 
00119 // This class violates the sepcification for Read().
00120 
00121 class ProgramString : public Program {
00122 public:
00123     ProgramString();
00124     ~ProgramString();
00125     void Clear() { buf[0] = '\0'; }
00126     uint Length() { return str_length; }
00127     ProgramString& operator << (const char*);
00128     ProgramString& operator << (const char);
00129 
00130 private:
00131     uint str_length;
00132 };
00133 
00134 #endif /* _buffer_h */

Generated on Mon Feb 10 17:32:44 2003 for VFiasco Semantics Compiler by doxygen1.2.15