[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
|
---|
[4175659] | 12 | // Last Modified On : Mon Dec 2 15:14:13 2024
|
---|
| 13 | // Update Count : 75
|
---|
[51587aa] | 14 | //
|
---|
[51b73452] | 15 |
|
---|
[6b0b624] | 16 | #pragma once
|
---|
[51b73452] | 17 |
|
---|
[c92bdcc] | 18 | #include "ErrorObjects.hpp"
|
---|
[77bfc80] | 19 | #include "AST/Node.hpp"
|
---|
[b1f2007d] | 20 | #include "AST/ParseNode.hpp"
|
---|
[af39199d] | 21 | #include <cstring>
|
---|
[294647b] | 22 |
|
---|
[d55d7a6] | 23 | //-----------------------------------------------------------------------------
|
---|
| 24 | // Errors
|
---|
[138e29e] | 25 |
|
---|
[4358c1e] | 26 | extern bool SemanticErrorThrow;
|
---|
| 27 |
|
---|
[b1f2007d] | 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 | }
|
---|
[51b73452] | 34 |
|
---|
[b1f2007d] | 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 |
|
---|
[b1f2007d] | 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] | 46 | enum class Severity {
|
---|
| 47 | Suppress,
|
---|
| 48 | Warn,
|
---|
| 49 | Error,
|
---|
| 50 | Critical
|
---|
| 51 | };
|
---|
| 52 |
|
---|
| 53 | struct WarningData {
|
---|
| 54 | const char * const name;
|
---|
[68e9ace] | 55 | const Severity default_severity;
|
---|
[98538288] | 56 | const char * const message;
|
---|
[6040e67d] | 57 | };
|
---|
| 58 |
|
---|
[44bca7f] | 59 | constexpr WarningData WarningFormats[] = {
|
---|
[b1f2007d] | 60 | {"self-assign" , Severity::Warn, "self assignment of expression: %s" },
|
---|
| 61 | {"reference-conversion" , Severity::Warn, "rvalue to reference conversion of rvalue: %s" },
|
---|
| 62 | {"aggregate-forward-decl" , Severity::Warn, "forward declaration of nested aggregate: %s" },
|
---|
| 63 | {"superfluous-decl" , Severity::Warn, "declaration does not allocate storage: %s" },
|
---|
| 64 | {"superfluous-else" , Severity::Warn, "else clause never executed for empty loop conditional" },
|
---|
| 65 | {"gcc-attributes" , Severity::Warn, "invalid attribute: %s" },
|
---|
| 66 | {"c++-like-copy" , Severity::Warn, "Constructor from reference is not a valid copy constructor" },
|
---|
| 67 | {"depreciated-trait-syntax" , Severity::Warn, "trait type-parameters are now specified using the forall clause" },
|
---|
[a16764a6] | 68 | };
|
---|
[d55d7a6] | 69 |
|
---|
[a16764a6] | 70 | enum class Warning {
|
---|
[babeeda] | 71 | SelfAssignment,
|
---|
[ec6c040] | 72 | RvalueToReferenceConversion,
|
---|
[2e02851] | 73 | AggrForwardDecl,
|
---|
[679e644] | 74 | SuperfluousDecl,
|
---|
[b6ae4fb] | 75 | SuperfluousElse,
|
---|
[fd2debf] | 76 | GccAttributes,
|
---|
[98538288] | 77 | CppCopy,
|
---|
[8a97248] | 78 | DeprecTraitSyntax,
|
---|
[610354a] | 79 | NUMBER_OF_WARNINGS, // MUST be last warning
|
---|
[d55d7a6] | 80 | };
|
---|
| 81 |
|
---|
[a16764a6] | 82 | static_assert(
|
---|
| 83 | (sizeof(WarningFormats) / sizeof(WarningFormats[0])) == ((unsigned long)Warning::NUMBER_OF_WARNINGS),
|
---|
| 84 | "Each warning format should have a corresponding warning enum value"
|
---|
| 85 | );
|
---|
| 86 |
|
---|
[610354a] | 87 | void SemanticWarning( CodeLocation loc, Warning warn, ... );
|
---|
[d55d7a6] | 88 |
|
---|
[610354a] | 89 | void SemanticWarning_SuppressAll();
|
---|
| 90 | void SemanticWarning_EnableAll();
|
---|
[68e9ace] | 91 | void SemanticWarning_WarningAsError();
|
---|
[610354a] | 92 | void SemanticWarning_Set(const char * const name, Severity s);
|
---|
[d55d7a6] | 93 |
|
---|
[af39199d] | 94 | // SKULLDUGGERY: cfa.cc is built before SemanticError.cc but needs this routine.
|
---|
| 95 | static inline bool SemanticWarning_Exist(const char * const name) {
|
---|
| 96 | for ( const auto & w : WarningFormats ) {
|
---|
| 97 | if ( std::strcmp( name, w.name ) == 0 ) return true;
|
---|
| 98 | }
|
---|
| 99 | return false;
|
---|
| 100 | }
|
---|
| 101 |
|
---|
[d55d7a6] | 102 | //-----------------------------------------------------------------------------
|
---|
| 103 | // Helpers
|
---|
[a16764a6] | 104 | namespace ErrorHelpers {
|
---|
[1a69a90] | 105 | enum class Colors {
|
---|
| 106 | Never = false,
|
---|
| 107 | Always = true,
|
---|
| 108 | Auto,
|
---|
| 109 | };
|
---|
| 110 |
|
---|
| 111 | extern Colors colors;
|
---|
| 112 |
|
---|
[a16764a6] | 113 | const std::string & error_str();
|
---|
| 114 | const std::string & warning_str();
|
---|
| 115 | const std::string & bold_ttycode();
|
---|
| 116 | const std::string & reset_font_ttycode();
|
---|
[d55d7a6] | 117 |
|
---|
[a16764a6] | 118 | std::string make_bold( const std::string & str );
|
---|
[d55d7a6] | 119 |
|
---|
[a16764a6] | 120 | struct bold {};
|
---|
| 121 | std::ostream & operator<<(std::ostream & os, bold);
|
---|
[d55d7a6] | 122 |
|
---|
[a16764a6] | 123 | struct reset_font {};
|
---|
| 124 | std::ostream & operator<<(std::ostream & os, reset_font);
|
---|
[d55d7a6] | 125 | }
|
---|
| 126 |
|
---|
[51587aa] | 127 | // Local Variables: //
|
---|
| 128 | // tab-width: 4 //
|
---|
| 129 | // mode: c++ //
|
---|
| 130 | // compile-command: "make install" //
|
---|
| 131 | // End: //
|
---|