Skip to content

Commit

Permalink
Remove support for building the "utils library"
Browse files Browse the repository at this point in the history
It wasn't used and the CMakeLists.txt is already complicated as is.

Building in-tree is the suggested way for in-house checks that need
clazy Qt helper functions.
  • Loading branch information
Sergio Martins committed Oct 23, 2018
1 parent 2872014 commit 4c6c491
Show file tree
Hide file tree
Showing 18 changed files with 139 additions and 221 deletions.
52 changes: 0 additions & 52 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,13 @@ set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
add_definitions(-D__STDC_LIMIT_MACROS -D__STDC_CONSTANT_MACROS)
add_definitions(-D_GNU_SOURCE -DHAVE_CLANG_CONFIG_H)

option(CLAZY_BUILD_UTILS_LIB "Enable this option to build a library so you can reuse clazy's utility functions" OFF)
option(CLAZY_AST_MATCHERS_CRASH_WORKAROUND "Disable AST Matchers if being built with clang. See bug #392223" ON)

if (CLAZY_AST_MATCHERS_CRASH_WORKAROUND AND "${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
message("Enabling AST Matchers workaround. Consider building with gcc instead. See bug #392223.")
add_definitions(-DCLAZY_DISABLE_AST_MATCHERS)
endif()

if(CLAZY_BUILD_UTILS_LIB)
add_definitions(-DCLAZY_BUILD_UTILS_LIB)
endif()

if(NOT CLAZY_BUILD_WITH_CLANG AND MSVC AND NOT CLANG_LIBRARY_IMPORT)
message(FATAL_ERROR "\nOn MSVC you need to pass -DCLANG_LIBRARY_IMPORT=C:/path/to/llvm-build/lib/clang.lib to cmake when building Clazy.\nAlso make sure you've built LLVM with -DLLVM_EXPORT_SYMBOLS_FOR_PLUGINS=ON")
endif()
Expand Down Expand Up @@ -134,30 +129,8 @@ macro(add_clang_plugin name)
target_link_libraries(${name} ${CLANG_LIBRARY_IMPORT}) # Link against clang.exe to share the plugin registry
endif()

if(CLAZY_BUILD_UTILS_LIB)
target_link_libraries(${name} clazylib)
endif()
endmacro()

if(CLAZY_BUILD_UTILS_LIB)
# clazylib version
set(clazylib_VERSION_MAJOR 0)
set(clazylib_VERSION_MINOR 1)
# Enable the full x.y.z version only for release versions
set(clazylib_VERSION_PATCH 0)

set(clazylib_VERSION ${clazylib_VERSION_MAJOR}.${clazylib_VERSION_MINOR})
add_library(clazylib SHARED ${CLAZY_LIB_SRC})
link_to_llvm(clazylib FALSE)
generate_export_header(clazylib)
set_target_properties(clazylib PROPERTIES VERSION ${clazylib_VERSION} SOVERSION ${clazylib_VERSION_MAJOR})
install(TARGETS clazylib EXPORT LibClazyExport
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
)
endif()

set(SYMBOL_FILE Lazy.exports)

if (NOT CLAZY_BUILD_WITH_CLANG)
Expand Down Expand Up @@ -203,31 +176,6 @@ if (NOT CLAZY_BUILD_WITH_CLANG)
set(MAN_INSTALL_DIR "${SHARE_INSTALL_DIR}/man/man1")
add_subdirectory(docs)

if(CLAZY_BUILD_UTILS_LIB)
# Install public headers
set(CLAZY_LIB_INCLUDES
src/AccessSpecifierManager.h
src/checkbase.h
src/checkmanager.h
src/clazy_export.h
src/clazy_stl.h
src/ContextUtils.h
src/FixItUtils.h
src/HierarchyUtils.h
src/LoopUtils.h
src/MacroUtils.h
src/QtUtils.h
src/SuppressionManager.h
src/StmtBodyRange.h
src/StringUtils.h
src/TemplateUtils.h
src/TypeUtils.h
src/Utils.h
src/ClazyContext.h
)
install(FILES ${CLAZY_LIB_INCLUDES} DESTINATION include/clazy)
endif()

# rpath
set(CMAKE_SKIP_BUILD_RPATH FALSE)
set(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE)
Expand Down
1 change: 1 addition & 0 deletions Changelog
Original file line number Diff line number Diff line change
Expand Up @@ -94,3 +94,4 @@
* v1.5 (, 2019)
- New Checks:
ifndef-define-typo
- Removed support for the obscure -DCLAZY_BUILD_UTILS_LIB to simplify the CMakeLists.txt.
5 changes: 1 addition & 4 deletions ClazySources.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,9 @@ set(CLAZY_SHARED_SRCS # sources shared between clazy-standalone and clazy plugin
${CLAZY_CHECKS_SRCS}
${CMAKE_CURRENT_LIST_DIR}/src/ClazyContext.cpp
${CMAKE_CURRENT_LIST_DIR}/src/Clazy.cpp
${CLAZY_LIB_SRC}
)

if (NOT CLAZY_BUILD_UTILS_LIB)
set(CLAZY_SHARED_SRCS ${CLAZY_SHARED_SRCS} ${CLAZY_LIB_SRC})
endif()

set(CLAZY_PLUGIN_SRCS # Sources for the plugin
${CLAZY_SHARED_SRCS}
)
Expand Down
11 changes: 5 additions & 6 deletions src/AccessSpecifierManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,16 @@
#ifndef CLAZY_ACCESS_SPECIFIER_MANAGER_H
#define CLAZY_ACCESS_SPECIFIER_MANAGER_H

# include <clang/Frontend/CompilerInstance.h>
# include <unordered_map>
# include <vector>

#include "checkbase.h"
#include "clazy_export.h"

#include <clang/Frontend/CompilerInstance.h>
#include <clang/Basic/SourceLocation.h>
#include <clang/Basic/Specifiers.h>
#include <llvm/ADT/StringRef.h>

#include <unordered_map>
#include <vector>

/*
clang supports "public", "private" and "protected"
This is a small wrapper to have support for "public slots", "signals", etc. so you can easily
Expand Down Expand Up @@ -77,7 +76,7 @@ struct ClazyAccessSpecifier

using ClazySpecifierList = std::vector<ClazyAccessSpecifier>;

class CLAZYLIB_EXPORT AccessSpecifierManager
class AccessSpecifierManager
{
public:
explicit AccessSpecifierManager(const clang::CompilerInstance &ci);
Expand Down
19 changes: 9 additions & 10 deletions src/ContextUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
#ifndef CLAZY_CONTEXT_UTILS_H
#define CLAZY_CONTEXT_UTILS_H

#include "clazy_export.h"
#include "TypeUtils.h"

#include <clang/AST/DeclBase.h>
Expand Down Expand Up @@ -62,7 +61,7 @@ inline bool isValueDeclInFunctionContext(const clang::ValueDecl *valueDecl)
* Returns the list of scopes for a decl context (namespaces, classes, inner classes, etc)
* The inner ones are at the beginning of the list
*/
CLAZYLIB_EXPORT std::vector<clang::DeclContext *> contextsForDecl(clang::DeclContext *);
std::vector<clang::DeclContext *> contextsForDecl(clang::DeclContext *);

/**
* Returns the first context for a decl.
Expand Down Expand Up @@ -148,11 +147,11 @@ T* firstContextOfType(clang::DeclContext *context)
* if currentScope == nullptr will return a fully qualified name
*/

CLAZYLIB_EXPORT std::string getMostNeededQualifiedName(const clang::SourceManager &sourceManager,
clang::CXXMethodDecl *method,
clang::DeclContext *currentScope,
clang::SourceLocation usageLoc,
bool honourUsingDirectives);
std::string getMostNeededQualifiedName(const clang::SourceManager &sourceManager,
clang::CXXMethodDecl *method,
clang::DeclContext *currentScope,
clang::SourceLocation usageLoc,
bool honourUsingDirectives);

/**
* Returns true, if in a specific context, we can take the address of a method
Expand All @@ -164,9 +163,9 @@ CLAZYLIB_EXPORT std::string getMostNeededQualifiedName(const clang::SourceManage
* but only if you qualify it with the derived class name, so &Derived::baseMethod, instead of &Base::baseMethod
* If this was the case then isSpecialProtectedCase will be true
*/
CLAZYLIB_EXPORT bool canTakeAddressOf(clang::CXXMethodDecl *method,
clang::DeclContext *context,
bool &isSpecialProtectedCase);
bool canTakeAddressOf(clang::CXXMethodDecl *method,
clang::DeclContext *context,
bool &isSpecialProtectedCase);

}

Expand Down
25 changes: 12 additions & 13 deletions src/FixItUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@

#ifndef CLAZY_FIXIT_UTILS_H
#define CLAZY_FIXIT_UTILS_H
#include "clazy_export.h"

#include <clang/Parse/Parser.h>
#include <clang/Basic/TokenKinds.h>
Expand All @@ -47,35 +46,35 @@ namespace clazy {
/**
* Replaces whatever is in range, with replacement
*/
CLAZYLIB_EXPORT clang::FixItHint createReplacement(clang::SourceRange range, const std::string &replacement);
clang::FixItHint createReplacement(clang::SourceRange range, const std::string &replacement);

/**
* Inserts insertion at start
*/
CLAZYLIB_EXPORT clang::FixItHint createInsertion(clang::SourceLocation start, const std::string &insertion);
clang::FixItHint createInsertion(clang::SourceLocation start, const std::string &insertion);

/**
* Transforms foo into method(foo), by inserting "method(" at the beginning, and ')' at the end
*/
CLAZYLIB_EXPORT void insertParentMethodCall(const std::string &method, clang::SourceRange range, std::vector<clang::FixItHint> &fixits);
void insertParentMethodCall(const std::string &method, clang::SourceRange range, std::vector<clang::FixItHint> &fixits);

/**
* Transforms foo into method("literal"), by inserting "method(" at the beginning, and ')' at the end
* Takes into account multi-token literals such as "foo""bar"
*/
CLAZYLIB_EXPORT bool insertParentMethodCallAroundStringLiteral(const clang::ASTContext *context, const std::string &method, clang::StringLiteral *lt, std::vector<clang::FixItHint> &fixits);
bool insertParentMethodCallAroundStringLiteral(const clang::ASTContext *context, const std::string &method, clang::StringLiteral *lt, std::vector<clang::FixItHint> &fixits);

/**
* Returns the range this literal spans. Takes into account multi token literals, such as "foo""bar"
*/
CLAZYLIB_EXPORT clang::SourceRange rangeForLiteral(const clang::ASTContext *context, clang::StringLiteral *);
clang::SourceRange rangeForLiteral(const clang::ASTContext *context, clang::StringLiteral *);

/**
* Goes through all children of stmt and finds the biggests source location.
*/
CLAZYLIB_EXPORT clang::SourceLocation biggestSourceLocationInStmt(const clang::SourceManager &sm, clang::Stmt *stmt);
clang::SourceLocation biggestSourceLocationInStmt(const clang::SourceManager &sm, clang::Stmt *stmt);

CLAZYLIB_EXPORT clang::SourceLocation locForNextToken(const clang::ASTContext *context, clang::SourceLocation start, clang::tok::TokenKind kind);
clang::SourceLocation locForNextToken(const clang::ASTContext *context, clang::SourceLocation start, clang::tok::TokenKind kind);

/**
* Returns the end location of the token that starts at start.
Expand All @@ -87,26 +86,26 @@ CLAZYLIB_EXPORT clang::SourceLocation locForNextToken(const clang::ASTContext *c
* ^ // expr->getLocEnd()
* ^ // clazy::locForEndOfToken(expr->getLocStart())
*/
CLAZYLIB_EXPORT clang::SourceLocation locForEndOfToken(const clang::ASTContext *context, clang::SourceLocation start, int offset = 0);
clang::SourceLocation locForEndOfToken(const clang::ASTContext *context, clang::SourceLocation start, int offset = 0);

/**
* Transforms a call such as: foo("hello").bar() into baz("hello")
*/
CLAZYLIB_EXPORT bool transformTwoCallsIntoOne(const clang::ASTContext *context, clang::CallExpr *foo, clang::CXXMemberCallExpr *bar,
bool transformTwoCallsIntoOne(const clang::ASTContext *context, clang::CallExpr *foo, clang::CXXMemberCallExpr *bar,
const std::string &baz, std::vector<clang::FixItHint> &fixits);


/**
* Transforms a call such as: foo("hello").bar() into baz()
* This version basically replaces everything from start to end with baz.
*/
CLAZYLIB_EXPORT bool transformTwoCallsIntoOneV2(const clang::ASTContext *context, clang::CXXMemberCallExpr *bar,
bool transformTwoCallsIntoOneV2(const clang::ASTContext *context, clang::CXXMemberCallExpr *bar,
const std::string &baz, std::vector<clang::FixItHint> &fixits);

CLAZYLIB_EXPORT clang::FixItHint fixItReplaceWordWithWord(const clang::ASTContext *context, clang::Stmt *begin,
clang::FixItHint fixItReplaceWordWithWord(const clang::ASTContext *context, clang::Stmt *begin,
const std::string &replacement, const std::string &replacee);

CLAZYLIB_EXPORT std::vector<clang::FixItHint> fixItRemoveToken(const clang::ASTContext *context,
std::vector<clang::FixItHint> fixItRemoveToken(const clang::ASTContext *context,
clang::Stmt *stmt,
bool removeParenthesis);

Expand Down
1 change: 0 additions & 1 deletion src/HierarchyUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@

// Contains utility classes to retrieve parents and childs from AST Nodes

#include "clazy_export.h"
#include "clazy_stl.h"
#include "StringUtils.h"

Expand Down
15 changes: 7 additions & 8 deletions src/LoopUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
#define CLAZY_LOOP_UTILS_H

#include "clazy_stl.h"
#include "clazy_export.h"

#include <clang/AST/StmtCXX.h>
#include <clang/AST/Stmt.h>
Expand All @@ -45,20 +44,20 @@ namespace clazy {
/**
* Returns the body of a for, range-foor, while or do-while loop
*/
CLAZYLIB_EXPORT clang::Stmt *bodyFromLoop(clang::Stmt *);
clang::Stmt *bodyFromLoop(clang::Stmt *);

/**
* Recursively goes through stmt's children and returns true if it finds a "break", "continue" or a "return" stmt
* All child statements that are on a source code line <
* If onlyBeforThisLoc is valid, then this function will only return true if the break/return/continue happens before
*/
CLAZYLIB_EXPORT bool loopCanBeInterrupted(clang::Stmt *loop, const clang::SourceManager &sm,
clang::SourceLocation onlyBeforeThisLoc);
bool loopCanBeInterrupted(clang::Stmt *loop, const clang::SourceManager &sm,
clang::SourceLocation onlyBeforeThisLoc);

/**
* Returns true if stmt is a for, while or do-while loop
*/
CLAZYLIB_EXPORT inline bool isLoop(clang::Stmt *stmt)
inline bool isLoop(clang::Stmt *stmt)
{
return llvm::isa<clang::DoStmt>(stmt) || llvm::isa<clang::WhileStmt>(stmt) ||
llvm::isa<clang::ForStmt>(stmt) || llvm::isa<clang::CXXForRangeStmt>(stmt);
Expand All @@ -69,20 +68,20 @@ namespace clazy {
*
* Q_FOREACH (auto f, expression) or for (auto i : expression)
*/
CLAZYLIB_EXPORT clang::Expr* containerExprForLoop(clang::Stmt *loop);
clang::Expr* containerExprForLoop(clang::Stmt *loop);

/**
* Returns the container decl for a range-loop or Q_FOREACH
*
* Q_FOREACH (auto f, container) or for (auto i : container)
*/
CLAZYLIB_EXPORT clang::VarDecl* containerDeclForLoop(clang::Stmt *loop);
clang::VarDecl* containerDeclForLoop(clang::Stmt *loop);

/**
* Returns true of stmt is inside a for, while or do-while loop.
* If yes, returns the loop statement, otherwise nullptr.
*/
CLAZYLIB_EXPORT clang::Stmt* isInLoop(clang::ParentMap *pmap, clang::Stmt *stmt);
clang::Stmt* isInLoop(clang::ParentMap *pmap, clang::Stmt *stmt);
}

#endif
1 change: 0 additions & 1 deletion src/MacroUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
#ifndef CLAZY_MACRO_UTILS_H
#define CLAZY_MACRO_UTILS_H

#include "clazy_export.h"
#include "clazy_stl.h"

#include <clang/AST/ASTContext.h>
Expand Down
Loading

0 comments on commit 4c6c491

Please sign in to comment.