[Libreoffice-commits] dev-tools.git: 2 commits - clang/find-unprefixed-members.cxx .clang-format
Miklos Vajna
vmiklos at collabora.co.uk
Thu Jan 18 08:16:23 UTC 2018
.clang-format | 46 +++++++++++++++
clang/find-unprefixed-members.cxx | 112 ++++++++++++++++++++------------------
2 files changed, 105 insertions(+), 53 deletions(-)
New commits:
commit 9539761ff634d25462c795d99c3e6f5e380029b8
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date: Thu Jan 18 09:15:42 2018 +0100
clang: avoid yaml header/footer for empty output in find-unprefixed-members
diff --git a/clang/find-unprefixed-members.cxx b/clang/find-unprefixed-members.cxx
index 677966a..d3d65b3 100644
--- a/clang/find-unprefixed-members.cxx
+++ b/clang/find-unprefixed-members.cxx
@@ -260,8 +260,8 @@ public:
const std::vector<RenameResult>& rResults = aVisitor.getResults();
// Ignore missing prefixes in structs without member functions.
bool bFound = false;
- if (m_rContext.getYaml())
- std::cerr << "---" << std::endl;
+ // Will this be the first YAML line?
+ bool bFirst = true;
for (const std::string& rFunction : rFunctions)
{
for (const RenameResult& rResult : rResults)
@@ -270,6 +270,12 @@ public:
{
if (m_rContext.getYaml())
{
+ if (bFirst)
+ {
+ bFirst = false;
+ if (m_rContext.getYaml())
+ std::cerr << "---" << std::endl;
+ }
std::cerr << "- QualifiedName: " << rResult.m_aScope
<< "::" << rResult.m_aOldName << std::endl;
std::cerr << " NewName: " << rResult.m_aNewName << std::endl;
@@ -281,7 +287,8 @@ public:
}
}
}
- if (m_rContext.getYaml())
+ if (!bFirst && m_rContext.getYaml())
+ // There were some YAML lines.
std::cerr << "..." << std::endl;
if (bFound)
exit(1);
commit 56a2ee6abd297e6c9eff46f085aa03a1a95f45eb
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date: Thu Jan 18 09:15:15 2018 +0100
clang: format find-unprefixed-members
diff --git a/.clang-format b/.clang-format
new file mode 100644
index 0000000..797f224
--- /dev/null
+++ b/.clang-format
@@ -0,0 +1,46 @@
+AccessModifierOffset: -4
+ConstructorInitializerIndentWidth: 4
+AlignEscapedNewlinesLeft: false
+AlignTrailingComments: false
+AllowAllParametersOfDeclarationOnNextLine: true
+AllowShortIfStatementsOnASingleLine: false
+AllowShortLoopsOnASingleLine: false
+AlwaysBreakTemplateDeclarations: false
+AlwaysBreakBeforeMultilineStrings: false
+BreakBeforeBinaryOperators: true
+BreakBeforeTernaryOperators: true
+BreakConstructorInitializersBeforeComma: true
+BinPackParameters: true
+ColumnLimit: 100
+ConstructorInitializerAllOnOneLineOrOnePerLine: false
+DerivePointerBinding: false
+ExperimentalAutoDetectBinPacking: false
+IndentCaseLabels: true
+KeepEmptyLinesAtTheStartOfBlocks: false
+MaxEmptyLinesToKeep: 1
+NamespaceIndentation: None
+ObjCSpaceBeforeProtocolList: true
+PenaltyBreakBeforeFirstCallParameter: 19
+PenaltyBreakComment: 60
+PenaltyBreakString: 1000
+PenaltyBreakFirstLessLess: 120
+PenaltyExcessCharacter: 1000000
+PenaltyReturnTypeOnItsOwnLine: 60
+PointerBindsToType: true
+ReflowComments: false
+SpacesBeforeTrailingComments: 1
+Cpp11BracedListStyle: false
+Standard: Cpp11
+IndentWidth: 4
+TabWidth: 8
+UseTab: Never
+BreakBeforeBraces: Allman
+IndentFunctionDeclarationAfterType: false
+SpacesInParentheses: false
+SpacesInAngles: false
+SpaceInEmptyParentheses: false
+SpacesInCStyleCastParentheses: false
+SpaceAfterControlStatementKeyword: true
+SpaceBeforeAssignmentOperators: true
+ContinuationIndentWidth: 4
+SortIncludes: false
diff --git a/clang/find-unprefixed-members.cxx b/clang/find-unprefixed-members.cxx
index 605b1b0..677966a 100644
--- a/clang/find-unprefixed-members.cxx
+++ b/clang/find-unprefixed-members.cxx
@@ -17,10 +17,11 @@ public:
std::string m_aOldName;
std::string m_aNewName;
- RenameResult(const std::string& rScope, const std::string& rOldName, const std::string& rNewName)
- : m_aScope(rScope),
- m_aOldName(rOldName),
- m_aNewName(rNewName)
+ RenameResult(const std::string& rScope, const std::string& rOldName,
+ const std::string& rNewName)
+ : m_aScope(rScope)
+ , m_aOldName(rOldName)
+ , m_aNewName(rNewName)
{
}
};
@@ -36,13 +37,15 @@ class Context
clang::ASTContext* m_pContext;
public:
- Context(const std::string& rClassName, const std::string& rClassPrefix, const std::string& rClassExcludedPrefix, bool bPoco, bool bYaml, const std::string& rPathPrefix)
- : m_aClassName(rClassName),
- m_aClassPrefix(rClassPrefix),
- m_bPoco(bPoco),
- m_bYaml(bYaml),
- m_aPathPrefix(rPathPrefix),
- m_pContext(nullptr)
+ Context(const std::string& rClassName, const std::string& rClassPrefix,
+ const std::string& rClassExcludedPrefix, bool bPoco, bool bYaml,
+ const std::string& rPathPrefix)
+ : m_aClassName(rClassName)
+ , m_aClassPrefix(rClassPrefix)
+ , m_bPoco(bPoco)
+ , m_bYaml(bYaml)
+ , m_aPathPrefix(rPathPrefix)
+ , m_pContext(nullptr)
{
std::stringstream aStream(rClassExcludedPrefix);
std::string aExclude;
@@ -114,10 +117,7 @@ public:
rName.insert(0, "s_");
}
- void setASTContext(clang::ASTContext& rContext)
- {
- m_pContext = &rContext;
- }
+ void setASTContext(clang::ASTContext& rContext) { m_pContext = &rContext; }
bool ignoreLocation(const clang::SourceLocation& rLocation)
{
@@ -132,17 +132,15 @@ public:
}
else
{
- const char* pName = m_pContext->getSourceManager().getPresumedLoc(aLocation).getFilename();
+ const char* pName
+ = m_pContext->getSourceManager().getPresumedLoc(aLocation).getFilename();
bRet = std::string(pName).find(m_aPathPrefix) != 0;
}
return bRet;
}
- bool getYaml() const
- {
- return m_bYaml;
- }
+ bool getYaml() const { return m_bYaml; }
};
class Visitor : public clang::RecursiveASTVisitor<Visitor>
@@ -160,15 +158,9 @@ public:
m_rContext.setASTContext(rASTContext);
}
- const std::vector<RenameResult>& getResults()
- {
- return m_aResults;
- }
+ const std::vector<RenameResult>& getResults() { return m_aResults; }
- const std::set<std::string>& getFunctions()
- {
- return m_aFunctions;
- }
+ const std::set<std::string>& getFunctions() { return m_aFunctions; }
/*
* class C
@@ -190,7 +182,8 @@ public:
if (!m_rContext.checkNonStatic(aName))
{
m_rContext.suggestNonStatic(aName);
- m_aResults.push_back(RenameResult(pRecord->getQualifiedNameAsString(), pDecl->getNameAsString(), aName));
+ m_aResults.push_back(RenameResult(pRecord->getQualifiedNameAsString(),
+ pDecl->getNameAsString(), aName));
}
}
@@ -220,7 +213,8 @@ public:
if (!m_rContext.checkStatic(aName))
{
m_rContext.suggestStatic(aName);
- m_aResults.push_back(RenameResult(pRecord->getQualifiedNameAsString(), pDecl->getNameAsString(), aName));
+ m_aResults.push_back(RenameResult(pRecord->getQualifiedNameAsString(),
+ pDecl->getNameAsString(), aName));
}
}
@@ -232,7 +226,8 @@ public:
if (m_rContext.ignoreLocation(pDecl->getLocation()))
return true;
- if (clang::isa<clang::CXXConstructorDecl>(pDecl) || clang::isa<clang::CXXDestructorDecl>(pDecl))
+ if (clang::isa<clang::CXXConstructorDecl>(pDecl)
+ || clang::isa<clang::CXXDestructorDecl>(pDecl))
return true;
clang::CXXRecordDecl* pRecord = pDecl->getParent();
@@ -275,11 +270,13 @@ public:
{
if (m_rContext.getYaml())
{
- std::cerr << "- QualifiedName: " << rResult.m_aScope << "::" << rResult.m_aOldName << std::endl;
+ std::cerr << "- QualifiedName: " << rResult.m_aScope
+ << "::" << rResult.m_aOldName << std::endl;
std::cerr << " NewName: " << rResult.m_aNewName << std::endl;
}
else
- std::cerr << rResult.m_aScope << "::" << rResult.m_aOldName << "," << rResult.m_aNewName << std::endl;
+ std::cerr << rResult.m_aScope << "::" << rResult.m_aOldName << ","
+ << rResult.m_aNewName << std::endl;
bFound = true;
}
}
@@ -307,10 +304,7 @@ public:
return llvm::make_unique<ASTConsumer>(m_rContext);
}
#else
- clang::ASTConsumer* newASTConsumer()
- {
- return new ASTConsumer(m_rContext);
- }
+ clang::ASTConsumer* newASTConsumer() { return new ASTConsumer(m_rContext); }
#endif
};
@@ -320,28 +314,33 @@ int main(int argc, const char** argv)
llvm::cl::opt<std::string> aClassName("class-name",
llvm::cl::desc("Qualified name (namespace::Class)."),
llvm::cl::cat(aCategory));
- llvm::cl::opt<std::string> aClassPrefix("class-prefix",
- llvm::cl::desc("Qualified name prefix (e.g. namespace::Cl)."),
- llvm::cl::cat(aCategory));
- llvm::cl::opt<std::string> aClassExcludedPrefix("class-excluded-prefix",
- llvm::cl::desc("Qualified name prefix to exclude (e.g. std::), has priority over the -class-prefix include."),
- llvm::cl::cat(aCategory));
- llvm::cl::opt<bool> bPoco("poco",
- llvm::cl::desc("Expect Poco-style '_' instead of LibreOffice-style 'm_' as prefix."),
- llvm::cl::cat(aCategory));
+ llvm::cl::opt<std::string> aClassPrefix(
+ "class-prefix", llvm::cl::desc("Qualified name prefix (e.g. namespace::Cl)."),
+ llvm::cl::cat(aCategory));
+ llvm::cl::opt<std::string> aClassExcludedPrefix(
+ "class-excluded-prefix",
+ llvm::cl::desc("Qualified name prefix to exclude (e.g. std::), has priority over the "
+ "-class-prefix include."),
+ llvm::cl::cat(aCategory));
+ llvm::cl::opt<bool> bPoco(
+ "poco",
+ llvm::cl::desc("Expect Poco-style '_' instead of LibreOffice-style 'm_' as prefix."),
+ llvm::cl::cat(aCategory));
llvm::cl::opt<bool> bYaml("yaml",
llvm::cl::desc("Output YAML instead of CSV, for clang-rename."),
llvm::cl::cat(aCategory));
- llvm::cl::opt<std::string> aPathPrefix("path-prefix",
- llvm::cl::desc("If not empty, ignore all source code paths not matching this prefix."),
- llvm::cl::cat(aCategory));
+ llvm::cl::opt<std::string> aPathPrefix(
+ "path-prefix",
+ llvm::cl::desc("If not empty, ignore all source code paths not matching this prefix."),
+ llvm::cl::cat(aCategory));
clang::tooling::CommonOptionsParser aParser(argc, argv, aCategory);
clang::tooling::ClangTool aTool(aParser.getCompilations(), aParser.getSourcePathList());
Context aContext(aClassName, aClassPrefix, aClassExcludedPrefix, bPoco, bYaml, aPathPrefix);
FrontendAction aAction(aContext);
- std::unique_ptr<clang::tooling::FrontendActionFactory> pFactory = clang::tooling::newFrontendActionFactory(&aAction);
+ std::unique_ptr<clang::tooling::FrontendActionFactory> pFactory
+ = clang::tooling::newFrontendActionFactory(&aAction);
return aTool.run(pFactory.get());
}
More information about the Libreoffice-commits
mailing list