diff options
| author | Tim Foley <tfoleyNV@users.noreply.github.com> | 2017-06-26 14:31:31 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2017-06-26 14:31:31 -0700 |
| commit | 8824b102a5dd5ac1f08daedd897b5994b1bf8b6d (patch) | |
| tree | 3669bf42ed6e971cde176cb422beab6c53158e8c /source/slang/emit.cpp | |
| parent | 0259ddb0a72d3b12278404847f6e30b63e97cfc3 (diff) | |
| parent | 7d97d424c0a754ec49cccfc8af6c8983e0d06d80 (diff) | |
Merge pull request #44 from tfoleyNV/string-literal-parsing-fix
Fix parsing of string literals.
Diffstat (limited to 'source/slang/emit.cpp')
| -rw-r--r-- | source/slang/emit.cpp | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/source/slang/emit.cpp b/source/slang/emit.cpp index eae9cd052..699294d84 100644 --- a/source/slang/emit.cpp +++ b/source/slang/emit.cpp @@ -765,6 +765,34 @@ static void emitCallExpr( emitSimpleCallExpr(context, callExpr, outerPrec); } +static void emitStringLiteral( + EmitContext* context, + String const& value) +{ + emit(context, "\""); + for (auto c : value) + { + // TODO: This needs a more complete implementation, + // especially if we want to support Unicode. + + char buffer[] = { c, 0 }; + switch (c) + { + default: + emit(context, buffer); + break; + + case '\"': emit(context, "\\\""); + case '\'': emit(context, "\\\'"); + case '\\': emit(context, "\\\\"); + case '\n': emit(context, "\\n"); + case '\r': emit(context, "\\r"); + case '\t': emit(context, "\\t"); + } + } + emit(context, "\""); +} + static void EmitExprWithPrecedence(EmitContext* context, RefPtr<ExpressionSyntaxNode> expr, int outerPrec) { bool needClose = false; @@ -874,6 +902,9 @@ static void EmitExprWithPrecedence(EmitContext* context, RefPtr<ExpressionSyntax case ConstantExpressionSyntaxNode::ConstantType::Bool: Emit(context, litExpr->IntValue ? "true" : "false"); break; + case ConstantExpressionSyntaxNode::ConstantType::String: + emitStringLiteral(context, litExpr->stringValue); + break; default: assert(!"unreachable"); break; |
