source: src/ResolvExpr/ConversionCost.h @ d066c5b

Last change on this file since d066c5b was 0522ebe, checked in by JiadaL <j82liang@…>, 10 months ago

Add EnumPosType? to type system

  • Property mode set to 100644
File size: 2.9 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// 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
25namespace ResolvExpr {
26
27// Some function pointer types, differ in return type.
28using CostCalculation = std::function<Cost(const ast::Type *, const ast::Type *, bool,
29        const ast::SymbolTable &, const ast::TypeEnvironment &)>;
30using PtrsCalculation = std::function<int(const ast::Type *, const ast::Type *,
31        const ast::SymbolTable &, const ast::TypeEnvironment &)>;
32
33Cost conversionCost(
34        const ast::Type * src, const ast::Type * dst, bool srcIsLvalue,
35        const ast::SymbolTable & symtab, const ast::TypeEnvironment & env );
36
37Cost convertToReferenceCost( const ast::Type * src, const ast::ReferenceType * dest,
38        bool srcIsLvalue, const ast::SymbolTable & indexer, const ast::TypeEnvironment & env,
39        PtrsCalculation func );
40
41class ConversionCost : public ast::WithShortCircuiting {
42protected:
43        const ast::Type * dst;
44        bool srcIsLvalue;
45        const ast::SymbolTable & symtab;
46        const ast::TypeEnvironment & env;
47        CostCalculation costCalc;
48public:
49        static size_t traceId;
50        Cost cost;
51        Cost result() { return cost; }
52
53        ConversionCost( const ast::Type * dst, bool srcIsLvalue, const ast::SymbolTable & symtab,
54                        const ast::TypeEnvironment & env, CostCalculation costCalc ) :
55                dst( dst ), srcIsLvalue( srcIsLvalue ), symtab( symtab ), env( env ),
56                costCalc( costCalc ), cost( Cost::infinity )
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 );
74        void postvisit( const ast::EnumPosType * posType );
75private:
76        // refactor for code resue
77        void conversionCostFromBasicToBasic( const ast::BasicType * src, const ast::BasicType* dest );
78};
79
80} // namespace ResolvExpr
81
82// Local Variables: //
83// tab-width: 4 //
84// mode: c++ //
85// compile-command: "make install" //
86// End: //
Note: See TracBrowser for help on using the repository browser.