[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 | // |
---|
[c92bdcc] | 7 | // ConversionCost.hpp -- |
---|
[a32b204] | 8 | // |
---|
| 9 | // Author : Richard C. Bilson |
---|
| 10 | // Created On : Sun May 17 09:37:28 2015 |
---|
[fb2bde4] | 11 | // Last Modified By : Andrew Beach |
---|
[1d17939] | 12 | // Last Modified On : Wed Jul 29 16:12:00 2020 |
---|
[cf32116] | 13 | // Update Count : 7 |
---|
[a32b204] | 14 | // |
---|
| 15 | |
---|
[6b0b624] | 16 | #pragma once |
---|
[51b7345] | 17 | |
---|
[0c6596f] | 18 | #include <functional> // for function |
---|
| 19 | |
---|
[c92bdcc] | 20 | #include "Cost.hpp" // for Cost |
---|
[bd0b6b62] | 21 | |
---|
[fb2bde4] | 22 | #include "AST/Fwd.hpp" |
---|
| 23 | #include "AST/Pass.hpp" // for WithShortCircuiting |
---|
[ea6332d] | 24 | |
---|
[51b7345] | 25 | namespace ResolvExpr { |
---|
[ea6332d] | 26 | |
---|
[fb2bde4] | 27 | // Some function pointer types, differ in return type. |
---|
[cf32116] | 28 | using CostCalculation = std::function<Cost(const ast::Type *, const ast::Type *, bool, |
---|
[fb2bde4] | 29 | const ast::SymbolTable &, const ast::TypeEnvironment &)>; |
---|
[cf32116] | 30 | using PtrsCalculation = std::function<int(const ast::Type *, const ast::Type *, |
---|
[fb2bde4] | 31 | const ast::SymbolTable &, const ast::TypeEnvironment &)>; |
---|
| 32 | |
---|
[fed6a0f] | 33 | Cost conversionCost( |
---|
| 34 | const ast::Type * src, const ast::Type * dst, bool srcIsLvalue, |
---|
| 35 | const ast::SymbolTable & symtab, const ast::TypeEnvironment & env ); |
---|
| 36 | |
---|
| 37 | Cost convertToReferenceCost( const ast::Type * src, const ast::ReferenceType * dest, |
---|
| 38 | bool srcIsLvalue, const ast::SymbolTable & indexer, const ast::TypeEnvironment & env, |
---|
| 39 | PtrsCalculation func ); |
---|
| 40 | |
---|
[0bd3faf] | 41 | class ConversionCost : public ast::WithShortCircuiting { |
---|
[3c89751] | 42 | protected: |
---|
[fb2bde4] | 43 | const ast::Type * dst; |
---|
[cf32116] | 44 | bool srcIsLvalue; |
---|
[fb2bde4] | 45 | const ast::SymbolTable & symtab; |
---|
| 46 | const ast::TypeEnvironment & env; |
---|
| 47 | CostCalculation costCalc; |
---|
| 48 | public: |
---|
[c15085d] | 49 | static size_t traceId; |
---|
[fb2bde4] | 50 | Cost cost; |
---|
[e6b42e7] | 51 | Cost result() { return cost; } |
---|
[fb2bde4] | 52 | |
---|
[0bd3faf] | 53 | ConversionCost( const ast::Type * dst, bool srcIsLvalue, const ast::SymbolTable & symtab, |
---|
[fb2bde4] | 54 | const ast::TypeEnvironment & env, CostCalculation costCalc ) : |
---|
[cf32116] | 55 | dst( dst ), srcIsLvalue( srcIsLvalue ), symtab( symtab ), env( env ), |
---|
| 56 | costCalc( costCalc ), cost( Cost::infinity ) |
---|
[fb2bde4] | 57 | {} |
---|
| 58 | |
---|
| 59 | void previsit( const ast::Node * ) { visit_children = false; } |
---|
| 60 | |
---|
| 61 | void postvisit( const ast::VoidType * voidType ); |
---|
| 62 | void postvisit( const ast::BasicType * basicType ); |
---|
| 63 | void postvisit( const ast::PointerType * pointerType ); |
---|
| 64 | void postvisit( const ast::ArrayType * arrayType ); |
---|
| 65 | void postvisit( const ast::ReferenceType * refType ); |
---|
| 66 | void postvisit( const ast::FunctionType * functionType ); |
---|
| 67 | void postvisit( const ast::EnumInstType * enumInstType ); |
---|
| 68 | void postvisit( const ast::TraitInstType * traitInstType ); |
---|
| 69 | void postvisit( const ast::TypeInstType * typeInstType ); |
---|
| 70 | void postvisit( const ast::TupleType * tupleType ); |
---|
| 71 | void postvisit( const ast::VarArgsType * varArgsType ); |
---|
| 72 | void postvisit( const ast::ZeroType * zeroType ); |
---|
| 73 | void postvisit( const ast::OneType * oneType ); |
---|
[fc134a48] | 74 | private: |
---|
| 75 | // refactor for code resue |
---|
| 76 | void conversionCostFromBasicToBasic( const ast::BasicType * src, const ast::BasicType* dest ); |
---|
[fb2bde4] | 77 | }; |
---|
| 78 | |
---|
[51b7345] | 79 | } // namespace ResolvExpr |
---|
| 80 | |
---|
[a32b204] | 81 | // Local Variables: // |
---|
| 82 | // tab-width: 4 // |
---|
| 83 | // mode: c++ // |
---|
| 84 | // compile-command: "make install" // |
---|
| 85 | // End: // |
---|