From 575230b93370fea86ecccb53fba73927280e917b Mon Sep 17 00:00:00 2001 From: Tim Foley Date: Thu, 12 Oct 2017 13:53:42 -0700 Subject: Work towards target-specific function overloads (#210) * Checkpoint: interface conformance work - Add explicit definition of `saturate` for the GLSL target, which calls through to `clamp` - Needed to add explicit initializer to `__BuiltinFloatingPointType` to allow initialization from a single `float`, so that the `saturate` implementation can be sure that it can initialize a `T` from `0.0` or `1.0`. - This triggered errors in overload resolution, because the logic in place could not figure out that the `T` of the outer generic (`saturate()`) conformed to the interface required by the callee. At this point I have the call to the scalar `clamp()` getting past type-checking, but not the vector or matrix cases. * More fixups for overload resolution inside generics - Make sure value parameters are treated the same as type parameters: we only want to solve for the parameters of the generic actually being applied, and not accidentally generate constraints for outer generics (e.g., when checking the body of a generic function). - Make sure that the diagnostics stuff uses the correct source manager when expanding the location of a builtin. * Fixes for function redeclaration - Handle case of redeclaring a generic function - Enumerate siblings in the parent of the *generic* not the parent of the *function* - Add logic to compare generic signatures - When generic signatures match, specialize functions to compatible generic arguments before comparing the function signatures - Fix redeclaration logic to *not* detect prefix/postifx operators as redeclarations of one another - Build an explicit representation of function redeclaration groups - First declaration is the "primary" and others are stored in a linked list - Make overload resolution handle redeclared functions - Only consider the primary declaration and skip others --- source/slang/parser.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'source/slang/parser.cpp') diff --git a/source/slang/parser.cpp b/source/slang/parser.cpp index a0e07ea12..2b6535bef 100644 --- a/source/slang/parser.cpp +++ b/source/slang/parser.cpp @@ -3842,6 +3842,17 @@ namespace Slang return modifier; } + static RefPtr parseSpecializedForTargetModifier(Parser* parser, void* /*userData*/) + { + auto modifier = new SpecializedForTargetModifier(); + if (AdvanceIf(parser, TokenType::LParent)) + { + modifier->targetToken = parser->ReadToken(TokenType::Identifier); + parser->ReadToken(TokenType::RParent); + } + return modifier; + } + static RefPtr parseGLSLExtensionModifier(Parser* parser, void* /*userData*/) { auto modifier = new RequiredGLSLExtensionModifier(); @@ -4057,6 +4068,7 @@ namespace Slang MODIFIER(__intrinsic_op, parseIntrinsicOpModifier); MODIFIER(__target_intrinsic, parseTargetIntrinsicModifier); + MODIFIER(__specialized_for_target, parseSpecializedForTargetModifier); MODIFIER(__glsl_extension, parseGLSLExtensionModifier); MODIFIER(__glsl_version, parseGLSLVersionModifier); -- cgit v1.2.3