Modules | Files | Inheritance Tree | Inheritance Graph | Name Index | Config
File: Synopsis/Parser/C++/occ/buffer.h
    1| /*
    2|   Copyright (C) 1997-2000 Shigeru Chiba, University of Tsukuba.
    3| 
    4|   Permission to use, copy, distribute and modify this software and   
    5|   its documentation for any purpose is hereby granted without fee,        
    6|   provided that the above copyright notice appear in all copies and that 
    7|   both that copyright notice and this permission notice appear in 
    8|   supporting documentation.
    9| 
   10|   Shigeru Chiba makes no representations about the suitability of this 
   11|   software for any purpose.  It is provided "as is" without express or
   12|   implied warranty.
   13| */
   14| /*
   15|   Copyright (c) 1995, 1996 Xerox Corporation.
   16|   All Rights Reserved.
   17| 
   18|   Use and copying of this software and preparation of derivative works
   19|   based upon this software are permitted. Any copy of this software or
   20|   of any derivative work must include the above copyright notice of
   21|   Xerox Corporation, this paragraph and the one after it.  Any
   22|   distribution of this software or derivative works must comply with all
   23|   applicable United States export control laws.
   24| 
   25|   This software is made available AS IS, and XEROX CORPORATION DISCLAIMS
   26|   ALL WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION THE
   27|   IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
   28|   PURPOSE, AND NOTWITHSTANDING ANY OTHER PROVISION CONTAINED HEREIN, ANY
   29|   LIABILITY FOR DAMAGES RESULTING FROM THE SOFTWARE OR ITS USE IS
   30|   EXPRESSLY DISCLAIMED, WHETHER ARISING IN CONTRACT, TORT (INCLUDING
   31|   NEGLIGENCE) OR STRICT LIABILITY, EVEN IF XEROX CORPORATION IS ADVISED
   32|   OF THE POSSIBILITY OF SUCH DAMAGES.
   33| */
   34| 
   35| #ifndef _buffer_h
   36| #define _buffer_h
   37| 
   38| #include <fstream>
   39| #include "types.h"
   40| 
   41| class Ptree;
   42| 
   43| class Program : public Object {
   44| public:
   45|     Program(char *name);
   46| 
   47|     virtual ~Program();
   48| 
   49|     void Rewind() { index = 0; }
   50|     void Rewind(uint i) { index = i; }
   51|     uint GetSize() { return size; }
   52|     void Unget() { --index; }
   53| 
   54|     char Ref(uint position) { return buf[position]; }
   55|     void Set(char c, uint position) { buf[position] = c; }
   56| 
   57|     /* The location of the last character obtained by Get(). */
   58|     uint GetCurPos() { return index - 1; }
   59| 
   60|     /* The location of the next character obtained by Get(). */
   61|     uint GetNextPos() { return index; }
   62| 
   63|     /* The result of Read() must be the same for each call. */
   64|     const charRead(uint p) { return &buf[p]; }
   65| 
   66|     virtual char Get();
   67| 
   68|     void Subst(Ptree* newtext, Ptree* oldtext);
   69|     void Insert(Ptree* pos, Ptree* before_text, Ptree* after_text);
   70|     void Replace(char*, char*, Ptree*);
   71|     void MinimumSubst(Ptree* newtext, Ptree* oldtext);
   72| 
   73|     uint LineNumber(char*, char*&, int&);
   74| 
   75|     void Write(std::ostream&, const char*);
   76|     sint ReadLineDirective(uintsintuint&, int&);
   77| 
   78| private:
   79|     bool MinimumSubst2(Ptree* newtext, Ptree* oldtext);
   80| 
   81| protected:
   82|     char*       buf;
   83|     uint        sizeindex;
   84|     char        *defaultname;
   85| 
   86|     // Private data for line number map -- "compiler firewall"
   87|     struct Private;
   88|     Private* m;
   89| 
   90| private:
   91|     class Replacement : public LightObject {
   92|     public:
   93|         Replacement(Replacement*, uintuint, Ptree*);
   94|         Replacementnext;
   95|         uint startpos;
   96|         uint endpos;
   97|         Ptree* text;
   98|     };
   99| 
  100|     Replacementreplacement;
  101| };
  102| 
  103| class ProgramFile : public Program {
  104| public:
  105|     ProgramFile(std::ifstream&, char *filename = "unknown");
  106|     ~ProgramFile();
  107| };
  108| 
  109| class ProgramFromStdin : public Program {
  110| public:
  111|     ProgramFromStdin();
  112|     ~ProgramFromStdin();
  113|     char Get();
  114| 
  115| protected:
  116|     uint buf_size;
  117| };
  118| 
  119| // This class violates the sepcification for Read().
  120| 
  121| class ProgramString : public Program {
  122| public:
  123|     ProgramString();
  124|     ~ProgramString();
  125|     void Clear() { buf[0] = '\0'; }
  126|     uint Length() { return str_length; }
  127|     ProgramStringoperator << (const char*);
  128|     ProgramStringoperator << (const char);
  129| 
  130| private:
  131|     uint str_length;
  132| };
  133| 
  134| #endif /* _buffer_h */