You've already forked linux-packaging-mono
acceptance-tests
data
debian
docs
external
Newtonsoft.Json
api-doc-tools
api-snapshot
aspnetwebstack
bdwgc
binary-reference-assemblies
bockbuild
boringssl
cecil
cecil-legacy
corefx
corert
helix-binaries
ikdasm
ikvm
illinker-test-assets
linker
llvm-project
clang
INPUTS
bindings
cmake
docs
examples
include
lib
ARCMigrate
AST
ASTMatchers
Analysis
Basic
CodeGen
CrossTU
Driver
Edit
Format
Frontend
Rewrite
CMakeLists.txt
FixItRewriter.cpp
FrontendActions.cpp
HTMLPrint.cpp
InclusionRewriter.cpp
RewriteMacros.cpp
RewriteModernObjC.cpp.REMOVED.git-id
RewriteObjC.cpp.REMOVED.git-id
RewriteTest.cpp
ASTConsumers.cpp
ASTMerge.cpp
ASTUnit.cpp
CMakeLists.txt
CacheTokens.cpp
ChainedDiagnosticConsumer.cpp
ChainedIncludesSource.cpp
CodeGenOptions.cpp
CompilerInstance.cpp
CompilerInvocation.cpp.REMOVED.git-id
CreateInvocationFromCommandLine.cpp
DependencyFile.cpp
DependencyGraph.cpp
DiagnosticRenderer.cpp
FrontendAction.cpp
FrontendActions.cpp
FrontendOptions.cpp
HeaderIncludeGen.cpp
InitHeaderSearch.cpp
InitPreprocessor.cpp
LangStandards.cpp
LayoutOverrideSource.cpp
LogDiagnosticPrinter.cpp
ModuleDependencyCollector.cpp
MultiplexConsumer.cpp
PCHContainerOperations.cpp
PrecompiledPreamble.cpp
PrintPreprocessedOutput.cpp
SerializedDiagnosticPrinter.cpp
SerializedDiagnosticReader.cpp
TestModuleFileExtension.cpp
TestModuleFileExtension.h
TextDiagnostic.cpp
TextDiagnosticBuffer.cpp
TextDiagnosticPrinter.cpp
VerifyDiagnosticConsumer.cpp
FrontendTool
Headers
Index
Lex
Parse
Rewrite
Sema
Serialization
StaticAnalyzer
Tooling
CMakeLists.txt
runtime
tools
unittests
utils
www
.arcconfig
.clang-format
.clang-tidy
.gitignore
CMakeLists.txt
CODE_OWNERS.TXT
INSTALL.txt
LICENSE.TXT
ModuleInfo.txt
NOTES.txt
README.txt
clang-tools-extra
compiler-rt
eng
libcxx
libcxxabi
libunwind
lld
lldb
llvm
nuget
openmp
polly
Directory.Build.props
Directory.Build.targets
NuGet.config
azure-pipelines.yml
build.cmd
build.sh
dir.common.props
global.json
llvm.proj
mxe-Win64.cmake.in
nuget-buildtasks
nunit-lite
roslyn-binaries
rx
xunit-binaries
how-to-bump-roslyn-binaries.md
ikvm-native
llvm
m4
man
mcs
mono
msvc
netcore
po
runtime
samples
scripts
support
tools
COPYING.LIB
LICENSE
Makefile.am
Makefile.in
NEWS
README.md
acinclude.m4
aclocal.m4
autogen.sh
code_of_conduct.md
compile
config.guess
config.h.in
config.rpath
config.sub
configure.REMOVED.git-id
configure.ac.REMOVED.git-id
depcomp
install-sh
ltmain.sh.REMOVED.git-id
missing
mkinstalldirs
mono-uninstalled.pc.in
test-driver
winconfig.h
94 lines
3.2 KiB
C++
94 lines
3.2 KiB
C++
//===--- HTMLPrint.cpp - Source code -> HTML pretty-printing --------------===//
|
|
//
|
|
// The LLVM Compiler Infrastructure
|
|
//
|
|
// This file is distributed under the University of Illinois Open Source
|
|
// License. See LICENSE.TXT for details.
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
//
|
|
// Pretty-printing of source code to HTML.
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#include "clang/AST/ASTConsumer.h"
|
|
#include "clang/AST/ASTContext.h"
|
|
#include "clang/AST/Decl.h"
|
|
#include "clang/Basic/Diagnostic.h"
|
|
#include "clang/Basic/FileManager.h"
|
|
#include "clang/Basic/SourceManager.h"
|
|
#include "clang/Lex/Preprocessor.h"
|
|
#include "clang/Rewrite/Core/HTMLRewrite.h"
|
|
#include "clang/Rewrite/Core/Rewriter.h"
|
|
#include "clang/Rewrite/Frontend/ASTConsumers.h"
|
|
#include "llvm/Support/raw_ostream.h"
|
|
using namespace clang;
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
// Functional HTML pretty-printing.
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
namespace {
|
|
class HTMLPrinter : public ASTConsumer {
|
|
Rewriter R;
|
|
std::unique_ptr<raw_ostream> Out;
|
|
Preprocessor &PP;
|
|
bool SyntaxHighlight, HighlightMacros;
|
|
|
|
public:
|
|
HTMLPrinter(std::unique_ptr<raw_ostream> OS, Preprocessor &pp,
|
|
bool _SyntaxHighlight, bool _HighlightMacros)
|
|
: Out(std::move(OS)), PP(pp), SyntaxHighlight(_SyntaxHighlight),
|
|
HighlightMacros(_HighlightMacros) {}
|
|
|
|
void Initialize(ASTContext &context) override;
|
|
void HandleTranslationUnit(ASTContext &Ctx) override;
|
|
};
|
|
}
|
|
|
|
std::unique_ptr<ASTConsumer>
|
|
clang::CreateHTMLPrinter(std::unique_ptr<raw_ostream> OS, Preprocessor &PP,
|
|
bool SyntaxHighlight, bool HighlightMacros) {
|
|
return llvm::make_unique<HTMLPrinter>(std::move(OS), PP, SyntaxHighlight,
|
|
HighlightMacros);
|
|
}
|
|
|
|
void HTMLPrinter::Initialize(ASTContext &context) {
|
|
R.setSourceMgr(context.getSourceManager(), context.getLangOpts());
|
|
}
|
|
|
|
void HTMLPrinter::HandleTranslationUnit(ASTContext &Ctx) {
|
|
if (PP.getDiagnostics().hasErrorOccurred())
|
|
return;
|
|
|
|
// Format the file.
|
|
FileID FID = R.getSourceMgr().getMainFileID();
|
|
const FileEntry* Entry = R.getSourceMgr().getFileEntryForID(FID);
|
|
StringRef Name;
|
|
// In some cases, in particular the case where the input is from stdin,
|
|
// there is no entry. Fall back to the memory buffer for a name in those
|
|
// cases.
|
|
if (Entry)
|
|
Name = Entry->getName();
|
|
else
|
|
Name = R.getSourceMgr().getBuffer(FID)->getBufferIdentifier();
|
|
|
|
html::AddLineNumbers(R, FID);
|
|
html::AddHeaderFooterInternalBuiltinCSS(R, FID, Name);
|
|
|
|
// If we have a preprocessor, relex the file and syntax highlight.
|
|
// We might not have a preprocessor if we come from a deserialized AST file,
|
|
// for example.
|
|
|
|
if (SyntaxHighlight) html::SyntaxHighlight(R, FID, PP);
|
|
if (HighlightMacros) html::HighlightMacros(R, FID, PP);
|
|
html::EscapeText(R, FID, false, true);
|
|
|
|
// Emit the HTML.
|
|
const RewriteBuffer &RewriteBuf = R.getEditBuffer(FID);
|
|
char *Buffer = (char*)malloc(RewriteBuf.size());
|
|
std::copy(RewriteBuf.begin(), RewriteBuf.end(), Buffer);
|
|
Out->write(Buffer, RewriteBuf.size());
|
|
free(Buffer);
|
|
}
|