From 4a94f39020dcc143f9a1d8f5c57ba77a828ead61 Mon Sep 17 00:00:00 2001 From: Tim Foley Date: Tue, 15 Aug 2017 09:29:52 -0700 Subject: Improve diagnostics for overlapping/conflicting bindings Closes #38 - Change overlapping bindings case from error to warning (it is *technically* allowed in HLSL/GLSL) - Make diagnostic messages for these cases include a note to point at the "other" declaration in each case, so that user can more easily isolate the problem - Unrelated fix: make sure `slangc` sets up its diagnostic callback *before* parsing command-line options so that error messages output during options parsing will be visible - Unrelated fix: make sure that formatting for diagnostic messages doesn't print diagnostic ID for notes (all have IDs < 0). - Note: eventually I'd like to not print diagnostic IDs at all (I think they are cluttering up our output), but doing that requires touching all the test cases... --- source/slang/parameter-binding.cpp | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'source/slang/parameter-binding.cpp') diff --git a/source/slang/parameter-binding.cpp b/source/slang/parameter-binding.cpp index 757662101..a00520c05 100644 --- a/source/slang/parameter-binding.cpp +++ b/source/slang/parameter-binding.cpp @@ -735,6 +735,7 @@ static RefPtr findUsedRangeSetForTranslationUnit( static void addExplicitParameterBinding( ParameterBindingContext* context, RefPtr parameterInfo, + VarDeclBase* varDecl, LayoutSemanticInfo const& semanticInfo, UInt count, RefPtr usedRangeSet = nullptr) @@ -751,8 +752,13 @@ static void addExplicitParameterBinding( || bindingInfo.index != semanticInfo.index || bindingInfo.space != semanticInfo.space ) { + getSink(context)->diagnose(varDecl, Diagnostics::conflictingExplicitBindingsForParameter, getReflectionName(varDecl)); + auto firstVarDecl = parameterInfo->varLayouts[0]->varDecl.getDecl(); - getSink(context)->diagnose(firstVarDecl, Diagnostics::conflictingExplicitBindingsForParameter, getReflectionName(firstVarDecl)); + if( firstVarDecl != varDecl ) + { + getSink(context)->diagnose(firstVarDecl, Diagnostics::seeOtherDeclarationOf, getReflectionName(firstVarDecl)); + } } // TODO(tfoley): `register` semantics can technically be @@ -781,6 +787,8 @@ static void addExplicitParameterBinding( getSink(context)->diagnose(paramA, Diagnostics::parameterBindingsOverlap, getReflectionName(paramA), getReflectionName(paramB)); + + getSink(context)->diagnose(paramB, Diagnostics::seeDeclarationOf, getReflectionName(paramB)); } } } @@ -822,7 +830,7 @@ static void addExplicitParameterBindings_HLSL( // TODO: warning here! } - addExplicitParameterBinding(context, parameterInfo, semanticInfo, count); + addExplicitParameterBinding(context, parameterInfo, varDecl, semanticInfo, count); } } @@ -888,7 +896,7 @@ static void addExplicitParameterBindings_GLSL( auto count = resInfo->count; semanticInfo.kind = kind; - addExplicitParameterBinding(context, parameterInfo, semanticInfo, int(count), usedRangeSet); + addExplicitParameterBinding(context, parameterInfo, varDecl, semanticInfo, int(count), usedRangeSet); } // Given a single parameter, collect whatever information we have on -- cgit v1.2.3