Ignore:
Timestamp:
May 19, 2015, 4:58:14 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:
843054c2
Parents:
01aeade
Message:

licencing: sixth groups of files

Location:
translator/Designators
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • translator/Designators/Processor.cc

    r01aeade ra08ba92  
    55// file "LICENCE" distributed with Cforall.
    66//
    7 // XXX.cc --
     7// Processor.cc --
    88//
    99// Author           : Richard C. Bilson
    1010// Created On       : Mon May 18 07:44:20 2015
    11 // Last Modified By :
    12 // Last Modified On :
    13 // Update Count     : 0
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Tue May 19 16:23:10 2015
     13// Update Count     : 2
    1414//
     15
    1516#include <vector>
    1617#include <algorithm>
     
    2021
    2122namespace Designators {
    22     Matcher::Matcher( const std::list< DeclarationWithType * > &decls ) {
    23         int cnt = 0;
    24         for ( std::list< DeclarationWithType * >::const_iterator i = decls.begin();
    25              i != decls.end(); i++, cnt++ ) {
    26             std::string newName = (*i)->get_name();
    27             if ( table.find( newName ) == table.end() ) {
    28                 table.insert( std::pair<std::string, int>(newName, cnt) );
    29                 order.push_back( newName );
    30                 declarations.push_back( *i );
    31                 alternatives.push_back( 0 );
    32             }
     23        Matcher::Matcher( const std::list< DeclarationWithType * > &decls ) {
     24                int cnt = 0;
     25                for ( std::list< DeclarationWithType * >::const_iterator i = decls.begin();
     26                          i != decls.end(); i++, cnt++ ) {
     27                        std::string newName = (*i)->get_name();
     28                        if ( table.find( newName ) == table.end() ) {
     29                                table.insert( std::pair<std::string, int>(newName, cnt) );
     30                                order.push_back( newName );
     31                                declarations.push_back( *i );
     32                                alternatives.push_back( 0 );
     33                        } // if
     34                } // for
    3335        }
    34     }
    3536
    36     template< class InputIterator >
    37     bool Matcher::add(InputIterator begin, InputIterator end, ResolvExpr::Alternative &alt ) {
    38         while ( begin != end ) {
    39             if ( table.find( *begin ) != table.end() )
    40                 alternatives[ table[ *begin ] ] = new ResolvExpr::Alternative(alt);
    41             else
    42                 return false;
    43             begin++;
     37        template< class InputIterator >
     38        bool Matcher::add(InputIterator begin, InputIterator end, ResolvExpr::Alternative &alt ) {
     39                while ( begin != end ) {
     40                        if ( table.find( *begin ) != table.end() )
     41                                alternatives[ table[ *begin ] ] = new ResolvExpr::Alternative(alt);
     42                        else
     43                                return false;
     44                        begin++;
     45                } // while
     46                return true;
    4447        }
    45         return true;
    46     }
    4748
    48     template< class InputIterator, class OutputIterator >
    49     bool Matcher::slice(InputIterator begin, InputIterator end, OutputIterator out ) {
    50         while ( begin != end )
    51             if ( table.find( *begin ) != table.end() )
    52                 *out++ = declarations [ table[ *begin++ ] ];
    53             else
    54                 return false; // throw 0;
    55         return true;
    56     }
     49        template< class InputIterator, class OutputIterator >
     50        bool Matcher::slice(InputIterator begin, InputIterator end, OutputIterator out ) {
     51                while ( begin != end )
     52                        if ( table.find( *begin ) != table.end() )
     53                                *out++ = declarations [ table[ *begin++ ] ];
     54                        else
     55                                return false; // throw 0;
     56                return true;
     57        }
    5758
    58     template< class OutputIterator >
    59     bool Matcher::get_reorderedCall( OutputIterator out ) {
    60         // fill call with defaults, if need be
    61         for (Matcher::iterator o = begin(); o != end(); o++ )
    62             if ( alternatives[ table[ *o ] ] == 0 )
    63                 return false;
    64             else
    65                 out++ = *alternatives[table[ *o ]];
    66         return true;
    67     }
     59        template< class OutputIterator >
     60        bool Matcher::get_reorderedCall( OutputIterator out ) {
     61                // fill call with defaults, if need be
     62                for (Matcher::iterator o = begin(); o != end(); o++ )
     63                        if ( alternatives[ table[ *o ] ] == 0 )
     64                                return false;
     65                        else
     66                                out++ = *alternatives[table[ *o ]];
     67                return true;
     68        }
    6869
    69     bool fixDesignations( ResolvExpr::AlternativeFinder &finder, Expression *designation ) {
    70         // Distribute `designation' over alternatives contained in `finder'
    71         if ( ! designation) return false;
    72         else
    73             for ( ResolvExpr::AlternativeFinder::iterator alt = finder.begin(); alt != finder.end(); alt++ )
    74                 alt->expr->set_argName( designation );
    75         return true;
    76     }
     70        bool fixDesignations( ResolvExpr::AlternativeFinder &finder, Expression *designation ) {
     71                // Distribute `designation' over alternatives contained in `finder'
     72                if ( ! designation) return false;
     73                else
     74                        for ( ResolvExpr::AlternativeFinder::iterator alt = finder.begin(); alt != finder.end(); alt++ )
     75                                alt->expr->set_argName( designation );
     76                return true;
     77        }
    7778
    78     template < class OutputIterator >
    79     bool extractNames( Expression *expr, OutputIterator out, Matcher matcher ) {
    80         Expression *designator = expr->get_argName();
    81         if ( designator == 0 ) return false;
     79        template < class OutputIterator >
     80        bool extractNames( Expression *expr, OutputIterator out, Matcher matcher ) {
     81                Expression *designator = expr->get_argName();
     82                if ( designator == 0 ) return false;
    8283
    83         if ( NameExpr *ndes = dynamic_cast<NameExpr *>(designator) )
    84             out++ = ndes->get_name();
    85         else if ( TupleExpr *tdes = dynamic_cast<TupleExpr *>(designator) ) {
    86             std::cerr << "Tuple designation" << std::endl;
     84                if ( NameExpr *ndes = dynamic_cast<NameExpr *>(designator) )
     85                        out++ = ndes->get_name();
     86                else if ( TupleExpr *tdes = dynamic_cast<TupleExpr *>(designator) ) {
     87                        std::cerr << "Tuple designation" << std::endl;
    8788//      ObjectDecl *decl = extractTupleV(matcher, tdes); // xxx
    88             // transform?
    89             for ( std::list< Expression * >::iterator n = tdes->get_exprs().begin();
    90                 n != tdes->get_exprs().end(); n++ ) {
     89                        // transform?
     90                        for ( std::list< Expression * >::iterator n = tdes->get_exprs().begin();
     91                                  n != tdes->get_exprs().end(); n++ ) {
    9192
    92                 if ( NameExpr *name = dynamic_cast<NameExpr *>(*n) )
    93                     out++ = name->get_name();
    94                 else
    95                     // flatten nested Tuples
    96                     throw SemanticError( "Invalid tuple designation." );
    97             }
     93                                if ( NameExpr *name = dynamic_cast<NameExpr *>(*n) )
     94                                        out++ = name->get_name();
     95                                else
     96                                        // flatten nested Tuples
     97                                        throw SemanticError( "Invalid tuple designation." );
     98                        } // for
     99                } // if
     100                return true;
    98101        }
    99         return true;
    100     }
    101102
    102     std::string extractName( Expression *expr ) /* throw NoNameExtraction */ {
    103         if ( NameExpr *name = dynamic_cast< NameExpr *>(expr) )
    104             return name->get_name();
    105         else /* if () */
    106             throw 0;
    107     }
     103        std::string extractName( Expression *expr ) /* throw NoNameExtraction */ {
     104                if ( NameExpr *name = dynamic_cast< NameExpr *>(expr) )
     105                        return name->get_name();
     106                else /* if () */
     107                        throw 0;
     108        }
    108109
    109     DeclarationWithType *gensym( DeclarationWithType *, std::string prefix ) {
    110         return 0;
    111     }
     110        DeclarationWithType *gensym( DeclarationWithType *, std::string prefix ) {
     111                return 0;
     112        }
    112113
    113     ObjectDecl *extractTupleV( Matcher matcher, TupleExpr *nmTuple ) {
    114         // extract a subtuple of the function `fun' argument list, corresponding to the tuple of names requested by
    115         // `nmTuple'.
    116         std::list< Expression * > &exprs = nmTuple->get_exprs();
    117         std::cerr << "In extractTupleV, the tuple has " << exprs.size() << " components." << std::endl;
    118         std::list< std::string > names;
    119         std::transform( exprs.begin(), exprs.end(), back_inserter(names), extractName );
    120         std::list< DeclarationWithType * > decls;
    121         matcher.slice( names.begin(), names.end(), back_inserter(decls) );
    122         //std::for_each( decls.begin(), decls.end(), gensym );
    123         std::cerr << "Returning declaration with " << decls.size() << " components." << std::endl;
     114        ObjectDecl *extractTupleV( Matcher matcher, TupleExpr *nmTuple ) {
     115                // extract a subtuple of the function `fun' argument list, corresponding to the tuple of names requested by
     116                // `nmTuple'.
     117                std::list< Expression * > &exprs = nmTuple->get_exprs();
     118                std::cerr << "In extractTupleV, the tuple has " << exprs.size() << " components." << std::endl;
     119                std::list< std::string > names;
     120                std::transform( exprs.begin(), exprs.end(), back_inserter(names), extractName );
     121                std::list< DeclarationWithType * > decls;
     122                matcher.slice( names.begin(), names.end(), back_inserter(decls) );
     123                //std::for_each( decls.begin(), decls.end(), gensym );
     124                std::cerr << "Returning declaration with " << decls.size() << " components." << std::endl;
    124125
    125         return 0;//new ObjectDecl()
    126     }
     126                return 0;//new ObjectDecl()
     127        }
    127128
    128     void check_alternative( FunctionType *fun, ResolvExpr::AltList &args ) {
    129         using namespace ResolvExpr;
     129        void check_alternative( FunctionType *fun, ResolvExpr::AltList &args ) {
     130                using namespace ResolvExpr;
    130131
    131         Matcher matcher( fun->get_parameters() );
    132         for ( AltList::iterator a = args.begin(); a != args.end(); a++ ) {
    133             std::list< std::string > actNames;
    134             if ( ! extractNames( a->expr, back_inserter(actNames), matcher ) ) {
    135                 return; // not a designated call, leave alternative alone
    136             } else {
    137                 // see if there's a match
    138                 matcher.add( actNames.begin(), actNames.end(), *a );
    139             }
     132                Matcher matcher( fun->get_parameters() );
     133                for ( AltList::iterator a = args.begin(); a != args.end(); a++ ) {
     134                        std::list< std::string > actNames;
     135                        if ( ! extractNames( a->expr, back_inserter(actNames), matcher ) ) {
     136                                return; // not a designated call, leave alternative alone
     137                        } else {
     138                                // see if there's a match
     139                                matcher.add( actNames.begin(), actNames.end(), *a );
     140                        } // if
     141                } // for
     142                //AltList newArgs;
     143                args.clear();
     144                matcher.get_reorderedCall( back_inserter(args) );
     145
     146                return;
    140147        }
    141         //AltList newArgs;
    142         args.clear();
    143         matcher.get_reorderedCall( back_inserter(args) );
    144 
    145         return;
    146     }
    147148#if 0
    148     void pruneAlternatives( Expression *expr, ResolvExpr::AlternativeFinder &finder ) {
    149         if ( expr->get_argName() != 0 ) {
    150             // Looking at designated expression
    151             using namespace ResolvExpr;
    152             AltList &alternatives = finder.get_alternatives();
    153             std::cerr << "Now printing alternatives: " << std::endl;
    154             for ( AltList::iterator a = alternatives.begin(); a != alternatives.end(); a++ )
    155                 a->expr->print( std::cerr );
    156             //std::cerr << "Looking for constructions of length no more than: " << tdes->get_exprs().size() << "." << std::endl;
     149        void pruneAlternatives( Expression *expr, ResolvExpr::AlternativeFinder &finder ) {
     150                if ( expr->get_argName() != 0 ) {
     151                        // Looking at designated expression
     152                        using namespace ResolvExpr;
     153                        AltList &alternatives = finder.get_alternatives();
     154                        std::cerr << "Now printing alternatives: " << std::endl;
     155                        for ( AltList::iterator a = alternatives.begin(); a != alternatives.end(); a++ )
     156                                a->expr->print( std::cerr );
     157                        //std::cerr << "Looking for constructions of length no more than: " << tdes->get_exprs().size() << "." << std::endl;
     158                }
     159                return;
    157160        }
    158         return;
    159     }
    160161#endif // 0
    161162} // namespaces Designators
     163
    162164// Local Variables: //
    163165// tab-width: 4 //
  • translator/Designators/Processor.h

    r01aeade ra08ba92  
    55// file "LICENCE" distributed with Cforall.
    66//
    7 // XXX.cc --
     7// Processor.h --
    88//
    99// Author           : Richard C. Bilson
    1010// Created On       : Mon May 18 07:44:20 2015
    11 // Last Modified By :
    12 // Last Modified On :
    13 // Update Count     : 0
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Tue May 19 16:24:34 2015
     13// Update Count     : 3
    1414//
     15
    1516#include "SynTree/Declaration.h"
    1617#include "SynTree/Expression.h"
     
    2425
    2526namespace Designators {
    26   class Matcher;
    27   class GenSym;
     27        class Matcher;
     28        class GenSym;
    2829
    29   template < class OutputIterator >  bool extractNames( std::list< DeclarationWithType * > &, OutputIterator );
    30   template < class OutputIterator >  bool extractNames( Expression *, OutputIterator, Matcher );
    31   void check_alternative( FunctionType *, ResolvExpr::AltList & );
    32   ObjectDecl *extractTupleV( Matcher, TupleExpr *names );
    33   bool fixDesignations( ResolvExpr::AlternativeFinder &finder, Expression *designation );
    34   DeclarationWithType *gensym( GenSym &, DeclarationWithType * );
     30        template < class OutputIterator >  bool extractNames( std::list< DeclarationWithType * > &, OutputIterator );
     31        template < class OutputIterator >  bool extractNames( Expression *, OutputIterator, Matcher );
     32        void check_alternative( FunctionType *, ResolvExpr::AltList & );
     33        ObjectDecl *extractTupleV( Matcher, TupleExpr *names );
     34        bool fixDesignations( ResolvExpr::AlternativeFinder &finder, Expression *designation );
     35        DeclarationWithType *gensym( GenSym &, DeclarationWithType * );
    3536
    36   class GenSym {
    37   public:
    38     GenSym( std::string prefix = "" ) : gensym_count(0) {}
    39     GenSym( GenSym &other ) { gensym_count = other.gensym_count; }
     37        class GenSym {
     38          public:
     39                GenSym( std::string prefix = "" ) : gensym_count(0) {}
     40                GenSym( GenSym &other ) { gensym_count = other.gensym_count; }
    4041
    4142//    std::string get_symbol() { }
    42   private:
    43     std::string prefix;
    44     int gensym_count;
    45   };
     43          private:
     44                std::string prefix;
     45                int gensym_count;
     46        };
    4647
    47   // template< typename Key >
    48   class Matcher {
    49   public:
    50     typedef std::vector< std::string >::iterator iterator;
     48        // template< typename Key >
     49        class Matcher {
     50          public:
     51                typedef std::vector< std::string >::iterator iterator;
    5152
    52     Matcher( const std::list< DeclarationWithType * > & );
    53     ~Matcher() {}
     53                Matcher( const std::list< DeclarationWithType * > & );
     54                ~Matcher() {}
    5455
    55     template< class OutputIterator > bool get_reorderedCall( OutputIterator );
    56     template< class InputIterator >  bool add(InputIterator, InputIterator, ResolvExpr::Alternative &);
    57     template< class InputIterator, class OutputIterator >  bool slice(InputIterator begin, InputIterator end, OutputIterator );
    58     //std::vector<std::string> &get_order() const { return order; }
     56                template< class OutputIterator > bool get_reorderedCall( OutputIterator );
     57                template< class InputIterator >  bool add(InputIterator, InputIterator, ResolvExpr::Alternative &);
     58                template< class InputIterator, class OutputIterator >  bool slice(InputIterator begin, InputIterator end, OutputIterator );
     59                //std::vector<std::string> &get_order() const { return order; }
    5960
    60     iterator begin() { return order.begin(); }
    61     iterator end() { return order.end(); }
     61                iterator begin() { return order.begin(); }
     62                iterator end() { return order.end(); }
    6263
    63     //Expression *operator[]( int idx ) { return table( order[ idx ] ); }
    64   private:
    65     std::map< std::string, int > table;
    66     std::vector<std::string> order;
    67     std::vector<DeclarationWithType *> declarations;
    68     std::vector<ResolvExpr::Alternative *> alternatives;
    69   };
    70   //  void pruneAlternatives( Expression *expr, ResolvExpr::AlternativeFinder & );
    71 
     64                //Expression *operator[]( int idx ) { return table( order[ idx ] ); }
     65          private:
     66                std::map< std::string, int > table;
     67                std::vector<std::string> order;
     68                std::vector<DeclarationWithType *> declarations;
     69                std::vector<ResolvExpr::Alternative *> alternatives;
     70        };
     71        //  void pruneAlternatives( Expression *expr, ResolvExpr::AlternativeFinder & );
    7272} // namespace Designators
    7373
    74 /*
    75   Local Variables:
    76   mode: c++
    77   End:
    78 */
    7974// Local Variables: //
    8075// tab-width: 4 //
Note: See TracChangeset for help on using the changeset viewer.