source: src/Common/SemanticError.h @ 4bae7b4

Last change on this file since 4bae7b4 was be00a2d, checked in by Peter A. Buhr <pabuhr@…>, 21 months ago

change BadQualifiersZeroOne? warning from dubious print of specified qualifer(s) to a generic message

  • Property mode set to 100644
File size: 4.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 : Sat Feb 25 12:01:31 2023
13// Update Count     : 37
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 Severity default_severity;
52        const char * const message;
53};
54
55constexpr WarningData WarningFormats[] = {
56        {"self-assign"              , Severity::Warn    , "self assignment of expression: %s"                          },
57        {"reference-conversion"     , Severity::Warn    , "rvalue to reference conversion of rvalue: %s"               },
58        {"qualifiers-zero_t-one_t"  , Severity::Warn    , "questionable use of type qualifier(s) with %s"              },
59        {"aggregate-forward-decl"   , Severity::Warn    , "forward declaration of nested aggregate: %s"                },
60        {"superfluous-decl"         , Severity::Warn    , "declaration does not allocate storage: %s"                  },
61        {"superfluous-else"         , Severity::Warn    , "else clause never executed for empty loop conditional"      },
62        {"gcc-attributes"           , Severity::Warn    , "invalid attribute: %s"                                      },
63        {"c++-like-copy"            , Severity::Warn    , "Constructor from reference is not a valid copy constructor" },
64        {"depreciated-trait-syntax" , Severity::Warn    , "trait type-parameters are now specified using the forall clause" },
65};
66
67enum class Warning {
68        SelfAssignment,
69        RvalueToReferenceConversion,
70        BadQualifiersZeroOne,
71        AggrForwardDecl,
72        SuperfluousDecl,
73        SuperfluousElse,
74        GccAttributes,
75        CppCopy,
76        DeprecTraitSyntax,
77        NUMBER_OF_WARNINGS, // This MUST be the last warning
78};
79
80static_assert(
81        (sizeof(WarningFormats) / sizeof(WarningFormats[0])) == ((unsigned long)Warning::NUMBER_OF_WARNINGS),
82        "Each warning format should have a corresponding warning enum value"
83);
84
85#define SemanticWarning(loc, id, ...) SemanticWarningImpl(loc, id, WarningFormats[(int)id].message, ##__VA_ARGS__)
86
87void SemanticWarningImpl (CodeLocation loc, Warning warn, const char * const fmt, ...) __attribute__((format(printf, 3, 4)));
88
89void SemanticWarning_SuppressAll   ();
90void SemanticWarning_EnableAll     ();
91void SemanticWarning_WarningAsError();
92void SemanticWarning_Set           (const char * const name, Severity s);
93
94// SKULLDUGGERY: cfa.cc is built before SemanticError.cc but needs this routine.
95static inline bool SemanticWarning_Exist(const char * const name) {
96        for ( const auto & w : WarningFormats ) {
97                if ( std::strcmp( name, w.name ) == 0 ) return true;
98        }
99        return false;
100}
101
102//-----------------------------------------------------------------------------
103// Helpers
104namespace ErrorHelpers {
105        enum class Colors {
106                Never = false,
107                Always = true,
108                Auto,
109        };
110
111        extern Colors colors;
112
113        const std::string & error_str();
114        const std::string & warning_str();
115        const std::string & bold_ttycode();
116        const std::string & reset_font_ttycode();
117
118        std::string make_bold( const std::string & str );
119
120        struct bold {};
121        std::ostream & operator<<(std::ostream & os, bold);
122
123        struct reset_font {};
124        std::ostream & operator<<(std::ostream & os, reset_font);
125}
126
127// Local Variables: //
128// tab-width: 4 //
129// mode: c++ //
130// compile-command: "make install" //
131// End: //
Note: See TracBrowser for help on using the repository browser.