Changeset 933f32f for src/Common


Ignore:
Timestamp:
May 24, 2019, 10:19:41 AM (6 years ago)
Author:
Thierry Delisle <tdelisle@…>
Branches:
ADT, arm-eh, ast-experimental, cleanup-dtors, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
Children:
d908563
Parents:
6a9d4b4 (diff), 292642a (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 branch 'master' into cleanup-dtors

Location:
src/Common
Files:
10 added
1 deleted
7 edited
1 moved

Legend:

Unmodified
Added
Removed
  • src/Common/Assert.cc

    r6a9d4b4 r933f32f  
    3939}
    4040
     41void abort(const char *fmt, ... ) noexcept __attribute__((noreturn, format(printf, 1, 2)));
     42void abort(const char *fmt, ... ) noexcept {
     43        va_list args;
     44        va_start( args, fmt );
     45        vfprintf( stderr, fmt, args );
     46        va_end( args );
     47        fprintf( stderr, "\n" );
     48        abort();
     49}
     50
    4151// Local Variables: //
    4252// tab-width: 4 //
  • src/Common/PassVisitor.h

    r6a9d4b4 r933f32f  
    44
    55#include <stack>
    6 
     6#include <type_traits>
     7
     8#include "Common/Stats.h"
    79#include "Common/utility.h"
    810
     
    153155        virtual void visit( ConstructorInit * ctorInit ) override final;
    154156
    155         virtual void visit( Subrange * subrange ) override final;
    156 
    157157        virtual void visit( Constant * constant ) override final;
    158158
     
    255255        virtual Initializer * mutate( ConstructorInit * ctorInit ) override final;
    256256
    257         virtual Subrange * mutate( Subrange * subrange ) override final;
    258 
    259257        virtual Constant * mutate( Constant * constant ) override final;
    260258
     
    300298
    301299
    302         TypeSubstitution **             get_env_ptr    () { return env_impl             ( pass, 0); }
     300        auto                                    get_env_ptr    () -> decltype(env_impl( pass, 0)) { return env_impl( pass, 0); }
    303301        std::list< Statement* > *       get_beforeStmts() { return stmtsToAddBefore_impl( pass, 0); }
    304302        std::list< Statement* > *       get_afterStmts () { return stmtsToAddAfter_impl ( pass, 0); }
     
    347345};
    348346
     347class WithConstTypeSubstitution {
     348protected:
     349        WithConstTypeSubstitution() = default;
     350        ~WithConstTypeSubstitution() = default;
     351
     352public:
     353        const TypeSubstitution * env = nullptr;
     354};
     355
    349356class WithStmtsToAdd {
    350357protected:
     
    426433};
    427434
     435#include "Common/Stats.h"
     436
     437extern struct PassVisitorStats {
     438        size_t depth = 0;
     439        Stats::Counters::MaxCounter<double> * max = nullptr;
     440        Stats::Counters::AverageCounter<double> * avg = nullptr;
     441} pass_visitor_stats;
     442
    428443#include "SynTree/TypeSubstitution.h"
    429444#include "PassVisitor.impl.h"
  • src/Common/PassVisitor.impl.h

    r6a9d4b4 r933f32f  
    2020
    2121#define MUTATE_END( type, node )                \
    22         return call_postmutate< type * >( node ); \
     22        auto __return = call_postmutate< type * >( node ); \
     23        assert( __return ); \
     24        return __return;
    2325
    2426
     
    6769        SemanticErrorException errors;
    6870
     71        pass_visitor_stats.depth++;
     72        pass_visitor_stats.max->push(pass_visitor_stats.depth);
     73        pass_visitor_stats.avg->push(pass_visitor_stats.depth);
    6974        for ( std::list< Declaration* >::iterator i = decls.begin(); ; ++i ) {
     75
     76
    7077                // splice in new declarations after previous decl
    7178                if ( !empty( afterDecls ) ) { decls.splice( i, *afterDecls ); }
     
    8390                if ( !empty( beforeDecls ) ) { decls.splice( i, *beforeDecls ); }
    8491        }
     92        pass_visitor_stats.depth--;
    8593        if ( ! errors.isEmpty() ) {
    8694                throw errors;
     
    94102        SemanticErrorException errors;
    95103
     104        pass_visitor_stats.depth++;
     105        pass_visitor_stats.max->push(pass_visitor_stats.depth);
     106        pass_visitor_stats.avg->push(pass_visitor_stats.depth);
    96107        for ( std::list< Declaration* >::iterator i = decls.begin(); ; ++i ) {
    97108                // splice in new declarations after previous decl
     
    109120                if ( !empty( beforeDecls ) ) { decls.splice( i, *beforeDecls ); }
    110121        }
     122        pass_visitor_stats.depth--;
    111123        if ( ! errors.isEmpty() ) {
    112124                throw errors;
     
    126138        if ( ! visitor.get_visit_children() ) return;
    127139        SemanticErrorException errors;
     140
     141        pass_visitor_stats.depth++;
     142        pass_visitor_stats.max->push(pass_visitor_stats.depth);
     143        pass_visitor_stats.avg->push(pass_visitor_stats.depth);
    128144        for ( typename Container::iterator i = container.begin(); i != container.end(); ++i ) {
    129145                try {
     
    135151                }
    136152        }
     153        pass_visitor_stats.depth--;
    137154        if ( ! errors.isEmpty() ) {
    138155                throw errors;
     
    151168template< typename Container, typename pass_type >
    152169inline void maybeMutate_impl( Container & container, PassVisitor< pass_type > & mutator ) {
     170
    153171        if ( ! mutator.get_visit_children() ) return;
    154172        SemanticErrorException errors;
     173
     174        pass_visitor_stats.depth++;
     175        pass_visitor_stats.max->push(pass_visitor_stats.depth);
     176        pass_visitor_stats.avg->push(pass_visitor_stats.depth);
    155177        for ( typename Container::iterator i = container.begin(); i != container.end(); ++i ) {
    156178                try {
     
    163185                } // try
    164186        } // for
     187        pass_visitor_stats.depth--;
    165188        if ( ! errors.isEmpty() ) {
    166189                throw errors;
     
    185208        DeclList_t* afterDecls  = get_afterDecls();
    186209
     210        pass_visitor_stats.depth++;
     211        pass_visitor_stats.max->push(pass_visitor_stats.depth);
     212        pass_visitor_stats.avg->push(pass_visitor_stats.depth);
    187213        for ( std::list< Statement* >::iterator i = statements.begin(); i != statements.end(); ++i ) {
    188214
     
    192218                try {
    193219                        func( *i );
     220                        assert( *i );
    194221                        assert(( empty( beforeStmts ) && empty( afterStmts ))
    195222                            || ( empty( beforeDecls ) && empty( afterDecls )) );
     
    202229                if ( !empty( beforeStmts ) ) { statements.splice( i, *beforeStmts ); }
    203230        }
     231        pass_visitor_stats.depth--;
    204232
    205233        if ( !empty( afterDecls ) ) { splice( std::back_inserter( statements ), afterDecls); }
     
    229257
    230258        // don't want statements from outer CompoundStmts to be added to this CompoundStmt
    231         ValueGuardPtr< TypeSubstitution * >  oldEnv        ( get_env_ptr    () );
     259        ValueGuardPtr< typename std::remove_pointer<decltype(get_env_ptr())>::type >  oldEnv( get_env_ptr() );
    232260        ValueGuardPtr< DeclList_t >          oldBeforeDecls( get_beforeDecls() );
    233261        ValueGuardPtr< DeclList_t >          oldAfterDecls ( get_afterDecls () );
     
    19651993
    19661994        // don't want statements from outer CompoundStmts to be added to this StmtExpr
    1967         ValueGuardPtr< TypeSubstitution * >      oldEnv        ( get_env_ptr() );
     1995        ValueGuardPtr< typename std::remove_pointer<decltype(get_env_ptr())>::type >  oldEnv( get_env_ptr() );
    19681996        ValueGuardPtr< std::list< Statement* > > oldBeforeStmts( get_beforeStmts() );
    19691997        ValueGuardPtr< std::list< Statement* > > oldAfterStmts ( get_afterStmts () );
     
    19822010
    19832011        // don't want statements from outer CompoundStmts to be added to this StmtExpr
    1984         ValueGuardPtr< TypeSubstitution * >      oldEnv        ( get_env_ptr() );
     2012        ValueGuardPtr< typename std::remove_pointer<decltype(get_env_ptr())>::type >  oldEnv( get_env_ptr() );
    19852013        ValueGuardPtr< std::list< Statement* > > oldBeforeStmts( get_beforeStmts() );
    19862014        ValueGuardPtr< std::list< Statement* > > oldAfterStmts ( get_afterStmts () );
     
    26782706
    26792707//--------------------------------------------------------------------------
    2680 // Subrange
    2681 template< typename pass_type >
    2682 void PassVisitor< pass_type >::visit( Subrange * node ) {
    2683         VISIT_START( node );
    2684 
    2685         VISIT_END( node );
    2686 }
    2687 
    2688 template< typename pass_type >
    2689 Subrange * PassVisitor< pass_type >::mutate( Subrange * node  )  {
    2690         MUTATE_START( node );
    2691 
    2692         MUTATE_END( Subrange, node );
    2693 }
    2694 
    2695 //--------------------------------------------------------------------------
    26962708// Attribute
    26972709template< typename pass_type >
  • src/Common/PassVisitor.proto.h

    r6a9d4b4 r933f32f  
    165165static inline type * name##_impl( __attribute__((unused)) pass_type& pass, __attribute__((unused)) long unused ) { return nullptr;}    \
    166166
    167 FIELD_PTR( TypeSubstitution *, env )
     167FIELD_PTR( const TypeSubstitution *, env )
    168168FIELD_PTR( std::list< Statement* >, stmtsToAddBefore )
    169169FIELD_PTR( std::list< Statement* >, stmtsToAddAfter  )
     
    174174FIELD_PTR( PassVisitor<pass_type> * const, visitor )
    175175
     176#undef FIELD_PTR
     177
    176178//---------------------------------------------------------
    177179// Indexer
     
    220222INDEXER_FUNC2( addWith   , std::list< Expression * > &, BaseSyntaxNode * );
    221223
     224#undef INDEXER_FUNC1
     225#undef INDEXER_FUNC2
    222226
    223227template<typename pass_type>
  • src/Common/SemanticError.h

    r6a9d4b4 r933f32f  
    1717
    1818#include "ErrorObjects.h"
     19#include "AST/Node.hpp"
    1920#include <cstring>
    2021
  • src/Common/Stats/Heap.h

    r6a9d4b4 r933f32f  
    1616#pragma once
    1717
    18 namespace HeapStats {
    19         void newPass( const char * const name );
    20         void printStats();
     18namespace Stats {
     19        namespace Heap {
     20                void newPass( const char * const name );
     21                void print();
     22        }
    2123}
  • src/Common/module.mk

    r6a9d4b4 r933f32f  
    1515###############################################################################
    1616
    17 SRC += Common/SemanticError.cc \
    18        Common/UniqueName.cc \
    19        Common/DebugMalloc.cc \
    20        Common/Assert.cc \
    21        Common/Heap.cc \
    22        Common/Eval.cc
     17SRC_COMMON = \
     18      Common/Assert.cc \
     19      Common/Eval.cc \
     20      Common/PassVisitor.cc \
     21      Common/SemanticError.cc \
     22      Common/Stats/Counter.cc \
     23      Common/Stats/Heap.cc \
     24      Common/Stats/Stats.cc \
     25      Common/Stats/Time.cc \
     26      Common/UniqueName.cc
     27
     28SRC += $(SRC_COMMON) Common/DebugMalloc.cc
     29SRCDEMANGLE += $(SRC_COMMON)
  • src/Common/utility.h

    r6a9d4b4 r933f32f  
    463463std::pair<long long int, bool> eval(Expression * expr);
    464464
    465 // -----------------------------------------------------------------------------
    466 /// Reorders the input range in-place so that the minimal-value elements according to the
    467 /// comparator are in front;
     465namespace ast {
     466        class Expr;
     467}
     468
     469std::pair<long long int, bool> eval(const ast::Expr * expr);
     470
     471// -----------------------------------------------------------------------------
     472/// Reorders the input range in-place so that the minimal-value elements according to the
     473/// comparator are in front;
    468474/// returns the iterator after the last minimal-value element.
    469475template<typename Iter, typename Compare>
    470476Iter sort_mins( Iter begin, Iter end, Compare& lt ) {
    471477        if ( begin == end ) return end;
    472        
     478
    473479        Iter min_pos = begin;
    474480        for ( Iter i = begin + 1; i != end; ++i ) {
Note: See TracChangeset for help on using the changeset viewer.