Changeset b826e6b for src/Common


Ignore:
Timestamp:
Jul 19, 2017, 11:49:33 AM (7 years ago)
Author:
Aaron Moss <a3moss@…>
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, resolv-new, with_gc
Children:
9cc0472
Parents:
fea3faa (diff), a57cb58 (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' of plg.uwaterloo.ca:software/cfa/cfa-cc

Location:
src/Common
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • src/Common/Assert.cc

    rfea3faa rb826e6b  
    1414//
    1515
    16 #include <assert.h>
    17 #include <cstdarg>                                                                              // varargs
    18 #include <cstdio>                                                                               // fprintf
    19 #include <cstdlib>                                                                              // abort
     16#include <cstdarg>  // for va_end, va_list, va_start
     17#include <cstdio>   // for fprintf, stderr, vfprintf
     18#include <cstdlib>  // for abort
    2019
    2120extern const char * __progname;                                                 // global name of running executable (argv[0])
  • src/Common/PassVisitor.h

    rfea3faa rb826e6b  
    1212#include "SynTree/Expression.h"
    1313#include "SynTree/Constant.h"
     14#include "SynTree/TypeSubstitution.h"
    1415
    1516#include "PassVisitor.proto.h"
     
    2627//                          stmtsToAddBefore or stmtsToAddAfter respectively.
    2728// | WithShortCircuiting  - provides the ability to skip visiting child nodes; set visit_children to false in pre{visit,mutate} to skip visiting children
    28 // | WithScopes           - provides the ability to save/restore data like a LIFO stack; to save, call GuardValue with the variable to save, the variable
     29// | WithGuards           - provides the ability to save/restore data like a LIFO stack; to save, call GuardValue with the variable to save, the variable
    2930//                          will automatically be restored to its previous value after the corresponding postvisit/postmutate teminates.
    3031//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------
     
    3233class PassVisitor final : public Visitor, public Mutator {
    3334public:
    34         PassVisitor() = default;
    3535
    3636        template< typename... Args >
     
    257257
    258258        void set_visit_children( bool& ref ) { bool_ref * ptr = visit_children_impl(pass, 0); if(ptr) ptr->set( ref ); }
    259 
    260         guard_value_impl init_guard() {
    261                 guard_value_impl guard;
    262                 auto at_cleanup = at_cleanup_impl(pass, 0);
    263                 if( at_cleanup ) {
    264                         *at_cleanup = [&guard]( cleanup_func_t && func, void* val ) {
    265                                 guard.push( std::move( func ), val );
    266                         };
    267                 }
    268                 return guard;
    269         }
    270259};
    271260
     
    283272
    284273public:
    285         TypeSubstitution * env;
     274        TypeSubstitution * env = nullptr;
    286275};
    287276
     
    295284        std::list< Statement* > stmtsToAddAfter;
    296285};
     286
     287class WithDeclsToAdd {
     288protected:
     289        WithDeclsToAdd() = default;
     290        ~WithDeclsToAdd() = default;
     291
     292public:
     293        std::list< Declaration* > declsToAddBefore;
     294        std::list< Declaration* > declsToAddAfter;
     295};
     296
    297297class WithShortCircuiting {
    298298protected:
     
    304304};
    305305
    306 class WithScopes {
    307 protected:
    308         WithScopes() = default;
    309         ~WithScopes() = default;
     306class WithGuards {
     307protected:
     308        WithGuards() = default;
     309        ~WithGuards() = default;
    310310
    311311public:
     
    318318                }, static_cast< void * >( & val ) );
    319319        }
     320
     321        template< typename T >
     322        void GuardScope( T& val ) {
     323                val.beginScope();
     324                at_cleanup( []( void * val ) {
     325                        static_cast< T * >( val )->endScope();
     326                }, static_cast< void * >( & val ) );
     327        }
     328
     329        template< typename Func >
     330        void GuardAction( Func func ) {
     331                at_cleanup( [func](__attribute__((unused)) void *) { func(); }, nullptr );
     332        }
    320333};
    321334
     
    323336class WithVisitorRef {
    324337protected:
    325         WithVisitorRef() = default;
    326         ~WithVisitorRef() = default;
    327 
    328 public:
    329         PassVisitor<pass_type> * const visitor;
     338        WithVisitorRef() {}
     339        ~WithVisitorRef() {}
     340
     341public:
     342        PassVisitor<pass_type> * const visitor = nullptr;
    330343};
    331344
  • src/Common/PassVisitor.impl.h

    rfea3faa rb826e6b  
    33#define VISIT_START( node )                     \
    44        __attribute__((unused))                   \
    5         const auto & guard = init_guard();        \
     5        guard_value_impl guard( at_cleanup_impl(pass, 0) );       \
    66        bool visit_children = true;               \
    77        set_visit_children( visit_children );   \
     
    1515#define MUTATE_START( node )                    \
    1616        __attribute__((unused))                   \
    17         const auto & guard = init_guard();        \
     17        guard_value_impl guard( at_cleanup_impl(pass, 0) );       \
    1818        bool visit_children = true;               \
    1919        set_visit_children( visit_children );   \
     
    6868        for ( std::list< Declaration* >::iterator i = decls.begin(); ; ++i ) {
    6969                // splice in new declarations after previous decl
    70                 if ( !empty( afterDecls ) ) { decls.splice( i, *afterDecls ); } 
     70                if ( !empty( afterDecls ) ) { decls.splice( i, *afterDecls ); }
    7171
    7272                if ( i == decls.end() ) break;
     
    8888        for ( std::list< Declaration* >::iterator i = decls.begin(); ; ++i ) {
    8989                // splice in new declarations after previous decl
    90                 if ( !empty( afterDecls ) ) { decls.splice( i, *afterDecls ); } 
     90                if ( !empty( afterDecls ) ) { decls.splice( i, *afterDecls ); }
    9191
    9292                if ( i == decls.end() ) break;
     
    104104void PassVisitor< pass_type >::handleStatementList( std::list< Statement * > & statements, func_t func ) {
    105105        SemanticError errors;
     106
     107        // don't want statements from outer CompoundStmts to be added to this CompoundStmt
     108        ValueGuardPtr< StmtList_t > oldBeforeStmts( get_beforeStmts() );
     109        ValueGuardPtr< StmtList_t > oldAfterStmts ( get_afterStmts () );
     110        ValueGuardPtr< DeclList_t > oldBeforeDecls( get_beforeDecls() );
     111        ValueGuardPtr< DeclList_t > oldAfterDecls ( get_afterDecls () );
    106112
    107113        StmtList_t* beforeStmts = get_beforeStmts();
     
    181187Statement * PassVisitor< pass_type >::visitStatement( Statement * stmt ) {
    182188        return handleStatement( stmt, [this]( Statement * stmt ) {
    183                 maybeAccept( stmt, *this ); 
     189                maybeAccept( stmt, *this );
    184190                return stmt;
    185191        });
     
    212218                expr->accept( *this );
    213219                return expr;
    214         });             
     220        });
    215221}
    216222
     
    565571        VISIT_START( node );
    566572
     573        // maybeAccept( node->get_env(), *this );
     574        maybeAccept( node->get_result(), *this );
     575
    567576        for ( auto expr : node->get_args() ) {
    568577                visitExpression( expr );
     
    575584Expression * PassVisitor< pass_type >::mutate( UntypedExpr * node ) {
    576585        MUTATE_START( node );
     586
     587        node->set_env( maybeMutate( node->get_env(), *this ) );
     588        node->set_result( maybeMutate( node->get_result(), *this ) );
    577589
    578590        for ( auto& expr : node->get_args() ) {
  • src/Common/PassVisitor.proto.h

    rfea3faa rb826e6b  
    55
    66typedef std::function<void( void * )> cleanup_func_t;
     7typedef std::function< void( cleanup_func_t, void * ) > at_cleanup_t;
    78
    89class guard_value_impl {
    910public:
    10         guard_value_impl() = default;
     11        guard_value_impl( at_cleanup_t * at_cleanup ) {
     12                if( at_cleanup ) {
     13                        *at_cleanup = [this]( cleanup_func_t && func, void* val ) {
     14                                push( std::move( func ), val );
     15                        };
     16                }
     17        }
    1118
    1219        ~guard_value_impl() {
     
    3340};
    3441
    35 typedef std::function< void( cleanup_func_t, void * ) > at_cleanup_t;
    3642
    3743class bool_ref {
     
    5662// Deep magic (a.k.a template meta programming) to make the templated visitor work
    5763// Basically the goal is to make 2 previsit_impl
    58 // 1 - Use when a pass implements a valid previsit. This uses overloading which means the any overload of 
     64// 1 - Use when a pass implements a valid previsit. This uses overloading which means the any overload of
    5965//     'pass.previsit( node )' that compiles will be used for that node for that type
    6066//     This requires that this option only compile for passes that actually define an appropriate visit.
  • src/Common/SemanticError.cc

    rfea3faa rb826e6b  
    1414//
    1515
    16 #include <iostream>
    17 #include <list>
    18 #include <string>
    19 #include <algorithm>
    20 #include <iterator>
     16#include <cstdio>            // for fileno, stderr
     17#include <unistd.h>          // for isatty
     18#include <iostream>          // for basic_ostream, operator<<, ostream
     19#include <list>              // for list, _List_iterator
     20#include <string>            // for string, operator<<, operator+, to_string
    2121
     22#include "Common/utility.h"  // for to_string, CodeLocation (ptr only)
    2223#include "SemanticError.h"
    23 
    24 #include <unistd.h>
    2524
    2625inline const std::string& error_str() {
  • src/Common/SemanticError.h

    rfea3faa rb826e6b  
    1717#define SEMANTICERROR_H
    1818
    19 #include <exception>
    20 #include <string>
    21 #include <sstream>
    22 #include <list>
    23 #include <iostream>
     19#include <exception>  // for exception
     20#include <iostream>   // for ostream
     21#include <list>       // for list
     22#include <string>     // for string
    2423
    25 #include "utility.h"
     24#include "utility.h"  // for CodeLocation, toString
    2625
    2726struct error {
  • src/Common/utility.h

    rfea3faa rb826e6b  
    305305// for ( val : group_iterate( container1, container2, ... ) ) {}
    306306// syntax to have a for each that iterates multiple containers of the same length
    307 // TODO: update to use variadic arguments
     307// TODO: update to use variadic arguments, perfect forwarding
    308308
    309309template< typename T1, typename T2 >
Note: See TracChangeset for help on using the changeset viewer.