summaryrefslogtreecommitdiffstats
path: root/source/slang/slang-mangle.cpp
diff options
context:
space:
mode:
authorYong He <yonghe@outlook.com>2022-06-22 19:58:34 -0700
committerGitHub <noreply@github.com>2022-06-22 19:58:34 -0700
commit07a380d72a13899a84cbdc35692be7a3d9246dcb (patch)
tree68e77f2e9682b3b7c3debd745604a494439e5b25 /source/slang/slang-mangle.cpp
parente5a75563a1ba2e378353af8b937b8b7bb0fe2c2b (diff)
More Language Server Improvements. (#2289)
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());