diff options
| author | Tim Foley <tfoleyNV@users.noreply.github.com> | 2017-06-28 11:26:02 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2017-06-28 11:26:02 -0700 |
| commit | b8e31688c6826475b5199468aedea0bc44c0adc1 (patch) | |
| tree | 79b9227ef038d173d780a440035e616dc31104bb /source/slang/emit.cpp | |
| parent | afe41a6c994a684cd646b4432a285ef959d0716b (diff) | |
| parent | d601921b71ed44835e8d4fa6f13ff7aefcf7649d (diff) | |
Merge pull request #48 from tfoleyNV/literal-suffix-fix
Fix handling of literal suffixes
Diffstat (limited to 'source/slang/emit.cpp')
| -rw-r--r-- | source/slang/emit.cpp | 43 |
1 files changed, 42 insertions, 1 deletions
diff --git a/source/slang/emit.cpp b/source/slang/emit.cpp index 77b0c2fe9..9a1d44641 100644 --- a/source/slang/emit.cpp +++ b/source/slang/emit.cpp @@ -219,6 +219,8 @@ static void Emit(EmitContext* context, double value) Emit(context, buffer); } +static void emitTokenWithLocation(EmitContext* context, Token const& token); + // Expressions // Determine if an expression should not be emitted when it is the base of @@ -487,7 +489,7 @@ static String getStringOrIdentifierTokenValue( case TokenType::Identifier: return token.Content; - case TokenType::StringLiterial: + case TokenType::StringLiteral: return getStringLiteralTokenValue(token); break; } @@ -900,14 +902,53 @@ static void EmitExprWithPrecedence(EmitContext* context, RefPtr<ExpressionSyntax { needClose = MaybeEmitParens(context, outerPrec, kPrecedence_Atomic); + char const* suffix = ""; + auto type = litExpr->Type.type; switch (litExpr->ConstType) { case ConstantExpressionSyntaxNode::ConstantType::Int: + if(!type) + { + // Special case for "rewrite" mode + emitTokenWithLocation(context, litExpr->token); + break; + } + if(type->Equals(ExpressionType::GetInt())) + {} + else if(type->Equals(ExpressionType::GetUInt())) + { + suffix = "u"; + } + else + { + assert(!"unimplemented"); + } Emit(context, litExpr->IntValue); + Emit(context, suffix); break; + + case ConstantExpressionSyntaxNode::ConstantType::Float: + if(!type) + { + // Special case for "rewrite" mode + emitTokenWithLocation(context, litExpr->token); + break; + } + if(type->Equals(ExpressionType::GetFloat())) + {} + else if(type->Equals(ExpressionType::getDoubleType())) + { + suffix = "l"; + } + else + { + assert(!"unimplemented"); + } Emit(context, litExpr->FloatValue); + Emit(context, suffix); break; + case ConstantExpressionSyntaxNode::ConstantType::Bool: Emit(context, litExpr->IntValue ? "true" : "false"); break; |
