| 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 | //
|
|---|
| 7 | // SemanticError.h --
|
|---|
| 8 | //
|
|---|
| 9 | // Author : Richard C. Bilson
|
|---|
| 10 | // Created On : Mon May 18 07:44:20 2015
|
|---|
| 11 | // Last Modified By : Peter A. Buhr
|
|---|
| 12 | // Last Modified On : Wed May 2 15:00:01 2018
|
|---|
| 13 | // Update Count : 23
|
|---|
| 14 | //
|
|---|
| 15 |
|
|---|
| 16 | #pragma once
|
|---|
| 17 |
|
|---|
| 18 | #include "ErrorObjects.h"
|
|---|
| 19 |
|
|---|
| 20 | //-----------------------------------------------------------------------------
|
|---|
| 21 | // Errors
|
|---|
| 22 |
|
|---|
| 23 | __attribute__((noreturn)) void SemanticError( CodeLocation location, std::string error );
|
|---|
| 24 |
|
|---|
| 25 | template< typename T >
|
|---|
| 26 | __attribute__((noreturn)) static inline void SemanticError( const T * obj, const std::string & error ) {
|
|---|
| 27 | SemanticError( obj->location, toString( error, obj ) );
|
|---|
| 28 | }
|
|---|
| 29 |
|
|---|
| 30 | template< typename T >
|
|---|
| 31 | __attribute__((noreturn)) static inline void SemanticError( CodeLocation location, const T * obj, const std::string & error ) {
|
|---|
| 32 | SemanticError( location, toString( error, obj ) );
|
|---|
| 33 | }
|
|---|
| 34 |
|
|---|
| 35 | //-----------------------------------------------------------------------------
|
|---|
| 36 | // Warnings
|
|---|
| 37 |
|
|---|
| 38 | enum class Severity {
|
|---|
| 39 | Suppress,
|
|---|
| 40 | Warn,
|
|---|
| 41 | Error,
|
|---|
| 42 | Critical
|
|---|
| 43 | };
|
|---|
| 44 |
|
|---|
| 45 | struct WarningData {
|
|---|
| 46 | const char * const name;
|
|---|
| 47 | const char * const message;
|
|---|
| 48 | const Severity default_severity;
|
|---|
| 49 | };
|
|---|
| 50 |
|
|---|
| 51 | constexpr WarningData WarningFormats[] = {
|
|---|
| 52 | {"self-assign" , "self assignment of expression: %s" , Severity::Warn},
|
|---|
| 53 | {"reference-conversion" , "rvalue to reference conversion of rvalue: %s" , Severity::Warn},
|
|---|
| 54 | {"qualifiers-zero_t-one_t", "questionable use of type qualifier %s with %s", Severity::Warn},
|
|---|
| 55 | };
|
|---|
| 56 |
|
|---|
| 57 | enum class Warning {
|
|---|
| 58 | SelfAssignment,
|
|---|
| 59 | RvalueToReferenceConversion,
|
|---|
| 60 | BadQualifiersZeroOne,
|
|---|
| 61 | NUMBER_OF_WARNINGS, //This MUST be the last warning
|
|---|
| 62 | };
|
|---|
| 63 |
|
|---|
| 64 | static_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 |
|
|---|
| 69 | #define SemanticWarning(loc, id, ...) SemanticWarningImpl(loc, id, WarningFormats[(int)id].message, __VA_ARGS__)
|
|---|
| 70 |
|
|---|
| 71 | void SemanticWarningImpl (CodeLocation loc, Warning warn, const char * const fmt, ...) __attribute__((format(printf, 3, 4)));
|
|---|
| 72 |
|
|---|
| 73 | void SemanticWarning_SuppressAll ();
|
|---|
| 74 | void SemanticWarning_EnableAll ();
|
|---|
| 75 | void SemanticWarning_WarningAsError();
|
|---|
| 76 | void SemanticWarning_Set (const char * const name, Severity s);
|
|---|
| 77 |
|
|---|
| 78 | //-----------------------------------------------------------------------------
|
|---|
| 79 | // Helpers
|
|---|
| 80 | namespace 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();
|
|---|
| 85 |
|
|---|
| 86 | std::string make_bold( const std::string & str );
|
|---|
| 87 |
|
|---|
| 88 | struct bold {};
|
|---|
| 89 | std::ostream & operator<<(std::ostream & os, bold);
|
|---|
| 90 |
|
|---|
| 91 | struct reset_font {};
|
|---|
| 92 | std::ostream & operator<<(std::ostream & os, reset_font);
|
|---|
| 93 | }
|
|---|
| 94 |
|
|---|
| 95 | // Local Variables: //
|
|---|
| 96 | // tab-width: 4 //
|
|---|
| 97 | // mode: c++ //
|
|---|
| 98 | // compile-command: "make install" //
|
|---|
| 99 | // End: //
|
|---|