Swift: update formatting to clang-format 17.0.6

Also, added a format check in `swift.yml`.
This commit is contained in:
Paolo Tranquilli
2024-01-25 13:57:10 +01:00
parent 01b89508a8
commit 33b6ce7365
9 changed files with 28 additions and 27 deletions

1
.clang-format Normal file
View File

@@ -0,0 +1 @@
DisableFormat: true

View File

@@ -73,6 +73,15 @@ jobs:
steps: steps:
- uses: actions/checkout@v4 - uses: actions/checkout@v4
- uses: ./swift/actions/run-integration-tests - uses: ./swift/actions/run-integration-tests
clang-format:
if : ${{ github.event_name == 'pull_request' }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: pre-commit/action@646c83fcd040023954eafda54b4db0192ce70507
name: Check that python code is properly formatted
with:
extra_args: clang-format --all-files
codegen: codegen:
if : ${{ github.event_name == 'pull_request' }} if : ${{ github.event_name == 'pull_request' }}
runs-on: ubuntu-latest runs-on: ubuntu-latest
@@ -82,12 +91,12 @@ jobs:
- uses: actions/setup-python@v4 - uses: actions/setup-python@v4
with: with:
python-version-file: 'swift/.python-version' python-version-file: 'swift/.python-version'
- uses: pre-commit/action@v3.0.0 - uses: pre-commit/action@646c83fcd040023954eafda54b4db0192ce70507
name: Check that python code is properly formatted name: Check that python code is properly formatted
with: with:
extra_args: autopep8 --all-files extra_args: autopep8 --all-files
- uses: ./.github/actions/fetch-codeql - uses: ./.github/actions/fetch-codeql
- uses: pre-commit/action@v3.0.0 - uses: pre-commit/action@646c83fcd040023954eafda54b4db0192ce70507
name: Check that QL generated code was checked in name: Check that QL generated code was checked in
with: with:
extra_args: swift-codegen --all-files extra_args: swift-codegen --all-files

View File

@@ -10,10 +10,9 @@ repos:
exclude: /test/.*$(?<!\.ql)(?<!\.qll)(?<!\.qlref)|.*\.patch exclude: /test/.*$(?<!\.ql)(?<!\.qll)(?<!\.qlref)|.*\.patch
- repo: https://github.com/pre-commit/mirrors-clang-format - repo: https://github.com/pre-commit/mirrors-clang-format
rev: v13.0.1 rev: v17.0.6
hooks: hooks:
- id: clang-format - id: clang-format
files: ^swift/.*\.(h|c|cpp)$
- repo: https://github.com/pre-commit/mirrors-autopep8 - repo: https://github.com/pre-commit/mirrors-autopep8
rev: v1.6.0 rev: v1.6.0

View File

@@ -338,7 +338,10 @@ class SwiftDispatcher {
virtual void visit(const swift::MacroRoleAttr* attr) = 0; virtual void visit(const swift::MacroRoleAttr* attr) = 0;
template <typename T> template <typename T>
requires(!std::derived_from<T, swift::TypeRepr>) void visit(const T* e, swift::Type) { visit(e); } requires(!std::derived_from<T, swift::TypeRepr>)
void visit(const T* e, swift::Type) {
visit(e);
}
const swift::SourceManager& sourceManager; const swift::SourceManager& sourceManager;
SwiftExtractorState& state; SwiftExtractorState& state;

View File

@@ -17,34 +17,25 @@ class TrapDomain;
namespace detail { namespace detail {
template <typename T> template <typename T>
concept HasSourceRange = requires(T e) { concept HasSourceRange = requires(T e) { e.getSourceRange(); };
e.getSourceRange();
};
template <typename T> template <typename T>
concept HasStartAndEndLoc = requires(T e) { concept HasStartAndEndLoc = requires(T e) {
e.getStartLoc(); e.getStartLoc();
e.getEndLoc(); e.getEndLoc();
} } && !(HasSourceRange<T>);
&&!(HasSourceRange<T>);
template <typename T> template <typename T>
concept HasLAndRParenLoc = requires(T e) { concept HasLAndRParenLoc = requires(T e) {
e.getLParenLoc(); e.getLParenLoc();
e.getRParenLoc(); e.getRParenLoc();
} } && !(HasSourceRange<T>)&&!(HasStartAndEndLoc<T>);
&&!(HasSourceRange<T>)&&!(HasStartAndEndLoc<T>);
template <typename T> template <typename T>
concept HasOneLoc = requires(T e) { concept HasOneLoc = requires(T e) { e.getLoc(); } && !(HasSourceRange<T>)&&(!HasStartAndEndLoc<T>);
e.getLoc();
}
&&!(HasSourceRange<T>)&&(!HasStartAndEndLoc<T>);
template <typename T> template <typename T>
concept HasOneLocField = requires(T e) { concept HasOneLocField = requires(T e) { e.Loc; };
e.Loc;
};
swift::SourceRange getSourceRange(const HasSourceRange auto& locatable) { swift::SourceRange getSourceRange(const HasSourceRange auto& locatable) {
return locatable.getSourceRange(); return locatable.getSourceRange();
@@ -89,9 +80,7 @@ swift::SourceRange getSourceRange(const llvm::MutableArrayRef<Locatable>& locata
} // namespace detail } // namespace detail
template <typename E> template <typename E>
concept IsLocatable = requires(E e) { concept IsLocatable = requires(E e) { detail::getSourceRange(e); };
detail::getSourceRange(e);
};
class SwiftLocationExtractor { class SwiftLocationExtractor {
public: public:

View File

@@ -3,7 +3,6 @@
namespace codeql { namespace codeql {
codeql::NamedPattern PatternTranslator::translateNamedPattern(const swift::NamedPattern& pattern) { codeql::NamedPattern PatternTranslator::translateNamedPattern(const swift::NamedPattern& pattern) {
auto entry = createPatternEntry(pattern); auto entry = createPatternEntry(pattern);
entry.var_decl = dispatcher.fetchLabel(pattern.getDecl()); entry.var_decl = dispatcher.fetchLabel(pattern.getDecl());
return entry; return entry;

View File

@@ -83,8 +83,8 @@ class TrapLabel : public UntypedTrapLabel {
static TrapLabel unsafeCreateFromUntyped(UntypedTrapLabel label) { return TrapLabel{label.id_}; } static TrapLabel unsafeCreateFromUntyped(UntypedTrapLabel label) { return TrapLabel{label.id_}; }
template <typename SourceTag> template <typename SourceTag>
requires std::derived_from<SourceTag, Tag> TrapLabel(const TrapLabel<SourceTag>& other) requires std::derived_from<SourceTag, Tag>
: UntypedTrapLabel(other) {} TrapLabel(const TrapLabel<SourceTag>& other) : UntypedTrapLabel(other) {}
}; };
// wrapper class to allow directly assigning a vector of TrapLabel<A> to a vector of // wrapper class to allow directly assigning a vector of TrapLabel<A> to a vector of
@@ -96,7 +96,7 @@ struct TrapLabelVectorWrapper {
std::vector<TrapLabel<TagParam>> data; std::vector<TrapLabel<TagParam>> data;
template <typename DestinationTag> template <typename DestinationTag>
requires std::derived_from<Tag, DestinationTag> requires std::derived_from<Tag, DestinationTag>
operator std::vector<TrapLabel<DestinationTag>>() && { operator std::vector<TrapLabel<DestinationTag>>() && {
// reinterpret_cast is safe because TrapLabel instances differ only on the type, not the // reinterpret_cast is safe because TrapLabel instances differ only on the type, not the
// underlying data // underlying data

View File

@@ -0,0 +1 @@
DisableFormat: true

View File

@@ -63,7 +63,7 @@
#define DIAGNOSE_WITH_LEVEL(LEVEL, ID, FORMAT, ...) \ #define DIAGNOSE_WITH_LEVEL(LEVEL, ID, FORMAT, ...) \
do { \ do { \
auto _now = ::binlog::clockNow(); \ auto _now = ::binlog::clockNow(); \
const ::codeql::Diagnostic& _id = ID; \ const ::codeql::Diagnostic& _id = ID; \
::codeql::Log::diagnose(_id, std::chrono::nanoseconds{_now}, \ ::codeql::Log::diagnose(_id, std::chrono::nanoseconds{_now}, \
fmt::format(FORMAT __VA_OPT__(, ) __VA_ARGS__)); \ fmt::format(FORMAT __VA_OPT__(, ) __VA_ARGS__)); \
LOG_WITH_LEVEL_AND_TIME(LEVEL, _now, CODEQL_DIAGNOSTIC_LOG_FORMAT_PREFIX FORMAT, \ LOG_WITH_LEVEL_AND_TIME(LEVEL, _now, CODEQL_DIAGNOSTIC_LOG_FORMAT_PREFIX FORMAT, \