Skip to content

Commit

Permalink
Merge pull request #15433 from github/redsun82/clang-format
Browse files Browse the repository at this point in the history
Swift: update formatting to `clang-format` 17.0.6
  • Loading branch information
redsun82 authored Jan 25, 2024
2 parents 10343dd + 33b6ce7 commit b2489f7
Show file tree
Hide file tree
Showing 9 changed files with 28 additions and 27 deletions.
1 change: 1 addition & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
DisableFormat: true
13 changes: 11 additions & 2 deletions .github/workflows/swift.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,15 @@ jobs:
steps:
- uses: actions/checkout@v4
- 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:
if : ${{ github.event_name == 'pull_request' }}
runs-on: ubuntu-latest
Expand All @@ -82,12 +91,12 @@ jobs:
- uses: actions/setup-python@v4
with:
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
with:
extra_args: autopep8 --all-files
- 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
with:
extra_args: swift-codegen --all-files
Expand Down
3 changes: 1 addition & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,9 @@ repos:
exclude: /test/.*$(?<!\.ql)(?<!\.qll)(?<!\.qlref)|.*\.patch

- repo: https://github.com/pre-commit/mirrors-clang-format
rev: v13.0.1
rev: v17.0.6
hooks:
- id: clang-format
files: ^swift/.*\.(h|c|cpp)$

- repo: https://github.com/pre-commit/mirrors-autopep8
rev: v1.6.0
Expand Down
5 changes: 4 additions & 1 deletion swift/extractor/infra/SwiftDispatcher.h
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,10 @@ class SwiftDispatcher {
virtual void visit(const swift::MacroRoleAttr* attr) = 0;

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;
SwiftExtractorState& state;
Expand Down
23 changes: 6 additions & 17 deletions swift/extractor/infra/SwiftLocationExtractor.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,34 +17,25 @@ class TrapDomain;

namespace detail {
template <typename T>
concept HasSourceRange = requires(T e) {
e.getSourceRange();
};
concept HasSourceRange = requires(T e) { e.getSourceRange(); };

template <typename T>
concept HasStartAndEndLoc = requires(T e) {
e.getStartLoc();
e.getEndLoc();
}
&&!(HasSourceRange<T>);
} && !(HasSourceRange<T>);

template <typename T>
concept HasLAndRParenLoc = requires(T e) {
e.getLParenLoc();
e.getRParenLoc();
}
&&!(HasSourceRange<T>)&&!(HasStartAndEndLoc<T>);
} && !(HasSourceRange<T>)&&!(HasStartAndEndLoc<T>);

template <typename T>
concept HasOneLoc = requires(T e) {
e.getLoc();
}
&&!(HasSourceRange<T>)&&(!HasStartAndEndLoc<T>);
concept HasOneLoc = requires(T e) { e.getLoc(); } && !(HasSourceRange<T>)&&(!HasStartAndEndLoc<T>);

template <typename T>
concept HasOneLocField = requires(T e) {
e.Loc;
};
concept HasOneLocField = requires(T e) { e.Loc; };

swift::SourceRange getSourceRange(const HasSourceRange auto& locatable) {
return locatable.getSourceRange();
Expand Down Expand Up @@ -89,9 +80,7 @@ swift::SourceRange getSourceRange(const llvm::MutableArrayRef<Locatable>& locata
} // namespace detail

template <typename E>
concept IsLocatable = requires(E e) {
detail::getSourceRange(e);
};
concept IsLocatable = requires(E e) { detail::getSourceRange(e); };

class SwiftLocationExtractor {
public:
Expand Down
1 change: 0 additions & 1 deletion swift/extractor/translators/PatternTranslator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace codeql {

codeql::NamedPattern PatternTranslator::translateNamedPattern(const swift::NamedPattern& pattern) {

auto entry = createPatternEntry(pattern);
entry.var_decl = dispatcher.fetchLabel(pattern.getDecl());
return entry;
Expand Down
6 changes: 3 additions & 3 deletions swift/extractor/trap/TrapLabel.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ class TrapLabel : public UntypedTrapLabel {
static TrapLabel unsafeCreateFromUntyped(UntypedTrapLabel label) { return TrapLabel{label.id_}; }

template <typename SourceTag>
requires std::derived_from<SourceTag, Tag> TrapLabel(const TrapLabel<SourceTag>& other)
: UntypedTrapLabel(other) {}
requires std::derived_from<SourceTag, Tag>
TrapLabel(const TrapLabel<SourceTag>& other) : UntypedTrapLabel(other) {}
};

// wrapper class to allow directly assigning a vector of TrapLabel<A> to a vector of
Expand All @@ -96,7 +96,7 @@ struct TrapLabelVectorWrapper {
std::vector<TrapLabel<TagParam>> data;

template <typename DestinationTag>
requires std::derived_from<Tag, DestinationTag>
requires std::derived_from<Tag, DestinationTag>
operator std::vector<TrapLabel<DestinationTag>>() && {
// reinterpret_cast is safe because TrapLabel instances differ only on the type, not the
// underlying data
Expand Down
1 change: 1 addition & 0 deletions swift/integration-tests/.clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
DisableFormat: true
2 changes: 1 addition & 1 deletion swift/logging/SwiftLogging.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
#define DIAGNOSE_WITH_LEVEL(LEVEL, ID, FORMAT, ...) \
do { \
auto _now = ::binlog::clockNow(); \
const ::codeql::Diagnostic& _id = ID; \
const ::codeql::Diagnostic& _id = ID; \
::codeql::Log::diagnose(_id, std::chrono::nanoseconds{_now}, \
fmt::format(FORMAT __VA_OPT__(, ) __VA_ARGS__)); \
LOG_WITH_LEVEL_AND_TIME(LEVEL, _now, CODEQL_DIAGNOSTIC_LOG_FORMAT_PREFIX FORMAT, \
Expand Down

0 comments on commit b2489f7

Please sign in to comment.