]> git.tdb.fi Git - libs/gl.git/commitdiff
Sort diagnostics according to their provoking location
authorMikko Rasa <tdb@tdb.fi>
Mon, 8 Mar 2021 20:14:41 +0000 (22:14 +0200)
committerMikko Rasa <tdb@tdb.fi>
Tue, 9 Mar 2021 08:15:11 +0000 (10:15 +0200)
source/glsl/compiler.cpp
source/glsl/compiler.h

index e46e5401a8fbe452e8175cc622545d7f52caf6f7..9c1238c029eec1155957b105748ae078767a4437 100644 (file)
@@ -293,6 +293,8 @@ bool Compiler::validate(Stage &stage)
        ReferenceValidator().apply(stage);
        ExpressionValidator().apply(stage);
 
+       stable_sort(stage.diagnostics, &diagnostic_line_order);
+
        for(vector<Diagnostic>::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_source<diag2.provoking_source;
+               else if(diag2.provoking_source<=BUILTIN_SOURCE)
+                       return false;
+               else
+                       return diag1.provoking_source>diag2.provoking_source;
+       }
+       return diag1.provoking_line<diag2.provoking_line;
+}
+
 Compiler::OptimizeResult Compiler::optimize(Stage &stage)
 {
        ConstantConditionEliminator().apply(stage);
index 6448ae6cfa6fe962dc5097ffcf2011f835ebbaf9..5104388870f5a22bbfff775d843ce9ab095f2bbf 100644 (file)
@@ -133,6 +133,8 @@ private:
 
        bool validate(Stage &);
 
+       static bool diagnostic_line_order(const Diagnostic &, const Diagnostic &);
+
        /** Applies optimizations to a stage.  The return value indicates which
        stage should be optimized next. */
        OptimizeResult optimize(Stage &);