Changeset ff29f08 for src/Common


Ignore:
Timestamp:
May 18, 2018, 2:09:21 PM (6 years ago)
Author:
Aaron Moss <a3moss@…>
Branches:
new-env, with_gc
Children:
2472a19
Parents:
f6f0cca3 (diff), c7d8100c (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge remote-tracking branch 'origin/master' into with_gc

Location:
src/Common
Files:
2 added
7 edited

Legend:

Unmodified
Added
Removed
  • src/Common/PassVisitor.h

    rf6f0cca3 rff29f08  
    7171        virtual void visit( ExprStmt * exprStmt ) override final;
    7272        virtual void visit( AsmStmt * asmStmt ) override final;
     73        virtual void visit( DirectiveStmt * dirStmt ) override final;
    7374        virtual void visit( IfStmt * ifStmt ) override final;
    7475        virtual void visit( WhileStmt * whileStmt ) override final;
     
    170171        virtual Statement * mutate( ExprStmt * exprStmt ) override final;
    171172        virtual Statement * mutate( AsmStmt * asmStmt ) override final;
     173        virtual Statement * mutate( DirectiveStmt * dirStmt ) override final;
    172174        virtual Statement * mutate( IfStmt * ifStmt ) override final;
    173175        virtual Statement * mutate( WhileStmt * whileStmt ) override final;
  • src/Common/PassVisitor.impl.h

    rf6f0cca3 rff29f08  
    690690        VISIT_START( node );
    691691
    692         maybeAccept_impl( node->condition, *this );
    693         maybeAccept_impl( node->message  , *this );
     692        node->condition = visitExpression( node->condition );
     693        maybeAccept_impl( node->message, *this );
    694694
    695695        VISIT_END( node );
     
    700700        MUTATE_START( node );
    701701
    702         maybeMutate_impl( node->condition, *this );
    703         maybeMutate_impl( node->message  , *this );
     702        node->condition = mutateExpression( node->condition );
     703        maybeMutate_impl( node->message, *this );
    704704
    705705        MUTATE_END( StaticAssertDecl, node );
     
    772772        maybeMutate_impl( node->input, *this );
    773773        maybeMutate_impl( node->clobber, *this );
     774
     775        MUTATE_END( Statement, node );
     776}
     777
     778//--------------------------------------------------------------------------
     779// AsmStmt
     780template< typename pass_type >
     781void PassVisitor< pass_type >::visit( DirectiveStmt * node ) {
     782        VISIT_START( node )
     783
     784        VISIT_END( node );
     785}
     786
     787template< typename pass_type >
     788Statement * PassVisitor< pass_type >::mutate( DirectiveStmt * node ) {
     789        MUTATE_START( node );
    774790
    775791        MUTATE_END( Statement, node );
  • src/Common/PassVisitor.proto.h

    rf6f0cca3 rff29f08  
    4747
    4848        operator bool() { return m_ref ? *m_ref : true; }
    49         bool operator=( bool val ) { return *m_ref = val; }
     49        bool operator=( bool val ) { assert(m_ref); return *m_ref = val; }
    5050
    5151private:
     
    5353        friend class ChildrenGuard;
    5454
    55         bool * set( bool & val ) {
     55        bool * set( bool * val ) {
    5656                bool * prev = m_ref;
    57                 m_ref = &val;
     57                m_ref = val;
    5858                return prev;
    5959        }
     
    6767        ChildrenGuard( bool_ref * ref )
    6868                : m_val ( true )
    69                 , m_prev( ref ? ref->set( m_val ) : nullptr )
     69                , m_prev( ref ? ref->set( &m_val ) : nullptr )
    7070                , m_ref ( ref )
    7171        {}
     
    7373        ~ChildrenGuard() {
    7474                if( m_ref ) {
    75                         m_ref->set( *m_prev );
     75                        m_ref->set( m_prev );
    7676                }
    7777        }
  • src/Common/SemanticError.cc

    rf6f0cca3 rff29f08  
    77// SemanticError.cc --
    88//
    9 // Author           : Richard C. Bilson
     9// Author           : Thierry Delisle
    1010// Created On       : Mon May 18 07:44:20 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Tue Aug 29 18:17:35 2017
    13 // Update Count     : 3
     12// Last Modified On : Wed May 16 15:01:20 2018
     13// Update Count     : 9
    1414//
    1515
    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"
     27
     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 ( const 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
     72bool SemanticErrorThrow = false;
    2573
    2674SemanticErrorException::SemanticErrorException( CodeLocation location, std::string error ) {
     
    4896
    4997void SemanticError( CodeLocation location, std::string error ) {
     98        SemanticErrorThrow = true;
    5099        throw SemanticErrorException(location, error);
    51100}
     
    69118
    70119void SemanticWarningImpl( CodeLocation location, Warning warning, const char * const fmt, ... ) {
    71         Severity severity = WarningFormats[(int)warning].severity;
     120        Severity severity = get_severities()[(int)warning];
    72121        switch(severity) {
    73122        case Severity::Suppress :
  • src/Common/SemanticError.h

    rf6f0cca3 rff29f08  
    77// SemanticError.h --
    88//
    9 // Author           : Richard C. Bilson
     9// Author           : Thierry Delisle
    1010// Created On       : Mon May 18 07:44:20 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Thu Apr 19 17:52:03 2018
    13 // Update Count     : 19
     12// Last Modified On : Wed May 16 15:01:23 2018
     13// Update Count     : 30
    1414//
    1515
     
    1717
    1818#include "ErrorObjects.h"
     19#include <cstring>
    1920
    2021//-----------------------------------------------------------------------------
    2122// Errors
     23
     24extern bool SemanticErrorThrow;
    2225
    2326__attribute__((noreturn)) void SemanticError( CodeLocation location, std::string error );
     
    4649        const char * const name;
    4750        const char * const message;
    48         mutable Severity severity;
     51        const Severity default_severity;
    4952};
    5053
    51 constexpr const WarningData WarningFormats[] = {
    52         {"self-assign"         , "self assignment of expression: %s"           , Severity::Warn},
    53         {"reference-conversion", "rvalue to reference conversion of rvalue: %s", Severity::Warn},
     54constexpr WarningData WarningFormats[] = {
     55        {"self-assign"            , "self assignment of expression: %s"            , Severity::Warn},
     56        {"reference-conversion"   , "rvalue to reference conversion of rvalue: %s" , Severity::Warn},
    5457        {"qualifiers-zero_t-one_t", "questionable use of type qualifier %s with %s", Severity::Warn},
    5558};
     
    7174void SemanticWarningImpl (CodeLocation loc, Warning warn, const char * const fmt, ...) __attribute__((format(printf, 3, 4)));
    7275
     76void SemanticWarning_SuppressAll   ();
     77void SemanticWarning_EnableAll     ();
     78void SemanticWarning_WarningAsError();
     79void SemanticWarning_Set           (const char * const name, Severity s);
     80
     81// SKULLDUGGERY: cfa.cc is built before SemanticError.cc but needs this routine.
     82static inline bool SemanticWarning_Exist(const char * const name) {
     83        for ( const auto & w : WarningFormats ) {
     84                if ( std::strcmp( name, w.name ) == 0 ) return true;
     85        }
     86        return false;
     87}
    7388
    7489//-----------------------------------------------------------------------------
  • src/Common/module.mk

    rf6f0cca3 rff29f08  
    1919       Common/DebugMalloc.cc \
    2020       Common/GC.cc \
    21        Common/Assert.cc
     21       Common/Assert.cc \
     22       Common/Heap.cc
  • src/Common/utility.h

    rf6f0cca3 rff29f08  
    1010// Created On       : Mon May 18 07:44:20 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Fri Apr 20 22:35:33 2018
    13 // Update Count     : 38
     12// Last Modified On : Sun May  6 22:24:16 2018
     13// Update Count     : 40
    1414//
    1515
     
    438438
    439439template<typename T>
    440 inline constexpr T ilog2(const T & t) {
    441         if ( std::is_integral<T>::value ) {
     440inline
     441#if defined(__GNUC__) && __GNUC__ > 4
     442constexpr
     443#endif
     444T ilog2(const T & t) {
     445        if(std::is_integral<T>::value) {
    442446                const constexpr int r = sizeof(t) * __CHAR_BIT__ - 1;
    443                 if ( sizeof(T) == sizeof(unsigned int ) ) return r - __builtin_clz( t );
    444                 if ( sizeof(T) == sizeof(unsigned long) ) return r - __builtin_clzl( t );
    445                 if ( sizeof(T) == sizeof(unsigned long long) ) return r - __builtin_clzll( t );
    446         } // if
     447                if( sizeof(T) == sizeof(unsigned       int) ) return r - __builtin_clz  ( t );
     448                if( sizeof(T) == sizeof(unsigned      long) ) return r - __builtin_clzl ( t );
     449                if( sizeof(T) == sizeof(unsigned long long) ) return r - __builtin_clzll( t );
     450        }
     451        assert(false);
    447452        return -1;
    448 } // ilong2
     453} // ilog2
    449454
    450455
Note: See TracChangeset for help on using the changeset viewer.