Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add clang format workflow #1920

Merged
merged 20 commits into from
Mar 8, 2024
34 changes: 34 additions & 0 deletions .github/workflows/clang_format.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: Clang Format

on:
workflow_dispatch:
push:
branches: ["main"]
pull_request:
# The branches below must be a subset of the branches above
branches: ["main"]

jobs:
clang-format:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Install Clang Format
run: |
# TODO: Figure out how always to install the latest version of clang-format
externl marked this conversation as resolved.
Show resolved Hide resolved
# This LLVM script will add the relevant LLVM PPA: https://apt.llvm.org/
wget https://apt.llvm.org/llvm.sh -O /tmp/llvm.sh
chmod +x /tmp/llvm.sh
sudo /tmp/llvm.sh 18
sudo apt-get install -y clang-format-18 clang-tidy-18
externl marked this conversation as resolved.
Show resolved Hide resolved
rm /tmp/llvm.sh

- name: Clang format version
run: clang-format-18 --version

- name: Run Clang Format
run: |
find . -name "*.h" -o -name "*.c" -o -name "*.cpp" -name "*.mm" | xargs clang-format-18 --style=file --fallback-style=none --Werror --dry-run
find cpp -name "*.m" | xargs clang-format-18 --style=file --fallback-style=none --Werror --dry-run
externl marked this conversation as resolved.
Show resolved Hide resolved
16 changes: 6 additions & 10 deletions cpp/src/Ice/LocatorInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,8 @@ namespace
{
LocatorInfo::RequestPtr request = shared_from_this();
_locatorInfo->getLocator()->findObjectByIdAsync(
_reference->getIdentity(),
[request](const optional<ObjectPrx>& object) { request->response(object); },
[request](exception_ptr e) { request->exception(e); });
_reference->getIdentity(), [request](const optional<ObjectPrx>& object)
externl marked this conversation as resolved.
Show resolved Hide resolved
{ request->response(object); }, [request](exception_ptr e) { request->exception(e); });
}
catch (const Ice::Exception&)
{
Expand All @@ -64,9 +63,8 @@ namespace
{
LocatorInfo::RequestPtr request = shared_from_this();
_locatorInfo->getLocator()->findAdapterByIdAsync(
_reference->getAdapterId(),
[request](const optional<ObjectPrx>& object) { request->response(object); },
[request](exception_ptr e) { request->exception(e); });
_reference->getAdapterId(), [request](const optional<ObjectPrx>& object)
{ request->response(object); }, [request](exception_ptr e) { request->exception(e); });
}
catch (const Ice::Exception&)
{
Expand Down Expand Up @@ -620,8 +618,7 @@ IceInternal::LocatorInfo::getEndpointsException(const ReferencePtr& ref, std::ex
if (ref->getInstance()->traceLevels()->location >= 1)
{
Trace out(ref->getInstance()->initializationData().logger, ref->getInstance()->traceLevels()->locationCat);
out << "adapter not found"
<< "\n";
out << "adapter not found" << "\n";
out << "adapter = " << ref->getAdapterId();
}

Expand All @@ -632,8 +629,7 @@ IceInternal::LocatorInfo::getEndpointsException(const ReferencePtr& ref, std::ex
if (ref->getInstance()->traceLevels()->location >= 1)
{
Trace out(ref->getInstance()->initializationData().logger, ref->getInstance()->traceLevels()->locationCat);
out << "object not found"
<< "\n";
out << "object not found" << "\n";
out << "object = " << Ice::identityToString(ref->getIdentity(), ref->getInstance()->toStringMode());
}

Expand Down
3 changes: 1 addition & 2 deletions cpp/src/Ice/RouterInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,7 @@ IceInternal::RouterInfo::getClientEndpointsAsync(
RouterInfoPtr self = shared_from_this();
_router->getClientProxyAsync(
[self, response](const optional<Ice::ObjectPrx>& proxy, optional<bool> hasRoutingTable)
{ response(self->setClientEndpoints(proxy, hasRoutingTable.value_or(true))); },
ex);
{ response(self->setClientEndpoints(proxy, hasRoutingTable.value_or(true))); }, ex);
}

vector<EndpointIPtr>
Expand Down
4 changes: 1 addition & 3 deletions cpp/src/Ice/ThreadPool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -922,9 +922,7 @@ IceInternal::ThreadPool::ioCompleted(ThreadPoolCurrent& current)
{
Warning out(_instance->initializationData().logger);
out << "thread pool `" << _prefix << "' is running low on threads\n"
<< "Size=" << _size << ", "
<< "SizeMax=" << _sizeMax << ", "
<< "SizeWarn=" << _sizeWarn;
<< "Size=" << _size << ", " << "SizeMax=" << _sizeMax << ", " << "SizeWarn=" << _sizeWarn;
}

if (!_destroyed)
Expand Down
5 changes: 1 addition & 4 deletions cpp/src/IceBridge/IceBridge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -358,10 +358,7 @@ BridgeConnection::send(
}
prx->ice_invokeAsync(
current.operation, current.mode, inParams, nullptr, error,
[response = std::move(response)](bool) {
response(true, {nullptr, nullptr});
},
current.ctx);
[response = std::move(response)](bool) { response(true, {nullptr, nullptr}); }, current.ctx);
}
else
{
Expand Down
10 changes: 4 additions & 6 deletions cpp/src/IceGrid/AdapterCache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -688,9 +688,8 @@ ReplicaGroupEntry::getLocatorAdapterInfo(
vector<pair<float, shared_ptr<ServerAdapterEntry>>> rl;
transform(
replicas.begin(), replicas.end(), back_inserter(rl),
[loadSample](const auto& value) -> pair<float, shared_ptr<ServerAdapterEntry>> {
return {value->getLeastLoadedNodeLoad(loadSample), value};
});
[loadSample](const auto& value) -> pair<float, shared_ptr<ServerAdapterEntry>>
{ return {value->getLeastLoadedNodeLoad(loadSample), value}; });
sort(rl.begin(), rl.end(), [](const auto& lhs, const auto& rhs) { return lhs.first < rhs.first; });
replicas.clear();
transform(rl.begin(), rl.end(), back_inserter(replicas), [](const auto& value) { return value.second; });
Expand Down Expand Up @@ -779,9 +778,8 @@ ReplicaGroupEntry::getLeastLoadedNodeLoad(LoadSample loadSample) const
vector<pair<float, shared_ptr<ServerAdapterEntry>>> rl;
transform(
replicas.begin(), replicas.end(), back_inserter(rl),
[loadSample](const auto& value) -> pair<float, shared_ptr<ServerAdapterEntry>> {
return {value->getLeastLoadedNodeLoad(loadSample), value};
});
[loadSample](const auto& value) -> pair<float, shared_ptr<ServerAdapterEntry>>
{ return {value->getLeastLoadedNodeLoad(loadSample), value}; });
return min_element(rl.begin(), rl.end(), [](const auto& lhs, const auto& rhs) { return lhs.first < rhs.first; })
->first;
}
Expand Down
3 changes: 1 addition & 2 deletions cpp/src/IceGrid/AdminCallbackRouter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,5 @@ AdminCallbackRouter::ice_invokeAsync(
target->ice_invokeAsync(
current.operation, current.mode, inParams, std::move(response),
[exception = std::move(exception)](exception_ptr)
{ exception(make_exception_ptr(Ice::ObjectNotExistException(__FILE__, __LINE__))); },
nullptr, current.ctx);
{ exception(make_exception_ptr(Ice::ObjectNotExistException(__FILE__, __LINE__))); }, nullptr, current.ctx);
}
2 changes: 1 addition & 1 deletion cpp/src/IceGrid/Grammar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ typedef short int yytype_int16;
# endif
#endif

#define YYSIZE_MAXIMUM ((YYSIZE_T)-1)
#define YYSIZE_MAXIMUM ((YYSIZE_T) - 1)

#ifndef YY_
# if defined YYENABLE_NLS && YYENABLE_NLS
Expand Down
6 changes: 3 additions & 3 deletions cpp/src/IceGrid/Scanner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ typedef unsigned int flex_uint32_t;
* to BEGIN to return to the state. The YYSTATE alias is for lex
* compatibility.
*/
#define YY_START (((yy_start)-1) / 2)
#define YY_START (((yy_start) - 1) / 2)
#define YYSTATE YY_START
/* Action number for EOF rule of a given start state. */
#define YY_STATE_EOF(state) (YY_END_OF_BUFFER + state + 1)
Expand Down Expand Up @@ -1008,8 +1008,8 @@ YY_DECL
default:
YY_FATAL_ERROR("fatal flex scanner internal error--no action found");
} /* end of action switch */
} /* end of scanning one token */
} /* end of user's declarations */
} /* end of scanning one token */
} /* end of user's declarations */
} /* end of yylex */

/* yy_get_next_buffer - try to read in a new buffer
Expand Down
3 changes: 1 addition & 2 deletions cpp/src/IceGrid/ServerI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -313,8 +313,7 @@ namespace IceGrid

auto p = Ice::uncheckedCast<Ice::PropertiesAdminPrx>(_admin, facet);
p->setPropertiesAsync(
props, [self = shared_from_this()] { self->next(); },
[server = _server, desc = _desc](exception_ptr ex)
props, [self = shared_from_this()] { self->next(); }, [server = _server, desc = _desc](exception_ptr ex)
{ server->updateRuntimePropertiesCallback(ex, desc); });
}

Expand Down
3 changes: 1 addition & 2 deletions cpp/src/IceGrid/Util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -218,8 +218,7 @@ IceGrid::toObjectInfo(
catch (const Ice::ProxyParseException&)
{
ostringstream fallbackProxyStr;
fallbackProxyStr << "\"" << communicator->identityToString(obj.id) << "\""
<< " @ \"" << adapterId << "\"";
fallbackProxyStr << "\"" << communicator->identityToString(obj.id) << "\"" << " @ \"" << adapterId << "\"";
info.proxy = communicator->stringToProxy(fallbackProxyStr.str());
}
return info;
Expand Down
3 changes: 1 addition & 2 deletions cpp/src/IcePatch2Lib/ClientUtil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -650,8 +650,7 @@ namespace
std::shared_ptr<GetFileCompressedCB> cb)
{
serverNoCompress->getLargeFileCompressedAsync(
path, pos, chunkSize,
[cb](std::pair<const uint8_t*, const uint8_t*> result)
path, pos, chunkSize, [cb](std::pair<const uint8_t*, const uint8_t*> result)
{ cb->complete(ByteSeq(result.first, result.second)); },
[cb](exception_ptr exception) { cb->exception(exception); });
}
Expand Down
2 changes: 1 addition & 1 deletion cpp/src/IceStorm/Grammar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ typedef short int yytype_int16;
# endif
#endif

#define YYSIZE_MAXIMUM ((YYSIZE_T)-1)
#define YYSIZE_MAXIMUM ((YYSIZE_T) - 1)

#ifndef YY_
# if defined YYENABLE_NLS && YYENABLE_NLS
Expand Down
6 changes: 3 additions & 3 deletions cpp/src/IceStorm/Scanner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ typedef unsigned int flex_uint32_t;
* to BEGIN to return to the state. The YYSTATE alias is for lex
* compatibility.
*/
#define YY_START (((yy_start)-1) / 2)
#define YY_START (((yy_start) - 1) / 2)
#define YYSTATE YY_START
/* Action number for EOF rule of a given start state. */
#define YY_STATE_EOF(state) (YY_END_OF_BUFFER + state + 1)
Expand Down Expand Up @@ -1032,8 +1032,8 @@ YY_DECL
default:
YY_FATAL_ERROR("fatal flex scanner internal error--no action found");
} /* end of action switch */
} /* end of scanning one token */
} /* end of user's declarations */
} /* end of scanning one token */
} /* end of user's declarations */
} /* end of yylex */

/* yy_get_next_buffer - try to read in a new buffer
Expand Down
4 changes: 2 additions & 2 deletions cpp/src/Slice/Parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3562,8 +3562,8 @@ Slice::InterfaceDef::createOperation(
if (baseName == newName2)
{
ostringstream os;
os << "operation `" << name << "' differs only in capitalization from operation"
<< " `" << op->name() << "', which is defined in a base interface";
os << "operation `" << name << "' differs only in capitalization from operation" << " `" << op->name()
<< "', which is defined in a base interface";
_unit->error(os.str());
return nullptr;
}
Expand Down
6 changes: 3 additions & 3 deletions cpp/src/Slice/Scanner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,7 @@ typedef unsigned int flex_uint32_t;
* to BEGIN to return to the state. The YYSTATE alias is for lex
* compatibility.
*/
#define YY_START (((yy_start)-1) / 2)
#define YY_START (((yy_start) - 1) / 2)
#define YYSTATE YY_START
/* Action number for EOF rule of a given start state. */
#define YY_STATE_EOF(state) (YY_END_OF_BUFFER + state + 1)
Expand Down Expand Up @@ -2119,8 +2119,8 @@ YY_DECL
default:
YY_FATAL_ERROR("fatal flex scanner internal error--no action found");
} /* end of action switch */
} /* end of scanning one token */
} /* end of user's declarations */
} /* end of scanning one token */
} /* end of user's declarations */
} /* end of yylex */
/* %ok-for-header */

Expand Down
6 changes: 2 additions & 4 deletions cpp/src/Slice/SliceUtil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -362,11 +362,9 @@ Slice::printGeneratedHeader(IceUtilInternal::Output& out, const string& path, co

out << comment << " <auto-generated>\n";
out << comment << "\n";
out << comment << " Generated from file `" << file << "'"
<< "\n";
out << comment << " Generated from file `" << file << "'" << "\n";
out << comment << "\n";
out << comment << " Warning: do not edit this file."
<< "\n";
out << comment << " Warning: do not edit this file." << "\n";
out << comment << "\n";
out << comment << " </auto-generated>\n";
out << comment << "\n";
Expand Down
3 changes: 1 addition & 2 deletions cpp/src/ice2slice/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -247,8 +247,7 @@ main(int argc, char* argv[])
}
catch (...)
{
consoleErr << args[0] << ": error:"
<< "unknown exception" << endl;
consoleErr << args[0] << ": error:" << "unknown exception" << endl;
return EXIT_FAILURE;
}
}
21 changes: 7 additions & 14 deletions cpp/src/slice2cpp/Gen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1435,8 +1435,7 @@ Slice::Gen::DefaultFactoryVisitor::visitClassDefStart(const ClassDefPtr& p)
C << sp;

C << nl << "const ::IceInternal::DefaultValueFactoryInit<" << fixKwd(p->scoped()) << "> ";
C << "iceC" + p->flattenedScope() + p->name() + "_init"
<< "(\"" << p->scoped() << "\");";
C << "iceC" + p->flattenedScope() + p->name() + "_init" << "(\"" << p->scoped() << "\");";

if (p->compactId() >= 0)
{
Expand All @@ -1452,8 +1451,7 @@ Slice::Gen::DefaultFactoryVisitor::visitExceptionStart(const ExceptionPtr& p)
{
C << sp;
C << nl << "const ::IceInternal::DefaultUserExceptionFactoryInit<" << fixKwd(p->scoped()) << "> ";
C << "iceC" + p->flattenedScope() + p->name() + "_init"
<< "(\"" << p->scoped() << "\");";
C << "iceC" + p->flattenedScope() + p->name() + "_init" << "(\"" << p->scoped() << "\");";
return false;
}

Expand Down Expand Up @@ -1733,8 +1731,7 @@ Slice::Gen::ProxyVisitor::visitOperation(const OperationPtr& p)
// We call makePromiseOutgoing with the "sync" parameter set to true; the Promise/future implementation later on
// calls makePromiseOutgoing with this parameter set to false. This parameter is useful for collocated calls.
C << "::IceInternal::makePromiseOutgoing<" << futureT << ">";
C << spar << "true, this"
<< "&" + interface->name() + "Prx::_iceI_" + name;
C << spar << "true, this" << "&" + interface->name() + "Prx::_iceI_" + name;
C << inParamsImpl;
C << "context" << epar << ".get();";
if (futureOutParams.size() > 1)
Expand Down Expand Up @@ -1836,10 +1833,8 @@ Slice::Gen::ProxyVisitor::visitOperation(const OperationPtr& p)

C << nl << "return ::IceInternal::makeLambdaOutgoing<" << lambdaT << ">" << spar;

C << "std::move(" + (lambdaOutParams.size() > 1 ? string("responseCb") : "response") + ")"
<< "std::move(ex)"
<< "std::move(sent)"
<< "this";
C << "std::move(" + (lambdaOutParams.size() > 1 ? string("responseCb") : "response") + ")" << "std::move(ex)"
<< "std::move(sent)" << "this";
C << string("&" + getUnqualified(scoped, interfaceScope.substr(2)) + lambdaImplPrefix + name);
C << inParamsImpl;
C << "context" << epar << ";";
Expand Down Expand Up @@ -2165,8 +2160,7 @@ Slice::Gen::DataDefVisitor::visitExceptionStart(const ExceptionPtr& p)
H.inc();
if (base || !baseDataMembers.empty())
{
H << nl << helperClass << "<" << templateParameters << ">"
<< "(";
H << nl << helperClass << "<" << templateParameters << ">" << "(";

for (DataMemberList::const_iterator q = baseDataMembers.begin(); q != baseDataMembers.end(); ++q)
{
Expand Down Expand Up @@ -2779,8 +2773,7 @@ Slice::Gen::InterfaceVisitor::visitInterfaceDefEnd(const InterfaceDefPtr& p)
C << sp;
C << nl << "const ::Ice::Current& current = incoming.current();";
C << nl << "::std::pair<const ::std::string_view*, const ::std::string_view*> r = "
<< "::std::equal_range(allOperations, allOperations"
<< " + " << allOpNames.size() << ", current.operation);";
<< "::std::equal_range(allOperations, allOperations" << " + " << allOpNames.size() << ", current.operation);";
C << nl << "if(r.first == r.second)";
C << sb;
C << nl << "throw " << getUnqualified("::Ice::OperationNotExistException", scope)
Expand Down
3 changes: 1 addition & 2 deletions cpp/src/slice2cpp/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -344,8 +344,7 @@ main(int argc, char* argv[])
}
catch (...)
{
consoleErr << args[0] << ": error:"
<< "unknown exception" << endl;
consoleErr << args[0] << ": error:" << "unknown exception" << endl;
return EXIT_FAILURE;
}
}
4 changes: 2 additions & 2 deletions cpp/src/slice2cs/CsUtil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1385,8 +1385,8 @@ Slice::CsGenerator::writeSequenceMarshalUnmarshalCode(
else if (isCustom)
{
out << sb;
out << nl << param << " = new "
<< "global::" << genericType << "<" << typeToString(type, scope) << ">();";
out << nl << param << " = new " << "global::" << genericType << "<" << typeToString(type, scope)
<< ">();";
out << nl << "int szx = " << stream << ".readSize();";
out << nl << "for(int ix = 0; ix < szx; ++ix)";
out << sb;
Expand Down
Loading
Loading