Changeset d0d5054


Ignore:
Timestamp:
Apr 12, 2018, 5:13:04 PM (4 years ago)
Author:
Rob Schluntz <rschlunt@…>
Branches:
aaron-thesis, arm-eh, cleanup-dtors, deferred_resn, demangler, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, with_gc
Children:
01963df
Parents:
8711c6c
git-author:
Rob Schluntz <rschlunt@…> (04/12/18 17:07:59)
git-committer:
Rob Schluntz <rschlunt@…> (04/12/18 17:13:04)
Message:

Recursively substitute type variables when applying a substitution

Location:
src/SynTree
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • src/SynTree/TypeSubstitution.cc

    r8711c6c rd0d5054  
    149149                return inst;
    150150        } else {
    151 ///         std::cerr << "found " << inst->get_name() << ", replacing with ";
    152 ///         i->second->print( std::cerr );
    153 ///         std::cerr << std::endl;
     151                // cut off infinite loop for the case where a type is bound to itself.
     152                // Note: this does not prevent cycles in the general case, so it may be necessary to do something more sophisticated here.
     153                // TODO: investigate preventing type variables from being bound to themselves in the first place.
     154                if ( TypeInstType * replacement = dynamic_cast< TypeInstType * >( i->second ) ) {
     155                        if ( inst->name == replacement->name ) {
     156                                return inst;
     157                        }
     158                }
     159                // std::cerr << "found " << inst->name << ", replacing with " << i->second << std::endl;
    154160                subCount++;
    155161                Type * newtype = i->second->clone();
    156162                newtype->get_qualifiers() |= inst->get_qualifiers();
    157163                delete inst;
    158                 return newtype;
     164                // Note: need to recursively apply substitution to the new type because normalize does not substitute bound vars, but bound vars must be substituted when not in freeOnly mode.
     165                return newtype->acceptMutator( *visitor );
    159166        } // if
    160167}
  • src/SynTree/TypeSubstitution.h

    r8711c6c rd0d5054  
    129129
    130130// definitition must happen after PassVisitor is included so that WithGuards can be used
    131 struct TypeSubstitution::Substituter : public WithGuards {
     131struct TypeSubstitution::Substituter : public WithGuards, public WithVisitorRef<Substituter> {
    132132                Substituter( TypeSubstitution & sub, bool freeOnly ) : sub( sub ), freeOnly( freeOnly ) {}
    133133
Note: See TracChangeset for help on using the changeset viewer.