source: translator/Tuples/NameMatcher.cc @ 42dcae7

ADTaaron-thesisarm-ehast-experimentalcleanup-dtorsctordeferred_resndemanglerenumforall-pointer-decaygc_noraiijacob/cs343-translationjenkins-sandboxmemorynew-astnew-ast-unique-exprnew-envno_listpersistent-indexerpthread-emulationqualifiedEnumresolv-newstringwith_gc
Last change on this file since 42dcae7 was 51b7345, checked in by Peter A. Buhr <pabuhr@…>, 10 years ago

initial commit

  • Property mode set to 100644
File size: 1.8 KB
RevLine 
[51b7345]1#include "NameMatcher.h"
2#include "NameMatcher.h"
3
4namespace Tuples {
5  NameMatcher::NameMatcher( std::list< DeclarationWithType* > &formals )
6    : current( 0 ) {
7    int cnt = 0;
8    for( std::list< DeclarationWithType *>::const_iterator f = formals.begin(); f != formals.end(); ++f ) {
9      table.insert( std::pair< std::string, int >( (*f)->get_name(), cnt++ ) );
10      index.push_back(*f);
11    }
12    exprs.reserve( index.size() );
13  }
14
15  NameMatcher::~NameMatcher() {}
16
17  void NameMatcher::match( ResolvExpr::AltList &alternatives ) throw (NoMatch) {
18    if( alternatives.size() != index.size() )
19      throw NoMatch("Length of actuals and formals differ");
20
21    for( ResolvExpr::AltList::const_iterator a = alternatives.begin(); a != alternatives.end(); ++a ) {
22      if( a->expr->get_argName() != 0 )
23        if ( NameExpr *name = dynamic_cast<NameExpr *>( a->expr->get_argName() ) ) {
24          if ( table.find( name->get_name() ) != table.end() ) {
25            std::cerr << "Rearranging to " << table[ name->get_name() ] << "position in the list." << std::endl;
26            exprs[ table[ name->get_name() ] ] = &(*a);
27          } else
28            throw NoMatch( name->get_name() + "no such  designation" );
29        } /*else if( TupleExpr *tup = dynamic_cast<TupleExpr *>( a->expr->get_argName() ) )
30            std::cerr << "Designated expression" << std::endl; */
31      exprs.push_back( &(*a) );
32    }
33
34    /*std::cerr << "In matcher/match: ";
35    if ( exprs.size() != index.size() )
36      std::cerr << "exprs and index differ in length" << std::endl;
37    else
38      std::cerr << "is all good." << std::endl;
39    */
40  }
41
42  ResolvExpr::Alternative &NameMatcher::get_next() throw (NoMoreElements) {
43    if( current++ >= (int)(index.size()) )
44      throw NoMoreElements();
45    return *(new ResolvExpr::Alternative());
46  }
47} // namespace Tuples
Note: See TracBrowser for help on using the repository browser.