source: src/Common/SemanticError.h@ 43c461d

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 43c461d was af39199d, checked in by Peter A. Buhr <pabuhr@…>, 7 years ago

add and use search routine

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