Changeset 68e9ace for src/Common


Ignore:
Timestamp:
May 2, 2018, 5:36:02 PM (7 years ago)
Author:
Thierry Delisle <tdelisle@…>
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
Message:

Fixed semantic warning severity handling

Location:
src/Common
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • src/Common/SemanticError.cc

    r623c16a r68e9ace  
    1616#include <cstdarg>
    1717#include <cstdio>                                                                               // for fileno, stderr
     18#include <cstring>
    1819#include <unistd.h>                                                                             // for isatty
    1920#include <iostream>                                                                             // for basic_ostream, operator<<, ostream
    2021#include <list>                                                                                 // for list, _List_iterator
    2122#include <string>                                                                               // for string, operator<<, operator+, to_string
     23#include <vector>
    2224
    2325#include "Common/utility.h"                                                             // for to_string, CodeLocation (ptr only)
    2426#include "SemanticError.h"
    2527
     28//-----------------------------------------------------------------------------
     29// Severity Handling
     30std::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
     41void SemanticWarning_SuppressAll() {
     42        for( auto & s : get_severities() ) {
     43                s = Severity::Suppress;
     44        }
     45}
     46
     47void SemanticWarning_EnableAll() {
     48        for( auto & s : get_severities() ) {
     49                s = Severity::Warn;
     50        }
     51}
     52
     53void SemanticWarning_WarningAsError() {
     54        for( auto & s : get_severities() ) {
     55                if(s == Severity::Warn) s = Severity::Error;
     56        }
     57}
     58
     59void 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
    2672SemanticErrorException::SemanticErrorException( CodeLocation location, std::string error ) {
    2773        append( location, error );
     
    69115
    70116void SemanticWarningImpl( CodeLocation location, Warning warning, const char * const fmt, ... ) {
    71         Severity severity = WarningFormats[(int)warning].severity;
     117        Severity severity = get_severities()[(int)warning];
    72118        switch(severity) {
    73119        case Severity::Suppress :
  • src/Common/SemanticError.h

    r623c16a r68e9ace  
    4646        const char * const name;
    4747        const char * const message;
    48         mutable Severity severity;
     48        const Severity default_severity;
    4949};
    5050
    5151constexpr 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},
    5454        {"qualifiers-zero_t-one_t", "questionable use of type qualifier %s with %s", Severity::Warn},
    5555};
     
    7171void SemanticWarningImpl (CodeLocation loc, Warning warn, const char * const fmt, ...) __attribute__((format(printf, 3, 4)));
    7272
     73void SemanticWarning_SuppressAll   ();
     74void SemanticWarning_EnableAll     ();
     75void SemanticWarning_WarningAsError();
     76void SemanticWarning_Set           (const char * const name, Severity s);
    7377
    7478//-----------------------------------------------------------------------------
Note: See TracChangeset for help on using the changeset viewer.