source: src/Common/SemanticError.hpp @ df56e25

Last change on this file since df56e25 was 5786403, checked in by Peter A. Buhr <pabuhr@…>, 5 weeks ago

update semantic warnings

  • Property mode set to 100644
File size: 3.9 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//
[c92bdcc]7// SemanticError.hpp --
[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
[5786403]12// Last Modified On : Sun Dec 15 21:04:32 2024
13// Update Count     : 77
[51587aa]14//
[51b7345]15
[6b0b624]16#pragma once
[51b7345]17
[c92bdcc]18#include "ErrorObjects.hpp"
[77bfc80]19#include "AST/Node.hpp"
[b1f2007]20#include "AST/ParseNode.hpp"
[af39199d]21#include <cstring>
[294647b]22
[d55d7a6]23//-----------------------------------------------------------------------------
24// Errors
[138e29e]25
[4358c1e]26extern bool SemanticErrorThrow;
27
[b1f2007]28__attribute__((noreturn, format(printf, 2, 3))) void SemanticError( CodeLocation location, const char fmt[], ... );
29
[610354a]30__attribute__((noreturn)) static inline void SemanticError( CodeLocation location, std::string error ) {
31        SemanticErrorThrow = true;
32        throw SemanticErrorException( location, error );
33}
[51b7345]34
[b1f2007]35__attribute__((noreturn)) static inline void SemanticError( const ast::ParseNode * obj, const std::string & error ) {
[a16764a6]36        SemanticError( obj->location, toString( error, obj ) );
37}
[d55d7a6]38
[b1f2007]39__attribute__((noreturn)) static inline void SemanticError( CodeLocation location, const ast::Node * obj, const std::string & error ) {
[a16764a6]40        SemanticError( location, toString( error, obj ) );
41}
[d55d7a6]42
43//-----------------------------------------------------------------------------
44// Warnings
45
[6040e67d]46enum class Severity {
47        Suppress,
48        Warn,
49        Error,
50        Critical
51};
52
53struct WarningData {
54        const char * const name;
[68e9ace]55        const Severity default_severity;
[98538288]56        const char * const message;
[6040e67d]57};
58
[44bca7f]59constexpr WarningData WarningFormats[] = {
[5786403]60        {"self-assign"              , Severity::Warn, "self assignment of expression: %s." },
61        {"reference-conversion"     , Severity::Warn, "rvalue to reference conversion of rvalue: %s." },
62        {"aggregate-forward-decl"   , Severity::Warn, "forward declaration of nested aggregate: %s." },
63        {"superfluous-decl"         , Severity::Warn, "declaration does not declare anything." },
64        {"superfluous-else"         , Severity::Warn, "else clause never executed for empty loop conditional." },
65        {"gcc-attributes"           , Severity::Warn, "invalid attribute: %s." },
66        {"c++-like-copy"            , Severity::Warn, "Constructor from reference is not a valid copy constructor." },
67        {"depreciated-trait-syntax" , Severity::Warn, "trait type-parameters are now specified using the forall clause." },
[a16764a6]68};
[d55d7a6]69
[a16764a6]70enum class Warning {
[babeeda]71        SelfAssignment,
[ec6c040]72        RvalueToReferenceConversion,
[2e02851]73        AggrForwardDecl,
[679e644]74        SuperfluousDecl,
[b6ae4fb]75        SuperfluousElse,
[fd2debf]76        GccAttributes,
[98538288]77        CppCopy,
[8a97248]78        DeprecTraitSyntax,
[610354a]79        NUMBER_OF_WARNINGS, // MUST be last warning
[d55d7a6]80};
81
[a16764a6]82static_assert(
83        (sizeof(WarningFormats) / sizeof(WarningFormats[0])) == ((unsigned long)Warning::NUMBER_OF_WARNINGS),
84        "Each warning format should have a corresponding warning enum value"
85);
86
[610354a]87void SemanticWarning( CodeLocation loc, Warning warn, ... );
[d55d7a6]88
[610354a]89void SemanticWarning_SuppressAll();
90void SemanticWarning_EnableAll();
[68e9ace]91void SemanticWarning_WarningAsError();
[610354a]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.