source: src/Common/SemanticError.h@ 9d32bc8

ADT aaron-thesis arm-eh ast-experimental cleanup-dtors deferred_resn demangler enum forall-pointer-decay jacob/cs343-translation jenkins-sandbox new-ast new-ast-unique-expr new-env no_list persistent-indexer pthread-emulation qualifiedEnum with_gc
Last change on this file since 9d32bc8 was 68e9ace, checked in by Thierry Delisle <tdelisle@…>, 7 years ago

Fixed semantic warning severity handling

  • Property mode set to 100644
File size: 2.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//
[3906301]7// SemanticError.h --
[51587aa]8//
9// Author : Richard C. Bilson
10// Created On : Mon May 18 07:44:20 2015
[9ed4f94]11// Last Modified By : Peter A. Buhr
[44bca7f]12// Last Modified On : Wed May 2 15:00:01 2018
13// Update Count : 23
[51587aa]14//
[51b73452]15
[6b0b624]16#pragma once
[51b73452]17
[a16764a6]18#include "ErrorObjects.h"
[294647b]19
[d55d7a6]20//-----------------------------------------------------------------------------
21// Errors
[138e29e]22
[a16764a6]23__attribute__((noreturn)) void SemanticError( CodeLocation location, std::string error );
[51b73452]24
25template< typename T >
[a16764a6]26__attribute__((noreturn)) static inline void SemanticError( const T * obj, const std::string & error ) {
27 SemanticError( obj->location, toString( error, obj ) );
28}
[d55d7a6]29
30template< typename T >
[a16764a6]31__attribute__((noreturn)) static inline void SemanticError( CodeLocation location, const T * obj, const std::string & error ) {
32 SemanticError( location, toString( error, obj ) );
33}
[d55d7a6]34
35//-----------------------------------------------------------------------------
36// Warnings
37
[6040e67d]38enum class Severity {
39 Suppress,
40 Warn,
41 Error,
42 Critical
43};
44
45struct WarningData {
46 const char * const name;
47 const char * const message;
[68e9ace]48 const Severity default_severity;
[6040e67d]49};
50
[44bca7f]51constexpr WarningData WarningFormats[] = {
[68e9ace]52 {"self-assign" , "self assignment of expression: %s" , Severity::Warn},
53 {"reference-conversion" , "rvalue to reference conversion of rvalue: %s" , Severity::Warn},
[c28afead]54 {"qualifiers-zero_t-one_t", "questionable use of type qualifier %s with %s", Severity::Warn},
[a16764a6]55};
[d55d7a6]56
[a16764a6]57enum class Warning {
[babeeda]58 SelfAssignment,
[ec6c040]59 RvalueToReferenceConversion,
[9dc31c10]60 BadQualifiersZeroOne,
[a16764a6]61 NUMBER_OF_WARNINGS, //This MUST be the last warning
[d55d7a6]62};
63
[a16764a6]64static_assert(
65 (sizeof(WarningFormats) / sizeof(WarningFormats[0])) == ((unsigned long)Warning::NUMBER_OF_WARNINGS),
66 "Each warning format should have a corresponding warning enum value"
67);
68
[6040e67d]69#define SemanticWarning(loc, id, ...) SemanticWarningImpl(loc, id, WarningFormats[(int)id].message, __VA_ARGS__)
[a16764a6]70
71void SemanticWarningImpl (CodeLocation loc, Warning warn, const char * const fmt, ...) __attribute__((format(printf, 3, 4)));
[d55d7a6]72
[68e9ace]73void SemanticWarning_SuppressAll ();
74void SemanticWarning_EnableAll ();
75void SemanticWarning_WarningAsError();
76void SemanticWarning_Set (const char * const name, Severity s);
[d55d7a6]77
78//-----------------------------------------------------------------------------
79// Helpers
[a16764a6]80namespace ErrorHelpers {
81 const std::string & error_str();
82 const std::string & warning_str();
83 const std::string & bold_ttycode();
84 const std::string & reset_font_ttycode();
[d55d7a6]85
[a16764a6]86 std::string make_bold( const std::string & str );
[d55d7a6]87
[a16764a6]88 struct bold {};
89 std::ostream & operator<<(std::ostream & os, bold);
[d55d7a6]90
[a16764a6]91 struct reset_font {};
92 std::ostream & operator<<(std::ostream & os, reset_font);
[d55d7a6]93}
94
[51587aa]95// Local Variables: //
96// tab-width: 4 //
97// mode: c++ //
98// compile-command: "make install" //
99// End: //
Note: See TracBrowser for help on using the repository browser.