source: src/ResolvExpr/CandidatePrinter.cpp @ ab9c1b3

Last change on this file since ab9c1b3 was 39d8950, checked in by Andrew Beach <ajbeach@…>, 3 years ago

Thread global information through resolution. Non-top-level calls to the resolver have a bit of a hack but improvements would require changes to the Pass helpers.

  • Property mode set to 100644
File size: 1.6 KB
Line 
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// CandidatePrinter.cpp -- Print expression canditates.
8//
9// Author           : Andrew Beach
10// Created On       : Tue Nov  9  9:54:00 2021
11// Last Modified By : Andrew Beach
12// Last Modified On : Wed Mar 16 13:56:00 2022
13// Update Count     : 1
14//
15
16#include "CandidatePrinter.hpp"
17
18#include "AST/Expr.hpp"
19#include "AST/Pass.hpp"
20#include "AST/Print.hpp"
21#include "AST/Stmt.hpp"
22#include "AST/TranslationUnit.hpp"
23#include "ResolvExpr/CandidateFinder.hpp"
24#include "ResolvExpr/Resolver.h"
25
26#include <iostream>
27
28namespace ResolvExpr {
29
30namespace {
31
32class CandidatePrintCore : public ast::WithSymbolTable,
33                public ast::WithConstTranslationUnit {
34        std::ostream & os;
35public:
36        CandidatePrintCore( std::ostream & os ) : os( os ) {}
37
38        void postvisit( const ast::ExprStmt * stmt ) {
39                ast::TypeEnvironment env;
40                CandidateFinder finder( { symtab, transUnit().global }, env );
41                finder.find( stmt->expr, ResolvMode::withAdjustment() );
42                int count = 1;
43                os << "There are " << finder.candidates.size() << " candidates\n";
44                for ( const std::shared_ptr<Candidate> & cand : finder ) {
45                        os << "Candidate " << count++ << " ==============\n";
46                        ast::print( os, cand->expr->result.get() );
47                        os << std::endl;
48                }
49        }
50};
51
52} // namespace
53
54void printCandidates( ast::TranslationUnit & transUnit ) {
55        ast::Pass<CandidatePrintCore>::run( transUnit, std::cout );
56}
57
58} // namespace ResolvExpr
59
60// Local Variables: //
61// tab-width: 4 //
62// mode: c++ //
63// compile-command: "make install" //
64// End: //
Note: See TracBrowser for help on using the repository browser.