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 | |
| parent | afe41a6c994a684cd646b4432a285ef959d0716b (diff) | |
| parent | d601921b71ed44835e8d4fa6f13ff7aefcf7649d (diff) | |
Merge pull request #48 from tfoleyNV/literal-suffix-fix
Fix handling of literal suffixes
Diffstat (limited to 'source')
| -rw-r--r-- | source/slang/check.cpp | 4 | ||||
| -rw-r--r-- | source/slang/diagnostic-defs.h | 3 | ||||
| -rw-r--r-- | source/slang/emit.cpp | 43 | ||||
| -rw-r--r-- | source/slang/lexer.cpp | 230 | ||||
| -rw-r--r-- | source/slang/lexer.h | 6 | ||||
| -rw-r--r-- | source/slang/parser.cpp | 166 | ||||
| -rw-r--r-- | source/slang/preprocessor.cpp | 18 | ||||
| -rw-r--r-- | source/slang/syntax.cpp | 5 | ||||
| -rw-r--r-- | source/slang/syntax.h | 4 | ||||
| -rw-r--r-- | source/slang/token-defs.h | 8 |
10 files changed, 435 insertions, 52 deletions
diff --git a/source/slang/check.cpp b/source/slang/check.cpp index 11efb2f7d..dfa726150 100644 --- a/source/slang/check.cpp +++ b/source/slang/check.cpp @@ -1887,6 +1887,10 @@ namespace Slang } virtual RefPtr<ExpressionSyntaxNode> VisitConstantExpression(ConstantExpressionSyntaxNode *expr) override { + // The expression might already have a type, determined by its suffix + if(expr->Type.type) + return expr; + switch (expr->ConstType) { case ConstantExpressionSyntaxNode::ConstantType::Int: diff --git a/source/slang/diagnostic-defs.h b/source/slang/diagnostic-defs.h index f92f43ddb..c85270e08 100644 --- a/source/slang/diagnostic-defs.h +++ b/source/slang/diagnostic-defs.h @@ -284,6 +284,9 @@ DIAGNOSTIC(39999, Error, expectedPostfixOperator, "function called as postfix op DIAGNOSTIC(39999, Error, notEnoughArguments, "not enough arguments to call (got $0, expected $1)") DIAGNOSTIC(39999, Error, tooManyArguments, "too many arguments to call (got $0, expected $1)") +DIAGNOSTIC(39999, Error, invalidIntegerLiteralSuffix, "invalid suffix '$0' on integer literal") +DIAGNOSTIC(39999, Error, invalidFloatingPOintLiteralSuffix, "invalid suffix '$0' on floating-point literal") + // // 4xxxx - IL code generation. // 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; diff --git a/source/slang/lexer.cpp b/source/slang/lexer.cpp index f81ead87c..786376baf 100644 --- a/source/slang/lexer.cpp +++ b/source/slang/lexer.cpp @@ -370,7 +370,7 @@ namespace Slang { case 'f': case 'F': advance(lexer); - return TokenType::DoubleLiterial; + return TokenType::FloatingPointLiteral; default: break; @@ -415,25 +415,34 @@ namespace Slang return tokenType; } - static bool maybeLexNumberExponent(Lexer* lexer, int base) + static bool isNumberExponent(char c, int base) { - switch( peek(lexer) ) + switch( c ) { default: return false; case 'e': case 'E': if(base != 10) return false; - advance(lexer); break; case 'p': case 'P': if(base != 16) return false; - advance(lexer); break; } - // we saw an exponent marker, so we must + return true; + } + + static bool maybeLexNumberExponent(Lexer* lexer, int base) + { + if(!isNumberExponent(peek(lexer), base)) + return false; + + // we saw an exponent marker + advance(lexer); + + // Now start to read the exponent switch( peek(lexer) ) { case '+': case '-': @@ -453,21 +462,21 @@ namespace Slang lexDigits(lexer, base); maybeLexNumberExponent(lexer, base); - return maybeLexNumberSuffix(lexer, TokenType::DoubleLiterial); + return maybeLexNumberSuffix(lexer, TokenType::FloatingPointLiteral); } static TokenType lexNumber(Lexer* lexer, int base) { // TODO(tfoley): Need to consider whehter to allow any kind of digit separator character. - TokenType tokenType = TokenType::IntLiterial; + TokenType tokenType = TokenType::IntegerLiteral; // At the start of things, we just concern ourselves with digits lexDigits(lexer, base); if( peek(lexer) == '.' ) { - tokenType = TokenType::DoubleLiterial; + tokenType = TokenType::FloatingPointLiteral; advance(lexer); lexDigits(lexer, base); @@ -475,13 +484,204 @@ namespace Slang if( maybeLexNumberExponent(lexer, base)) { - tokenType = TokenType::DoubleLiterial; + tokenType = TokenType::FloatingPointLiteral; } maybeLexNumberSuffix(lexer, tokenType); return tokenType; } + static int maybeReadDigit(char const** ioCursor, int base) + { + auto& cursor = *ioCursor; + + for(;;) + { + int digitVal = 0; + int c = *cursor; + switch(c) + { + default: + return -1; + + // TODO: need to decide on digit separator characters + case '_': + cursor++; + continue; + + case '0': case '1': case '2': case '3': case '4': + case '5': case '6': case '7': case '8': case '9': + cursor++; + return c - '0'; + + case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': + if(base > 10) + { + cursor++; + return c - 'a'; + } + return -1; + + case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': + if(base > 10) + { + cursor++; + return c - 'A'; + } + return -1; + } + } + } + + static int readOptionalBase(char const** ioCursor) + { + auto& cursor = *ioCursor; + if( *cursor == '0' ) + { + cursor++; + switch(*cursor) + { + case 'x': case 'X': + cursor++; + return 16; + + case 'b': case 'B': + cursor++; + return 2; + + case '0': case '1': case '2': case '3': case '4': + case '5': case '6': case '7': case '8': case '9': + return 8; + + default: + return 10; + } + } + + return 10; + } + + + + IntegerLiteralValue getIntegerLiteralValue(Token const& token, String* outSuffix) + { + IntegerLiteralValue value = 0; + + char const* cursor = token.Content.begin(); + char const* end = token.Content.end(); + + int base = readOptionalBase(&cursor); + + for( ;;) + { + int digit = maybeReadDigit(&cursor, base); + if(digit < 0) + break; + + value = value*base + digit; + } + + if(outSuffix) + { + *outSuffix = String(cursor, end); + } + + return value; + } + + FloatingPointLiteralValue getFloatingPointLiteralValue(Token const& token, String* outSuffix) + { + FloatingPointLiteralValue value = 0; + + char const* cursor = token.Content.begin(); + char const* end = token.Content.end(); + + int radix = readOptionalBase(&cursor); + + bool seenDot = false; + FloatingPointLiteralValue divisor = 1; + for( ;;) + { + if(*cursor == '.') + { + cursor++; + seenDot = true; + continue; + } + + int digit = maybeReadDigit(&cursor, radix); + if(digit < 0) + break; + + value = value*radix + digit; + + if(seenDot) + { + divisor *= radix; + } + } + + // Now read optional exponent + if(isNumberExponent(*cursor, radix)) + { + cursor++; + + bool exponentIsNegative = false; + switch(*cursor) + { + default: + break; + + case '-': + exponentIsNegative = true; + cursor++; + break; + + case '+': + cursor++; + break; + } + + int exponentRadix = 10; + int exponent = 0; + + for(;;) + { + int digit = maybeReadDigit(&cursor, exponentRadix); + if(digit < 0) + break; + + exponent = exponent*exponentRadix + digit; + } + + FloatingPointLiteralValue exponentBase = 10; + if(radix == 16) + { + exponentBase = 2; + } + + FloatingPointLiteralValue exponentValue = pow(exponentBase, exponent); + + if( exponentIsNegative ) + { + divisor *= exponentValue; + } + else + { + value *= exponentValue; + } + } + + value /= divisor; + + if(outSuffix) + { + *outSuffix = String(cursor, end); + } + + return value; + } + static void lexStringLiteralBody(Lexer* lexer, char quote) { for(;;) @@ -575,8 +775,8 @@ namespace Slang String getStringLiteralTokenValue(Token const& token) { - assert(token.Type == TokenType::StringLiterial - || token.Type == TokenType::CharLiterial); + assert(token.Type == TokenType::StringLiteral + || token.Type == TokenType::CharLiteral); char const* cursor = token.Content.begin(); char const* end = token.Content.end(); @@ -758,7 +958,7 @@ namespace Slang switch(peek(lexer)) { default: - return TokenType::IntLiterial; + return TokenType::IntegerLiteral; case '.': advance(lexer); @@ -798,12 +998,12 @@ namespace Slang case '\"': advance(lexer); lexStringLiteralBody(lexer, '\"'); - return TokenType::StringLiterial; + return TokenType::StringLiteral; case '\'': advance(lexer); lexStringLiteralBody(lexer, '\''); - return TokenType::CharLiterial; + return TokenType::CharLiteral; case '+': advance(lexer); diff --git a/source/slang/lexer.h b/source/slang/lexer.h index 5bcfc0f4a..53bfc0999 100644 --- a/source/slang/lexer.h +++ b/source/slang/lexer.h @@ -91,6 +91,12 @@ namespace Slang // Helper routines for extracting values from tokens String getStringLiteralTokenValue(Token const& token); String getFileNameTokenValue(Token const& token); + + typedef unsigned long long IntegerLiteralValue; + typedef double FloatingPointLiteralValue; + + IntegerLiteralValue getIntegerLiteralValue(Token const& token, String* outSuffix = 0); + FloatingPointLiteralValue getFloatingPointLiteralValue(Token const& token, String* outSuffix = 0); } #endif
\ No newline at end of file diff --git a/source/slang/parser.cpp b/source/slang/parser.cpp index 3ffbc1263..6437deca2 100644 --- a/source/slang/parser.cpp +++ b/source/slang/parser.cpp @@ -630,7 +630,7 @@ namespace Slang modifier->Position = loc; parser->ReadToken(TokenType::LParent); - if (parser->LookAheadToken(TokenType::IntLiterial)) + if (parser->LookAheadToken(TokenType::IntegerLiteral)) { modifier->op = (IntrinsicOp)StringToInt(parser->ReadToken().Content); } @@ -662,7 +662,7 @@ namespace Slang if( AdvanceIf(parser, TokenType::Comma) ) { - if( parser->LookAheadToken(TokenType::StringLiterial) ) + if( parser->LookAheadToken(TokenType::StringLiteral) ) { modifier->definitionToken = parser->ReadToken(); } @@ -708,7 +708,7 @@ namespace Slang if(AdvanceIf(parser, TokenType::OpAssign)) { - modifier->valToken = parser->ReadToken(TokenType::IntLiterial); + modifier->valToken = parser->ReadToken(TokenType::IntegerLiteral); } AddModifier(&modifierLink, modifier); @@ -726,7 +726,7 @@ namespace Slang { RefPtr<BuiltinTypeModifier> modifier = new BuiltinTypeModifier(); parser->ReadToken(TokenType::LParent); - modifier->tag = BaseType(StringToInt(parser->ReadToken(TokenType::IntLiterial).Content)); + modifier->tag = BaseType(StringToInt(parser->ReadToken(TokenType::IntegerLiteral).Content)); parser->ReadToken(TokenType::RParent); AddModifier(&modifierLink, modifier); @@ -738,7 +738,7 @@ namespace Slang modifier->name = parser->ReadToken(TokenType::Identifier).Content; if (AdvanceIf(parser, TokenType::Comma)) { - modifier->tag = uint32_t(StringToInt(parser->ReadToken(TokenType::IntLiterial).Content)); + modifier->tag = uint32_t(StringToInt(parser->ReadToken(TokenType::IntegerLiteral).Content)); } parser->ReadToken(TokenType::RParent); @@ -807,9 +807,9 @@ namespace Slang auto decl = new ImportDecl(); decl->scope = parser->currentScope; - if (peekTokenType(parser) == TokenType::StringLiterial) + if (peekTokenType(parser) == TokenType::StringLiteral) { - auto nameToken = parser->ReadToken(TokenType::StringLiterial); + auto nameToken = parser->ReadToken(TokenType::StringLiteral); nameToken.Content = getStringLiteralTokenValue(nameToken); decl->nameToken = nameToken; } @@ -3213,34 +3213,153 @@ namespace Slang return initExpr; } - case TokenType::IntLiterial: - case TokenType::DoubleLiterial: + case TokenType::IntegerLiteral: { RefPtr<ConstantExpressionSyntaxNode> constExpr = new ConstantExpressionSyntaxNode(); - auto token = parser->tokenReader.AdvanceToken(); parser->FillPosition(constExpr.Ptr()); - if (token.Type == TokenType::IntLiterial) + + auto token = parser->tokenReader.AdvanceToken(); + constExpr->token = token; + + String suffix; + IntegerLiteralValue value = getIntegerLiteralValue(token, &suffix); + + // Look at any suffix on the value + char const* suffixCursor = suffix.begin(); + + RefPtr<ExpressionType> suffixType = nullptr; + if( suffixCursor && *suffixCursor ) { - constExpr->ConstType = ConstantExpressionSyntaxNode::ConstantType::Int; - constExpr->IntValue = StringToInt(token.Content); + int lCount = 0; + int uCount = 0; + int unknownCount = 0; + while(*suffixCursor) + { + switch( *suffixCursor++ ) + { + case 'l': case 'L': + lCount++; + break; + + case 'u': case 'U': + uCount++; + break; + + default: + unknownCount++; + break; + } + } + + if(unknownCount) + { + parser->sink->diagnose(token, Diagnostics::invalidIntegerLiteralSuffix, suffix); + suffixType = ExpressionType::GetError(); + } + // `u` or `ul` suffix -> `uint` + else if(uCount == 1 && (lCount <= 1)) + { + suffixType = ExpressionType::GetUInt(); + } + // `l` suffix on integer -> `int` (== `long`) + else if(lCount == 1 && !uCount) + { + suffixType = ExpressionType::GetInt(); + } + // TODO: probably need `ll` and `ull` + // TODO: are there other suffixes we need to handle? + else + { + parser->sink->diagnose(token, Diagnostics::invalidIntegerLiteralSuffix, suffix); + suffixType = ExpressionType::GetError(); + } } - else if (token.Type == TokenType::DoubleLiterial) + + constExpr->ConstType = ConstantExpressionSyntaxNode::ConstantType::Int; + constExpr->IntValue = value; + constExpr->Type = suffixType; + + return constExpr; + } + + + case TokenType::FloatingPointLiteral: + { + RefPtr<ConstantExpressionSyntaxNode> constExpr = new ConstantExpressionSyntaxNode(); + parser->FillPosition(constExpr.Ptr()); + + auto token = parser->tokenReader.AdvanceToken(); + constExpr->token = token; + + String suffix; + FloatingPointLiteralValue value = getFloatingPointLiteralValue(token, &suffix); + + // Look at any suffix on the value + char const* suffixCursor = suffix.begin(); + + RefPtr<ExpressionType> suffixType = nullptr; + if( suffixCursor && *suffixCursor ) { - constExpr->ConstType = ConstantExpressionSyntaxNode::ConstantType::Float; - constExpr->FloatValue = (FloatingPointLiteralValue) StringToDouble(token.Content); + int fCount = 0; + int lCount = 0; + int unknownCount = 0; + while(*suffixCursor) + { + switch( *suffixCursor++ ) + { + case 'f': case 'F': + fCount++; + break; + + case 'l': case 'L': + lCount++; + break; + + default: + unknownCount++; + break; + } + } + + if(unknownCount) + { + parser->sink->diagnose(token, Diagnostics::invalidFloatingPOintLiteralSuffix, suffix); + suffixType = ExpressionType::GetError(); + } + // `f` suffix -> `float` + if(fCount == 1 && !lCount) + { + suffixType = ExpressionType::GetFloat(); + } + // `l` or `lf` suffix on float -> `double` + else if(lCount == 1 && (fCount <= 1)) + { + suffixType = ExpressionType::getDoubleType(); + } + // TODO: are there other suffixes we need to handle? + else + { + parser->sink->diagnose(token, Diagnostics::invalidFloatingPOintLiteralSuffix, suffix); + suffixType = ExpressionType::GetError(); + } } + constExpr->ConstType = ConstantExpressionSyntaxNode::ConstantType::Float; + constExpr->FloatValue = value; + constExpr->Type = suffixType; + return constExpr; } - case TokenType::StringLiterial: + case TokenType::StringLiteral: { RefPtr<ConstantExpressionSyntaxNode> constExpr = new ConstantExpressionSyntaxNode(); auto token = parser->tokenReader.AdvanceToken(); + constExpr->token = token; parser->FillPosition(constExpr.Ptr()); constExpr->ConstType = ConstantExpressionSyntaxNode::ConstantType::String; - if (!parser->LookAheadToken(TokenType::StringLiterial)) + if (!parser->LookAheadToken(TokenType::StringLiteral)) { // Easy/common case: a single string constExpr->stringValue = getStringLiteralTokenValue(token); @@ -3249,7 +3368,7 @@ namespace Slang { StringBuilder sb; sb << getStringLiteralTokenValue(token); - while (parser->LookAheadToken(TokenType::StringLiterial)) + while (parser->LookAheadToken(TokenType::StringLiteral)) { token = parser->tokenReader.AdvanceToken(); sb << getStringLiteralTokenValue(token); @@ -3269,6 +3388,7 @@ namespace Slang { RefPtr<ConstantExpressionSyntaxNode> constExpr = new ConstantExpressionSyntaxNode(); auto token = parser->tokenReader.AdvanceToken(); + constExpr->token = token; parser->FillPosition(constExpr.Ptr()); constExpr->ConstType = ConstantExpressionSyntaxNode::ConstantType::Bool; constExpr->IntValue = token.Content == "true" ? 1 : 0; @@ -3467,18 +3587,18 @@ namespace Slang rs = initExpr; } - else if (LookAheadToken(TokenType::IntLiterial) || - LookAheadToken(TokenType::DoubleLiterial)) + else if (LookAheadToken(TokenType::IntegerLiteral) || + LookAheadToken(TokenType::FloatingPointLiteral)) { RefPtr<ConstantExpressionSyntaxNode> constExpr = new ConstantExpressionSyntaxNode(); auto token = tokenReader.AdvanceToken(); FillPosition(constExpr.Ptr()); - if (token.Type == TokenType::IntLiterial) + if (token.Type == TokenType::IntegerLiteral) { constExpr->ConstType = ConstantExpressionSyntaxNode::ConstantType::Int; constExpr->IntValue = StringToInt(token.Content); } - else if (token.Type == TokenType::DoubleLiterial) + else if (token.Type == TokenType::FloatingPointLiteral) { constExpr->ConstType = ConstantExpressionSyntaxNode::ConstantType::Float; constExpr->FloatValue = (FloatingPointLiteralValue) StringToDouble(token.Content); diff --git a/source/slang/preprocessor.cpp b/source/slang/preprocessor.cpp index 084f518fb..f84355018 100644 --- a/source/slang/preprocessor.cpp +++ b/source/slang/preprocessor.cpp @@ -1083,7 +1083,7 @@ static PreprocessorExpressionValue ParseAndEvaluateUnaryExpression(PreprocessorD return value; } - case TokenType::IntLiterial: + case TokenType::IntegerLiteral: return StringToInt(AdvanceToken(context).Content); case TokenType::Identifier: @@ -1488,7 +1488,7 @@ static void HandleImportDirective(PreprocessorDirectiveContext* context); static void HandleIncludeDirective(PreprocessorDirectiveContext* context) { Token pathToken; - if(!Expect(context, TokenType::StringLiterial, Diagnostics::expectedTokenInPreprocessorDirective, &pathToken)) + if(!Expect(context, TokenType::StringLiteral, Diagnostics::expectedTokenInPreprocessorDirective, &pathToken)) return; String path = getFileNameTokenValue(pathToken); @@ -1656,7 +1656,7 @@ static void HandleErrorDirective(PreprocessorDirectiveContext* context) static void HandleLineDirective(PreprocessorDirectiveContext* context) { int line = 0; - if (PeekTokenType(context) == TokenType::IntLiterial) + if (PeekTokenType(context) == TokenType::IntegerLiteral) { line = StringToInt(AdvanceToken(context).Content); } @@ -1672,7 +1672,7 @@ static void HandleLineDirective(PreprocessorDirectiveContext* context) else { GetSink(context)->diagnose(PeekLoc(context), Diagnostics::expected2TokensInPreprocessorDirective, - TokenType::IntLiterial, + TokenType::IntegerLiteral, "default", GetDirectiveName(context)); context->parseError = true; @@ -1686,11 +1686,11 @@ static void HandleLineDirective(PreprocessorDirectiveContext* context) { file = directiveLoc.FileName; } - else if (PeekTokenType(context) == TokenType::StringLiterial) + else if (PeekTokenType(context) == TokenType::StringLiteral) { file = AdvanceToken(context).Content; } - else if (PeekTokenType(context) == TokenType::IntLiterial) + else if (PeekTokenType(context) == TokenType::IntegerLiteral) { // Note(tfoley): GLSL allows the "source string" to be indicated by an integer // TODO(tfoley): Figure out a better way to handle this, if it matters @@ -1698,7 +1698,7 @@ static void HandleLineDirective(PreprocessorDirectiveContext* context) } else { - Expect(context, TokenType::StringLiterial, Diagnostics::expectedTokenInPreprocessorDirective); + Expect(context, TokenType::StringLiteral, Diagnostics::expectedTokenInPreprocessorDirective); return; } @@ -1723,7 +1723,7 @@ static void handleGLSLVersionDirective(PreprocessorDirectiveContext* context) Token versionNumberToken; if(!ExpectRaw( context, - TokenType::IntLiterial, + TokenType::IntegerLiteral, Diagnostics::expectedTokenInPreprocessorDirective, &versionNumberToken)) { @@ -2090,7 +2090,7 @@ TokenList preprocessSource( static void HandleImportDirective(PreprocessorDirectiveContext* context) { Token pathToken; - if(!Expect(context, TokenType::StringLiterial, Diagnostics::expectedTokenInPreprocessorDirective, &pathToken)) + if(!Expect(context, TokenType::StringLiteral, Diagnostics::expectedTokenInPreprocessorDirective, &pathToken)) return; String path = getFileNameTokenValue(pathToken); diff --git a/source/slang/syntax.cpp b/source/slang/syntax.cpp index f78d3c8ec..6b9a74f7d 100644 --- a/source/slang/syntax.cpp +++ b/source/slang/syntax.cpp @@ -1397,6 +1397,11 @@ namespace Slang return sBuiltinTypes[(int)BaseType::Float].GetValue().Ptr(); } + ExpressionType* ExpressionType::getDoubleType() + { + return sBuiltinTypes[(int)BaseType::Double].GetValue().Ptr(); + } + ExpressionType* ExpressionType::GetInt() { return sBuiltinTypes[(int)BaseType::Int].GetValue().Ptr(); 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, diff --git a/source/slang/token-defs.h b/source/slang/token-defs.h index 0fe833e36..08f67f996 100644 --- a/source/slang/token-defs.h +++ b/source/slang/token-defs.h @@ -21,10 +21,10 @@ TOKEN(EndOfFile, "end of file") TOKEN(EndOfDirective, "end of line") TOKEN(Invalid, "invalid character") TOKEN(Identifier, "identifier") -TOKEN(IntLiterial, "integer literal") -TOKEN(DoubleLiterial, "floating-point literal") -TOKEN(StringLiterial, "string literal") -TOKEN(CharLiterial, "character literal") +TOKEN(IntegerLiteral, "integer literal") +TOKEN(FloatingPointLiteral, "floating-point literal") +TOKEN(StringLiteral, "string literal") +TOKEN(CharLiteral, "character literal") TOKEN(WhiteSpace, "whitespace") TOKEN(NewLine, "newline") TOKEN(LineComment, "line comment") |
