Ignore:
Timestamp:
Oct 29, 2019, 4:01:24 PM (6 years ago)
Author:
Thierry Delisle <tdelisle@…>
Branches:
ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
Children:
773db65, 9421f3d8
Parents:
7951100 (diff), 8364209 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'master' of plg.uwaterloo.ca:software/cfa/cfa-cc

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/ResolvExpr/typeops.h

    r7951100 rb067d9b  
    99// Author           : Richard C. Bilson
    1010// Created On       : Sun May 17 07:28:22 2015
    11 // Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sat Jul 22 09:36:18 2017
    13 // Update Count     : 3
     11// Last Modified By : Andrew Beach
     12// Last Modified On : Thu Aug  8 16:36:00 2019
     13// Update Count     : 5
    1414//
    1515
     
    1818#include <vector>
    1919
     20#include "Cost.h"
     21#include "TypeEnvironment.h"
     22#include "WidenMode.h"
     23#include "AST/Fwd.hpp"
     24#include "AST/Node.hpp"
     25#include "AST/SymbolTable.hpp"
     26#include "AST/Type.hpp"
     27#include "AST/TypeEnvironment.hpp"
    2028#include "SynTree/SynTree.h"
    2129#include "SynTree/Type.h"
    22 #include "SymTab/Indexer.h"
    23 #include "Cost.h"
    24 #include "TypeEnvironment.h"
     30
     31namespace SymTab {
     32        class Indexer;
     33}
    2534
    2635namespace ResolvExpr {
     
    5463        // in AdjustExprType.cc
    5564        /// Replaces array types with the equivalent pointer, and function types with a pointer-to-function
    56         void adjustExprType( Type *&type, const TypeEnvironment &env, const SymTab::Indexer &indexer );
     65        void adjustExprType( Type *& type, const TypeEnvironment & env, const SymTab::Indexer & indexer );
    5766
    5867        /// Replaces array types with the equivalent pointer, and function types with a pointer-to-function using empty TypeEnvironment and Indexer
     
    6069
    6170        template< typename ForwardIterator >
    62         void adjustExprTypeList( ForwardIterator begin, ForwardIterator end, const TypeEnvironment &env, const SymTab::Indexer &indexer ) {
     71        void adjustExprTypeList( ForwardIterator begin, ForwardIterator end, const TypeEnvironment & env, const SymTab::Indexer & indexer ) {
    6372                while ( begin != end ) {
    6473                        adjustExprType( *begin++, env, indexer );
     
    6675        }
    6776
     77        /// Replaces array types with equivalent pointer, and function types with a pointer-to-function
     78        const ast::Type * adjustExprType(
     79                const ast::Type * type, const ast::TypeEnvironment & env, const ast::SymbolTable & symtab );
     80
    6881        // in CastCost.cc
    69         Cost castCost( Type *src, Type *dest, const SymTab::Indexer &indexer, const TypeEnvironment &env );
     82        Cost castCost( const Type * src, const Type * dest, bool srcIsLvalue,
     83                const SymTab::Indexer & indexer, const TypeEnvironment & env );
     84        Cost castCost(
     85                const ast::Type * src, const ast::Type * dst, const ast::SymbolTable & symtab,
     86                const ast::TypeEnvironment & env );
    7087
    7188        // in ConversionCost.cc
    72         Cost conversionCost( Type *src, Type *dest, const SymTab::Indexer &indexer, const TypeEnvironment &env );
     89        Cost conversionCost( const Type * src, const Type * dest, bool srcIsLvalue,
     90                const SymTab::Indexer & indexer, const TypeEnvironment & env );
     91        Cost conversionCost(
     92                const ast::Type * src, const ast::Type * dst, const ast::SymbolTable & symtab,
     93                const ast::TypeEnvironment & env );
     94
     95        // in AlternativeFinder.cc
     96        Cost computeConversionCost( Type * actualType, Type * formalType, bool actualIsLvalue,
     97                const SymTab::Indexer & indexer, const TypeEnvironment & env );
    7398
    7499        // in PtrsAssignable.cc
    75         int ptrsAssignable( Type *src, Type *dest, const TypeEnvironment &env );
     100        int ptrsAssignable( const Type * src, const Type * dest, const TypeEnvironment & env );
     101        int ptrsAssignable( const ast::Type * src, const ast::Type * dst,
     102                const ast::TypeEnvironment & env );
    76103
    77104        // in PtrsCastable.cc
    78         int ptrsCastable( Type *src, Type *dest, const TypeEnvironment &env, const SymTab::Indexer &indexer );
     105        int ptrsCastable( const Type * src, const Type * dest, const TypeEnvironment & env, const SymTab::Indexer & indexer );
     106        int ptrsCastable(
     107                const ast::Type * src, const ast::Type * dst, const ast::SymbolTable & symtab,
     108                const ast::TypeEnvironment & env );
    79109
    80110        // in Unify.cc
    81         bool isFtype( Type *type );
    82         bool typesCompatible( Type *, Type *, const SymTab::Indexer &indexer, const TypeEnvironment &env );
    83         bool typesCompatibleIgnoreQualifiers( Type *, Type *, const SymTab::Indexer &indexer, const TypeEnvironment &env );
    84 
    85         inline bool typesCompatible( Type *t1, Type *t2, const SymTab::Indexer &indexer ) {
     111        bool typesCompatible( const Type *, const Type *, const SymTab::Indexer & indexer, const TypeEnvironment & env );
     112        bool typesCompatibleIgnoreQualifiers( const Type *, const Type *, const SymTab::Indexer & indexer, const TypeEnvironment & env );
     113
     114        inline bool typesCompatible( const Type * t1, const Type * t2, const SymTab::Indexer & indexer ) {
    86115                TypeEnvironment env;
    87116                return typesCompatible( t1, t2, indexer, env );
    88117        }
    89118
    90         inline bool typesCompatibleIgnoreQualifiers( Type *t1, Type *t2, const SymTab::Indexer &indexer ) {
     119        inline bool typesCompatibleIgnoreQualifiers( const Type * t1, const Type * t2, const SymTab::Indexer & indexer ) {
    91120                TypeEnvironment env;
    92121                return typesCompatibleIgnoreQualifiers( t1, t2, indexer, env );
    93122        }
    94123
     124        bool typesCompatible(
     125                const ast::Type *, const ast::Type *, const ast::SymbolTable & symtab = {},
     126                const ast::TypeEnvironment & env = {} );
     127
     128        bool typesCompatibleIgnoreQualifiers(
     129                const ast::Type *, const ast::Type *, const ast::SymbolTable &,
     130                const ast::TypeEnvironment & env = {} );
     131
    95132        /// creates the type represented by the list of returnVals in a FunctionType. The caller owns the return value.
    96133        Type * extractResultType( FunctionType * functionType );
     134        /// Creates or extracts the type represented by the list of returns in a `FunctionType`.
     135        ast::ptr<ast::Type> extractResultType( const ast::FunctionType * func );
    97136
    98137        // in CommonType.cc
    99         Type *commonType( Type *type1, Type *type2, bool widenFirst, bool widenSecond, const SymTab::Indexer &indexer, TypeEnvironment &env, const OpenVarSet &openVars );
     138        Type * commonType( Type * type1, Type * type2, bool widenFirst, bool widenSecond, const SymTab::Indexer & indexer, TypeEnvironment & env, const OpenVarSet & openVars );
     139        ast::ptr< ast::Type > commonType(
     140                const ast::ptr< ast::Type > & type1, const ast::ptr< ast::Type > & type2, WidenMode widen,
     141                const ast::SymbolTable & symtab, ast::TypeEnvironment & env, const ast::OpenVarSet & open );
    100142
    101143        // in PolyCost.cc
    102         int polyCost( Type *type, const TypeEnvironment &env, const SymTab::Indexer &indexer );
     144        int polyCost( Type * type, const TypeEnvironment & env, const SymTab::Indexer & indexer );
     145        int polyCost(
     146                const ast::Type * type, const ast::SymbolTable & symtab, const ast::TypeEnvironment & env );
     147
     148        // in SpecCost.cc
     149        int specCost( Type * type );
     150        int specCost( const ast::Type * type );
    103151
    104152        // in Occurs.cc
    105         bool occurs( Type *type, std::string varName, const TypeEnvironment &env );
     153        bool occurs( const Type * type, const std::string & varName, const TypeEnvironment & env );
     154        // new AST version in TypeEnvironment.cpp (only place it was used in old AST)
     155
     156        template<typename Iter>
     157        bool occursIn( Type* ty, Iter begin, Iter end, const TypeEnvironment & env ) {
     158                while ( begin != end ) {
     159                        if ( occurs( ty, *begin, env ) ) return true;
     160                        ++begin;
     161                }
     162                return false;
     163        }
    106164
    107165        // in AlternativeFinder.cc
    108166        void referenceToRvalueConversion( Expression *& expr, Cost & cost );
    109 
    110         // flatten tuple type into list of types
     167        // in CandidateFinder.cpp
     168        const ast::Expr * referenceToRvalueConversion( const ast::Expr * expr, Cost & cost );
     169
     170        /// flatten tuple type into list of types
    111171        template< typename OutputIterator >
    112172        void flatten( Type * type, OutputIterator out ) {
     
    119179                }
    120180        }
     181
     182        /// flatten tuple type into existing list of types
     183        static inline void flatten(
     184                const ast::Type * type, std::vector< ast::ptr< ast::Type > > & out
     185        ) {
     186                if ( auto tupleType = dynamic_cast< const ast::TupleType * >( type ) ) {
     187                        for ( const ast::Type * t : tupleType->types ) {
     188                                flatten( t, out );
     189                        }
     190                } else {
     191                        out.emplace_back( type );
     192                }
     193        }
     194
     195        /// flatten tuple type into list of types
     196        static inline std::vector< ast::ptr< ast::Type > > flatten( const ast::Type * type ) {
     197                std::vector< ast::ptr< ast::Type > > out;
     198                out.reserve( type->size() );
     199                flatten( type, out );
     200                return out;
     201        }
     202
     203        // in TypeEnvironment.cc
     204        bool isFtype( const Type * type );
    121205} // namespace ResolvExpr
     206
     207namespace ast {
     208        // in TypeEnvironment.cpp
     209        bool isFtype( const ast::Type * type );
     210} // namespace ast
    122211
    123212// Local Variables: //
Note: See TracChangeset for help on using the changeset viewer.