Changeset e0e9a0b for src/AST/Type.cpp


Ignore:
Timestamp:
Jun 27, 2019, 5:16:54 PM (5 years ago)
Author:
Aaron Moss <a3moss@…>
Branches:
ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
Children:
7d0881c
Parents:
6be3b7d6
Message:

Somewhat deeper clone for types with forall qualifiers.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/AST/Type.cpp

    r6be3b7d6 re0e9a0b  
    2121
    2222#include "Decl.hpp"
     23#include "ForallSubstitutor.hpp" // for substituteForall
    2324#include "Init.hpp"
     25#include "Common/utility.h"      // for copy, move
    2426#include "InitTweak/InitTweak.h" // for getPointerBase
    2527#include "Tuples/Tuples.h"       // for isTtype
     
    9193);
    9294
     95// --- ParameterizedType
     96
     97void ParameterizedType::initWithSub(
     98        const ParameterizedType & o, Pass< ForallSubstitutor > & sub
     99) {
     100        forall = sub.pass( o.forall );
     101}
     102
    93103// --- FunctionType
     104
     105FunctionType::FunctionType( const FunctionType & o )
     106: ParameterizedType( o.qualifiers, copy( o.attributes ) ), returns(), params(),
     107  isVarArgs( o.isVarArgs ) {
     108        Pass< ForallSubstitutor > sub;
     109        initWithSub( o, sub );           // initialize substitution map
     110        returns = sub.pass( o.returns ); // apply to return and parameter types
     111        params = sub.pass( o.params );
     112}
    94113
    95114namespace {
     
    107126
    108127// --- ReferenceToType
     128
     129void ReferenceToType::initWithSub( const ReferenceToType & o, Pass< ForallSubstitutor > & sub ) {
     130        ParameterizedType::initWithSub( o, sub ); // initialize substitution
     131        params = sub.pass( o.params );            // apply to parameters
     132}
     133
     134ReferenceToType::ReferenceToType( const ReferenceToType & o )
     135: ParameterizedType( o.qualifiers, copy( o.attributes ) ), params(), name( o.name ),
     136  hoistType( o.hoistType ) {
     137        Pass< ForallSubstitutor > sub;
     138        initWithSub( o, sub );
     139}
     140
    109141std::vector<readonly<Decl>> ReferenceToType::lookup( const std::string& name ) const {
    110142        assertf( aggr(), "Must have aggregate to perform lookup" );
     
    119151// --- StructInstType
    120152
    121 StructInstType::StructInstType( const StructDecl * b, CV::Qualifiers q,
    122         std::vector<ptr<Attribute>>&& as )
    123 : ReferenceToType( b->name, q, std::move(as) ), base( b ) {}
     153StructInstType::StructInstType(
     154        const StructDecl * b, CV::Qualifiers q, std::vector<ptr<Attribute>>&& as )
     155: ReferenceToType( b->name, q, move(as) ), base( b ) {}
    124156
    125157bool StructInstType::isComplete() const { return base ? base->body : false; }
     
    127159// --- UnionInstType
    128160
    129 UnionInstType::UnionInstType( const UnionDecl * b, CV::Qualifiers q,
    130         std::vector<ptr<Attribute>>&& as )
    131 : ReferenceToType( b->name, q, std::move(as) ), base( b ) {}
     161UnionInstType::UnionInstType(
     162        const UnionDecl * b, CV::Qualifiers q, std::vector<ptr<Attribute>>&& as )
     163: ReferenceToType( b->name, q, move(as) ), base( b ) {}
    132164
    133165bool UnionInstType::isComplete() const { return base ? base->body : false; }
     
    135167// --- EnumInstType
    136168
    137 EnumInstType::EnumInstType( const EnumDecl * b, CV::Qualifiers q,
    138         std::vector<ptr<Attribute>>&& as )
    139 : ReferenceToType( b->name, q, std::move(as) ), base( b ) {}
     169EnumInstType::EnumInstType(
     170        const EnumDecl * b, CV::Qualifiers q, std::vector<ptr<Attribute>>&& as )
     171: ReferenceToType( b->name, q, move(as) ), base( b ) {}
    140172
    141173bool EnumInstType::isComplete() const { return base ? base->body : false; }
     
    143175// --- TraitInstType
    144176
    145 TraitInstType::TraitInstType( const TraitDecl * b, CV::Qualifiers q,
    146         std::vector<ptr<Attribute>>&& as )
    147 : ReferenceToType( b->name, q, std::move(as) ), base( b ) {}
     177TraitInstType::TraitInstType(
     178        const TraitDecl * b, CV::Qualifiers q, std::vector<ptr<Attribute>>&& as )
     179: ReferenceToType( b->name, q, move(as) ), base( b ) {}
    148180
    149181// --- TypeInstType
     182
     183TypeInstType::TypeInstType( const TypeInstType & o )
     184: ReferenceToType( o.name, o.qualifiers, copy( o.attributes ) ), base(), kind( o.kind ) {
     185        Pass< ForallSubstitutor > sub;
     186        initWithSub( o, sub );      // initialize substitution
     187        base = sub.pass( o.base );  // apply to base type
     188}
    150189
    151190void TypeInstType::set_base( const TypeDecl * b ) {
     
    159198
    160199TupleType::TupleType( std::vector<ptr<Type>> && ts, CV::Qualifiers q )
    161 : Type( q ), types( std::move(ts) ), members() {
     200: Type( q ), types( move(ts) ), members() {
    162201        // This constructor is awkward. `TupleType` needs to contain objects so that members can be
    163202        // named, but members without initializer nodes end up getting constructors, which breaks
Note: See TracChangeset for help on using the changeset viewer.