clang API Documentation

HTMLRewrite.h
Go to the documentation of this file.
00001 //==- HTMLRewrite.h - Translate source code into prettified HTML ---*- C++ -*-//
00002 //
00003 //                     The LLVM Compiler Infrastructure
00004 //
00005 // This file is distributed under the University of Illinois Open Source
00006 // License. See LICENSE.TXT for details.
00007 //
00008 //===----------------------------------------------------------------------===//
00009 //
00010 //  This file defines a set of functions used for translating source code
00011 //  into beautified HTML.
00012 //
00013 //===----------------------------------------------------------------------===//
00014 
00015 #ifndef LLVM_CLANG_REWRITE_CORE_HTMLREWRITE_H
00016 #define LLVM_CLANG_REWRITE_CORE_HTMLREWRITE_H
00017 
00018 #include "clang/Basic/SourceLocation.h"
00019 #include <string>
00020 
00021 namespace clang {
00022 
00023 class Rewriter;
00024 class RewriteBuffer;
00025 class Preprocessor;
00026 
00027 namespace html {
00028 
00029   /// HighlightRange - Highlight a range in the source code with the specified
00030   /// start/end tags.  B/E must be in the same file.  This ensures that
00031   /// start/end tags are placed at the start/end of each line if the range is
00032   /// multiline.
00033   void HighlightRange(Rewriter &R, SourceLocation B, SourceLocation E,
00034                       const char *StartTag, const char *EndTag);
00035 
00036   /// HighlightRange - Highlight a range in the source code with the specified
00037   /// start/end tags.  The Start/end of the range must be in the same file.
00038   /// This ensures that start/end tags are placed at the start/end of each line
00039   /// if the range is multiline.
00040   inline void HighlightRange(Rewriter &R, SourceRange Range,
00041                              const char *StartTag, const char *EndTag) {
00042     HighlightRange(R, Range.getBegin(), Range.getEnd(), StartTag, EndTag);
00043   }
00044 
00045   /// HighlightRange - This is the same as the above method, but takes
00046   /// decomposed file locations.
00047   void HighlightRange(RewriteBuffer &RB, unsigned B, unsigned E,
00048                       const char *BufferStart,
00049                       const char *StartTag, const char *EndTag);
00050 
00051   /// EscapeText - HTMLize a specified file so that special characters are
00052   /// are translated so that they are not interpreted as HTML tags.
00053   void EscapeText(Rewriter& R, FileID FID,
00054                   bool EscapeSpaces = false, bool ReplaceTabs = false);
00055 
00056   /// EscapeText - HTMLized the provided string so that special characters
00057   ///  in 's' are not interpreted as HTML tags.  Unlike the version of
00058   ///  EscapeText that rewrites a file, this version by default replaces tabs
00059   ///  with spaces.
00060   std::string EscapeText(StringRef s,
00061                          bool EscapeSpaces = false, bool ReplaceTabs = false);
00062 
00063   void AddLineNumbers(Rewriter& R, FileID FID);
00064 
00065   void AddHeaderFooterInternalBuiltinCSS(Rewriter& R, FileID FID,
00066                                          const char *title = nullptr);
00067 
00068   /// SyntaxHighlight - Relex the specified FileID and annotate the HTML with
00069   /// information about keywords, comments, etc.
00070   void SyntaxHighlight(Rewriter &R, FileID FID, const Preprocessor &PP);
00071 
00072   /// HighlightMacros - This uses the macro table state from the end of the
00073   /// file, to reexpand macros and insert (into the HTML) information about the
00074   /// macro expansions.  This won't be perfectly perfect, but it will be
00075   /// reasonably close.
00076   void HighlightMacros(Rewriter &R, FileID FID, const Preprocessor &PP);
00077 
00078 } // end html namespace
00079 } // end clang namespace
00080 
00081 #endif