source: src/ResolvExpr/ConversionCost.h@ f5ec35a

Last change on this file since f5ec35a was c6b4432, checked in by Andrew Beach <ajbeach@…>, 23 months ago

Remove BaseSyntaxNode and clean-up.

  • Property mode set to 100644
File size: 3.0 KB
RevLine 
[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
[1d17939]12// Last Modified On : Wed Jul 29 16:12:00 2020
[cf32116]13// Update Count : 7
[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
[ea6332d]24
25namespace SymTab {
[0c6596f]26 class Indexer;
[ea6332d]27} // namespace SymTab
[51b73452]28
29namespace ResolvExpr {
[0c6596f]30 class TypeEnvironment;
[ea6332d]31
[fb2bde4]32// Some function pointer types, differ in return type.
[cf32116]33using CostCalculation = std::function<Cost(const ast::Type *, const ast::Type *, bool,
[fb2bde4]34 const ast::SymbolTable &, const ast::TypeEnvironment &)>;
[cf32116]35using PtrsCalculation = std::function<int(const ast::Type *, const ast::Type *,
[fb2bde4]36 const ast::SymbolTable &, const ast::TypeEnvironment &)>;
37
[fed6a0f]38Cost conversionCost(
39 const ast::Type * src, const ast::Type * dst, bool srcIsLvalue,
40 const ast::SymbolTable & symtab, const ast::TypeEnvironment & env );
41
42Cost convertToReferenceCost( const ast::Type * src, const ast::ReferenceType * dest,
43 bool srcIsLvalue, const ast::SymbolTable & indexer, const ast::TypeEnvironment & env,
44 PtrsCalculation func );
45
[3c89751]46#warning when the old ConversionCost is removed, get ride of the _new suffix.
[fb2bde4]47class ConversionCost_new : public ast::WithShortCircuiting {
[3c89751]48protected:
[fb2bde4]49 const ast::Type * dst;
[cf32116]50 bool srcIsLvalue;
[fb2bde4]51 const ast::SymbolTable & symtab;
52 const ast::TypeEnvironment & env;
53 CostCalculation costCalc;
54public:
[c15085d]55 static size_t traceId;
[fb2bde4]56 Cost cost;
[e6b42e7]57 Cost result() { return cost; }
[fb2bde4]58
[cf32116]59 ConversionCost_new( const ast::Type * dst, bool srcIsLvalue, const ast::SymbolTable & symtab,
[fb2bde4]60 const ast::TypeEnvironment & env, CostCalculation costCalc ) :
[cf32116]61 dst( dst ), srcIsLvalue( srcIsLvalue ), symtab( symtab ), env( env ),
62 costCalc( costCalc ), cost( Cost::infinity )
[fb2bde4]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 );
[fc134a48]80private:
81 // refactor for code resue
82 void conversionCostFromBasicToBasic( const ast::BasicType * src, const ast::BasicType* dest );
[fb2bde4]83};
84
[51b73452]85} // namespace ResolvExpr
86
[a32b204]87// Local Variables: //
88// tab-width: 4 //
89// mode: c++ //
90// compile-command: "make install" //
91// End: //
Note: See TracBrowser for help on using the repository browser.