Changeset 93d2219 for src


Ignore:
Timestamp:
Oct 28, 2022, 3:12:16 PM (18 months ago)
Author:
JiadaL <j82liang@…>
Branches:
ADT, ast-experimental, master
Children:
fa2e183
Parents:
e874605 (diff), 22a0e87 (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

Location:
src
Files:
1 added
13 edited

Legend:

Unmodified
Added
Removed
  • src/AST/Type.cpp

    re874605 r93d2219  
    147147// --- TypeInstType
    148148
     149bool 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
    149155TypeInstType::TypeInstType( const TypeDecl * b,
    150156        CV::Qualifiers q, std::vector<ptr<Attribute>> && as )
     
    157163
    158164bool TypeInstType::isComplete() const { return base->sized; }
     165
     166std::string TypeInstType::TypeEnvKey::typeString() const {
     167        return std::string("_") + std::to_string(formal_usage)
     168                + "_" + std::to_string(expr_id) + "_" + base->name;
     169}
     170
     171bool 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
     178bool 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}
    159194
    160195// --- TupleType
  • src/AST/Type.hpp

    re874605 r93d2219  
    408408
    409409                TypeEnvKey() = default;
    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; }
     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;
    414417        };
    415418
    416         bool operator==(const TypeInstType & other) const { return base == other.base && formal_usage == other.formal_usage && expr_id == other.expr_id; }
     419        bool operator==(const TypeInstType & other) const;
    417420
    418421        TypeInstType(
  • src/AST/module.mk

    re874605 r93d2219  
    6767        AST/Util.cpp \
    6868        AST/Util.hpp \
     69        AST/Vector.hpp \
    6970        AST/Visitor.hpp
    7071
  • src/GenPoly/GenPoly.cc

    re874605 r93d2219  
    1010// Created On       : Mon May 18 07:44:20 2015
    1111// Last Modified By : Andrew Beach
    12 // Last Modified On : Fri Oct  7 15:25:00 2022
    13 // Update Count     : 16
     12// Last Modified On : Mon Oct 24 15:19:00 2022
     13// Update Count     : 17
    1414//
    1515
     
    194194
    195195        if ( auto inst = dynamic_cast< const ast::TypeInstType * >( type ) ) {
    196                 if ( typeVars.find( inst->typeString() ) != typeVars.end() ) return type;
     196                if ( typeVars.find( *inst ) != 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->name );
     229                auto var = typeVars.find( *inst );
    230230                if ( var != typeVars.end() && var->second.isComplete ) {
    231231
     
    784784
    785785void addToTypeVarMap( const ast::TypeInstType * type, TypeVarMap & typeVars ) {
    786         typeVars.insert( type->typeString(), ast::TypeDecl::Data( type->base ) );
     786        typeVars.insert( *type, ast::TypeDecl::Data( type->base ) );
    787787}
    788788
     
    816816        }
    817817
    818 void 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 
    825818} // namespace GenPoly
    826819
  • src/GenPoly/GenPoly.h

    re874605 r93d2219  
    1010// Created On       : Mon May 18 07:44:20 2015
    1111// Last Modified By : Andrew Beach
    12 // Last Modified On : Fri Oct  7 15:06:00 2022
    13 // Update Count     : 9
     12// Last Modified On : Mon Oct 24 15:18:00 2022
     13// Update Count     : 11
    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
    2425#include "SymTab/Mangler.h"       // for Mangler
    2526#include "SynTree/Declaration.h"  // for TypeDecl::Data, AggregateDecl, Type...
     
    2829namespace GenPoly {
    2930
    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< std::string, ast::TypeDecl::Data >;
     32        using TypeVarMap = ErasableScopedMap< ast::TypeInstType::TypeEnvKey, 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 * );
    3637
    3738        /// returns polymorphic type if is polymorphic type, NULL otherwise; will look up substitution in env if provided
     
    5354        /// true iff function has dynamic-layout return type under the type variable map generated from its forall-parameters
    5455        ReferenceToType *isDynRet( FunctionType *function );
     56        const ast::BaseInstType *isDynRet( const ast::FunctionType * func );
    5557
    5658        /// A function needs an adapter if it returns a dynamic-layout value or if any of its parameters have dynamic-layout type
     
    112114        /// Prints type variable map
    113115        void printTyVarMap( std::ostream &os, const TyVarMap &tyVarMap );
    114         void printTypeVarMap( std::ostream &os, const TypeVarMap & typeVars );
    115116
    116117        /// Gets the mangled name of this type; alias for SymTab::Mangler::mangleType().
     
    128129        /// Gets the name of the layout function for a given aggregate type, given its declaration
    129130        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        }
    130134
    131135} // namespace GenPoly
  • src/GenPoly/InstantiateGenericNew.cpp

    re874605 r93d2219  
    2626#include "AST/Pass.hpp"                // for Pass, WithGuard, WithShortCi...
    2727#include "AST/TranslationUnit.hpp"     // for TranslationUnit
     28#include "AST/Vector.hpp"              // for vector
    2829#include "CodeGen/OperatorTable.h"     // for isAssignment
    2930#include "Common/ScopedMap.h"          // for ScopedMap
     
    3940// Utilities:
    4041
    41 using type_vector = std::vector< ast::ptr< ast::TypeExpr > >;
     42using type_vector = ast::vector< ast::TypeExpr >;
    4243
    4344/// Abstracts type equality for a list of parameter types.
    4445struct TypeList {
    4546        TypeList() : params() {}
    46         TypeList( std::vector< ast::ptr< ast::Type > > const & params ) :
     47        TypeList( ast::vector< ast::Type > const & params ) :
    4748                params( params ) {}
    48         TypeList( std::vector< ast::ptr< ast::Type > > && params ) :
     49        TypeList( ast::vector< ast::Type > && params ) :
    4950                params( std::move( params ) ) {}
    5051        TypeList( TypeList const & that ) : params( that.params ) {}
    5152        TypeList( TypeList && that ) : params( std::move( that.params ) ) {}
    5253
    53         TypeList( std::vector< ast::ptr< ast::TypeExpr > > const & exprs ) :
     54        TypeList( ast::vector< ast::TypeExpr > const & exprs ) :
    5455                        params() {
    5556                for ( auto expr : exprs ) {
     
    8283        }
    8384
    84         std::vector<ast::ptr<ast::Type>> params;
     85        ast::vector<ast::Type> params;
    8586};
    8687
     
    103104        /// returns null if no such value exists.
    104105        ast::AggregateDecl const * lookup(
    105                         ast::AggregateDecl const * key, type_vector const & params ) const {
     106                        ast::AggregateDecl const * key,
     107                        type_vector const & params ) const {
    106108                // This type repackaging is used for the helpers.
    107109                ast::ptr<ast::AggregateDecl> ptr = key;
     
    150152}
    151153
    152 bool isDtypeStatic( std::vector<ast::ptr<ast::TypeDecl>> const & baseParams ) {
     154bool isDtypeStatic( ast::vector<ast::TypeDecl> const & baseParams ) {
    153155        return std::all_of( baseParams.begin(), baseParams.end(),
    154156                []( ast::TypeDecl const * td ){ return !td->isComplete(); }
     
    161163/// least one parameter type, and dynamic if there is no concrete instantiation.
    162164GenericType makeSubstitutions(
    163                 std::vector<ast::ptr<ast::TypeExpr>> & out,
    164                 std::vector<ast::ptr<ast::TypeDecl>> const & baseParams,
    165                 std::vector<ast::ptr<ast::Expr>> const & params ) {
     165                ast::vector<ast::TypeExpr> & out,
     166                ast::vector<ast::TypeDecl> const & baseParams,
     167                ast::vector<ast::Expr> const & params ) {
    166168        GenericType gt = GenericType::dtypeStatic;
    167169
     
    214216/// Substitutes types of members according to baseParams => typeSubs,
    215217/// returning the result in a new vector.
    216 std::vector<ast::ptr<ast::Decl>> substituteMembers(
    217                 std::vector<ast::ptr<ast::Decl>> const & members,
    218                 std::vector<ast::ptr<ast::TypeDecl>> const & baseParams,
    219                 std::vector<ast::ptr<ast::TypeExpr>> const & typeSubs ) {
    220         std::vector<ast::ptr<ast::Decl>> out;
     218ast::vector<ast::Decl> substituteMembers(
     219                ast::vector<ast::Decl> const & members,
     220                ast::vector<ast::TypeDecl> const & baseParams,
     221                ast::vector<ast::TypeExpr> const & typeSubs ) {
     222        ast::vector<ast::Decl> out;
    221223        ast::TypeSubstitution subs( baseParams, typeSubs );
    222224        for ( ast::ptr<ast::Decl> const & member : members ) {
     
    235237/// modifying them in-place.
    236238void substituteMembersHere(
    237                 std::vector<ast::ptr<ast::Decl>> & members,
    238                 std::vector<ast::ptr<ast::TypeDecl>> const & baseParams,
    239                 std::vector<ast::ptr<ast::TypeExpr>> const & typeSubs ) {
     239                ast::vector<ast::Decl> & members,
     240                ast::vector<ast::TypeDecl> const & baseParams,
     241                ast::vector<ast::TypeExpr> const & typeSubs ) {
    240242        ast::TypeSubstitution subs( baseParams, typeSubs );
    241243        for ( ast::ptr<ast::Decl> & member : members ) {
     
    285287
    286288        ast::Expr const * fixMemberExpr(
    287                 std::vector<ast::ptr<ast::TypeDecl>> const & baseParams,
     289                ast::vector<ast::TypeDecl> const & baseParams,
    288290                ast::MemberExpr const * memberExpr );
    289291
     
    349351
    350352ast::Expr const * FixDtypeStatic::fixMemberExpr(
    351                 std::vector<ast::ptr<ast::TypeDecl>> const & baseParams,
     353                ast::vector<ast::TypeDecl> const & baseParams,
    352354                ast::MemberExpr const * memberExpr ) {
    353355        // Need to cast dtype-static member expressions to their actual type
     
    461463                type_vector const & typeSubs, ast::UnionDecl const * decl );
    462464
    463         void replaceParametersWithConcrete( std::vector<ast::ptr<ast::Expr>> & params );
     465        void replaceParametersWithConcrete( ast::vector<ast::Expr> & params );
    464466        ast::Type const * replaceWithConcrete( ast::Type const * type, bool doClone );
    465467
     
    470472        /// marks it as stripped.
    471473        void stripDtypeParams( ast::AggregateDecl * base,
    472                 std::vector<ast::ptr<ast::TypeDecl>> & baseParams,
    473                 std::vector<ast::ptr<ast::TypeExpr>> const & typeSubs );
     474                ast::vector<ast::TypeDecl> & baseParams,
     475                ast::vector<ast::TypeExpr> const & typeSubs );
    474476};
    475477
     
    511513        // and put substitutions in typeSubs.
    512514        assertf( inst->base, "Base data-type has parameters." );
    513         std::vector<ast::ptr<ast::TypeExpr>> typeSubs;
     515        ast::vector<ast::TypeExpr> typeSubs;
    514516        GenericType gt = makeSubstitutions( typeSubs, inst->base->params, inst->params );
    515517        switch ( gt ) {
     
    570572                ast::AggregateDecl const * aggr =
    571573                        expr->aggregate->result.strict_as<ast::BaseInstType>()->aggr();
    572                 std::vector<ast::ptr<ast::Decl>> const & members = aggr->members;
     574                ast::vector<ast::Decl> const & members = aggr->members;
    573575                auto it = std::find( members.begin(), members.end(), expr->member );
    574576                memberIndex = std::distance( members.begin(), it );
     
    643645
    644646void GenericInstantiator::replaceParametersWithConcrete(
    645                 std::vector<ast::ptr<ast::Expr>> & params ) {
     647                ast::vector<ast::Expr> & params ) {
    646648        for ( ast::ptr<ast::Expr> & param : params ) {
    647649                auto paramType = param.as<ast::TypeExpr>();
     
    673675void GenericInstantiator::stripDtypeParams(
    674676                ast::AggregateDecl * base,
    675                 std::vector<ast::ptr<ast::TypeDecl>> & baseParams,
    676                 std::vector<ast::ptr<ast::TypeExpr>> const & typeSubs ) {
     677                ast::vector<ast::TypeDecl> & baseParams,
     678                ast::vector<ast::TypeExpr> const & typeSubs ) {
    677679        substituteMembersHere( base->members, baseParams, typeSubs );
    678680
  • src/GenPoly/ScrubTyVars.cc

    re874605 r93d2219  
    2020#include "GenPoly/ErasableScopedMap.h"  // for ErasableScopedMap<>::const_it...
    2121#include "ScrubTyVars.h"
    22 #include "SymTab/Mangler.h"             // for mangle, typeMode
     22#include "SymTab/Mangler.h"             // for mangleType
    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->name );
     197        auto typeVar = typeVars->find( *type );
    198198        if ( typeVar == typeVars->end() ) {
    199199                return type;
     
    227227        if ( dynType ) {
    228228                return new ast::NameExpr( expr->location,
    229                         sizeofName( Mangle::mangle( dynType, Mangle::typeMode() ) ) );
     229                        sizeofName( Mangle::mangleType( dynType ) ) );
    230230        } else {
    231231                return expr;
     
    237237        if ( dynType ) {
    238238                return new ast::NameExpr( expr->location,
    239                         alignofName( Mangle::mangle( dynType, Mangle::typeMode() ) ) );
     239                        alignofName( Mangle::mangleType( dynType ) ) );
    240240        } else {
    241241                return expr;
  • src/Parser/ParseNode.h

    re874605 r93d2219  
    1010// Created On       : Sat May 16 13:28:16 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Tue Oct 18 14:15:37 2022
    13 // Update Count     : 936
     12// Last Modified On : Tue Oct 18 16:22:15 2022
     13// Update Count     : 937
    1414//
    1515
     
    468468                cur = dynamic_cast< const NodeType * >( temp ); // should not return nullptr
    469469                if ( ! cur && temp ) {                                                  // non-homogeneous nodes ?
    470                         SemanticError( cur->location, "internal error, non-homogeneous nodes founds in buildList processing." );
     470                        SemanticError( temp->location, "internal error, non-homogeneous nodes founds in buildList processing." );
    471471                } // if
    472472        } // while
  • src/ResolvExpr/SatisfyAssertions.cpp

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

    re874605 r93d2219  
    99// Author           : Richard C. Bilson
    1010// Created On       : Sun May 17 21:40:29 2015
    11 // Last Modified By : Peter A. Buhr
    12 // Last Modified On : Mon Jan 11 21:56:06 2021
    13 // Update Count     : 74
     11// Last Modified By : Andrew Beach
     12// Last Modified On : Fri Oct 21 16:18:00 2022
     13// Update Count     : 75
    1414//
    1515#include "Mangler.h"
     
    418418                        void postvisit( const ast::QualifiedType * qualType );
    419419
    420                         std::string get_mangleName() { return mangleName; }
     420                        /// The result is the current constructed mangled name.
     421                        std::string result() const { return mangleName; }
    421422                  private:
    422423                        std::string mangleName;         ///< Mangled name being constructed
     
    444445        } // namespace
    445446
    446 
    447447        std::string mangle( const ast::Node * decl, Mangle::Mode mode ) {
    448                 ast::Pass<Mangler_new> mangler( mode );
    449                 maybeAccept( decl, mangler );
    450                 return mangler.core.get_mangleName();
     448                return ast::Pass<Mangler_new>::read( decl, mode );
    451449        }
    452450
     
    689687                                        } // for
    690688                                        for ( auto & assert : ptype->assertions ) {
    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() );
     689                                                assertionNames.push_back( ast::Pass<Mangler_new>::read(
     690                                                        assert->var.get(),
     691                                                        mangleOverridable, typeMode, mangleGenericParams, nextVarNum, varNums ) );
    695692                                                acount++;
    696693                                        } // for
  • src/SymTab/Mangler.h

    re874605 r93d2219  
    99// Author           : Richard C. Bilson
    1010// Created On       : Sun May 17 21:44:03 2015
    11 // Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sat Jul 22 09:45:30 2017
    13 // Update Count     : 15
     11// Last Modified By : Andrew Beach
     12// Last Modified On : Thu Oct 27 11:58:00 2022
     13// Update Count     : 16
    1414//
    1515
     
    2222
    2323#include "AST/Bitfield.hpp"
    24 #include "AST/Fwd.hpp"
    2524#include "SynTree/SynTree.h"  // for Types
    2625#include "SynTree/Visitor.h"  // for Visitor, maybeAccept
     
    3332// * Currently name compression is not implemented.
    3433
     34namespace ast {
     35        class Node;
     36}
    3537namespace ResolvExpr {
    3638        class TypeEnvironment;
     
    101103        using Mode = bitfield<mangle_flags>;
    102104
    103         static inline Mode typeMode() { return NoOverrideable | Type; }
     105        /// Mangle declaration name.
     106        std::string mangle( const ast::Node * decl, Mode mode = {} );
    104107
    105         /// Mangle declaration name
    106         std::string mangle( const ast::Node * decl, Mode mode = {} );
     108        /// Most common mangle configuration for types.
     109        static inline std::string mangleType( const ast::Node * type ) {
     110                return mangle( type, { NoOverrideable | Type } );
     111        }
    107112
    108113        namespace Encoding {
  • src/SynTree/AddressExpr.cc

    re874605 r93d2219  
    5050                                set_result( addrType( refType->base ) );
    5151                        } else {
     52                                if(!arg->result->location.isSet()) arg->result->location = arg->location;
    5253                                SemanticError( arg->result, "Attempt to take address of non-lvalue expression: " );
    5354                        } // if
  • src/Virtual/ExpandCasts.cc

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