From d601921b71ed44835e8d4fa6f13ff7aefcf7649d Mon Sep 17 00:00:00 2001 From: Tim Foley Date: Wed, 28 Jun 2017 10:20:16 -0700 Subject: Actually respect suffixes on numeric literals. - Add logic to extract the value and suffix from a numeric literal - This duplicates some of the lexing logic, but this is hard to avoid without redundant runtime work - Note that I'm not using and stdlib string-to-number code. This should be more robust once it is working, but it is obviously error prone in the near term. The main up-sides to this are: - We can handle binary integer literals - We can handle hexadecimal floating-point literals without stdlib support - We can hypothetically support digit separators, if we ever wanted - The parser looks at the suffix characters sliced off by the lexer, and tries to pick a type to use for a literal - It uses `NULL` if there is no suffix, to avoid some nasty order dependencies where the stdlib might need to parse a number before it has seen the definition of `int` - Right now I only handle a few cases, so there may be bugs lurking here - The emit logic needs to handle the fact that a literal node in the AST might have a non-default type attached. - Right now I just quickly check for the most likely types, and emit the literal with a matching suffix. This doesn't seem robust if any source language supports a suffix for a type where a target has no corresponding suffix. In the long term some amount of casting is probably required. --- source/slang/syntax.h | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'source/slang/syntax.h') diff --git a/source/slang/syntax.h b/source/slang/syntax.h index 7289719f4..81d6f8e01 100644 --- a/source/slang/syntax.h +++ b/source/slang/syntax.h @@ -375,6 +375,7 @@ namespace Slang UInt, UInt64, Float, + Double, #if 0 Texture2D = 48, TextureCube = 49, @@ -485,6 +486,7 @@ namespace Slang static ExpressionType* GetBool(); static ExpressionType* GetFloat(); + static ExpressionType* getDoubleType(); static ExpressionType* GetInt(); static ExpressionType* GetUInt(); static ExpressionType* GetVoid(); @@ -1916,6 +1918,8 @@ namespace Slang class ConstantExpressionSyntaxNode : public ExpressionSyntaxNode { public: + Token token; + enum class ConstantType { Int, -- cgit v1.2.3