source: src/Common/SemanticError.h @ 6a0b043

Last change on this file since 6a0b043 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
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.h --
[51587aa]8//
[af39199d]9// Author           : Thierry Delisle
[51587aa]10// Created On       : Mon May 18 07:44:20 2015
[9ed4f94]11// Last Modified By : Peter A. Buhr
[be00a2d]12// Last Modified On : Sat Feb 25 12:01:31 2023
13// Update Count     : 37
[51587aa]14//
[51b7345]15
[6b0b624]16#pragma once
[51b7345]17
[a16764a6]18#include "ErrorObjects.h"
[77bfc80]19#include "AST/Node.hpp"
[af39199d]20#include <cstring>
[294647b]21
[d55d7a6]22//-----------------------------------------------------------------------------
23// Errors
[138e29e]24
[4358c1e]25extern bool SemanticErrorThrow;
26
[a16764a6]27__attribute__((noreturn)) void SemanticError( CodeLocation location, std::string error );
[51b7345]28
29template< typename T >
[a16764a6]30__attribute__((noreturn)) static inline void SemanticError( const T * obj, const std::string & error ) {
31        SemanticError( obj->location, toString( error, obj ) );
32}
[d55d7a6]33
34template< typename T >
[a16764a6]35__attribute__((noreturn)) static inline void SemanticError( CodeLocation location, const T * obj, const std::string & error ) {
36        SemanticError( location, toString( error, obj ) );
37}
[d55d7a6]38
39//-----------------------------------------------------------------------------
40// Warnings
41
[6040e67d]42enum class Severity {
43        Suppress,
44        Warn,
45        Error,
46        Critical
47};
48
49struct WarningData {
50        const char * const name;
[68e9ace]51        const Severity default_severity;
[98538288]52        const char * const message;
[6040e67d]53};
54
[44bca7f]55constexpr WarningData WarningFormats[] = {
[8a97248]56        {"self-assign"              , Severity::Warn    , "self assignment of expression: %s"                          },
57        {"reference-conversion"     , Severity::Warn    , "rvalue to reference conversion of rvalue: %s"               },
[be00a2d]58        {"qualifiers-zero_t-one_t"  , Severity::Warn    , "questionable use of type qualifier(s) with %s"              },
[8a97248]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" },
[a16764a6]65};
[d55d7a6]66
[a16764a6]67enum class Warning {
[babeeda]68        SelfAssignment,
[ec6c040]69        RvalueToReferenceConversion,
[9dc31c10]70        BadQualifiersZeroOne,
[2e02851]71        AggrForwardDecl,
[679e644]72        SuperfluousDecl,
[b6ae4fb]73        SuperfluousElse,
[fd2debf]74        GccAttributes,
[98538288]75        CppCopy,
[8a97248]76        DeprecTraitSyntax,
[679e644]77        NUMBER_OF_WARNINGS, // This MUST be the last warning
[d55d7a6]78};
79
[a16764a6]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
[b6ae4fb]85#define SemanticWarning(loc, id, ...) SemanticWarningImpl(loc, id, WarningFormats[(int)id].message, ##__VA_ARGS__)
[a16764a6]86
87void SemanticWarningImpl (CodeLocation loc, Warning warn, const char * const fmt, ...) __attribute__((format(printf, 3, 4)));
[d55d7a6]88
[68e9ace]89void SemanticWarning_SuppressAll   ();
90void SemanticWarning_EnableAll     ();
91void SemanticWarning_WarningAsError();
92void SemanticWarning_Set           (const char * const name, Severity s);
[d55d7a6]93
[af39199d]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
[d55d7a6]102//-----------------------------------------------------------------------------
103// Helpers
[a16764a6]104namespace ErrorHelpers {
[1a69a90]105        enum class Colors {
106                Never = false,
107                Always = true,
108                Auto,
109        };
110
111        extern Colors colors;
112
[a16764a6]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();
[d55d7a6]117
[a16764a6]118        std::string make_bold( const std::string & str );
[d55d7a6]119
[a16764a6]120        struct bold {};
121        std::ostream & operator<<(std::ostream & os, bold);
[d55d7a6]122
[a16764a6]123        struct reset_font {};
124        std::ostream & operator<<(std::ostream & os, reset_font);
[d55d7a6]125}
126
[51587aa]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.