[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
|
---|
| 12 | // Last Modified On : Tue Aug 29 22:03:36 2017
|
---|
| 13 | // Update Count : 17
|
---|
[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 |
|
---|
| 25 | template< 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 |
|
---|
| 30 | template< 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 |
|
---|
[a16764a6] | 38 | constexpr const char * const WarningFormats[] = {
|
---|
[babeeda] | 39 | "self assignment of expression: %s",
|
---|
[a16764a6] | 40 | };
|
---|
[d55d7a6] | 41 |
|
---|
[a16764a6] | 42 | enum class Warning {
|
---|
[babeeda] | 43 | SelfAssignment,
|
---|
[a16764a6] | 44 | NUMBER_OF_WARNINGS, //This MUST be the last warning
|
---|
[d55d7a6] | 45 | };
|
---|
| 46 |
|
---|
[a16764a6] | 47 | static_assert(
|
---|
| 48 | (sizeof(WarningFormats) / sizeof(WarningFormats[0])) == ((unsigned long)Warning::NUMBER_OF_WARNINGS),
|
---|
| 49 | "Each warning format should have a corresponding warning enum value"
|
---|
| 50 | );
|
---|
| 51 |
|
---|
[2103a51] | 52 | #define SemanticWarning(loc, id, ...) SemanticWarningImpl(loc, id, WarningFormats[(int)id], __VA_ARGS__)
|
---|
[a16764a6] | 53 |
|
---|
| 54 | void SemanticWarningImpl (CodeLocation loc, Warning warn, const char * const fmt, ...) __attribute__((format(printf, 3, 4)));
|
---|
[d55d7a6] | 55 |
|
---|
| 56 |
|
---|
| 57 | //-----------------------------------------------------------------------------
|
---|
| 58 | // Helpers
|
---|
[a16764a6] | 59 | namespace ErrorHelpers {
|
---|
| 60 | const std::string & error_str();
|
---|
| 61 | const std::string & warning_str();
|
---|
| 62 | const std::string & bold_ttycode();
|
---|
| 63 | const std::string & reset_font_ttycode();
|
---|
[d55d7a6] | 64 |
|
---|
[a16764a6] | 65 | std::string make_bold( const std::string & str );
|
---|
[d55d7a6] | 66 |
|
---|
[a16764a6] | 67 | struct bold {};
|
---|
| 68 | std::ostream & operator<<(std::ostream & os, bold);
|
---|
[d55d7a6] | 69 |
|
---|
[a16764a6] | 70 | struct reset_font {};
|
---|
| 71 | std::ostream & operator<<(std::ostream & os, reset_font);
|
---|
[d55d7a6] | 72 | }
|
---|
| 73 |
|
---|
[51587aa] | 74 | // Local Variables: //
|
---|
| 75 | // tab-width: 4 //
|
---|
| 76 | // mode: c++ //
|
---|
| 77 | // compile-command: "make install" //
|
---|
| 78 | // End: //
|
---|