source: src/Common/SemanticError.cc @ a16764a6

ADTaaron-thesisarm-ehast-experimentalcleanup-dtorsdeferred_resndemanglerenumforall-pointer-decayjacob/cs343-translationjenkins-sandboxnew-astnew-ast-unique-exprnew-envno_listpersistent-indexerpthread-emulationqualifiedEnumresolv-newwith_gc
Last change on this file since a16764a6 was a16764a6, checked in by Thierry Delisle <tdelisle@…>, 6 years ago

Changed warning system to prepare for toggling warnings

  • Property mode set to 100644
File size: 2.8 KB
RevLine 
[51587aa]1//
2// Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo
3//
4// The contents of this file are covered under the licence agreement in the
5// file "LICENCE" distributed with Cforall.
6//
[3906301]7// SemanticError.cc --
[51587aa]8//
9// Author           : Richard C. Bilson
10// Created On       : Mon May 18 07:44:20 2015
[01aeade]11// Last Modified By : Peter A. Buhr
[9ed4f94]12// Last Modified On : Tue Aug 29 18:17:35 2017
13// Update Count     : 3
[51587aa]14//
[51b7345]15
[9ed4f94]16#include <cstdio>                                                                               // for fileno, stderr
17#include <unistd.h>                                                                             // for isatty
18#include <iostream>                                                                             // for basic_ostream, operator<<, ostream
19#include <list>                                                                                 // for list, _List_iterator
20#include <string>                                                                               // for string, operator<<, operator+, to_string
[51b7345]21
[9ed4f94]22#include "Common/utility.h"                                                             // for to_string, CodeLocation (ptr only)
[51b7345]23#include "SemanticError.h"
24
[a16764a6]25SemanticErrorException::SemanticErrorException( CodeLocation location, std::string error ) {
[d55d7a6]26        append( location, error );
[51b7345]27}
28
[a16764a6]29void SemanticErrorException::append( SemanticErrorException &other ) {
[138e29e]30        errors.splice( errors.end(), other.errors );
[3906301]31}
32
[a16764a6]33void SemanticErrorException::append( CodeLocation location, const std::string & msg ) {
[d55d7a6]34        errors.emplace_back( location, msg );
[51b7345]35}
36
[a16764a6]37bool SemanticErrorException::isEmpty() const {
[01aeade]38        return errors.empty();
[51b7345]39}
40
[a16764a6]41void SemanticErrorException::print() {
[138e29e]42        using std::to_string;
[9ed4f94]43        for( auto err : errors ) {
[a16764a6]44                std::cerr << ErrorHelpers::bold() << err.location << ErrorHelpers::error_str() << ErrorHelpers::reset_font() << err.description << std::endl;
[138e29e]45        }
[51b7345]46}
[01aeade]47
[a16764a6]48void SemanticError( CodeLocation location, std::string error ) {
49        throw SemanticErrorException(location, error);
50}
51
52void SemanticWarningImpl( CodeLocation location, std::string msg ) {
53        std::cerr << ErrorHelpers::bold() << location << ErrorHelpers::warning_str() << ErrorHelpers::reset_font() << msg << std::endl;
54}
55
56//-----------------------------------------------------------------------------
57// Helpers
58namespace ErrorHelpers {
59        const std::string & error_str() {
60                static std::string str = isatty( STDERR_FILENO ) ? "\e[31merror:\e[39m " : "error: ";
61                return str;
62        }
63
64        const std::string & warning_str() {
65                static std::string str = isatty( STDERR_FILENO ) ? "\e[95mwarning:\e[39m " : "warning: ";
66                return str;
67        }
68
69        const std::string & bold_ttycode() {
70                static std::string str = isatty( STDERR_FILENO ) ? "\e[1m" : "";
71                return str;
72        }
73
74        const std::string & reset_font_ttycode() {
75                static std::string str = isatty( STDERR_FILENO ) ? "\e[0m" : "";
76                return str;
77        }
78
79        std::string make_bold( const std::string & str ) {
80                return bold_ttycode() + str + reset_font_ttycode();
81        }
82
83        std::ostream & operator<<(std::ostream & os, bold) {
84                os << bold_ttycode();
85                return os;
86        }
87
88        std::ostream & operator<<(std::ostream & os, reset_font) {
89                os << reset_font_ttycode();
90                return os;
91        }
[294647b]92}
93
[51587aa]94// Local Variables: //
95// tab-width: 4 //
96// mode: c++ //
97// compile-command: "make install" //
98// End: //
Note: See TracBrowser for help on using the repository browser.