Synopsis - Cross-Reference
File: /Synopsis/Parsers/Cxx/SXRGenerator.hh1// 2// Copyright (C) 2008 Stefan Seefeld 3// All rights reserved. 4// Licensed to the public under the terms of the GNU LGPL (>= 2), 5// see the file COPYING for details. 6// 7 8#ifndef SXRGenerator_hh_ 9#define SXRGenerator_hh_ 10 11#include "ASG.hh" 12#include <iostream> 13#include "SXRBuffer.hh" 14#include <string> 15 16namespace Synopsis 17{ 18class Buffer; 19class Parser; 20namespace PTree { class Node;} 21} 22class Walker; 23class FileFilter; 24 25//. Stores link information about the file. Link info is stored in two files 26//. with two purposes. 27//. 28//. The first file stores all links and non-link spans, in a 29//. simple text file with one record per line and with spaces as field 30//. separators. The fields themselves are encoded using URL-style %FF encoding 31//. of non alpha-numeric characters (including spaces, brackers, commas etc). 32//. The purpose of this file is for syntax-hightlighting of source files. 33//. 34//. The second file stores only cross-reference information, which is a subset 35//. of the first file. 36class SXRGenerator 37{ 38public: 39 //. Enumeration of record types 40 enum Context 41 { 42 Reference, //.< General name reference 43 Definition, //.< Definition of the declaration 44 Span, //.< Non-declarative span of text 45 Implementation, //.< Implementation of a declaration 46 UsingDirective, //.< Referenced in a using directive 47 UsingDeclaration, //.< Referenced in a using declaration 48 FunctionCall, //.< Called as a function 49 NumContext //.< Marker used to check size of array 50 }; 51 52 //. Constructor. 53 //. @param filter the filter to use to decide whether to output syntax and 54 //. xref records 55 //. @param swalker the Walker object we are linking for 56 SXRGenerator(FileFilter* filter, Walker* walker); 57 58 //. Destructor. Closes all opened file streams 59 ~SXRGenerator(); 60 61 //. Store a link for the given Ptree node. If a decl is given, store an 62 //. xref too 63 void xref(Synopsis::PTree::Node *node, Context, ScopedName const &name, std::string const &desc, ASG::Declaration const *decl = 0); 64 65 //. Store a Definition link for the given Ptree node using the ASG node 66 void xref(Synopsis::PTree::Node *node, ASG::Declaration const *decl); 67 68 //. Store a link for the given node using the given Context, which defaults 69 //. to a Reference 70 void xref(Synopsis::PTree::Node *node, Types::Type*, Context = Reference); 71 72 //. Store a span for the given Ptree node 73 void span(Synopsis::PTree::Node *node, char const *desc); 74 75 //. Store a long (possibly multi-line) span 76 void long_span(Synopsis::PTree::Node *node, char const *desc); 77 78 //. Returns the Walker 79 Walker* walker(); 80 81private: 82 //. The type of a map of streams 83 typedef std::map<ASG::SourceFile *, SXRBuffer *> SXRDict; 84 85 void store_span(unsigned int line, unsigned int col, int len, char const *type); 86 void store_xref(ASG::SourceFile*, 87 int line, int col, int len, Context context, 88 ScopedName const &name, std::string const &desc, bool continuation); 89 90 SXRBuffer *get_buffer(ASG::SourceFile*); 91 92 //. Computes ptr's column in the original source. This requires looking for 93 //. macro call expansion that may have displaced ptr in the preprocessed file. 94 int map_column(ASG::SourceFile *file, int line, char const *ptr); 95 96 //. The filter 97 FileFilter* filter_; 98 99 //. The Buffer object 100 Synopsis::Buffer *buffer_; 101 102 //. The Walker object 103 Walker* walker_; 104 105 //. A map of streams for each file 106 SXRDict buffers_; 107}; 108 109#endif