source: translator/Tuples/NameMatcher.cc@ fe3b61b

ADT aaron-thesis arm-eh ast-experimental cleanup-dtors ctor deferred_resn demangler enum forall-pointer-decay gc_noraii jacob/cs343-translation jenkins-sandbox memory new-ast new-ast-unique-expr new-env no_list persistent-indexer pthread-emulation qualifiedEnum resolv-new string with_gc
Last change on this file since fe3b61b was 51b73452, checked in by Peter A. Buhr <pabuhr@…>, 11 years ago

initial commit

  • Property mode set to 100644
File size: 1.8 KB
Line 
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.