Path: blob/main_old/src/compiler/translator/Diagnostics.cpp
1693 views
//1// Copyright 2012 The ANGLE Project Authors. All rights reserved.2// Use of this source code is governed by a BSD-style license that can be3// found in the LICENSE file.4//56#include "compiler/translator/Diagnostics.h"78#include "common/debug.h"9#include "compiler/preprocessor/SourceLocation.h"10#include "compiler/translator/Common.h"11#include "compiler/translator/InfoSink.h"1213namespace sh14{1516TDiagnostics::TDiagnostics(TInfoSinkBase &infoSink)17: mInfoSink(infoSink), mNumErrors(0), mNumWarnings(0)18{}1920TDiagnostics::~TDiagnostics() {}2122void TDiagnostics::writeInfo(Severity severity,23const angle::pp::SourceLocation &loc,24const char *reason,25const char *token)26{27switch (severity)28{29case SH_ERROR:30++mNumErrors;31break;32case SH_WARNING:33++mNumWarnings;34break;35default:36UNREACHABLE();37break;38}3940/* VC++ format: file(linenum) : error #: 'token' : extrainfo */41mInfoSink.prefix(severity);42mInfoSink.location(loc.file, loc.line);43mInfoSink << "'" << token << "' : " << reason << "\n";44}4546void TDiagnostics::globalError(const char *message)47{48++mNumErrors;49mInfoSink.prefix(SH_ERROR);50mInfoSink << message << "\n";51}5253void TDiagnostics::error(const angle::pp::SourceLocation &loc,54const char *reason,55const char *token)56{57writeInfo(SH_ERROR, loc, reason, token);58}5960void TDiagnostics::warning(const angle::pp::SourceLocation &loc,61const char *reason,62const char *token)63{64writeInfo(SH_WARNING, loc, reason, token);65}6667void TDiagnostics::error(const TSourceLoc &loc, const char *reason, const char *token)68{69angle::pp::SourceLocation srcLoc;70srcLoc.file = loc.first_file;71srcLoc.line = loc.first_line;72error(srcLoc, reason, token);73}7475void TDiagnostics::warning(const TSourceLoc &loc, const char *reason, const char *token)76{77angle::pp::SourceLocation srcLoc;78srcLoc.file = loc.first_file;79srcLoc.line = loc.first_line;80warning(srcLoc, reason, token);81}8283void TDiagnostics::print(ID id, const angle::pp::SourceLocation &loc, const std::string &text)84{85writeInfo(isError(id) ? SH_ERROR : SH_WARNING, loc, message(id), text.c_str());86}8788void TDiagnostics::resetErrorCount()89{90mNumErrors = 0;91mNumWarnings = 0;92}9394PerformanceDiagnostics::PerformanceDiagnostics(TDiagnostics *diagnostics)95: mDiagnostics(diagnostics)96{97ASSERT(diagnostics);98}99100void PerformanceDiagnostics::warning(const TSourceLoc &loc, const char *reason, const char *token)101{102mDiagnostics->warning(loc, reason, token);103}104105} // namespace sh106107108