[PATCH] D147875: [clang][Diagnostics] Show line numbers when printing code snippets

2023-05-04 Thread Konrad Wilhelm Kleine via Phabricator via cfe-commits
kwk added a comment.

@tbaeder I have a small suggestion.




Comment at: clang/lib/Frontend/TextDiagnostic.cpp:1121-1138
+static unsigned getNumDisplayWidth(unsigned N) {
+  if (N < 10)
+return 1;
+  if (N < 100)
+return 2;
+  if (N < 1'000)
+return 3;

This function screamed at me to be generalized so I gave it a try: 
https://gist.github.com/kwk/7e408065ea291e49fea4a83cf90a9cdf


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D147875/new/

https://reviews.llvm.org/D147875

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D149641: [docs] Hide collaboration and include graphs in doxygen docs

2023-05-04 Thread Konrad Wilhelm Kleine via Phabricator via cfe-commits
kwk accepted this revision.
kwk added a comment.

LGTM


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D149641/new/

https://reviews.llvm.org/D149641

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D138472: clang/cmake: Use installed gtest libraries for stand-alone builds

2023-01-25 Thread Konrad Wilhelm Kleine via Phabricator via cfe-commits
kwk accepted this revision.
kwk added a comment.
This revision is now accepted and ready to land.

Working for me.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D138472/new/

https://reviews.llvm.org/D138472

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D141581: [clang] Make clangBasic and clangDriver depend on LLVMTargetParser.

2023-01-23 Thread Konrad Wilhelm Kleine via Phabricator via cfe-commits
kwk added a comment.

In D141581#4071617 , @thesamesam 
wrote:

> This is currently holding back further testing on our end which is concerning 
> me a bit, especially as we approach the branch point. Could you revert this 
> please if a fix isn't imminent? Thank you!

@thesamesam what do you mean with "revert"? Just by looking at this 
differential I cannot see that this patch has landed. Has it?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D141581/new/

https://reviews.llvm.org/D141581

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D141581: [clang] Make clangBasic and clangDriver depend on LLVMTargetParser.

2023-01-20 Thread Konrad Wilhelm Kleine via Phabricator via cfe-commits
kwk added a comment.

@tstellar as you suspected, I had the following problem when building clang in 
standalone mode and your patch solved it for me. Thank you.

  -- Configuring done
  CMake Error at /usr/lib64/cmake/llvm/AddLLVM.cmake:536 (add_dependencies):
The dependency target "RISCVTargetParserTableGen" of target
"obj.clangBasic" does not exist.
  Call Stack (most recent call first):
cmake/modules/AddClang.cmake:106 (llvm_add_library)
lib/Basic/CMakeLists.txt:40 (add_clang_library)
  
  
  CMake Error at /usr/lib64/cmake/llvm/AddLLVM.cmake:719 (add_dependencies):
The dependency target "RISCVTargetParserTableGen" of target "clangBasic"
does not exist.
  Call Stack (most recent call first):
cmake/modules/AddClang.cmake:106 (llvm_add_library)
lib/Basic/CMakeLists.txt:40 (add_clang_library)
  
  
  CMake Error at /usr/lib64/cmake/llvm/AddLLVM.cmake:536 (add_dependencies):
The dependency target "RISCVTargetParserTableGen" of target
"obj.clangDriver" does not exist.
  Call Stack (most recent call first):
cmake/modules/AddClang.cmake:106 (llvm_add_library)
lib/Driver/CMakeLists.txt:17 (add_clang_library)
  
  
  CMake Error at /usr/lib64/cmake/llvm/AddLLVM.cmake:719 (add_dependencies):
The dependency target "RISCVTargetParserTableGen" of target "clangDriver"
does not exist.
  Call Stack (most recent call first):
cmake/modules/AddClang.cmake:106 (llvm_add_library)
lib/Driver/CMakeLists.txt:17 (add_clang_library)


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D141581/new/

https://reviews.llvm.org/D141581

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D141050: [standalone-build] outsource, simplify and unify repetitive CMake code

2023-01-12 Thread Konrad Wilhelm Kleine via Phabricator via cfe-commits
kwk updated this revision to Diff 488582.
kwk added a comment.

- both, build tree and install method support find_package by setting different 
LLVM_CMAKE_DIR


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D141050/new/

https://reviews.llvm.org/D141050

Files:
  clang/CMakeLists.txt
  cmake/Modules/StandaloneBuildHelpers.cmake
  lld/CMakeLists.txt

Index: lld/CMakeLists.txt
===
--- lld/CMakeLists.txt
+++ lld/CMakeLists.txt
@@ -23,23 +23,16 @@
 # Must go below project(..)
 include(GNUInstallDirs)
 
-if(LLD_BUILT_STANDALONE)
-  set(CMAKE_CXX_STANDARD 17 CACHE STRING "C++ standard to conform to")
-  set(CMAKE_CXX_STANDARD_REQUIRED YES)
-  set(CMAKE_CXX_EXTENSIONS NO)
-
-  set(CMAKE_INCLUDE_CURRENT_DIR ON)
-
-  find_package(LLVM REQUIRED HINTS "${LLVM_CMAKE_DIR}")
-  list(APPEND CMAKE_MODULE_PATH "${LLVM_DIR}")
-
-  # Turn into CACHE PATHs for overwritting
-  set(LLVM_INCLUDE_DIRS ${LLVM_INCLUDE_DIRS} CACHE PATH "Path to llvm/include and any other header dirs needed")
-  set(LLVM_BINARY_DIR "${LLVM_BINARY_DIR}" CACHE PATH "Path to LLVM build tree")
-  set(LLVM_MAIN_SRC_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../llvm" CACHE PATH "Path to LLVM source tree")
+# Make sure that our source directory is on the current cmake module path so that
+# we can include cmake files from this directory.
+list(INSERT CMAKE_MODULE_PATH 0
+  "${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules"
+  "${LLVM_COMMON_CMAKE_UTILS}/Modules"
+  )
 
-  find_program(LLVM_TABLEGEN_EXE "llvm-tblgen" ${LLVM_TOOLS_BINARY_DIR}
-NO_DEFAULT_PATH)
+if(LLD_BUILT_STANDALONE)
+  include(StandaloneBuildHelpers)
+  require_llvm_utility_binary_path("llvm-tblgen" LLVM_TABLEGEN_EXE)
 
   # They are used as destination of target generators.
   set(LLVM_RUNTIME_OUTPUT_INTDIR ${CMAKE_BINARY_DIR}/${CMAKE_CFG_INTDIR}/bin)
@@ -59,53 +52,17 @@
   if(LLVM_INCLUDE_TESTS)
 find_package(Python3 ${LLVM_MINIMUM_PYTHON_VERSION} REQUIRED
   COMPONENTS Interpreter)
-
-# Check prebuilt llvm/utils.
-if(EXISTS ${LLVM_TOOLS_BINARY_DIR}/FileCheck${CMAKE_EXECUTABLE_SUFFIX}
-AND EXISTS ${LLVM_TOOLS_BINARY_DIR}/not${CMAKE_EXECUTABLE_SUFFIX})
-  set(LLVM_UTILS_PROVIDED ON)
-endif()
-
-if(EXISTS ${LLVM_MAIN_SRC_DIR}/utils/lit/lit.py)
-  # Note: path not really used, except for checking if lit was found
-  set(LLVM_LIT ${LLVM_MAIN_SRC_DIR}/utils/lit/lit.py)
-  if(NOT LLVM_UTILS_PROVIDED)
-add_subdirectory(${LLVM_MAIN_SRC_DIR}/utils/FileCheck utils/FileCheck)
-add_subdirectory(${LLVM_MAIN_SRC_DIR}/utils/not utils/not)
-set(LLVM_UTILS_PROVIDED ON)
-set(LLD_TEST_DEPS FileCheck not)
-  endif()
-  set(UNITTEST_DIR ${LLVM_THIRD_PARTY_DIR}/unittest)
-  if(EXISTS ${UNITTEST_DIR}/googletest/include/gtest/gtest.h
-  AND NOT EXISTS ${LLVM_LIBRARY_DIR}/${CMAKE_STATIC_LIBRARY_PREFIX}gtest${CMAKE_STATIC_LIBRARY_SUFFIX}
-  AND EXISTS ${UNITTEST_DIR}/CMakeLists.txt)
-add_subdirectory(${UNITTEST_DIR} third-party/unittest)
-  endif()
-else()
-  # Seek installed Lit.
-  find_program(LLVM_LIT
-   NAMES llvm-lit lit.py lit
-   PATHS "${LLVM_MAIN_SRC_DIR}/utils/lit"
-   DOC "Path to lit.py")
-endif()
-
-if(LLVM_LIT)
-  # Define the default arguments to use with 'lit', and an option for the user
-  # to override.
-  set(LIT_ARGS_DEFAULT "-sv")
-  if (MSVC OR XCODE)
-set(LIT_ARGS_DEFAULT "${LIT_ARGS_DEFAULT} --no-progress-bar")
-  endif()
-  set(LLVM_LIT_ARGS "${LIT_ARGS_DEFAULT}" CACHE STRING "Default options for lit")
-
-  get_errc_messages(LLVM_LIT_ERRC_MESSAGES)
-
-  # On Win32 hosts, provide an option to specify the path to the GnuWin32 tools.
-  if(WIN32 AND NOT CYGWIN)
-set(LLVM_LIT_TOOLS_DIR "" CACHE PATH "Path to GnuWin32 tools")
-  endif()
-else()
-  set(LLVM_INCLUDE_TESTS OFF)
+find_external_lit()
+set_lit_defaults()
+require_llvm_utility_binary_path("FileCheck")
+require_llvm_utility_binary_path("count")
+require_llvm_utility_binary_path("not")
+
+set(UNITTEST_DIR ${LLVM_THIRD_PARTY_DIR}/unittest)
+if(EXISTS ${UNITTEST_DIR}/googletest/include/gtest/gtest.h
+AND NOT EXISTS ${LLVM_LIBRARY_DIR}/${CMAKE_STATIC_LIBRARY_PREFIX}gtest${CMAKE_STATIC_LIBRARY_SUFFIX}
+AND EXISTS ${UNITTEST_DIR}/CMakeLists.txt)
+  add_subdirectory(${UNITTEST_DIR} third-party/unittest)
 endif()
   endif()
 
@@ -153,12 +110,6 @@
 "`CMakeFiles'. Please delete them.")
 endif()
 
-# Add path for custom modules.
-list(INSERT CMAKE_MODULE_PATH 0
-  "${LLD_SOURCE_DIR}/cmake/modules"
-  "${LLVM_COMMON_CMAKE_UTILS}/Modules"
-  )
-
 include(AddLLD)
 
 option(LLD_USE_VTUNE
Index: cmake/Modules/StandaloneBuildHelpers.cmake
===
--- /dev/null
+++ 

[PATCH] D141050: [standalone-build] outsource, simplify and unify repetitive CMake code

2023-01-10 Thread Konrad Wilhelm Kleine via Phabricator via cfe-commits
kwk updated this revision to Diff 487826.
kwk added a comment.

- Make require_llvm_utility_binary_path usable from a build-tree setup


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D141050/new/

https://reviews.llvm.org/D141050

Files:
  clang/CMakeLists.txt
  cmake/Modules/StandaloneBuildHelpers.cmake
  lld/CMakeLists.txt

Index: lld/CMakeLists.txt
===
--- lld/CMakeLists.txt
+++ lld/CMakeLists.txt
@@ -23,23 +23,16 @@
 # Must go below project(..)
 include(GNUInstallDirs)
 
-if(LLD_BUILT_STANDALONE)
-  set(CMAKE_CXX_STANDARD 17 CACHE STRING "C++ standard to conform to")
-  set(CMAKE_CXX_STANDARD_REQUIRED YES)
-  set(CMAKE_CXX_EXTENSIONS NO)
-
-  set(CMAKE_INCLUDE_CURRENT_DIR ON)
-
-  find_package(LLVM REQUIRED HINTS "${LLVM_CMAKE_DIR}")
-  list(APPEND CMAKE_MODULE_PATH "${LLVM_DIR}")
-
-  # Turn into CACHE PATHs for overwritting
-  set(LLVM_INCLUDE_DIRS ${LLVM_INCLUDE_DIRS} CACHE PATH "Path to llvm/include and any other header dirs needed")
-  set(LLVM_BINARY_DIR "${LLVM_BINARY_DIR}" CACHE PATH "Path to LLVM build tree")
-  set(LLVM_MAIN_SRC_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../llvm" CACHE PATH "Path to LLVM source tree")
+# Make sure that our source directory is on the current cmake module path so that
+# we can include cmake files from this directory.
+list(INSERT CMAKE_MODULE_PATH 0
+  "${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules"
+  "${LLVM_COMMON_CMAKE_UTILS}/Modules"
+  )
 
-  find_program(LLVM_TABLEGEN_EXE "llvm-tblgen" ${LLVM_TOOLS_BINARY_DIR}
-NO_DEFAULT_PATH)
+if(LLD_BUILT_STANDALONE)
+  include(StandaloneBuildHelpers)
+  require_llvm_utility_binary_path("llvm-tblgen" LLVM_TABLEGEN_EXE)
 
   # They are used as destination of target generators.
   set(LLVM_RUNTIME_OUTPUT_INTDIR ${CMAKE_BINARY_DIR}/${CMAKE_CFG_INTDIR}/bin)
@@ -59,53 +52,17 @@
   if(LLVM_INCLUDE_TESTS)
 find_package(Python3 ${LLVM_MINIMUM_PYTHON_VERSION} REQUIRED
   COMPONENTS Interpreter)
-
-# Check prebuilt llvm/utils.
-if(EXISTS ${LLVM_TOOLS_BINARY_DIR}/FileCheck${CMAKE_EXECUTABLE_SUFFIX}
-AND EXISTS ${LLVM_TOOLS_BINARY_DIR}/not${CMAKE_EXECUTABLE_SUFFIX})
-  set(LLVM_UTILS_PROVIDED ON)
-endif()
-
-if(EXISTS ${LLVM_MAIN_SRC_DIR}/utils/lit/lit.py)
-  # Note: path not really used, except for checking if lit was found
-  set(LLVM_LIT ${LLVM_MAIN_SRC_DIR}/utils/lit/lit.py)
-  if(NOT LLVM_UTILS_PROVIDED)
-add_subdirectory(${LLVM_MAIN_SRC_DIR}/utils/FileCheck utils/FileCheck)
-add_subdirectory(${LLVM_MAIN_SRC_DIR}/utils/not utils/not)
-set(LLVM_UTILS_PROVIDED ON)
-set(LLD_TEST_DEPS FileCheck not)
-  endif()
-  set(UNITTEST_DIR ${LLVM_THIRD_PARTY_DIR}/unittest)
-  if(EXISTS ${UNITTEST_DIR}/googletest/include/gtest/gtest.h
-  AND NOT EXISTS ${LLVM_LIBRARY_DIR}/${CMAKE_STATIC_LIBRARY_PREFIX}gtest${CMAKE_STATIC_LIBRARY_SUFFIX}
-  AND EXISTS ${UNITTEST_DIR}/CMakeLists.txt)
-add_subdirectory(${UNITTEST_DIR} third-party/unittest)
-  endif()
-else()
-  # Seek installed Lit.
-  find_program(LLVM_LIT
-   NAMES llvm-lit lit.py lit
-   PATHS "${LLVM_MAIN_SRC_DIR}/utils/lit"
-   DOC "Path to lit.py")
-endif()
-
-if(LLVM_LIT)
-  # Define the default arguments to use with 'lit', and an option for the user
-  # to override.
-  set(LIT_ARGS_DEFAULT "-sv")
-  if (MSVC OR XCODE)
-set(LIT_ARGS_DEFAULT "${LIT_ARGS_DEFAULT} --no-progress-bar")
-  endif()
-  set(LLVM_LIT_ARGS "${LIT_ARGS_DEFAULT}" CACHE STRING "Default options for lit")
-
-  get_errc_messages(LLVM_LIT_ERRC_MESSAGES)
-
-  # On Win32 hosts, provide an option to specify the path to the GnuWin32 tools.
-  if(WIN32 AND NOT CYGWIN)
-set(LLVM_LIT_TOOLS_DIR "" CACHE PATH "Path to GnuWin32 tools")
-  endif()
-else()
-  set(LLVM_INCLUDE_TESTS OFF)
+find_external_lit()
+set_lit_defaults()
+require_llvm_utility_binary_path("FileCheck")
+require_llvm_utility_binary_path("count")
+require_llvm_utility_binary_path("not")
+
+set(UNITTEST_DIR ${LLVM_THIRD_PARTY_DIR}/unittest)
+if(EXISTS ${UNITTEST_DIR}/googletest/include/gtest/gtest.h
+AND NOT EXISTS ${LLVM_LIBRARY_DIR}/${CMAKE_STATIC_LIBRARY_PREFIX}gtest${CMAKE_STATIC_LIBRARY_SUFFIX}
+AND EXISTS ${UNITTEST_DIR}/CMakeLists.txt)
+  add_subdirectory(${UNITTEST_DIR} third-party/unittest)
 endif()
   endif()
 
@@ -153,12 +110,6 @@
 "`CMakeFiles'. Please delete them.")
 endif()
 
-# Add path for custom modules.
-list(INSERT CMAKE_MODULE_PATH 0
-  "${LLD_SOURCE_DIR}/cmake/modules"
-  "${LLVM_COMMON_CMAKE_UTILS}/Modules"
-  )
-
 include(AddLLD)
 
 option(LLD_USE_VTUNE
Index: cmake/Modules/StandaloneBuildHelpers.cmake
===
--- /dev/null
+++ cmake/Modules/StandaloneBuildHelpers.cmake
@@ -0,0 

[PATCH] D141050: [standalone-build] outsource, simplify and unify repetitive CMake code

2023-01-10 Thread Konrad Wilhelm Kleine via Phabricator via cfe-commits
kwk added a comment.

Thank you @phosek for your review! I really appreciate it. I've addressed all 
of your comments. Could you give it another review?




Comment at: clang/CMakeLists.txt:35
+  include(StandaloneBuildHelpers)
+  get_llvm_utility_binary_path("llvm-tblgen" "LLVM_TABLEGEN_EXE")
 

phosek wrote:
> It's somewhat unusual to quote output variable names in our CMake files, I'd 
> prefer to follow existing conventions for consistency.
I obey to the consistency.



Comment at: cmake/Modules/StandaloneBuildHelpers.cmake:12-19
+if (NOT (CLANG_BUILT_STANDALONE
+ OR LLD_BUILT_STANDALONE
+ OR COMPILER_RT_STANDALONE_BUILD
+ OR OPENMP_STANDALONE_BUILD
+ OR MLIR_STANDALONE_BUILD
+ OR LLDB_BUILT_STANDALONE))
+message(FATAL_ERROR "Make sure you build in standalone mode")

phosek wrote:
> I'd omit this, I don't think it's necessary to restrict the usage of this 
> module.
I think restricting the usage makes it clear for what it is. And right now this 
CMake file does stuff just when you include it which not a good thing in terms 
of isolation. If you don't mind I'd like to keep this restriction and only 
remove it before this patch lands in a better shape. Okay?



Comment at: cmake/Modules/StandaloneBuildHelpers.cmake:25-30
+if(NOT MSVC_IDE)
+set(LLVM_ENABLE_ASSERTIONS ${ENABLE_ASSERTIONS}
+  CACHE BOOL "Enable assertions")
+# Assertions should follow llvm-config's.
+mark_as_advanced(LLVM_ENABLE_ASSERTIONS)
+endif()

phosek wrote:
> Do you know why is this needed or this just copy pasted from Clang? I'd 
> consider dropping this altogether (ideally in a separate change).
Honestly, I started to move the CMake code from clang over to this file piece 
by piece once I found that the exact or similar formatted code existed in other 
projects like lld. But you caught me red-handed :).

This is the patch that introduced this particular section: [[ 
https://github.com/llvm/llvm-project/commit/e6d79ec0ebac350355c76d8132e9f1cce62e0cac
 | e6d79ec0ebac350355c76d8132e9f1cce62e0cac ]]. It is from 2013.

I'm not so long involved in the llvm project that I can give a solid answer to 
this but hasn't llvm-config been deprecated for building LLVM itself? If that 
is the case, I'm happy to remove this section from the `clang/CMakeLists.txt` 
in the first place in a separate patch. 



Comment at: cmake/Modules/StandaloneBuildHelpers.cmake:45-46
+
+# Automatically add the current source and build directories to the include 
path.
+set(CMAKE_INCLUDE_CURRENT_DIR ON)
+

phosek wrote:
> This shouldn't be needed since you've already had to insert the module path 
> manually.
I don't see what the one has to do with the other immediately. Maybe I'm a 
fool. The `CMAKE_INCLUDE_CURRENT_DIR` is for including C/C++ files and not 
CMake files so it doesn't matter what I have in my module path, no?. Here's a 
little example project I created to proof to myself that my assumption is 
really true: https://github.com/kwk/cmake-example-CMAKE_INCLUDE_CURRENT_DIR . 
Just run `make` once you've clone it. Then comment out [[ 
https://github.com/kwk/cmake-example-CMAKE_INCLUDE_CURRENT_DIR/blob/main/src/CMakeLists.txt#L10
 | this line ]] to see the effect: `include(EnableCurrentIncludeDir)`.



Comment at: cmake/Modules/StandaloneBuildHelpers.cmake:61
+function(get_llvm_utility_binary_path utility out_var)
+set(_imploc IMPORTED_LOCATION_NOCONFIG)
+# Based on the build type that the installed LLVM was built with,

phosek wrote:
> We use 2 spaces for indentation in our CMake files.
I've fixed the indention to use 2 spaces.



Comment at: cmake/Modules/StandaloneBuildHelpers.cmake:82-109
+# The set_lit_defaults macro exists because the code existed in multiple
+# locations before.
+macro(set_lit_defaults)
+set(LIT_ARGS_DEFAULT "-sv")
+if (MSVC OR XCODE)
+  set(LIT_ARGS_DEFAULT "${LIT_ARGS_DEFAULT} --no-progress-bar")
+endif()

phosek wrote:
> Is there any reason to keep these two macros separate? Could we combine them?
Yes, to both of your questions :) . Yes, I find it easier to read the files 
that include this file and use the functions and macros when they are 
separated. And yes, we could combine them to `setup_external_lit` or something 
alike. But for the course of this patch I'd like to keep them separated and do 
the merge later if you don't mind.



Comment at: lld/CMakeLists.txt:57
+set_lit_defaults()
+get_llvm_utility_binary_path("FileCheck" "FileCheck_EXE")
+get_llvm_utility_binary_path("count" "count_EXE")

phosek wrote:
> Where are these variables being used?
They were not being used, yet. I forgot to make the second parameter of 
`get_llvm_utility_binary_path` an optional one. Now it is optional and you can 
omit the second parameter. 

[PATCH] D141050: [standalone-build] outsource, simplify and unify repetitive CMake code

2023-01-10 Thread Konrad Wilhelm Kleine via Phabricator via cfe-commits
kwk updated this revision to Diff 487750.
kwk marked 2 inline comments as done.
kwk added a comment.

- Don't quote output variables
- Use 2 space indention in CMake files
- Make out_var optional for get_llvm_utility_binary_path
- Rename get_llvm_utility_binary_path -> require_llvm_utility_binary_path


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D141050/new/

https://reviews.llvm.org/D141050

Files:
  clang/CMakeLists.txt
  cmake/Modules/StandaloneBuildHelpers.cmake
  lld/CMakeLists.txt

Index: lld/CMakeLists.txt
===
--- lld/CMakeLists.txt
+++ lld/CMakeLists.txt
@@ -23,23 +23,16 @@
 # Must go below project(..)
 include(GNUInstallDirs)
 
-if(LLD_BUILT_STANDALONE)
-  set(CMAKE_CXX_STANDARD 17 CACHE STRING "C++ standard to conform to")
-  set(CMAKE_CXX_STANDARD_REQUIRED YES)
-  set(CMAKE_CXX_EXTENSIONS NO)
-
-  set(CMAKE_INCLUDE_CURRENT_DIR ON)
-
-  find_package(LLVM REQUIRED HINTS "${LLVM_CMAKE_DIR}")
-  list(APPEND CMAKE_MODULE_PATH "${LLVM_DIR}")
-
-  # Turn into CACHE PATHs for overwritting
-  set(LLVM_INCLUDE_DIRS ${LLVM_INCLUDE_DIRS} CACHE PATH "Path to llvm/include and any other header dirs needed")
-  set(LLVM_BINARY_DIR "${LLVM_BINARY_DIR}" CACHE PATH "Path to LLVM build tree")
-  set(LLVM_MAIN_SRC_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../llvm" CACHE PATH "Path to LLVM source tree")
+# Make sure that our source directory is on the current cmake module path so that
+# we can include cmake files from this directory.
+list(INSERT CMAKE_MODULE_PATH 0
+  "${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules"
+  "${LLVM_COMMON_CMAKE_UTILS}/Modules"
+  )
 
-  find_program(LLVM_TABLEGEN_EXE "llvm-tblgen" ${LLVM_TOOLS_BINARY_DIR}
-NO_DEFAULT_PATH)
+if(LLD_BUILT_STANDALONE)
+  include(StandaloneBuildHelpers)
+  require_llvm_utility_binary_path("llvm-tblgen" LLVM_TABLEGEN_EXE)
 
   # They are used as destination of target generators.
   set(LLVM_RUNTIME_OUTPUT_INTDIR ${CMAKE_BINARY_DIR}/${CMAKE_CFG_INTDIR}/bin)
@@ -59,53 +52,17 @@
   if(LLVM_INCLUDE_TESTS)
 find_package(Python3 ${LLVM_MINIMUM_PYTHON_VERSION} REQUIRED
   COMPONENTS Interpreter)
-
-# Check prebuilt llvm/utils.
-if(EXISTS ${LLVM_TOOLS_BINARY_DIR}/FileCheck${CMAKE_EXECUTABLE_SUFFIX}
-AND EXISTS ${LLVM_TOOLS_BINARY_DIR}/not${CMAKE_EXECUTABLE_SUFFIX})
-  set(LLVM_UTILS_PROVIDED ON)
-endif()
-
-if(EXISTS ${LLVM_MAIN_SRC_DIR}/utils/lit/lit.py)
-  # Note: path not really used, except for checking if lit was found
-  set(LLVM_LIT ${LLVM_MAIN_SRC_DIR}/utils/lit/lit.py)
-  if(NOT LLVM_UTILS_PROVIDED)
-add_subdirectory(${LLVM_MAIN_SRC_DIR}/utils/FileCheck utils/FileCheck)
-add_subdirectory(${LLVM_MAIN_SRC_DIR}/utils/not utils/not)
-set(LLVM_UTILS_PROVIDED ON)
-set(LLD_TEST_DEPS FileCheck not)
-  endif()
-  set(UNITTEST_DIR ${LLVM_THIRD_PARTY_DIR}/unittest)
-  if(EXISTS ${UNITTEST_DIR}/googletest/include/gtest/gtest.h
-  AND NOT EXISTS ${LLVM_LIBRARY_DIR}/${CMAKE_STATIC_LIBRARY_PREFIX}gtest${CMAKE_STATIC_LIBRARY_SUFFIX}
-  AND EXISTS ${UNITTEST_DIR}/CMakeLists.txt)
-add_subdirectory(${UNITTEST_DIR} third-party/unittest)
-  endif()
-else()
-  # Seek installed Lit.
-  find_program(LLVM_LIT
-   NAMES llvm-lit lit.py lit
-   PATHS "${LLVM_MAIN_SRC_DIR}/utils/lit"
-   DOC "Path to lit.py")
-endif()
-
-if(LLVM_LIT)
-  # Define the default arguments to use with 'lit', and an option for the user
-  # to override.
-  set(LIT_ARGS_DEFAULT "-sv")
-  if (MSVC OR XCODE)
-set(LIT_ARGS_DEFAULT "${LIT_ARGS_DEFAULT} --no-progress-bar")
-  endif()
-  set(LLVM_LIT_ARGS "${LIT_ARGS_DEFAULT}" CACHE STRING "Default options for lit")
-
-  get_errc_messages(LLVM_LIT_ERRC_MESSAGES)
-
-  # On Win32 hosts, provide an option to specify the path to the GnuWin32 tools.
-  if(WIN32 AND NOT CYGWIN)
-set(LLVM_LIT_TOOLS_DIR "" CACHE PATH "Path to GnuWin32 tools")
-  endif()
-else()
-  set(LLVM_INCLUDE_TESTS OFF)
+find_external_lit()
+set_lit_defaults()
+require_llvm_utility_binary_path("FileCheck")
+require_llvm_utility_binary_path("count")
+require_llvm_utility_binary_path("not")
+
+set(UNITTEST_DIR ${LLVM_THIRD_PARTY_DIR}/unittest)
+if(EXISTS ${UNITTEST_DIR}/googletest/include/gtest/gtest.h
+AND NOT EXISTS ${LLVM_LIBRARY_DIR}/${CMAKE_STATIC_LIBRARY_PREFIX}gtest${CMAKE_STATIC_LIBRARY_SUFFIX}
+AND EXISTS ${UNITTEST_DIR}/CMakeLists.txt)
+  add_subdirectory(${UNITTEST_DIR} third-party/unittest)
 endif()
   endif()
 
@@ -153,12 +110,6 @@
 "`CMakeFiles'. Please delete them.")
 endif()
 
-# Add path for custom modules.
-list(INSERT CMAKE_MODULE_PATH 0
-  "${LLD_SOURCE_DIR}/cmake/modules"
-  "${LLVM_COMMON_CMAKE_UTILS}/Modules"
-  )
-
 include(AddLLD)
 
 option(LLD_USE_VTUNE
Index: 

[PATCH] D141050: [standalone-build] outsource, simplify and unify repetitive CMake code

2023-01-05 Thread Konrad Wilhelm Kleine via Phabricator via cfe-commits
kwk created this revision.
kwk added reviewers: tstellar, phosek.
Herald added subscribers: bzcheeseman, rriddle.
Herald added a project: All.
kwk requested review of this revision.
Herald added subscribers: cfe-commits, stephenneuendorffer.
Herald added a project: clang.

Rationale
=

This is an opinionated change for the standalone build mode CMake code.

The rationale behind this change is to unify the parts of standalone
builds that historically had to be kept in each and every project. With
the advent of the top-level `cmake` directory inside the LLVM source
tree, it is now possible to bundle the CMake instructions into a file,
aka `cmake/Modules/StandaloneBuildHelpers.cmake`, and include that file
in each project that wants to build in standalone-mode.

Historically the standalone build mode is used mostly by Linux
distributions. Certainly not every LLVM contributor cares about Linux
distributions. To reduce the frictions it makes even more sense to have
a unified place where to keep the specialities of building in standalone
mode.

Affected projects (so far)
--

This change brings the unified standalone build mode to the clang and
lld project.

Assumptions
===

One radical assumption for this change is that in order to build clang
or ldd in standalone mode, you have to first build the `llvm` subproject
and *install* it into any location. You can assist the build process to
find LLVM using `find_package(LLVM)` by specifying
`-DCMAKE_PREFIX_PATH=${LLVM_INSTALL_DIR}/lib/cmake/llvm` in the cmake
configuration process.
You have to build the `llvm subproject with utilies included and
installed
(`-DLLVM_INCLUDE_UTILS:BOOL=ON` and `-DLLVM_INSTALL_UTILS:BOOL=ON`. But
I'm sure that this is done most of the time anyways, no?

Don't build as you go: No more cross-project dependencies on LLVM utilties
--

Another assumption is that in standalone build mode it makes no sense to
build clang and try to build an LLVM utility binary like `FileCheck` if
that is missing. This only adds noise to the cmake files and creates an
indirect dependency on the LLVM utilities directory which doesn't exist
in the the clang source tarball. Therefore we go and search for

Don't silently turn off tests
-

Before this change, we would silently turn off tests if a binary like
`FileCheck`, `count` or `not` was missing. This is not only dangerous
but IMHO not helpful. If someone asks for tests by passing
`-DLLVM_INCLUDE_TESTS=On` we should error out at configure time because
we cannot fulfil this request when a binary is missing. This is exactly
what this tests does. If you want to check if an LLVM utility binary
exists and what the path to it is, you can call
`get_llvm_utility_binary_path("FileCheck" "FileCheck_EXE")` and it will
get the import location for the target, aka the path to the binary that
was found when we did `find_package(LLVM)`.

NOTE: You can take a look at this small example project which shows you
how importing of an installed project works:
https://github.com/kwk/cmake-export-binary-example/blob/2b429fccef97eb93c1717ceddb27bbe0022339d2/project-b/CMakeLists.txt#L7-L10



Require external LIT in standalone mode
---

We also think that in standalone mode you always want to use an external
lit and not build it as you go. That's why the `find_external_lit` macro
checks if `LLVM_EXTERNAL_LIT` is set and the path exists. If one of
these conditions doesn't hold true, we error out.

TODO:

( ) make sure the correct binaries of `FileCheck` and `count` and `not`
get substituted in lit test files.
( ) get feedback on this change or just opinions
( ) extend usage to other projects like `mlir`, `libomp` and so on.
( ) more encapsulation in `cmake/Modules/StandaloneBuildHelpers.cmake`


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D141050

Files:
  clang/CMakeLists.txt
  cmake/Modules/StandaloneBuildHelpers.cmake
  lld/CMakeLists.txt

Index: lld/CMakeLists.txt
===
--- lld/CMakeLists.txt
+++ lld/CMakeLists.txt
@@ -23,23 +23,16 @@
 # Must go below project(..)
 include(GNUInstallDirs)
 
-if(LLD_BUILT_STANDALONE)
-  set(CMAKE_CXX_STANDARD 17 CACHE STRING "C++ standard to conform to")
-  set(CMAKE_CXX_STANDARD_REQUIRED YES)
-  set(CMAKE_CXX_EXTENSIONS NO)
-
-  set(CMAKE_INCLUDE_CURRENT_DIR ON)
-
-  find_package(LLVM REQUIRED HINTS "${LLVM_CMAKE_DIR}")
-  list(APPEND CMAKE_MODULE_PATH "${LLVM_DIR}")
-
-  # Turn into CACHE PATHs for overwritting
-  set(LLVM_INCLUDE_DIRS ${LLVM_INCLUDE_DIRS} CACHE PATH "Path to llvm/include and any other header dirs needed")
-  set(LLVM_BINARY_DIR "${LLVM_BINARY_DIR}" CACHE PATH "Path to LLVM build tree")
-  set(LLVM_MAIN_SRC_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../llvm" CACHE PATH "Path to LLVM source tree")
+# Make sure that our source directory is on 

[PATCH] D138472: clang/cmake: Use installed gtest libraries for stand-alone builds

2022-11-22 Thread Konrad Wilhelm Kleine via Phabricator via cfe-commits
kwk added inline comments.



Comment at: clang/CMakeLists.txt:103
 if (LLVM_LIT AND LLVM_UTILS_PROVIDED)
-  set(UNITTEST_DIR ${LLVM_THIRD_PARTY_DIR}/utils/unittest)
-  if(EXISTS ${UNITTEST_DIR}/googletest/include/gtest/gtest.h
- AND NOT EXISTS 
${LLVM_LIBRARY_DIR}/${CMAKE_STATIC_LIBRARY_PREFIX}gtest${CMAKE_STATIC_LIBRARY_SUFFIX}
- AND EXISTS ${UNITTEST_DIR}/CMakeLists.txt)
-add_subdirectory(${UNITTEST_DIR} third-part/unittest)
+  find_package(LLVMGTest)
+  if (NOT TARGET llvm_gtest)

I don't see no `FindLLVMGTest.cmake` file anywhere. Is that suppose to exist 
yet or which Patch is suppose to create it?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D138472/new/

https://reviews.llvm.org/D138472

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D138258: clang/cmake: Fix incorrectly disabling tests when LLVM_EXTERNAL_LIT is used

2022-11-18 Thread Konrad Wilhelm Kleine via Phabricator via cfe-commits
kwk requested changes to this revision.
kwk added a comment.
This revision now requires changes to proceed.

As much as I would like this to be fixed. I vote against this patch because in 
`lld/CMakeLists.txt` there's an almost (if not entirely) identical piece of 
code 

 that screams to be outsourced into a `/cmake/Modules/FindLit.cmake` (to be 
created). I'll have a look at this and see if I can come up with a patch for 
this. Afterall `/cmake` is the central place to distribute share CMake code 
between subprojects, right @phosek (didn't you create `/cmake` in the first 
place?

Alternatively, we can copy the code from `lld/CMakeLists.txt` and outsource it 
afterwards so that the shared code becomes more obvious.

If there're any objections regarding outsourcing to `FindLit.cmake`, then I 
would only ask to copy the code from `lld/CMakeLists.txt`. There the 
`find_program` part sits below the if block.




Comment at: clang/CMakeLists.txt:97
 # Seek installed Lit.
-find_program(LLVM_LIT
- NAMES llvm-lit lit.py lit
- PATHS "${LLVM_MAIN_SRC_DIR}/utils/lit"
- DOC "Path to lit.py")
+if (NOT LLVM_EXTERNAL_LIT)
+  find_program(LLVM_EXTERNAL_LIT

mgorny wrote:
> I don't think you need to do this if you rename the var, `find_program()` 
> doesn't seem to do any searching when the var is already set.
> 
> I've tested with a dummy CMakeLists:
> 
> ```
> set(FOO /bin/true)
> find_program(FOO NAMES foo)
> message(FATAL_ERROR ${FOO})
> ```
> 
> gives `/bin/true` for me.
> I don't think you need to do this if you rename the var, `find_program()` 
> doesn't seem to do any searching when the var is already set.

This might be true but it is counter intuitive to assume that `find_program` 
does nothing. So for readability I'd keep the `if (NOT LLVM_EXTERNAL_LIT)`. I 
know it is not needed but with the `if` it won't look like 
`find_program(LLVM_EXTERNAL_LIT` is the only/central place to set the variable 
`LLVM_EXTERNAL_LIT`. With the guard around it, it becomes more obvious that 
this is more of  a fallback.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D138258/new/

https://reviews.llvm.org/D138258

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D134852: [clang-format][NFC] Clean up class HeaderIncludes and Format.cpp

2022-10-05 Thread Konrad Wilhelm Kleine via Phabricator via cfe-commits
kwk accepted this revision.
kwk added inline comments.
This revision is now accepted and ready to land.



Comment at: clang/lib/Format/Format.cpp:2774
-
-const char CppIncludeRegexPattern[] =
-R"(^[\t\ ]*#[\t\ ]*(import|include)[^"<]*(["<][^">]*[">]))";

owenpan wrote:
> kwk wrote:
> > owenpan wrote:
> > > kwk wrote:
> > > > MyDeveloperDay wrote:
> > > > > Did I miss where this comes from now?
> > > > @MyDeveloperDay `clang/lib/Tooling/Inclusions/HeaderIncludes.cpp` still 
> > > > has this:
> > > > 
> > > > ```lang=c++
> > > > const char IncludeRegexPattern[] =
> > > > R"(^[\t\ ]*#[\t\ ]*(import|include)[^"<]*(["<][^">]*[">]))";
> > > > ```
> > > > 
> > > > And in `clang/lib/Tooling/Inclusions/HeaderIncludes.cpp` @owenpan uses 
> > > > it to initialize the final regex 
> > > > 
> > > > ```lang=c++
> > > > const llvm::Regex HeaderIncludes::IncludeRegex(IncludeRegexPattern); 
> > > > ```
> > > > 
> > > > The fact that we have two regex that are identical is an issue on its 
> > > > own that I tried to address with [my 
> > > > patch](https://reviews.llvm.org/D134733) as well. I didn't initialize 
> > > > the regex like @owenpan does here but I had a function to return it. 
> > > > Eventually a function makes it easier to apply the injection from a 
> > > > config file as you've suggested 
> > > > [here](https://reviews.llvm.org/D134733#3821957). So I favor my 
> > > > solution.
> > > > 
> > > > 
> > > > 
> > > > 
> > > > The fact that we have two regex that are identical is an issue on its 
> > > > own that I tried to address with [my 
> > > > patch](https://reviews.llvm.org/D134733) as well.
> > > 
> > > It should be addressed in a separate NFC patch such as this one.
> > > 
> > > > I didn't initialize the regex like @owenpan does here but I had a 
> > > > function to return it. Eventually a function makes it easier to apply 
> > > > the injection from a config file as you've suggested 
> > > > [here](https://reviews.llvm.org/D134733#3821957). So I favor my 
> > > > solution.
> > > 
> > > Making `IncludeRegex` a public static const member is one of the better 
> > > solutions when `IncludeRegexPattern` is fixed as it has been. If and when 
> > > we decide to support user specified patterns, we will make any necessary 
> > > changes then.
> > > > The fact that we have two regex that are identical is an issue on its 
> > > > own that I tried to address with [my 
> > > > patch](https://reviews.llvm.org/D134733) as well.
> > > 
> > > It should be addressed in a separate NFC patch such as this one.
> > 
> > Ehm, I thought I *did* create a separate NFC patch with D134733. I prefixed 
> > it with `[chore]` but that is as good as NFC. I can rename it if you want.  
> > 
> > > 
> > > > I didn't initialize the regex like @owenpan does here but I had a 
> > > > function to return it. Eventually a function makes it easier to apply 
> > > > the injection from a config file as you've suggested 
> > > > [here](https://reviews.llvm.org/D134733#3821957). So I favor my 
> > > > solution.
> > > 
> > > Making `IncludeRegex` a public static const member is one of the better 
> > > solutions when `IncludeRegexPattern` is fixed as it has been. If and when 
> > > we decide to support user specified patterns, we will make any necessary 
> > > changes then.
> > 
> > Okay, but you could have suggested that in D134733, no? I've made the 
> > change in D134733 here: 
> > https://reviews.llvm.org/D134733?vs=463205=464196#toc, so the regex is 
> > static const. But I've also outsourced the function for accessing the 
> > include name so the logic is at one place not scattered over and over and 
> > the trimming is also in its own function. Having everything going through 
> > that functions is easier for maintenance IMHO. Before I wondered why we had 
> > two include regex patterns (both the same btw.) and why an include name 
> > wasn't found when I had changed the `Matches[2]` to `Matches[3]` for 
> > example. That won't happen when its going through the function. You just 
> > change it in one place and not "plenty".
> > 
> > I hope we can agree that my change is now complete with additions from 
> > yours here. I most certainly don't want to disrupt your workflow and I 
> > apologize if I had. Unfortunately text can be misinterpreted way too much.
> > Ehm, I thought I *did* create a separate NFC patch with D134733. I prefixed 
> > it with `[chore]` but that is as good as NFC. I can rename it if you want.
> 
> I didn't know by `chore` you meant `NFC`. Thanks for renaming it.
> 
> > Okay, but you could have suggested that in D134733, no?
> 
> It would be too many places to point out as you can tell from this patch. 
> When mixed with other unrelated changes in D134733, it would be more 
> difficult for me to review and other people to follow. Making this patch 
> allows me to focus on the best way to solve the problem without worrying 
> about any additional "noise".
> 
> > I hope we can agree 

[PATCH] D134852: [clang-format][NFC] Clean up class HeaderIncludes and Format.cpp

2022-09-30 Thread Konrad Wilhelm Kleine via Phabricator via cfe-commits
kwk added inline comments.



Comment at: clang/lib/Format/Format.cpp:2774
-
-const char CppIncludeRegexPattern[] =
-R"(^[\t\ ]*#[\t\ ]*(import|include)[^"<]*(["<][^">]*[">]))";

owenpan wrote:
> kwk wrote:
> > MyDeveloperDay wrote:
> > > Did I miss where this comes from now?
> > @MyDeveloperDay `clang/lib/Tooling/Inclusions/HeaderIncludes.cpp` still has 
> > this:
> > 
> > ```lang=c++
> > const char IncludeRegexPattern[] =
> > R"(^[\t\ ]*#[\t\ ]*(import|include)[^"<]*(["<][^">]*[">]))";
> > ```
> > 
> > And in `clang/lib/Tooling/Inclusions/HeaderIncludes.cpp` @owenpan uses it 
> > to initialize the final regex 
> > 
> > ```lang=c++
> > const llvm::Regex HeaderIncludes::IncludeRegex(IncludeRegexPattern); 
> > ```
> > 
> > The fact that we have two regex that are identical is an issue on its own 
> > that I tried to address with [my patch](https://reviews.llvm.org/D134733) 
> > as well. I didn't initialize the regex like @owenpan does here but I had a 
> > function to return it. Eventually a function makes it easier to apply the 
> > injection from a config file as you've suggested 
> > [here](https://reviews.llvm.org/D134733#3821957). So I favor my solution.
> > 
> > 
> > 
> > 
> > The fact that we have two regex that are identical is an issue on its own 
> > that I tried to address with [my patch](https://reviews.llvm.org/D134733) 
> > as well.
> 
> It should be addressed in a separate NFC patch such as this one.
> 
> > I didn't initialize the regex like @owenpan does here but I had a function 
> > to return it. Eventually a function makes it easier to apply the injection 
> > from a config file as you've suggested 
> > [here](https://reviews.llvm.org/D134733#3821957). So I favor my solution.
> 
> Making `IncludeRegex` a public static const member is one of the better 
> solutions when `IncludeRegexPattern` is fixed as it has been. If and when we 
> decide to support user specified patterns, we will make any necessary changes 
> then.
> > The fact that we have two regex that are identical is an issue on its own 
> > that I tried to address with [my patch](https://reviews.llvm.org/D134733) 
> > as well.
> 
> It should be addressed in a separate NFC patch such as this one.

Ehm, I thought I *did* create a separate NFC patch with D134733. I prefixed it 
with `[chore]` but that is as good as NFC. I can rename it if you want.  

> 
> > I didn't initialize the regex like @owenpan does here but I had a function 
> > to return it. Eventually a function makes it easier to apply the injection 
> > from a config file as you've suggested 
> > [here](https://reviews.llvm.org/D134733#3821957). So I favor my solution.
> 
> Making `IncludeRegex` a public static const member is one of the better 
> solutions when `IncludeRegexPattern` is fixed as it has been. If and when we 
> decide to support user specified patterns, we will make any necessary changes 
> then.

Okay, but you could have suggested that in D134733, no? I've made the change in 
D134733 here: https://reviews.llvm.org/D134733?vs=463205=464196#toc, so the 
regex is static const. But I've also outsourced the function for accessing the 
include name so the logic is at one place not scattered over and over and the 
trimming is also in its own function. Having everything going through that 
functions is easier for maintenance IMHO. Before I wondered why we had two 
include regex patterns (both the same btw.) and why an include name wasn't 
found when I had changed the `Matches[2]` to `Matches[3]` for example. That 
won't happen when its going through the function. You just change it in one 
place and not "plenty".

I hope we can agree that my change is now complete with additions from yours 
here. I most certainly don't want to disrupt your workflow and I apologize if I 
had. Unfortunately text can be misinterpreted way too much.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D134852/new/

https://reviews.llvm.org/D134852

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D134733: [clang-format][chore] transparent #include name regex

2022-09-30 Thread Konrad Wilhelm Kleine via Phabricator via cfe-commits
kwk updated this revision to Diff 464196.
kwk added a comment.

- Make include regex a static member and not a function
- Run clang-format


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D134733/new/

https://reviews.llvm.org/D134733

Files:
  clang/include/clang/Tooling/Inclusions/HeaderIncludes.h
  clang/lib/Format/Format.cpp
  clang/lib/Tooling/Inclusions/HeaderIncludes.cpp

Index: clang/lib/Tooling/Inclusions/HeaderIncludes.cpp
===
--- clang/lib/Tooling/Inclusions/HeaderIncludes.cpp
+++ clang/lib/Tooling/Inclusions/HeaderIncludes.cpp
@@ -169,13 +169,6 @@
   });
 }
 
-inline StringRef trimInclude(StringRef IncludeName) {
-  return IncludeName.trim("\"<>");
-}
-
-const char IncludeRegexPattern[] =
-R"(^[\t\ ]*#[\t\ ]*(import|include)[^"<]*(["<][^">]*[">]))";
-
 // The filename of Path excluding extension.
 // Used to match implementation with headers, this differs from sys::path::stem:
 //  - in names with multiple dots (foo.cu.cc) it terminates at the *first*
@@ -266,6 +259,16 @@
   return false;
 }
 
+static const char IncludeRegexPattern[] =
+R"(^[\t\ ]*#[\t\ ]*(import|include)[^"<]*(["<][^">]*[">]))";
+/// IncludeRegex ia regex that can match various styles of C++ includes.
+/// For example:
+/// \code
+/// #include 
+/// #include "bar.h"
+/// \endcode
+const llvm::Regex HeaderIncludes::IncludeRegex(IncludeRegexPattern);
+
 HeaderIncludes::HeaderIncludes(StringRef FileName, StringRef Code,
const IncludeStyle )
 : FileName(FileName), Code(Code), FirstIncludeOffset(-1),
@@ -274,8 +277,7 @@
   MaxInsertOffset(MinInsertOffset +
   getMaxHeaderInsertionOffset(
   FileName, Code.drop_front(MinInsertOffset), Style)),
-  Categories(Style, FileName),
-  IncludeRegex(llvm::Regex(IncludeRegexPattern)) {
+  Categories(Style, FileName) {
   // Add 0 for main header and INT_MAX for headers that are not in any
   // category.
   Priorities = {0, INT_MAX};
@@ -289,11 +291,12 @@
   SmallVector Matches;
   for (auto Line : Lines) {
 NextLineOffset = std::min(Code.size(), Offset + Line.size() + 1);
-if (IncludeRegex.match(Line, )) {
+if (tooling::HeaderIncludes::IncludeRegex.match(Line, )) {
+  StringRef IncludeName = tooling::getIncludeNameFromMatches(Matches);
   // If this is the last line without trailing newline, we need to make
   // sure we don't delete across the file boundary.
   addExistingInclude(
-  Include(Matches[2],
+  Include(IncludeName,
   tooling::Range(
   Offset, std::min(Line.size() + 1, Code.size() - Offset))),
   NextLineOffset);
@@ -403,5 +406,18 @@
   return Result;
 }
 
+llvm::StringRef getIncludeNameFromMatches(
+const llvm::SmallVectorImpl ) {
+  if (Matches.size() >= 3) {
+return Matches[2];
+  }
+  llvm_unreachable("Matches is too small");
+  return llvm::StringRef();
+}
+
+llvm::StringRef trimInclude(llvm::StringRef IncludeName) {
+  return IncludeName.trim("\"<>;");
+}
+
 } // namespace tooling
 } // namespace clang
Index: clang/lib/Format/Format.cpp
===
--- clang/lib/Format/Format.cpp
+++ clang/lib/Format/Format.cpp
@@ -44,6 +44,7 @@
 #include "llvm/Support/VirtualFileSystem.h"
 #include "llvm/Support/YAMLTraits.h"
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -2769,13 +2770,6 @@
   }
 }
 
-namespace {
-
-const char CppIncludeRegexPattern[] =
-R"(^[\t\ ]*#[\t\ ]*(import|include)[^"<]*(["<][^">]*[">]))";
-
-} // anonymous namespace
-
 tooling::Replacements sortCppIncludes(const FormatStyle , StringRef Code,
   ArrayRef Ranges,
   StringRef FileName,
@@ -2785,7 +2779,6 @@
   .StartsWith("\xEF\xBB\xBF", 3) // UTF-8 BOM
   .Default(0);
   unsigned SearchFrom = 0;
-  llvm::Regex IncludeRegex(CppIncludeRegexPattern);
   SmallVector Matches;
   SmallVector IncludesInBlock;
 
@@ -2842,8 +2835,9 @@
 
 bool MergeWithNextLine = Trimmed.endswith("\\");
 if (!FormattingOff && !MergeWithNextLine) {
-  if (IncludeRegex.match(Line, )) {
-StringRef IncludeName = Matches[2];
+  if (tooling::HeaderIncludes::IncludeRegex.match(Line, )) {
+StringRef IncludeName = tooling::getIncludeNameFromMatches(Matches);
+
 if (Line.contains("/*") && !Line.contains("*/")) {
   // #include with a start of a block comment, but without the end.
   // Need to keep all the lines until the end of the comment together.
@@ -3120,8 +3114,8 @@
 
 inline bool isHeaderInsertion(const tooling::Replacement ) {
   return Replace.getOffset() == UINT_MAX && Replace.getLength() == 0 &&
- llvm::Regex(CppIncludeRegexPattern)
- .match(Replace.getReplacementText());
+   

[PATCH] D134733: [clang-format][chore] transparent #include name regex

2022-09-29 Thread Konrad Wilhelm Kleine via Phabricator via cfe-commits
kwk added inline comments.



Comment at: clang/lib/Tooling/Inclusions/HeaderIncludes.cpp:407
+const llvm::SmallVectorImpl ) {
+  if (Matches.size() >= 3) {
+return Matches[2];

MyDeveloperDay wrote:
> kwk wrote:
> > MyDeveloperDay wrote:
> > > ‘>= 2’
> > @MyDeveloperDay correct me if I'm wrong but if an array has size `3` it has 
> > indexes `0`, `1` and `2`. And an array of size `2` only has `0` and `1`.  
> > So the case `=2`, which is implied by your suggested`>=2`, is actually an 
> > out of bounds access when going `Matches[2]`.  Because that is effectively 
> > accessing the third element. The only valid change would be to check for 
> > `Matches.size() > 2` IMHO and that is the same as `Matches.size() >= 3`.
> > 
> > I must admit that I had to look at the regex a few times only to realize 
> > that it has two non-optional matching groups `(...)`. The third matching 
> > group at index `0` is the whole line. So in theory `>=3` isn't possible 
> > with the current regex. I wanted to give my best to have this logic 
> > "survive" a change to the regex in which for example something is added 
> > after the matching group of the include name; let's say a comment or 
> > something.
> > 
> > I hope I haven't made myself a complete fool.  
> No foolery other than my own. I meant to say '> 2',  actually the first time 
> I wrote the comment it disappear because it didn't escape the '>'
> 
> So one though I had for the config was something like this (ignore regex 
> itself I just put anything in it to show the principle)
> 
> ```
> ---
> Language Cpp
> IncludeRegex:  ^[\t\ ]*[@#][\t\ 
> ]*(import|include)([^"/]*("[^"]+")|[^]+>)|[\t/\ ]*([^;]+;)
> IncludeRegexGroup: 1
> ---
> Language: ObjectiveC
> IncludeRegex:  ^[\t\ ]*[@#][\t\ 
> ]*(import|include)([^"/]*("[^"]+")|[^]+>)|[\t/\ ]*([^;]+;)
> IncludeRegexGroup: 2
> ---
> Language: CSharp
> IncludeRegex:  using  ([A-z])*
> IncludeRegexGroup: 0
> ---
> Language: Carbon
> IncludeRegex:  package ([A-z])* api
> IncludeRegexGroup: 0
> ---
> 
> ```
> 
> Wouldn't this allow different languages to have their own Include/Import 
> regex? Just thinking out loud
> 
> It could be more powerful than having 1 regex to rule them all.
> 
> 
> 
> 
@MyDeveloperDay I like the idea of this approach! But I also see that a single 
language alone, namely C++, is quite a tough nut to crack with the advent of 
Modules (https://en.cppreference.com/w/cpp/language/modules). I'm afraid the 
bit of `IncludeRegexGroup` would need to be expanded to be either a

* **fixed number** (wherever possible)
* a **method** as in: last-non-empty-matching-group

Only then I think that your solution would work. Can one have a setting in 
clang format that allows for mixed input as in number or string? A bit of a 
hacky solution but probably cutting 100% of all regexes would be to have an 
enum with these allowed strings: 
`last-non-empty-matching-group,first-non-empty-matching-group,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20`.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D134733/new/

https://reviews.llvm.org/D134733

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D134852: [clang-format][NFC] Clean up class HeaderIncludes and Format.cpp

2022-09-29 Thread Konrad Wilhelm Kleine via Phabricator via cfe-commits
kwk added a comment.

I didn't see much difference in what this patch does compare to mine but I saw 
that it removes the need for instantiating multiple `llvm::Regex` objects from 
a single static pattern. But that's something I've just done in a new revision 
of my own patch: https://reviews.llvm.org/D134733?vs=463205=463786#toc . 
This fast clean up makes it only harder for me to get my patch in but 
essentially both do the same thing except that I also have a single convenience 
function for trimming include names from `"` and `<>"`.




Comment at: clang/lib/Format/Format.cpp:2774
-
-const char CppIncludeRegexPattern[] =
-R"(^[\t\ ]*#[\t\ ]*(import|include)[^"<]*(["<][^">]*[">]))";

MyDeveloperDay wrote:
> Did I miss where this comes from now?
@MyDeveloperDay `clang/lib/Tooling/Inclusions/HeaderIncludes.cpp` still has 
this:

```lang=c++
const char IncludeRegexPattern[] =
R"(^[\t\ ]*#[\t\ ]*(import|include)[^"<]*(["<][^">]*[">]))";
```

And in `clang/lib/Tooling/Inclusions/HeaderIncludes.cpp` @owenpan uses it to 
initialize the final regex 

```lang=c++
const llvm::Regex HeaderIncludes::IncludeRegex(IncludeRegexPattern); 
```

The fact that we have two regex that are identical is an issue on its own that 
I tried to address with [my patch](https://reviews.llvm.org/D134733) as well. I 
didn't initialize the regex like @owenpan does here but I had a function to 
return it. Eventually a function makes it easier to apply the injection from a 
config file as you've suggested 
[here](https://reviews.llvm.org/D134733#3821957). So I favor my solution.






Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D134852/new/

https://reviews.llvm.org/D134852

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D134733: [clang-format][chore] transparent #include name regex

2022-09-29 Thread Konrad Wilhelm Kleine via Phabricator via cfe-commits
kwk updated this revision to Diff 463786.
kwk added a comment.

- Remove ad-hoc instantiated IncludeRegex objects


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D134733/new/

https://reviews.llvm.org/D134733

Files:
  clang/include/clang/Tooling/Inclusions/HeaderIncludes.h
  clang/lib/Format/Format.cpp
  clang/lib/Tooling/Inclusions/HeaderIncludes.cpp

Index: clang/lib/Tooling/Inclusions/HeaderIncludes.cpp
===
--- clang/lib/Tooling/Inclusions/HeaderIncludes.cpp
+++ clang/lib/Tooling/Inclusions/HeaderIncludes.cpp
@@ -169,13 +169,6 @@
   });
 }
 
-inline StringRef trimInclude(StringRef IncludeName) {
-  return IncludeName.trim("\"<>");
-}
-
-const char IncludeRegexPattern[] =
-R"(^[\t\ ]*#[\t\ ]*(import|include)[^"<]*(["<][^">]*[">]))";
-
 // The filename of Path excluding extension.
 // Used to match implementation with headers, this differs from sys::path::stem:
 //  - in names with multiple dots (foo.cu.cc) it terminates at the *first*
@@ -274,8 +267,7 @@
   MaxInsertOffset(MinInsertOffset +
   getMaxHeaderInsertionOffset(
   FileName, Code.drop_front(MinInsertOffset), Style)),
-  Categories(Style, FileName),
-  IncludeRegex(llvm::Regex(IncludeRegexPattern)) {
+  Categories(Style, FileName) {
   // Add 0 for main header and INT_MAX for headers that are not in any
   // category.
   Priorities = {0, INT_MAX};
@@ -289,11 +281,12 @@
   SmallVector Matches;
   for (auto Line : Lines) {
 NextLineOffset = std::min(Code.size(), Offset + Line.size() + 1);
-if (IncludeRegex.match(Line, )) {
+if (tooling::getCppIncludeRegex().match(Line, )) {
+  StringRef IncludeName = tooling::getIncludeNameFromMatches(Matches);
   // If this is the last line without trailing newline, we need to make
   // sure we don't delete across the file boundary.
   addExistingInclude(
-  Include(Matches[2],
+  Include(IncludeName,
   tooling::Range(
   Offset, std::min(Line.size() + 1, Code.size() - Offset))),
   NextLineOffset);
@@ -403,5 +396,24 @@
   return Result;
 }
 
+llvm::Regex getCppIncludeRegex() {
+  static const char CppIncludeRegexPattern[] =
+  R"(^[\t\ ]*#[\t\ ]*(import|include)[^"<]*(["<][^">]*[">]))";
+  return llvm::Regex(CppIncludeRegexPattern);
+}
+
+llvm::StringRef getIncludeNameFromMatches(
+const llvm::SmallVectorImpl ) {
+  if (Matches.size() >= 3) {
+return Matches[2];
+  }
+  llvm_unreachable("Matches is too small");
+  return llvm::StringRef();
+}
+
+llvm::StringRef trimInclude(llvm::StringRef IncludeName) {
+  return IncludeName.trim("\"<>;");
+}
+
 } // namespace tooling
 } // namespace clang
Index: clang/lib/Format/Format.cpp
===
--- clang/lib/Format/Format.cpp
+++ clang/lib/Format/Format.cpp
@@ -44,6 +44,7 @@
 #include "llvm/Support/VirtualFileSystem.h"
 #include "llvm/Support/YAMLTraits.h"
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -2769,13 +2770,6 @@
   }
 }
 
-namespace {
-
-const char CppIncludeRegexPattern[] =
-R"(^[\t\ ]*#[\t\ ]*(import|include)[^"<]*(["<][^">]*[">]))";
-
-} // anonymous namespace
-
 tooling::Replacements sortCppIncludes(const FormatStyle , StringRef Code,
   ArrayRef Ranges,
   StringRef FileName,
@@ -2785,7 +2779,6 @@
   .StartsWith("\xEF\xBB\xBF", 3) // UTF-8 BOM
   .Default(0);
   unsigned SearchFrom = 0;
-  llvm::Regex IncludeRegex(CppIncludeRegexPattern);
   SmallVector Matches;
   SmallVector IncludesInBlock;
 
@@ -2842,8 +2835,9 @@
 
 bool MergeWithNextLine = Trimmed.endswith("\\");
 if (!FormattingOff && !MergeWithNextLine) {
-  if (IncludeRegex.match(Line, )) {
-StringRef IncludeName = Matches[2];
+  if (tooling::getCppIncludeRegex().match(Line, )) {
+StringRef IncludeName = tooling::getIncludeNameFromMatches(Matches);
+
 if (Line.contains("/*") && !Line.contains("*/")) {
   // #include with a start of a block comment, but without the end.
   // Need to keep all the lines until the end of the comment together.
@@ -3120,8 +3114,7 @@
 
 inline bool isHeaderInsertion(const tooling::Replacement ) {
   return Replace.getOffset() == UINT_MAX && Replace.getLength() == 0 &&
- llvm::Regex(CppIncludeRegexPattern)
- .match(Replace.getReplacementText());
+ tooling::getCppIncludeRegex().match(Replace.getReplacementText());
 }
 
 inline bool isHeaderDeletion(const tooling::Replacement ) {
@@ -3129,7 +3122,7 @@
 }
 
 // FIXME: insert empty lines between newly created blocks.
-tooling::Replacements
+static tooling::Replacements
 fixCppIncludeInsertions(StringRef Code, const tooling::Replacements ,
 const FormatStyle ) {
  

[PATCH] D134733: [clang-format][chore] transparent #include name regex

2022-09-28 Thread Konrad Wilhelm Kleine via Phabricator via cfe-commits
kwk added a comment.

@MyDeveloperDay please see my potentially uneducated comments.




Comment at: clang/lib/Tooling/Inclusions/HeaderIncludes.cpp:400
+llvm::Regex getCppIncludeRegex() {
+  static const char CppIncludeRegexPattern[] =
+  R"(^[\t\ ]*#[\t\ ]*(import|include)[^"<]*(["<][^">]*[">]))";

MyDeveloperDay wrote:
> What if this was overridable via the Style we could experiment with changing 
> the regex
Well, right now that was never a requirement and to be honest it isn't very 
worth exploring this because its not easy to determine which the correct 
matching group is for the include name.

For example, let's say you would allow this to be configurable from the config 
file and a user enters the regex from my previous patch (D121370):

```
^[\t\ ]*[@#][\t\ ]*(import|include)([^"/]*("[^"]+")|[^]+>)|[\t/\ 
]*([^;]+;))
```

How would you determine which is the correct matching group? I first thought 
about taking the last one matching but then I found that my regex was not able 
to cope with trailing comments. And even in my case there's more than one 
matching group for the include name. All in all I really don't see any value in 
outsourcing this to the config file is not something I see value in.

The only thing valuable would be to have a regex for multiple languages. Sorry 
if this is what you intended. I just wouldn't want to move this out to the 
config file for the end-user to play with. 



Comment at: clang/lib/Tooling/Inclusions/HeaderIncludes.cpp:407
+const llvm::SmallVectorImpl ) {
+  if (Matches.size() >= 3) {
+return Matches[2];

MyDeveloperDay wrote:
> ‘>= 2’
@MyDeveloperDay correct me if I'm wrong but if an array has size `3` it has 
indexes `0`, `1` and `2`. And an array of size `2` only has `0` and `1`.  So 
the case `=2`, which is implied by your suggested`>=2`, is actually an out of 
bounds access when going `Matches[2]`.  Because that is effectively accessing 
the third element. The only valid change would be to check for `Matches.size() 
> 2` IMHO and that is the same as `Matches.size() >= 3`.

I must admit that I had to look at the regex a few times only to realize that 
it has two non-optional matching groups `(...)`. The third matching group at 
index `0` is the whole line. So in theory `>=3` isn't possible with the current 
regex. I wanted to give my best to have this logic "survive" a change to the 
regex in which for example something is added after the matching group of the 
include name; let's say a comment or something.

I hope I haven't made myself a complete fool.  


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D134733/new/

https://reviews.llvm.org/D134733

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D121370: [clang-format] SortIncludes should support "@import" lines in Objective-C

2022-09-27 Thread Konrad Wilhelm Kleine via Phabricator via cfe-commits
kwk abandoned this revision.
kwk added a comment.

In D121370#3817753 , @MyDeveloperDay 
wrote:

> @kwk have we bottomed out on this issue? its been stale for a bit. If we are 
> not going to work on it further can be "Abandon" the review to get it off our 
> lists?

We can abandon this patch and I might look into it some other time. But I 
wanted to rescue bits from this patch that don't change the current behavior. 
That's why I've created: https://reviews.llvm.org/D134733 . I hope we can 
approve it to get the transparency in and make a patch like D121370 
 a bit smaller in the future.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D121370/new/

https://reviews.llvm.org/D121370

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D134733: [clang-format][chore] transparent #include name regex

2022-09-27 Thread Konrad Wilhelm Kleine via Phabricator via cfe-commits
kwk created this revision.
kwk added a reviewer: MyDeveloperDay.
Herald added a project: All.
kwk requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

The foundation for this patch was done in:
https://reviews.llvm.org/D121370. I wanted to "rescue" some pieces from
it.

Unlike D121370 , this patch doesn't modify 
the regular expression itself.
It simply provides three functions to have a cleaner and more
transparent way how the include name is processed from an `#include`
line.

Here's how I've tested this patch:

  $ cd llvm-project
  $ mkdir build && cd build
  $ cmake ../llvm/ -DCMAKE_BUILD_TYPE=Release -DCLANG_BUILD_TOOLS=On 
-DLLVM_ENABLE_PROJECTS=clang -DCLANG_INCLUDE_TESTS=ON -DLLVM_BUILD_UTILS=ON -G 
Ninja
  $ ninja clangFormat
  $ ninja FormatTests
  $ ./tools/clang/unittests/Format/FormatTests --gtest_filter=SortIncludesTest*

And if that worked I doubled checked that nothing else broke by running
all format checks:

  $ ./tools/clang/unittests/Format/FormatTests


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D134733

Files:
  clang/include/clang/Tooling/Inclusions/HeaderIncludes.h
  clang/lib/Format/Format.cpp
  clang/lib/Tooling/Inclusions/HeaderIncludes.cpp

Index: clang/lib/Tooling/Inclusions/HeaderIncludes.cpp
===
--- clang/lib/Tooling/Inclusions/HeaderIncludes.cpp
+++ clang/lib/Tooling/Inclusions/HeaderIncludes.cpp
@@ -169,13 +169,6 @@
   });
 }
 
-inline StringRef trimInclude(StringRef IncludeName) {
-  return IncludeName.trim("\"<>");
-}
-
-const char IncludeRegexPattern[] =
-R"(^[\t\ ]*#[\t\ ]*(import|include)[^"<]*(["<][^">]*[">]))";
-
 // The filename of Path excluding extension.
 // Used to match implementation with headers, this differs from sys::path::stem:
 //  - in names with multiple dots (foo.cu.cc) it terminates at the *first*
@@ -274,8 +267,7 @@
   MaxInsertOffset(MinInsertOffset +
   getMaxHeaderInsertionOffset(
   FileName, Code.drop_front(MinInsertOffset), Style)),
-  Categories(Style, FileName),
-  IncludeRegex(llvm::Regex(IncludeRegexPattern)) {
+  Categories(Style, FileName), IncludeRegex(getCppIncludeRegex()) {
   // Add 0 for main header and INT_MAX for headers that are not in any
   // category.
   Priorities = {0, INT_MAX};
@@ -290,10 +282,11 @@
   for (auto Line : Lines) {
 NextLineOffset = std::min(Code.size(), Offset + Line.size() + 1);
 if (IncludeRegex.match(Line, )) {
+  StringRef IncludeName = tooling::getIncludeNameFromMatches(Matches);
   // If this is the last line without trailing newline, we need to make
   // sure we don't delete across the file boundary.
   addExistingInclude(
-  Include(Matches[2],
+  Include(IncludeName,
   tooling::Range(
   Offset, std::min(Line.size() + 1, Code.size() - Offset))),
   NextLineOffset);
@@ -403,5 +396,24 @@
   return Result;
 }
 
+llvm::Regex getCppIncludeRegex() {
+  static const char CppIncludeRegexPattern[] =
+  R"(^[\t\ ]*#[\t\ ]*(import|include)[^"<]*(["<][^">]*[">]))";
+  return llvm::Regex(CppIncludeRegexPattern);
+}
+
+llvm::StringRef getIncludeNameFromMatches(
+const llvm::SmallVectorImpl ) {
+  if (Matches.size() >= 3) {
+return Matches[2];
+  }
+  llvm_unreachable("Matches is too small");
+  return llvm::StringRef();
+}
+
+llvm::StringRef trimInclude(llvm::StringRef IncludeName) {
+  return IncludeName.trim("\"<>;");
+}
+
 } // namespace tooling
 } // namespace clang
Index: clang/lib/Format/Format.cpp
===
--- clang/lib/Format/Format.cpp
+++ clang/lib/Format/Format.cpp
@@ -44,6 +44,7 @@
 #include "llvm/Support/VirtualFileSystem.h"
 #include "llvm/Support/YAMLTraits.h"
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -2769,13 +2770,6 @@
   }
 }
 
-namespace {
-
-const char CppIncludeRegexPattern[] =
-R"(^[\t\ ]*#[\t\ ]*(import|include)[^"<]*(["<][^">]*[">]))";
-
-} // anonymous namespace
-
 tooling::Replacements sortCppIncludes(const FormatStyle , StringRef Code,
   ArrayRef Ranges,
   StringRef FileName,
@@ -2785,7 +2779,7 @@
   .StartsWith("\xEF\xBB\xBF", 3) // UTF-8 BOM
   .Default(0);
   unsigned SearchFrom = 0;
-  llvm::Regex IncludeRegex(CppIncludeRegexPattern);
+  llvm::Regex IncludeRegex(tooling::getCppIncludeRegex());
   SmallVector Matches;
   SmallVector IncludesInBlock;
 
@@ -2843,7 +2837,8 @@
 bool MergeWithNextLine = Trimmed.endswith("\\");
 if (!FormattingOff && !MergeWithNextLine) {
   if (IncludeRegex.match(Line, )) {
-StringRef IncludeName = Matches[2];
+StringRef IncludeName = tooling::getIncludeNameFromMatches(Matches);
+
 if 

[PATCH] D133801: Extraction of a matcher for an unused value from an expression from the bugprone-unused-return-value check

2022-09-23 Thread Konrad Wilhelm Kleine via Phabricator via cfe-commits
kwk added inline comments.



Comment at: clang-tools-extra/unittests/clang-tidy/MatchersTest.cpp:2
+#include "utils/Matchers.h"
+#include "../../clang/unittests/ASTMatchers/ASTMatchersTest.h"
+

njames93 wrote:
> @kwk I seem to recall you saying in another patch that this include will 
> break standalone builds, would stripping the leading `../../` work?
> @kwk I seem to recall you saying in another patch that this include will 
> break standalone builds, 

@njames93 that's correct. But I don't recall the patch ID :/

> would stripping the leading `../../` work?

I don't know if the file is found then but it would make standalone builds 
certainly easier.

I'm not sure if I calculate correctly but given:

`clang-tools-extra/unittests/clang-tidy/MatchersTest.cpp`

then `../../` means `clang-tools-extra/`, no? If so, that directory doesn't 
contain a `clang` directory here. It seems as if the `../../` is relative to 
some other directory but not this file. Or am I too tired to get it?



Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D133801/new/

https://reviews.llvm.org/D133801

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D56303: [clang-tidy] Recognize labelled statements when simplifying boolean exprs

2022-07-18 Thread Konrad Wilhelm Kleine via Phabricator via cfe-commits
kwk added subscribers: tstellar, serge-sans-paille, kwk.
kwk added inline comments.
Herald added a project: All.



Comment at: clang-tools-extra/unittests/clang-tidy/ReadabilityModuleTest.cpp:1
+#include "../../clang/unittests/ASTMatchers/ASTMatchersTest.h"
 #include "ClangTidyTest.h"

@LegalizeAdulthood I'm doing standalone builds of the LLVM projects and we're 
seeing an error that this file cannot be found. I wonder why this even worked 
before because we're essentially checking out (or better extract) `clang` into 
`/clang-15.0.0-src/` and `clang-extra-tools` into 
`clang-extra-tools-15.0.0-src`. So no matter how smart you design your `-I` 
include path flags, there`ll never be a `../../clang` that contains the file to 
be included here. @tstellar does this ring a bell? I've looked at this with 
@serge-sans-paille today and be both thought this cannot work. Here's the 
logfile {F23837155} of this build (which might be unreachable in a few days): 
https://download.copr.fedorainfracloud.org/results/@fedora-llvm-team/llvm-snapshots/fedora-35-x86_64/04639555-clang/builder-live.log.gz


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D56303/new/

https://reviews.llvm.org/D56303

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D121370: [clang-format] SortIncludes should support "@import" lines in Objective-C

2022-05-03 Thread Konrad Wilhelm Kleine via Phabricator via cfe-commits
kwk added a comment.

I found another problem with both regular expressions (pre mine and mine): They 
cannot find

  /* a comment before */ #include 

Is this a known problem @MyDeveloperDay @owenpan @krasimir ?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D121370/new/

https://reviews.llvm.org/D121370

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D121370: [clang-format] SortIncludes should support "@import" lines in Objective-C

2022-05-03 Thread Konrad Wilhelm Kleine via Phabricator via cfe-commits
kwk planned changes to this revision.
kwk added a comment.

Some thing that doesn't work at the moment is ordering an include like this:

  #include /*some include*/ "wontwork.h"

I wonder if it worked before. Let's see. Yes it worked. Grrr. I guess I need to 
do more...


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D121370/new/

https://reviews.llvm.org/D121370

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D121370: [clang-format] SortIncludes should support "@import" lines in Objective-C

2022-05-03 Thread Konrad Wilhelm Kleine via Phabricator via cfe-commits
kwk added a comment.

@krasimir could you please test this patch on your side? I've reopened it and 
tested it with the following file that contains both `//` and `/* ... */` 
trailing comments on include lines followed by `foo` and alike. The includes 
use `<...>` and `"..."` notation to locate files.

*test.h*

  #include 
  
  #include "util/bar.h"
  #include "util/foo/foo.h"  // foo
  #include "util/bar/bar.h"  // bar
  #include "utilzbar0.h"  // bar0
  #include   // foo3
  #include   // bar3
  #include   // foo2
  #include   // bar2
  #include "util/bar.h"
  #include "util/foo/foo.h"  /* foo */
  #include "util/bar/bar.h"  /* bar */
  #include "utilzbar0.h"  /* bar0 */
  #include   /* foo3 */
  #include   /* bar3 */
  #include   /* foo2 */
  #include   /* bar2 */

Run test with `ninja clang-format && bin/clang-format -style=google test.h`:

  #include   // bar2
  #include   /* bar2 */
  #include   // bar3
  #include   /* bar3 */
  #include   // foo2
  #include   /* foo2 */
  #include   // foo3
  #include   /* foo3 */
  
  #include 
  
  #include "util/bar.h"
  #include "util/bar/bar.h"  // bar
  #include "util/bar/bar.h"  /* bar */
  #include "util/foo/foo.h"  // foo
  #include "util/foo/foo.h"  /* foo */
  #include "utilzbar0.h" // bar0
  #include "utilzbar0.h" /* bar0 */

To me, this looks precisely how it should look like. What do you think?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D121370/new/

https://reviews.llvm.org/D121370

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D121370: [clang-format] SortIncludes should support "@import" lines in Objective-C

2022-05-03 Thread Konrad Wilhelm Kleine via Phabricator via cfe-commits
kwk updated this revision to Diff 426701.
kwk added a comment.

Address trailing comments on include lines by ignoring slashes in
characters that lead up to the match groups.

  ^[\t\ ]*[@#][\t\ ]*(import|include)([^"/]*("[^"]+")|[^]+>)|[\t/\ 
]*([^;]+;))
  ~~~ ~~~ 

  ^ ^   ^   ^   ^
  | |   |   |   |
  Now support @ and #.Clearly support "" and <> as ell as an
  include name without enclosing 
characters.
  Allows for no mixture of "> or <" or
  empty include names. Trailing
  comments on include lines as shown in
  D124513 are ignored now by
  ignoring slashes in the characters 
that
  lead up to a match group.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D121370/new/

https://reviews.llvm.org/D121370

Files:
  clang/include/clang/Tooling/Inclusions/HeaderIncludes.h
  clang/lib/Format/Format.cpp
  clang/lib/Tooling/Inclusions/HeaderIncludes.cpp
  clang/unittests/Format/SortIncludesTest.cpp

Index: clang/unittests/Format/SortIncludesTest.cpp
===
--- clang/unittests/Format/SortIncludesTest.cpp
+++ clang/unittests/Format/SortIncludesTest.cpp
@@ -472,6 +472,103 @@
  /*ExpectedNumRanges=*/0));
 }
 
+TEST_F(SortIncludesTest, SupportAtImportLines) {
+  // Test from https://github.com/llvm/llvm-project/issues/38995
+  EXPECT_EQ("#import \"a.h\"\n"
+"#import \"b.h\"\n"
+"#import \"c.h\"\n"
+"#import \n"
+"@import Foundation;\n",
+sort("#import \"b.h\"\n"
+ "#import \"c.h\"\n"
+ "#import \n"
+ "@import Foundation;\n"
+ "#import \"a.h\"\n"));
+
+  // Slightly more complicated test that shows sorting in each priorities still
+  // works.
+  EXPECT_EQ("#import \"a.h\"\n"
+"#import \"b.h\"\n"
+"#import \"c.h\"\n"
+"#import \n"
+"@import Base;\n"
+"@import Foundation;\n"
+"@import base;\n"
+"@import foundation;\n",
+sort("#import \"b.h\"\n"
+ "#import \"c.h\"\n"
+ "@import Base;\n"
+ "#import \n"
+ "@import foundation;\n"
+ "@import Foundation;\n"
+ "@import base;\n"
+ "#import \"a.h\"\n"));
+
+  // Test that shows main headers in two groups are still found and sorting
+  // still works. The @import's are kept in their respective group but are
+  // put at the end of each group.
+  FmtStyle.IncludeStyle.IncludeBlocks = tooling::IncludeStyle::IBS_Preserve;
+  EXPECT_EQ("#import \"foo.hpp\"\n"
+"#import \"b.h\"\n"
+"#import \"c.h\"\n"
+"#import \n"
+"@import Base;\n"
+"@import Foundation;\n"
+"@import foundation;\n"
+"\n"
+"#import \"foo.h\"\n"
+"#include \"foobar\"\n"
+"#import \n"
+"@import ;\n"
+"@import ;\n",
+sort("#import \"b.h\"\n"
+ "@import Foundation;\n"
+ "@import foundation;\n"
+ "#import \"c.h\"\n"
+ "#import \n"
+ "@import Base;\n"
+ "#import \"foo.hpp\"\n"
+ "\n"
+ "@import ;\n"
+ "#import \n"
+ "@import ;\n"
+ "#include \"foobar\"\n"
+ "#import \"foo.h\"\n",
+ "foo.c", 2));
+
+  // Regrouping and putting @import's in the very last group
+  FmtStyle.IncludeStyle.IncludeBlocks = tooling::IncludeStyle::IBS_Regroup;
+  EXPECT_EQ("#import \"foo.hpp\"\n"
+"\n"
+"#import \"b.h\"\n"
+"#import \"c.h\"\n"
+"#import \"foo.h\"\n"
+"#include \"foobar\"\n"
+"\n"
+"#import \n"
+"#import \n"
+"\n"
+"@import ;\n"
+"@import Base;\n"
+"@import Foundation;\n"
+"@import ;\n"
+"@import foundation;\n",
+sort("#import \"b.h\"\n"
+ "@import Foundation;\n"
+ "@import foundation;\n"
+ "#import \"c.h\"\n"
+ "#import \n"
+ "@import Base;\n"
+ "#import \"foo.hpp\"\n"
+ "\n"
+ "@import ;\n"
+ "#import 

[PATCH] D121370: [clang-format] SortIncludes should support "@import" lines in Objective-C

2022-04-26 Thread Konrad Wilhelm Kleine via Phabricator via cfe-commits
kwk added a comment.

In D121370#3471183 , @krasimir wrote:

> It appears that this regressed include sorting in the following case, where 
> the contents of `test.h` show the expected include order and the 
> `clang-format` behavior before this patch:
>
>   % cat test.h
>   #include 
>   
>   #include "util/bar.h"
>   #include "util/foo/foo.h"  // foo
>   % bin/clang-format --version; bin/clang-format -style=google test.h
>   clang-format version 15.0.0 (https://github.com/llvm/llvm-project.git 
> d46fa023caa2db5a9f1e21dd038bcb626261d958)
>   #include "util/foo/foo.h"  // foo
>   #include 
>   
>   #include "util/bar.h"
>
> @kwk could you please take a look

@krasimir I'm on sick leave and will have a look as soon as I'm back. Can it 
wait that long?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D121370/new/

https://reviews.llvm.org/D121370

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D121370: [clang-format] SortIncludes should support "@import" lines in Objective-C

2022-04-20 Thread Konrad Wilhelm Kleine via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGd46fa023caa2: [clang-format] SortIncludes should support 
@import lines in Objective-C (authored by kwk).

Changed prior to commit:
  https://reviews.llvm.org/D121370?vs=423584=423829#toc

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D121370/new/

https://reviews.llvm.org/D121370

Files:
  clang/include/clang/Tooling/Inclusions/HeaderIncludes.h
  clang/lib/Format/Format.cpp
  clang/lib/Tooling/Inclusions/HeaderIncludes.cpp
  clang/unittests/Format/SortIncludesTest.cpp

Index: clang/unittests/Format/SortIncludesTest.cpp
===
--- clang/unittests/Format/SortIncludesTest.cpp
+++ clang/unittests/Format/SortIncludesTest.cpp
@@ -458,6 +458,103 @@
  "#include \"b.h\"\n"));
 }
 
+TEST_F(SortIncludesTest, SupportAtImportLines) {
+  // Test from https://github.com/llvm/llvm-project/issues/38995
+  EXPECT_EQ("#import \"a.h\"\n"
+"#import \"b.h\"\n"
+"#import \"c.h\"\n"
+"#import \n"
+"@import Foundation;\n",
+sort("#import \"b.h\"\n"
+ "#import \"c.h\"\n"
+ "#import \n"
+ "@import Foundation;\n"
+ "#import \"a.h\"\n"));
+
+  // Slightly more complicated test that shows sorting in each priorities still
+  // works.
+  EXPECT_EQ("#import \"a.h\"\n"
+"#import \"b.h\"\n"
+"#import \"c.h\"\n"
+"#import \n"
+"@import Base;\n"
+"@import Foundation;\n"
+"@import base;\n"
+"@import foundation;\n",
+sort("#import \"b.h\"\n"
+ "#import \"c.h\"\n"
+ "@import Base;\n"
+ "#import \n"
+ "@import foundation;\n"
+ "@import Foundation;\n"
+ "@import base;\n"
+ "#import \"a.h\"\n"));
+
+  // Test that shows main headers in two groups are still found and sorting
+  // still works. The @import's are kept in their respective group but are
+  // put at the end of each group.
+  FmtStyle.IncludeStyle.IncludeBlocks = tooling::IncludeStyle::IBS_Preserve;
+  EXPECT_EQ("#import \"foo.hpp\"\n"
+"#import \"b.h\"\n"
+"#import \"c.h\"\n"
+"#import \n"
+"@import Base;\n"
+"@import Foundation;\n"
+"@import foundation;\n"
+"\n"
+"#import \"foo.h\"\n"
+"#include \"foobar\"\n"
+"#import \n"
+"@import ;\n"
+"@import ;\n",
+sort("#import \"b.h\"\n"
+ "@import Foundation;\n"
+ "@import foundation;\n"
+ "#import \"c.h\"\n"
+ "#import \n"
+ "@import Base;\n"
+ "#import \"foo.hpp\"\n"
+ "\n"
+ "@import ;\n"
+ "#import \n"
+ "@import ;\n"
+ "#include \"foobar\"\n"
+ "#import \"foo.h\"\n",
+ "foo.c", 2));
+
+  // Regrouping and putting @import's in the very last group
+  FmtStyle.IncludeStyle.IncludeBlocks = tooling::IncludeStyle::IBS_Regroup;
+  EXPECT_EQ("#import \"foo.hpp\"\n"
+"\n"
+"#import \"b.h\"\n"
+"#import \"c.h\"\n"
+"#import \"foo.h\"\n"
+"#include \"foobar\"\n"
+"\n"
+"#import \n"
+"#import \n"
+"\n"
+"@import ;\n"
+"@import Base;\n"
+"@import Foundation;\n"
+"@import ;\n"
+"@import foundation;\n",
+sort("#import \"b.h\"\n"
+ "@import Foundation;\n"
+ "@import foundation;\n"
+ "#import \"c.h\"\n"
+ "#import \n"
+ "@import Base;\n"
+ "#import \"foo.hpp\"\n"
+ "\n"
+ "@import ;\n"
+ "#import \n"
+ "@import ;\n"
+ "#include \"foobar\"\n"
+ "#import \"foo.h\"\n",
+ "foo.c"));
+}
+
 TEST_F(SortIncludesTest, LeavesMainHeaderFirst) {
   Style.IncludeIsMainRegex = "([-_](test|unittest))?$";
   EXPECT_EQ("#include \"llvm/a.h\"\n"
Index: clang/lib/Tooling/Inclusions/HeaderIncludes.cpp
===
--- clang/lib/Tooling/Inclusions/HeaderIncludes.cpp
+++ clang/lib/Tooling/Inclusions/HeaderIncludes.cpp
@@ -169,13 +169,6 @@
   });
 }
 
-inline StringRef trimInclude(StringRef IncludeName) {
-  return IncludeName.trim("\"<>");
-}
-
-const char IncludeRegexPattern[] =
-R"(^[\t\ ]*#[\t\ ]*(import|include)[^"<]*(["<][^">]*[">]))";
-
 // The 

[PATCH] D121370: [clang-format] SortIncludes should support "@import" lines in Objective-C

2022-04-19 Thread Konrad Wilhelm Kleine via Phabricator via cfe-commits
kwk updated this revision to Diff 423584.
kwk added a comment.

- typo: @include bar; -> @import bar;


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D121370/new/

https://reviews.llvm.org/D121370

Files:
  clang/include/clang/Tooling/Inclusions/HeaderIncludes.h
  clang/lib/Format/Format.cpp
  clang/lib/Tooling/Inclusions/HeaderIncludes.cpp

Index: clang/lib/Tooling/Inclusions/HeaderIncludes.cpp
===
--- clang/lib/Tooling/Inclusions/HeaderIncludes.cpp
+++ clang/lib/Tooling/Inclusions/HeaderIncludes.cpp
@@ -169,24 +169,6 @@
   });
 }
 
-inline StringRef trimInclude(StringRef IncludeName) {
-  return IncludeName.trim("\"<>;");
-}
-
-const char IncludeRegexPattern[] =
-R"(^[\t\ ]*[@#][\t\ ]*(import|include)([^"]*("[^"]+")|[^<]*(<[^>]+>)|[\t\ ]*([^;]+;)))";
-
-// Returns the last match group in the above regex (IncludeRegexPattern) that
-// is not empty.
-StringRef getIncludeNameFromMatches(const SmallVectorImpl ) {
-  for (int i = Matches.size() - 1; i > 0; i--) {
-if (!Matches[i].empty())
-  return Matches[i];
-  }
-  llvm_unreachable("No non-empty match group found in list of matches");
-  return StringRef();
-}
-
 // The filename of Path excluding extension.
 // Used to match implementation with headers, this differs from sys::path::stem:
 //  - in names with multiple dots (foo.cu.cc) it terminates at the *first*
@@ -285,8 +267,7 @@
   MaxInsertOffset(MinInsertOffset +
   getMaxHeaderInsertionOffset(
   FileName, Code.drop_front(MinInsertOffset), Style)),
-  Categories(Style, FileName),
-  IncludeRegex(llvm::Regex(IncludeRegexPattern)) {
+  Categories(Style, FileName), IncludeRegex(getCppIncludeRegex()) {
   // Add 0 for main header and INT_MAX for headers that are not in any
   // category.
   Priorities = {0, INT_MAX};
@@ -301,7 +282,7 @@
   for (auto Line : Lines) {
 NextLineOffset = std::min(Code.size(), Offset + Line.size() + 1);
 if (IncludeRegex.match(Line, )) {
-  StringRef IncludeName = getIncludeNameFromMatches(Matches);
+  StringRef IncludeName = tooling::getIncludeNameFromMatches(Matches);
   // If this is the last line without trailing newline, we need to make
   // sure we don't delete across the file boundary.
   addExistingInclude(
@@ -415,5 +396,25 @@
   return Result;
 }
 
+llvm::Regex getCppIncludeRegex() {
+  static const char CppIncludeRegexPattern[] =
+  R"(^[\t\ ]*[@#][\t\ ]*(import|include)([^"]*("[^"]+")|[^<]*(<[^>]+>)|[\t\ ]*([^;]+;)))";
+  return llvm::Regex(CppIncludeRegexPattern);
+}
+
+llvm::StringRef getIncludeNameFromMatches(
+const llvm::SmallVectorImpl ) {
+  for (auto Match : llvm::reverse(Matches)) {
+if (!Match.empty())
+  return Match;
+  }
+  llvm_unreachable("No non-empty match group found in list of matches");
+  return llvm::StringRef();
+}
+
+llvm::StringRef trimInclude(llvm::StringRef IncludeName) {
+  return IncludeName.trim("\"<>;");
+}
+
 } // namespace tooling
 } // namespace clang
Index: clang/lib/Format/Format.cpp
===
--- clang/lib/Format/Format.cpp
+++ clang/lib/Format/Format.cpp
@@ -2722,23 +2722,6 @@
   }
 }
 
-namespace {
-
-const char CppIncludeRegexPattern[] =
-R"(^[\t\ ]*[@#][\t\ ]*(import|include)([^"]*("[^"]+")|[^<]*(<[^>]+>)|[\t\ ]*([^;]+;)))";
-} // anonymous namespace
-
-// Returns the last match group in the above regex (CppIncludeRegexPattern) that
-// is not empty.
-StringRef getIncludeNameFromMatches(const SmallVectorImpl ) {
-  for (int i = Matches.size() - 1; i > 0; i--) {
-if (!Matches[i].empty())
-  return Matches[i];
-  }
-  llvm_unreachable("No non-empty match group found in list of matches");
-  return StringRef();
-}
-
 tooling::Replacements sortCppIncludes(const FormatStyle , StringRef Code,
   ArrayRef Ranges,
   StringRef FileName,
@@ -2748,7 +2731,7 @@
   .StartsWith("\xEF\xBB\xBF", 3) // UTF-8 BOM
   .Default(0);
   unsigned SearchFrom = 0;
-  llvm::Regex IncludeRegex(CppIncludeRegexPattern);
+  llvm::Regex IncludeRegex(tooling::getCppIncludeRegex());
   SmallVector Matches;
   SmallVector IncludesInBlock;
 
@@ -2804,7 +2787,7 @@
 bool MergeWithNextLine = Trimmed.endswith("\\");
 if (!FormattingOff && !MergeWithNextLine) {
   if (IncludeRegex.match(Line, )) {
-StringRef IncludeName = getIncludeNameFromMatches(Matches);
+StringRef IncludeName = tooling::getIncludeNameFromMatches(Matches);
 // This addresses https://github.com/llvm/llvm-project/issues/38995
 bool WithSemicolon = false;
 if (!IncludeName.startswith("\"") && !IncludeName.startswith("<") &&
@@ -3087,20 +3070,15 @@
 
 inline bool isHeaderInsertion(const tooling::Replacement ) {
   return Replace.getOffset() 

[PATCH] D121370: [clang-format] SortIncludes should support "@import" lines in Objective-C

2022-04-19 Thread Konrad Wilhelm Kleine via Phabricator via cfe-commits
kwk marked 2 inline comments as done.
kwk added a comment.

In D121370#3456223 , @owenpan wrote:

> Should we handle `#import` and `@import` for Object-C only so as to simply 
> the regex for C++?

@owenpan my counter question probably reveals how few things I know about 
clang-format and how much I still have to learn. I only see `sortCppIncludes` 
but no `sortObjCIncludes` in the function list in `Format.h`. That said, do you 
want to introduce that or do you want to put logic in `sortCppIncludes` that 
knows about the programming language at hand and decides which regex to pick?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D121370/new/

https://reviews.llvm.org/D121370

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D121370: [clang-format] SortIncludes should support "@import" lines in Objective-C

2022-04-19 Thread Konrad Wilhelm Kleine via Phabricator via cfe-commits
kwk updated this revision to Diff 423582.
kwk added a comment.

- Make functions lowercase


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D121370/new/

https://reviews.llvm.org/D121370

Files:
  clang/include/clang/Tooling/Inclusions/HeaderIncludes.h
  clang/lib/Format/Format.cpp
  clang/lib/Tooling/Inclusions/HeaderIncludes.cpp

Index: clang/lib/Tooling/Inclusions/HeaderIncludes.cpp
===
--- clang/lib/Tooling/Inclusions/HeaderIncludes.cpp
+++ clang/lib/Tooling/Inclusions/HeaderIncludes.cpp
@@ -169,24 +169,6 @@
   });
 }
 
-inline StringRef trimInclude(StringRef IncludeName) {
-  return IncludeName.trim("\"<>;");
-}
-
-const char IncludeRegexPattern[] =
-R"(^[\t\ ]*[@#][\t\ ]*(import|include)([^"]*("[^"]+")|[^<]*(<[^>]+>)|[\t\ ]*([^;]+;)))";
-
-// Returns the last match group in the above regex (IncludeRegexPattern) that
-// is not empty.
-StringRef getIncludeNameFromMatches(const SmallVectorImpl ) {
-  for (int i = Matches.size() - 1; i > 0; i--) {
-if (!Matches[i].empty())
-  return Matches[i];
-  }
-  llvm_unreachable("No non-empty match group found in list of matches");
-  return StringRef();
-}
-
 // The filename of Path excluding extension.
 // Used to match implementation with headers, this differs from sys::path::stem:
 //  - in names with multiple dots (foo.cu.cc) it terminates at the *first*
@@ -285,8 +267,7 @@
   MaxInsertOffset(MinInsertOffset +
   getMaxHeaderInsertionOffset(
   FileName, Code.drop_front(MinInsertOffset), Style)),
-  Categories(Style, FileName),
-  IncludeRegex(llvm::Regex(IncludeRegexPattern)) {
+  Categories(Style, FileName), IncludeRegex(getCppIncludeRegex()) {
   // Add 0 for main header and INT_MAX for headers that are not in any
   // category.
   Priorities = {0, INT_MAX};
@@ -301,7 +282,7 @@
   for (auto Line : Lines) {
 NextLineOffset = std::min(Code.size(), Offset + Line.size() + 1);
 if (IncludeRegex.match(Line, )) {
-  StringRef IncludeName = getIncludeNameFromMatches(Matches);
+  StringRef IncludeName = tooling::getIncludeNameFromMatches(Matches);
   // If this is the last line without trailing newline, we need to make
   // sure we don't delete across the file boundary.
   addExistingInclude(
@@ -415,5 +396,25 @@
   return Result;
 }
 
+llvm::Regex getCppIncludeRegex() {
+  static const char CppIncludeRegexPattern[] =
+  R"(^[\t\ ]*[@#][\t\ ]*(import|include)([^"]*("[^"]+")|[^<]*(<[^>]+>)|[\t\ ]*([^;]+;)))";
+  return llvm::Regex(CppIncludeRegexPattern);
+}
+
+llvm::StringRef getIncludeNameFromMatches(
+const llvm::SmallVectorImpl ) {
+  for (auto Match : llvm::reverse(Matches)) {
+if (!Match.empty())
+  return Match;
+  }
+  llvm_unreachable("No non-empty match group found in list of matches");
+  return llvm::StringRef();
+}
+
+llvm::StringRef trimInclude(llvm::StringRef IncludeName) {
+  return IncludeName.trim("\"<>;");
+}
+
 } // namespace tooling
 } // namespace clang
Index: clang/lib/Format/Format.cpp
===
--- clang/lib/Format/Format.cpp
+++ clang/lib/Format/Format.cpp
@@ -2722,23 +2722,6 @@
   }
 }
 
-namespace {
-
-const char CppIncludeRegexPattern[] =
-R"(^[\t\ ]*[@#][\t\ ]*(import|include)([^"]*("[^"]+")|[^<]*(<[^>]+>)|[\t\ ]*([^;]+;)))";
-} // anonymous namespace
-
-// Returns the last match group in the above regex (CppIncludeRegexPattern) that
-// is not empty.
-StringRef getIncludeNameFromMatches(const SmallVectorImpl ) {
-  for (int i = Matches.size() - 1; i > 0; i--) {
-if (!Matches[i].empty())
-  return Matches[i];
-  }
-  llvm_unreachable("No non-empty match group found in list of matches");
-  return StringRef();
-}
-
 tooling::Replacements sortCppIncludes(const FormatStyle , StringRef Code,
   ArrayRef Ranges,
   StringRef FileName,
@@ -2748,7 +2731,7 @@
   .StartsWith("\xEF\xBB\xBF", 3) // UTF-8 BOM
   .Default(0);
   unsigned SearchFrom = 0;
-  llvm::Regex IncludeRegex(CppIncludeRegexPattern);
+  llvm::Regex IncludeRegex(tooling::getCppIncludeRegex());
   SmallVector Matches;
   SmallVector IncludesInBlock;
 
@@ -2804,7 +2787,7 @@
 bool MergeWithNextLine = Trimmed.endswith("\\");
 if (!FormattingOff && !MergeWithNextLine) {
   if (IncludeRegex.match(Line, )) {
-StringRef IncludeName = getIncludeNameFromMatches(Matches);
+StringRef IncludeName = tooling::getIncludeNameFromMatches(Matches);
 // This addresses https://github.com/llvm/llvm-project/issues/38995
 bool WithSemicolon = false;
 if (!IncludeName.startswith("\"") && !IncludeName.startswith("<") &&
@@ -3087,20 +3070,15 @@
 
 inline bool isHeaderInsertion(const tooling::Replacement ) {
   return Replace.getOffset() == 

[PATCH] D121370: [clang-format] SortIncludes should support "@import" lines in Objective-C

2022-04-16 Thread Konrad Wilhelm Kleine via Phabricator via cfe-commits
kwk marked 3 inline comments as done.
kwk added inline comments.



Comment at: clang/lib/Format/Format.cpp:2692-2695
+  for (int i = Matches.size() - 1; i > 0; i--) {
+if (!Matches[i].empty())
+  return Matches[i];
+  }

owenpan wrote:
> I think you missed `Matches[0]`.
I did miss it and fixed it but it doesn't make much sense to use the first 
match because that's always the overall string that's being matched. 
Nevertheless, I've used your porposed reverse loop and the logic is better if 
it includes even the first match.



Comment at: clang/lib/Tooling/Inclusions/HeaderIncludes.cpp:176-188
 const char IncludeRegexPattern[] =
-R"(^[\t\ ]*#[\t\ ]*(import|include)[^"<]*(["<][^">]*[">]))";
+R"(^[\t\ ]*[@#][\t\ ]*(import|include)([^"]*("[^"]+")|[^<]*(<[^>]+>)|[\t\ 
]*([^;]+;)))";
+
+// Returns the last match group in the above regex (IncludeRegexPattern) that
+// is not empty.
+StringRef getIncludeNameFromMatches(const SmallVectorImpl ) 
{
+  for (int i = Matches.size() - 1; i > 0; i--) {

owenpan wrote:
> owenpan wrote:
> > If these are the same as in `Format.cpp` above, we should move the 
> > definitions to `HeaderIncludes.h`.
> > If these are the same as in `Format.cpp` above, we should move the 
> > definitions to `HeaderIncludes.h`.
> 
> I meant we should remove the definitions from `Format.cpp` and add the 
> declarations to `HeaderIncludes.h`.
I think I've done what you intended me to do.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D121370/new/

https://reviews.llvm.org/D121370

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D121370: [clang-format] SortIncludes should support "@import" lines in Objective-C

2022-04-16 Thread Konrad Wilhelm Kleine via Phabricator via cfe-commits
kwk updated this revision to Diff 423257.
kwk marked an inline comment as done.
kwk added a comment.

- Make function static


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D121370/new/

https://reviews.llvm.org/D121370

Files:
  clang/include/clang/Tooling/Inclusions/HeaderIncludes.h
  clang/lib/Format/Format.cpp
  clang/lib/Tooling/Inclusions/HeaderIncludes.cpp
  clang/unittests/Format/SortIncludesTest.cpp

Index: clang/unittests/Format/SortIncludesTest.cpp
===
--- clang/unittests/Format/SortIncludesTest.cpp
+++ clang/unittests/Format/SortIncludesTest.cpp
@@ -458,6 +458,103 @@
  "#include \"b.h\"\n"));
 }
 
+TEST_F(SortIncludesTest, SupportAtImportLines) {
+  // Test from https://github.com/llvm/llvm-project/issues/38995
+  EXPECT_EQ("#import \"a.h\"\n"
+"#import \"b.h\"\n"
+"#import \"c.h\"\n"
+"#import \n"
+"@import Foundation;\n",
+sort("#import \"b.h\"\n"
+ "#import \"c.h\"\n"
+ "#import \n"
+ "@import Foundation;\n"
+ "#import \"a.h\"\n"));
+
+  // Slightly more complicated test that shows sorting in each priorities still
+  // works.
+  EXPECT_EQ("#import \"a.h\"\n"
+"#import \"b.h\"\n"
+"#import \"c.h\"\n"
+"#import \n"
+"@import Base;\n"
+"@import Foundation;\n"
+"@import base;\n"
+"@import foundation;\n",
+sort("#import \"b.h\"\n"
+ "#import \"c.h\"\n"
+ "@import Base;\n"
+ "#import \n"
+ "@import foundation;\n"
+ "@import Foundation;\n"
+ "@import base;\n"
+ "#import \"a.h\"\n"));
+
+  // Test that shows main headers in two groups are still found and sorting
+  // still works. The @import's are kept in their respective group but are
+  // put at the end of each group.
+  FmtStyle.IncludeStyle.IncludeBlocks = tooling::IncludeStyle::IBS_Preserve;
+  EXPECT_EQ("#import \"foo.hpp\"\n"
+"#import \"b.h\"\n"
+"#import \"c.h\"\n"
+"#import \n"
+"@import Base;\n"
+"@import Foundation;\n"
+"@import foundation;\n"
+"\n"
+"#import \"foo.h\"\n"
+"#include \"foobar\"\n"
+"#import \n"
+"@import ;\n"
+"@import ;\n",
+sort("#import \"b.h\"\n"
+ "@import Foundation;\n"
+ "@import foundation;\n"
+ "#import \"c.h\"\n"
+ "#import \n"
+ "@import Base;\n"
+ "#import \"foo.hpp\"\n"
+ "\n"
+ "@import ;\n"
+ "#import \n"
+ "@import ;\n"
+ "#include \"foobar\"\n"
+ "#import \"foo.h\"\n",
+ "foo.c", 2));
+
+  // Regrouping and putting @import's in the very last group
+  FmtStyle.IncludeStyle.IncludeBlocks = tooling::IncludeStyle::IBS_Regroup;
+  EXPECT_EQ("#import \"foo.hpp\"\n"
+"\n"
+"#import \"b.h\"\n"
+"#import \"c.h\"\n"
+"#import \"foo.h\"\n"
+"#include \"foobar\"\n"
+"\n"
+"#import \n"
+"#import \n"
+"\n"
+"@import ;\n"
+"@import Base;\n"
+"@import Foundation;\n"
+"@import ;\n"
+"@import foundation;\n",
+sort("#import \"b.h\"\n"
+ "@import Foundation;\n"
+ "@import foundation;\n"
+ "#import \"c.h\"\n"
+ "#import \n"
+ "@import Base;\n"
+ "#import \"foo.hpp\"\n"
+ "\n"
+ "@import ;\n"
+ "#import \n"
+ "@import ;\n"
+ "#include \"foobar\"\n"
+ "#import \"foo.h\"\n",
+ "foo.c"));
+}
+
 TEST_F(SortIncludesTest, LeavesMainHeaderFirst) {
   Style.IncludeIsMainRegex = "([-_](test|unittest))?$";
   EXPECT_EQ("#include \"llvm/a.h\"\n"
Index: clang/lib/Tooling/Inclusions/HeaderIncludes.cpp
===
--- clang/lib/Tooling/Inclusions/HeaderIncludes.cpp
+++ clang/lib/Tooling/Inclusions/HeaderIncludes.cpp
@@ -169,13 +169,6 @@
   });
 }
 
-inline StringRef trimInclude(StringRef IncludeName) {
-  return IncludeName.trim("\"<>");
-}
-
-const char IncludeRegexPattern[] =
-R"(^[\t\ ]*#[\t\ ]*(import|include)[^"<]*(["<][^">]*[">]))";
-
 // The filename of Path excluding extension.
 // Used to match implementation with headers, this differs from sys::path::stem:
 //  - in names with multiple dots (foo.cu.cc) it terminates at the *first*
@@ -274,8 

[PATCH] D121370: [clang-format] SortIncludes should support "@import" lines in Objective-C

2022-04-16 Thread Konrad Wilhelm Kleine via Phabricator via cfe-commits
kwk updated this revision to Diff 423256.
kwk added a comment.

- Use proposed reverse loop


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D121370/new/

https://reviews.llvm.org/D121370

Files:
  clang/include/clang/Tooling/Inclusions/HeaderIncludes.h
  clang/lib/Format/Format.cpp
  clang/lib/Tooling/Inclusions/HeaderIncludes.cpp
  clang/unittests/Format/SortIncludesTest.cpp

Index: clang/unittests/Format/SortIncludesTest.cpp
===
--- clang/unittests/Format/SortIncludesTest.cpp
+++ clang/unittests/Format/SortIncludesTest.cpp
@@ -458,6 +458,103 @@
  "#include \"b.h\"\n"));
 }
 
+TEST_F(SortIncludesTest, SupportAtImportLines) {
+  // Test from https://github.com/llvm/llvm-project/issues/38995
+  EXPECT_EQ("#import \"a.h\"\n"
+"#import \"b.h\"\n"
+"#import \"c.h\"\n"
+"#import \n"
+"@import Foundation;\n",
+sort("#import \"b.h\"\n"
+ "#import \"c.h\"\n"
+ "#import \n"
+ "@import Foundation;\n"
+ "#import \"a.h\"\n"));
+
+  // Slightly more complicated test that shows sorting in each priorities still
+  // works.
+  EXPECT_EQ("#import \"a.h\"\n"
+"#import \"b.h\"\n"
+"#import \"c.h\"\n"
+"#import \n"
+"@import Base;\n"
+"@import Foundation;\n"
+"@import base;\n"
+"@import foundation;\n",
+sort("#import \"b.h\"\n"
+ "#import \"c.h\"\n"
+ "@import Base;\n"
+ "#import \n"
+ "@import foundation;\n"
+ "@import Foundation;\n"
+ "@import base;\n"
+ "#import \"a.h\"\n"));
+
+  // Test that shows main headers in two groups are still found and sorting
+  // still works. The @import's are kept in their respective group but are
+  // put at the end of each group.
+  FmtStyle.IncludeStyle.IncludeBlocks = tooling::IncludeStyle::IBS_Preserve;
+  EXPECT_EQ("#import \"foo.hpp\"\n"
+"#import \"b.h\"\n"
+"#import \"c.h\"\n"
+"#import \n"
+"@import Base;\n"
+"@import Foundation;\n"
+"@import foundation;\n"
+"\n"
+"#import \"foo.h\"\n"
+"#include \"foobar\"\n"
+"#import \n"
+"@import ;\n"
+"@import ;\n",
+sort("#import \"b.h\"\n"
+ "@import Foundation;\n"
+ "@import foundation;\n"
+ "#import \"c.h\"\n"
+ "#import \n"
+ "@import Base;\n"
+ "#import \"foo.hpp\"\n"
+ "\n"
+ "@import ;\n"
+ "#import \n"
+ "@import ;\n"
+ "#include \"foobar\"\n"
+ "#import \"foo.h\"\n",
+ "foo.c", 2));
+
+  // Regrouping and putting @import's in the very last group
+  FmtStyle.IncludeStyle.IncludeBlocks = tooling::IncludeStyle::IBS_Regroup;
+  EXPECT_EQ("#import \"foo.hpp\"\n"
+"\n"
+"#import \"b.h\"\n"
+"#import \"c.h\"\n"
+"#import \"foo.h\"\n"
+"#include \"foobar\"\n"
+"\n"
+"#import \n"
+"#import \n"
+"\n"
+"@import ;\n"
+"@import Base;\n"
+"@import Foundation;\n"
+"@import ;\n"
+"@import foundation;\n",
+sort("#import \"b.h\"\n"
+ "@import Foundation;\n"
+ "@import foundation;\n"
+ "#import \"c.h\"\n"
+ "#import \n"
+ "@import Base;\n"
+ "#import \"foo.hpp\"\n"
+ "\n"
+ "@import ;\n"
+ "#import \n"
+ "@import ;\n"
+ "#include \"foobar\"\n"
+ "#import \"foo.h\"\n",
+ "foo.c"));
+}
+
 TEST_F(SortIncludesTest, LeavesMainHeaderFirst) {
   Style.IncludeIsMainRegex = "([-_](test|unittest))?$";
   EXPECT_EQ("#include \"llvm/a.h\"\n"
Index: clang/lib/Tooling/Inclusions/HeaderIncludes.cpp
===
--- clang/lib/Tooling/Inclusions/HeaderIncludes.cpp
+++ clang/lib/Tooling/Inclusions/HeaderIncludes.cpp
@@ -169,13 +169,6 @@
   });
 }
 
-inline StringRef trimInclude(StringRef IncludeName) {
-  return IncludeName.trim("\"<>");
-}
-
-const char IncludeRegexPattern[] =
-R"(^[\t\ ]*#[\t\ ]*(import|include)[^"<]*(["<][^">]*[">]))";
-
 // The filename of Path excluding extension.
 // Used to match implementation with headers, this differs from sys::path::stem:
 //  - in names with multiple dots (foo.cu.cc) it terminates at the *first*
@@ -274,8 +267,7 @@
   

[PATCH] D121370: [clang-format] SortIncludes should support "@import" lines in Objective-C

2022-04-16 Thread Konrad Wilhelm Kleine via Phabricator via cfe-commits
kwk updated this revision to Diff 423255.
kwk added a comment.

- Added llvm:: namespace


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D121370/new/

https://reviews.llvm.org/D121370

Files:
  clang/include/clang/Tooling/Inclusions/HeaderIncludes.h
  clang/lib/Format/Format.cpp
  clang/lib/Tooling/Inclusions/HeaderIncludes.cpp
  clang/unittests/Format/SortIncludesTest.cpp

Index: clang/unittests/Format/SortIncludesTest.cpp
===
--- clang/unittests/Format/SortIncludesTest.cpp
+++ clang/unittests/Format/SortIncludesTest.cpp
@@ -458,6 +458,103 @@
  "#include \"b.h\"\n"));
 }
 
+TEST_F(SortIncludesTest, SupportAtImportLines) {
+  // Test from https://github.com/llvm/llvm-project/issues/38995
+  EXPECT_EQ("#import \"a.h\"\n"
+"#import \"b.h\"\n"
+"#import \"c.h\"\n"
+"#import \n"
+"@import Foundation;\n",
+sort("#import \"b.h\"\n"
+ "#import \"c.h\"\n"
+ "#import \n"
+ "@import Foundation;\n"
+ "#import \"a.h\"\n"));
+
+  // Slightly more complicated test that shows sorting in each priorities still
+  // works.
+  EXPECT_EQ("#import \"a.h\"\n"
+"#import \"b.h\"\n"
+"#import \"c.h\"\n"
+"#import \n"
+"@import Base;\n"
+"@import Foundation;\n"
+"@import base;\n"
+"@import foundation;\n",
+sort("#import \"b.h\"\n"
+ "#import \"c.h\"\n"
+ "@import Base;\n"
+ "#import \n"
+ "@import foundation;\n"
+ "@import Foundation;\n"
+ "@import base;\n"
+ "#import \"a.h\"\n"));
+
+  // Test that shows main headers in two groups are still found and sorting
+  // still works. The @import's are kept in their respective group but are
+  // put at the end of each group.
+  FmtStyle.IncludeStyle.IncludeBlocks = tooling::IncludeStyle::IBS_Preserve;
+  EXPECT_EQ("#import \"foo.hpp\"\n"
+"#import \"b.h\"\n"
+"#import \"c.h\"\n"
+"#import \n"
+"@import Base;\n"
+"@import Foundation;\n"
+"@import foundation;\n"
+"\n"
+"#import \"foo.h\"\n"
+"#include \"foobar\"\n"
+"#import \n"
+"@import ;\n"
+"@import ;\n",
+sort("#import \"b.h\"\n"
+ "@import Foundation;\n"
+ "@import foundation;\n"
+ "#import \"c.h\"\n"
+ "#import \n"
+ "@import Base;\n"
+ "#import \"foo.hpp\"\n"
+ "\n"
+ "@import ;\n"
+ "#import \n"
+ "@import ;\n"
+ "#include \"foobar\"\n"
+ "#import \"foo.h\"\n",
+ "foo.c", 2));
+
+  // Regrouping and putting @import's in the very last group
+  FmtStyle.IncludeStyle.IncludeBlocks = tooling::IncludeStyle::IBS_Regroup;
+  EXPECT_EQ("#import \"foo.hpp\"\n"
+"\n"
+"#import \"b.h\"\n"
+"#import \"c.h\"\n"
+"#import \"foo.h\"\n"
+"#include \"foobar\"\n"
+"\n"
+"#import \n"
+"#import \n"
+"\n"
+"@import ;\n"
+"@import Base;\n"
+"@import Foundation;\n"
+"@import ;\n"
+"@import foundation;\n",
+sort("#import \"b.h\"\n"
+ "@import Foundation;\n"
+ "@import foundation;\n"
+ "#import \"c.h\"\n"
+ "#import \n"
+ "@import Base;\n"
+ "#import \"foo.hpp\"\n"
+ "\n"
+ "@import ;\n"
+ "#import \n"
+ "@import ;\n"
+ "#include \"foobar\"\n"
+ "#import \"foo.h\"\n",
+ "foo.c"));
+}
+
 TEST_F(SortIncludesTest, LeavesMainHeaderFirst) {
   Style.IncludeIsMainRegex = "([-_](test|unittest))?$";
   EXPECT_EQ("#include \"llvm/a.h\"\n"
Index: clang/lib/Tooling/Inclusions/HeaderIncludes.cpp
===
--- clang/lib/Tooling/Inclusions/HeaderIncludes.cpp
+++ clang/lib/Tooling/Inclusions/HeaderIncludes.cpp
@@ -169,13 +169,6 @@
   });
 }
 
-inline StringRef trimInclude(StringRef IncludeName) {
-  return IncludeName.trim("\"<>");
-}
-
-const char IncludeRegexPattern[] =
-R"(^[\t\ ]*#[\t\ ]*(import|include)[^"<]*(["<][^">]*[">]))";
-
 // The filename of Path excluding extension.
 // Used to match implementation with headers, this differs from sys::path::stem:
 //  - in names with multiple dots (foo.cu.cc) it terminates at the *first*
@@ -274,8 +267,7 @@
   

[PATCH] D121370: [clang-format] SortIncludes should support "@import" lines in Objective-C

2022-04-16 Thread Konrad Wilhelm Kleine via Phabricator via cfe-commits
kwk updated this revision to Diff 423254.
kwk added a comment.

- Put shared code for finding include names HeaderIncludes


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D121370/new/

https://reviews.llvm.org/D121370

Files:
  clang/include/clang/Tooling/Inclusions/HeaderIncludes.h
  clang/lib/Format/Format.cpp
  clang/lib/Tooling/Inclusions/HeaderIncludes.cpp
  clang/unittests/Format/SortIncludesTest.cpp

Index: clang/unittests/Format/SortIncludesTest.cpp
===
--- clang/unittests/Format/SortIncludesTest.cpp
+++ clang/unittests/Format/SortIncludesTest.cpp
@@ -458,6 +458,103 @@
  "#include \"b.h\"\n"));
 }
 
+TEST_F(SortIncludesTest, SupportAtImportLines) {
+  // Test from https://github.com/llvm/llvm-project/issues/38995
+  EXPECT_EQ("#import \"a.h\"\n"
+"#import \"b.h\"\n"
+"#import \"c.h\"\n"
+"#import \n"
+"@import Foundation;\n",
+sort("#import \"b.h\"\n"
+ "#import \"c.h\"\n"
+ "#import \n"
+ "@import Foundation;\n"
+ "#import \"a.h\"\n"));
+
+  // Slightly more complicated test that shows sorting in each priorities still
+  // works.
+  EXPECT_EQ("#import \"a.h\"\n"
+"#import \"b.h\"\n"
+"#import \"c.h\"\n"
+"#import \n"
+"@import Base;\n"
+"@import Foundation;\n"
+"@import base;\n"
+"@import foundation;\n",
+sort("#import \"b.h\"\n"
+ "#import \"c.h\"\n"
+ "@import Base;\n"
+ "#import \n"
+ "@import foundation;\n"
+ "@import Foundation;\n"
+ "@import base;\n"
+ "#import \"a.h\"\n"));
+
+  // Test that shows main headers in two groups are still found and sorting
+  // still works. The @import's are kept in their respective group but are
+  // put at the end of each group.
+  FmtStyle.IncludeStyle.IncludeBlocks = tooling::IncludeStyle::IBS_Preserve;
+  EXPECT_EQ("#import \"foo.hpp\"\n"
+"#import \"b.h\"\n"
+"#import \"c.h\"\n"
+"#import \n"
+"@import Base;\n"
+"@import Foundation;\n"
+"@import foundation;\n"
+"\n"
+"#import \"foo.h\"\n"
+"#include \"foobar\"\n"
+"#import \n"
+"@import ;\n"
+"@import ;\n",
+sort("#import \"b.h\"\n"
+ "@import Foundation;\n"
+ "@import foundation;\n"
+ "#import \"c.h\"\n"
+ "#import \n"
+ "@import Base;\n"
+ "#import \"foo.hpp\"\n"
+ "\n"
+ "@import ;\n"
+ "#import \n"
+ "@import ;\n"
+ "#include \"foobar\"\n"
+ "#import \"foo.h\"\n",
+ "foo.c", 2));
+
+  // Regrouping and putting @import's in the very last group
+  FmtStyle.IncludeStyle.IncludeBlocks = tooling::IncludeStyle::IBS_Regroup;
+  EXPECT_EQ("#import \"foo.hpp\"\n"
+"\n"
+"#import \"b.h\"\n"
+"#import \"c.h\"\n"
+"#import \"foo.h\"\n"
+"#include \"foobar\"\n"
+"\n"
+"#import \n"
+"#import \n"
+"\n"
+"@import ;\n"
+"@import Base;\n"
+"@import Foundation;\n"
+"@import ;\n"
+"@import foundation;\n",
+sort("#import \"b.h\"\n"
+ "@import Foundation;\n"
+ "@import foundation;\n"
+ "#import \"c.h\"\n"
+ "#import \n"
+ "@import Base;\n"
+ "#import \"foo.hpp\"\n"
+ "\n"
+ "@import ;\n"
+ "#import \n"
+ "@import ;\n"
+ "#include \"foobar\"\n"
+ "#import \"foo.h\"\n",
+ "foo.c"));
+}
+
 TEST_F(SortIncludesTest, LeavesMainHeaderFirst) {
   Style.IncludeIsMainRegex = "([-_](test|unittest))?$";
   EXPECT_EQ("#include \"llvm/a.h\"\n"
Index: clang/lib/Tooling/Inclusions/HeaderIncludes.cpp
===
--- clang/lib/Tooling/Inclusions/HeaderIncludes.cpp
+++ clang/lib/Tooling/Inclusions/HeaderIncludes.cpp
@@ -169,13 +169,6 @@
   });
 }
 
-inline StringRef trimInclude(StringRef IncludeName) {
-  return IncludeName.trim("\"<>");
-}
-
-const char IncludeRegexPattern[] =
-R"(^[\t\ ]*#[\t\ ]*(import|include)[^"<]*(["<][^">]*[">]))";
-
 // The filename of Path excluding extension.
 // Used to match implementation with headers, this differs from sys::path::stem:
 //  - in names with multiple dots (foo.cu.cc) it terminates at the *first*
@@ -274,8 +267,7 

[PATCH] D121370: [clang-format] SortIncludes should support "@import" lines in Objective-C

2022-03-22 Thread Konrad Wilhelm Kleine via Phabricator via cfe-commits
kwk marked 2 inline comments as done.
kwk added a comment.

@HazardyKnusperkeks I've addressed your comments and did an early return 
together with `llvm_unreachable()` which is used in the `clang/lib/Format` in 
other places as well. I hope this is to your liking. There's no longer an 
`assert`. Do you want that as well?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D121370/new/

https://reviews.llvm.org/D121370

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D121370: [clang-format] SortIncludes should support "@import" lines in Objective-C

2022-03-22 Thread Konrad Wilhelm Kleine via Phabricator via cfe-commits
kwk updated this revision to Diff 417379.
kwk added a comment.

- Address review comment


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D121370/new/

https://reviews.llvm.org/D121370

Files:
  clang/lib/Format/Format.cpp
  clang/lib/Tooling/Inclusions/HeaderIncludes.cpp
  clang/unittests/Format/SortIncludesTest.cpp

Index: clang/unittests/Format/SortIncludesTest.cpp
===
--- clang/unittests/Format/SortIncludesTest.cpp
+++ clang/unittests/Format/SortIncludesTest.cpp
@@ -458,6 +458,103 @@
  "#include \"b.h\"\n"));
 }
 
+TEST_F(SortIncludesTest, SupportAtImportLines) {
+  // Test from https://github.com/llvm/llvm-project/issues/38995
+  EXPECT_EQ("#import \"a.h\"\n"
+"#import \"b.h\"\n"
+"#import \"c.h\"\n"
+"#import \n"
+"@import Foundation;\n",
+sort("#import \"b.h\"\n"
+ "#import \"c.h\"\n"
+ "#import \n"
+ "@import Foundation;\n"
+ "#import \"a.h\"\n"));
+
+  // Slightly more complicated test that shows sorting in each priorities still
+  // works.
+  EXPECT_EQ("#import \"a.h\"\n"
+"#import \"b.h\"\n"
+"#import \"c.h\"\n"
+"#import \n"
+"@import Base;\n"
+"@import Foundation;\n"
+"@import base;\n"
+"@import foundation;\n",
+sort("#import \"b.h\"\n"
+ "#import \"c.h\"\n"
+ "@import Base;\n"
+ "#import \n"
+ "@import foundation;\n"
+ "@import Foundation;\n"
+ "@import base;\n"
+ "#import \"a.h\"\n"));
+
+  // Test that shows main headers in two groups are still found and sorting
+  // still works. The @import's are kept in their respective group but are
+  // put at the end of each group.
+  FmtStyle.IncludeStyle.IncludeBlocks = tooling::IncludeStyle::IBS_Preserve;
+  EXPECT_EQ("#import \"foo.hpp\"\n"
+"#import \"b.h\"\n"
+"#import \"c.h\"\n"
+"#import \n"
+"@import Base;\n"
+"@import Foundation;\n"
+"@import foundation;\n"
+"\n"
+"#import \"foo.h\"\n"
+"#include \"foobar\"\n"
+"#import \n"
+"@import ;\n"
+"@import ;\n",
+sort("#import \"b.h\"\n"
+ "@import Foundation;\n"
+ "@import foundation;\n"
+ "#import \"c.h\"\n"
+ "#import \n"
+ "@import Base;\n"
+ "#import \"foo.hpp\"\n"
+ "\n"
+ "@import ;\n"
+ "#import \n"
+ "@import ;\n"
+ "#include \"foobar\"\n"
+ "#import \"foo.h\"\n",
+ "foo.c", 2));
+
+  // Regrouping and putting @import's in the very last group
+  FmtStyle.IncludeStyle.IncludeBlocks = tooling::IncludeStyle::IBS_Regroup;
+  EXPECT_EQ("#import \"foo.hpp\"\n"
+"\n"
+"#import \"b.h\"\n"
+"#import \"c.h\"\n"
+"#import \"foo.h\"\n"
+"#include \"foobar\"\n"
+"\n"
+"#import \n"
+"#import \n"
+"\n"
+"@import ;\n"
+"@import Base;\n"
+"@import Foundation;\n"
+"@import ;\n"
+"@import foundation;\n",
+sort("#import \"b.h\"\n"
+ "@import Foundation;\n"
+ "@import foundation;\n"
+ "#import \"c.h\"\n"
+ "#import \n"
+ "@import Base;\n"
+ "#import \"foo.hpp\"\n"
+ "\n"
+ "@import ;\n"
+ "#import \n"
+ "@import ;\n"
+ "#include \"foobar\"\n"
+ "#import \"foo.h\"\n",
+ "foo.c"));
+}
+
 TEST_F(SortIncludesTest, LeavesMainHeaderFirst) {
   Style.IncludeIsMainRegex = "([-_](test|unittest))?$";
   EXPECT_EQ("#include \"llvm/a.h\"\n"
Index: clang/lib/Tooling/Inclusions/HeaderIncludes.cpp
===
--- clang/lib/Tooling/Inclusions/HeaderIncludes.cpp
+++ clang/lib/Tooling/Inclusions/HeaderIncludes.cpp
@@ -170,11 +170,22 @@
 }
 
 inline StringRef trimInclude(StringRef IncludeName) {
-  return IncludeName.trim("\"<>");
+  return IncludeName.trim("\"<>;");
 }
 
 const char IncludeRegexPattern[] =
-R"(^[\t\ ]*#[\t\ ]*(import|include)[^"<]*(["<][^">]*[">]))";
+R"(^[\t\ ]*[@#][\t\ ]*(import|include)([^"]*("[^"]+")|[^<]*(<[^>]+>)|[\t\ ]*([^;]+;)))";
+
+// Returns the last match group in the above regex (IncludeRegexPattern) that
+// is not empty.
+StringRef getIncludeNameFromMatches(const SmallVectorImpl ) {
+  for (int i = Matches.size() - 

[PATCH] D121370: [clang-format] SortIncludes should support "@import" lines in Objective-C

2022-03-22 Thread Konrad Wilhelm Kleine via Phabricator via cfe-commits
kwk added a comment.

@MyDeveloperDay can you please have another look now that the patch has 
additional tests and most comments that still apply have been addressed?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D121370/new/

https://reviews.llvm.org/D121370

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D121370: [clang-format] SortIncludes should support "@import" lines in Objective-C

2022-03-21 Thread Konrad Wilhelm Kleine via Phabricator via cfe-commits
kwk updated this revision to Diff 417101.
kwk added a comment.

- Remove duplicate assert


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D121370/new/

https://reviews.llvm.org/D121370

Files:
  clang/lib/Format/Format.cpp
  clang/lib/Tooling/Inclusions/HeaderIncludes.cpp
  clang/unittests/Format/SortIncludesTest.cpp

Index: clang/unittests/Format/SortIncludesTest.cpp
===
--- clang/unittests/Format/SortIncludesTest.cpp
+++ clang/unittests/Format/SortIncludesTest.cpp
@@ -458,6 +458,103 @@
  "#include \"b.h\"\n"));
 }
 
+TEST_F(SortIncludesTest, SupportAtImportLines) {
+  // Test from https://github.com/llvm/llvm-project/issues/38995
+  EXPECT_EQ("#import \"a.h\"\n"
+"#import \"b.h\"\n"
+"#import \"c.h\"\n"
+"#import \n"
+"@import Foundation;\n",
+sort("#import \"b.h\"\n"
+ "#import \"c.h\"\n"
+ "#import \n"
+ "@import Foundation;\n"
+ "#import \"a.h\"\n"));
+
+  // Slightly more complicated test that shows sorting in each priorities still
+  // works.
+  EXPECT_EQ("#import \"a.h\"\n"
+"#import \"b.h\"\n"
+"#import \"c.h\"\n"
+"#import \n"
+"@import Base;\n"
+"@import Foundation;\n"
+"@import base;\n"
+"@import foundation;\n",
+sort("#import \"b.h\"\n"
+ "#import \"c.h\"\n"
+ "@import Base;\n"
+ "#import \n"
+ "@import foundation;\n"
+ "@import Foundation;\n"
+ "@import base;\n"
+ "#import \"a.h\"\n"));
+
+  // Test that shows main headers in two groups are still found and sorting
+  // still works. The @import's are kept in their respective group but are
+  // put at the end of each group.
+  FmtStyle.IncludeStyle.IncludeBlocks = tooling::IncludeStyle::IBS_Preserve;
+  EXPECT_EQ("#import \"foo.hpp\"\n"
+"#import \"b.h\"\n"
+"#import \"c.h\"\n"
+"#import \n"
+"@import Base;\n"
+"@import Foundation;\n"
+"@import foundation;\n"
+"\n"
+"#import \"foo.h\"\n"
+"#include \"foobar\"\n"
+"#import \n"
+"@import ;\n"
+"@import ;\n",
+sort("#import \"b.h\"\n"
+ "@import Foundation;\n"
+ "@import foundation;\n"
+ "#import \"c.h\"\n"
+ "#import \n"
+ "@import Base;\n"
+ "#import \"foo.hpp\"\n"
+ "\n"
+ "@import ;\n"
+ "#import \n"
+ "@import ;\n"
+ "#include \"foobar\"\n"
+ "#import \"foo.h\"\n",
+ "foo.c", 2));
+
+  // Regrouping and putting @import's in the very last group
+  FmtStyle.IncludeStyle.IncludeBlocks = tooling::IncludeStyle::IBS_Regroup;
+  EXPECT_EQ("#import \"foo.hpp\"\n"
+"\n"
+"#import \"b.h\"\n"
+"#import \"c.h\"\n"
+"#import \"foo.h\"\n"
+"#include \"foobar\"\n"
+"\n"
+"#import \n"
+"#import \n"
+"\n"
+"@import ;\n"
+"@import Base;\n"
+"@import Foundation;\n"
+"@import ;\n"
+"@import foundation;\n",
+sort("#import \"b.h\"\n"
+ "@import Foundation;\n"
+ "@import foundation;\n"
+ "#import \"c.h\"\n"
+ "#import \n"
+ "@import Base;\n"
+ "#import \"foo.hpp\"\n"
+ "\n"
+ "@import ;\n"
+ "#import \n"
+ "@import ;\n"
+ "#include \"foobar\"\n"
+ "#import \"foo.h\"\n",
+ "foo.c"));
+}
+
 TEST_F(SortIncludesTest, LeavesMainHeaderFirst) {
   Style.IncludeIsMainRegex = "([-_](test|unittest))?$";
   EXPECT_EQ("#include \"llvm/a.h\"\n"
Index: clang/lib/Tooling/Inclusions/HeaderIncludes.cpp
===
--- clang/lib/Tooling/Inclusions/HeaderIncludes.cpp
+++ clang/lib/Tooling/Inclusions/HeaderIncludes.cpp
@@ -170,11 +170,25 @@
 }
 
 inline StringRef trimInclude(StringRef IncludeName) {
-  return IncludeName.trim("\"<>");
+  return IncludeName.trim("\"<>;");
 }
 
 const char IncludeRegexPattern[] =
-R"(^[\t\ ]*#[\t\ ]*(import|include)[^"<]*(["<][^">]*[">]))";
+R"(^[\t\ ]*[@#][\t\ ]*(import|include)([^"]*("[^"]+")|[^<]*(<[^>]+>)|[\t\ ]*([^;]+;)))";
+
+// Returns the last match group in the above regex (IncludeRegexPattern) that
+// is not empty.
+StringRef getIncludeNameFromMatches(const SmallVectorImpl ) {
+  StringRef res;
+  for (int i 

[PATCH] D121370: [clang-format] SortIncludes should support "@import" lines in Objective-C

2022-03-21 Thread Konrad Wilhelm Kleine via Phabricator via cfe-commits
kwk updated this revision to Diff 417099.
kwk added a comment.

- Remove left-over comment


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D121370/new/

https://reviews.llvm.org/D121370

Files:
  clang/lib/Format/Format.cpp
  clang/lib/Tooling/Inclusions/HeaderIncludes.cpp
  clang/unittests/Format/SortIncludesTest.cpp

Index: clang/unittests/Format/SortIncludesTest.cpp
===
--- clang/unittests/Format/SortIncludesTest.cpp
+++ clang/unittests/Format/SortIncludesTest.cpp
@@ -458,6 +458,103 @@
  "#include \"b.h\"\n"));
 }
 
+TEST_F(SortIncludesTest, SupportAtImportLines) {
+  // Test from https://github.com/llvm/llvm-project/issues/38995
+  EXPECT_EQ("#import \"a.h\"\n"
+"#import \"b.h\"\n"
+"#import \"c.h\"\n"
+"#import \n"
+"@import Foundation;\n",
+sort("#import \"b.h\"\n"
+ "#import \"c.h\"\n"
+ "#import \n"
+ "@import Foundation;\n"
+ "#import \"a.h\"\n"));
+
+  // Slightly more complicated test that shows sorting in each priorities still
+  // works.
+  EXPECT_EQ("#import \"a.h\"\n"
+"#import \"b.h\"\n"
+"#import \"c.h\"\n"
+"#import \n"
+"@import Base;\n"
+"@import Foundation;\n"
+"@import base;\n"
+"@import foundation;\n",
+sort("#import \"b.h\"\n"
+ "#import \"c.h\"\n"
+ "@import Base;\n"
+ "#import \n"
+ "@import foundation;\n"
+ "@import Foundation;\n"
+ "@import base;\n"
+ "#import \"a.h\"\n"));
+
+  // Test that shows main headers in two groups are still found and sorting
+  // still works. The @import's are kept in their respective group but are
+  // put at the end of each group.
+  FmtStyle.IncludeStyle.IncludeBlocks = tooling::IncludeStyle::IBS_Preserve;
+  EXPECT_EQ("#import \"foo.hpp\"\n"
+"#import \"b.h\"\n"
+"#import \"c.h\"\n"
+"#import \n"
+"@import Base;\n"
+"@import Foundation;\n"
+"@import foundation;\n"
+"\n"
+"#import \"foo.h\"\n"
+"#include \"foobar\"\n"
+"#import \n"
+"@import ;\n"
+"@import ;\n",
+sort("#import \"b.h\"\n"
+ "@import Foundation;\n"
+ "@import foundation;\n"
+ "#import \"c.h\"\n"
+ "#import \n"
+ "@import Base;\n"
+ "#import \"foo.hpp\"\n"
+ "\n"
+ "@import ;\n"
+ "#import \n"
+ "@import ;\n"
+ "#include \"foobar\"\n"
+ "#import \"foo.h\"\n",
+ "foo.c", 2));
+
+  // Regrouping and putting @import's in the very last group
+  FmtStyle.IncludeStyle.IncludeBlocks = tooling::IncludeStyle::IBS_Regroup;
+  EXPECT_EQ("#import \"foo.hpp\"\n"
+"\n"
+"#import \"b.h\"\n"
+"#import \"c.h\"\n"
+"#import \"foo.h\"\n"
+"#include \"foobar\"\n"
+"\n"
+"#import \n"
+"#import \n"
+"\n"
+"@import ;\n"
+"@import Base;\n"
+"@import Foundation;\n"
+"@import ;\n"
+"@import foundation;\n",
+sort("#import \"b.h\"\n"
+ "@import Foundation;\n"
+ "@import foundation;\n"
+ "#import \"c.h\"\n"
+ "#import \n"
+ "@import Base;\n"
+ "#import \"foo.hpp\"\n"
+ "\n"
+ "@import ;\n"
+ "#import \n"
+ "@import ;\n"
+ "#include \"foobar\"\n"
+ "#import \"foo.h\"\n",
+ "foo.c"));
+}
+
 TEST_F(SortIncludesTest, LeavesMainHeaderFirst) {
   Style.IncludeIsMainRegex = "([-_](test|unittest))?$";
   EXPECT_EQ("#include \"llvm/a.h\"\n"
Index: clang/lib/Tooling/Inclusions/HeaderIncludes.cpp
===
--- clang/lib/Tooling/Inclusions/HeaderIncludes.cpp
+++ clang/lib/Tooling/Inclusions/HeaderIncludes.cpp
@@ -170,11 +170,25 @@
 }
 
 inline StringRef trimInclude(StringRef IncludeName) {
-  return IncludeName.trim("\"<>");
+  return IncludeName.trim("\"<>;");
 }
 
 const char IncludeRegexPattern[] =
-R"(^[\t\ ]*#[\t\ ]*(import|include)[^"<]*(["<][^">]*[">]))";
+R"(^[\t\ ]*[@#][\t\ ]*(import|include)([^"]*("[^"]+")|[^<]*(<[^>]+>)|[\t\ ]*([^;]+;)))";
+
+// Returns the last match group in the above regex (IncludeRegexPattern) that
+// is not empty.
+StringRef getIncludeNameFromMatches(const SmallVectorImpl ) {
+  StringRef res;
+  for (int 

[PATCH] D120884: [format] Use int8_t as the underlying type of all enums in FormatStyle

2022-03-21 Thread Konrad Wilhelm Kleine via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG063bd3b886b2: [format] Use int8_t as the underlying type of 
all enums in FormatStyle (authored by kwk).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D120884/new/

https://reviews.llvm.org/D120884

Files:
  clang/include/clang/Format/Format.h

Index: clang/include/clang/Format/Format.h
===
--- clang/include/clang/Format/Format.h
+++ clang/include/clang/Format/Format.h
@@ -62,7 +62,7 @@
   int AccessModifierOffset;
 
   /// Different styles for aligning after open brackets.
-  enum BracketAlignmentStyle : unsigned char {
+  enum BracketAlignmentStyle : int8_t {
 /// Align parameters on the open bracket, e.g.:
 /// \code
 ///   someLongFunction(argument1,
@@ -105,7 +105,7 @@
   BracketAlignmentStyle AlignAfterOpenBracket;
 
   /// Different style for aligning array initializers.
-  enum ArrayInitializerAlignmentStyle {
+  enum ArrayInitializerAlignmentStyle : int8_t {
 /// Align array column and left justify the columns e.g.:
 /// \code
 ///   struct test demo[] =
@@ -296,7 +296,7 @@
   AlignConsecutiveStyle AlignConsecutiveDeclarations;
 
   /// Different styles for aligning escaped newlines.
-  enum EscapedNewlineAlignmentStyle : unsigned char {
+  enum EscapedNewlineAlignmentStyle : int8_t {
 /// Don't align escaped newlines.
 /// \code
 ///   #define A \
@@ -331,7 +331,7 @@
   EscapedNewlineAlignmentStyle AlignEscapedNewlines;
 
   /// Different styles for aligning operands.
-  enum OperandAlignmentStyle : unsigned char {
+  enum OperandAlignmentStyle : int8_t {
 /// Do not align operands of binary and ternary expressions.
 /// The wrapped lines are indented ``ContinuationIndentWidth`` spaces from
 /// the start of the line.
@@ -434,7 +434,7 @@
 
   /// Different styles for merging short blocks containing at most one
   /// statement.
-  enum ShortBlockStyle : unsigned char {
+  enum ShortBlockStyle : int8_t {
 /// Never merge blocks into a single line.
 /// \code
 ///   while (true) {
@@ -481,7 +481,7 @@
 
   /// Different styles for merging short functions containing at most one
   /// statement.
-  enum ShortFunctionStyle : unsigned char {
+  enum ShortFunctionStyle : int8_t {
 /// Never merge functions into a single line.
 SFS_None,
 /// Only merge functions defined inside a class. Same as "inline",
@@ -533,7 +533,7 @@
   ShortFunctionStyle AllowShortFunctionsOnASingleLine;
 
   /// Different styles for handling short if statements.
-  enum ShortIfStyle : unsigned char {
+  enum ShortIfStyle : int8_t {
 /// Never put short ifs on the same line.
 /// \code
 ///   if (a)
@@ -605,7 +605,7 @@
 
   /// Different styles for merging short lambdas containing at most one
   /// statement.
-  enum ShortLambdaStyle : unsigned char {
+  enum ShortLambdaStyle : int8_t {
 /// Never merge lambdas into a single line.
 SLS_None,
 /// Only merge empty lambdas.
@@ -644,7 +644,7 @@
 
   /// Different ways to break after the function definition return type.
   /// This option is **deprecated** and is retained for backwards compatibility.
-  enum DefinitionReturnTypeBreakingStyle : unsigned char {
+  enum DefinitionReturnTypeBreakingStyle : int8_t {
 /// Break after return type automatically.
 /// ``PenaltyReturnTypeOnItsOwnLine`` is taken into account.
 DRTBS_None,
@@ -656,7 +656,7 @@
 
   /// Different ways to break after the function definition or
   /// declaration return type.
-  enum ReturnTypeBreakingStyle : unsigned char {
+  enum ReturnTypeBreakingStyle : int8_t {
 /// Break after return type automatically.
 /// ``PenaltyReturnTypeOnItsOwnLine`` is taken into account.
 /// \code
@@ -750,7 +750,7 @@
   bool AlwaysBreakBeforeMultilineStrings;
 
   /// Different ways to break after the template declaration.
-  enum BreakTemplateDeclarationsStyle : unsigned char {
+  enum BreakTemplateDeclarationsStyle : int8_t {
 /// Do not force break before declaration.
 /// ``PenaltyBreakTemplateDeclaration`` is taken into account.
 /// \code
@@ -828,7 +828,7 @@
   bool BinPackArguments;
 
   /// The style of inserting trailing commas into container literals.
-  enum TrailingCommaStyle : unsigned char {
+  enum TrailingCommaStyle : int8_t {
 /// Do not insert trailing commas.
 TCS_None,
 /// Insert trailing commas in container literals that were wrapped over
@@ -874,7 +874,7 @@
 
   /// The style of wrapping parameters on the same line (bin-packed) or
   /// on one line each.
-  enum BinPackStyle : unsigned char {
+  enum BinPackStyle : int8_t {
 /// Automatically determine parameter bin-packing behavior.
 BPS_Auto,
 /// Always bin-pack parameters.
@@ -884,7 +884,7 @@
   };
 
   /// The style of breaking before or after binary operators.
-  enum BinaryOperatorStyle : 

[PATCH] D121370: [clang-format] SortIncludes should support "@import" lines in Objective-C

2022-03-21 Thread Konrad Wilhelm Kleine via Phabricator via cfe-commits
kwk marked 3 inline comments as done.
kwk added a comment.

@HazardyKnusperkeks thank you for the approval. Can you have one last view 
please? I've introduced a function to get the match instead of repeating the 
for loop two times.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D121370/new/

https://reviews.llvm.org/D121370

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D121370: [clang-format] SortIncludes should support "@import" lines in Objective-C

2022-03-21 Thread Konrad Wilhelm Kleine via Phabricator via cfe-commits
kwk updated this revision to Diff 417097.
kwk marked an inline comment as done.
kwk added a comment.

- introduce getIncludeNameFromMatches
- Fix format


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D121370/new/

https://reviews.llvm.org/D121370

Files:
  clang/lib/Format/Format.cpp
  clang/lib/Tooling/Inclusions/HeaderIncludes.cpp
  clang/unittests/Format/SortIncludesTest.cpp

Index: clang/unittests/Format/SortIncludesTest.cpp
===
--- clang/unittests/Format/SortIncludesTest.cpp
+++ clang/unittests/Format/SortIncludesTest.cpp
@@ -458,6 +458,103 @@
  "#include \"b.h\"\n"));
 }
 
+TEST_F(SortIncludesTest, SupportAtImportLines) {
+  // Test from https://github.com/llvm/llvm-project/issues/38995
+  EXPECT_EQ("#import \"a.h\"\n"
+"#import \"b.h\"\n"
+"#import \"c.h\"\n"
+"#import \n"
+"@import Foundation;\n",
+sort("#import \"b.h\"\n"
+ "#import \"c.h\"\n"
+ "#import \n"
+ "@import Foundation;\n"
+ "#import \"a.h\"\n"));
+
+  // Slightly more complicated test that shows sorting in each priorities still
+  // works.
+  EXPECT_EQ("#import \"a.h\"\n"
+"#import \"b.h\"\n"
+"#import \"c.h\"\n"
+"#import \n"
+"@import Base;\n"
+"@import Foundation;\n"
+"@import base;\n"
+"@import foundation;\n",
+sort("#import \"b.h\"\n"
+ "#import \"c.h\"\n"
+ "@import Base;\n"
+ "#import \n"
+ "@import foundation;\n"
+ "@import Foundation;\n"
+ "@import base;\n"
+ "#import \"a.h\"\n"));
+
+  // Test that shows main headers in two groups are still found and sorting
+  // still works. The @import's are kept in their respective group but are
+  // put at the end of each group.
+  FmtStyle.IncludeStyle.IncludeBlocks = tooling::IncludeStyle::IBS_Preserve;
+  EXPECT_EQ("#import \"foo.hpp\"\n"
+"#import \"b.h\"\n"
+"#import \"c.h\"\n"
+"#import \n"
+"@import Base;\n"
+"@import Foundation;\n"
+"@import foundation;\n"
+"\n"
+"#import \"foo.h\"\n"
+"#include \"foobar\"\n"
+"#import \n"
+"@import ;\n"
+"@import ;\n",
+sort("#import \"b.h\"\n"
+ "@import Foundation;\n"
+ "@import foundation;\n"
+ "#import \"c.h\"\n"
+ "#import \n"
+ "@import Base;\n"
+ "#import \"foo.hpp\"\n"
+ "\n"
+ "@import ;\n"
+ "#import \n"
+ "@import ;\n"
+ "#include \"foobar\"\n"
+ "#import \"foo.h\"\n",
+ "foo.c", 2));
+
+  // Regrouping and putting @import's in the very last group
+  FmtStyle.IncludeStyle.IncludeBlocks = tooling::IncludeStyle::IBS_Regroup;
+  EXPECT_EQ("#import \"foo.hpp\"\n"
+"\n"
+"#import \"b.h\"\n"
+"#import \"c.h\"\n"
+"#import \"foo.h\"\n"
+"#include \"foobar\"\n"
+"\n"
+"#import \n"
+"#import \n"
+"\n"
+"@import ;\n"
+"@import Base;\n"
+"@import Foundation;\n"
+"@import ;\n"
+"@import foundation;\n",
+sort("#import \"b.h\"\n"
+ "@import Foundation;\n"
+ "@import foundation;\n"
+ "#import \"c.h\"\n"
+ "#import \n"
+ "@import Base;\n"
+ "#import \"foo.hpp\"\n"
+ "\n"
+ "@import ;\n"
+ "#import \n"
+ "@import ;\n"
+ "#include \"foobar\"\n"
+ "#import \"foo.h\"\n",
+ "foo.c"));
+}
+
 TEST_F(SortIncludesTest, LeavesMainHeaderFirst) {
   Style.IncludeIsMainRegex = "([-_](test|unittest))?$";
   EXPECT_EQ("#include \"llvm/a.h\"\n"
Index: clang/lib/Tooling/Inclusions/HeaderIncludes.cpp
===
--- clang/lib/Tooling/Inclusions/HeaderIncludes.cpp
+++ clang/lib/Tooling/Inclusions/HeaderIncludes.cpp
@@ -170,11 +170,25 @@
 }
 
 inline StringRef trimInclude(StringRef IncludeName) {
-  return IncludeName.trim("\"<>");
+  return IncludeName.trim("\"<>;");
 }
 
 const char IncludeRegexPattern[] =
-R"(^[\t\ ]*#[\t\ ]*(import|include)[^"<]*(["<][^">]*[">]))";
+R"(^[\t\ ]*[@#][\t\ ]*(import|include)([^"]*("[^"]+")|[^<]*(<[^>]+>)|[\t\ ]*([^;]+;)))";
+
+// Returns the last match group in the above regex (IncludeRegexPattern) that
+// is not empty.
+StringRef 

[PATCH] D120884: [format] Use int8_t as the underlying type of all enums in FormatStyle

2022-03-21 Thread Konrad Wilhelm Kleine via Phabricator via cfe-commits
kwk added a comment.

@HazardyKnusperkeks @owenpan can you please have a quick look again. All I did 
was rebasing my changes and in the meantime I was interrupted... This patch has 
been sitting for some time and I'd like to land it as soon one of you approves 
it.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D120884/new/

https://reviews.llvm.org/D120884

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D120884: [format] Use int8_t as the underlying type of all enums in FormatStyle

2022-03-21 Thread Konrad Wilhelm Kleine via Phabricator via cfe-commits
kwk updated this revision to Diff 417044.
kwk added a comment.

Fixup my work after interruption by screaming children wanting dinner ;)

This is how I've tested this patch:

  ninja clang-format && ninja FormatTests && 
./tools/clang/unittests/Format/FormatTests


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D120884/new/

https://reviews.llvm.org/D120884

Files:
  clang/include/clang/Format/Format.h

Index: clang/include/clang/Format/Format.h
===
--- clang/include/clang/Format/Format.h
+++ clang/include/clang/Format/Format.h
@@ -62,7 +62,7 @@
   int AccessModifierOffset;
 
   /// Different styles for aligning after open brackets.
-  enum BracketAlignmentStyle : unsigned char {
+  enum BracketAlignmentStyle : int8_t {
 /// Align parameters on the open bracket, e.g.:
 /// \code
 ///   someLongFunction(argument1,
@@ -105,7 +105,7 @@
   BracketAlignmentStyle AlignAfterOpenBracket;
 
   /// Different style for aligning array initializers.
-  enum ArrayInitializerAlignmentStyle {
+  enum ArrayInitializerAlignmentStyle : int8_t {
 /// Align array column and left justify the columns e.g.:
 /// \code
 ///   struct test demo[] =
@@ -296,7 +296,7 @@
   AlignConsecutiveStyle AlignConsecutiveDeclarations;
 
   /// Different styles for aligning escaped newlines.
-  enum EscapedNewlineAlignmentStyle : unsigned char {
+  enum EscapedNewlineAlignmentStyle : int8_t {
 /// Don't align escaped newlines.
 /// \code
 ///   #define A \
@@ -331,7 +331,7 @@
   EscapedNewlineAlignmentStyle AlignEscapedNewlines;
 
   /// Different styles for aligning operands.
-  enum OperandAlignmentStyle : unsigned char {
+  enum OperandAlignmentStyle : int8_t {
 /// Do not align operands of binary and ternary expressions.
 /// The wrapped lines are indented ``ContinuationIndentWidth`` spaces from
 /// the start of the line.
@@ -434,7 +434,7 @@
 
   /// Different styles for merging short blocks containing at most one
   /// statement.
-  enum ShortBlockStyle : unsigned char {
+  enum ShortBlockStyle : int8_t {
 /// Never merge blocks into a single line.
 /// \code
 ///   while (true) {
@@ -481,7 +481,7 @@
 
   /// Different styles for merging short functions containing at most one
   /// statement.
-  enum ShortFunctionStyle : unsigned char {
+  enum ShortFunctionStyle : int8_t {
 /// Never merge functions into a single line.
 SFS_None,
 /// Only merge functions defined inside a class. Same as "inline",
@@ -533,7 +533,7 @@
   ShortFunctionStyle AllowShortFunctionsOnASingleLine;
 
   /// Different styles for handling short if statements.
-  enum ShortIfStyle : unsigned char {
+  enum ShortIfStyle : int8_t {
 /// Never put short ifs on the same line.
 /// \code
 ///   if (a)
@@ -605,7 +605,7 @@
 
   /// Different styles for merging short lambdas containing at most one
   /// statement.
-  enum ShortLambdaStyle : unsigned char {
+  enum ShortLambdaStyle : int8_t {
 /// Never merge lambdas into a single line.
 SLS_None,
 /// Only merge empty lambdas.
@@ -644,7 +644,7 @@
 
   /// Different ways to break after the function definition return type.
   /// This option is **deprecated** and is retained for backwards compatibility.
-  enum DefinitionReturnTypeBreakingStyle : unsigned char {
+  enum DefinitionReturnTypeBreakingStyle : int8_t {
 /// Break after return type automatically.
 /// ``PenaltyReturnTypeOnItsOwnLine`` is taken into account.
 DRTBS_None,
@@ -656,7 +656,7 @@
 
   /// Different ways to break after the function definition or
   /// declaration return type.
-  enum ReturnTypeBreakingStyle : unsigned char {
+  enum ReturnTypeBreakingStyle : int8_t {
 /// Break after return type automatically.
 /// ``PenaltyReturnTypeOnItsOwnLine`` is taken into account.
 /// \code
@@ -750,7 +750,7 @@
   bool AlwaysBreakBeforeMultilineStrings;
 
   /// Different ways to break after the template declaration.
-  enum BreakTemplateDeclarationsStyle : unsigned char {
+  enum BreakTemplateDeclarationsStyle : int8_t {
 /// Do not force break before declaration.
 /// ``PenaltyBreakTemplateDeclaration`` is taken into account.
 /// \code
@@ -828,7 +828,7 @@
   bool BinPackArguments;
 
   /// The style of inserting trailing commas into container literals.
-  enum TrailingCommaStyle : unsigned char {
+  enum TrailingCommaStyle : int8_t {
 /// Do not insert trailing commas.
 TCS_None,
 /// Insert trailing commas in container literals that were wrapped over
@@ -874,7 +874,7 @@
 
   /// The style of wrapping parameters on the same line (bin-packed) or
   /// on one line each.
-  enum BinPackStyle : unsigned char {
+  enum BinPackStyle : int8_t {
 /// Automatically determine parameter bin-packing behavior.
 BPS_Auto,
 /// Always bin-pack parameters.
@@ -884,7 +884,7 @@
   };
 
   /// The style of breaking 

[PATCH] D120884: [format] Use int8_t as the underlying type of all enums in FormatStyle

2022-03-21 Thread Konrad Wilhelm Kleine via Phabricator via cfe-commits
kwk updated this revision to Diff 416971.
kwk added a comment.

Fixup


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D120884/new/

https://reviews.llvm.org/D120884

Files:
  clang/include/clang/Format/Format.h

Index: clang/include/clang/Format/Format.h
===
--- clang/include/clang/Format/Format.h
+++ clang/include/clang/Format/Format.h
@@ -62,7 +62,7 @@
   int AccessModifierOffset;
 
   /// Different styles for aligning after open brackets.
-  enum BracketAlignmentStyle : unsigned char {
+  enum BracketAlignmentStyle : int8_t {
 /// Align parameters on the open bracket, e.g.:
 /// \code
 ///   someLongFunction(argument1,
@@ -105,7 +105,7 @@
   BracketAlignmentStyle AlignAfterOpenBracket;
 
   /// Different style for aligning array initializers.
-  enum ArrayInitializerAlignmentStyle {
+  enum ArrayInitializerAlignmentStyle : int8_t {
 /// Align array column and left justify the columns e.g.:
 /// \code
 ///   struct test demo[] =
@@ -138,116 +138,18 @@
   /// \version 13
   ArrayInitializerAlignmentStyle AlignArrayOfStructures;
 
-  /// Alignment options.
-  ///
-  /// They can also be read as a whole for compatibility. The choices are:
-  /// - None
-  /// - Consecutive
-  /// - AcrossEmptyLines
-  /// - AcrossComments
-  /// - AcrossEmptyLinesAndComments
-  ///
-  /// For example, to align across empty lines and not across comments, either
-  /// of these work.
-  /// \code
-  ///   AlignConsecutiveMacros: AcrossEmptyLines
-  ///
-  ///   AlignConsecutiveMacros:
-  /// Enabled: true
-  /// AcrossEmptyLines: true
-  /// AcrossComments: false
-  /// \endcode
-  struct AlignConsecutiveStyle {
-/// Whether aligning is enabled.
-/// \code
-///   #define SHORT_NAME   42
-///   #define LONGER_NAME  0x007f
-///   #define EVEN_LONGER_NAME (2)
-///   #define foo(x)   (x * x)
-///   #define bar(y, z)(y + z)
-///
-///   int a= 1;
-///   int somelongname = 2;
-///   double c = 3;
-///
-///   int  : 1;
-///   int b: 12;
-///   int ccc  : 8;
-///
-///   int  = 12;
-///   float   b = 23;
-///   std::string ccc;
-/// \endcode
-bool Enabled;
-/// Whether to align across empty lines.
-/// \code
-///   true:
-///   int a= 1;
-///   int somelongname = 2;
-///   double c = 3;
-///
-///   int d= 3;
-///
-///   false:
-///   int a= 1;
-///   int somelongname = 2;
-///   double c = 3;
-///
-///   int d = 3;
-/// \endcode
-bool AcrossEmptyLines;
-/// Whether to align across comments.
-/// \code
-///   true:
-///   int d= 3;
-///   /* A comment. */
-///   double e = 4;
-///
-///   false:
-///   int d = 3;
-///   /* A comment. */
-///   double e = 4;
-/// \endcode
-bool AcrossComments;
-/// Only for ``AlignConsecutiveAssignments``.  Whether compound assignments
-/// like ``+=`` are aligned along with ``=``.
-/// \code
-///   true:
-///   a   &= 2;
-///   bbb  = 2;
-///
-///   false:
-///   a &= 2;
-///   bbb = 2;
-/// \endcode
-bool AlignCompound;
-/// Only for ``AlignConsecutiveAssignments``.  Whether short assignment
-/// operators are left-padded to the same length as long ones in order to
-/// put all assignment operators to the right of the left hand side.
-/// \code
-///   true:
-///   a   >>= 2;
-///   bbb   = 2;
-///
-///   a = 2;
-///   bbb >>= 2;
-///
-///   false:
-///   a >>= 2;
-///   bbb = 2;
-///
-///   a = 2;
-///   bbb >>= 2;
-/// \endcode
-bool PadOperators;
-bool operator==(const AlignConsecutiveStyle ) const {
-  return Enabled == R.Enabled && AcrossEmptyLines == R.AcrossEmptyLines &&
- AcrossComments == R.AcrossComments &&
- AlignCompound == R.AlignCompound && PadOperators == R.PadOperators;
-}
-bool operator!=(const AlignConsecutiveStyle ) const {
-  return !(*this == R);
-}
+  /// Styles for alignment of consecutive tokens. Tokens can be assignment signs
+  /// (see
+  /// ``AlignConsecutiveAssignments``), bitfield member separators (see
+  /// ``AlignConsecutiveBitFields``), names in declarations (see
+  /// ``AlignConsecutiveDeclarations``) or macro definitions (see
+  /// ``AlignConsecutiveMacros``).
+  enum AlignConsecutiveStyle : int8_t {
+ACS_None,
+ACS_Consecutive,
+ACS_AcrossEmptyLines,
+ACS_AcrossComments,
+ACS_AcrossEmptyLinesAndComments
   };
 
   /// Style of aligning consecutive macro definitions.
@@ -296,7 +198,7 @@
   AlignConsecutiveStyle AlignConsecutiveDeclarations;
 
   /// Different styles for aligning escaped newlines.
-  

[PATCH] D120884: [format] Use int8_t as the underlying type of all enums in FormatStyle

2022-03-21 Thread Konrad Wilhelm Kleine via Phabricator via cfe-commits
kwk updated this revision to Diff 416970.
kwk added a comment.

Rebased


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D120884/new/

https://reviews.llvm.org/D120884

Files:
  clang/include/clang/Format/Format.h

Index: clang/include/clang/Format/Format.h
===
--- clang/include/clang/Format/Format.h
+++ clang/include/clang/Format/Format.h
@@ -62,7 +62,7 @@
   int AccessModifierOffset;
 
   /// Different styles for aligning after open brackets.
-  enum BracketAlignmentStyle : unsigned char {
+  enum BracketAlignmentStyle : int8_t {
 /// Align parameters on the open bracket, e.g.:
 /// \code
 ///   someLongFunction(argument1,
@@ -105,7 +105,7 @@
   BracketAlignmentStyle AlignAfterOpenBracket;
 
   /// Different style for aligning array initializers.
-  enum ArrayInitializerAlignmentStyle {
+  enum ArrayInitializerAlignmentStyle : int8_t {
 /// Align array column and left justify the columns e.g.:
 /// \code
 ///   struct test demo[] =
@@ -138,6 +138,7 @@
   /// \version 13
   ArrayInitializerAlignmentStyle AlignArrayOfStructures;
 
+<<< HEAD
   /// Alignment options.
   ///
   /// They can also be read as a whole for compatibility. The choices are:
@@ -248,6 +249,20 @@
 bool operator!=(const AlignConsecutiveStyle ) const {
   return !(*this == R);
 }
+===
+  /// Styles for alignment of consecutive tokens. Tokens can be assignment signs
+  /// (see
+  /// ``AlignConsecutiveAssignments``), bitfield member separators (see
+  /// ``AlignConsecutiveBitFields``), names in declarations (see
+  /// ``AlignConsecutiveDeclarations``) or macro definitions (see
+  /// ``AlignConsecutiveMacros``).
+  enum AlignConsecutiveStyle : int8_t {
+ACS_None,
+ACS_Consecutive,
+ACS_AcrossEmptyLines,
+ACS_AcrossComments,
+ACS_AcrossEmptyLinesAndComments
+>>> 60c77906316c ([format] Use int8_t as the underlying type of all enums in FormatStyle)
   };
 
   /// Style of aligning consecutive macro definitions.
@@ -296,7 +311,7 @@
   AlignConsecutiveStyle AlignConsecutiveDeclarations;
 
   /// Different styles for aligning escaped newlines.
-  enum EscapedNewlineAlignmentStyle : unsigned char {
+  enum EscapedNewlineAlignmentStyle : int8_t {
 /// Don't align escaped newlines.
 /// \code
 ///   #define A \
@@ -331,7 +346,7 @@
   EscapedNewlineAlignmentStyle AlignEscapedNewlines;
 
   /// Different styles for aligning operands.
-  enum OperandAlignmentStyle : unsigned char {
+  enum OperandAlignmentStyle : int8_t {
 /// Do not align operands of binary and ternary expressions.
 /// The wrapped lines are indented ``ContinuationIndentWidth`` spaces from
 /// the start of the line.
@@ -434,7 +449,7 @@
 
   /// Different styles for merging short blocks containing at most one
   /// statement.
-  enum ShortBlockStyle : unsigned char {
+  enum ShortBlockStyle : int8_t {
 /// Never merge blocks into a single line.
 /// \code
 ///   while (true) {
@@ -481,7 +496,7 @@
 
   /// Different styles for merging short functions containing at most one
   /// statement.
-  enum ShortFunctionStyle : unsigned char {
+  enum ShortFunctionStyle : int8_t {
 /// Never merge functions into a single line.
 SFS_None,
 /// Only merge functions defined inside a class. Same as "inline",
@@ -533,7 +548,7 @@
   ShortFunctionStyle AllowShortFunctionsOnASingleLine;
 
   /// Different styles for handling short if statements.
-  enum ShortIfStyle : unsigned char {
+  enum ShortIfStyle : int8_t {
 /// Never put short ifs on the same line.
 /// \code
 ///   if (a)
@@ -605,7 +620,7 @@
 
   /// Different styles for merging short lambdas containing at most one
   /// statement.
-  enum ShortLambdaStyle : unsigned char {
+  enum ShortLambdaStyle : int8_t {
 /// Never merge lambdas into a single line.
 SLS_None,
 /// Only merge empty lambdas.
@@ -644,7 +659,7 @@
 
   /// Different ways to break after the function definition return type.
   /// This option is **deprecated** and is retained for backwards compatibility.
-  enum DefinitionReturnTypeBreakingStyle : unsigned char {
+  enum DefinitionReturnTypeBreakingStyle : int8_t {
 /// Break after return type automatically.
 /// ``PenaltyReturnTypeOnItsOwnLine`` is taken into account.
 DRTBS_None,
@@ -656,7 +671,7 @@
 
   /// Different ways to break after the function definition or
   /// declaration return type.
-  enum ReturnTypeBreakingStyle : unsigned char {
+  enum ReturnTypeBreakingStyle : int8_t {
 /// Break after return type automatically.
 /// ``PenaltyReturnTypeOnItsOwnLine`` is taken into account.
 /// \code
@@ -750,7 +765,7 @@
   bool AlwaysBreakBeforeMultilineStrings;
 
   /// Different ways to break after the template declaration.
-  enum BreakTemplateDeclarationsStyle : unsigned char {
+  enum BreakTemplateDeclarationsStyle : int8_t {
 /// Do not 

[PATCH] D121370: [clang-format] SortIncludes should support "@import" lines in Objective-C

2022-03-21 Thread Konrad Wilhelm Kleine via Phabricator via cfe-commits
kwk updated this revision to Diff 416878.
kwk added a comment.

- Fix test but unsure if correct


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D121370/new/

https://reviews.llvm.org/D121370

Files:
  clang/lib/Format/Format.cpp
  clang/lib/Tooling/Inclusions/HeaderIncludes.cpp
  clang/unittests/Format/SortIncludesTest.cpp

Index: clang/unittests/Format/SortIncludesTest.cpp
===
--- clang/unittests/Format/SortIncludesTest.cpp
+++ clang/unittests/Format/SortIncludesTest.cpp
@@ -458,6 +458,103 @@
  "#include \"b.h\"\n"));
 }
 
+TEST_F(SortIncludesTest, SupportAtImportLines) {
+  // Test from https://github.com/llvm/llvm-project/issues/38995
+  EXPECT_EQ("#import \"a.h\"\n"
+"#import \"b.h\"\n"
+"#import \"c.h\"\n"
+"#import \n"
+"@import Foundation;\n",
+sort("#import \"b.h\"\n"
+ "#import \"c.h\"\n"
+ "#import \n"
+ "@import Foundation;\n"
+ "#import \"a.h\"\n"));
+
+  // Slightly more complicated test that shows sorting in each priorities still
+  // works.
+  EXPECT_EQ("#import \"a.h\"\n"
+"#import \"b.h\"\n"
+"#import \"c.h\"\n"
+"#import \n"
+"@import Base;\n"
+"@import Foundation;\n"
+"@import base;\n"
+"@import foundation;\n",
+sort("#import \"b.h\"\n"
+ "#import \"c.h\"\n"
+ "@import Base;\n"
+ "#import \n"
+ "@import foundation;\n"
+ "@import Foundation;\n"
+ "@import base;\n"
+ "#import \"a.h\"\n"));
+
+  // Test that shows main headers in two groups are still found and sorting
+  // still works. The @import's are kept in their respective group but are
+  // put at the end of each group. 
+  FmtStyle.IncludeStyle.IncludeBlocks = tooling::IncludeStyle::IBS_Preserve;
+  EXPECT_EQ("#import \"foo.hpp\"\n"
+"#import \"b.h\"\n"
+"#import \"c.h\"\n"
+"#import \n"
+"@import Base;\n"
+"@import Foundation;\n"
+"@import foundation;\n"
+"\n"
+"#import \"foo.h\"\n"
+"#include \"foobar\"\n"
+"#import \n"
+"@import ;\n"
+"@import ;\n",
+sort("#import \"b.h\"\n"
+ "@import Foundation;\n"
+ "@import foundation;\n"
+ "#import \"c.h\"\n"
+ "#import \n"
+ "@import Base;\n"
+ "#import \"foo.hpp\"\n"
+ "\n"
+ "@import ;\n"
+ "#import \n"
+ "@import ;\n"
+ "#include \"foobar\"\n"
+ "#import \"foo.h\"\n",
+ "foo.c", 2));
+
+  // Regrouping and putting @import's in the very last group
+  FmtStyle.IncludeStyle.IncludeBlocks = tooling::IncludeStyle::IBS_Regroup;
+  EXPECT_EQ("#import \"foo.hpp\"\n"
+"\n"
+"#import \"b.h\"\n"
+"#import \"c.h\"\n"
+"#import \"foo.h\"\n"
+"#include \"foobar\"\n"
+"\n"
+"#import \n"
+"#import \n"
+"\n"
+"@import ;\n"
+"@import Base;\n"
+"@import Foundation;\n"
+"@import ;\n"
+"@import foundation;\n",
+sort("#import \"b.h\"\n"
+ "@import Foundation;\n"
+ "@import foundation;\n"
+ "#import \"c.h\"\n"
+ "#import \n"
+ "@import Base;\n"
+ "#import \"foo.hpp\"\n"
+ "\n"
+ "@import ;\n"
+ "#import \n"
+ "@import ;\n"
+ "#include \"foobar\"\n"
+ "#import \"foo.h\"\n",
+ "foo.c"));
+}
+
 TEST_F(SortIncludesTest, LeavesMainHeaderFirst) {
   Style.IncludeIsMainRegex = "([-_](test|unittest))?$";
   EXPECT_EQ("#include \"llvm/a.h\"\n"
Index: clang/lib/Tooling/Inclusions/HeaderIncludes.cpp
===
--- clang/lib/Tooling/Inclusions/HeaderIncludes.cpp
+++ clang/lib/Tooling/Inclusions/HeaderIncludes.cpp
@@ -170,11 +170,11 @@
 }
 
 inline StringRef trimInclude(StringRef IncludeName) {
-  return IncludeName.trim("\"<>");
+  return IncludeName.trim("\"<>;");
 }
 
 const char IncludeRegexPattern[] =
-R"(^[\t\ ]*#[\t\ ]*(import|include)[^"<]*(["<][^">]*[">]))";
+R"(^[\t\ ]*[@#][\t\ ]*(import|include)([^"]*("[^"]+")|[^<]*(<[^>]+>)|[\t\ ]*([^;]+;)))";
 
 // The filename of Path excluding extension.
 // Used to match implementation with headers, this differs from sys::path::stem:
@@ -290,10 +290,17 @@
   for (auto Line : Lines) {
 

[PATCH] D121370: [clang-format] SortIncludes should support "@import" lines in Objective-C

2022-03-21 Thread Konrad Wilhelm Kleine via Phabricator via cfe-commits
kwk added a comment.

In the current state, some tests in `SortIncludesTest.SupportAtImportLines` are 
failing.

This is strange, because I've tested it with this `.clang-format` file:

  BasedOnStyle: LLVM
  IncludeBlocks: Regroup



NOTE: for each test I've change the `Regroup` to `Preserve` respectively`.

This was the input file: **`foo.c`**:

  #import "b.h"
  @import Foundation;
  @import foundation;
  #import "c.h"
  #import 
  @import Base;
  #import "foo.hpp"
  
  @import ;
  #import 
  @import ;
  #include "foobar"
  #import "foo.h"

And this was the command to test it by hand:

  $ ninja clang-format && ./bin/clang-format --style=file foo.c

The output of this manual invocation looks correct to me so I've pasted
it into the test file and escaped the quotes. But there it fails with:

  $ ninja clang-format && ninja FormatTests &&
  ./tools/clang/unittests/Format/FormatTests
  --gtest_filter=SortIncludesTest.SupportAtImportLines
  
  [2/2] Linking CXX executable tools/clang/unittests/Format/FormatTests
  Note: Google Test filter = SortIncludesTest.SupportAtImportLines
  [==] Running 1 test from 1 test suite.
  [--] Global test environment set-up.
  [--] 1 test from SortIncludesTest
  [ RUN  ] SortIncludesTest.SupportAtImportLines
  /home/fedora/llvm-project/clang/unittests/Format/SortIncludesTest.cpp:33:
  Failure
  Expected equality of these values:
ExpectedNumRanges
  Which is: 1
Replaces.size()
  Which is: 2
  /home/fedora/llvm-project/clang/unittests/Format/SortIncludesTest.cpp:555:
  Failure
  Expected equality of these values:
"#import \"foo.hpp\"\n" "\n" "#import \"b.h\"\n" "#import \"c.h\"\n"
  "#import \"foo.h\"\n" "#include \"foobar\"\n" "\n" "#import \n"
  "#import \n" "\n" "@import ;\n" "@import ;\n" "@import
  Base;\n" "@import Foundation;\n" "@import foundation;\n"
  Which is: "#import \"foo.hpp\"\n\n#import \"b.h\"\n#import
  \"c.h\"\n#import \"foo.h\"\n#include \"foobar\"\n\n#import
  \n#import \n\n@import ;\n@import ;\n@import
  Base;\n@import Foundation;\n@import foundation;\n"
sort("#import \"b.h\"\n" "@import Foundation;\n" "@import
  foundation;\n" "#import \"c.h\"\n" "#import \n" "@import Base;\n"
  "#import \"foo.hpp\"\n" "\n" "@import ;\n" "#import \n"
  "@import ;\n" "#include \"foobar\"\n" "#import \"foo.h\"\n",
  "foo.c")
  Which is: "#import \"foo.hpp\"\n\n#import \"b.h\"\n#import
  \"c.h\"\n#import \"foo.h\"\n#include \"foobar\"\n\n#import
  \n#import \n\n@import ;\n@import Base;\n@import
  Foundation;\n@import ;\n@import foundation;\n"
  With diff:
  @@ -10,6 +10,6 @@
  
   @import ;
  -@import ;
   @import Base;
   @import Foundation;
  +@import ;
   @import foundation;\n
  
  [  FAILED  ] SortIncludesTest.SupportAtImportLines (16 ms)
  [--] 1 test from SortIncludesTest (16 ms total)
  
  [--] Global test environment tear-down
  [==] 1 test from 1 test suite ran. (16 ms total)
  [  PASSED  ] 0 tests.
  [  FAILED  ] 1 test, listed below:
  [  FAILED  ] SortIncludesTest.SupportAtImportLines

What's bothering me is that inside the tests there seems to be a
different sorting for upper- and lower-case includes. But maybe I'm
mistaken.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D121370/new/

https://reviews.llvm.org/D121370

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D121370: [clang-format] SortIncludes should support "@import" lines in Objective-C

2022-03-21 Thread Konrad Wilhelm Kleine via Phabricator via cfe-commits
kwk added a comment.

In D121370#3387175 , 
@HazardyKnusperkeks wrote:

> In D121370#3383574 , 
> @HazardyKnusperkeks wrote:
>
>> Some test with a main header and blocks would be nice.
>
> This one please. :)

Done.




Comment at: clang/lib/Format/Format.cpp:2762
+// This addresses https://github.com/llvm/llvm-project/issues/38995
+int WithSemicolon = false;
+if (!IncludeName.startswith("\"") && !IncludeName.startswith("<") &&

MyDeveloperDay wrote:
> int false?
> int false?

Yes, this was just to see if everybody is awake ;). Just kiddin'. Good catch.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D121370/new/

https://reviews.llvm.org/D121370

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D121370: [clang-format] SortIncludes should support "@import" lines in Objective-C

2022-03-21 Thread Konrad Wilhelm Kleine via Phabricator via cfe-commits
kwk updated this revision to Diff 416877.
kwk added a comment.

- Fix: int -> bool


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D121370/new/

https://reviews.llvm.org/D121370

Files:
  clang/lib/Format/Format.cpp
  clang/lib/Tooling/Inclusions/HeaderIncludes.cpp
  clang/unittests/Format/SortIncludesTest.cpp

Index: clang/unittests/Format/SortIncludesTest.cpp
===
--- clang/unittests/Format/SortIncludesTest.cpp
+++ clang/unittests/Format/SortIncludesTest.cpp
@@ -458,6 +458,103 @@
  "#include \"b.h\"\n"));
 }
 
+TEST_F(SortIncludesTest, SupportAtImportLines) {
+  // Test from https://github.com/llvm/llvm-project/issues/38995
+  EXPECT_EQ("#import \"a.h\"\n"
+"#import \"b.h\"\n"
+"#import \"c.h\"\n"
+"#import \n"
+"@import Foundation;\n",
+sort("#import \"b.h\"\n"
+ "#import \"c.h\"\n"
+ "#import \n"
+ "@import Foundation;\n"
+ "#import \"a.h\"\n"));
+
+  // Slightly more complicated test that shows sorting in each priorities still
+  // works.
+  EXPECT_EQ("#import \"a.h\"\n"
+"#import \"b.h\"\n"
+"#import \"c.h\"\n"
+"#import \n"
+"@import Base;\n"
+"@import Foundation;\n"
+"@import base;\n"
+"@import foundation;\n",
+sort("#import \"b.h\"\n"
+ "#import \"c.h\"\n"
+ "@import Base;\n"
+ "#import \n"
+ "@import foundation;\n"
+ "@import Foundation;\n"
+ "@import base;\n"
+ "#import \"a.h\"\n"));
+
+  // Test that shows main headers in two groups are still found and sorting
+  // still works. The @import's are kept in their respective group but are
+  // put at the end of each group. 
+  FmtStyle.IncludeStyle.IncludeBlocks = tooling::IncludeStyle::IBS_Preserve;
+  EXPECT_EQ("#import \"foo.hpp\"\n"
+"#import \"b.h\"\n"
+"#import \"c.h\"\n"
+"#import \n"
+"@import Base;\n"
+"@import Foundation;\n"
+"@import foundation;\n"
+"\n"
+"#import \"foo.h\"\n"
+"#include \"foobar\"\n"
+"#import \n"
+"@import ;\n"
+"@import ;\n",
+sort("#import \"b.h\"\n"
+ "@import Foundation;\n"
+ "@import foundation;\n"
+ "#import \"c.h\"\n"
+ "#import \n"
+ "@import Base;\n"
+ "#import \"foo.hpp\"\n"
+ "\n"
+ "@import ;\n"
+ "#import \n"
+ "@import ;\n"
+ "#include \"foobar\"\n"
+ "#import \"foo.h\"\n",
+ "foo.c"));
+
+  // Regrouping and putting @import's in the very last group
+  FmtStyle.IncludeStyle.IncludeBlocks = tooling::IncludeStyle::IBS_Regroup;
+  EXPECT_EQ("#import \"foo.hpp\"\n"
+"\n"
+"#import \"b.h\"\n"
+"#import \"c.h\"\n"
+"#import \"foo.h\"\n"
+"#include \"foobar\"\n"
+"\n"
+"#import \n"
+"#import \n"
+"\n"
+"@import ;\n"
+"@import ;\n"
+"@import Base;\n"
+"@import Foundation;\n"
+"@import foundation;\n",
+sort("#import \"b.h\"\n"
+ "@import Foundation;\n"
+ "@import foundation;\n"
+ "#import \"c.h\"\n"
+ "#import \n"
+ "@import Base;\n"
+ "#import \"foo.hpp\"\n"
+ "\n"
+ "@import ;\n"
+ "#import \n"
+ "@import ;\n"
+ "#include \"foobar\"\n"
+ "#import \"foo.h\"\n",
+ "foo.c"));
+}
+
 TEST_F(SortIncludesTest, LeavesMainHeaderFirst) {
   Style.IncludeIsMainRegex = "([-_](test|unittest))?$";
   EXPECT_EQ("#include \"llvm/a.h\"\n"
Index: clang/lib/Tooling/Inclusions/HeaderIncludes.cpp
===
--- clang/lib/Tooling/Inclusions/HeaderIncludes.cpp
+++ clang/lib/Tooling/Inclusions/HeaderIncludes.cpp
@@ -170,11 +170,11 @@
 }
 
 inline StringRef trimInclude(StringRef IncludeName) {
-  return IncludeName.trim("\"<>");
+  return IncludeName.trim("\"<>;");
 }
 
 const char IncludeRegexPattern[] =
-R"(^[\t\ ]*#[\t\ ]*(import|include)[^"<]*(["<][^">]*[">]))";
+R"(^[\t\ ]*[@#][\t\ ]*(import|include)([^"]*("[^"]+")|[^<]*(<[^>]+>)|[\t\ ]*([^;]+;)))";
 
 // The filename of Path excluding extension.
 // Used to match implementation with headers, this differs from sys::path::stem:
@@ -290,10 +290,17 @@
   for (auto Line : Lines) {
 NextLineOffset = 

[PATCH] D121370: [clang-format] SortIncludes should support "@import" lines in Objective-C

2022-03-21 Thread Konrad Wilhelm Kleine via Phabricator via cfe-commits
kwk updated this revision to Diff 416876.
kwk marked an inline comment as done.
kwk added a comment.

- Address review comments on grouping and main headers


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D121370/new/

https://reviews.llvm.org/D121370

Files:
  clang/lib/Format/Format.cpp
  clang/lib/Tooling/Inclusions/HeaderIncludes.cpp
  clang/unittests/Format/SortIncludesTest.cpp

Index: clang/unittests/Format/SortIncludesTest.cpp
===
--- clang/unittests/Format/SortIncludesTest.cpp
+++ clang/unittests/Format/SortIncludesTest.cpp
@@ -458,6 +458,103 @@
  "#include \"b.h\"\n"));
 }
 
+TEST_F(SortIncludesTest, SupportAtImportLines) {
+  // Test from https://github.com/llvm/llvm-project/issues/38995
+  EXPECT_EQ("#import \"a.h\"\n"
+"#import \"b.h\"\n"
+"#import \"c.h\"\n"
+"#import \n"
+"@import Foundation;\n",
+sort("#import \"b.h\"\n"
+ "#import \"c.h\"\n"
+ "#import \n"
+ "@import Foundation;\n"
+ "#import \"a.h\"\n"));
+
+  // Slightly more complicated test that shows sorting in each priorities still
+  // works.
+  EXPECT_EQ("#import \"a.h\"\n"
+"#import \"b.h\"\n"
+"#import \"c.h\"\n"
+"#import \n"
+"@import Base;\n"
+"@import Foundation;\n"
+"@import base;\n"
+"@import foundation;\n",
+sort("#import \"b.h\"\n"
+ "#import \"c.h\"\n"
+ "@import Base;\n"
+ "#import \n"
+ "@import foundation;\n"
+ "@import Foundation;\n"
+ "@import base;\n"
+ "#import \"a.h\"\n"));
+
+  // Test that shows main headers in two groups are still found and sorting
+  // still works. The @import's are kept in their respective group but are
+  // put at the end of each group. 
+  FmtStyle.IncludeStyle.IncludeBlocks = tooling::IncludeStyle::IBS_Preserve;
+  EXPECT_EQ("#import \"foo.hpp\"\n"
+"#import \"b.h\"\n"
+"#import \"c.h\"\n"
+"#import \n"
+"@import Base;\n"
+"@import Foundation;\n"
+"@import foundation;\n"
+"\n"
+"#import \"foo.h\"\n"
+"#include \"foobar\"\n"
+"#import \n"
+"@import ;\n"
+"@import ;\n",
+sort("#import \"b.h\"\n"
+ "@import Foundation;\n"
+ "@import foundation;\n"
+ "#import \"c.h\"\n"
+ "#import \n"
+ "@import Base;\n"
+ "#import \"foo.hpp\"\n"
+ "\n"
+ "@import ;\n"
+ "#import \n"
+ "@import ;\n"
+ "#include \"foobar\"\n"
+ "#import \"foo.h\"\n",
+ "foo.c"));
+
+  // Regrouping and putting @import's in the very last group
+  FmtStyle.IncludeStyle.IncludeBlocks = tooling::IncludeStyle::IBS_Regroup;
+  EXPECT_EQ("#import \"foo.hpp\"\n"
+"\n"
+"#import \"b.h\"\n"
+"#import \"c.h\"\n"
+"#import \"foo.h\"\n"
+"#include \"foobar\"\n"
+"\n"
+"#import \n"
+"#import \n"
+"\n"
+"@import ;\n"
+"@import ;\n"
+"@import Base;\n"
+"@import Foundation;\n"
+"@import foundation;\n",
+sort("#import \"b.h\"\n"
+ "@import Foundation;\n"
+ "@import foundation;\n"
+ "#import \"c.h\"\n"
+ "#import \n"
+ "@import Base;\n"
+ "#import \"foo.hpp\"\n"
+ "\n"
+ "@import ;\n"
+ "#import \n"
+ "@import ;\n"
+ "#include \"foobar\"\n"
+ "#import \"foo.h\"\n",
+ "foo.c"));
+}
+
 TEST_F(SortIncludesTest, LeavesMainHeaderFirst) {
   Style.IncludeIsMainRegex = "([-_](test|unittest))?$";
   EXPECT_EQ("#include \"llvm/a.h\"\n"
Index: clang/lib/Tooling/Inclusions/HeaderIncludes.cpp
===
--- clang/lib/Tooling/Inclusions/HeaderIncludes.cpp
+++ clang/lib/Tooling/Inclusions/HeaderIncludes.cpp
@@ -170,11 +170,11 @@
 }
 
 inline StringRef trimInclude(StringRef IncludeName) {
-  return IncludeName.trim("\"<>");
+  return IncludeName.trim("\"<>;");
 }
 
 const char IncludeRegexPattern[] =
-R"(^[\t\ ]*#[\t\ ]*(import|include)[^"<]*(["<][^">]*[">]))";
+R"(^[\t\ ]*[@#][\t\ ]*(import|include)([^"]*("[^"]+")|[^<]*(<[^>]+>)|[\t\ ]*([^;]+;)))";
 
 // The filename of Path excluding extension.
 // Used to match implementation with headers, this differs from 

[PATCH] D121370: [clang-format] SortIncludes should support "@import" lines in Objective-C

2022-03-16 Thread Konrad Wilhelm Kleine via Phabricator via cfe-commits
kwk marked an inline comment as done.
kwk added a comment.

Addressed review comments.




Comment at: clang/lib/Format/Format.cpp:2779
 /*CheckMainHeader=*/!MainIncludeFound && FirstIncludeBlock);
-int Priority = Categories.getSortIncludePriority(
-IncludeName, !MainIncludeFound && FirstIncludeBlock);
+int Priority = WithSemicolon ? INT_MAX
+ : Categories.getSortIncludePriority(

HazardyKnusperkeks wrote:
> I don't know about the others, but I prefer C++: `std::numeric_limits`
Sure. That's done now.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D121370/new/

https://reviews.llvm.org/D121370

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D121370: [clang-format] SortIncludes should support "@import" lines in Objective-C

2022-03-16 Thread Konrad Wilhelm Kleine via Phabricator via cfe-commits
kwk updated this revision to Diff 415769.
kwk added a comment.

- Use std::numeric_limits::max() instead of INT_MAX


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D121370/new/

https://reviews.llvm.org/D121370

Files:
  clang/lib/Format/Format.cpp
  clang/lib/Tooling/Inclusions/HeaderIncludes.cpp
  clang/unittests/Format/SortIncludesTest.cpp

Index: clang/unittests/Format/SortIncludesTest.cpp
===
--- clang/unittests/Format/SortIncludesTest.cpp
+++ clang/unittests/Format/SortIncludesTest.cpp
@@ -458,6 +458,39 @@
  "#include \"b.h\"\n"));
 }
 
+TEST_F(SortIncludesTest, SupportAtImportLines) {
+  // Test from https://github.com/llvm/llvm-project/issues/38995
+  EXPECT_EQ("#import \"a.h\"\n"
+"#import \"b.h\"\n"
+"#import \"c.h\"\n"
+"#import \n"
+"@import Foundation;\n",
+sort("#import \"b.h\"\n"
+ "#import \"c.h\"\n"
+ "#import \n"
+ "@import Foundation;\n"
+ "#import \"a.h\"\n"));
+
+  // Slightly more complicated test that shows sorting in each priorities still
+  // works.
+  EXPECT_EQ("#import \"a.h\"\n"
+"#import \"b.h\"\n"
+"#import \"c.h\"\n"
+"#import \n"
+"@import Base;\n"
+"@import Foundation;\n"
+"@import base;\n"
+"@import foundation;\n",
+sort("#import \"b.h\"\n"
+ "#import \"c.h\"\n"
+ "@import Base;\n"
+ "#import \n"
+ "@import foundation;\n"
+ "@import Foundation;\n"
+ "@import base;\n"
+ "#import \"a.h\"\n"));
+}
+
 TEST_F(SortIncludesTest, LeavesMainHeaderFirst) {
   Style.IncludeIsMainRegex = "([-_](test|unittest))?$";
   EXPECT_EQ("#include \"llvm/a.h\"\n"
Index: clang/lib/Tooling/Inclusions/HeaderIncludes.cpp
===
--- clang/lib/Tooling/Inclusions/HeaderIncludes.cpp
+++ clang/lib/Tooling/Inclusions/HeaderIncludes.cpp
@@ -170,11 +170,11 @@
 }
 
 inline StringRef trimInclude(StringRef IncludeName) {
-  return IncludeName.trim("\"<>");
+  return IncludeName.trim("\"<>;");
 }
 
 const char IncludeRegexPattern[] =
-R"(^[\t\ ]*#[\t\ ]*(import|include)[^"<]*(["<][^">]*[">]))";
+R"(^[\t\ ]*[@#][\t\ ]*(import|include)([^"]*("[^"]+")|[^<]*(<[^>]+>)|[\t\ ]*([^;]+;)))";
 
 // The filename of Path excluding extension.
 // Used to match implementation with headers, this differs from sys::path::stem:
@@ -290,10 +290,17 @@
   for (auto Line : Lines) {
 NextLineOffset = std::min(Code.size(), Offset + Line.size() + 1);
 if (IncludeRegex.match(Line, )) {
+  StringRef IncludeName;
+  for (int i = Matches.size() - 1; i > 0; i--) {
+if (!Matches[i].empty()) {
+  IncludeName = Matches[i];
+  break;
+}
+  }
   // If this is the last line without trailing newline, we need to make
   // sure we don't delete across the file boundary.
   addExistingInclude(
-  Include(Matches[2],
+  Include(IncludeName,
   tooling::Range(
   Offset, std::min(Line.size() + 1, Code.size() - Offset))),
   NextLineOffset);
Index: clang/lib/Format/Format.cpp
===
--- clang/lib/Format/Format.cpp
+++ clang/lib/Format/Format.cpp
@@ -44,6 +44,7 @@
 #include "llvm/Support/VirtualFileSystem.h"
 #include "llvm/Support/YAMLTraits.h"
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -2682,8 +2683,7 @@
 namespace {
 
 const char CppIncludeRegexPattern[] =
-R"(^[\t\ ]*#[\t\ ]*(import|include)[^"<]*(["<][^">]*[">]))";
-
+R"(^[\t\ ]*[@#][\t\ ]*(import|include)([^"]*("[^"]+")|[^<]*(<[^>]+>)|[\t\ ]*([^;]+;)))";
 } // anonymous namespace
 
 tooling::Replacements sortCppIncludes(const FormatStyle , StringRef Code,
@@ -2751,7 +2751,20 @@
 bool MergeWithNextLine = Trimmed.endswith("\\");
 if (!FormattingOff && !MergeWithNextLine) {
   if (IncludeRegex.match(Line, )) {
-StringRef IncludeName = Matches[2];
+StringRef IncludeName;
+for (int i = Matches.size() - 1; i > 0; i--) {
+  if (!Matches[i].empty()) {
+IncludeName = Matches[i];
+break;
+  }
+}
+// This addresses https://github.com/llvm/llvm-project/issues/38995
+int WithSemicolon = false;
+if (!IncludeName.startswith("\"") && !IncludeName.startswith("<") &&
+IncludeName.endswith(";")) {
+  WithSemicolon = true;
+}
+
 if (Line.contains("/*") && !Line.contains("*/")) {
   // #include with a start of a block comment, but without the end.
   // Need to keep all the lines until the end of the comment together.
@@ -2764,8 +2777,10 

[PATCH] D121370: [clang-format] SortIncludes should support "@import" lines in Objective-C

2022-03-15 Thread Konrad Wilhelm Kleine via Phabricator via cfe-commits
kwk updated this revision to Diff 415489.
kwk edited the summary of this revision.
kwk added a comment.

- Fix formatting


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D121370/new/

https://reviews.llvm.org/D121370

Files:
  clang/lib/Format/Format.cpp
  clang/lib/Tooling/Inclusions/HeaderIncludes.cpp
  clang/unittests/Format/SortIncludesTest.cpp

Index: clang/unittests/Format/SortIncludesTest.cpp
===
--- clang/unittests/Format/SortIncludesTest.cpp
+++ clang/unittests/Format/SortIncludesTest.cpp
@@ -458,6 +458,39 @@
  "#include \"b.h\"\n"));
 }
 
+TEST_F(SortIncludesTest, SupportAtImportLines) {
+  // Test from https://github.com/llvm/llvm-project/issues/38995
+  EXPECT_EQ("#import \"a.h\"\n"
+"#import \"b.h\"\n"
+"#import \"c.h\"\n"
+"#import \n"
+"@import Foundation;\n",
+sort("#import \"b.h\"\n"
+ "#import \"c.h\"\n"
+ "#import \n"
+ "@import Foundation;\n"
+ "#import \"a.h\"\n"));
+
+  // Slightly more complicated test that shows sorting in each priorities still
+  // works.
+  EXPECT_EQ("#import \"a.h\"\n"
+"#import \"b.h\"\n"
+"#import \"c.h\"\n"
+"#import \n"
+"@import Base;\n"
+"@import Foundation;\n"
+"@import base;\n"
+"@import foundation;\n",
+sort("#import \"b.h\"\n"
+ "#import \"c.h\"\n"
+ "@import Base;\n"
+ "#import \n"
+ "@import foundation;\n"
+ "@import Foundation;\n"
+ "@import base;\n"
+ "#import \"a.h\"\n"));
+}
+
 TEST_F(SortIncludesTest, LeavesMainHeaderFirst) {
   Style.IncludeIsMainRegex = "([-_](test|unittest))?$";
   EXPECT_EQ("#include \"llvm/a.h\"\n"
Index: clang/lib/Tooling/Inclusions/HeaderIncludes.cpp
===
--- clang/lib/Tooling/Inclusions/HeaderIncludes.cpp
+++ clang/lib/Tooling/Inclusions/HeaderIncludes.cpp
@@ -170,11 +170,11 @@
 }
 
 inline StringRef trimInclude(StringRef IncludeName) {
-  return IncludeName.trim("\"<>");
+  return IncludeName.trim("\"<>;");
 }
 
 const char IncludeRegexPattern[] =
-R"(^[\t\ ]*#[\t\ ]*(import|include)[^"<]*(["<][^">]*[">]))";
+R"(^[\t\ ]*[@#][\t\ ]*(import|include)([^"]*("[^"]+")|[^<]*(<[^>]+>)|[\t\ ]*([^;]+;)))";
 
 // The filename of Path excluding extension.
 // Used to match implementation with headers, this differs from sys::path::stem:
@@ -290,10 +290,17 @@
   for (auto Line : Lines) {
 NextLineOffset = std::min(Code.size(), Offset + Line.size() + 1);
 if (IncludeRegex.match(Line, )) {
+  StringRef IncludeName;
+  for (int i = Matches.size() - 1; i > 0; i--) {
+if (!Matches[i].empty()) {
+  IncludeName = Matches[i];
+  break;
+}
+  }
   // If this is the last line without trailing newline, we need to make
   // sure we don't delete across the file boundary.
   addExistingInclude(
-  Include(Matches[2],
+  Include(IncludeName,
   tooling::Range(
   Offset, std::min(Line.size() + 1, Code.size() - Offset))),
   NextLineOffset);
Index: clang/lib/Format/Format.cpp
===
--- clang/lib/Format/Format.cpp
+++ clang/lib/Format/Format.cpp
@@ -2682,8 +2682,7 @@
 namespace {
 
 const char CppIncludeRegexPattern[] =
-R"(^[\t\ ]*#[\t\ ]*(import|include)[^"<]*(["<][^">]*[">]))";
-
+R"(^[\t\ ]*[@#][\t\ ]*(import|include)([^"]*("[^"]+")|[^<]*(<[^>]+>)|[\t\ ]*([^;]+;)))";
 } // anonymous namespace
 
 tooling::Replacements sortCppIncludes(const FormatStyle , StringRef Code,
@@ -2751,7 +2750,20 @@
 bool MergeWithNextLine = Trimmed.endswith("\\");
 if (!FormattingOff && !MergeWithNextLine) {
   if (IncludeRegex.match(Line, )) {
-StringRef IncludeName = Matches[2];
+StringRef IncludeName;
+for (int i = Matches.size() - 1; i > 0; i--) {
+  if (!Matches[i].empty()) {
+IncludeName = Matches[i];
+break;
+  }
+}
+// This addresses https://github.com/llvm/llvm-project/issues/38995
+int WithSemicolon = false;
+if (!IncludeName.startswith("\"") && !IncludeName.startswith("<") &&
+IncludeName.endswith(";")) {
+  WithSemicolon = true;
+}
+
 if (Line.contains("/*") && !Line.contains("*/")) {
   // #include with a start of a block comment, but without the end.
   // Need to keep all the lines until the end of the comment together.
@@ -2764,8 +2776,10 @@
 int Category = Categories.getIncludePriority(
 IncludeName,
 /*CheckMainHeader=*/!MainIncludeFound && 

[PATCH] D121370: [clang-format] SortIncludes should support "@import" lines in Objective-C

2022-03-15 Thread Konrad Wilhelm Kleine via Phabricator via cfe-commits
kwk updated this revision to Diff 415487.
kwk added a comment.

Changed the strategy of how includes are sorted by increasing the priority if 
an include is of the "new" type: `@import Foundation;`. This will sort these 
includes after everything else just as requested in 
https://github.com/llvm/llvm-project/issues/38995.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D121370/new/

https://reviews.llvm.org/D121370

Files:
  clang/lib/Format/Format.cpp
  clang/lib/Tooling/Inclusions/HeaderIncludes.cpp
  clang/unittests/Format/SortIncludesTest.cpp

Index: clang/unittests/Format/SortIncludesTest.cpp
===
--- clang/unittests/Format/SortIncludesTest.cpp
+++ clang/unittests/Format/SortIncludesTest.cpp
@@ -458,6 +458,39 @@
  "#include \"b.h\"\n"));
 }
 
+TEST_F(SortIncludesTest, SupportAtImportLines) {
+  // Test from https://github.com/llvm/llvm-project/issues/38995
+  EXPECT_EQ("#import \"a.h\"\n"
+"#import \"b.h\"\n"
+"#import \"c.h\"\n"
+"#import \n"
+"@import Foundation;\n",
+sort("#import \"b.h\"\n"
+ "#import \"c.h\"\n"
+ "#import \n"
+ "@import Foundation;\n"
+ "#import \"a.h\"\n"));
+
+  // Slightly more complicated test that shows sorting in each priorities still
+  // works.
+  EXPECT_EQ("#import \"a.h\"\n"
+"#import \"b.h\"\n"
+"#import \"c.h\"\n"
+"#import \n"
+"@import Base;\n"
+"@import Foundation;\n"
+"@import base;\n"
+"@import foundation;\n",
+sort("#import \"b.h\"\n"
+ "#import \"c.h\"\n"
+ "@import Base;\n"
+ "#import \n"
+ "@import foundation;\n"
+ "@import Foundation;\n"
+ "@import base;\n"
+ "#import \"a.h\"\n"));
+}
+
 TEST_F(SortIncludesTest, LeavesMainHeaderFirst) {
   Style.IncludeIsMainRegex = "([-_](test|unittest))?$";
   EXPECT_EQ("#include \"llvm/a.h\"\n"
Index: clang/lib/Tooling/Inclusions/HeaderIncludes.cpp
===
--- clang/lib/Tooling/Inclusions/HeaderIncludes.cpp
+++ clang/lib/Tooling/Inclusions/HeaderIncludes.cpp
@@ -170,11 +170,11 @@
 }
 
 inline StringRef trimInclude(StringRef IncludeName) {
-  return IncludeName.trim("\"<>");
+  return IncludeName.trim("\"<>;");
 }
 
 const char IncludeRegexPattern[] =
-R"(^[\t\ ]*#[\t\ ]*(import|include)[^"<]*(["<][^">]*[">]))";
+R"(^[\t\ ]*[@#][\t\ ]*(import|include)([^"]*("[^"]+")|[^<]*(<[^>]+>)|[\t\ ]*([^;]+;)))";
 
 // The filename of Path excluding extension.
 // Used to match implementation with headers, this differs from sys::path::stem:
@@ -290,10 +290,17 @@
   for (auto Line : Lines) {
 NextLineOffset = std::min(Code.size(), Offset + Line.size() + 1);
 if (IncludeRegex.match(Line, )) {
+  StringRef IncludeName;
+  for (int i=Matches.size()-1; i>0; i--) {
+if (!Matches[i].empty()) {
+  IncludeName = Matches[i];
+  break;
+}
+  }
   // If this is the last line without trailing newline, we need to make
   // sure we don't delete across the file boundary.
   addExistingInclude(
-  Include(Matches[2],
+  Include(IncludeName,
   tooling::Range(
   Offset, std::min(Line.size() + 1, Code.size() - Offset))),
   NextLineOffset);
Index: clang/lib/Format/Format.cpp
===
--- clang/lib/Format/Format.cpp
+++ clang/lib/Format/Format.cpp
@@ -2682,8 +2682,7 @@
 namespace {
 
 const char CppIncludeRegexPattern[] =
-R"(^[\t\ ]*#[\t\ ]*(import|include)[^"<]*(["<][^">]*[">]))";
-
+R"(^[\t\ ]*[@#][\t\ ]*(import|include)([^"]*("[^"]+")|[^<]*(<[^>]+>)|[\t\ ]*([^;]+;)))";
 } // anonymous namespace
 
 tooling::Replacements sortCppIncludes(const FormatStyle , StringRef Code,
@@ -2698,7 +2697,7 @@
   llvm::Regex IncludeRegex(CppIncludeRegexPattern);
   SmallVector Matches;
   SmallVector IncludesInBlock;
-
+  
   // In compiled files, consider the first #include to be the main #include of
   // the file if it is not a system #include. This ensures that the header
   // doesn't have hidden dependencies
@@ -2751,7 +2750,19 @@
 bool MergeWithNextLine = Trimmed.endswith("\\");
 if (!FormattingOff && !MergeWithNextLine) {
   if (IncludeRegex.match(Line, )) {
-StringRef IncludeName = Matches[2];
+StringRef IncludeName;
+for (int i=Matches.size()-1; i>0; i--) {
+  if (!Matches[i].empty()) {
+IncludeName = Matches[i];
+break;
+  }
+}
+// This addresses https://github.com/llvm/llvm-project/issues/38995
+int WithSemicolon = false;
+if 

[PATCH] D121370: [clang-format] SortIncludes should support "@import" lines in Objective-C

2022-03-10 Thread Konrad Wilhelm Kleine via Phabricator via cfe-commits
kwk planned changes to this revision.
kwk added a comment.

A test if failing. Need to address this first.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D121370/new/

https://reviews.llvm.org/D121370

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D121370: [clang-format] SortIncludes should support "@import" lines in Objective-C

2022-03-10 Thread Konrad Wilhelm Kleine via Phabricator via cfe-commits
kwk added a comment.

Thank you for your comments! I've addressed many of them and now address the 
rest.




Comment at: clang/lib/Format/Format.cpp:2759
+  IncludeName =
+  StringRef(Twine("<", IncludeName).concat(Twine(">")).str());
+}

curdeius wrote:
> HazardyKnusperkeks wrote:
> > How does that not go out of scope and I have a dangling reference?
> Why not doing it the other way round, i.e. trimming `<>"` from include name?
> Why not doing it the other way round, i.e. trimming `<>"` from include name?

Because the include name is used for sorting later and if the `<>` is removed 
from the name, the `<>` included will be mixed with the `""`. That's 
undesirable. 



Comment at: clang/lib/Format/Format.cpp:2759
+  IncludeName =
+  StringRef(Twine("<", IncludeName).concat(Twine(">")).str());
+}

kwk wrote:
> curdeius wrote:
> > HazardyKnusperkeks wrote:
> > > How does that not go out of scope and I have a dangling reference?
> > Why not doing it the other way round, i.e. trimming `<>"` from include name?
> > Why not doing it the other way round, i.e. trimming `<>"` from include name?
> 
> Because the include name is used for sorting later and if the `<>` is removed 
> from the name, the `<>` included will be mixed with the `""`. That's 
> undesirable. 
> How does that not go out of scope and I have a dangling reference?

Sorry I was a bit lost with this but with some help I found other places in 
which `concat` was used and `toStringRef`. I hope everything is fine now.



Comment at: clang/lib/Tooling/Inclusions/HeaderIncludes.cpp:177
 const char IncludeRegexPattern[] =
-R"(^[\t\ ]*#[\t\ ]*(import|include)[^"<]*(["<][^">]*[">]))";
+R"(^[\t\ ]*[@#]?[\t\ ]*(import|include)[^"<]*[\t\n\ 
\\]*("[^"]+"|<[^>]+>|[^"<>;]+;))";
 

HazardyKnusperkeks wrote:
> HazardyKnusperkeks wrote:
> > I don't see why this is needed. It should match with the previous stuff.
> Do we want that optional?
> I don't see why this is needed. It should match with the previous stuff.

That's why I thought too. I swear I ran the tests before and I wouldn't work 
without this. But I re-ran the tests and now it works. Thanks for bringing up 
this very obvious part.



Comment at: clang/lib/Tooling/Inclusions/HeaderIncludes.cpp:177
 const char IncludeRegexPattern[] =
-R"(^[\t\ ]*#[\t\ ]*(import|include)[^"<]*(["<][^">]*[">]))";
+R"(^[\t\ ]*[@#]?[\t\ ]*(import|include)[^"<]*[\t\n\ 
\\]*("[^"]+"|<[^>]+>|[^"<>;]+;))";
 

kwk wrote:
> HazardyKnusperkeks wrote:
> > HazardyKnusperkeks wrote:
> > > I don't see why this is needed. It should match with the previous stuff.
> > Do we want that optional?
> > I don't see why this is needed. It should match with the previous stuff.
> 
> That's why I thought too. I swear I ran the tests before and I wouldn't work 
> without this. But I re-ran the tests and now it works. Thanks for bringing up 
> this very obvious part.
> Do we want that optional?

We don't need it optional for the tests to pass. Only for C++20 Modules, we 
need it optional. But this is *not* part of this change. I've removed the 
optional part of this. 



Comment at: clang/unittests/Format/SortIncludesTest.cpp:471
+ "@import Foundation;\n"
+ "#import \"a.h\"\n"));
+}

HazardyKnusperkeks wrote:
> I've no idea about obj-c, is it feasible to mix `#` and `@`? If so please add 
> a test where the `@` is between `#`s.
> I've no idea about obj-c, is it feasible to mix `#` and `@`? If so please add 
> a test where the `@` is between `#`s.

This test is copied from the issue itself. I have no idea about Obj-c as well. 
The `@` already *is* between the `#`. Did I miss something?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D121370/new/

https://reviews.llvm.org/D121370

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D121370: [clang-format] SortIncludes should support "@import" lines in Objective-C

2022-03-10 Thread Konrad Wilhelm Kleine via Phabricator via cfe-commits
kwk updated this revision to Diff 414469.
kwk marked 2 inline comments as done.
kwk added a comment.

- Make @ or # not optional again
- Remove [\t\n\ \\]*
- Properly concat string


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D121370/new/

https://reviews.llvm.org/D121370

Files:
  clang/lib/Format/Format.cpp
  clang/lib/Tooling/Inclusions/HeaderIncludes.cpp
  clang/unittests/Format/SortIncludesTest.cpp


Index: clang/unittests/Format/SortIncludesTest.cpp
===
--- clang/unittests/Format/SortIncludesTest.cpp
+++ clang/unittests/Format/SortIncludesTest.cpp
@@ -458,6 +458,19 @@
  "#include \"b.h\"\n"));
 }
 
+TEST_F(SortIncludesTest, SupportAtImportLines) {
+  EXPECT_EQ("#import \"a.h\"\n"
+"#import \"b.h\"\n"
+"#import \"c.h\"\n"
+"#import \n"
+"@import Foundation;\n",
+sort("#import \"b.h\"\n"
+ "#import \"c.h\"\n"
+ "#import \n"
+ "@import Foundation;\n"
+ "#import \"a.h\"\n"));
+}
+
 TEST_F(SortIncludesTest, LeavesMainHeaderFirst) {
   Style.IncludeIsMainRegex = "([-_](test|unittest))?$";
   EXPECT_EQ("#include \"llvm/a.h\"\n"
Index: clang/lib/Tooling/Inclusions/HeaderIncludes.cpp
===
--- clang/lib/Tooling/Inclusions/HeaderIncludes.cpp
+++ clang/lib/Tooling/Inclusions/HeaderIncludes.cpp
@@ -170,11 +170,11 @@
 }
 
 inline StringRef trimInclude(StringRef IncludeName) {
-  return IncludeName.trim("\"<>");
+  return IncludeName.trim("\"<>;");
 }
 
 const char IncludeRegexPattern[] =
-R"(^[\t\ ]*#[\t\ ]*(import|include)[^"<]*(["<][^">]*[">]))";
+R"(^[\t\ ]*[@#][\t\ ]*(import|include)[^"<]*("[^"]+"|<[^>]+>|[^"<>;]+;))";
 
 // The filename of Path excluding extension.
 // Used to match implementation with headers, this differs from 
sys::path::stem:
Index: clang/lib/Format/Format.cpp
===
--- clang/lib/Format/Format.cpp
+++ clang/lib/Format/Format.cpp
@@ -2682,7 +2682,7 @@
 namespace {
 
 const char CppIncludeRegexPattern[] =
-R"(^[\t\ ]*#[\t\ ]*(import|include)[^"<]*(["<][^">]*[">]))";
+R"(^[\t\ ]*[@#][\t\ ]*(import|include)[^"<]*("[^"]+"|<[^>]+>|[^"<>;]+;))";
 
 } // anonymous namespace
 
@@ -2752,6 +2752,15 @@
 if (!FormattingOff && !MergeWithNextLine) {
   if (IncludeRegex.match(Line, )) {
 StringRef IncludeName = Matches[2];
+SmallString<0> IncludeNameStr;
+// HACK(kkleine): Sort C++ module includes/imports that are not 
enclosed
+// in "" or <> as if they are enclosed with <.
+if (!IncludeName.startswith("\"") && !IncludeName.startswith("<")) {
+  IncludeName = Twine("<", IncludeName)
+.concat(Twine(">"))
+.toStringRef(IncludeNameStr);
+}
+
 if (Line.contains("/*") && !Line.contains("*/")) {
   // #include with a start of a block comment, but without the end.
   // Need to keep all the lines until the end of the comment together.


Index: clang/unittests/Format/SortIncludesTest.cpp
===
--- clang/unittests/Format/SortIncludesTest.cpp
+++ clang/unittests/Format/SortIncludesTest.cpp
@@ -458,6 +458,19 @@
  "#include \"b.h\"\n"));
 }
 
+TEST_F(SortIncludesTest, SupportAtImportLines) {
+  EXPECT_EQ("#import \"a.h\"\n"
+"#import \"b.h\"\n"
+"#import \"c.h\"\n"
+"#import \n"
+"@import Foundation;\n",
+sort("#import \"b.h\"\n"
+ "#import \"c.h\"\n"
+ "#import \n"
+ "@import Foundation;\n"
+ "#import \"a.h\"\n"));
+}
+
 TEST_F(SortIncludesTest, LeavesMainHeaderFirst) {
   Style.IncludeIsMainRegex = "([-_](test|unittest))?$";
   EXPECT_EQ("#include \"llvm/a.h\"\n"
Index: clang/lib/Tooling/Inclusions/HeaderIncludes.cpp
===
--- clang/lib/Tooling/Inclusions/HeaderIncludes.cpp
+++ clang/lib/Tooling/Inclusions/HeaderIncludes.cpp
@@ -170,11 +170,11 @@
 }
 
 inline StringRef trimInclude(StringRef IncludeName) {
-  return IncludeName.trim("\"<>");
+  return IncludeName.trim("\"<>;");
 }
 
 const char IncludeRegexPattern[] =
-R"(^[\t\ ]*#[\t\ ]*(import|include)[^"<]*(["<][^">]*[">]))";
+R"(^[\t\ ]*[@#][\t\ ]*(import|include)[^"<]*("[^"]+"|<[^>]+>|[^"<>;]+;))";
 
 // The filename of Path excluding extension.
 // Used to match implementation with headers, this differs from sys::path::stem:
Index: clang/lib/Format/Format.cpp
===
--- clang/lib/Format/Format.cpp
+++ clang/lib/Format/Format.cpp
@@ -2682,7 +2682,7 @@
 namespace {
 
 const char CppIncludeRegexPattern[] =

[PATCH] D121370: [clang-format] SortIncludes should support "@import" lines in Objective-C

2022-03-10 Thread Konrad Wilhelm Kleine via Phabricator via cfe-commits
kwk created this revision.
kwk added reviewers: HazardyKnusperkeks, MyDeveloperDay.
Herald added a project: All.
kwk requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Fixes #38995

This is an attempt to modify the regular expression to identify
`@import` and `import` alongside the regular `#include`. The challenging
part was not to support `@` in addition to `#` but how to handle
everything that comes after the `include|import` keywords. Previously
everything that wasn't `"` or `<` was consumed. But as you can see in
this example from the issue #38995, there is no `"` or `<` following the
keyword:

  @import Foundation;

I experimented with a lot of fancy and useful expressions in this
online regex tool  only to find out that some
things are simply not supported by the regex implementation in LLVM.

- For example the beginning `[\t\ ]*` should be replacable by the horizontal 
whitespace character `\h*` but this will break the 
`SortIncludesTest.LeadingWhitespace` test.

That's why I've chosen to come back to the basic building blocks.

The essential change in this patch is the change from this regular
expression:

  ^[\t\ ]*#[\t\ ]*(import|include)[^"<]*(["<][^">]*[">])
  ~  ~~
  ^  ^
  |  |
  only support # prefix not @|
 only support "" and <> as delimiters
 no support for C++ modules and ;
 ending. Also this allows for ">
 or <" or "" or <> which all seems
 either off or wrong.

to this:

  ^[\t\ ]*[@#]?[\t\ ]*(import|include)[^"<]*[\t\n\ 
\\]*("[^"]+"|<[^>]+>|[^"<>;]+;)
  ~ ~~~ ~~~ ~~~ 
~
  ^ ^   ^   ^   ^
  | |   |   |   |
  | |   Clearly support "" and 
<>
  | |   as well as an include 
name
  | |   without enclosing 
characters.
  | |   Allows for no mixture 
of ">
  | |or <" or empty include 
names.
  | |
  Now optionally support @ and #.   These are needed to support: 
@import Foundation;

Here is how I've tested this patch:

  ninja clang-Format
  ninja FormatTests
  ./tools/clang/unittests/Format/FormatTests --gtest_filter=SortIncludesTest*

And if that worked I doubled checked that nothing else broke by running
all format checks:

  ./tools/clang/unittests/Format/FormatTests

One side effect of this change is it should partially support
C++20 Module 
`import` lines without the optional `export` in front. Adding
this can be a change on its own that shouldn't be too hard.

I see an opportunity to optimized the matching to exclude `@include` for
example. But eventually these should be caught by the compiler, so...


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D121370

Files:
  clang/lib/Format/Format.cpp
  clang/lib/Tooling/Inclusions/HeaderIncludes.cpp
  clang/unittests/Format/SortIncludesTest.cpp


Index: clang/unittests/Format/SortIncludesTest.cpp
===
--- clang/unittests/Format/SortIncludesTest.cpp
+++ clang/unittests/Format/SortIncludesTest.cpp
@@ -458,6 +458,19 @@
  "#include \"b.h\"\n"));
 }
 
+TEST_F(SortIncludesTest, SupportAtImportLines) {
+  EXPECT_EQ("#import \"a.h\"\n"
+"#import \"b.h\"\n"
+"#import \"c.h\"\n"
+"#import \n"
+"@import Foundation;\n",
+sort("#import \"b.h\"\n"
+ "#import \"c.h\"\n"
+ "#import \n"
+ "@import Foundation;\n"
+ "#import \"a.h\"\n"));
+}
+
 TEST_F(SortIncludesTest, LeavesMainHeaderFirst) {
   Style.IncludeIsMainRegex = "([-_](test|unittest))?$";
   EXPECT_EQ("#include \"llvm/a.h\"\n"
Index: clang/lib/Tooling/Inclusions/HeaderIncludes.cpp
===
--- clang/lib/Tooling/Inclusions/HeaderIncludes.cpp
+++ clang/lib/Tooling/Inclusions/HeaderIncludes.cpp
@@ -170,11 +170,11 @@
 }
 
 inline StringRef trimInclude(StringRef IncludeName) {
-  return IncludeName.trim("\"<>");
+  return IncludeName.trim("\"<>;");
 }
 
 const char IncludeRegexPattern[] =
-R"(^[\t\ ]*#[\t\ ]*(import|include)[^"<]*(["<][^">]*[">]))";
+R"(^[\t\ ]*[@#]?[\t\ ]*(import|include)[^"<]*[\t\n\ 

[PATCH] D120884: [format] Use int8_t as the underlying type of all enums in FormatStyle

2022-03-03 Thread Konrad Wilhelm Kleine via Phabricator via cfe-commits
kwk added a comment.

In D120884#3356746 , 
@HazardyKnusperkeks wrote:

> Please use the clang-format tag.

Yes, sorry that I forgot it again. And thank you for approving. Shall I wait 
for the others to approve this or land the patch?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D120884/new/

https://reviews.llvm.org/D120884

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D120398: [format] follow up: Use unsigned char as the base of all enums in FormatStyle

2022-03-03 Thread Konrad Wilhelm Kleine via Phabricator via cfe-commits
kwk abandoned this revision.
kwk added a comment.

I abandon this revision in favor of https://reviews.llvm.org/D120884.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D120398/new/

https://reviews.llvm.org/D120398

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D120884: [format] Use int8_t as the underlying type of all enums in FormatStyle

2022-03-03 Thread Konrad Wilhelm Kleine via Phabricator via cfe-commits
kwk created this revision.
kwk added reviewers: HazardyKnusperkeks, MyDeveloperDay, curdeius.
Herald added a project: All.
kwk requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

It was requested here (https://reviews.llvm.org/D120398#3353053) to make
the underlying type of all enums in `FormatStyle` an `int8_t`.

Originally the type was changed in https://reviews.llvm.org/D93758.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D120884

Files:
  clang/include/clang/Format/Format.h

Index: clang/include/clang/Format/Format.h
===
--- clang/include/clang/Format/Format.h
+++ clang/include/clang/Format/Format.h
@@ -62,7 +62,7 @@
   int AccessModifierOffset;
 
   /// Different styles for aligning after open brackets.
-  enum BracketAlignmentStyle : unsigned char {
+  enum BracketAlignmentStyle : int8_t {
 /// Align parameters on the open bracket, e.g.:
 /// \code
 ///   someLongFunction(argument1,
@@ -105,7 +105,7 @@
   BracketAlignmentStyle AlignAfterOpenBracket;
 
   /// Different style for aligning array initializers.
-  enum ArrayInitializerAlignmentStyle {
+  enum ArrayInitializerAlignmentStyle : int8_t {
 /// Align array column and left justify the columns e.g.:
 /// \code
 ///   struct test demo[] =
@@ -140,7 +140,7 @@
   /// ``AlignConsecutiveBitFields``), names in declarations (see
   /// ``AlignConsecutiveDeclarations``) or macro definitions (see
   /// ``AlignConsecutiveMacros``).
-  enum AlignConsecutiveStyle {
+  enum AlignConsecutiveStyle : int8_t {
 ACS_None,
 ACS_Consecutive,
 ACS_AcrossEmptyLines,
@@ -429,7 +429,7 @@
   AlignConsecutiveStyle AlignConsecutiveDeclarations;
 
   /// Different styles for aligning escaped newlines.
-  enum EscapedNewlineAlignmentStyle : unsigned char {
+  enum EscapedNewlineAlignmentStyle : int8_t {
 /// Don't align escaped newlines.
 /// \code
 ///   #define A \
@@ -464,7 +464,7 @@
   EscapedNewlineAlignmentStyle AlignEscapedNewlines;
 
   /// Different styles for aligning operands.
-  enum OperandAlignmentStyle : unsigned char {
+  enum OperandAlignmentStyle : int8_t {
 /// Do not align operands of binary and ternary expressions.
 /// The wrapped lines are indented ``ContinuationIndentWidth`` spaces from
 /// the start of the line.
@@ -567,7 +567,7 @@
 
   /// Different styles for merging short blocks containing at most one
   /// statement.
-  enum ShortBlockStyle : unsigned char {
+  enum ShortBlockStyle : int8_t {
 /// Never merge blocks into a single line.
 /// \code
 ///   while (true) {
@@ -614,7 +614,7 @@
 
   /// Different styles for merging short functions containing at most one
   /// statement.
-  enum ShortFunctionStyle : unsigned char {
+  enum ShortFunctionStyle : int8_t {
 /// Never merge functions into a single line.
 SFS_None,
 /// Only merge functions defined inside a class. Same as "inline",
@@ -666,7 +666,7 @@
   ShortFunctionStyle AllowShortFunctionsOnASingleLine;
 
   /// Different styles for handling short if statements.
-  enum ShortIfStyle : unsigned char {
+  enum ShortIfStyle : int8_t {
 /// Never put short ifs on the same line.
 /// \code
 ///   if (a)
@@ -738,7 +738,7 @@
 
   /// Different styles for merging short lambdas containing at most one
   /// statement.
-  enum ShortLambdaStyle : unsigned char {
+  enum ShortLambdaStyle : int8_t {
 /// Never merge lambdas into a single line.
 SLS_None,
 /// Only merge empty lambdas.
@@ -777,7 +777,7 @@
 
   /// Different ways to break after the function definition return type.
   /// This option is **deprecated** and is retained for backwards compatibility.
-  enum DefinitionReturnTypeBreakingStyle : unsigned char {
+  enum DefinitionReturnTypeBreakingStyle : int8_t {
 /// Break after return type automatically.
 /// ``PenaltyReturnTypeOnItsOwnLine`` is taken into account.
 DRTBS_None,
@@ -789,7 +789,7 @@
 
   /// Different ways to break after the function definition or
   /// declaration return type.
-  enum ReturnTypeBreakingStyle : unsigned char {
+  enum ReturnTypeBreakingStyle : int8_t {
 /// Break after return type automatically.
 /// ``PenaltyReturnTypeOnItsOwnLine`` is taken into account.
 /// \code
@@ -883,7 +883,7 @@
   bool AlwaysBreakBeforeMultilineStrings;
 
   /// Different ways to break after the template declaration.
-  enum BreakTemplateDeclarationsStyle : unsigned char {
+  enum BreakTemplateDeclarationsStyle : int8_t {
 /// Do not force break before declaration.
 /// ``PenaltyBreakTemplateDeclaration`` is taken into account.
 /// \code
@@ -961,7 +961,7 @@
   bool BinPackArguments;
 
   /// The style of inserting trailing commas into container literals.
-  enum TrailingCommaStyle : unsigned char {
+  enum TrailingCommaStyle : int8_t {
 /// Do not insert trailing commas.
 TCS_None,
 /// 

[PATCH] D120398: [format] follow up: Use unsigned char as the base of all enums in FormatStyle

2022-03-01 Thread Konrad Wilhelm Kleine via Phabricator via cfe-commits
kwk added a comment.

In D120398#3352436 , 
@HazardyKnusperkeks wrote:

> 



> That being said, I don't care that much that we declare the enums with a 
> type. But I care about consistency. Either land this, or revert D93758 
> .

Consistency was more or less the only reason why I made this change in the 
first place and I didn't expect so many comments on a change that is almost 
identical to D93758 . Sure I didn't have a 
good argument for or against it so far but... consistency... I'm glad this 
discussion came up anyways. Will look at each comment tomorrow.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D120398/new/

https://reviews.llvm.org/D120398

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D120712: [clang-format][docs] handle explicit enum values

2022-03-01 Thread Konrad Wilhelm Kleine via Phabricator via cfe-commits
kwk added a comment.

In D120712#3352051 , @MyDeveloperDay 
wrote:

> Does it need to be so "cloak and dagger"?  ;-)

No, you're right it doesn't have to be this way.

> We always welcome patches, but please think about logging the idea in github 
> issues (and assigning it to yourself), and use the good will of the regular 
> contributors to give you some feedback/advice (you never know we might know a 
> thing or too)

Fair enough.

> I'd like to see this review in the context of what you are proposing. I know 
> it doesn't do any actual harm on its own, but its doesn't actually do 
> anything, as such its technical debt right? we have to maintain and support 
> it when it goes wrong (it will unlikely go wrong, but it could I guess).
>
> My suggestion is to hold off this patch until you have something that needs 
> it then submit the reviews at the same time and mark with a dependency.  
> (@curdeius, @HazardyKnusperkeks, @owenpan  am I being fair?)

That sounds like a plan.

> Please also consider being more open about what you intend to work on, you 
> never know we could save you time and effort. Plus remember you'll want one 
> of us to review the changes so its good to build good relationships with the 
> key contributors and get their input.

To be honest, I'm rather new to the clang-format code base and plan on adding 
something for which I'd like to do the work. I've took your advice and create 
this github issue: https://github.com/llvm/llvm-project/issues/54137 . I look 
forward to comments on it. I really want to establish a good relationship and I 
appreciate that you kindly tell me about this.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D120712/new/

https://reviews.llvm.org/D120712

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D120712: [clang-format][docs] handle explicit enum values

2022-03-01 Thread Konrad Wilhelm Kleine via Phabricator via cfe-commits
kwk added a comment.

In D120712#3351889 , @MyDeveloperDay 
wrote:

>> My reasoning was that I'm going to introduce an explicit enum value
>
> Any reason why?

Yes, I but where's the fun if I told you now ;) . Just kidding. I don't want to 
go into the details but I plan on supporting a shared value between all 
enumerations. That's all I can say for now before I have my PoC ready to be 
presented for further discussion. But even if this future patch will never 
land, this very patch doesn't hurt, does it? Like I said, I tried to split my 
work into more easily consumable patches but I guess you're not convinced.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D120712/new/

https://reviews.llvm.org/D120712

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D120712: [clang-format][docs] handle explicit enum values

2022-03-01 Thread Konrad Wilhelm Kleine via Phabricator via cfe-commits
kwk added inline comments.



Comment at: clang/docs/tools/dump_format_style.py:174-175
 return '* ``%s`` (in configuration: ``%s``)\n%s' % (
-self.name,
-re.sub('.*_', '', self.config),
+self.clean_name,
+self.clean_config,
 doxygen2rst(indent(self.comment, 2)))

MyDeveloperDay wrote:
> Feels like there is repetition here
Are you suggesting to introduce a function `name_only` that looks like this?

```lang=python
def name_only(s: str) -> str:
  return s.split("=", 1)[0].strip()
```

If so, should this be a member function of `EnumValue` or where would you see 
it?

I'm not fond of introducing this function TBH because the name suggest it to be 
very generically usable when in fact it does just a simple thing. If you pass 
`foo and bar` to it you get `foo and bar` but that's not a usable name of any 
kind, right?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D120712/new/

https://reviews.llvm.org/D120712

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D120712: [clang-format][docs] handle explicit enum values

2022-03-01 Thread Konrad Wilhelm Kleine via Phabricator via cfe-commits
kwk added a comment.

In D120712#3351014 , @MyDeveloperDay 
wrote:

> I'm not quite sure how I feel about adding functionality that doesn't 
> actually do anything.

I hear you. My reasoning was that I'm going to introduce an explicit enum value 
sometime soon and when I have that value and this patch in one together with 
the added logic it would be harder to review. Whereas with my upcoming changes 
I'm simply updating the `clang/docs/ClangFormatStyleOptions.rst` by 
regenerating it with this script and you can just approve it. Essentially I 
want to make the review process as easy as it could be.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D120712/new/

https://reviews.llvm.org/D120712

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D120712: [clang-format][docs] handle explicit enum values

2022-03-01 Thread Konrad Wilhelm Kleine via Phabricator via cfe-commits
kwk created this revision.
kwk added a reviewer: FederAndInk.
kwk requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

If there was this enum definition before:

  struct FormatStyle {
//...
  
/// Different styles for aligning after open brackets.
enum WhateverStyle : unsigned char {
  /// Foo
  WS_Bar = 5
};
  };

We would output the following in
`clang/docs/ClangFormatStyleOptions.rst`
when running `cd ~/llvm-project/clang/docs/tools &&
./dump_format_style.py`:

  * ``WS_Bar = 5`` (in configuration: ``Bar = 5``)
Foo.

With this patch, we change it to something that looks more like what we
are accustomed to:

  * ``WS_Bar`` (in configuration: ``Bar``)
Foo.

This is a theoretical change because we don't have format style enums
that currently explicitly select a value. But while I was doing some
research on how to extend the `FormatStyle` I noticed this behavior and
thought it would make a small change.

You can experiment with and without this change by simply running 
`dump_format_style.py` while setting `AIAS_Left` to `AIAS_Left = 0`
in `clang/include/clang/Format/Format.h`. Without this change in
`Format.h` you shouldn't see any change being made to
`clang/docs/ClangFormatStyleOptions.rst`.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D120712

Files:
  clang/docs/tools/dump_format_style.py


Index: clang/docs/tools/dump_format_style.py
===
--- clang/docs/tools/dump_format_style.py
+++ clang/docs/tools/dump_format_style.py
@@ -159,10 +159,20 @@
 self.comment = comment
 self.config = config
 
+  @property
+  def clean_name(self) -> str:
+# In case the enum value has an explicit value (e.g. enum foo {bar = 42};)
+# we remove everything after the equal sign and just use "bar". 
+return self.name.split("=", 1)[0].strip()
+
+  @property
+  def clean_config(self) -> str:
+return re.sub('.*_', '', self.config).split("=", 1)[0].strip()
+
   def __str__(self):
 return '* ``%s`` (in configuration: ``%s``)\n%s' % (
-self.name,
-re.sub('.*_', '', self.config),
+self.clean_name,
+self.clean_config,
 doxygen2rst(indent(self.comment, 2)))
 
 


Index: clang/docs/tools/dump_format_style.py
===
--- clang/docs/tools/dump_format_style.py
+++ clang/docs/tools/dump_format_style.py
@@ -159,10 +159,20 @@
 self.comment = comment
 self.config = config
 
+  @property
+  def clean_name(self) -> str:
+# In case the enum value has an explicit value (e.g. enum foo {bar = 42};)
+# we remove everything after the equal sign and just use "bar". 
+return self.name.split("=", 1)[0].strip()
+
+  @property
+  def clean_config(self) -> str:
+return re.sub('.*_', '', self.config).split("=", 1)[0].strip()
+
   def __str__(self):
 return '* ``%s`` (in configuration: ``%s``)\n%s' % (
-self.name,
-re.sub('.*_', '', self.config),
+self.clean_name,
+self.clean_config,
 doxygen2rst(indent(self.comment, 2)))
 
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D120398: [format] follow up: Use unsigned char as the base of all enums in FormatStyle

2022-02-24 Thread Konrad Wilhelm Kleine via Phabricator via cfe-commits
kwk updated this revision to Diff 411105.
kwk added a comment.

Rebased on upstream/main


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D120398/new/

https://reviews.llvm.org/D120398

Files:
  clang/include/clang/Format/Format.h


Index: clang/include/clang/Format/Format.h
===
--- clang/include/clang/Format/Format.h
+++ clang/include/clang/Format/Format.h
@@ -105,7 +105,7 @@
   BracketAlignmentStyle AlignAfterOpenBracket;
 
   /// Different style for aligning array initializers.
-  enum ArrayInitializerAlignmentStyle {
+  enum ArrayInitializerAlignmentStyle : unsigned char {
 /// Align array column and left justify the columns e.g.:
 /// \code
 ///   struct test demo[] =
@@ -140,7 +140,7 @@
   /// ``AlignConsecutiveBitFields``), names in declarations (see
   /// ``AlignConsecutiveDeclarations``) or macro definitions (see
   /// ``AlignConsecutiveMacros``).
-  enum AlignConsecutiveStyle {
+  enum AlignConsecutiveStyle : unsigned char {
 ACS_None,
 ACS_Consecutive,
 ACS_AcrossEmptyLines,
@@ -1771,7 +1771,7 @@
   BraceWrappingFlags BraceWrapping;
 
   /// Different ways to break before concept declarations.
-  enum BreakBeforeConceptDeclarationsStyle {
+  enum BreakBeforeConceptDeclarationsStyle : unsigned char {
 /// Keep the template declaration line together with ``concept``.
 /// \code
 ///   template  concept C = ...;
@@ -1882,7 +1882,7 @@
   std::string CommentPragmas;
 
   /// Different specifiers and qualifiers alignment styles.
-  enum QualifierAlignmentStyle {
+  enum QualifierAlignmentStyle : unsigned char {
 /// Don't change specifiers/qualifiers to either Left or Right alignment
 /// (default).
 /// \code
@@ -3067,7 +3067,7 @@
   std::vector RawStringFormats;
 
   /// \brief The ``&`` and ``&&`` alignment style.
-  enum ReferenceAlignmentStyle {
+  enum ReferenceAlignmentStyle : unsigned char {
 /// Align reference like ``PointerAlignment``.
 RAS_Pointer,
 /// Align reference to the left.
@@ -3166,7 +3166,7 @@
   /// \brief The possible positions for the requires clause. The
   /// ``IndentRequires`` option is only used if the ``requires`` is put on the
   /// start of a line.
-  enum RequiresClausePositionStyle {
+  enum RequiresClausePositionStyle : unsigned char {
 /// Always put the ``requires`` clause on its own line.
 /// \code
 ///   template 
@@ -3245,7 +3245,7 @@
   RequiresClausePositionStyle RequiresClausePosition;
 
   /// \brief The style if definition blocks should be separated.
-  enum SeparateDefinitionStyle {
+  enum SeparateDefinitionStyle : unsigned char {
 /// Leave definition blocks as they are.
 SDS_Leave,
 /// Insert an empty line between definition blocks.


Index: clang/include/clang/Format/Format.h
===
--- clang/include/clang/Format/Format.h
+++ clang/include/clang/Format/Format.h
@@ -105,7 +105,7 @@
   BracketAlignmentStyle AlignAfterOpenBracket;
 
   /// Different style for aligning array initializers.
-  enum ArrayInitializerAlignmentStyle {
+  enum ArrayInitializerAlignmentStyle : unsigned char {
 /// Align array column and left justify the columns e.g.:
 /// \code
 ///   struct test demo[] =
@@ -140,7 +140,7 @@
   /// ``AlignConsecutiveBitFields``), names in declarations (see
   /// ``AlignConsecutiveDeclarations``) or macro definitions (see
   /// ``AlignConsecutiveMacros``).
-  enum AlignConsecutiveStyle {
+  enum AlignConsecutiveStyle : unsigned char {
 ACS_None,
 ACS_Consecutive,
 ACS_AcrossEmptyLines,
@@ -1771,7 +1771,7 @@
   BraceWrappingFlags BraceWrapping;
 
   /// Different ways to break before concept declarations.
-  enum BreakBeforeConceptDeclarationsStyle {
+  enum BreakBeforeConceptDeclarationsStyle : unsigned char {
 /// Keep the template declaration line together with ``concept``.
 /// \code
 ///   template  concept C = ...;
@@ -1882,7 +1882,7 @@
   std::string CommentPragmas;
 
   /// Different specifiers and qualifiers alignment styles.
-  enum QualifierAlignmentStyle {
+  enum QualifierAlignmentStyle : unsigned char {
 /// Don't change specifiers/qualifiers to either Left or Right alignment
 /// (default).
 /// \code
@@ -3067,7 +3067,7 @@
   std::vector RawStringFormats;
 
   /// \brief The ``&`` and ``&&`` alignment style.
-  enum ReferenceAlignmentStyle {
+  enum ReferenceAlignmentStyle : unsigned char {
 /// Align reference like ``PointerAlignment``.
 RAS_Pointer,
 /// Align reference to the left.
@@ -3166,7 +3166,7 @@
   /// \brief The possible positions for the requires clause. The
   /// ``IndentRequires`` option is only used if the ``requires`` is put on the
   /// start of a line.
-  enum RequiresClausePositionStyle {
+  enum RequiresClausePositionStyle : unsigned char {
 /// Always put the ``requires`` clause on its own 

[PATCH] D120398: [format] follow up: Use unsigned char as the base of all enums in FormatStyle

2022-02-23 Thread Konrad Wilhelm Kleine via Phabricator via cfe-commits
kwk created this revision.
kwk requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Analogous to https://reviews.llvm.org/D93758, this patch uses
`unsigned char` for all enums in `FormatStyle`.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D120398

Files:
  clang/include/clang/Format/Format.h


Index: clang/include/clang/Format/Format.h
===
--- clang/include/clang/Format/Format.h
+++ clang/include/clang/Format/Format.h
@@ -105,7 +105,7 @@
   BracketAlignmentStyle AlignAfterOpenBracket;
 
   /// Different style for aligning array initializers.
-  enum ArrayInitializerAlignmentStyle {
+  enum ArrayInitializerAlignmentStyle : unsigned char {
 /// Align array column and left justify the columns e.g.:
 /// \code
 ///   struct test demo[] =
@@ -140,7 +140,7 @@
   /// ``AlignConsecutiveBitFields``), names in declarations (see
   /// ``AlignConsecutiveDeclarations``) or macro definitions (see
   /// ``AlignConsecutiveMacros``).
-  enum AlignConsecutiveStyle {
+  enum AlignConsecutiveStyle : unsigned char {
 ACS_None,
 ACS_Consecutive,
 ACS_AcrossEmptyLines,
@@ -1771,7 +1771,7 @@
   BraceWrappingFlags BraceWrapping;
 
   /// Different ways to break before concept declarations.
-  enum BreakBeforeConceptDeclarationsStyle {
+  enum BreakBeforeConceptDeclarationsStyle : unsigned char {
 /// Keep the template declaration line together with ``concept``.
 /// \code
 ///   template  concept C = ...;
@@ -1882,7 +1882,7 @@
   std::string CommentPragmas;
 
   /// Different specifiers and qualifiers alignment styles.
-  enum QualifierAlignmentStyle {
+  enum QualifierAlignmentStyle : unsigned char {
 /// Don't change specifiers/qualifiers to either Left or Right alignment
 /// (default).
 /// \code
@@ -3067,7 +3067,7 @@
   std::vector RawStringFormats;
 
   /// \brief The ``&`` and ``&&`` alignment style.
-  enum ReferenceAlignmentStyle {
+  enum ReferenceAlignmentStyle : unsigned char {
 /// Align reference like ``PointerAlignment``.
 RAS_Pointer,
 /// Align reference to the left.
@@ -3166,7 +3166,7 @@
   /// \brief The possible positions for the requires clause. The
   /// ``IndentRequires`` option is only used if the ``requires`` is put on the
   /// start of a line.
-  enum RequiresClausePositionStyle {
+  enum RequiresClausePositionStyle : unsigned char {
 /// Always put the ``requires`` clause on its own line.
 /// \code
 ///   template 
@@ -3245,7 +3245,7 @@
   RequiresClausePositionStyle RequiresClausePosition;
 
   /// \brief The style if definition blocks should be separated.
-  enum SeparateDefinitionStyle {
+  enum SeparateDefinitionStyle : unsigned char {
 /// Leave definition blocks as they are.
 SDS_Leave,
 /// Insert an empty line between definition blocks.


Index: clang/include/clang/Format/Format.h
===
--- clang/include/clang/Format/Format.h
+++ clang/include/clang/Format/Format.h
@@ -105,7 +105,7 @@
   BracketAlignmentStyle AlignAfterOpenBracket;
 
   /// Different style for aligning array initializers.
-  enum ArrayInitializerAlignmentStyle {
+  enum ArrayInitializerAlignmentStyle : unsigned char {
 /// Align array column and left justify the columns e.g.:
 /// \code
 ///   struct test demo[] =
@@ -140,7 +140,7 @@
   /// ``AlignConsecutiveBitFields``), names in declarations (see
   /// ``AlignConsecutiveDeclarations``) or macro definitions (see
   /// ``AlignConsecutiveMacros``).
-  enum AlignConsecutiveStyle {
+  enum AlignConsecutiveStyle : unsigned char {
 ACS_None,
 ACS_Consecutive,
 ACS_AcrossEmptyLines,
@@ -1771,7 +1771,7 @@
   BraceWrappingFlags BraceWrapping;
 
   /// Different ways to break before concept declarations.
-  enum BreakBeforeConceptDeclarationsStyle {
+  enum BreakBeforeConceptDeclarationsStyle : unsigned char {
 /// Keep the template declaration line together with ``concept``.
 /// \code
 ///   template  concept C = ...;
@@ -1882,7 +1882,7 @@
   std::string CommentPragmas;
 
   /// Different specifiers and qualifiers alignment styles.
-  enum QualifierAlignmentStyle {
+  enum QualifierAlignmentStyle : unsigned char {
 /// Don't change specifiers/qualifiers to either Left or Right alignment
 /// (default).
 /// \code
@@ -3067,7 +3067,7 @@
   std::vector RawStringFormats;
 
   /// \brief The ``&`` and ``&&`` alignment style.
-  enum ReferenceAlignmentStyle {
+  enum ReferenceAlignmentStyle : unsigned char {
 /// Align reference like ``PointerAlignment``.
 RAS_Pointer,
 /// Align reference to the left.
@@ -3166,7 +3166,7 @@
   /// \brief The possible positions for the requires clause. The
   /// ``IndentRequires`` option is only used if the ``requires`` is put on the
   /// start of a line.
-  enum RequiresClausePositionStyle {
+  enum 

[PATCH] D113993: WIP: [clang] customizable build-id style

2021-11-16 Thread Konrad Wilhelm Kleine via Phabricator via cfe-commits
kwk updated this revision to Diff 387650.
kwk added a comment.

enabled DEFAULT_LINKER_BUILD_ID_STYLE in linux


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D113993/new/

https://reviews.llvm.org/D113993

Files:
  clang/CMakeLists.txt
  clang/include/clang/Config/config.h.cmake
  clang/lib/Driver/ToolChains/Hurd.cpp
  clang/lib/Driver/ToolChains/Linux.cpp


Index: clang/lib/Driver/ToolChains/Linux.cpp
===
--- clang/lib/Driver/ToolChains/Linux.cpp
+++ clang/lib/Driver/ToolChains/Linux.cpp
@@ -245,7 +245,11 @@
   }
 
 #ifdef ENABLE_LINKER_BUILD_ID
-  ExtraOpts.push_back("--build-id");
+  #ifdef ENABLE_LINKER_BUILD_ID_STYLE
+ExtraOpts.push_back("--build-id=" ENABLE_LINKER_BUILD_ID_STYLE);
+  #else
+ExtraOpts.push_back("--build-id");
+  #endif
 #endif
 
   if (IsAndroid || Distro.IsOpenSUSE())
Index: clang/lib/Driver/ToolChains/Hurd.cpp
===
--- clang/lib/Driver/ToolChains/Hurd.cpp
+++ clang/lib/Driver/ToolChains/Hurd.cpp
@@ -82,7 +82,11 @@
   const std::string MultiarchTriple = getMultiarchTriple(D, Triple, SysRoot);
 
 #ifdef ENABLE_LINKER_BUILD_ID
-  ExtraOpts.push_back("--build-id");
+  #ifdef ENABLE_LINKER_BUILD_ID_STYLE
+ExtraOpts.push_back("--build-id=" ENABLE_LINKER_BUILD_ID_STYLE);
+  #else
+ExtraOpts.push_back("--build-id");
+  #endif
 #endif
 
   Generic_GCC::AddMultilibPaths(D, SysRoot, OSLibDir, MultiarchTriple, Paths);
Index: clang/include/clang/Config/config.h.cmake
===
--- clang/include/clang/Config/config.h.cmake
+++ clang/include/clang/Config/config.h.cmake
@@ -69,9 +69,12 @@
 /* Linker version detected at compile time. */
 #cmakedefine HOST_LINK_VERSION "${HOST_LINK_VERSION}"
 
-/* pass --build-id to ld */
+/* Pass --build-id or 

[PATCH] D113993: WIP: [clang] customizable build-id style

2021-11-16 Thread Konrad Wilhelm Kleine via Phabricator via cfe-commits
kwk updated this revision to Diff 387610.

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D113993/new/

https://reviews.llvm.org/D113993

Files:
  clang/CMakeLists.txt
  clang/include/clang/Config/config.h.cmake
  clang/lib/Driver/ToolChains/Hurd.cpp


Index: clang/lib/Driver/ToolChains/Hurd.cpp
===
--- clang/lib/Driver/ToolChains/Hurd.cpp
+++ clang/lib/Driver/ToolChains/Hurd.cpp
@@ -82,7 +82,11 @@
   const std::string MultiarchTriple = getMultiarchTriple(D, Triple, SysRoot);
 
 #ifdef ENABLE_LINKER_BUILD_ID
-  ExtraOpts.push_back("--build-id");
+  #ifdef ENABLE_LINKER_BUILD_ID_STYLE
+ExtraOpts.push_back("--build-id=" ENABLE_LINKER_BUILD_ID_STYLE);
+  #else
+ExtraOpts.push_back("--build-id");
+  #endif
 #endif
 
   Generic_GCC::AddMultilibPaths(D, SysRoot, OSLibDir, MultiarchTriple, Paths);
Index: clang/include/clang/Config/config.h.cmake
===
--- clang/include/clang/Config/config.h.cmake
+++ clang/include/clang/Config/config.h.cmake
@@ -69,9 +69,12 @@
 /* Linker version detected at compile time. */
 #cmakedefine HOST_LINK_VERSION "${HOST_LINK_VERSION}"
 
-/* pass --build-id to ld */
+/* Pass --build-id or 

[PATCH] D113993: WIP: [clang] customizable build-id style

2021-11-16 Thread Konrad Wilhelm Kleine via Phabricator via cfe-commits
kwk updated this revision to Diff 387608.
kwk added a comment.

Use correct CMake variable type: BOOLEAN -> BOOL


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D113993/new/

https://reviews.llvm.org/D113993

Files:
  clang/CMakeLists.txt


Index: clang/CMakeLists.txt
===
--- clang/CMakeLists.txt
+++ clang/CMakeLists.txt
@@ -219,7 +219,7 @@
 set(DEFAULT_SYSROOT "" CACHE STRING
   "Default  to all compiler invocations for --sysroot=." )
 
-set(ENABLE_LINKER_BUILD_ID OFF CACHE BOOLEAN
+set(ENABLE_LINKER_BUILD_ID OFF CACHE BOOL
   "Pass --build-id or 

[PATCH] D113993: WIP: [clang] customizable build-id style

2021-11-16 Thread Konrad Wilhelm Kleine via Phabricator via cfe-commits
kwk updated this revision to Diff 387606.
kwk edited the summary of this revision.
kwk added a comment.

Renamed: `ENABLE_LINKER_BUILD_ID_STYLE` to `DEFAULT_LINKER_BUILD_ID_STYLE`.
Fixed issues with CMake (not done yet)


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D113993/new/

https://reviews.llvm.org/D113993

Files:
  clang/CMakeLists.txt
  clang/include/clang/Config/config.h.cmake
  clang/lib/Driver/ToolChains/Hurd.cpp


Index: clang/lib/Driver/ToolChains/Hurd.cpp
===
--- clang/lib/Driver/ToolChains/Hurd.cpp
+++ clang/lib/Driver/ToolChains/Hurd.cpp
@@ -82,7 +82,11 @@
   const std::string MultiarchTriple = getMultiarchTriple(D, Triple, SysRoot);
 
 #ifdef ENABLE_LINKER_BUILD_ID
-  ExtraOpts.push_back("--build-id");
+  #ifdef ENABLE_LINKER_BUILD_ID_STYLE
+ExtraOpts.push_back("--build-id=" ENABLE_LINKER_BUILD_ID_STYLE);
+  #else
+ExtraOpts.push_back("--build-id");
+  #endif
 #endif
 
   Generic_GCC::AddMultilibPaths(D, SysRoot, OSLibDir, MultiarchTriple, Paths);
Index: clang/include/clang/Config/config.h.cmake
===
--- clang/include/clang/Config/config.h.cmake
+++ clang/include/clang/Config/config.h.cmake
@@ -69,9 +69,12 @@
 /* Linker version detected at compile time. */
 #cmakedefine HOST_LINK_VERSION "${HOST_LINK_VERSION}"
 
-/* pass --build-id to ld */
+/* Pass --build-id or 

[PATCH] D113993: WIP: [clang] customizable build-id style

2021-11-16 Thread Konrad Wilhelm Kleine via Phabricator via cfe-commits
kwk created this revision.
kwk added reviewers: tbaeder, tstellar.
kwk added projects: clang, lld.
Herald added a subscriber: mgorny.
kwk requested review of this revision.
Herald added a subscriber: cfe-commits.

**This is work in progress. I'm evaluating the patch now.**

This change introduces the possibility to specify a style of build-id
generation that must be one of "md5", "sha1", "fast", "uuid", or
"0x". To set this style, one can set
`ENABLE_LINKER_BUILD_ID_STYLE`. Setting the style will  automatically
turn `ON` `ENABLE_LINKER_BUILD_ID`.

The effect is that invocations of the compiler will link with

[PATCH] D112921: [clang] Enable sized deallocation by default in C++14 onwards

2021-11-12 Thread Konrad Wilhelm Kleine via Phabricator via cfe-commits
kwk added a comment.

You've disabled sized deallocation in some tests by providing 
`-fno-sized-deallocation `. I admit I haven't looked at those tests in detail 
but I would like to understand if those tests would otherwise fail. If they 
fail, is there work that needs to be done later to make them work again?




Comment at: clang/lib/Driver/ToolChains/Clang.cpp:6403
 
-  // -fsized-deallocation is off by default, as it is an ABI-breaking change 
for
-  // most platforms.
-  if (Args.hasFlag(options::OPT_fsized_deallocation,
-   options::OPT_fno_sized_deallocation, false))
-CmdArgs.push_back("-fsized-deallocation");
+  // -fsized-deallocation is on by default in C++14 onwards and otherwise off
+  // by default.

@rjmccall mentioned [here](https://reviews.llvm.org/D8467#3125570) that 

> Apple would like this to only be enabled conditionally based on deployment 
> target.

Is this considered at all?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D112921/new/

https://reviews.llvm.org/D112921

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D106809: [clang-offload-bundler] Make Bundle Entry ID backward compatible

2021-09-10 Thread Konrad Wilhelm Kleine via Phabricator via cfe-commits
kwk added a comment.

@saiislam please have a look into why this happens. Is the 
`-debug-only=CodeObjectCompatibility` maybe a left-over of some sort?




Comment at: clang/test/Driver/clang-offload-bundler.c:405
+// Tests to check compatibility between Bundle Entry ID formats i.e. between 
presence/absence of extra hyphen in case of missing environment field
+// RUN: clang-offload-bundler -unbundle -type=a 
-targets=openmp-amdgcn-amd-amdhsa--gfx906,openmp-amdgcn-amd-amdhsa-gfx908 
-inputs=%t.input-archive.a 
-outputs=%t-archive-gfx906-simple.a,%t-archive-gfx908-simple.a 
-debug-only=CodeObjectCompatibility 2>&1 | FileCheck %s 
-check-prefix=BUNDLECOMPATIBILITY
+// BUNDLECOMPATIBILITY: Compatible: Exact match:[CodeObject: 
openmp-amdgcn-amd-amdhsa-gfx906]   :   [Target: 
openmp-amdgcn-amd-amdhsa--gfx906]

RKSimon wrote:
> @saiislam This is causing an issue on a thinlto buildbot: 
> https://lab.llvm.org/buildbot/#/builders/67/builds/4148
@saiislam We're seeing the same issue in one of our [downstream 
builders](https://download.copr.fedorainfracloud.org/results/kkleine/llvm-snapshots/fedora-rawhide-x86_64/02687097-clang/builder-live.log.gz):
 

```
: 'RUN: at line 405';   clang-offload-bundler -unbundle -type=a 
-targets=openmp-amdgcn-amd-amdhsa--gfx906,openmp-amdgcn-amd-amdhsa-gfx908 
-inputs=/builddir/build/BUILD/clang-14.0.0.src/redhat-linux-build/test/Driver/Output/clang-offload-bundler.c.tmp.input-archive.a
 
-outputs=/builddir/build/BUILD/clang-14.0.0.src/redhat-linux-build/test/Driver/Output/clang-offload-bundler.c.tmp-archive-gfx906-simple.a,/builddir/build/BUILD/clang-14.0.0.src/redhat-linux-build/test/Driver/Output/clang-offload-bundler.c.tmp-archive-gfx908-simple.a
 -debug-only=CodeObjectCompatibility 2>&1 | /usr/bin/FileCheck 
/builddir/build/BUILD/clang-14.0.0.src/test/Driver/clang-offload-bundler.c 
-check-prefix=BUNDLECOMPATIBILITY
--
Exit Code: 1

Command Output (stderr):
--
/builddir/build/BUILD/clang-14.0.0.src/test/Driver/clang-offload-bundler.c:406:25:
 error: BUNDLECOMPATIBILITY: expected string not found in input
// BUNDLECOMPATIBILITY: Compatible: Exact match: [CodeObject: 
openmp-amdgcn-amd-amdhsa-gfx906] : [Target: openmp-amdgcn-amd-amdhsa--gfx906]
^
:1:1: note: scanning from here
clang-offload-bundler: Unknown command line argument 
'-debug-only=CodeObjectCompatibility'. Try: 'clang-offload-bundler --help'
^

Input file: 
Check file: 
/builddir/build/BUILD/clang-14.0.0.src/test/Driver/clang-offload-bundler.c

-dump-input=help explains the following input dump.

Input was:
<<
   1: clang-offload-bundler: Unknown command line argument 
'-debug-only=CodeObjectCompatibility'. Try: 'clang-offload-bundler --help' 
check:406 
X~~~
 error: no match found
   2: clang-offload-bundler: Did you mean 
'--unbundle=CodeObjectCompatibility'? 
check:406 
~~
>>

--
```




Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D106809/new/

https://reviews.llvm.org/D106809

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D80531: [clang-tidy]: Added modernize-replace-disallow-copy-and-assign-macro

2020-06-03 Thread Konrad Wilhelm Kleine via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGe636e6b79ac0: [clang-tidy]: Added 
modernize-replace-disallow-copy-and-assign-macro (authored by kwk).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D80531/new/

https://reviews.llvm.org/D80531

Files:
  clang-tools-extra/clang-tidy/modernize/CMakeLists.txt
  clang-tools-extra/clang-tidy/modernize/ModernizeTidyModule.cpp
  
clang-tools-extra/clang-tidy/modernize/ReplaceDisallowCopyAndAssignMacroCheck.cpp
  
clang-tools-extra/clang-tidy/modernize/ReplaceDisallowCopyAndAssignMacroCheck.h
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  
clang-tools-extra/docs/clang-tidy/checks/modernize-replace-disallow-copy-and-assign-macro.rst
  
clang-tools-extra/test/clang-tidy/checkers/modernize-replace-disallow-copy-and-assign-macro.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/modernize-replace-disallow-copy-and-assign-macro.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/modernize-replace-disallow-copy-and-assign-macro.cpp
@@ -0,0 +1,79 @@
+// RUN: %check_clang_tidy -format-style=LLVM -check-suffix=DEFAULT %s \
+// RUN:   modernize-replace-disallow-copy-and-assign-macro %t
+
+// RUN: %check_clang_tidy -format-style=LLVM -check-suffix=DIFFERENT-NAME %s \
+// RUN:  modernize-replace-disallow-copy-and-assign-macro %t \
+// RUN:  -config="{CheckOptions: [ \
+// RUN:   {key: modernize-replace-disallow-copy-and-assign-macro.MacroName, \
+// RUN:value: MY_MACRO_NAME}]}"
+
+// RUN: %check_clang_tidy -format-style=LLVM -check-suffix=FINALIZE %s \
+// RUN:  modernize-replace-disallow-copy-and-assign-macro %t \
+// RUN:  -config="{CheckOptions: [ \
+// RUN:   {key: modernize-replace-disallow-copy-and-assign-macro.MacroName, \
+// RUN:value: DISALLOW_COPY_AND_ASSIGN_FINALIZE}]}"
+
+// RUN: clang-tidy %s -checks="-*,modernize-replace-disallow-copy-and-assign-macro" \
+// RUN:   -config="{CheckOptions: [ \
+// RUN:{key: modernize-replace-disallow-copy-and-assign-macro.MacroName, \
+// RUN: value: DISALLOW_COPY_AND_ASSIGN_MORE_AGUMENTS}]}" | count 0
+
+// RUN: clang-tidy %s -checks="-*,modernize-replace-disallow-copy-and-assign-macro" \
+// RUN:   -config="{CheckOptions: [ \
+// RUN:{key: modernize-replace-disallow-copy-and-assign-macro.MacroName, \
+// RUN: value: DISALLOW_COPY_AND_ASSIGN_NEEDS_PREEXPANSION}]}" | count 0
+
+// Note: the last two tests expect no diagnostics, but FileCheck cannot handle
+// that, hence the use of | count 0.
+
+#define DISALLOW_COPY_AND_ASSIGN(TypeName)
+
+class TestClass1 {
+private:
+  DISALLOW_COPY_AND_ASSIGN(TestClass1);
+};
+// CHECK-MESSAGES-DEFAULT: :[[@LINE-2]]:3: warning: prefer deleting copy constructor and assignment operator over using macro 'DISALLOW_COPY_AND_ASSIGN' [modernize-replace-disallow-copy-and-assign-macro]
+// CHECK-FIXES-DEFAULT:  {{^}}  TestClass1(const TestClass1 &) = delete;{{$}}
+// CHECK-FIXES-DEFAULT-NEXT: {{^}}  const TestClass1 =(const TestClass1 &) = delete;{{$}}
+
+#define MY_MACRO_NAME(TypeName)
+
+class TestClass2 {
+private:
+  MY_MACRO_NAME(TestClass2);
+};
+// CHECK-MESSAGES-DIFFERENT-NAME: :[[@LINE-2]]:3: warning: prefer deleting copy constructor and assignment operator over using macro 'MY_MACRO_NAME' [modernize-replace-disallow-copy-and-assign-macro]
+// CHECK-FIXES-DIFFERENT-NAME:  {{^}}  TestClass2(const TestClass2 &) = delete;{{$}}
+// CHECK-FIXES-DIFFERENT-NAME-NEXT: {{^}}  const TestClass2 =(const TestClass2 &) = delete;{{$}}
+
+#define DISALLOW_COPY_AND_ASSIGN_FINALIZE(TypeName) \
+  TypeName(const TypeName &) = delete;  \
+  const TypeName =(const TypeName &) = delete;
+
+class TestClass3 {
+private:
+  // Notice, that the macro allows to be used without a semicolon because the
+  // macro definition already contains one above. Therefore our replacement must
+  // contain a semicolon at the end.
+  DISALLOW_COPY_AND_ASSIGN_FINALIZE(TestClass3)
+};
+// CHECK-MESSAGES-FINALIZE: :[[@LINE-2]]:3: warning: prefer deleting copy constructor and assignment operator over using macro 'DISALLOW_COPY_AND_ASSIGN_FINALIZE' [modernize-replace-disallow-copy-and-assign-macro]
+// CHECK-FIXES-FINALIZE:  {{^}}  TestClass3(const TestClass3 &) = delete;{{$}}
+// CHECK-FIXES-FINALIZE-NEXT: {{^}}  const TestClass3 =(const TestClass3 &) = delete;{{$}}
+
+#define DISALLOW_COPY_AND_ASSIGN_MORE_AGUMENTS(A, B)
+
+class TestClass4 {
+private:
+  DISALLOW_COPY_AND_ASSIGN_MORE_AGUMENTS(TestClass4, TestClass4);
+};
+// CHECK-MESSAGES-MORE-ARGUMENTS-NOT: warning: prefer deleting copy constructor and assignment operator over using macro 'DISALLOW_COPY_AND_ASSIGN_MORE_AGUMENTS'
+
+#define DISALLOW_COPY_AND_ASSIGN_NEEDS_PREEXPANSION(A)
+#define TESTCLASS TestClass5
+
+class TestClass5 {
+private:
+  DISALLOW_COPY_AND_ASSIGN_NEEDS_PREEXPANSION(TESTCLASS);
+};
+// 

[PATCH] D80531: [clang-tidy]: Added modernize-replace-disallow-copy-and-assign-macro

2020-06-02 Thread Konrad Wilhelm Kleine via Phabricator via cfe-commits
kwk added a comment.

In D80531#2069383 , @njames93 wrote:

> LGTM with 2 small nits, but I'd still give a few days see if anyone else 
> wants to weight in.


I'm okay with this but I'd like to understand when it's time to wait for 
others? Only when a patch is approved or from the beginning of patch's life? I 
mean who looks at patches that are approved unless you filter for the amount of 
approvers? How many approvers must there be?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D80531/new/

https://reviews.llvm.org/D80531



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D80531: [clang-tidy]: Added modernize-replace-disallow-copy-and-assign-macro

2020-06-02 Thread Konrad Wilhelm Kleine via Phabricator via cfe-commits
kwk added a comment.

Done.




Comment at: 
clang-tools-extra/clang-tidy/modernize/ReplaceDisallowCopyAndAssignMacroCheck.h:52
+
+  const std::string getMacroName() const { return MacroName; }
+

njames93 wrote:
> Return by reference here.
Yeah, that makes sense. Stupid me.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D80531/new/

https://reviews.llvm.org/D80531



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D80531: [clang-tidy]: Added modernize-replace-disallow-copy-and-assign-macro

2020-06-02 Thread Konrad Wilhelm Kleine via Phabricator via cfe-commits
kwk updated this revision to Diff 267960.
kwk marked 4 inline comments as done.
kwk added a comment.

- Return macro name by reference
- Add colon to paragraph showing code


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D80531/new/

https://reviews.llvm.org/D80531

Files:
  clang-tools-extra/clang-tidy/modernize/CMakeLists.txt
  clang-tools-extra/clang-tidy/modernize/ModernizeTidyModule.cpp
  
clang-tools-extra/clang-tidy/modernize/ReplaceDisallowCopyAndAssignMacroCheck.cpp
  
clang-tools-extra/clang-tidy/modernize/ReplaceDisallowCopyAndAssignMacroCheck.h
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  
clang-tools-extra/docs/clang-tidy/checks/modernize-replace-disallow-copy-and-assign-macro.rst
  
clang-tools-extra/test/clang-tidy/checkers/modernize-replace-disallow-copy-and-assign-macro.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/modernize-replace-disallow-copy-and-assign-macro.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/modernize-replace-disallow-copy-and-assign-macro.cpp
@@ -0,0 +1,79 @@
+// RUN: %check_clang_tidy -format-style=LLVM -check-suffix=DEFAULT %s \
+// RUN:   modernize-replace-disallow-copy-and-assign-macro %t
+
+// RUN: %check_clang_tidy -format-style=LLVM -check-suffix=DIFFERENT-NAME %s \
+// RUN:  modernize-replace-disallow-copy-and-assign-macro %t \
+// RUN:  -config="{CheckOptions: [ \
+// RUN:   {key: modernize-replace-disallow-copy-and-assign-macro.MacroName, \
+// RUN:value: MY_MACRO_NAME}]}"
+
+// RUN: %check_clang_tidy -format-style=LLVM -check-suffix=FINALIZE %s \
+// RUN:  modernize-replace-disallow-copy-and-assign-macro %t \
+// RUN:  -config="{CheckOptions: [ \
+// RUN:   {key: modernize-replace-disallow-copy-and-assign-macro.MacroName, \
+// RUN:value: DISALLOW_COPY_AND_ASSIGN_FINALIZE}]}"
+
+// RUN: clang-tidy %s -checks="-*,modernize-replace-disallow-copy-and-assign-macro" \
+// RUN:   -config="{CheckOptions: [ \
+// RUN:{key: modernize-replace-disallow-copy-and-assign-macro.MacroName, \
+// RUN: value: DISALLOW_COPY_AND_ASSIGN_MORE_AGUMENTS}]}" | count 0
+
+// RUN: clang-tidy %s -checks="-*,modernize-replace-disallow-copy-and-assign-macro" \
+// RUN:   -config="{CheckOptions: [ \
+// RUN:{key: modernize-replace-disallow-copy-and-assign-macro.MacroName, \
+// RUN: value: DISALLOW_COPY_AND_ASSIGN_NEEDS_PREEXPANSION}]}" | count 0
+
+// Note: the last two tests expect no diagnostics, but FileCheck cannot handle
+// that, hence the use of | count 0.
+
+#define DISALLOW_COPY_AND_ASSIGN(TypeName)
+
+class TestClass1 {
+private:
+  DISALLOW_COPY_AND_ASSIGN(TestClass1);
+};
+// CHECK-MESSAGES-DEFAULT: :[[@LINE-2]]:3: warning: prefer deleting copy constructor and assignment operator over using macro 'DISALLOW_COPY_AND_ASSIGN' [modernize-replace-disallow-copy-and-assign-macro]
+// CHECK-FIXES-DEFAULT:  {{^}}  TestClass1(const TestClass1 &) = delete;{{$}}
+// CHECK-FIXES-DEFAULT-NEXT: {{^}}  const TestClass1 =(const TestClass1 &) = delete;{{$}}
+
+#define MY_MACRO_NAME(TypeName)
+
+class TestClass2 {
+private:
+  MY_MACRO_NAME(TestClass2);
+};
+// CHECK-MESSAGES-DIFFERENT-NAME: :[[@LINE-2]]:3: warning: prefer deleting copy constructor and assignment operator over using macro 'MY_MACRO_NAME' [modernize-replace-disallow-copy-and-assign-macro]
+// CHECK-FIXES-DIFFERENT-NAME:  {{^}}  TestClass2(const TestClass2 &) = delete;{{$}}
+// CHECK-FIXES-DIFFERENT-NAME-NEXT: {{^}}  const TestClass2 =(const TestClass2 &) = delete;{{$}}
+
+#define DISALLOW_COPY_AND_ASSIGN_FINALIZE(TypeName) \
+  TypeName(const TypeName &) = delete;  \
+  const TypeName =(const TypeName &) = delete;
+
+class TestClass3 {
+private:
+  // Notice, that the macro allows to be used without a semicolon because the
+  // macro definition already contains one above. Therefore our replacement must
+  // contain a semicolon at the end.
+  DISALLOW_COPY_AND_ASSIGN_FINALIZE(TestClass3)
+};
+// CHECK-MESSAGES-FINALIZE: :[[@LINE-2]]:3: warning: prefer deleting copy constructor and assignment operator over using macro 'DISALLOW_COPY_AND_ASSIGN_FINALIZE' [modernize-replace-disallow-copy-and-assign-macro]
+// CHECK-FIXES-FINALIZE:  {{^}}  TestClass3(const TestClass3 &) = delete;{{$}}
+// CHECK-FIXES-FINALIZE-NEXT: {{^}}  const TestClass3 =(const TestClass3 &) = delete;{{$}}
+
+#define DISALLOW_COPY_AND_ASSIGN_MORE_AGUMENTS(A, B)
+
+class TestClass4 {
+private:
+  DISALLOW_COPY_AND_ASSIGN_MORE_AGUMENTS(TestClass4, TestClass4);
+};
+// CHECK-MESSAGES-MORE-ARGUMENTS-NOT: warning: prefer deleting copy constructor and assignment operator over using macro 'DISALLOW_COPY_AND_ASSIGN_MORE_AGUMENTS'
+
+#define DISALLOW_COPY_AND_ASSIGN_NEEDS_PREEXPANSION(A)
+#define TESTCLASS TestClass5
+
+class TestClass5 {
+private:
+  DISALLOW_COPY_AND_ASSIGN_NEEDS_PREEXPANSION(TESTCLASS);
+};
+// 

[PATCH] D80531: [clang-tidy]: Added modernize-replace-disallow-copy-and-assign-macro

2020-06-02 Thread Konrad Wilhelm Kleine via Phabricator via cfe-commits
kwk marked 4 inline comments as done.
kwk added a comment.

Marked more comments as "done" after going through the code again.




Comment at: 
clang-tools-extra/clang-tidy/modernize/ReplaceDisallowCopyAndAssignMacroCheck.cpp:49
+R"cpp({0}(const {0} &) = delete;
+const {0} =(const {0} &) = delete{1})cpp",
+classIdent->getNameStart(), shouldAppendSemi(Range) ? ";" : "");

kwk wrote:
> njames93 wrote:
> > if you wanted to, you could format this quite easily to avoid the need of 
> > specifying a formatter in the checks
> > ```{2}const {0} =(const {0} &) = delete{1})cpp",...
> > Lexer::getIndentationForLine(Range.getBegin(), SM))```
> Well, that does fix the indentation but for east/west-side alignment of `&` 
> this doesn't solve the problem, does it?
Well, yes but it will only work for the indentation not for anything else, like 
east/west alignment of `&` for example.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D80531/new/

https://reviews.llvm.org/D80531



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D80531: [clang-tidy]: Added modernize-replace-disallow-copy-and-assign-macro

2020-05-28 Thread Konrad Wilhelm Kleine via Phabricator via cfe-commits
kwk updated this revision to Diff 267021.
kwk marked 9 inline comments as done.
kwk added a comment.

- Don't store SourceManager but get it from Preprocessor
- Use getName instead of getNameStart
- Remove FIXME
- change warning message
- doxygen: \a -> \p
- Make MacroName private and add getter


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D80531/new/

https://reviews.llvm.org/D80531

Files:
  clang-tools-extra/clang-tidy/modernize/CMakeLists.txt
  clang-tools-extra/clang-tidy/modernize/ModernizeTidyModule.cpp
  
clang-tools-extra/clang-tidy/modernize/ReplaceDisallowCopyAndAssignMacroCheck.cpp
  
clang-tools-extra/clang-tidy/modernize/ReplaceDisallowCopyAndAssignMacroCheck.h
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  
clang-tools-extra/docs/clang-tidy/checks/modernize-replace-disallow-copy-and-assign-macro.rst
  
clang-tools-extra/test/clang-tidy/checkers/modernize-replace-disallow-copy-and-assign-macro.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/modernize-replace-disallow-copy-and-assign-macro.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/modernize-replace-disallow-copy-and-assign-macro.cpp
@@ -0,0 +1,79 @@
+// RUN: %check_clang_tidy -format-style=LLVM -check-suffix=DEFAULT %s \
+// RUN:   modernize-replace-disallow-copy-and-assign-macro %t
+
+// RUN: %check_clang_tidy -format-style=LLVM -check-suffix=DIFFERENT-NAME %s \
+// RUN:  modernize-replace-disallow-copy-and-assign-macro %t \
+// RUN:  -config="{CheckOptions: [ \
+// RUN:   {key: modernize-replace-disallow-copy-and-assign-macro.MacroName, \
+// RUN:value: MY_MACRO_NAME}]}"
+
+// RUN: %check_clang_tidy -format-style=LLVM -check-suffix=FINALIZE %s \
+// RUN:  modernize-replace-disallow-copy-and-assign-macro %t \
+// RUN:  -config="{CheckOptions: [ \
+// RUN:   {key: modernize-replace-disallow-copy-and-assign-macro.MacroName, \
+// RUN:value: DISALLOW_COPY_AND_ASSIGN_FINALIZE}]}"
+
+// RUN: clang-tidy %s -checks="-*,modernize-replace-disallow-copy-and-assign-macro" \
+// RUN:   -config="{CheckOptions: [ \
+// RUN:{key: modernize-replace-disallow-copy-and-assign-macro.MacroName, \
+// RUN: value: DISALLOW_COPY_AND_ASSIGN_MORE_AGUMENTS}]}" | count 0
+
+// RUN: clang-tidy %s -checks="-*,modernize-replace-disallow-copy-and-assign-macro" \
+// RUN:   -config="{CheckOptions: [ \
+// RUN:{key: modernize-replace-disallow-copy-and-assign-macro.MacroName, \
+// RUN: value: DISALLOW_COPY_AND_ASSIGN_NEEDS_PREEXPANSION}]}" | count 0
+
+// Note: the last two tests expect no diagnostics, but FileCheck cannot handle
+// that, hence the use of | count 0.
+
+#define DISALLOW_COPY_AND_ASSIGN(TypeName)
+
+class TestClass1 {
+private:
+  DISALLOW_COPY_AND_ASSIGN(TestClass1);
+};
+// CHECK-MESSAGES-DEFAULT: :[[@LINE-2]]:3: warning: prefer deleting copy constructor and assignment operator over using macro 'DISALLOW_COPY_AND_ASSIGN' [modernize-replace-disallow-copy-and-assign-macro]
+// CHECK-FIXES-DEFAULT:  {{^}}  TestClass1(const TestClass1 &) = delete;{{$}}
+// CHECK-FIXES-DEFAULT-NEXT: {{^}}  const TestClass1 =(const TestClass1 &) = delete;{{$}}
+
+#define MY_MACRO_NAME(TypeName)
+
+class TestClass2 {
+private:
+  MY_MACRO_NAME(TestClass2);
+};
+// CHECK-MESSAGES-DIFFERENT-NAME: :[[@LINE-2]]:3: warning: prefer deleting copy constructor and assignment operator over using macro 'MY_MACRO_NAME' [modernize-replace-disallow-copy-and-assign-macro]
+// CHECK-FIXES-DIFFERENT-NAME:  {{^}}  TestClass2(const TestClass2 &) = delete;{{$}}
+// CHECK-FIXES-DIFFERENT-NAME-NEXT: {{^}}  const TestClass2 =(const TestClass2 &) = delete;{{$}}
+
+#define DISALLOW_COPY_AND_ASSIGN_FINALIZE(TypeName) \
+  TypeName(const TypeName &) = delete;  \
+  const TypeName =(const TypeName &) = delete;
+
+class TestClass3 {
+private:
+  // Notice, that the macro allows to be used without a semicolon because the
+  // macro definition already contains one above. Therefore our replacement must
+  // contain a semicolon at the end.
+  DISALLOW_COPY_AND_ASSIGN_FINALIZE(TestClass3)
+};
+// CHECK-MESSAGES-FINALIZE: :[[@LINE-2]]:3: warning: prefer deleting copy constructor and assignment operator over using macro 'DISALLOW_COPY_AND_ASSIGN_FINALIZE' [modernize-replace-disallow-copy-and-assign-macro]
+// CHECK-FIXES-FINALIZE:  {{^}}  TestClass3(const TestClass3 &) = delete;{{$}}
+// CHECK-FIXES-FINALIZE-NEXT: {{^}}  const TestClass3 =(const TestClass3 &) = delete;{{$}}
+
+#define DISALLOW_COPY_AND_ASSIGN_MORE_AGUMENTS(A, B)
+
+class TestClass4 {
+private:
+  DISALLOW_COPY_AND_ASSIGN_MORE_AGUMENTS(TestClass4, TestClass4);
+};
+// CHECK-MESSAGES-MORE-ARGUMENTS-NOT: warning: prefer deleting copy constructor and assignment operator over using macro 'DISALLOW_COPY_AND_ASSIGN_MORE_AGUMENTS'
+
+#define DISALLOW_COPY_AND_ASSIGN_NEEDS_PREEXPANSION(A)
+#define TESTCLASS 

[PATCH] D80531: [clang-tidy]: Added modernize-replace-disallow-copy-and-assign-macro

2020-05-28 Thread Konrad Wilhelm Kleine via Phabricator via cfe-commits
kwk added a comment.

@njames93 I've addressed all your comments and hope the patch is good to land 
now :)




Comment at: 
clang-tools-extra/clang-tidy/modernize/ReplaceDisallowCopyAndAssignMacroCheck.cpp:25
+  const SourceManager )
+  : Check(Check), PP(PP), SM(SM) {}
+

njames93 wrote:
> nit: You don't need to store a reference to the `SourceManager` as the 
> `Preprocessor` holds a reference to it.
@njames93 thank you for letting me know. I passed it along because the 
´ClangTidyCheck::registerPPCallbacks` that I override actually accepts both, 
`SourceManager` and the `PP`:

```
lang=c++
virtual void registerPPCallbacks(const SourceManager , Preprocessor *PP,
   Preprocessor *ModuleExpanderPP) {}
```

Other checks like `MakeSmartPtrCheck`, `PassByValueCheck` also do this similar 
to mine. 

Anyway, I've changed the code to your liking. 



Comment at: 
clang-tools-extra/clang-tidy/modernize/ReplaceDisallowCopyAndAssignMacroCheck.h:52
+
+  const std::string MacroName;
+};

njames93 wrote:
> Make this private with a get function and I'll be happy. 
Done. But since the variable is `const` having it public shouldn't allow a 
caller do anything but read the macro name. But I understand that convention is 
king ;)


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D80531/new/

https://reviews.llvm.org/D80531



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D80531: [clang-tidy]: Added modernize-replace-disallow-copy-and-assign-macro

2020-05-28 Thread Konrad Wilhelm Kleine via Phabricator via cfe-commits
kwk added a comment.

@njames93 and @Eugene.Zelenko do you guys think this patch is ready to be 
approved and land?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D80531/new/

https://reviews.llvm.org/D80531



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D80531: [clang-tidy]: Added modernize-replace-disallow-copy-and-assign-macro

2020-05-27 Thread Konrad Wilhelm Kleine via Phabricator via cfe-commits
kwk updated this revision to Diff 266438.
kwk marked an inline comment as done.
kwk added a comment.

- fix link in doc


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D80531/new/

https://reviews.llvm.org/D80531

Files:
  clang-tools-extra/clang-tidy/modernize/CMakeLists.txt
  clang-tools-extra/clang-tidy/modernize/ModernizeTidyModule.cpp
  
clang-tools-extra/clang-tidy/modernize/ReplaceDisallowCopyAndAssignMacroCheck.cpp
  
clang-tools-extra/clang-tidy/modernize/ReplaceDisallowCopyAndAssignMacroCheck.h
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  
clang-tools-extra/docs/clang-tidy/checks/modernize-replace-disallow-copy-and-assign-macro.rst
  
clang-tools-extra/test/clang-tidy/checkers/modernize-replace-disallow-copy-and-assign-macro.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/modernize-replace-disallow-copy-and-assign-macro.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/modernize-replace-disallow-copy-and-assign-macro.cpp
@@ -0,0 +1,79 @@
+// RUN: %check_clang_tidy -format-style=LLVM -check-suffix=DEFAULT %s \
+// RUN:   modernize-replace-disallow-copy-and-assign-macro %t
+
+// RUN: %check_clang_tidy -format-style=LLVM -check-suffix=DIFFERENT-NAME %s \
+// RUN:  modernize-replace-disallow-copy-and-assign-macro %t \
+// RUN:  -config="{CheckOptions: [ \
+// RUN:   {key: modernize-replace-disallow-copy-and-assign-macro.MacroName, \
+// RUN:value: MY_MACRO_NAME}]}"
+
+// RUN: %check_clang_tidy -format-style=LLVM -check-suffix=FINALIZE %s \
+// RUN:  modernize-replace-disallow-copy-and-assign-macro %t \
+// RUN:  -config="{CheckOptions: [ \
+// RUN:   {key: modernize-replace-disallow-copy-and-assign-macro.MacroName, \
+// RUN:value: DISALLOW_COPY_AND_ASSIGN_FINALIZE}]}"
+
+// RUN: clang-tidy %s -checks="-*,modernize-replace-disallow-copy-and-assign-macro" \
+// RUN:   -config="{CheckOptions: [ \
+// RUN:{key: modernize-replace-disallow-copy-and-assign-macro.MacroName, \
+// RUN: value: DISALLOW_COPY_AND_ASSIGN_MORE_AGUMENTS}]}" | count 0
+
+// RUN: clang-tidy %s -checks="-*,modernize-replace-disallow-copy-and-assign-macro" \
+// RUN:   -config="{CheckOptions: [ \
+// RUN:{key: modernize-replace-disallow-copy-and-assign-macro.MacroName, \
+// RUN: value: DISALLOW_COPY_AND_ASSIGN_NEEDS_PREEXPANSION}]}" | count 0
+
+// Note: the last two tests expect no diagnostics, but FileCheck cannot handle
+// that, hence the use of | count 0.
+
+#define DISALLOW_COPY_AND_ASSIGN(TypeName)
+
+class TestClass1 {
+private:
+  DISALLOW_COPY_AND_ASSIGN(TestClass1);
+};
+// CHECK-MESSAGES-DEFAULT: :[[@LINE-2]]:3: warning: using copy and assign macro 'DISALLOW_COPY_AND_ASSIGN' [modernize-replace-disallow-copy-and-assign-macro]
+// CHECK-FIXES-DEFAULT:  {{^}}  TestClass1(const TestClass1 &) = delete;{{$}}
+// CHECK-FIXES-DEFAULT-NEXT: {{^}}  const TestClass1 =(const TestClass1 &) = delete;{{$}}
+
+#define MY_MACRO_NAME(TypeName)
+
+class TestClass2 {
+private:
+  MY_MACRO_NAME(TestClass2);
+};
+// CHECK-MESSAGES-DIFFERENT-NAME: :[[@LINE-2]]:3: warning: using copy and assign macro 'MY_MACRO_NAME' [modernize-replace-disallow-copy-and-assign-macro]
+// CHECK-FIXES-DIFFERENT-NAME:  {{^}}  TestClass2(const TestClass2 &) = delete;{{$}}
+// CHECK-FIXES-DIFFERENT-NAME-NEXT: {{^}}  const TestClass2 =(const TestClass2 &) = delete;{{$}}
+
+#define DISALLOW_COPY_AND_ASSIGN_FINALIZE(TypeName) \
+  TypeName(const TypeName &) = delete;  \
+  const TypeName =(const TypeName &) = delete;
+
+class TestClass3 {
+private:
+  // Notice, that the macro allows to be used without a semicolon because the
+  // macro definition already contains one above. Therefore our replacement must
+  // contain a semicolon at the end.
+  DISALLOW_COPY_AND_ASSIGN_FINALIZE(TestClass3)
+};
+// CHECK-MESSAGES-FINALIZE: :[[@LINE-2]]:3: warning: using copy and assign macro 'DISALLOW_COPY_AND_ASSIGN_FINALIZE' [modernize-replace-disallow-copy-and-assign-macro]
+// CHECK-FIXES-FINALIZE:  {{^}}  TestClass3(const TestClass3 &) = delete;{{$}}
+// CHECK-FIXES-FINALIZE-NEXT: {{^}}  const TestClass3 =(const TestClass3 &) = delete;{{$}}
+
+#define DISALLOW_COPY_AND_ASSIGN_MORE_AGUMENTS(A, B)
+
+class TestClass4 {
+private:
+  DISALLOW_COPY_AND_ASSIGN_MORE_AGUMENTS(TestClass4, TestClass4);
+};
+// CHECK-MESSAGES-MORE-ARGUMENTS-NOT: warning: using copy and assign macro 'DISALLOW_COPY_AND_ASSIGN_MORE_AGUMENTS'
+
+#define DISALLOW_COPY_AND_ASSIGN_NEEDS_PREEXPANSION(A)
+#define TESTCLASS TestClass5
+
+class TestClass5 {
+private:
+  DISALLOW_COPY_AND_ASSIGN_NEEDS_PREEXPANSION(TESTCLASS);
+};
+// CHECK-MESSAGES-MORE-ARGUMENTS-NOT: warning: using copy and assign macro 'DISALLOW_COPY_AND_ASSIGN_NEEDS_PREEXPANSION'
Index: clang-tools-extra/docs/clang-tidy/checks/modernize-replace-disallow-copy-and-assign-macro.rst

[PATCH] D80531: [clang-tidy]: Added modernize-replace-disallow-copy-and-assign-macro

2020-05-27 Thread Konrad Wilhelm Kleine via Phabricator via cfe-commits
kwk added a comment.

@Eugene.Zelenko thank you for your patience with me. I fixed the link.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D80531/new/

https://reviews.llvm.org/D80531



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D80531: [clang-tidy]: Added modernize-replace-disallow-copy-and-assign-macro

2020-05-26 Thread Konrad Wilhelm Kleine via Phabricator via cfe-commits
kwk updated this revision to Diff 266268.
kwk added a comment.

- Adjust link to documentation


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D80531/new/

https://reviews.llvm.org/D80531

Files:
  clang-tools-extra/clang-tidy/modernize/CMakeLists.txt
  clang-tools-extra/clang-tidy/modernize/ModernizeTidyModule.cpp
  
clang-tools-extra/clang-tidy/modernize/ReplaceDisallowCopyAndAssignMacroCheck.cpp
  
clang-tools-extra/clang-tidy/modernize/ReplaceDisallowCopyAndAssignMacroCheck.h
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  
clang-tools-extra/docs/clang-tidy/checks/modernize-replace-disallow-copy-and-assign-macro.rst
  
clang-tools-extra/test/clang-tidy/checkers/modernize-replace-disallow-copy-and-assign-macro.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/modernize-replace-disallow-copy-and-assign-macro.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/modernize-replace-disallow-copy-and-assign-macro.cpp
@@ -0,0 +1,79 @@
+// RUN: %check_clang_tidy -format-style=LLVM -check-suffix=DEFAULT %s \
+// RUN:   modernize-replace-disallow-copy-and-assign-macro %t
+
+// RUN: %check_clang_tidy -format-style=LLVM -check-suffix=DIFFERENT-NAME %s \
+// RUN:  modernize-replace-disallow-copy-and-assign-macro %t \
+// RUN:  -config="{CheckOptions: [ \
+// RUN:   {key: modernize-replace-disallow-copy-and-assign-macro.MacroName, \
+// RUN:value: MY_MACRO_NAME}]}"
+
+// RUN: %check_clang_tidy -format-style=LLVM -check-suffix=FINALIZE %s \
+// RUN:  modernize-replace-disallow-copy-and-assign-macro %t \
+// RUN:  -config="{CheckOptions: [ \
+// RUN:   {key: modernize-replace-disallow-copy-and-assign-macro.MacroName, \
+// RUN:value: DISALLOW_COPY_AND_ASSIGN_FINALIZE}]}"
+
+// RUN: clang-tidy %s -checks="-*,modernize-replace-disallow-copy-and-assign-macro" \
+// RUN:   -config="{CheckOptions: [ \
+// RUN:{key: modernize-replace-disallow-copy-and-assign-macro.MacroName, \
+// RUN: value: DISALLOW_COPY_AND_ASSIGN_MORE_AGUMENTS}]}" | count 0
+
+// RUN: clang-tidy %s -checks="-*,modernize-replace-disallow-copy-and-assign-macro" \
+// RUN:   -config="{CheckOptions: [ \
+// RUN:{key: modernize-replace-disallow-copy-and-assign-macro.MacroName, \
+// RUN: value: DISALLOW_COPY_AND_ASSIGN_NEEDS_PREEXPANSION}]}" | count 0
+
+// Note: the last two tests expect no diagnostics, but FileCheck cannot handle
+// that, hence the use of | count 0.
+
+#define DISALLOW_COPY_AND_ASSIGN(TypeName)
+
+class TestClass1 {
+private:
+  DISALLOW_COPY_AND_ASSIGN(TestClass1);
+};
+// CHECK-MESSAGES-DEFAULT: :[[@LINE-2]]:3: warning: using copy and assign macro 'DISALLOW_COPY_AND_ASSIGN' [modernize-replace-disallow-copy-and-assign-macro]
+// CHECK-FIXES-DEFAULT:  {{^}}  TestClass1(const TestClass1 &) = delete;{{$}}
+// CHECK-FIXES-DEFAULT-NEXT: {{^}}  const TestClass1 =(const TestClass1 &) = delete;{{$}}
+
+#define MY_MACRO_NAME(TypeName)
+
+class TestClass2 {
+private:
+  MY_MACRO_NAME(TestClass2);
+};
+// CHECK-MESSAGES-DIFFERENT-NAME: :[[@LINE-2]]:3: warning: using copy and assign macro 'MY_MACRO_NAME' [modernize-replace-disallow-copy-and-assign-macro]
+// CHECK-FIXES-DIFFERENT-NAME:  {{^}}  TestClass2(const TestClass2 &) = delete;{{$}}
+// CHECK-FIXES-DIFFERENT-NAME-NEXT: {{^}}  const TestClass2 =(const TestClass2 &) = delete;{{$}}
+
+#define DISALLOW_COPY_AND_ASSIGN_FINALIZE(TypeName) \
+  TypeName(const TypeName &) = delete;  \
+  const TypeName =(const TypeName &) = delete;
+
+class TestClass3 {
+private:
+  // Notice, that the macro allows to be used without a semicolon because the
+  // macro definition already contains one above. Therefore our replacement must
+  // contain a semicolon at the end.
+  DISALLOW_COPY_AND_ASSIGN_FINALIZE(TestClass3)
+};
+// CHECK-MESSAGES-FINALIZE: :[[@LINE-2]]:3: warning: using copy and assign macro 'DISALLOW_COPY_AND_ASSIGN_FINALIZE' [modernize-replace-disallow-copy-and-assign-macro]
+// CHECK-FIXES-FINALIZE:  {{^}}  TestClass3(const TestClass3 &) = delete;{{$}}
+// CHECK-FIXES-FINALIZE-NEXT: {{^}}  const TestClass3 =(const TestClass3 &) = delete;{{$}}
+
+#define DISALLOW_COPY_AND_ASSIGN_MORE_AGUMENTS(A, B)
+
+class TestClass4 {
+private:
+  DISALLOW_COPY_AND_ASSIGN_MORE_AGUMENTS(TestClass4, TestClass4);
+};
+// CHECK-MESSAGES-MORE-ARGUMENTS-NOT: warning: using copy and assign macro 'DISALLOW_COPY_AND_ASSIGN_MORE_AGUMENTS'
+
+#define DISALLOW_COPY_AND_ASSIGN_NEEDS_PREEXPANSION(A)
+#define TESTCLASS TestClass5
+
+class TestClass5 {
+private:
+  DISALLOW_COPY_AND_ASSIGN_NEEDS_PREEXPANSION(TESTCLASS);
+};
+// CHECK-MESSAGES-MORE-ARGUMENTS-NOT: warning: using copy and assign macro 'DISALLOW_COPY_AND_ASSIGN_NEEDS_PREEXPANSION'
Index: clang-tools-extra/docs/clang-tidy/checks/modernize-replace-disallow-copy-and-assign-macro.rst

[PATCH] D80531: [clang-tidy]: Added modernize-replace-disallow-copy-and-assign-macro

2020-05-26 Thread Konrad Wilhelm Kleine via Phabricator via cfe-commits
kwk marked an inline comment as done.
kwk added inline comments.



Comment at: 
clang-tools-extra/docs/clang-tidy/checks/modernize-replace-disallow-copy-and-assign-macro.rst:41
+  specification untouched. You might want to run the check
+  `modernize-use-equals-delete `_ to get
+  warnings for deleted functions in private sections.

Eugene.Zelenko wrote:
> See Release Notes on how to create links on documentation.
I did look at another test 
(https://raw.githubusercontent.com/llvm/llvm-project/master/clang-tools-extra/docs/clang-tidy/checks/readability-convert-member-functions-to-static.rst)
 and copied from there. But I will now change it.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D80531/new/

https://reviews.llvm.org/D80531



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D80531: [clang-tidy]: Added modernize-replace-disallow-copy-and-assign-macro

2020-05-26 Thread Konrad Wilhelm Kleine via Phabricator via cfe-commits
kwk marked 2 inline comments as done.
kwk added inline comments.



Comment at: 
clang-tools-extra/docs/clang-tidy/checks/modernize-replace-disallow-copy-and-assign-macro.rst:41
+  specification untouched. You might want to run the check
+  `modernize-use-equals-delete `_ to get
+  warnings for deleted functions in private sections.

kwk wrote:
> Eugene.Zelenko wrote:
> > See Release Notes on how to create links on documentation.
> I did look at another test 
> (https://raw.githubusercontent.com/llvm/llvm-project/master/clang-tools-extra/docs/clang-tidy/checks/readability-convert-member-functions-to-static.rst)
>  and copied from there. But I will now change it.
@Eugene.Zelenko Done.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D80531/new/

https://reviews.llvm.org/D80531



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D80531: [clang-tidy]: Added modernize-replace-disallow-copy-and-assign-macro

2020-05-26 Thread Konrad Wilhelm Kleine via Phabricator via cfe-commits
kwk updated this revision to Diff 266257.
kwk marked 2 inline comments as done.
kwk added a comment.

- Refer to modernize-use-equals-delete for warning about deleted functions in 
private sections


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D80531/new/

https://reviews.llvm.org/D80531

Files:
  clang-tools-extra/clang-tidy/modernize/CMakeLists.txt
  clang-tools-extra/clang-tidy/modernize/ModernizeTidyModule.cpp
  
clang-tools-extra/clang-tidy/modernize/ReplaceDisallowCopyAndAssignMacroCheck.cpp
  
clang-tools-extra/clang-tidy/modernize/ReplaceDisallowCopyAndAssignMacroCheck.h
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  
clang-tools-extra/docs/clang-tidy/checks/modernize-replace-disallow-copy-and-assign-macro.rst
  
clang-tools-extra/test/clang-tidy/checkers/modernize-replace-disallow-copy-and-assign-macro.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/modernize-replace-disallow-copy-and-assign-macro.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/modernize-replace-disallow-copy-and-assign-macro.cpp
@@ -0,0 +1,79 @@
+// RUN: %check_clang_tidy -format-style=LLVM -check-suffix=DEFAULT %s \
+// RUN:   modernize-replace-disallow-copy-and-assign-macro %t
+
+// RUN: %check_clang_tidy -format-style=LLVM -check-suffix=DIFFERENT-NAME %s \
+// RUN:  modernize-replace-disallow-copy-and-assign-macro %t \
+// RUN:  -config="{CheckOptions: [ \
+// RUN:   {key: modernize-replace-disallow-copy-and-assign-macro.MacroName, \
+// RUN:value: MY_MACRO_NAME}]}"
+
+// RUN: %check_clang_tidy -format-style=LLVM -check-suffix=FINALIZE %s \
+// RUN:  modernize-replace-disallow-copy-and-assign-macro %t \
+// RUN:  -config="{CheckOptions: [ \
+// RUN:   {key: modernize-replace-disallow-copy-and-assign-macro.MacroName, \
+// RUN:value: DISALLOW_COPY_AND_ASSIGN_FINALIZE}]}"
+
+// RUN: clang-tidy %s -checks="-*,modernize-replace-disallow-copy-and-assign-macro" \
+// RUN:   -config="{CheckOptions: [ \
+// RUN:{key: modernize-replace-disallow-copy-and-assign-macro.MacroName, \
+// RUN: value: DISALLOW_COPY_AND_ASSIGN_MORE_AGUMENTS}]}" | count 0
+
+// RUN: clang-tidy %s -checks="-*,modernize-replace-disallow-copy-and-assign-macro" \
+// RUN:   -config="{CheckOptions: [ \
+// RUN:{key: modernize-replace-disallow-copy-and-assign-macro.MacroName, \
+// RUN: value: DISALLOW_COPY_AND_ASSIGN_NEEDS_PREEXPANSION}]}" | count 0
+
+// Note: the last two tests expect no diagnostics, but FileCheck cannot handle
+// that, hence the use of | count 0.
+
+#define DISALLOW_COPY_AND_ASSIGN(TypeName)
+
+class TestClass1 {
+private:
+  DISALLOW_COPY_AND_ASSIGN(TestClass1);
+};
+// CHECK-MESSAGES-DEFAULT: :[[@LINE-2]]:3: warning: using copy and assign macro 'DISALLOW_COPY_AND_ASSIGN' [modernize-replace-disallow-copy-and-assign-macro]
+// CHECK-FIXES-DEFAULT:  {{^}}  TestClass1(const TestClass1 &) = delete;{{$}}
+// CHECK-FIXES-DEFAULT-NEXT: {{^}}  const TestClass1 =(const TestClass1 &) = delete;{{$}}
+
+#define MY_MACRO_NAME(TypeName)
+
+class TestClass2 {
+private:
+  MY_MACRO_NAME(TestClass2);
+};
+// CHECK-MESSAGES-DIFFERENT-NAME: :[[@LINE-2]]:3: warning: using copy and assign macro 'MY_MACRO_NAME' [modernize-replace-disallow-copy-and-assign-macro]
+// CHECK-FIXES-DIFFERENT-NAME:  {{^}}  TestClass2(const TestClass2 &) = delete;{{$}}
+// CHECK-FIXES-DIFFERENT-NAME-NEXT: {{^}}  const TestClass2 =(const TestClass2 &) = delete;{{$}}
+
+#define DISALLOW_COPY_AND_ASSIGN_FINALIZE(TypeName) \
+  TypeName(const TypeName &) = delete;  \
+  const TypeName =(const TypeName &) = delete;
+
+class TestClass3 {
+private:
+  // Notice, that the macro allows to be used without a semicolon because the
+  // macro definition already contains one above. Therefore our replacement must
+  // contain a semicolon at the end.
+  DISALLOW_COPY_AND_ASSIGN_FINALIZE(TestClass3)
+};
+// CHECK-MESSAGES-FINALIZE: :[[@LINE-2]]:3: warning: using copy and assign macro 'DISALLOW_COPY_AND_ASSIGN_FINALIZE' [modernize-replace-disallow-copy-and-assign-macro]
+// CHECK-FIXES-FINALIZE:  {{^}}  TestClass3(const TestClass3 &) = delete;{{$}}
+// CHECK-FIXES-FINALIZE-NEXT: {{^}}  const TestClass3 =(const TestClass3 &) = delete;{{$}}
+
+#define DISALLOW_COPY_AND_ASSIGN_MORE_AGUMENTS(A, B)
+
+class TestClass4 {
+private:
+  DISALLOW_COPY_AND_ASSIGN_MORE_AGUMENTS(TestClass4, TestClass4);
+};
+// CHECK-MESSAGES-MORE-ARGUMENTS-NOT: warning: using copy and assign macro 'DISALLOW_COPY_AND_ASSIGN_MORE_AGUMENTS'
+
+#define DISALLOW_COPY_AND_ASSIGN_NEEDS_PREEXPANSION(A)
+#define TESTCLASS TestClass5
+
+class TestClass5 {
+private:
+  DISALLOW_COPY_AND_ASSIGN_NEEDS_PREEXPANSION(TESTCLASS);
+};
+// CHECK-MESSAGES-MORE-ARGUMENTS-NOT: warning: using copy and assign macro 'DISALLOW_COPY_AND_ASSIGN_NEEDS_PREEXPANSION'
Index: 

[PATCH] D80531: [clang-tidy]: Added modernize-replace-disallow-copy-and-assign-macro

2020-05-26 Thread Konrad Wilhelm Kleine via Phabricator via cfe-commits
kwk added inline comments.



Comment at: 
clang-tools-extra/docs/clang-tidy/checks/modernize-replace-disallow-copy-and-assign-macro.rst:31
+* Notice that the migration example above leaves the ``private`` access
+  specification untouched. This opens room for improvement, yes I know.
+

Eugene.Zelenko wrote:
> kwk wrote:
> > Eugene.Zelenko wrote:
> > > Please refer to //modernize-use-equals-delete// instead of second 
> > > statement.
> > `modernize-use-equals-delete` doesn't help because it also does not remove 
> > the `private` access. Why refer to it?
> It complaines about deleted stuff in private section.
Agreed, that makes sense. Sorry for not getting that right away. Afterall I did 
write about that above :)

> Yes modernize-use-equals-delete does, this but it only notifies about it.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D80531/new/

https://reviews.llvm.org/D80531



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D80531: [clang-tidy]: Added modernize-replace-disallow-copy-and-assign-macro

2020-05-26 Thread Konrad Wilhelm Kleine via Phabricator via cfe-commits
kwk added a comment.

Thanks @njames93 and @Eugene.Zelenko for your review. Most of it, I addressed 
but for some I have comments. See inline.




Comment at: 
clang-tools-extra/clang-tidy/modernize/ReplaceDisallowCopyAndAssignMacroCheck.cpp:36
+// be the class name.
+const Token *classNameTok = Args->getUnexpArgument(0);
+if (Args->ArgNeedsPreexpansion(classNameTok, PP))

njames93 wrote:
> s/classNameTok/ClassNameTok
Ah, forgot about the CamelCase. Sorry.



Comment at: 
clang-tools-extra/clang-tidy/modernize/ReplaceDisallowCopyAndAssignMacroCheck.cpp:49
+R"cpp({0}(const {0} &) = delete;
+const {0} =(const {0} &) = delete{1})cpp",
+classIdent->getNameStart(), shouldAppendSemi(Range) ? ";" : "");

njames93 wrote:
> if you wanted to, you could format this quite easily to avoid the need of 
> specifying a formatter in the checks
> ```{2}const {0} =(const {0} &) = delete{1})cpp",...
> Lexer::getIndentationForLine(Range.getBegin(), SM))```
Well, that does fix the indentation but for east/west-side alignment of `&` 
this doesn't solve the problem, does it?



Comment at: 
clang-tools-extra/docs/clang-tidy/checks/modernize-replace-disallow-copy-and-assign-macro.rst:31
+* Notice that the migration example above leaves the ``private`` access
+  specification untouched. This opens room for improvement, yes I know.
+

Eugene.Zelenko wrote:
> Please refer to //modernize-use-equals-delete// instead of second statement.
`modernize-use-equals-delete` doesn't help because it also does not remove the 
`private` access. Why refer to it?



Comment at: 
clang-tools-extra/test/clang-tidy/checkers/modernize-replace-disallow-copy-and-assign-macro.cpp:36-38
+// CHECK-MESSAGES-NEXT-DEFAULT: {{^}}  
DISALLOW_COPY_AND_ASSIGN(TestClass1);{{$}}
+// CHECK-MESSAGES-NEXT-DEFAULT: {{^}}  ^{{$}}
+// CHECK-MESSAGES-NEXT-DEFAULT: {{^}}  TestClass1(const TestClass1 &) = 
delete;const TestClass1 =(const TestClass1 &) = delete{{$}}

njames93 wrote:
> These really aren't important to test for, so long as the diagnostic and fix 
> it are checked, that's all you need to worry about. Like how you have it for 
> `TestClass2`
Sure, I get that. I think I left them in because I wasn't that familiar with 
how `%check_clang_tidy` calls `FileCheck` two times. Thanks for catching this. 
Removed.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D80531/new/

https://reviews.llvm.org/D80531



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D80531: [clang-tidy]: Added modernize-replace-disallow-copy-and-assign-macro

2020-05-26 Thread Konrad Wilhelm Kleine via Phabricator via cfe-commits
kwk updated this revision to Diff 266251.
kwk marked 11 inline comments as done.
kwk added a comment.

- Avoid  constructing string
- CamelCase for vars
- more readable snippets for documentation
- Added empty line after header in documentation
- Remove sentence from doc
- Remove unimportant tests


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D80531/new/

https://reviews.llvm.org/D80531

Files:
  clang-tools-extra/clang-tidy/modernize/CMakeLists.txt
  clang-tools-extra/clang-tidy/modernize/ModernizeTidyModule.cpp
  
clang-tools-extra/clang-tidy/modernize/ReplaceDisallowCopyAndAssignMacroCheck.cpp
  
clang-tools-extra/clang-tidy/modernize/ReplaceDisallowCopyAndAssignMacroCheck.h
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  
clang-tools-extra/docs/clang-tidy/checks/modernize-replace-disallow-copy-and-assign-macro.rst
  
clang-tools-extra/test/clang-tidy/checkers/modernize-replace-disallow-copy-and-assign-macro.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/modernize-replace-disallow-copy-and-assign-macro.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/modernize-replace-disallow-copy-and-assign-macro.cpp
@@ -0,0 +1,79 @@
+// RUN: %check_clang_tidy -format-style=LLVM -check-suffix=DEFAULT %s \
+// RUN:   modernize-replace-disallow-copy-and-assign-macro %t
+
+// RUN: %check_clang_tidy -format-style=LLVM -check-suffix=DIFFERENT-NAME %s \
+// RUN:  modernize-replace-disallow-copy-and-assign-macro %t \
+// RUN:  -config="{CheckOptions: [ \
+// RUN:   {key: modernize-replace-disallow-copy-and-assign-macro.MacroName, \
+// RUN:value: MY_MACRO_NAME}]}"
+
+// RUN: %check_clang_tidy -format-style=LLVM -check-suffix=FINALIZE %s \
+// RUN:  modernize-replace-disallow-copy-and-assign-macro %t \
+// RUN:  -config="{CheckOptions: [ \
+// RUN:   {key: modernize-replace-disallow-copy-and-assign-macro.MacroName, \
+// RUN:value: DISALLOW_COPY_AND_ASSIGN_FINALIZE}]}"
+
+// RUN: clang-tidy %s -checks="-*,modernize-replace-disallow-copy-and-assign-macro" \
+// RUN:   -config="{CheckOptions: [ \
+// RUN:{key: modernize-replace-disallow-copy-and-assign-macro.MacroName, \
+// RUN: value: DISALLOW_COPY_AND_ASSIGN_MORE_AGUMENTS}]}" | count 0
+
+// RUN: clang-tidy %s -checks="-*,modernize-replace-disallow-copy-and-assign-macro" \
+// RUN:   -config="{CheckOptions: [ \
+// RUN:{key: modernize-replace-disallow-copy-and-assign-macro.MacroName, \
+// RUN: value: DISALLOW_COPY_AND_ASSIGN_NEEDS_PREEXPANSION}]}" | count 0
+
+// Note: the last two tests expect no diagnostics, but FileCheck cannot handle
+// that, hence the use of | count 0.
+
+#define DISALLOW_COPY_AND_ASSIGN(TypeName)
+
+class TestClass1 {
+private:
+  DISALLOW_COPY_AND_ASSIGN(TestClass1);
+};
+// CHECK-MESSAGES-DEFAULT: :[[@LINE-2]]:3: warning: using copy and assign macro 'DISALLOW_COPY_AND_ASSIGN' [modernize-replace-disallow-copy-and-assign-macro]
+// CHECK-FIXES-DEFAULT:  {{^}}  TestClass1(const TestClass1 &) = delete;{{$}}
+// CHECK-FIXES-DEFAULT-NEXT: {{^}}  const TestClass1 =(const TestClass1 &) = delete;{{$}}
+
+#define MY_MACRO_NAME(TypeName)
+
+class TestClass2 {
+private:
+  MY_MACRO_NAME(TestClass2);
+};
+// CHECK-MESSAGES-DIFFERENT-NAME: :[[@LINE-2]]:3: warning: using copy and assign macro 'MY_MACRO_NAME' [modernize-replace-disallow-copy-and-assign-macro]
+// CHECK-FIXES-DIFFERENT-NAME:  {{^}}  TestClass2(const TestClass2 &) = delete;{{$}}
+// CHECK-FIXES-DIFFERENT-NAME-NEXT: {{^}}  const TestClass2 =(const TestClass2 &) = delete;{{$}}
+
+#define DISALLOW_COPY_AND_ASSIGN_FINALIZE(TypeName) \
+  TypeName(const TypeName &) = delete;  \
+  const TypeName =(const TypeName &) = delete;
+
+class TestClass3 {
+private:
+  // Notice, that the macro allows to be used without a semicolon because the
+  // macro definition already contains one above. Therefore our replacement must
+  // contain a semicolon at the end.
+  DISALLOW_COPY_AND_ASSIGN_FINALIZE(TestClass3)
+};
+// CHECK-MESSAGES-FINALIZE: :[[@LINE-2]]:3: warning: using copy and assign macro 'DISALLOW_COPY_AND_ASSIGN_FINALIZE' [modernize-replace-disallow-copy-and-assign-macro]
+// CHECK-FIXES-FINALIZE:  {{^}}  TestClass3(const TestClass3 &) = delete;{{$}}
+// CHECK-FIXES-FINALIZE-NEXT: {{^}}  const TestClass3 =(const TestClass3 &) = delete;{{$}}
+
+#define DISALLOW_COPY_AND_ASSIGN_MORE_AGUMENTS(A, B)
+
+class TestClass4 {
+private:
+  DISALLOW_COPY_AND_ASSIGN_MORE_AGUMENTS(TestClass4, TestClass4);
+};
+// CHECK-MESSAGES-MORE-ARGUMENTS-NOT: warning: using copy and assign macro 'DISALLOW_COPY_AND_ASSIGN_MORE_AGUMENTS'
+
+#define DISALLOW_COPY_AND_ASSIGN_NEEDS_PREEXPANSION(A)
+#define TESTCLASS TestClass5
+
+class TestClass5 {
+private:
+  DISALLOW_COPY_AND_ASSIGN_NEEDS_PREEXPANSION(TESTCLASS);
+};
+// CHECK-MESSAGES-MORE-ARGUMENTS-NOT: warning: using copy and assign macro 

[PATCH] D80531: [clang-tidy]: Added modernize-replace-disallow-copy-and-assign-macro

2020-05-26 Thread Konrad Wilhelm Kleine via Phabricator via cfe-commits
kwk marked 2 inline comments as done.
kwk added a comment.

@njames93 I've implemented everything you've mentioned. This simplified a lot.




Comment at: 
clang-tools-extra/docs/clang-tidy/checks/modernize-replace-disallow-copy-and-assign-macro.rst:41
+
+.. option:: FinalizeWithSemicolon
+

njames93 wrote:
> This option should be removed and instead infer the value dynamically by 
> checking the token directly after the macro use to see if its a semi-colon.
> 
> Something like this in the PPCallback should get you there
> ```
>   bool shouldAppendSemi(SourceRange MacroLoc) {
> llvm::Optional Next =
> Lexer::findNextToken(MacroLoc.getEnd(), SM, PP.getLangOpts());
> return !(Next && Next->is(tok::semi));
>   }```
Thank you so much for this!


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D80531/new/

https://reviews.llvm.org/D80531



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D80531: [clang-tidy]: Added modernize-replace-disallow-copy-and-assign-macro

2020-05-26 Thread Konrad Wilhelm Kleine via Phabricator via cfe-commits
kwk updated this revision to Diff 266148.
kwk marked 4 inline comments as done.
kwk added a comment.

- Wrap RUN lines
- Use CamelCase variable name
- Simplify access to options
- Make check options const
- Use two-line placeholder
- Automate placement of semicolon at the end


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D80531/new/

https://reviews.llvm.org/D80531

Files:
  clang-tools-extra/clang-tidy/modernize/CMakeLists.txt
  clang-tools-extra/clang-tidy/modernize/ModernizeTidyModule.cpp
  
clang-tools-extra/clang-tidy/modernize/ReplaceDisallowCopyAndAssignMacroCheck.cpp
  
clang-tools-extra/clang-tidy/modernize/ReplaceDisallowCopyAndAssignMacroCheck.h
  clang-tools-extra/docs/ReleaseNotes.rst
  clang-tools-extra/docs/clang-tidy/checks/list.rst
  
clang-tools-extra/docs/clang-tidy/checks/modernize-replace-disallow-copy-and-assign-macro.rst
  
clang-tools-extra/test/clang-tidy/checkers/modernize-replace-disallow-copy-and-assign-macro.cpp

Index: clang-tools-extra/test/clang-tidy/checkers/modernize-replace-disallow-copy-and-assign-macro.cpp
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/checkers/modernize-replace-disallow-copy-and-assign-macro.cpp
@@ -0,0 +1,82 @@
+// RUN: %check_clang_tidy -format-style=LLVM -check-suffix=DEFAULT %s \
+// RUN:   modernize-replace-disallow-copy-and-assign-macro %t
+
+// RUN: %check_clang_tidy -format-style=LLVM -check-suffix=DIFFERENT-NAME %s \
+// RUN:  modernize-replace-disallow-copy-and-assign-macro %t \
+// RUN:  -config="{CheckOptions: [ \
+// RUN:   {key: modernize-replace-disallow-copy-and-assign-macro.MacroName, \
+// RUN:value: MY_MACRO_NAME}]}"
+
+// RUN: %check_clang_tidy -format-style=LLVM -check-suffix=FINALIZE %s \
+// RUN:  modernize-replace-disallow-copy-and-assign-macro %t \
+// RUN:  -config="{CheckOptions: [ \
+// RUN:   {key: modernize-replace-disallow-copy-and-assign-macro.MacroName, \
+// RUN:value: DISALLOW_COPY_AND_ASSIGN_FINALIZE}]}"
+
+// RUN: clang-tidy %s -checks="-*,modernize-replace-disallow-copy-and-assign-macro" \
+// RUN:   -config="{CheckOptions: [ \
+// RUN:{key: modernize-replace-disallow-copy-and-assign-macro.MacroName, \
+// RUN: value: DISALLOW_COPY_AND_ASSIGN_MORE_AGUMENTS}]}" | count 0
+
+// RUN: clang-tidy %s -checks="-*,modernize-replace-disallow-copy-and-assign-macro" \
+// RUN:   -config="{CheckOptions: [ \
+// RUN:{key: modernize-replace-disallow-copy-and-assign-macro.MacroName, \
+// RUN: value: DISALLOW_COPY_AND_ASSIGN_NEEDS_PREEXPANSION}]}" | count 0
+
+// Note: the last two tests expect no diagnostics, but FileCheck cannot handle
+// that, hence the use of | count 0.
+
+#define DISALLOW_COPY_AND_ASSIGN(TypeName)
+
+class TestClass1 {
+private:
+  DISALLOW_COPY_AND_ASSIGN(TestClass1);
+};
+// CHECK-MESSAGES-DEFAULT: :[[@LINE-2]]:3: warning: using copy and assign macro 'DISALLOW_COPY_AND_ASSIGN' [modernize-replace-disallow-copy-and-assign-macro]
+// CHECK-MESSAGES-NEXT-DEFAULT: {{^}}  DISALLOW_COPY_AND_ASSIGN(TestClass1);{{$}}
+// CHECK-MESSAGES-NEXT-DEFAULT: {{^}}  ^{{$}}
+// CHECK-MESSAGES-NEXT-DEFAULT: {{^}}  TestClass1(const TestClass1 &) = delete;const TestClass1 =(const TestClass1 &) = delete{{$}}
+// CHECK-FIXES-DEFAULT:  {{^}}  TestClass1(const TestClass1 &) = delete;{{$}}
+// CHECK-FIXES-DEFAULT-NEXT: {{^}}  const TestClass1 =(const TestClass1 &) = delete;{{$}}
+
+#define MY_MACRO_NAME(TypeName)
+
+class TestClass2 {
+private:
+  MY_MACRO_NAME(TestClass2);
+};
+// CHECK-MESSAGES-DIFFERENT-NAME: :[[@LINE-2]]:3: warning: using copy and assign macro 'MY_MACRO_NAME' [modernize-replace-disallow-copy-and-assign-macro]
+// CHECK-FIXES-DIFFERENT-NAME:  {{^}}  TestClass2(const TestClass2 &) = delete;{{$}}
+// CHECK-FIXES-DIFFERENT-NAME-NEXT: {{^}}  const TestClass2 =(const TestClass2 &) = delete;{{$}}
+
+#define DISALLOW_COPY_AND_ASSIGN_FINALIZE(TypeName) \
+  TypeName(const TypeName &) = delete;  \
+  const TypeName =(const TypeName &) = delete;
+
+class TestClass3 {
+private:
+  // Notice, that the macro allows to be used without a semicolon because the
+  // macro definition already contains one above. Therefore our replacement must
+  // contain a semicolon at the end.
+  DISALLOW_COPY_AND_ASSIGN_FINALIZE(TestClass3)
+};
+// CHECK-MESSAGES-FINALIZE: :[[@LINE-2]]:3: warning: using copy and assign macro 'DISALLOW_COPY_AND_ASSIGN_FINALIZE' [modernize-replace-disallow-copy-and-assign-macro]
+// CHECK-FIXES-FINALIZE:  {{^}}  TestClass3(const TestClass3 &) = delete;{{$}}
+// CHECK-FIXES-FINALIZE-NEXT: {{^}}  const TestClass3 =(const TestClass3 &) = delete;{{$}}
+
+#define DISALLOW_COPY_AND_ASSIGN_MORE_AGUMENTS(A, B)
+
+class TestClass4 {
+private:
+  DISALLOW_COPY_AND_ASSIGN_MORE_AGUMENTS(TestClass4, TestClass4);
+};
+// CHECK-MESSAGES-MORE-ARGUMENTS-NOT: warning: using copy and assign macro 'DISALLOW_COPY_AND_ASSIGN_MORE_AGUMENTS'

[PATCH] D80531: [clang-tidy]: Added modernize-replace-disallow-copy-and-assign-macro

2020-05-26 Thread Konrad Wilhelm Kleine via Phabricator via cfe-commits
kwk planned changes to this revision.
kwk added a comment.

Thank you @njames93 for the review. I'm implementing what you wrote.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D80531/new/

https://reviews.llvm.org/D80531



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


  1   2   >