Modules | Files | Inheritance Tree | Inheritance Graph | Name Index | Config
File: Synopsis/Parser/C++/syn/linkstore.hh
    1| // Synopsis C++ Parser: linkstore.hh header file
    2| // The LinkStore class which stores syntax and xref link info
    3| 
    4| // $Id: linkstore.hh,v 1.9 2002/12/21 05:04:40 chalky Exp $
    5| //
    6| // This file is a part of Synopsis.
    7| // Copyright (C) 2000-2002 Stephen Davies
    8| // Copyright (C) 2000, 2001 Stefan Seefeld
    9| //
   10| // Synopsis is free software; you can redistribute it and/or modify it
   11| // under the terms of the GNU General Public License as published by
   12| // the Free Software Foundation; either version 2 of the License, or
   13| // (at your option) any later version.
   14| //
   15| // This program is distributed in the hope that it will be useful,
   16| // but WITHOUT ANY WARRANTY; without even the implied warranty of
   17| // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   18| // General Public License for more details.
   19| //
   20| // You should have received a copy of the GNU General Public License
   21| // along with this program; if not, write to the Free Software
   22| // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
   23| // 02111-1307, USA.
   24| //
   25| // $Log: linkstore.hh,v $
   26| // Revision 1.9  2002/12/21 05:04:40  chalky
   27| // Move constants since gcc 3.2 didn't like them.
   28| //
   29| // Revision 1.8  2002/12/09 04:01:00  chalky
   30| // Added multiple file support to parsers, changed AST datastructure to handle
   31| // new information, added a demo to demo/C++. AST Declarations now have a
   32| // reference to a SourceFile (which includes a filename) instead of a filename.
   33| //
   34| // Revision 1.7  2002/11/17 12:11:43  chalky
   35| // Reformatted all files with astyle --style=ansi, renamed fakegc.hh
   36| //
   37| // Revision 1.6  2002/11/02 06:37:38  chalky
   38| // Allow non-frames output, some refactoring of page layout, new modules.
   39| //
   40| // Revision 1.5  2002/02/19 09:05:16  chalky
   41| // Applied patch from David Abrahams to help compilation on Cygwin
   42| //
   43| // Revision 1.4  2002/01/30 11:53:15  chalky
   44| // Couple bug fixes, some cleaning up.
   45| //
   46| // Revision 1.3  2002/01/28 13:17:24  chalky
   47| // More cleaning up of code. Combined xref into LinkStore. Encoded links file.
   48| //
   49| // Revision 1.2  2002/01/25 14:24:33  chalky
   50| // Start of refactoring and restyling effort.
   51| //
   52| // Revision 1.1  2001/06/10 00:31:39  chalky
   53| // Refactored link storage, better comments, better parsing
   54| //
   55| 
   56| #ifndef H_SYNOPSIS_CPP_LINKSTORE
   57| #define H_SYNOPSIS_CPP_LINKSTORE
   58| 
   59| #include "ast.hh"
   60| #include <iostream>
   61| class Parser;
   62| class Ptree;
   63| class SWalker;
   64| class FileFilter;
   65| 
   66| //. Stores link information about the file. Link info is stored in two files
   67| //. with two purposes.
   68| //.
   69| //. The first file stores all links and non-link spans, in a
   70| //. simple text file with one record per line and with spaces as field
   71| //. separators. The fields themselves are encoded using URL-style %FF encoding
   72| //. of non alpha-numeric characters (including spaces, brackers, commas etc).
   73| //. The purpose of this file is for syntax-hightlighting of source files.
   74| //.
   75| //. The second file stores only cross-reference information, which is a subset
   76| //. of the first file.
   77| class LinkStore
   78| {
   79| public:
   80|     //. Enumeration of record types
   81|     enum Context
   82|     {
   83|         Reference,              //.< General name reference
   84|         Definition,         //.< Definition of the declaration
   85|         Span,               //.< Non-declarative span of text
   86|         Implementation,     //.< Implementation of a declaration
   87|         UsingDirective,     //.< Referenced in a using directive
   88|         UsingDeclaration,   //.< Referenced in a using declaration
   89|         FunctionCall,       //.< Called as a function
   90|         NumContext          //.< Marker used to check size of array
   91|     };
   92| 
   93|     //. Constructor.
   94|     //. @param filter the filter to use to decide whether to output syntax and
   95|     //. xref records
   96|     //. @param swalker the SWalker object we are linking for
   97|     LinkStore(FileFilter* filter, SWalker* swalker);
   98| 
   99|     //. Destructor. Closes all opened file streams
  100|     ~LinkStore();
  101| 
  102|     //. Store a link for the given Ptree node. If a decl is given, store an
  103|     //. xref too
  104|     void link(Ptree* node, Contextconst ScopedName& name, const std::string& desc, const AST::Declaration* decl = NULL);
  105| 
  106|     //. Store a Definition link for the given Ptree node using the AST node
  107|     void link(Ptree* node, const AST::Declaration* decl);
  108| 
  109|     //. Store a link for the given node using the given Context, which defaults
  110|     //. to a Reference
  111|     void link(Ptree* node, Types::Type*, Context = Reference);
  112| 
  113|     //. Store a span
  114|     void span(int line, int col, int len, const char* desc);
  115| 
  116|     //. Store a span for the given Ptree node
  117|     void span(Ptree* node, const char* desc);
  118| 
  119|     //. Store a long (possibly multi-line) span
  120|     void long_span(Ptree* node, const char* desc);
  121| 
  122|     //. Returns the SWalker
  123|     SWalker* swalker();
  124| 
  125|     //. Encode a string to the output stream
  126|     //. Usage: cout << encode("some string") << endl; output--> "some%20string\n"
  127|     class encode;
  128| 
  129|     //. Encode a ScopedName to the output stream
  130|     class encode_name;
  131| 
  132| protected:
  133|     //. Store a link in the Syntax File
  134|     void store_syntax_record(AST::SourceFile*, int line, int col, int len, Context context, const ScopedName& name, const std::string& desc);
  135| 
  136|     //. Store a link in the CrossRef File
  137|     void store_xref_record(AST::SourceFile*, const AST::Declaration* decl, const std::string& file, int line, Context context);
  138| 
  139|     //. Gets the ostream for a syntax file
  140|     std::ostreamget_syntax_stream(AST::SourceFile*);
  141| 
  142|     //. Gets the ostream for a xref file
  143|     std::ostreamget_xref_stream(AST::SourceFile*);
  144| 
  145|     //. Calculates the column number of 'ptr'. m_buffer_start is used as a
  146|     //. lower bounds, since the function counts backwards until it finds a
  147|     //. newline. As an added bonus, the returned column number is adjusted
  148|     //. using the link map generated from expanding macros so it can be output
  149|     //. straight to the link file :) The adjustment requires the line number.
  150|     int find_col(int line, const char* ptr);
  151| 
  152|     //. Compiler firewalled private data type
  153|     struct Private;
  154|     //. Compiler firewalled private data
  155|     Private* m;
  156| };
  157| 
  158| #endif
  159| // vim: set ts=8 sts=4 sw=4 et: