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