source: src/Common/SemanticError.h @ a2f146ee

ADTaaron-thesisarm-ehast-experimentalcleanup-dtorsdeferred_resndemanglerenumforall-pointer-decayjacob/cs343-translationjenkins-sandboxnew-astnew-ast-unique-exprno_listpersistent-indexerpthread-emulationqualifiedEnum
Last change on this file since a2f146ee was 679e644, checked in by Peter A. Buhr <pabuhr@…>, 6 years ago

extend plan 9, anonymous declarations, change token for default argument

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