From f65d756bff8d4c5cbc15bd0322a2ae8e6b896a21 Mon Sep 17 00:00:00 2001 From: Ellie Hermaszewska Date: Tue, 29 Oct 2024 14:49:26 +0800 Subject: format * format * Minor test fixes * enable checking cpp format in ci --- .../compiler-core/slang-perfect-hash-codegen.cpp | 117 +++++++++++---------- 1 file changed, 62 insertions(+), 55 deletions(-) (limited to 'source/compiler-core/slang-perfect-hash-codegen.cpp') diff --git a/source/compiler-core/slang-perfect-hash-codegen.cpp b/source/compiler-core/slang-perfect-hash-codegen.cpp index c09ee4a2c..77f88de15 100644 --- a/source/compiler-core/slang-perfect-hash-codegen.cpp +++ b/source/compiler-core/slang-perfect-hash-codegen.cpp @@ -1,55 +1,62 @@ #include "slang-perfect-hash-codegen.h" + #include "../core/slang-io.h" namespace Slang { - SlangResult writeHashFile( - String outCppPath, - String valueType, - const List includes, - const HashParams& hashParams, - const List values) - { - StringBuilder sb; - StringWriter writer(&sb, WriterFlags(0)); - WriterHelper w(&writer); +SlangResult writeHashFile( + String outCppPath, + String valueType, + const List includes, + const HashParams& hashParams, + const List values) +{ + StringBuilder sb; + StringWriter writer(&sb, WriterFlags(0)); + WriterHelper w(&writer); - w.print("// Hash function for %s\n", valueType.getBuffer()); - w.print("//\n"); - w.print("// This file was thoughtfully generated by a machine,\n"); - w.print("// don't even think about modifying it yourself!\n"); - w.print("//\n"); - w.print("\n"); - for (const auto& i : includes) - { - if (i.getLength()) - w.print("#include \"%s\"\n", i.getBuffer()); - } - w.print("\n"); - w.print("\n"); - w.print("namespace Slang\n"); - w.print("{\n"); - w.print("\n"); + w.print("// Hash function for %s\n", valueType.getBuffer()); + w.print("//\n"); + w.print("// This file was thoughtfully generated by a machine,\n"); + w.print("// don't even think about modifying it yourself!\n"); + w.print("//\n"); + w.print("\n"); + for (const auto& i : includes) + { + if (i.getLength()) + w.print("#include \"%s\"\n", i.getBuffer()); + } + w.print("\n"); + w.print("\n"); + w.print("namespace Slang\n"); + w.print("{\n"); + w.print("\n"); - w.put(perfectHashToEmbeddableCpp( - hashParams, - valueType.getUnownedSlice(), - (String("lookup") + valueType).getUnownedSlice(), - values - ).getBuffer()); + w.put(perfectHashToEmbeddableCpp( + hashParams, + valueType.getUnownedSlice(), + (String("lookup") + valueType).getUnownedSlice(), + values) + .getBuffer()); - w.print("}\n"); + w.print("}\n"); - return File::writeAllTextIfChanged(outCppPath, sb.getUnownedSlice()); - } + return File::writeAllTextIfChanged(outCppPath, sb.getUnownedSlice()); +} - SlangResult writePerfectHashLookupCppFile(String fileName, List opnames, String enumName, String enumerantPrefix, String enumHeaderFile, DiagnosticSink* sink) +SlangResult writePerfectHashLookupCppFile( + String fileName, + List opnames, + String enumName, + String enumerantPrefix, + String enumHeaderFile, + DiagnosticSink* sink) +{ + HashParams hashParams; + auto r = minimalPerfectHash(opnames, hashParams); + switch (r) { - HashParams hashParams; - auto r = minimalPerfectHash(opnames, hashParams); - switch (r) - { - case HashFindResult::UnavoidableHashCollision: + case HashFindResult::UnavoidableHashCollision: { sink->diagnoseRaw( Severity::Error, @@ -58,24 +65,24 @@ namespace Slang "collision for some input words\n"); return SLANG_FAIL; } - case HashFindResult::NonUniqueKeys: + case HashFindResult::NonUniqueKeys: { sink->diagnoseRaw(Severity::Error, "Input word list has duplicates\n"); return SLANG_FAIL; } - case HashFindResult::Success:; - } - - List values; - values.reserve(hashParams.destTable.getCount()); - for (const auto& v : hashParams.destTable) - values.add(enumerantPrefix + v); - return writeHashFile( - fileName, - enumName, - { "core/slang-common.h", "core/slang-string.h", enumHeaderFile }, - hashParams, - values); + case HashFindResult::Success:; } + List values; + values.reserve(hashParams.destTable.getCount()); + for (const auto& v : hashParams.destTable) + values.add(enumerantPrefix + v); + return writeHashFile( + fileName, + enumName, + {"core/slang-common.h", "core/slang-string.h", enumHeaderFile}, + hashParams, + values); } + +} // namespace Slang -- cgit v1.2.3