summaryrefslogtreecommitdiffstats
path: root/tools/gfx-util/shader-cursor.cpp
diff options
context:
space:
mode:
authorYong He <yonghe@outlook.com>2021-01-19 09:10:15 -0800
committerGitHub <noreply@github.com>2021-01-19 09:10:15 -0800
commitc6fd4a5b35911f0f056f6e924a2dbc86e328cc46 (patch)
treef89f84633ab9c66a8a96c87ae77e6c47e4ab6a29 /tools/gfx-util/shader-cursor.cpp
parent1296c7bb55b14db24308f31cacdda7f7a71fc937 (diff)
Make `ShaderCursor` no longer depend on core. (#1661)
Diffstat (limited to 'tools/gfx-util/shader-cursor.cpp')
-rw-r--r--tools/gfx-util/shader-cursor.cpp39
1 files changed, 19 insertions, 20 deletions
diff --git a/tools/gfx-util/shader-cursor.cpp b/tools/gfx-util/shader-cursor.cpp
index 65cf2f8ac..f80803bdd 100644
--- a/tools/gfx-util/shader-cursor.cpp
+++ b/tools/gfx-util/shader-cursor.cpp
@@ -20,7 +20,7 @@ Result gfx::ShaderCursor::getDereferenced(ShaderCursor& outCursor) const
}
}
-Result ShaderCursor::getField(Slang::UnownedStringSlice const& name, ShaderCursor& outCursor)
+Result ShaderCursor::getField(const char* name, const char* nameEnd, ShaderCursor& outCursor)
{
// If this cursor is invalid, then can't possible fetch a field.
//
@@ -40,7 +40,7 @@ Result ShaderCursor::getField(Slang::UnownedStringSlice const& name, ShaderCurso
//
// If there is no such field, we have an error.
//
- SlangInt fieldIndex = m_typeLayout->findFieldIndexByName(name.begin(), name.end());
+ SlangInt fieldIndex = m_typeLayout->findFieldIndexByName(name, nameEnd);
if (fieldIndex == -1)
return SLANG_E_INVALID_ARG;
@@ -110,7 +110,7 @@ Result ShaderCursor::getField(Slang::UnownedStringSlice const& name, ShaderCurso
// to the *contents* of the constant buffer.
//
ShaderCursor d = getDereferenced();
- return d.getField(name, outCursor);
+ return d.getField(name, nameEnd, outCursor);
}
break;
}
@@ -118,7 +118,7 @@ Result ShaderCursor::getField(Slang::UnownedStringSlice const& name, ShaderCurso
return SLANG_E_INVALID_ARG;
}
-ShaderCursor ShaderCursor::getElement(Slang::Index index)
+ShaderCursor ShaderCursor::getElement(SlangInt index)
{
// TODO: need to auto-dereference various buffer types...
@@ -140,27 +140,25 @@ ShaderCursor ShaderCursor::getElement(Slang::Index index)
}
-static int _peek(Slang::UnownedStringSlice const& slice)
+static int _peek(const char* slice)
{
- const char* b = slice.begin();
- const char* e = slice.end();
- if (b == e)
+ const char* b = slice;
+ if (!b || !*b)
return -1;
return *b;
}
-static int _get(Slang::UnownedStringSlice& slice)
+static int _get(const char*& slice)
{
- const char* b = slice.begin();
- const char* e = slice.end();
- if (b == e)
+ const char* b = slice;
+ if (!b || !*b)
return -1;
auto result = *b++;
- slice = Slang::UnownedStringSlice(b, e);
+ slice = b;
return result;
}
-Result ShaderCursor::followPath(Slang::UnownedStringSlice const& path, ShaderCursor& ioCursor)
+Result ShaderCursor::followPath(const char* path, ShaderCursor& ioCursor)
{
ShaderCursor cursor = ioCursor;
@@ -172,7 +170,7 @@ Result ShaderCursor::followPath(Slang::UnownedStringSlice const& path, ShaderCur
};
int state = ALLOW_NAME | ALLOW_SUBSCRIPT;
- Slang::UnownedStringSlice rest = path;
+ const char* rest = path;
for (;;)
{
int c = _peek(rest);
@@ -194,7 +192,7 @@ Result ShaderCursor::followPath(Slang::UnownedStringSlice const& path, ShaderCur
return SLANG_E_INVALID_ARG;
_get(rest);
- Slang::Index index = 0;
+ SlangInt index = 0;
while (_peek(rest) != ']')
{
int d = _get(rest);
@@ -218,7 +216,7 @@ Result ShaderCursor::followPath(Slang::UnownedStringSlice const& path, ShaderCur
}
else
{
- const char* nameBegin = rest.begin();
+ const char* nameBegin = rest;
for (;;)
{
switch (_peek(rest))
@@ -234,9 +232,10 @@ Result ShaderCursor::followPath(Slang::UnownedStringSlice const& path, ShaderCur
}
break;
}
- char const* nameEnd = rest.begin();
- Slang::UnownedStringSlice name(nameBegin, nameEnd);
- cursor = cursor.getField(name);
+ char const* nameEnd = rest;
+ ShaderCursor newCursor;
+ cursor.getField(nameBegin, nameEnd, newCursor);
+ cursor = newCursor;
state = ALLOW_DOT | ALLOW_SUBSCRIPT;
continue;
}