source: src/Common/SemanticError.h @ 1a69a90

arm-ehjacob/cs343-translationjenkins-sandboxnew-astnew-ast-unique-expr
Last change on this file since 1a69a90 was 1a69a90, checked in by Thierry Delisle <tdelisle@…>, 2 years ago

Added --colors command line arguments to have more control on whether or not to print errors with colors

  • Property mode set to 100644
File size: 3.7 KB
Line 
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//
7// SemanticError.h --
8//
9// Author           : Thierry Delisle
10// Created On       : Mon May 18 07:44:20 2015
11// Last Modified By : Peter A. Buhr
12// Last Modified On : Thu Jul 19 10:09:17 2018
13// Update Count     : 31
14//
15
16#pragma once
17
18#include "ErrorObjects.h"
19#include "AST/Node.hpp"
20#include <cstring>
21
22//-----------------------------------------------------------------------------
23// Errors
24
25extern bool SemanticErrorThrow;
26
27__attribute__((noreturn)) void SemanticError( CodeLocation location, std::string error );
28
29template< typename T >
30__attribute__((noreturn)) static inline void SemanticError( const T * obj, const std::string & error ) {
31        SemanticError( obj->location, toString( error, obj ) );
32}
33
34template< typename T >
35__attribute__((noreturn)) static inline void SemanticError( CodeLocation location, const T * obj, const std::string & error ) {
36        SemanticError( location, toString( error, obj ) );
37}
38
39//-----------------------------------------------------------------------------
40// Warnings
41
42enum class Severity {
43        Suppress,
44        Warn,
45        Error,
46        Critical
47};
48
49struct WarningData {
50        const char * const name;
51        const char * const message;
52        const Severity default_severity;
53};
54
55constexpr WarningData WarningFormats[] = {
56        {"self-assign"            , "self assignment of expression: %s"            , Severity::Warn},
57        {"reference-conversion"   , "rvalue to reference conversion of rvalue: %s" , Severity::Warn},
58        {"qualifiers-zero_t-one_t", "questionable use of type qualifier %s with %s", Severity::Warn},
59        {"aggregate-forward-decl" , "forward declaration of nested aggregate: %s"  , Severity::Warn},
60        {"superfluous-decl"       , "declaration does not allocate storage: %s"    , Severity::Warn},
61        {"gcc-attributes"         , "invalid attribute: %s"                        , Severity::Warn},
62};
63
64enum class Warning {
65        SelfAssignment,
66        RvalueToReferenceConversion,
67        BadQualifiersZeroOne,
68        AggrForwardDecl,
69        SuperfluousDecl,
70        GccAttributes,
71        NUMBER_OF_WARNINGS, // This MUST be the last warning
72};
73
74static_assert(
75        (sizeof(WarningFormats) / sizeof(WarningFormats[0])) == ((unsigned long)Warning::NUMBER_OF_WARNINGS),
76        "Each warning format should have a corresponding warning enum value"
77);
78
79#define SemanticWarning(loc, id, ...) SemanticWarningImpl(loc, id, WarningFormats[(int)id].message, __VA_ARGS__)
80
81void SemanticWarningImpl (CodeLocation loc, Warning warn, const char * const fmt, ...) __attribute__((format(printf, 3, 4)));
82
83void SemanticWarning_SuppressAll   ();
84void SemanticWarning_EnableAll     ();
85void SemanticWarning_WarningAsError();
86void SemanticWarning_Set           (const char * const name, Severity s);
87
88// SKULLDUGGERY: cfa.cc is built before SemanticError.cc but needs this routine.
89static inline bool SemanticWarning_Exist(const char * const name) {
90        for ( const auto & w : WarningFormats ) {
91                if ( std::strcmp( name, w.name ) == 0 ) return true;
92        }
93        return false;
94}
95
96//-----------------------------------------------------------------------------
97// Helpers
98namespace ErrorHelpers {
99        enum class Colors {
100                Never = false,
101                Always = true,
102                Auto,
103        };
104
105        extern Colors colors;
106
107        const std::string & error_str();
108        const std::string & warning_str();
109        const std::string & bold_ttycode();
110        const std::string & reset_font_ttycode();
111
112        std::string make_bold( const std::string & str );
113
114        struct bold {};
115        std::ostream & operator<<(std::ostream & os, bold);
116
117        struct reset_font {};
118        std::ostream & operator<<(std::ostream & os, reset_font);
119}
120
121// Local Variables: //
122// tab-width: 4 //
123// mode: c++ //
124// compile-command: "make install" //
125// End: //
Note: See TracBrowser for help on using the repository browser.