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 | // NameMatcher.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 15:00:06 2015 |
---|
13 | // Update Count : 1 |
---|
14 | // |
---|
15 | |
---|
16 | #include "NameMatcher.h" |
---|
17 | #include "NameMatcher.h" |
---|
18 | |
---|
19 | namespace Tuples { |
---|
20 | NameMatcher::NameMatcher( std::list< DeclarationWithType* > &formals ) : current( 0 ) { |
---|
21 | int cnt = 0; |
---|
22 | for ( std::list< DeclarationWithType *>::const_iterator f = formals.begin(); f != formals.end(); ++f ) { |
---|
23 | table.insert( std::pair< std::string, int >( (*f)->get_name(), cnt++ ) ); |
---|
24 | index.push_back(*f); |
---|
25 | } // for |
---|
26 | exprs.reserve( index.size() ); |
---|
27 | } |
---|
28 | |
---|
29 | NameMatcher::~NameMatcher() {} |
---|
30 | |
---|
31 | void NameMatcher::match( ResolvExpr::AltList &alternatives ) throw (NoMatch) { |
---|
32 | if ( alternatives.size() != index.size() ) |
---|
33 | throw NoMatch("Length of actuals and formals differ"); |
---|
34 | |
---|
35 | for ( ResolvExpr::AltList::const_iterator a = alternatives.begin(); a != alternatives.end(); ++a ) { |
---|
36 | if ( a->expr->get_argName() != 0 ) |
---|
37 | if ( NameExpr *name = dynamic_cast<NameExpr *>( a->expr->get_argName() ) ) { |
---|
38 | if ( table.find( name->get_name() ) != table.end() ) { |
---|
39 | std::cerr << "Rearranging to " << table[ name->get_name() ] << "position in the list." << std::endl; |
---|
40 | exprs[ table[ name->get_name() ] ] = &(*a); |
---|
41 | } else |
---|
42 | throw NoMatch( name->get_name() + "no such designation" ); |
---|
43 | } /*else if ( TupleExpr *tup = dynamic_cast<TupleExpr *>( a->expr->get_argName() ) ) |
---|
44 | std::cerr << "Designated expression" << std::endl; */ |
---|
45 | exprs.push_back( &(*a) ); |
---|
46 | } // for |
---|
47 | |
---|
48 | /*std::cerr << "In matcher/match: "; |
---|
49 | if ( exprs.size() != index.size() ) |
---|
50 | std::cerr << "exprs and index differ in length" << std::endl; |
---|
51 | else |
---|
52 | std::cerr << "is all good." << std::endl; |
---|
53 | */ |
---|
54 | } |
---|
55 | |
---|
56 | ResolvExpr::Alternative &NameMatcher::get_next() throw (NoMoreElements) { |
---|
57 | if ( current++ >= (int)(index.size()) ) |
---|
58 | throw NoMoreElements(); |
---|
59 | return *(new ResolvExpr::Alternative()); |
---|
60 | } |
---|
61 | } // namespace Tuples |
---|
62 | |
---|
63 | // Local Variables: // |
---|
64 | // tab-width: 4 // |
---|
65 | // mode: c++ // |
---|
66 | // compile-command: "make install" // |
---|
67 | // End: // |
---|