Changeset 68e9ace for src/Common
- Timestamp:
- May 2, 2018, 5:36:02 PM (7 years ago)
- Branches:
- ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, with_gc
- Children:
- 161cdf1
- Parents:
- 623c16a
- Location:
- src/Common
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Common/SemanticError.cc
r623c16a r68e9ace 16 16 #include <cstdarg> 17 17 #include <cstdio> // for fileno, stderr 18 #include <cstring> 18 19 #include <unistd.h> // for isatty 19 20 #include <iostream> // for basic_ostream, operator<<, ostream 20 21 #include <list> // for list, _List_iterator 21 22 #include <string> // for string, operator<<, operator+, to_string 23 #include <vector> 22 24 23 25 #include "Common/utility.h" // for to_string, CodeLocation (ptr only) 24 26 #include "SemanticError.h" 25 27 28 //----------------------------------------------------------------------------- 29 // Severity Handling 30 std::vector<Severity> & get_severities() { 31 static std::vector<Severity> severities; 32 if(severities.empty()) { 33 severities.reserve((size_t)Warning::NUMBER_OF_WARNINGS); 34 for ( const auto w : WarningFormats ) { 35 severities.push_back( w.default_severity ); 36 } // for 37 } 38 return severities; 39 } 40 41 void SemanticWarning_SuppressAll() { 42 for( auto & s : get_severities() ) { 43 s = Severity::Suppress; 44 } 45 } 46 47 void SemanticWarning_EnableAll() { 48 for( auto & s : get_severities() ) { 49 s = Severity::Warn; 50 } 51 } 52 53 void SemanticWarning_WarningAsError() { 54 for( auto & s : get_severities() ) { 55 if(s == Severity::Warn) s = Severity::Error; 56 } 57 } 58 59 void SemanticWarning_Set(const char * const name, Severity s) { 60 size_t idx = 0; 61 for ( auto & w : WarningFormats ) { 62 if ( std::strcmp( name, w.name ) == 0 ) { 63 get_severities()[idx] = s; 64 break; 65 } 66 idx++; 67 } 68 } 69 70 //----------------------------------------------------------------------------- 71 // Semantic Error 26 72 SemanticErrorException::SemanticErrorException( CodeLocation location, std::string error ) { 27 73 append( location, error ); … … 69 115 70 116 void SemanticWarningImpl( CodeLocation location, Warning warning, const char * const fmt, ... ) { 71 Severity severity = WarningFormats[(int)warning].severity;117 Severity severity = get_severities()[(int)warning]; 72 118 switch(severity) { 73 119 case Severity::Suppress : -
src/Common/SemanticError.h
r623c16a r68e9ace 46 46 const char * const name; 47 47 const char * const message; 48 mutable Severityseverity;48 const Severity default_severity; 49 49 }; 50 50 51 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},52 {"self-assign" , "self assignment of expression: %s" , Severity::Warn}, 53 {"reference-conversion" , "rvalue to reference conversion of rvalue: %s" , Severity::Warn}, 54 54 {"qualifiers-zero_t-one_t", "questionable use of type qualifier %s with %s", Severity::Warn}, 55 55 }; … … 71 71 void SemanticWarningImpl (CodeLocation loc, Warning warn, const char * const fmt, ...) __attribute__((format(printf, 3, 4))); 72 72 73 void SemanticWarning_SuppressAll (); 74 void SemanticWarning_EnableAll (); 75 void SemanticWarning_WarningAsError(); 76 void SemanticWarning_Set (const char * const name, Severity s); 73 77 74 78 //-----------------------------------------------------------------------------
Note: See TracChangeset
for help on using the changeset viewer.