summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorjsmall-nvidia <jsmall@nvidia.com>2020-05-26 13:53:10 -0400
committerGitHub <noreply@github.com>2020-05-26 13:53:10 -0400
commitb1369040c3d6d6a8704bdb17d9de99f36a108e07 (patch)
tree2761b93946969fe2f505161d3c75e8cabb6107b6 /tools
parentee2ec68596262398b2d77c128f45b3f32a28c35e (diff)
Improvements around hashing (#1355)
* Fields from upper to lower case in slang-ast-decl.h * Lower camel field names in slang-ast-stmt.h * Fix fields in slang-ast-expr.h * slang-ast-type.h make fields lowerCamel. * slang-ast-base.h members functions lowerCamel. * Method names in slang-ast-type.h to lowerCamel. * GetCanonicalType -> getCanonicalType * Substitute -> substitute * Equals -> equals ToString -> toString * ParentDecl -> parentDecl Members -> members * * Make hash code types explicit * Use HashCode as return type of GetHashCode * Added conversion from double to int64_t * Split Stable from other hash functions * toHash32/64 to convert a HashCode to the other styles. GetHashCode32/64 -> getHashCode32/64 GetStableHashCode32/64 -> getStableHashCode32/64 * Other Get/Stable/HashCode32/64 fixes * GetHashCode -> getHashCode * Equals -> equals * CreateCanonicalType -> createCanonicalType * Catches of polymorphic types should be through references otherwise slicing can occur. * Fixes for newer verison of gcc. Fix hashing problem on gcc for Dictionary. * Another fix for GetHashPos * Fix signed issue around GetHashPos
Diffstat (limited to 'tools')
-rw-r--r--tools/gfx/render.h5
-rw-r--r--tools/render-test/bind-location.cpp6
-rw-r--r--tools/render-test/bind-location.h19
-rw-r--r--tools/render-test/shader-input-layout.cpp2
-rw-r--r--tools/slang-test/slang-test-main.cpp18
-rw-r--r--tools/slang-test/slangc-tool.cpp2
6 files changed, 27 insertions, 25 deletions
diff --git a/tools/gfx/render.h b/tools/gfx/render.h
index 423820a0b..1aa932e0e 100644
--- a/tools/gfx/render.h
+++ b/tools/gfx/render.h
@@ -21,10 +21,11 @@ namespace gfx {
using Slang::RefObject;
using Slang::RefPtr;
using Slang::Dictionary;
-using Slang::GetHashCode;
-using Slang::combineHash;
using Slang::List;
+using Slang::getHashCode;
+using Slang::combineHash;
+
typedef SlangResult Result;
// Had to move here, because Options needs types defined here
diff --git a/tools/render-test/bind-location.cpp b/tools/render-test/bind-location.cpp
index da344dc03..4ec590fd5 100644
--- a/tools/render-test/bind-location.cpp
+++ b/tools/render-test/bind-location.cpp
@@ -762,7 +762,7 @@ bool BindLocation::operator==(const ThisType& rhs) const
return (m_bindPointSet && rhs.m_bindPointSet) && (m_bindPointSet->m_points == rhs.m_bindPointSet->m_points);
}
-int BindLocation::GetHashCode() const
+HashCode BindLocation::getHashCode() const
{
if (!m_typeLayout)
{
@@ -770,11 +770,11 @@ int BindLocation::GetHashCode() const
}
if (m_bindPointSet)
{
- return m_bindPointSet->GetHashCode();
+ return m_bindPointSet->getHashCode();
}
else
{
- return Slang::combineHash(Slang::combineHash(m_category, Slang::GetHashCode(m_typeLayout)), m_point.GetHashCode());
+ return Slang::combineHash(Slang::combineHash(m_category, Slang::getHashCode(m_typeLayout)), m_point.getHashCode());
}
}
diff --git a/tools/render-test/bind-location.h b/tools/render-test/bind-location.h
index 0e1e907b8..cfa88cce0 100644
--- a/tools/render-test/bind-location.h
+++ b/tools/render-test/bind-location.h
@@ -91,7 +91,7 @@ struct BindPoint
bool operator==(const ThisType& rhs) const { return m_space == rhs.m_space && m_offset == rhs.m_offset; }
bool operator!=(const ThisType& rhs) const { return !(*this == rhs); }
- int GetHashCode() const { return Slang::combineHash(Slang::GetHashCode(m_space), Slang::GetHashCode(m_offset)); }
+ Slang::HashCode getHashCode() const { return Slang::combineHash(Slang::getHashCode(m_space), Slang::getHashCode(m_offset)); }
BindPoint() = default;
BindPoint(Slang::Index space, size_t offset):m_space(space), m_offset(offset) {}
@@ -157,22 +157,23 @@ struct BindPoints
}
bool operator!=(const ThisType& rhs) const { return !(*this == rhs); }
- int GetHashCode() const
+ Slang::HashCode getHashCode() const
{
- int hash = 0x5435abbc;
+ using namespace Slang;
+ HashCode hash = 0x5435abbc;
int bits = 0;
int bit = 1;
- for (Slang::Index i = 0; i < SLANG_PARAMETER_CATEGORY_COUNT; ++i, bit += bit)
+ for (Index i = 0; i < SLANG_PARAMETER_CATEGORY_COUNT; ++i, bit += bit)
{
const auto& point = m_points[i];
if (point.isValid())
{
- hash = Slang::combineHash(hash, point.GetHashCode());
+ hash = combineHash(hash, point.getHashCode());
bits |= bit;
}
}
// The categories set is important too, so merge that in
- return Slang::combineHash(bits, hash);
+ return combineHash(bits, hash);
}
BindPoint& operator[](SlangParameterCategory category) { return m_points[Slang::Index(category)]; }
@@ -188,7 +189,7 @@ class BindPointSet : public Slang::RefObject
public:
typedef Slang::RefObject Super;
- int GetHashCode() const { return m_points.GetHashCode(); }
+ Slang::HashCode getHashCode() const { return m_points.getHashCode(); }
BindPointSet(const BindPoints& points) :
m_points(points)
@@ -272,7 +273,7 @@ struct BindLocation
bool operator!=(const ThisType& rhs) const { return !(*this == rhs); }
/// Get the hash code
- int GetHashCode() const;
+ Slang::HashCode getHashCode() const;
/// Default Ctor - constructs as invalid
BindLocation() {}
@@ -294,7 +295,7 @@ struct BindLocation
BindPoint m_point; ///< If there isn't a bind point set, this defines the point
/// Holds multiple BindPoints.
- /// To keep invariants (such that GetHashCode and == work), it can only be set if
+ /// To keep invariants (such that getHashCode and == work), it can only be set if
/// there is more than one category. If there is just one, m_category and m_point *MUST* be used.
/// NOTE! Can only be written to if there is a single reference.
Slang::RefPtr<BindPointSet> m_bindPointSet;
diff --git a/tools/render-test/shader-input-layout.cpp b/tools/render-test/shader-input-layout.cpp
index f9d6a60e1..4c68899ef 100644
--- a/tools/render-test/shader-input-layout.cpp
+++ b/tools/render-test/shader-input-layout.cpp
@@ -546,7 +546,7 @@ namespace renderer_test
entries.add(entry);
}
}
- catch (TextFormatException)
+ catch (const TextFormatException&)
{
throw TextFormatException(String("Invalid input syntax at line ") + parser.NextToken().Position.Line);
}
diff --git a/tools/slang-test/slang-test-main.cpp b/tools/slang-test/slang-test-main.cpp
index 7c511a01a..f2b51562e 100644
--- a/tools/slang-test/slang-test-main.cpp
+++ b/tools/slang-test/slang-test-main.cpp
@@ -346,7 +346,7 @@ TestResult gatherTestsForFile(
{
fileContents = Slang::File::readAllText(filePath);
}
- catch (Slang::IOException)
+ catch (const Slang::IOException&)
{
return TestResult::Fail;
}
@@ -1142,7 +1142,7 @@ TestResult runSimpleTest(TestContext* context, TestInput& input)
{
expectedOutput = Slang::File::readAllText(expectedOutputPath);
}
- catch (Slang::IOException)
+ catch (const Slang::IOException&)
{
}
@@ -1291,7 +1291,7 @@ TestResult runReflectionTest(TestContext* context, TestInput& input)
{
expectedOutput = Slang::File::readAllText(expectedOutputPath);
}
- catch (Slang::IOException)
+ catch (const Slang::IOException&)
{
}
@@ -1332,7 +1332,7 @@ String getExpectedOutput(String const& outputStem)
{
expectedOutput = Slang::File::readAllText(expectedOutputPath);
}
- catch (Slang::IOException)
+ catch (const Slang::IOException&)
{
}
@@ -1479,7 +1479,7 @@ static TestResult runCPPCompilerSharedLibrary(TestContext* context, TestInput& i
String expectedOutputPath = outputStem + ".expected";
expectedOutput = Slang::File::readAllText(expectedOutputPath);
}
- catch (Slang::IOException)
+ catch (const Slang::IOException&)
{
}
@@ -1619,7 +1619,7 @@ static TestResult runCPPCompilerExecute(TestContext* context, TestInput& input)
String expectedOutputPath = outputStem + ".expected";
expectedOutput = Slang::File::readAllText(expectedOutputPath);
}
- catch (Slang::IOException)
+ catch (const Slang::IOException&)
{
}
@@ -1709,7 +1709,7 @@ TestResult runCrossCompilerTest(TestContext* context, TestInput& input)
{
Slang::File::writeAllText(expectedOutputPath, expectedOutput);
}
- catch (Slang::IOException)
+ catch (const Slang::IOException&)
{
return TestResult::Fail;
}
@@ -1794,7 +1794,7 @@ TestResult generateHLSLBaseline(
{
Slang::File::writeAllText(expectedOutputPath, expectedOutput);
}
- catch (Slang::IOException)
+ catch (const Slang::IOException&)
{
return TestResult::Fail;
}
@@ -1875,7 +1875,7 @@ static TestResult _runHLSLComparisonTest(
{
expectedOutput = Slang::File::readAllText(expectedOutputPath);
}
- catch (Slang::IOException)
+ catch (const Slang::IOException&)
{
}
diff --git a/tools/slang-test/slangc-tool.cpp b/tools/slang-test/slangc-tool.cpp
index da810fa88..d7043001a 100644
--- a/tools/slang-test/slangc-tool.cpp
+++ b/tools/slang-test/slangc-tool.cpp
@@ -38,7 +38,7 @@ static SlangResult _compile(SlangCompileRequest* compileRequest, int argc, const
res = SLANG_FAILED(res) ? SLANG_E_INTERNAL_FAIL : res;
}
#ifndef _DEBUG
- catch (Exception & e)
+ catch (const Exception& e)
{
StdWriters::getOut().print("internal compiler error: %S\n", e.Message.toWString().begin());
res = SLANG_FAIL;