Add InsertBraces: true to .clang-format

Bug: none
Change-Id: I4b4f2a4abfea7adcea406f458bc4e4a13b0e8c43
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/91000
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: Austin Eng <enga@chromium.org>
Reviewed-by: dan sinclair <dsinclair@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
This commit is contained in:
Austin Eng 2022-05-19 20:08:19 +00:00 committed by Dawn LUCI CQ
parent 2081ee43bf
commit 86a617f110
18 changed files with 654 additions and 336 deletions

View File

@ -7,4 +7,4 @@ ColumnLimit: 100
IndentWidth: 4
ObjCBlockIndentWidth: 4
AccessModifierOffset: -2
InsertBraces: true

View File

@ -103,10 +103,11 @@ class StackAllocator : public std::allocator<T> {
// Free: when trying to free the stack buffer, just mark it as free. For
// non-stack-buffer pointers, just fall though to the standard allocator.
void deallocate(pointer p, size_type n) {
if (source_ && p == source_->stack_buffer())
if (source_ && p == source_->stack_buffer()) {
source_->used_stack_buffer_ = false;
else
} else {
std::allocator<T>::deallocate(p, n);
}
}
private:

View File

@ -25,8 +25,9 @@
namespace {
// TODO(amaiorano): Move to utility header
std::vector<std::string> Split(const std::string& s, char delim) {
if (s.empty())
if (s.empty()) {
return {};
}
std::vector<std::string> result;
const size_t lastIndex = s.length() - 1;
@ -36,13 +37,15 @@ std::vector<std::string> Split(const std::string& s, char delim) {
while (i <= lastIndex) {
if (s[i] == delim) {
auto token = s.substr(startIndex, i - startIndex);
if (!token.empty()) // Discard empty tokens
if (!token.empty()) { // Discard empty tokens
result.push_back(token);
}
startIndex = i + 1;
} else if (i == lastIndex) {
auto token = s.substr(startIndex, i - startIndex + 1);
if (!token.empty()) // Discard empty tokens
if (!token.empty()) { // Discard empty tokens
result.push_back(token);
}
}
++i;
}
@ -151,7 +154,8 @@ GPUAdapter::GPUAdapter(dawn::native::Adapter a, const Flags& flags) : adapter_(a
name_ = props.name;
}
// TODO(dawn:1133): Avoid the extra copy by making the generator make a virtual method with const std::string&
// TODO(dawn:1133): Avoid the extra copy by making the generator make a virtual method with const
// std::string&
std::string GPUAdapter::getName(Napi::Env) {
return name_;
}

View File

@ -921,8 +921,9 @@ class TraceEndOnScopeClose {
// Note: members of m_data intentionally left uninitialized. See initialize.
TraceEndOnScopeClose() : m_pdata(0) {}
~TraceEndOnScopeClose() {
if (m_pdata)
if (m_pdata) {
addEventIfEnabled();
}
}
void initialize(dawn::platform::Platform* platform,

View File

@ -978,8 +978,7 @@ std::pair<wgpu::Device, WGPUDevice> DawnTestBase::CreateDeviceImpl(std::string i
mDeviceErrorCallback.MakeUserdata(device.Get()));
device.SetDeviceLostCallback(mDeviceLostCallback.Callback(),
mDeviceLostCallback.MakeUserdata(device.Get()));
EXPECT_CALL(mDeviceLostCallback,
Call(WGPUDeviceLostReason_Destroyed, testing::_, device.Get()))
EXPECT_CALL(mDeviceLostCallback, Call(WGPUDeviceLostReason_Destroyed, testing::_, device.Get()))
.Times(testing::AtMost(1));
device.SetLoggingCallback(

View File

@ -84,8 +84,9 @@ class VideoViewsTestBackendGbm : public VideoViewsTestBackend {
for (uint32_t i = kRenderNodeStart; i < kRenderNodeEnd; i++) {
std::string renderNode = kRenderNodeTemplate + std::to_string(i);
renderNodeFd = open(renderNode.c_str(), O_RDWR);
if (renderNodeFd >= 0)
if (renderNodeFd >= 0) {
break;
}
}
ASSERT(renderNodeFd > 0);

View File

@ -47,8 +47,9 @@ TEST(StackContainer, Vector) {
}
// The array should still be in order.
for (int i = 0; i < stack_size * 2; i++)
for (int i = 0; i < stack_size * 2; i++) {
EXPECT_EQ(i, vect.container()[i]);
}
// Resize to smaller. Our STL implementation won't reallocate in this case,
// otherwise it might use our stack buffer. We reserve right after the resize
@ -64,8 +65,9 @@ TEST(StackContainer, Vector) {
std::vector<int, StackAllocator<int, stack_size>> other(vect.container());
EXPECT_EQ(stack_buffer, &other.front());
EXPECT_TRUE(vect.stack_data().used_stack_buffer_);
for (int i = 0; i < stack_size; i++)
for (int i = 0; i < stack_size; i++) {
EXPECT_EQ(i, other[i]);
}
}
TEST(StackContainer, VectorDoubleDelete) {

View File

@ -154,8 +154,9 @@ class VulkanImageWrappingTestBackendDmaBuf : public VulkanImageWrappingTestBacke
for (uint32_t i = kRenderNodeStart; i < kRenderNodeEnd; i++) {
std::string renderNode = kRenderNodeTemplate + std::to_string(i);
renderNodeFd = open(renderNode.c_str(), O_RDWR);
if (renderNodeFd >= 0)
if (renderNodeFd >= 0) {
break;
}
}
EXPECT_GE(renderNodeFd, 0) << "Failed to get file descriptor for render node";
@ -167,8 +168,9 @@ class VulkanImageWrappingTestBackendDmaBuf : public VulkanImageWrappingTestBacke
private:
gbm_bo* CreateGbmBo(uint32_t width, uint32_t height, bool linear) {
uint32_t flags = GBM_BO_USE_RENDERING;
if (linear)
if (linear) {
flags |= GBM_BO_USE_LINEAR;
}
gbm_bo* gbmBo = gbm_bo_create(mGbmDevice, width, height, GBM_FORMAT_XBGR8888, flags);
EXPECT_NE(gbmBo, nullptr) << "Failed to create GBM buffer object";
return gbmBo;

View File

@ -125,30 +125,36 @@ Format parse_format(const std::string& fmt) {
(void)fmt;
#if TINT_BUILD_SPV_WRITER
if (fmt == "spirv")
if (fmt == "spirv") {
return Format::kSpirv;
if (fmt == "spvasm")
}
if (fmt == "spvasm") {
return Format::kSpvAsm;
}
#endif // TINT_BUILD_SPV_WRITER
#if TINT_BUILD_WGSL_WRITER
if (fmt == "wgsl")
if (fmt == "wgsl") {
return Format::kWgsl;
}
#endif // TINT_BUILD_WGSL_WRITER
#if TINT_BUILD_MSL_WRITER
if (fmt == "msl")
if (fmt == "msl") {
return Format::kMsl;
}
#endif // TINT_BUILD_MSL_WRITER
#if TINT_BUILD_HLSL_WRITER
if (fmt == "hlsl")
if (fmt == "hlsl") {
return Format::kHlsl;
}
#endif // TINT_BUILD_HLSL_WRITER
#if TINT_BUILD_GLSL_WRITER
if (fmt == "glsl")
if (fmt == "glsl") {
return Format::kGlsl;
}
#endif // TINT_BUILD_GLSL_WRITER
return Format::kNone;

View File

@ -602,10 +602,12 @@ class StructuredTraverser {
// header, we will visit its merge block, then its continue target (if any).
// Also records the post order ordering.
void VisitBackward(uint32_t id) {
if (id == 0)
if (id == 0) {
return;
if (visited_.count(id))
}
if (visited_.count(id)) {
return;
}
visited_.insert(id);
const spvtools::opt::BasicBlock* bb = id_to_block_[id]; // non-null for valid modules
@ -1600,8 +1602,9 @@ bool FunctionEmitter::RegisterMerges() {
bool is_single_block_loop = false;
block_info->basic_block->ForEachSuccessorLabel(
[&is_single_block_loop, block_id](const uint32_t succ) {
if (block_id == succ)
if (block_id == succ) {
is_single_block_loop = true;
}
});
const auto ct = block_info->continue_for_header;
block_info->is_continue_entire_loop = ct == block_id;

View File

@ -232,8 +232,9 @@ bool Lexer::is_hex(char ch) const {
}
bool Lexer::matches(size_t pos, std::string_view sub_string) {
if (pos >= length())
if (pos >= length()) {
return false;
}
return substr(pos, sub_string.size()) == sub_string;
}
@ -265,8 +266,9 @@ Token Lexer::skip_blankspace_and_comments() {
// If the cursor didn't advance we didn't remove any blankspace
// so we're done.
if (loc == location_)
if (loc == location_) {
break;
}
}
if (is_eof()) {
return {Token::Type::kEOF, begin_source()};
@ -1043,110 +1045,159 @@ Token Lexer::try_punctuation() {
}
Token Lexer::check_keyword(const Source& source, std::string_view str) {
if (str == "array")
if (str == "array") {
return {Token::Type::kArray, source, "array"};
if (str == "atomic")
}
if (str == "atomic") {
return {Token::Type::kAtomic, source, "atomic"};
if (str == "bitcast")
}
if (str == "bitcast") {
return {Token::Type::kBitcast, source, "bitcast"};
if (str == "bool")
}
if (str == "bool") {
return {Token::Type::kBool, source, "bool"};
if (str == "break")
}
if (str == "break") {
return {Token::Type::kBreak, source, "break"};
if (str == "case")
}
if (str == "case") {
return {Token::Type::kCase, source, "case"};
if (str == "continue")
}
if (str == "continue") {
return {Token::Type::kContinue, source, "continue"};
if (str == "continuing")
}
if (str == "continuing") {
return {Token::Type::kContinuing, source, "continuing"};
if (str == "discard")
}
if (str == "discard") {
return {Token::Type::kDiscard, source, "discard"};
if (str == "default")
}
if (str == "default") {
return {Token::Type::kDefault, source, "default"};
if (str == "else")
}
if (str == "else") {
return {Token::Type::kElse, source, "else"};
if (str == "enable")
}
if (str == "enable") {
return {Token::Type::kEnable, source, "enable"};
if (str == "f16")
}
if (str == "f16") {
return {Token::Type::kF16, source, "f16"};
if (str == "f32")
}
if (str == "f32") {
return {Token::Type::kF32, source, "f32"};
if (str == "fallthrough")
}
if (str == "fallthrough") {
return {Token::Type::kFallthrough, source, "fallthrough"};
if (str == "false")
}
if (str == "false") {
return {Token::Type::kFalse, source, "false"};
if (str == "fn")
}
if (str == "fn") {
return {Token::Type::kFn, source, "fn"};
if (str == "for")
}
if (str == "for") {
return {Token::Type::kFor, source, "for"};
if (str == "function")
}
if (str == "function") {
return {Token::Type::kFunction, source, "function"};
if (str == "i32")
}
if (str == "i32") {
return {Token::Type::kI32, source, "i32"};
if (str == "if")
}
if (str == "if") {
return {Token::Type::kIf, source, "if"};
if (str == "import")
}
if (str == "import") {
return {Token::Type::kImport, source, "import"};
if (str == "let")
}
if (str == "let") {
return {Token::Type::kLet, source, "let"};
if (str == "loop")
}
if (str == "loop") {
return {Token::Type::kLoop, source, "loop"};
if (str == "mat2x2")
}
if (str == "mat2x2") {
return {Token::Type::kMat2x2, source, "mat2x2"};
if (str == "mat2x3")
}
if (str == "mat2x3") {
return {Token::Type::kMat2x3, source, "mat2x3"};
if (str == "mat2x4")
}
if (str == "mat2x4") {
return {Token::Type::kMat2x4, source, "mat2x4"};
if (str == "mat3x2")
}
if (str == "mat3x2") {
return {Token::Type::kMat3x2, source, "mat3x2"};
if (str == "mat3x3")
}
if (str == "mat3x3") {
return {Token::Type::kMat3x3, source, "mat3x3"};
if (str == "mat3x4")
}
if (str == "mat3x4") {
return {Token::Type::kMat3x4, source, "mat3x4"};
if (str == "mat4x2")
}
if (str == "mat4x2") {
return {Token::Type::kMat4x2, source, "mat4x2"};
if (str == "mat4x3")
}
if (str == "mat4x3") {
return {Token::Type::kMat4x3, source, "mat4x3"};
if (str == "mat4x4")
}
if (str == "mat4x4") {
return {Token::Type::kMat4x4, source, "mat4x4"};
if (str == "override")
}
if (str == "override") {
return {Token::Type::kOverride, source, "override"};
if (str == "private")
}
if (str == "private") {
return {Token::Type::kPrivate, source, "private"};
if (str == "ptr")
}
if (str == "ptr") {
return {Token::Type::kPtr, source, "ptr"};
if (str == "return")
}
if (str == "return") {
return {Token::Type::kReturn, source, "return"};
if (str == "sampler")
}
if (str == "sampler") {
return {Token::Type::kSampler, source, "sampler"};
if (str == "sampler_comparison")
}
if (str == "sampler_comparison") {
return {Token::Type::kComparisonSampler, source, "sampler_comparison"};
if (str == "storage_buffer" || str == "storage")
}
if (str == "storage_buffer" || str == "storage") {
return {Token::Type::kStorage, source, "storage"};
if (str == "struct")
}
if (str == "struct") {
return {Token::Type::kStruct, source, "struct"};
if (str == "switch")
}
if (str == "switch") {
return {Token::Type::kSwitch, source, "switch"};
if (str == "texture_1d")
}
if (str == "texture_1d") {
return {Token::Type::kTextureSampled1d, source, "texture_1d"};
if (str == "texture_2d")
}
if (str == "texture_2d") {
return {Token::Type::kTextureSampled2d, source, "texture_2d"};
if (str == "texture_2d_array")
}
if (str == "texture_2d_array") {
return {Token::Type::kTextureSampled2dArray, source, "texture_2d_array"};
if (str == "texture_3d")
}
if (str == "texture_3d") {
return {Token::Type::kTextureSampled3d, source, "texture_3d"};
if (str == "texture_cube")
}
if (str == "texture_cube") {
return {Token::Type::kTextureSampledCube, source, "texture_cube"};
}
if (str == "texture_cube_array") {
return {Token::Type::kTextureSampledCubeArray, source, "texture_cube_array"};
}
if (str == "texture_depth_2d")
if (str == "texture_depth_2d") {
return {Token::Type::kTextureDepth2d, source, "texture_depth_2d"};
}
if (str == "texture_depth_2d_array") {
return {Token::Type::kTextureDepth2dArray, source, "texture_depth_2d_array"};
}
if (str == "texture_depth_cube")
if (str == "texture_depth_cube") {
return {Token::Type::kTextureDepthCube, source, "texture_depth_cube"};
}
if (str == "texture_depth_cube_array") {
return {Token::Type::kTextureDepthCubeArray, source, "texture_depth_cube_array"};
}
@ -1171,24 +1222,33 @@ Token Lexer::check_keyword(const Source& source, std::string_view str) {
if (str == "texture_storage_3d") {
return {Token::Type::kTextureStorage3d, source, "texture_storage_3d"};
}
if (str == "true")
if (str == "true") {
return {Token::Type::kTrue, source, "true"};
if (str == "type")
}
if (str == "type") {
return {Token::Type::kType, source, "type"};
if (str == "u32")
}
if (str == "u32") {
return {Token::Type::kU32, source, "u32"};
if (str == "uniform")
}
if (str == "uniform") {
return {Token::Type::kUniform, source, "uniform"};
if (str == "var")
}
if (str == "var") {
return {Token::Type::kVar, source, "var"};
if (str == "vec2")
}
if (str == "vec2") {
return {Token::Type::kVec2, source, "vec2"};
if (str == "vec3")
}
if (str == "vec3") {
return {Token::Type::kVec3, source, "vec3"};
if (str == "vec4")
}
if (str == "vec4") {
return {Token::Type::kVec4, source, "vec4"};
if (str == "workgroup")
}
if (str == "workgroup") {
return {Token::Type::kWorkgroup, source, "workgroup"};
}
return {};
}

File diff suppressed because it is too large Load Diff

View File

@ -67,4 +67,3 @@ const char* str(CtorConvIntrinsic i) {
}
} // namespace tint::resolver

View File

@ -34,8 +34,9 @@ Symbol SymbolTable::Register(const std::string& name) {
TINT_ASSERT(Symbol, !name.empty());
auto it = name_to_symbol_.find(name);
if (it != name_to_symbol_.end())
if (it != name_to_symbol_.end()) {
return it->second;
}
#if TINT_SYMBOL_STORE_DEBUG_NAME
Symbol sym(next_symbol_, program_id_, name);

View File

@ -1464,8 +1464,9 @@ bool GeneratorImpl::EmitTextureCall(std::ostream& out,
out << "(";
if (!EmitExpression(out, texture))
if (!EmitExpression(out, texture)) {
return false;
}
out << ", ";
@ -2601,8 +2602,10 @@ bool GeneratorImpl::EmitType(std::ostream& out,
if (storage && storage->access() != ast::Access::kRead) {
out << "writeonly ";
}
auto* subtype =
sampled ? sampled->type() : storage ? storage->type() : ms ? ms->type() : nullptr;
auto* subtype = sampled ? sampled->type()
: storage ? storage->type()
: ms ? ms->type()
: nullptr;
if (!subtype || subtype->Is<sem::F32>()) {
} else if (subtype->Is<sem::I32>()) {
out << "i";

View File

@ -2324,8 +2324,9 @@ bool GeneratorImpl::EmitTextureCall(std::ostream& out,
break;
}
if (!EmitExpression(out, texture))
if (!EmitExpression(out, texture)) {
return false;
}
// If pack_level_in_coords is true, then the mip level will be appended as the
// last value of the coordinates argument. If the WGSL builtin overload does
@ -2397,8 +2398,9 @@ bool GeneratorImpl::EmitTextureCall(std::ostream& out,
}
if (auto* sampler = arg(Usage::kSampler)) {
if (!EmitExpression(out, sampler))
if (!EmitExpression(out, sampler)) {
return false;
}
out << ", ";
}

View File

@ -1043,8 +1043,9 @@ bool GeneratorImpl::EmitTextureCall(std::ostream& out,
}
}
if (!EmitExpression(out, e->Declaration()))
if (!EmitExpression(out, e->Declaration())) {
return false;
}
if (casted) {
out << ")";

View File

@ -55,8 +55,9 @@ const char kGLSLstd450[] = "GLSL.std.450";
uint32_t size_of(const InstructionList& instructions) {
uint32_t size = 0;
for (const auto& inst : instructions)
for (const auto& inst : instructions) {
size += inst.word_length();
}
return size;
}