source: src/Common/SemanticError.h @ 3d56d15b

ADTaaron-thesisarm-ehast-experimentalcleanup-dtorsdeferred_resndemanglerenumforall-pointer-decayjacob/cs343-translationjenkins-sandboxnew-astnew-ast-unique-exprnew-envno_listpersistent-indexerpthread-emulationqualifiedEnumwith_gc
Last change on this file since 3d56d15b was 4358c1e, checked in by Peter A. Buhr <pabuhr@…>, 6 years ago

add SemanticErrorThrow? flag

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