Changes in / [22a0e87:88ac843e]


Ignore:
Location:
src
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • src/AST/Type.cpp

    r22a0e87 r88ac843e  
    147147// --- TypeInstType
    148148
    149 bool TypeInstType::operator==( const TypeInstType & other ) const {
    150         return base == other.base
    151                 && formal_usage == other.formal_usage
    152                 && expr_id == other.expr_id;
    153 }
    154 
    155149TypeInstType::TypeInstType( const TypeDecl * b,
    156150        CV::Qualifiers q, std::vector<ptr<Attribute>> && as )
     
    163157
    164158bool TypeInstType::isComplete() const { return base->sized; }
    165 
    166 std::string TypeInstType::TypeEnvKey::typeString() const {
    167         return std::string("_") + std::to_string(formal_usage)
    168                 + "_" + std::to_string(expr_id) + "_" + base->name;
    169 }
    170 
    171 bool TypeInstType::TypeEnvKey::operator==(
    172                 const TypeInstType::TypeEnvKey & other ) const {
    173         return base == other.base
    174                 && formal_usage == other.formal_usage
    175                 && expr_id == other.expr_id;
    176 }
    177 
    178 bool TypeInstType::TypeEnvKey::operator<(
    179                 const TypeInstType::TypeEnvKey & other ) const {
    180         // TypeEnvKey ordering is an arbitrary total ordering.
    181         // It doesn't mean anything but allows for a sorting.
    182         if ( base < other.base ) {
    183                 return true;
    184         } else if ( other.base < base ) {
    185                 return false;
    186         } else if ( formal_usage < other.formal_usage ) {
    187                 return true;
    188         } else if ( other.formal_usage < formal_usage ) {
    189                 return false;
    190         } else {
    191                 return expr_id < other.expr_id;
    192         }
    193 }
    194159
    195160// --- TupleType
  • src/AST/Type.hpp

    r22a0e87 r88ac843e  
    408408
    409409                TypeEnvKey() = default;
    410                 TypeEnvKey(const TypeDecl * base, int formal_usage = 0, int expr_id = 0)
    411                 : base(base), formal_usage(formal_usage), expr_id(expr_id) {}
    412                 TypeEnvKey(const TypeInstType & inst)
    413                 : base(inst.base), formal_usage(inst.formal_usage), expr_id(inst.expr_id) {}
    414                 std::string typeString() const;
    415                 bool operator==(const TypeEnvKey & other) const;
    416                 bool operator<(const TypeEnvKey & other) const;
     410                TypeEnvKey(const TypeDecl * base, int formal_usage = 0, int expr_id = 0): base(base), formal_usage(formal_usage), expr_id(expr_id) {}
     411                TypeEnvKey(const TypeInstType & inst): base(inst.base), formal_usage(inst.formal_usage), expr_id(inst.expr_id) {}
     412                std::string typeString() const { return std::string("_") + std::to_string(formal_usage) + "_" + std::to_string(expr_id) + "_" + base->name; }
     413                bool operator==(const TypeEnvKey & other) const { return base == other.base && formal_usage == other.formal_usage && expr_id == other.expr_id; }
    417414        };
    418415
    419         bool operator==(const TypeInstType & other) const;
     416        bool operator==(const TypeInstType & other) const { return base == other.base && formal_usage == other.formal_usage && expr_id == other.expr_id; }
    420417
    421418        TypeInstType(
  • src/GenPoly/GenPoly.cc

    r22a0e87 r88ac843e  
    1010// Created On       : Mon May 18 07:44:20 2015
    1111// Last Modified By : Andrew Beach
    12 // Last Modified On : Mon Oct 24 15:19:00 2022
    13 // Update Count     : 17
     12// Last Modified On : Fri Oct  7 15:25:00 2022
     13// Update Count     : 16
    1414//
    1515
     
    194194
    195195        if ( auto inst = dynamic_cast< const ast::TypeInstType * >( type ) ) {
    196                 if ( typeVars.find( *inst ) != typeVars.end() ) return type;
     196                if ( typeVars.find( inst->typeString() ) != typeVars.end() ) return type;
    197197        } else if ( auto array = dynamic_cast< const ast::ArrayType * >( type ) ) {
    198198                return isPolyType( array->base, subst );
     
    227227
    228228        if ( auto inst = dynamic_cast<ast::TypeInstType const *>( type ) ) {
    229                 auto var = typeVars.find( *inst );
     229                auto var = typeVars.find( inst->name );
    230230                if ( var != typeVars.end() && var->second.isComplete ) {
    231231
     
    784784
    785785void addToTypeVarMap( const ast::TypeInstType * type, TypeVarMap & typeVars ) {
    786         typeVars.insert( *type, ast::TypeDecl::Data( type->base ) );
     786        typeVars.insert( type->typeString(), ast::TypeDecl::Data( type->base ) );
    787787}
    788788
     
    816816        }
    817817
     818void printTypeVarMap( std::ostream &os, const TypeVarMap & typeVars ) {
     819        for ( auto const & pair : typeVars ) {
     820                os << pair.first << " (" << pair.second << ") ";
     821        } // for
     822        os << std::endl;
     823}
     824
    818825} // namespace GenPoly
    819826
  • src/GenPoly/GenPoly.h

    r22a0e87 r88ac843e  
    1010// Created On       : Mon May 18 07:44:20 2015
    1111// Last Modified By : Andrew Beach
    12 // Last Modified On : Mon Oct 24 15:18:00 2022
    13 // Update Count     : 11
     12// Last Modified On : Fri Oct  7 15:06:00 2022
     13// Update Count     : 9
    1414//
    1515
     
    2222#include "AST/Decl.hpp"           // for TypeDecl::Data
    2323#include "AST/Fwd.hpp"            // for ApplicationExpr, BaseInstType, Func...
    24 #include "AST/Type.hpp"           // for TypeInstType::TypeEnvKey
    2524#include "SymTab/Mangler.h"       // for Mangler
    2625#include "SynTree/Declaration.h"  // for TypeDecl::Data, AggregateDecl, Type...
     
    2928namespace GenPoly {
    3029
     30        // TODO Via some tricks this works for ast::TypeDecl::Data as well.
    3131        typedef ErasableScopedMap< std::string, TypeDecl::Data > TyVarMap;
    32         using TypeVarMap = ErasableScopedMap< ast::TypeInstType::TypeEnvKey, ast::TypeDecl::Data >;
     32        using TypeVarMap = ErasableScopedMap< std::string, ast::TypeDecl::Data >;
    3333
    3434        /// Replaces a TypeInstType by its referrent in the environment, if applicable
    3535        Type* replaceTypeInst( Type* type, const TypeSubstitution* env );
    36         const ast::Type * replaceTypeInst( const ast::Type *, const ast::TypeSubstitution * );
    3736
    3837        /// returns polymorphic type if is polymorphic type, NULL otherwise; will look up substitution in env if provided
     
    5453        /// true iff function has dynamic-layout return type under the type variable map generated from its forall-parameters
    5554        ReferenceToType *isDynRet( FunctionType *function );
    56         const ast::BaseInstType *isDynRet( const ast::FunctionType * func );
    5755
    5856        /// A function needs an adapter if it returns a dynamic-layout value or if any of its parameters have dynamic-layout type
     
    114112        /// Prints type variable map
    115113        void printTyVarMap( std::ostream &os, const TyVarMap &tyVarMap );
     114        void printTypeVarMap( std::ostream &os, const TypeVarMap & typeVars );
    116115
    117116        /// Gets the mangled name of this type; alias for SymTab::Mangler::mangleType().
     
    129128        /// Gets the name of the layout function for a given aggregate type, given its declaration
    130129        inline std::string layoutofName( AggregateDecl *decl ) { return std::string( "_layoutof_" ) + decl->get_name(); }
    131         inline std::string layoutofName( ast::AggregateDecl const * decl ) {
    132                 return std::string( "_layoutof_" ) + decl->name;
    133         }
    134130
    135131} // namespace GenPoly
  • src/GenPoly/ScrubTyVars.cc

    r22a0e87 r88ac843e  
    2020#include "GenPoly/ErasableScopedMap.h"  // for ErasableScopedMap<>::const_it...
    2121#include "ScrubTyVars.h"
    22 #include "SymTab/Mangler.h"             // for mangleType
     22#include "SymTab/Mangler.h"             // for mangle, typeMode
    2323#include "SynTree/Declaration.h"        // for TypeDecl, TypeDecl::Data, Typ...
    2424#include "SynTree/Expression.h"         // for Expression (ptr only), NameExpr
     
    195195        }
    196196
    197         auto typeVar = typeVars->find( *type );
     197        auto typeVar = typeVars->find( type->name );
    198198        if ( typeVar == typeVars->end() ) {
    199199                return type;
     
    227227        if ( dynType ) {
    228228                return new ast::NameExpr( expr->location,
    229                         sizeofName( Mangle::mangleType( dynType ) ) );
     229                        sizeofName( Mangle::mangle( dynType, Mangle::typeMode() ) ) );
    230230        } else {
    231231                return expr;
     
    237237        if ( dynType ) {
    238238                return new ast::NameExpr( expr->location,
    239                         alignofName( Mangle::mangleType( dynType ) ) );
     239                        alignofName( Mangle::mangle( dynType, Mangle::typeMode() ) ) );
    240240        } else {
    241241                return expr;
  • src/ResolvExpr/SatisfyAssertions.cpp

    r22a0e87 r88ac843e  
    268268                ast::ptr< ast::Type > resType = cand.expr->result;
    269269                cand.env.apply( resType );
    270                 return Mangle::mangleType( resType );
     270                return Mangle::mangle( resType, Mangle::typeMode() );
    271271        }
    272272
  • src/SymTab/Mangler.cc

    r22a0e87 r88ac843e  
    99// Author           : Richard C. Bilson
    1010// Created On       : Sun May 17 21:40:29 2015
    11 // Last Modified By : Andrew Beach
    12 // Last Modified On : Fri Oct 21 16:18:00 2022
    13 // Update Count     : 75
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Mon Jan 11 21:56:06 2021
     13// Update Count     : 74
    1414//
    1515#include "Mangler.h"
     
    418418                        void postvisit( const ast::QualifiedType * qualType );
    419419
    420                         /// The result is the current constructed mangled name.
    421                         std::string result() const { return mangleName; }
     420                        std::string get_mangleName() { return mangleName; }
    422421                  private:
    423422                        std::string mangleName;         ///< Mangled name being constructed
     
    445444        } // namespace
    446445
     446
    447447        std::string mangle( const ast::Node * decl, Mangle::Mode mode ) {
    448                 return ast::Pass<Mangler_new>::read( decl, mode );
     448                ast::Pass<Mangler_new> mangler( mode );
     449                maybeAccept( decl, mangler );
     450                return mangler.core.get_mangleName();
    449451        }
    450452
     
    687689                                        } // for
    688690                                        for ( auto & assert : ptype->assertions ) {
    689                                                 assertionNames.push_back( ast::Pass<Mangler_new>::read(
    690                                                         assert->var.get(),
    691                                                         mangleOverridable, typeMode, mangleGenericParams, nextVarNum, varNums ) );
     691                                                ast::Pass<Mangler_new> sub_mangler(
     692                                                        mangleOverridable, typeMode, mangleGenericParams, nextVarNum, varNums );
     693                                                assert->var->accept( sub_mangler );
     694                                                assertionNames.push_back( sub_mangler.core.get_mangleName() );
    692695                                                acount++;
    693696                                        } // for
  • src/SymTab/Mangler.h

    r22a0e87 r88ac843e  
    99// Author           : Richard C. Bilson
    1010// Created On       : Sun May 17 21:44:03 2015
    11 // Last Modified By : Andrew Beach
    12 // Last Modified On : Thu Oct 27 11:58:00 2022
    13 // Update Count     : 16
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Sat Jul 22 09:45:30 2017
     13// Update Count     : 15
    1414//
    1515
     
    2222
    2323#include "AST/Bitfield.hpp"
     24#include "AST/Fwd.hpp"
    2425#include "SynTree/SynTree.h"  // for Types
    2526#include "SynTree/Visitor.h"  // for Visitor, maybeAccept
     
    3233// * Currently name compression is not implemented.
    3334
    34 namespace ast {
    35         class Node;
    36 }
    3735namespace ResolvExpr {
    3836        class TypeEnvironment;
     
    103101        using Mode = bitfield<mangle_flags>;
    104102
    105         /// Mangle declaration name.
     103        static inline Mode typeMode() { return NoOverrideable | Type; }
     104
     105        /// Mangle declaration name
    106106        std::string mangle( const ast::Node * decl, Mode mode = {} );
    107 
    108         /// Most common mangle configuration for types.
    109         static inline std::string mangleType( const ast::Node * type ) {
    110                 return mangle( type, { NoOverrideable | Type } );
    111         }
    112107
    113108        namespace Encoding {
  • src/Virtual/ExpandCasts.cc

    r22a0e87 r88ac843e  
    295295        // returns the previous declaration for error messages.
    296296        ast::ObjectDecl const * insert( ast::ObjectDecl const * typeIdDecl ) {
    297                 std::string mangledName = Mangle::mangleType( typeIdDecl->type );
     297                std::string const & mangledName =
     298                                Mangle::mangle( typeIdDecl->type, Mangle::typeMode() );
    298299                ast::ObjectDecl const *& value = instances[ mangledName ];
    299300                if ( value ) {
     
    309310
    310311        ast::ObjectDecl const * lookup( ast::Type const * typeIdType ) {
    311                 std::string mangledName = Mangle::mangleType( typeIdType );
     312                std::string const & mangledName =
     313                                Mangle::mangle( typeIdType, Mangle::typeMode() );
    312314                auto const it = instances.find( mangledName );
    313315                return ( instances.end() == it ) ? nullptr : it->second;
Note: See TracChangeset for help on using the changeset viewer.