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