From 50a79aee4c53c4198bae38c7ff447133a043aacc Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Mon, 8 Mar 2021 22:14:41 +0200 Subject: [PATCH] Sort diagnostics according to their provoking location --- source/glsl/compiler.cpp | 17 +++++++++++++++++ source/glsl/compiler.h | 2 ++ 2 files changed, 19 insertions(+) diff --git a/source/glsl/compiler.cpp b/source/glsl/compiler.cpp index e46e5401..9c1238c0 100644 --- a/source/glsl/compiler.cpp +++ b/source/glsl/compiler.cpp @@ -293,6 +293,8 @@ bool Compiler::validate(Stage &stage) ReferenceValidator().apply(stage); ExpressionValidator().apply(stage); + stable_sort(stage.diagnostics, &diagnostic_line_order); + for(vector::const_iterator i=stage.diagnostics.begin(); i!=stage.diagnostics.end(); ++i) if(i->severity==Diagnostic::ERR) return false; @@ -300,6 +302,21 @@ bool Compiler::validate(Stage &stage) return true; } +bool Compiler::diagnostic_line_order(const Diagnostic &diag1, const Diagnostic &diag2) +{ + if(diag1.provoking_source!=diag2.provoking_source) + { + // Sort builtins first and imported modules according to import order. + if(diag1.provoking_source<=BUILTIN_SOURCE) + return diag1.provoking_sourcediag2.provoking_source; + } + return diag1.provoking_line