Changeset 2ed94a9 for src/GenPoly/Box.cc


Ignore:
Timestamp:
Feb 8, 2023, 2:27:55 PM (3 years ago)
Author:
JiadaL <j82liang@…>
Branches:
ADT, master
Children:
b110bcc
Parents:
997185e (diff), ccb29b4 (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/GenPoly/Box.cc

    r997185e r2ed94a9  
    1414//
    1515
     16#include "Box.h"
     17
    1618#include <algorithm>                     // for mismatch
    1719#include <cassert>                       // for assert, strict_dynamic_cast
     
    2325#include <string>                        // for string, allocator, basic_string
    2426#include <utility>                       // for pair
    25 
    26 #include "Box.h"
    2727
    2828#include "CodeGen/OperatorTable.h"
     
    3737#include "InitTweak/InitTweak.h"         // for getFunctionName, isAssignment
    3838#include "Lvalue.h"                      // for generalizedLvalue
    39 #include "ResolvExpr/typeops.h"          // for typesCompatible
     39#include "ResolvExpr/Unify.h"            // for typesCompatible
    4040#include "ScopedSet.h"                   // for ScopedSet, ScopedSet<>::iter...
    4141#include "ScrubTyVars.h"                 // for ScrubTyVars
     
    488488                                for ( FunctionType const * const funType : functions ) {
    489489                                        std::string mangleName = mangleAdapterName( funType, scopeTyVars );
    490                                         if ( adapters.find( mangleName ) == adapters.end() ) {
     490                                        if ( !adapters.contains( mangleName ) ) {
    491491                                                std::string adapterName = makeAdapterName( mangleName );
    492492                                                adapters.insert( std::pair< std::string, DeclarationWithType *>( mangleName, new ObjectDecl( adapterName, Type::StorageClasses(), LinkageSpec::C, nullptr, new PointerType( Type::Qualifiers(), makeAdapterType( funType, scopeTyVars ) ), nullptr ) ) );
     
    911911
    912912                        for ( FunctionType const * const funType : functions ) {
    913                                 FunctionType *originalFunction = funType->clone();
    914                                 FunctionType *realFunction = funType->clone();
    915                                 std::string mangleName = SymTab::Mangler::mangle( realFunction );
     913                                std::string mangleName = SymTab::Mangler::mangle( funType );
    916914
    917915                                // only attempt to create an adapter or pass one as a parameter if we haven't already done so for this
    918916                                // pre-substitution parameter function type.
    919917                                // The second part of the insert result is "is the value new".
    920                                 if ( adaptersDone.insert( mangleName ).second ) {
    921 
    922                                         // apply substitution to type variables to figure out what the adapter's type should look like
    923                                         assert( env );
    924                                         env->apply( realFunction );
    925                                         mangleName = SymTab::Mangler::mangle( realFunction );
    926                                         mangleName += makePolyMonoSuffix( originalFunction, exprTyVars );
    927 
    928                                         typedef ScopedMap< std::string, DeclarationWithType* >::iterator AdapterIter;
    929                                         AdapterIter adapter = adapters.find( mangleName );
    930                                         if ( adapter == adapters.end() ) {
    931                                                 // adapter has not been created yet in the current scope, so define it
    932                                                 FunctionDecl *newAdapter = makeAdapter( funType, realFunction, mangleName, exprTyVars );
    933                                                 std::pair< AdapterIter, bool > answer = adapters.insert( std::pair< std::string, DeclarationWithType *>( mangleName, newAdapter ) );
    934                                                 adapter = answer.first;
    935                                                 stmtsToAddBefore.push_back( new DeclStmt( newAdapter ) );
    936                                         } // if
    937                                         assert( adapter != adapters.end() );
    938 
    939                                         // add the appropriate adapter as a parameter
    940                                         appExpr->get_args().push_front( new VariableExpr( adapter->second ) );
     918                                if ( !adaptersDone.insert( mangleName ).second ) continue;
     919
     920                                // Apply substitution to type variables to figure out what the adapter's type should look like.
     921                                assert( env );
     922                                FunctionType *realType = funType->clone();
     923                                env->apply( realType );
     924                                mangleName = SymTab::Mangler::mangle( realType );
     925                                mangleName += makePolyMonoSuffix( funType, exprTyVars );
     926
     927                                typedef ScopedMap< std::string, DeclarationWithType* >::iterator AdapterIter;
     928                                AdapterIter adapter = adapters.find( mangleName );
     929                                if ( adapter == adapters.end() ) {
     930                                        // Adapter has not been created yet in the current scope, so define it.
     931                                        FunctionDecl *newAdapter = makeAdapter( funType, realType, mangleName, exprTyVars );
     932                                        std::pair< AdapterIter, bool > answer = adapters.insert( mangleName, newAdapter );
     933                                        adapter = answer.first;
     934                                        stmtsToAddBefore.push_back( new DeclStmt( newAdapter ) );
    941935                                } // if
     936                                assert( adapter != adapters.end() );
     937
     938                                // Add the appropriate adapter as a parameter.
     939                                appExpr->args.push_front( new VariableExpr( adapter->second ) );
    942940                        } // for
    943941                } // passAdapters
     
    14891487                                        if ( TypeInstType *typeInst = dynamic_cast< TypeInstType* >( ty ) ) {
    14901488                                                // do not try to monomorphize generic parameters
    1491                                                 if ( scopeTyVars.find( typeInst->get_name() ) != scopeTyVars.end() && ! genericParams.count( typeInst->name ) ) {
     1489                                                if ( scopeTyVars.contains( typeInst->get_name() ) && ! genericParams.count( typeInst->name ) ) {
    14921490                                                        // polymorphic aggregate members should be converted into monomorphic members.
    14931491                                                        // Using char[size_T] here respects the expected sizing rules of an aggregate type.
     
    16981696
    16991697                        if ( auto typeInst = dynamic_cast< TypeInstType const * >( ty ) ) {
    1700                                 if ( scopeTyVars.find( typeInst->get_name() ) != scopeTyVars.end() ) {
     1698                                if ( scopeTyVars.contains( typeInst->get_name() ) ) {
    17011699                                        // NOTE assumes here that getting put in the scopeTyVars included having the layout variables set
    17021700                                        return true;
     
    17061704                                // check if this type already has a layout generated for it
    17071705                                std::string typeName = mangleType( ty );
    1708                                 if ( knownLayouts.find( typeName ) != knownLayouts.end() ) return true;
     1706                                if ( knownLayouts.contains( typeName ) ) return true;
    17091707
    17101708                                // check if any of the type parameters have dynamic layout; if none do, this type is (or will be) monomorphized
     
    17431741                                // check if this type already has a layout generated for it
    17441742                                std::string typeName = mangleType( ty );
    1745                                 if ( knownLayouts.find( typeName ) != knownLayouts.end() ) return true;
     1743                                if ( knownLayouts.contains( typeName ) ) return true;
    17461744
    17471745                                // check if any of the type parameters have dynamic layout; if none do, this type is (or will be) monomorphized
     
    18341832                        } else {
    18351833                                std::string offsetName = offsetofName( mangleType( ty ) );
    1836                                 if ( knownOffsets.find( offsetName ) != knownOffsets.end() ) {
     1834                                if ( knownOffsets.contains( offsetName ) ) {
    18371835                                        // use the already-generated offsets for this type
    18381836                                        ret = new NameExpr( offsetName );
Note: See TracChangeset for help on using the changeset viewer.