summaryrefslogtreecommitdiffstats
path: root/source/slang/slang-emit-cpp.cpp
diff options
context:
space:
mode:
authorjsmall-nvidia <jsmall@nvidia.com>2022-05-27 17:28:05 -0400
committerGitHub <noreply@github.com>2022-05-27 17:28:05 -0400
commit2d3392f22c894957d17dd13486e0565c4ecea89c (patch)
treece4dadbd85a59e52725fa6f92613553cd5b29859 /source/slang/slang-emit-cpp.cpp
parentabb89b3e460e11e8f9a134199c2d559190bfc47e (diff)
Added NativeStringType (#2252)
* #include an absolute path didn't work - because paths were taken to always be relative. * Use TerminatedUnownedStringSlice for literals in output C++. * Remove Escape/Unescape functions used in slang-token-reader.cpp Add target type of 'host-cpp' etc to map to the target types. * Fix some corner cases around string encoding. * Added unit test for string escaping. Fixed some assorted escaping bugs. * Updated test output. * Added decode test. * Stop using hex output, to get around 'greedy' aspect. Use octal instead.
Diffstat (limited to 'source/slang/slang-emit-cpp.cpp')
-rw-r--r--source/slang/slang-emit-cpp.cpp16
1 files changed, 14 insertions, 2 deletions
diff --git a/source/slang/slang-emit-cpp.cpp b/source/slang/slang-emit-cpp.cpp
index 9887f1ba6..482ada394 100644
--- a/source/slang/slang-emit-cpp.cpp
+++ b/source/slang/slang-emit-cpp.cpp
@@ -532,6 +532,11 @@ SlangResult CPPSourceEmitter::calcTypeName(IRType* type, CodeGenTarget target, S
out << "TypeInfo*";
return SLANG_OK;
}
+ case kIROp_NativeStringType:
+ {
+ out << "const char*";
+ return SLANG_OK;
+ }
case kIROp_StringType:
{
out << "String";
@@ -2411,8 +2416,15 @@ bool CPPSourceEmitter::tryEmitInstExprImpl(IRInst* inst, const EmitOpInfo& inOut
}
case kIROp_StringLit:
{
- m_writer->emit("String(");
- m_writer->emit(Slang::Misc::EscapeStringLiteral(as<IRStringLit>(inst)->getStringSlice()));
+ m_writer->emit("toTerminatedSlice(");
+
+ auto handler = StringEscapeUtil::getHandler(StringEscapeUtil::Style::Cpp);
+
+ StringBuilder buf;
+ const auto slice = as<IRStringLit>(inst)->getStringSlice();
+ StringEscapeUtil::appendQuoted(handler, slice, buf);
+ m_writer->emit(buf);
+
m_writer->emit(")");
return true;
}