Skip to content

Commit

Permalink
Merge from 'master' to 'sycl-web'
Browse files Browse the repository at this point in the history
  • Loading branch information
sndmitriev committed Aug 27, 2019
2 parents d3e712a + ed153ef commit e800b8d
Show file tree
Hide file tree
Showing 472 changed files with 39,811 additions and 17,596 deletions.
2 changes: 1 addition & 1 deletion clang-tools-extra/clang-doc/BitcodeWriter.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ struct BitCodeConstants {
static constexpr unsigned IntSize = 16U;
static constexpr unsigned StringLengthSize = 16U;
static constexpr unsigned FilenameLengthSize = 16U;
static constexpr unsigned LineNumberSize = 16U;
static constexpr unsigned LineNumberSize = 32U;
static constexpr unsigned ReferenceTypeSize = 8U;
static constexpr unsigned USRLengthSize = 6U;
static constexpr unsigned USRBitLengthSize = 8U;
Expand Down
4 changes: 3 additions & 1 deletion clang-tools-extra/clang-doc/Generators.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,9 @@ std::string getTagType(TagTypeKind AS) {
llvm_unreachable("Unknown TagTypeKind");
}

bool Generator::createResources(ClangDocContext &CDCtx) { return true; }
llvm::Error Generator::createResources(ClangDocContext &CDCtx) {
return llvm::Error::success();
}

// A function to add a reference to Info in Idx.
// Given an Info X with the following namespaces: [B,A]; a reference to X will
Expand Down
2 changes: 1 addition & 1 deletion clang-tools-extra/clang-doc/Generators.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class Generator {
// It can be overwritten by any of the inherited generators.
// If the override method wants to run this it should call
// Generator::createResources(CDCtx);
virtual bool createResources(ClangDocContext &CDCtx);
virtual llvm::Error createResources(ClangDocContext &CDCtx);

static void addInfoToIndex(Index &Idx, const doc::Info *Info);
};
Expand Down
61 changes: 36 additions & 25 deletions clang-tools-extra/clang-doc/HTMLGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -829,7 +829,7 @@ class HTMLGenerator : public Generator {

llvm::Error generateDocForInfo(Info *I, llvm::raw_ostream &OS,
const ClangDocContext &CDCtx) override;
bool createResources(ClangDocContext &CDCtx) override;
llvm::Error createResources(ClangDocContext &CDCtx) override;
};

const char *HTMLGenerator::Format = "html";
Expand Down Expand Up @@ -883,16 +883,17 @@ static std::string getRefType(InfoType IT) {
llvm_unreachable("Unknown InfoType");
}

static bool SerializeIndex(ClangDocContext &CDCtx) {
static llvm::Error SerializeIndex(ClangDocContext &CDCtx) {
std::error_code OK;
std::error_code FileErr;
llvm::SmallString<128> FilePath;
llvm::sys::path::native(CDCtx.OutDirectory, FilePath);
llvm::sys::path::append(FilePath, "index_json.js");
llvm::raw_fd_ostream OS(FilePath, FileErr, llvm::sys::fs::F_None);
if (FileErr != OK) {
llvm::errs() << "Error creating index file: " << FileErr.message() << "\n";
return false;
return llvm::make_error<llvm::StringError>(
"Error creating index file: " + FileErr.message() + "\n",
llvm::inconvertibleErrorCode());
}
CDCtx.Idx.sort();
llvm::json::OStream J(OS, 2);
Expand All @@ -911,7 +912,7 @@ static bool SerializeIndex(ClangDocContext &CDCtx) {
OS << "var JsonIndex = `\n";
IndexToJSON(CDCtx.Idx);
OS << "`;\n";
return true;
return llvm::Error::success();
}

// Generates a main HTML node that has the main content of the file that shows
Expand All @@ -932,15 +933,16 @@ static std::unique_ptr<TagNode> genIndexFileMainNode() {
return MainNode;
}

static bool GenIndex(const ClangDocContext &CDCtx) {
static llvm::Error GenIndex(const ClangDocContext &CDCtx) {
std::error_code FileErr, OK;
llvm::SmallString<128> IndexPath;
llvm::sys::path::native(CDCtx.OutDirectory, IndexPath);
llvm::sys::path::append(IndexPath, "index.html");
llvm::raw_fd_ostream IndexOS(IndexPath, FileErr, llvm::sys::fs::F_None);
if (FileErr != OK) {
llvm::errs() << "Error creating main index: " << FileErr.message() << "\n";
return false;
return llvm::make_error<llvm::StringError>(
"Error creating main index: " + FileErr.message() + "\n",
llvm::inconvertibleErrorCode());
}

HTMLFile F;
Expand All @@ -958,10 +960,10 @@ static bool GenIndex(const ClangDocContext &CDCtx) {

F.Render(IndexOS);

return true;
return llvm::Error::success();
}

static bool CopyFile(StringRef FilePath, StringRef OutDirectory) {
static llvm::Error CopyFile(StringRef FilePath, StringRef OutDirectory) {
llvm::SmallString<128> PathWrite;
llvm::sys::path::native(OutDirectory, PathWrite);
llvm::sys::path::append(PathWrite, llvm::sys::path::filename(FilePath));
Expand All @@ -970,24 +972,33 @@ static bool CopyFile(StringRef FilePath, StringRef OutDirectory) {
std::error_code OK;
std::error_code FileErr = llvm::sys::fs::copy_file(PathRead, PathWrite);
if (FileErr != OK) {
llvm::errs() << "Error creating file "
<< llvm::sys::path::filename(FilePath) << ": "
<< FileErr.message() << "\n";
return false;
return llvm::make_error<llvm::StringError>(
"Error creating file " + llvm::sys::path::filename(FilePath) + ": " +
FileErr.message() + "\n",
llvm::inconvertibleErrorCode());
}
return true;
return llvm::Error::success();
}

bool HTMLGenerator::createResources(ClangDocContext &CDCtx) {
if (!SerializeIndex(CDCtx) || !GenIndex(CDCtx))
return false;
for (const auto &FilePath : CDCtx.UserStylesheets)
if (!CopyFile(FilePath, CDCtx.OutDirectory))
return false;
for (const auto &FilePath : CDCtx.FilesToCopy)
if (!CopyFile(FilePath, CDCtx.OutDirectory))
return false;
return true;
llvm::Error HTMLGenerator::createResources(ClangDocContext &CDCtx) {
auto Err = SerializeIndex(CDCtx);
if (Err)
return Err;
Err = GenIndex(CDCtx);
if (Err)
return Err;

for (const auto &FilePath : CDCtx.UserStylesheets) {
Err = CopyFile(FilePath, CDCtx.OutDirectory);
if (Err)
return Err;
}
for (const auto &FilePath : CDCtx.FilesToCopy) {
Err = CopyFile(FilePath, CDCtx.OutDirectory);
if (Err)
return Err;
}
return llvm::Error::success();
}

static GeneratorRegistry::Add<HTMLGenerator> HTML(HTMLGenerator::Format,
Expand Down
5 changes: 4 additions & 1 deletion clang-tools-extra/clang-doc/tool/ClangDocMain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -326,8 +326,11 @@ int main(int argc, const char **argv) {
return 1;

llvm::outs() << "Generating assets for docs...\n";
if (!G->get()->createResources(CDCtx))
Err = G->get()->createResources(CDCtx);
if (Err) {
llvm::errs() << toString(std::move(Err)) << "\n";
return 1;
}

return 0;
}
1 change: 1 addition & 0 deletions clang-tools-extra/clang-tidy/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ add_clang_library(clangTidy
ClangTidyOptions.cpp
ClangTidyProfiling.cpp
ExpandModularHeadersPPCallbacks.cpp
GlobList.cpp

DEPENDS
ClangSACheckers
Expand Down
42 changes: 1 addition & 41 deletions clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

#include "ClangTidyDiagnosticConsumer.h"
#include "ClangTidyOptions.h"
#include "GlobList.h"
#include "clang/AST/ASTDiagnostic.h"
#include "clang/Basic/Diagnostic.h"
#include "clang/Basic/DiagnosticOptions.h"
Expand Down Expand Up @@ -118,47 +119,6 @@ ClangTidyError::ClangTidyError(StringRef CheckName,
: tooling::Diagnostic(CheckName, DiagLevel, BuildDirectory),
IsWarningAsError(IsWarningAsError) {}

// Returns true if GlobList starts with the negative indicator ('-'), removes it
// from the GlobList.
static bool ConsumeNegativeIndicator(StringRef &GlobList) {
GlobList = GlobList.trim(" \r\n");
if (GlobList.startswith("-")) {
GlobList = GlobList.substr(1);
return true;
}
return false;
}
// Converts first glob from the comma-separated list of globs to Regex and
// removes it and the trailing comma from the GlobList.
static llvm::Regex ConsumeGlob(StringRef &GlobList) {
StringRef UntrimmedGlob = GlobList.substr(0, GlobList.find(','));
StringRef Glob = UntrimmedGlob.trim(' ');
GlobList = GlobList.substr(UntrimmedGlob.size() + 1);
SmallString<128> RegexText("^");
StringRef MetaChars("()^$|*+?.[]\\{}");
for (char C : Glob) {
if (C == '*')
RegexText.push_back('.');
else if (MetaChars.find(C) != StringRef::npos)
RegexText.push_back('\\');
RegexText.push_back(C);
}
RegexText.push_back('$');
return llvm::Regex(RegexText);
}

GlobList::GlobList(StringRef Globs)
: Positive(!ConsumeNegativeIndicator(Globs)), Regex(ConsumeGlob(Globs)),
NextGlob(Globs.empty() ? nullptr : new GlobList(Globs)) {}

bool GlobList::contains(StringRef S, bool Contains) {
if (Regex.match(S))
Contains = Positive;

if (NextGlob)
Contains = NextGlob->contains(S, Contains);
return Contains;
}

class ClangTidyContext::CachedGlobList {
public:
Expand Down
22 changes: 0 additions & 22 deletions clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
#include "clang/Tooling/Refactoring.h"
#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/StringMap.h"
#include "llvm/Support/Regex.h"
#include "llvm/Support/Timer.h"

namespace clang {
Expand Down Expand Up @@ -47,27 +46,6 @@ struct ClangTidyError : tooling::Diagnostic {
bool IsWarningAsError;
};

/// Read-only set of strings represented as a list of positive and
/// negative globs. Positive globs add all matched strings to the set, negative
/// globs remove them in the order of appearance in the list.
class GlobList {
public:
/// \p GlobList is a comma-separated list of globs (only '*'
/// metacharacter is supported) with optional '-' prefix to denote exclusion.
GlobList(StringRef Globs);

/// Returns \c true if the pattern matches \p S. The result is the last
/// matching glob's Positive flag.
bool contains(StringRef S) { return contains(S, false); }

private:
bool contains(StringRef S, bool Contains);

bool Positive;
llvm::Regex Regex;
std::unique_ptr<GlobList> NextGlob;
};

/// Contains displayed and ignored diagnostic counters for a ClangTidy
/// run.
struct ClangTidyStats {
Expand Down
56 changes: 56 additions & 0 deletions clang-tools-extra/clang-tidy/GlobList.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
//===--- tools/extra/clang-tidy/GlobList.cpp ------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#include "GlobList.h"
#include "llvm/ADT/SmallString.h"

using namespace clang;
using namespace tidy;

// Returns true if GlobList starts with the negative indicator ('-'), removes it
// from the GlobList.
static bool ConsumeNegativeIndicator(StringRef &GlobList) {
GlobList = GlobList.trim(" \r\n");
if (GlobList.startswith("-")) {
GlobList = GlobList.substr(1);
return true;
}
return false;
}

// Converts first glob from the comma-separated list of globs to Regex and
// removes it and the trailing comma from the GlobList.
static llvm::Regex ConsumeGlob(StringRef &GlobList) {
StringRef UntrimmedGlob = GlobList.substr(0, GlobList.find(','));
StringRef Glob = UntrimmedGlob.trim(' ');
GlobList = GlobList.substr(UntrimmedGlob.size() + 1);
SmallString<128> RegexText("^");
StringRef MetaChars("()^$|*+?.[]\\{}");
for (char C : Glob) {
if (C == '*')
RegexText.push_back('.');
else if (MetaChars.find(C) != StringRef::npos)
RegexText.push_back('\\');
RegexText.push_back(C);
}
RegexText.push_back('$');
return llvm::Regex(RegexText);
}

GlobList::GlobList(StringRef Globs)
: Positive(!ConsumeNegativeIndicator(Globs)), Regex(ConsumeGlob(Globs)),
NextGlob(Globs.empty() ? nullptr : new GlobList(Globs)) {}

bool GlobList::contains(StringRef S, bool Contains) {
if (Regex.match(S))
Contains = Positive;

if (NextGlob)
Contains = NextGlob->contains(S, Contains);
return Contains;
}
44 changes: 44 additions & 0 deletions clang-tools-extra/clang-tidy/GlobList.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
//===--- GlobList.h ---------------------------------------------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_GLOBLIST_H
#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_GLOBLIST_H

#include "clang/Basic/LLVM.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/Support/Regex.h"
#include <memory>

namespace clang {
namespace tidy {

/// Read-only set of strings represented as a list of positive and
/// negative globs. Positive globs add all matched strings to the set, negative
/// globs remove them in the order of appearance in the list.
class GlobList {
public:
/// \p GlobList is a comma-separated list of globs (only '*'
/// metacharacter is supported) with optional '-' prefix to denote exclusion.
GlobList(StringRef Globs);

/// Returns \c true if the pattern matches \p S. The result is the last
/// matching glob's Positive flag.
bool contains(StringRef S) { return contains(S, false); }

private:
bool contains(StringRef S, bool Contains);

bool Positive;
llvm::Regex Regex;
std::unique_ptr<GlobList> NextGlob;
};

} // end namespace tidy
} // end namespace clang

#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_GLOBLIST_H
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@
#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_FUCHSIA_RESTRICTINCLUDESSCHECK_H

#include "../ClangTidyCheck.h"
#include "../ClangTidyDiagnosticConsumer.h"
#include "../utils/OptionsUtils.h"
#include "../GlobList.h"

namespace clang {
namespace tidy {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ void UnusedUsingDeclsCheck::onEndOfTranslationUnit() {
<< Context.FoundUsingDecl;
// Emit a fix and a fix description of the check;
diag(Context.FoundUsingDecl->getLocation(),
/*FixDescription=*/"remove the using", DiagnosticIDs::Note)
/*Description=*/"remove the using", DiagnosticIDs::Note)
<< FixItHint::CreateRemoval(Context.UsingDeclRange);
}
}
Expand Down
1 change: 1 addition & 0 deletions clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

#include "../ClangTidy.h"
#include "../ClangTidyForceLinker.h"
#include "../GlobList.h"
#include "clang/Tooling/CommonOptionsParser.h"
#include "llvm/Support/Process.h"
#include "llvm/Support/Signals.h"
Expand Down
Loading

0 comments on commit e800b8d

Please sign in to comment.