1//==- HTMLRewrite.h - Translate source code into prettified HTML ---*- C++ -*-//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This file defines a set of functions used for translating source code
10// into beautified HTML.
11//
12//===----------------------------------------------------------------------===//
13
14#ifndef LLVM_CLANG_REWRITE_CORE_HTMLREWRITE_H
15#define LLVM_CLANG_REWRITE_CORE_HTMLREWRITE_H
16
17#include "clang/Basic/SourceLocation.h"
18#include <string>
19
20namespace clang {
21
22class Rewriter;
23class RewriteBuffer;
24class Preprocessor;
25
26namespace html {
27 struct RelexRewriteCache;
28 using RelexRewriteCacheRef = std::shared_ptr<RelexRewriteCache>;
29
30 /// If you need to rewrite the same file multiple times, you can instantiate
31 /// a RelexRewriteCache and refer functions such as SyntaxHighlight()
32 /// and HighlightMacros() to it so that to avoid re-lexing the file each time.
33 /// The cache may outlive the rewriter as long as cached FileIDs and source
34 /// locations continue to make sense for the translation unit as a whole.
35 RelexRewriteCacheRef instantiateRelexRewriteCache();
36
37 /// HighlightRange - Highlight a range in the source code with the specified
38 /// start/end tags. B/E must be in the same file. This ensures that
39 /// start/end tags are placed at the start/end of each line if the range is
40 /// multiline.
41 void HighlightRange(Rewriter &R, SourceLocation B, SourceLocation E,
42 const char *StartTag, const char *EndTag,
43 bool IsTokenRange = true);
44
45 /// HighlightRange - Highlight a range in the source code with the specified
46 /// start/end tags. The Start/end of the range must be in the same file.
47 /// This ensures that start/end tags are placed at the start/end of each line
48 /// if the range is multiline.
49 inline void HighlightRange(Rewriter &R, SourceRange Range,
50 const char *StartTag, const char *EndTag) {
51 HighlightRange(R, B: Range.getBegin(), E: Range.getEnd(), StartTag, EndTag);
52 }
53
54 /// HighlightRange - This is the same as the above method, but takes
55 /// decomposed file locations.
56 void HighlightRange(RewriteBuffer &RB, unsigned B, unsigned E,
57 const char *BufferStart,
58 const char *StartTag, const char *EndTag);
59
60 /// EscapeText - HTMLize a specified file so that special characters are
61 /// are translated so that they are not interpreted as HTML tags.
62 void EscapeText(Rewriter& R, FileID FID,
63 bool EscapeSpaces = false, bool ReplaceTabs = false);
64
65 /// EscapeText - HTMLized the provided string so that special characters
66 /// in 's' are not interpreted as HTML tags. Unlike the version of
67 /// EscapeText that rewrites a file, this version by default replaces tabs
68 /// with spaces.
69 std::string EscapeText(StringRef s,
70 bool EscapeSpaces = false, bool ReplaceTabs = false);
71
72 void AddLineNumbers(Rewriter& R, FileID FID);
73
74 void AddHeaderFooterInternalBuiltinCSS(Rewriter &R, FileID FID,
75 StringRef title);
76
77 /// SyntaxHighlight - Relex the specified FileID and annotate the HTML with
78 /// information about keywords, comments, etc.
79 void SyntaxHighlight(Rewriter &R, FileID FID, const Preprocessor &PP,
80 RelexRewriteCacheRef Cache = nullptr);
81
82 /// HighlightMacros - This uses the macro table state from the end of the
83 /// file, to reexpand macros and insert (into the HTML) information about the
84 /// macro expansions. This won't be perfectly perfect, but it will be
85 /// reasonably close.
86 void HighlightMacros(Rewriter &R, FileID FID, const Preprocessor &PP,
87 RelexRewriteCacheRef Cache = nullptr);
88
89} // end html namespace
90} // end clang namespace
91
92#endif
93

source code of clang/include/clang/Rewrite/Core/HTMLRewrite.h