From: Mikko Rasa Date: Mon, 8 Mar 2021 20:13:55 +0000 (+0200) Subject: Record information of the provoking location of a diagnostic X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=d18df036b247f7f0978b547bb8ea1d624af2c4b2;p=libs%2Fgl.git Record information of the provoking location of a diagnostic In case of diagnostics providing extra information to a previous one, this can be different from the direct location. --- diff --git a/source/glsl/glsl_error.h b/source/glsl/glsl_error.h index 46854744..84aa2f52 100644 --- a/source/glsl/glsl_error.h +++ b/source/glsl/glsl_error.h @@ -50,6 +50,8 @@ struct Diagnostic Severity severity; int source; unsigned line; + int provoking_source; + unsigned provoking_line; std::string message; Diagnostic(): severity(INFO), source(-2), line(0) { } diff --git a/source/glsl/validate.cpp b/source/glsl/validate.cpp index 4523b746..ea2e956d 100644 --- a/source/glsl/validate.cpp +++ b/source/glsl/validate.cpp @@ -11,17 +11,29 @@ namespace GL { namespace SL { Validator::Validator(): - stage(0) + stage(0), + last_provoker(0) { } -void Validator::diagnose(Node &node, Diagnostic::Severity severity, const string &message) +void Validator::diagnose(Node &node, Node &provoking_node, Diagnostic::Severity severity, const string &message) { Diagnostic diag; diag.severity = severity; diag.source = node.source; diag.line = node.line; + diag.provoking_source = provoking_node.source; + diag.provoking_line = provoking_node.line; diag.message = message; stage->diagnostics.push_back(diag); + + last_provoker = &provoking_node; +} + +void Validator::add_info(Node &node, const string &message) +{ + if(!last_provoker) + throw logic_error("Tried to add info without a previous provoker"); + diagnose(node, *last_provoker, Diagnostic::INFO, message); } @@ -83,7 +95,7 @@ DeclarationValidator::DeclarationValidator(): void DeclarationValidator::multiple_definition(const string &name, Statement &statement, Statement &previous) { error(statement, format("Multiple definition of %s", name)); - diagnose(previous, Diagnostic::INFO, "Previous definition is here"); + add_info(previous, "Previous definition is here"); } Statement *DeclarationValidator::find_definition(const string &name) diff --git a/source/glsl/validate.h b/source/glsl/validate.h index b6497327..9477b67d 100644 --- a/source/glsl/validate.h +++ b/source/glsl/validate.h @@ -14,11 +14,14 @@ class Validator: protected TraversingVisitor { protected: Stage *stage; + Node *last_provoker; Validator(); - void diagnose(Node &, Diagnostic::Severity, const std::string &); + void diagnose(Node &, Node &, Diagnostic::Severity, const std::string &); + void diagnose(Node &n, Diagnostic::Severity s, const std::string &m) { diagnose(n, n, s, m); } void error(Node &n, const std::string &m) { diagnose(n, Diagnostic::ERR, m); } + void add_info(Node &, const std::string &); }; class TypeValidator: private Validator