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 | // Candidate.cpp -- |
---|
8 | // |
---|
9 | // Author : Aaron B. Moss |
---|
10 | // Created On : Wed Jun 5 14:30:00 2019 |
---|
11 | // Last Modified By : Aaron B. Moss |
---|
12 | // Last Modified On : Wed Jun 5 14:30:00 2019 |
---|
13 | // Update Count : 1 |
---|
14 | // |
---|
15 | |
---|
16 | #include "Candidate.hpp" |
---|
17 | |
---|
18 | #include <iostream> |
---|
19 | #include <sstream> |
---|
20 | |
---|
21 | #include "AST/Print.hpp" |
---|
22 | |
---|
23 | namespace ResolvExpr { |
---|
24 | |
---|
25 | void print( std::ostream & os, const Candidate & cand, Indenter indent ) { |
---|
26 | os << "Cost " << cand.cost << ": "; |
---|
27 | if ( cand.expr ) { |
---|
28 | ++indent; |
---|
29 | ast::print( os, cand.expr, indent ); |
---|
30 | os << std::endl << indent-1 << "(types:" << std::endl; |
---|
31 | os << indent; |
---|
32 | ast::print( os, cand.expr->result, indent ); |
---|
33 | --indent; |
---|
34 | os << std::endl << indent << ")" << std::endl; |
---|
35 | } else { |
---|
36 | os << "Null expression!" << std::endl; |
---|
37 | } // if |
---|
38 | os << indent << "Environment:"; |
---|
39 | ast::print( os, cand.env, indent+1 ); |
---|
40 | os << std::endl; |
---|
41 | } |
---|
42 | |
---|
43 | void print( std::ostream & os, const CandidateList & cands, Indenter indent ) { |
---|
44 | std::vector<std::string> sorted; |
---|
45 | sorted.reserve(cands.size()); |
---|
46 | for(const auto & c : cands) { |
---|
47 | std::ostringstream ss; |
---|
48 | print( ss, *c, indent ); |
---|
49 | sorted.push_back(ss.str()); |
---|
50 | } |
---|
51 | |
---|
52 | std::sort(sorted.begin(), sorted.end()); |
---|
53 | |
---|
54 | for ( const auto & s : sorted ) { |
---|
55 | os << s << std::endl; |
---|
56 | } |
---|
57 | } |
---|
58 | |
---|
59 | } // namespace ResolvExpr |
---|
60 | |
---|
61 | // Local Variables: // |
---|
62 | // tab-width: 4 // |
---|
63 | // mode: c++ // |
---|
64 | // compile-command: "make install" // |
---|
65 | // End: // |
---|