source: src/Common/SemanticError.hpp @ 46651fb

Last change on this file since 46651fb was c92bdcc, checked in by Andrew Beach <ajbeach@…>, 6 months ago

Updated the rest of the names in src/ (except for the generated files).

  • 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//
[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
[610354a]12// Last Modified On : Thu Dec 14 13:48:07 2023
13// Update Count     : 72
[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[] = {
[b1f2007]60        {"self-assign"              , Severity::Warn, "self assignment of expression: %s"                          },
61        {"reference-conversion"     , Severity::Warn, "rvalue to reference conversion of rvalue: %s"               },
62        {"qualifiers-zero_t-one_t"  , Severity::Warn, "questionable use of type qualifier(s) with %s"              },
63        {"aggregate-forward-decl"   , Severity::Warn, "forward declaration of nested aggregate: %s"                },
64        {"superfluous-decl"         , Severity::Warn, "declaration does not allocate storage: %s"                  },
65        {"superfluous-else"         , Severity::Warn, "else clause never executed for empty loop conditional"      },
66        {"gcc-attributes"           , Severity::Warn, "invalid attribute: %s"                                      },
67        {"c++-like-copy"            , Severity::Warn, "Constructor from reference is not a valid copy constructor" },
68        {"depreciated-trait-syntax" , Severity::Warn, "trait type-parameters are now specified using the forall clause" },
[a16764a6]69};
[d55d7a6]70
[a16764a6]71enum class Warning {
[babeeda]72        SelfAssignment,
[ec6c040]73        RvalueToReferenceConversion,
[9dc31c10]74        BadQualifiersZeroOne,
[2e02851]75        AggrForwardDecl,
[679e644]76        SuperfluousDecl,
[b6ae4fb]77        SuperfluousElse,
[fd2debf]78        GccAttributes,
[98538288]79        CppCopy,
[8a97248]80        DeprecTraitSyntax,
[610354a]81        NUMBER_OF_WARNINGS, // MUST be last warning
[d55d7a6]82};
83
[a16764a6]84static_assert(
85        (sizeof(WarningFormats) / sizeof(WarningFormats[0])) == ((unsigned long)Warning::NUMBER_OF_WARNINGS),
86        "Each warning format should have a corresponding warning enum value"
87);
88
[610354a]89void SemanticWarning( CodeLocation loc, Warning warn, ... );
[d55d7a6]90
[610354a]91void SemanticWarning_SuppressAll();
92void SemanticWarning_EnableAll();
[68e9ace]93void SemanticWarning_WarningAsError();
[610354a]94void SemanticWarning_Set(const char * const name, Severity s);
[d55d7a6]95
[af39199d]96// SKULLDUGGERY: cfa.cc is built before SemanticError.cc but needs this routine.
97static inline bool SemanticWarning_Exist(const char * const name) {
98        for ( const auto & w : WarningFormats ) {
99                if ( std::strcmp( name, w.name ) == 0 ) return true;
100        }
101        return false;
102}
103
[d55d7a6]104//-----------------------------------------------------------------------------
105// Helpers
[a16764a6]106namespace ErrorHelpers {
[1a69a90]107        enum class Colors {
108                Never = false,
109                Always = true,
110                Auto,
111        };
112
113        extern Colors colors;
114
[a16764a6]115        const std::string & error_str();
116        const std::string & warning_str();
117        const std::string & bold_ttycode();
118        const std::string & reset_font_ttycode();
[d55d7a6]119
[a16764a6]120        std::string make_bold( const std::string & str );
[d55d7a6]121
[a16764a6]122        struct bold {};
123        std::ostream & operator<<(std::ostream & os, bold);
[d55d7a6]124
[a16764a6]125        struct reset_font {};
126        std::ostream & operator<<(std::ostream & os, reset_font);
[d55d7a6]127}
128
[51587aa]129// Local Variables: //
130// tab-width: 4 //
131// mode: c++ //
132// compile-command: "make install" //
133// End: //
Note: See TracBrowser for help on using the repository browser.