| [a32b204] | 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 | //
 | 
|---|
| [2463d0e] | 7 | // ConversionCost.h --
 | 
|---|
| [a32b204] | 8 | //
 | 
|---|
 | 9 | // Author           : Richard C. Bilson
 | 
|---|
 | 10 | // Created On       : Sun May 17 09:37:28 2015
 | 
|---|
| [fb2bde4] | 11 | // Last Modified By : Andrew Beach
 | 
|---|
 | 12 | // Last Modified On : Mon Jun 24 10:00:00 2019
 | 
|---|
 | 13 | // Update Count     : 5
 | 
|---|
| [a32b204] | 14 | //
 | 
|---|
 | 15 | 
 | 
|---|
| [6b0b624] | 16 | #pragma once
 | 
|---|
| [51b73452] | 17 | 
 | 
|---|
| [0c6596f] | 18 | #include <functional>         // for function
 | 
|---|
 | 19 | 
 | 
|---|
| [ea6332d] | 20 | #include "Cost.h"             // for Cost
 | 
|---|
| [bd0b6b62] | 21 | 
 | 
|---|
| [fb2bde4] | 22 | #include "AST/Fwd.hpp"
 | 
|---|
 | 23 | #include "AST/Pass.hpp"       // for WithShortCircuiting
 | 
|---|
| [bd0b6b62] | 24 | #include "Common/PassVisitor.h"
 | 
|---|
| [ea6332d] | 25 | #include "SynTree/Visitor.h"  // for Visitor
 | 
|---|
 | 26 | #include "SynTree/SynTree.h"  // for Visitor Nodes
 | 
|---|
 | 27 | 
 | 
|---|
 | 28 | namespace SymTab {
 | 
|---|
| [0c6596f] | 29 |         class Indexer;
 | 
|---|
| [ea6332d] | 30 | }  // namespace SymTab
 | 
|---|
| [51b73452] | 31 | 
 | 
|---|
 | 32 | namespace ResolvExpr {
 | 
|---|
| [0c6596f] | 33 |         class TypeEnvironment;
 | 
|---|
| [ea6332d] | 34 | 
 | 
|---|
| [721cd19f] | 35 |         typedef std::function<Cost(Type *, Type *, const SymTab::Indexer &, const TypeEnvironment &)> CostFunction;
 | 
|---|
| [bd0b6b62] | 36 |         struct ConversionCost : public WithShortCircuiting {
 | 
|---|
| [a32b204] | 37 |           public:
 | 
|---|
| [721cd19f] | 38 |                 ConversionCost( Type *dest, const SymTab::Indexer &indexer, const TypeEnvironment &env, CostFunction );
 | 
|---|
| [2463d0e] | 39 | 
 | 
|---|
| [a32b204] | 40 |                 Cost get_cost() const { return cost; }
 | 
|---|
 | 41 | 
 | 
|---|
| [bd0b6b62] | 42 |                 void previsit( BaseSyntaxNode * ) { visit_children = false; }
 | 
|---|
 | 43 | 
 | 
|---|
 | 44 |                 void postvisit( VoidType * voidType );
 | 
|---|
 | 45 |                 void postvisit( BasicType * basicType );
 | 
|---|
 | 46 |                 void postvisit( PointerType * pointerType );
 | 
|---|
 | 47 |                 void postvisit( ArrayType * arrayType );
 | 
|---|
 | 48 |                 void postvisit( ReferenceType * refType );
 | 
|---|
 | 49 |                 void postvisit( FunctionType * functionType );
 | 
|---|
 | 50 |                 void postvisit( StructInstType * aggregateUseType );
 | 
|---|
 | 51 |                 void postvisit( UnionInstType * aggregateUseType );
 | 
|---|
 | 52 |                 void postvisit( EnumInstType * aggregateUseType );
 | 
|---|
 | 53 |                 void postvisit( TraitInstType * aggregateUseType );
 | 
|---|
 | 54 |                 void postvisit( TypeInstType * aggregateUseType );
 | 
|---|
 | 55 |                 void postvisit( TupleType * tupleType );
 | 
|---|
 | 56 |                 void postvisit( VarArgsType * varArgsType );
 | 
|---|
 | 57 |                 void postvisit( ZeroType * zeroType );
 | 
|---|
 | 58 |                 void postvisit( OneType * oneType );
 | 
|---|
| [a32b204] | 59 |           protected:
 | 
|---|
 | 60 |                 Type *dest;
 | 
|---|
 | 61 |                 const SymTab::Indexer &indexer;
 | 
|---|
 | 62 |                 Cost cost;
 | 
|---|
 | 63 |                 const TypeEnvironment &env;
 | 
|---|
| [721cd19f] | 64 |                 CostFunction costFunc;
 | 
|---|
| [a32b204] | 65 |         };
 | 
|---|
| [2463d0e] | 66 | 
 | 
|---|
| [721cd19f] | 67 |         typedef std::function<int(Type *, Type *, const SymTab::Indexer &, const TypeEnvironment &)> PtrsFunction;
 | 
|---|
| [0c6596f] | 68 |         Cost convertToReferenceCost( Type * src, ReferenceType * dest, const SymTab::Indexer & indexer, const TypeEnvironment & env, PtrsFunction func );
 | 
|---|
| [fb2bde4] | 69 | 
 | 
|---|
 | 70 | // Some function pointer types, differ in return type.
 | 
|---|
 | 71 | using CostCalculation = std::function<Cost(const ast::Type *, const ast::Type *,
 | 
|---|
 | 72 |         const ast::SymbolTable &, const ast::TypeEnvironment &)>;
 | 
|---|
 | 73 | using NumCostCalculation = std::function<int(const ast::Type *, const ast::Type *,
 | 
|---|
 | 74 |         const ast::SymbolTable &, const ast::TypeEnvironment &)>;
 | 
|---|
 | 75 | 
 | 
|---|
| [3c89751] | 76 | #warning when the old ConversionCost is removed, get ride of the _new suffix.
 | 
|---|
| [fb2bde4] | 77 | class ConversionCost_new : public ast::WithShortCircuiting {
 | 
|---|
| [3c89751] | 78 | protected:
 | 
|---|
| [fb2bde4] | 79 |         const ast::Type * dst;
 | 
|---|
 | 80 |         const ast::SymbolTable & symtab;
 | 
|---|
 | 81 |         const ast::TypeEnvironment & env;
 | 
|---|
 | 82 |         CostCalculation costCalc;
 | 
|---|
 | 83 | public:
 | 
|---|
 | 84 |         Cost cost;
 | 
|---|
 | 85 | 
 | 
|---|
 | 86 |         ConversionCost_new( const ast::Type * dst, const ast::SymbolTable & symtab,
 | 
|---|
 | 87 |                         const ast::TypeEnvironment & env, CostCalculation costCalc ) :
 | 
|---|
 | 88 |                 dst( dst ), symtab( symtab ), env( env ), costCalc( costCalc ), cost( Cost::infinity )
 | 
|---|
 | 89 |         {}
 | 
|---|
 | 90 | 
 | 
|---|
 | 91 |         void previsit( const ast::Node * ) { visit_children = false; }
 | 
|---|
 | 92 | 
 | 
|---|
 | 93 |         void postvisit( const ast::VoidType * voidType );
 | 
|---|
 | 94 |         void postvisit( const ast::BasicType * basicType );
 | 
|---|
 | 95 |         void postvisit( const ast::PointerType * pointerType );
 | 
|---|
 | 96 |         void postvisit( const ast::ArrayType * arrayType );
 | 
|---|
 | 97 |         void postvisit( const ast::ReferenceType * refType );
 | 
|---|
 | 98 |         void postvisit( const ast::FunctionType * functionType );
 | 
|---|
 | 99 |         void postvisit( const ast::StructInstType * structInstType );
 | 
|---|
 | 100 |         void postvisit( const ast::UnionInstType * unionInstType );
 | 
|---|
 | 101 |         void postvisit( const ast::EnumInstType * enumInstType );
 | 
|---|
 | 102 |         void postvisit( const ast::TraitInstType * traitInstType );
 | 
|---|
 | 103 |         void postvisit( const ast::TypeInstType * typeInstType );
 | 
|---|
 | 104 |         void postvisit( const ast::TupleType * tupleType );
 | 
|---|
 | 105 |         void postvisit( const ast::VarArgsType * varArgsType );
 | 
|---|
 | 106 |         void postvisit( const ast::ZeroType * zeroType );
 | 
|---|
 | 107 |         void postvisit( const ast::OneType * oneType );
 | 
|---|
 | 108 | };
 | 
|---|
 | 109 | 
 | 
|---|
 | 110 | Cost convertToReferenceCost( const ast::Type * src, const ast::ReferenceType * dest,
 | 
|---|
 | 111 |         const ast::SymbolTable & indexer, const ast::TypeEnvironment & env, NumCostCalculation func );
 | 
|---|
 | 112 | 
 | 
|---|
| [51b73452] | 113 | } // namespace ResolvExpr
 | 
|---|
 | 114 | 
 | 
|---|
| [a32b204] | 115 | // Local Variables: //
 | 
|---|
 | 116 | // tab-width: 4 //
 | 
|---|
 | 117 | // mode: c++ //
 | 
|---|
 | 118 | // compile-command: "make install" //
 | 
|---|
 | 119 | // End: //
 | 
|---|