diff --git a/unittests/CMakeLists.txt b/unittests/CMakeLists.txt index 153f2f20b..2f7165b16 100644 --- a/unittests/CMakeLists.txt +++ b/unittests/CMakeLists.txt @@ -1,193 +1,193 @@ set(EXECUTABLE_OUTPUT_PATH ${CMAKE_CURRENT_BINARY_DIR}) set(SRC_PATH ../umbrello) include_directories( ${LIBXML2_INCLUDE_DIR} ${LIBXSLT_INCLUDE_DIR} ${CMAKE_SOURCE_DIR} ${SRC_PATH} ${SRC_PATH}/debug/ ${SRC_PATH}/dialogs/ ${SRC_PATH}/dialogs/pages ${SRC_PATH}/dialogs/widgets ${SRC_PATH}/clipboard ${SRC_PATH}/cmds ${SRC_PATH}/codegenerators ${SRC_PATH}/codegenerators/ada/ ${SRC_PATH}/codegenerators/as/ ${SRC_PATH}/codegenerators/cpp/ ${SRC_PATH}/codegenerators/csharp/ ${SRC_PATH}/codegenerators/d/ ${SRC_PATH}/codegenerators/idl/ ${SRC_PATH}/codegenerators/java/ ${SRC_PATH}/codegenerators/js/ ${SRC_PATH}/codegenerators/pascal/ ${SRC_PATH}/codegenerators/perl/ ${SRC_PATH}/codegenerators/php/ ${SRC_PATH}/codegenerators/python/ ${SRC_PATH}/codegenerators/ruby/ ${SRC_PATH}/codegenerators/sql/ ${SRC_PATH}/codegenerators/tcl/ ${SRC_PATH}/codegenerators/vala/ ${SRC_PATH}/codegenerators/xml/ ${SRC_PATH}/codegenwizard ${SRC_PATH}/codeimport ${SRC_PATH}/debug ${SRC_PATH}/dialogs ${SRC_PATH}/docgenerators ${SRC_PATH}/menus/ ${SRC_PATH}/refactoring ${SRC_PATH}/uml1model/ ${SRC_PATH}/umlwidgets/ ${CMAKE_CURRENT_BINARY_DIR} ) if(NOT BUILD_KF5) set(LIBS Qt4::QtCore Qt4::QtGui Qt4::QtXml Qt4::QtTest Qt4::QtWebKit ${KDE4_KFILE_LIBS} ${LIBXML2_LIBRARIES} ${LIBXSLT_LIBRARIES} libumbrello ) else() set(LIBS Qt5::Xml Qt5::Test Qt5::Widgets Qt5::WebKitWidgets KF5::I18n KF5::Crash ${LIBXML2_LIBRARIES} ${LIBXSLT_LIBRARIES} libumbrello ) endif() ecm_add_test( testbasictypes.cpp LINK_LIBRARIES ${LIBS} TEST_NAME testbasictypes ) ecm_add_test( testumlobject.cpp testbase.cpp LINK_LIBRARIES ${LIBS} TEST_NAME testumlobject ) ecm_add_test( testassociation.cpp testbase.cpp LINK_LIBRARIES ${LIBS} TEST_NAME testassociation ) ecm_add_test( testclassifier.cpp testbase.cpp LINK_LIBRARIES ${LIBS} TEST_NAME testclassifier ) ecm_add_test( testpackage.cpp testbase.cpp LINK_LIBRARIES ${LIBS} TEST_NAME testpackage ) ecm_add_test( testcppwriter.cpp testbase.cpp LINK_LIBRARIES ${LIBS} TEST_NAME testcppwriter ) ecm_add_test( testpythonwriter.cpp testbase.cpp LINK_LIBRARIES ${LIBS} TEST_NAME testpythonwriter ) ecm_add_test( testoptionstate.cpp testbase.cpp LINK_LIBRARIES ${LIBS} TEST_NAME testoptionstate ) ecm_add_test( testumlcanvasobject.cpp testbase.cpp LINK_LIBRARIES ${LIBS} TEST_NAME testumlcanvasobject ) ecm_add_test( testpreconditionwidget.cpp testbase.cpp LINK_LIBRARIES ${LIBS} TEST_NAME testpreconditionwidget ) set(testumlroledialog_SRCS testumlroledialog.cpp ) add_executable(testumlroledialog ${testumlroledialog_SRCS}) target_link_libraries(testumlroledialog ${LIBS}) add_executable(testcrashhandler testcrashhandler.cpp) target_link_libraries(testcrashhandler ${LIBS}) add_executable(testlistpopupmenu testlistpopupmenu.cpp testbase.cpp) target_link_libraries(testlistpopupmenu ${LIBS}) find_package(LLVM CONFIG) find_package(Clang CONFIG) if(NOT Clang_FOUND) find_package(CLANG QUIET) endif() -if(LLVM_FOUND AND (Clang_FOUND OR CLANG_FOUND) AND LLVM_VERSION VERSION_LESS "8.0.0") +if(LLVM_FOUND AND (Clang_FOUND OR CLANG_FOUND)) message(STATUS "Found LLVM ${LLVM_PACKAGE_VERSION}") message(STATUS "Using LLVMConfig.cmake in: ${LLVM_DIR}") message(STATUS "Found CLANG ${CLANG_PACKAGE_VERSION}") include_directories(${LLVM_INCLUDE_DIRS}) add_definitions(${LLVM_DEFINITIONS}) include_directories(${CLANG_INCLUDE_DIRS}) add_definitions(${CLANG_DEFINITIONS}) # Now build our tools add_executable(testllvm testllvm.cpp) # Find the libraries that correspond to the LLVM components # that we wish to use - if(LLVM_VERSION_MAJOR STREQUAL "7") + if(LLVM_PACKAGE_VERSION VERSION_GREATER_EQUAL "7.0.0") set(llvm_libs LLVM) else() llvm_map_components_to_libnames(llvm_libs support core irreader analysis) endif() # Link against LLVM libraries - target_link_libraries(testllvm ${llvm_libs} clangFrontend clangTooling clangBasic) + target_link_libraries(testllvm ${llvm_libs} clangFrontend clangTooling clangBasic clangSerialization) add_executable(testllvmparser testllvmparser.cpp) - if(NOT LLVM_VERSION_MAJOR STREQUAL "7") + if(LLVM_PACKAGE_VERSION VERSION_LESS "7.0.0") llvm_map_components_to_libnames(llvm_libs support) endif() - target_link_libraries(testllvmparser ${llvm_libs} clangFrontend clangTooling clangAST clangBasic ${LIBS}) + target_link_libraries(testllvmparser ${llvm_libs} clangFrontend clangTooling clangAST clangBasic clangSerialization ${LIBS}) ecm_mark_nongui_executable(testllvm testllvmparser) endif() add_custom_target(check COMMAND ${CMAKE_BUILD_TOOL} test) diff --git a/unittests/testllvmparser.cpp b/unittests/testllvmparser.cpp index 66107bade..dfaaed081 100644 --- a/unittests/testllvmparser.cpp +++ b/unittests/testllvmparser.cpp @@ -1,103 +1,108 @@ /* Copyright 2016 Ralf Habacker This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License or (at your option) version 3 or any later version accepted by the membership of KDE e.V. (or its successor approved by the membership of KDE e.V.), which shall act as a proxy defined in Section 14 of version 3 of the license. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #include "clang/AST/ASTConsumer.h" #include "clang/AST/RecursiveASTVisitor.h" +#include #include "clang/Frontend/CompilerInstance.h" #include "clang/Frontend/FrontendAction.h" #include "clang/Tooling/Tooling.h" #include #include using namespace clang; class FindNamedClassVisitor : public RecursiveASTVisitor { public: explicit FindNamedClassVisitor(ASTContext *Context) : Context(Context) { } bool VisitStmt(Stmt *s) { s->dump(); return true; } bool VisitCXXRecordDecl(CXXRecordDecl *Declaration) { if (Declaration->getQualifiedNameAsString() == "n::m::C") { +#if CLANG_VERSION_MAJOR >= 8 + FullSourceLoc FullLocation = Context->getFullLoc(Declaration->getBeginLoc()); +#else FullSourceLoc FullLocation = Context->getFullLoc(Declaration->getLocStart()); +#endif if (FullLocation.isValid()) llvm::outs() << "Found declaration at " << FullLocation.getSpellingLineNumber() << ":" << FullLocation.getSpellingColumnNumber() << "\n"; } return true; } private: ASTContext *Context; }; class FindNamedClassConsumer : public clang::ASTConsumer { public: explicit FindNamedClassConsumer(ASTContext *Context) : Visitor(Context) { } virtual void HandleTranslationUnit(clang::ASTContext &Context) { if (!Visitor.TraverseDecl(Context.getTranslationUnitDecl())) llvm::errs() << "could not parse file"; } private: FindNamedClassVisitor Visitor; }; class FindNamedClassAction : public clang::ASTFrontendAction { public: virtual std::unique_ptr CreateASTConsumer(clang::CompilerInstance &Compiler, llvm::StringRef InFile) { Q_UNUSED(InFile); return std::unique_ptr( new FindNamedClassConsumer(&Compiler.getASTContext())); } }; int main(int argc, char **argv) { QByteArray defaultSource = "namespace n {\n namespace m {\n class C {}; \n} \n}"; if (argc > 1) { QFile source(argv[1]); if (!source.open(QFile::ReadOnly)) return 1; defaultSource = source.readAll(); } return clang::tooling::runToolOnCode(new FindNamedClassAction, defaultSource.data()) ? 0 : 2; }