summaryrefslogtreecommitdiffstats
path: root/source/slang/slang-mangle.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'source/slang/slang-mangle.cpp')
-rw-r--r--source/slang/slang-mangle.cpp37
1 files changed, 26 insertions, 11 deletions
diff --git a/source/slang/slang-mangle.cpp b/source/slang/slang-mangle.cpp
index ca6dcecd7..c230776db 100644
--- a/source/slang/slang-mangle.cpp
+++ b/source/slang/slang-mangle.cpp
@@ -37,11 +37,8 @@ namespace Slang
context->sb.append(value);
}
- void emitName(
- ManglingContext* context,
- Name* name)
+ void emitNameImpl(ManglingContext* context, UnownedStringSlice str)
{
- String str = getText(name);
Index length = str.getLength();
// If the name consists of only traditional "identifer characters"
@@ -50,10 +47,14 @@ namespace Slang
bool allAllowed = true;
for (auto c : str)
{
- if (('a' <= c) && (c <= 'z')) continue;
- if (('A' <= c) && (c <= 'Z')) continue;
- if (('0' <= c) && (c <= '9')) continue;
- if (c == '_') continue;
+ if (('a' <= c) && (c <= 'z'))
+ continue;
+ if (('A' <= c) && (c <= 'Z'))
+ continue;
+ if (('0' <= c) && (c <= '9'))
+ continue;
+ if (c == '_')
+ continue;
allAllowed = false;
break;
@@ -84,9 +85,8 @@ namespace Slang
//
for (auto c : str)
{
- if (('a' <= c) && (c <= 'z')
- || ('A' <= c) && (c <= 'Z')
- || ('0' <= c) && (c <= '9'))
+ if (('a' <= c) && (c <= 'z') || ('A' <= c) && (c <= 'Z') ||
+ ('0' <= c) && (c <= '9'))
{
encoded.append(c);
}
@@ -119,6 +119,14 @@ namespace Slang
// target, rather than adding complexity here.
}
+ void emitName(
+ ManglingContext* context,
+ Name* name)
+ {
+ String str = getText(name);
+ emitNameImpl(context, str.getUnownedSlice());
+ }
+
void emitVal(
ManglingContext* context,
Val* val);
@@ -593,6 +601,13 @@ namespace Slang
return context.sb.ProduceString();
}
+ String getMangledNameFromNameString(const UnownedStringSlice& name)
+ {
+ ManglingContext context(nullptr);
+ emitNameImpl(&context, name);
+ return context.sb.ProduceString();
+ }
+
String getHashedName(const UnownedStringSlice& mangledName)
{
HashCode64 hash = getStableHashCode64(mangledName.begin(), mangledName.getLength());