Ignore:
Timestamp:
May 18, 2015, 11:45:33 PM (9 years ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, ctor, deferred_resn, demangler, enum, forall-pointer-decay, gc_noraii, jacob/cs343-translation, jenkins-sandbox, master, memory, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, string, with_gc
Children:
01aeade
Parents:
0dd3a2f
Message:

licencing: fourth groups of files

File:
1 edited

Legend:

Unmodified
Added
Removed
  • translator/Tuples/FunctionChecker.cc

    r0dd3a2f r51587aa  
     1//
     2// Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo
     3//
     4// The contents of this file are covered under the licence agreement in the
     5// file "LICENCE" distributed with Cforall.
     6//
     7// FunctionChecker.cc --
     8//
     9// Author           : Richard C. Bilson
     10// Created On       : Mon May 18 07:44:20 2015
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Mon May 18 11:59:55 2015
     13// Update Count     : 3
     14//
     15
    116#include "FunctionChecker.h"
    217#include "FunctionFixer.h"
     
    823
    924namespace Tuples {
    10   using namespace std;
     25        using namespace std;
    1126
    12   void checkFunctions( std::list< Declaration * > translationUnit )
    13   {
    14     FunctionChecker fchk(true);
    15     TupleDistrib td;
    16     FunctionFixer ff;
     27        void checkFunctions( std::list< Declaration * > translationUnit ) {
     28                FunctionChecker fchk( true );
     29                TupleDistrib td;
     30                FunctionFixer ff;
    1731
    18     mutateAll( translationUnit , fchk );
    19     mutateAll( translationUnit , ff );
    20     mutateAll( translationUnit , td );
    21     return;
    22   }
    23 
    24   FunctionChecker::FunctionChecker( bool _topLevel, UniqueName *_nameGen ) : topLevel( _topLevel ), nameGen( _nameGen ) {
    25     if ( topLevel) {
    26       assert( ! nameGen );
    27       nameGen = new UniqueName("_MVR_");
    28     } else
    29       assert( nameGen );
    30   }
    31 
    32   FunctionChecker::~FunctionChecker() {
    33     if ( topLevel) {
    34       delete nameGen;
    35       nameGen = 0;
    36     }
    37   }
    38 
    39   Statement* FunctionChecker::mutate(ExprStmt *exprStmt) {
    40     exprStmt->set_expr( maybeMutate( exprStmt->get_expr(), *this ) );
    41     if ( ! tempExpr.empty() ) {
    42       assert ( ! temporaries.empty() );
    43       CompoundStmt *newBlock = new CompoundStmt( std::list< Label >() );
    44       // declarations
    45       for ( std::list< ObjectDecl *>::iterator d = temporaries.begin(); d != temporaries.end(); ++d )
    46         newBlock->get_kids().push_back( new DeclStmt( std::list<Label>(), *d ) );
    47       // new expression statements
    48       for ( std::list< Expression *>::iterator e = tempExpr.begin(); e != tempExpr.end(); ++e )
    49         newBlock->get_kids().push_back( new ExprStmt( std::list<Label>(), *e ) );
    50 
    51       newBlock->get_kids().push_back( exprStmt );
    52       return newBlock;
    53     } else
    54       return exprStmt;
    55   }
    56 
    57   Expression* FunctionChecker::mutate(ApplicationExpr *applicationExpr) {
    58     if ( topLevel )
    59       ; // In top level of Functionchecker
    60 
    61     if ( applicationExpr->get_results().size() > 1 ) {
    62       for ( std::list< Type *>::iterator res = applicationExpr->get_results().begin(); res != applicationExpr->get_results().end(); res++ )
    63         temporaries.push_back( new ObjectDecl(nameGen->newName(),Declaration::Auto,LinkageSpec::AutoGen, 0, (*res)->clone(), 0 ) );
    64 
    65       assert( ! temporaries.empty() );
    66     }
    67 
    68     applicationExpr->set_function(  maybeMutate( applicationExpr->get_function(), *this ) );
    69 
    70     std::list< Expression * > newArgs;
    71     for ( std::list< Expression *>::iterator e = applicationExpr->get_args().begin(); e != applicationExpr->get_args().end(); ++e ) {
    72       FunctionChecker rec( false, nameGen );
    73       (*e)->acceptMutator( rec );
    74 
    75       if ( ! rec.temporaries.empty() ) {
    76         TupleExpr *lhs = new TupleExpr;
    77         std::list< Expression * > &tmem = lhs->get_exprs();
    78         for ( std::list<ObjectDecl *>::iterator d = rec.temporaries.begin();  d != rec.temporaries.end(); ++d ) {
    79           tmem.push_back( new VariableExpr( *d ) );
    80           newArgs.push_back( new VariableExpr( *d ) );
     32                mutateAll( translationUnit , fchk );
     33                mutateAll( translationUnit , ff );
     34                mutateAll( translationUnit , td );
     35                return;
    8136        }
    8237
    83         // construct tuple assignment
    84         std::list<Expression *> args;
    85         args.push_back( new AddressExpr(lhs) );
    86         args.push_back( *e );
    87         tempExpr.push_back( new UntypedExpr( new NameExpr("?=?"), args ) );
     38        FunctionChecker::FunctionChecker( bool _topLevel, UniqueName *_nameGen ) : topLevel( _topLevel ), nameGen( _nameGen ) {
     39                if ( topLevel ) {
     40                        assert( ! nameGen );
     41                        nameGen = new UniqueName("_MVR_");
     42                } else
     43                        assert( nameGen );
     44        }
    8845
    89         temporaries.splice( temporaries.end(), rec.temporaries );
    90       } else
    91         newArgs.push_back( *e );
    92       // percolate to recursive calls
    93     }
     46        FunctionChecker::~FunctionChecker() {
     47                if ( topLevel ) {
     48                        delete nameGen;
     49                        nameGen = 0;
     50                }
     51        }
    9452
    95     applicationExpr->get_args().clear();
    96     std::copy( newArgs.begin(), newArgs.end(), back_inserter(applicationExpr->get_args()) );
     53        Statement* FunctionChecker::mutate( ExprStmt *exprStmt ) {
     54                exprStmt->set_expr( maybeMutate( exprStmt->get_expr(), *this ) );
     55                if ( ! tempExpr.empty() ) {
     56                        assert ( ! temporaries.empty() );
     57                        CompoundStmt *newBlock = new CompoundStmt( std::list< Label >() );
     58                        // declarations
     59                        for ( std::list< ObjectDecl *>::iterator d = temporaries.begin(); d != temporaries.end(); ++d )
     60                                newBlock->get_kids().push_back( new DeclStmt( std::list<Label>(), *d ) );
     61                        // new expression statements
     62                        for ( std::list< Expression *>::iterator e = tempExpr.begin(); e != tempExpr.end(); ++e )
     63                                newBlock->get_kids().push_back( new ExprStmt( std::list<Label>(), *e ) );
    9764
    98     return applicationExpr;
    99   }
     65                        newBlock->get_kids().push_back( exprStmt );
     66                        return newBlock;
     67                } else
     68                        return exprStmt;
     69        }
    10070
    101   Expression* TupleDistrib::mutate(UntypedExpr *expr) {
    102     if (  NameExpr *assgnop = dynamic_cast< NameExpr * >(expr->get_function()) ) {
    103       if ( assgnop->get_name() == std::string("?=?") ) {
    104         std::list<Expression *> &args = expr->get_args();
    105         assert(args.size() == 2);
    106         //if args.front() points to a tuple and if args.back() is already resolved
    107         if ( AddressExpr *addr = dynamic_cast<AddressExpr *>(args.front()) )
    108           if ( TupleExpr *lhs = dynamic_cast<TupleExpr *>(addr->get_arg()) )
    109             if ( ApplicationExpr *rhs = dynamic_cast<ApplicationExpr *>( args.back() ) ) {
    110               for ( std::list<Expression *>::iterator tc = lhs->get_exprs().begin(); tc != lhs->get_exprs().end(); ++tc )
    111                 rhs->get_args().push_back( new AddressExpr( *tc ) );
    112               return rhs; // XXX
    113             }
    114       } else
    115         assert(false); // It's not an assignment, shouldn't be here
    116     }
    117     return expr;
    118   }
     71        Expression* FunctionChecker::mutate( ApplicationExpr *applicationExpr ) {
     72                if ( topLevel )
     73                        ; // In top level of Functionchecker
    11974
    120 } // namespace Tuples
     75                if ( applicationExpr->get_results().size() > 1 ) {
     76                        for ( std::list< Type *>::iterator res = applicationExpr->get_results().begin(); res != applicationExpr->get_results().end(); res++ )
     77                                temporaries.push_back( new ObjectDecl( nameGen->newName(),Declaration::Auto,LinkageSpec::AutoGen, 0, (*res )->clone(), 0 ) );
     78
     79                        assert( ! temporaries.empty() );
     80                }
     81
     82                applicationExpr->set_function(  maybeMutate( applicationExpr->get_function(), *this ) );
     83
     84                std::list< Expression * > newArgs;
     85                for ( std::list< Expression *>::iterator e = applicationExpr->get_args().begin(); e != applicationExpr->get_args().end(); ++e ) {
     86                        FunctionChecker rec( false, nameGen );
     87                        (*e )->acceptMutator( rec );
     88
     89                        if ( ! rec.temporaries.empty() ) {
     90                                TupleExpr *lhs = new TupleExpr;
     91                                std::list< Expression * > &tmem = lhs->get_exprs();
     92                                for ( std::list<ObjectDecl *>::iterator d = rec.temporaries.begin();  d != rec.temporaries.end(); ++d ) {
     93                                        tmem.push_back( new VariableExpr( *d ) );
     94                                        newArgs.push_back( new VariableExpr( *d ) );
     95                                }
     96
     97                                // construct tuple assignment
     98                                std::list<Expression *> args;
     99                                args.push_back( new AddressExpr( lhs ) );
     100                                args.push_back( *e );
     101                                tempExpr.push_back( new UntypedExpr( new NameExpr("?=?"), args ) );
     102
     103                                temporaries.splice( temporaries.end(), rec.temporaries );
     104                        } else
     105                                newArgs.push_back( *e );
     106                        // percolate to recursive calls
     107                }
     108
     109                applicationExpr->get_args().clear();
     110                std::copy( newArgs.begin(), newArgs.end(), back_inserter( applicationExpr->get_args()) );
     111
     112                return applicationExpr;
     113        }
     114
     115        Expression* TupleDistrib::mutate( UntypedExpr *expr ) {
     116                if (  NameExpr *assgnop = dynamic_cast< NameExpr * >( expr->get_function()) ) {
     117                        if ( assgnop->get_name() == std::string("?=?") ) {
     118                                std::list<Expression *> &args = expr->get_args();
     119                                assert( args.size() == 2 );
     120                                //if args.front() points to a tuple and if args.back() is already resolved
     121                                if ( AddressExpr *addr = dynamic_cast<AddressExpr *>( args.front()) )
     122                                        if ( TupleExpr *lhs = dynamic_cast<TupleExpr *>( addr->get_arg()) )
     123                                                if ( ApplicationExpr *rhs = dynamic_cast<ApplicationExpr *>( args.back() ) ) {
     124                                                        for ( std::list<Expression *>::iterator tc = lhs->get_exprs().begin(); tc != lhs->get_exprs().end(); ++tc )
     125                                                                rhs->get_args().push_back( new AddressExpr( *tc ) );
     126                                                        return rhs; // XXX
     127                                                } // if
     128                        } else
     129                                assert( false ); // It's not an assignment, shouldn't be here
     130                } // if
     131                return expr;
     132        }
     133
     134}
     135
     136// namespace Tuples
     137// Local Variables: //
     138// tab-width: 4 //
     139// mode: c++ //
     140// compile-command: "make install" //
     141// End: //
Note: See TracChangeset for help on using the changeset viewer.