Changeset 58fe85a for src/AST/Type.cpp


Ignore:
Timestamp:
Jan 7, 2021, 3:27:00 PM (5 years ago)
Author:
Thierry Delisle <tdelisle@…>
Branches:
ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast-unique-expr, pthread-emulation, qualifiedEnum
Children:
2b4daf2, 64aeca0
Parents:
3c64c668 (diff), eef8dfb (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' into park_unpark

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/AST/Type.cpp

    r3c64c668 r58fe85a  
    99// Author           : Aaron B. Moss
    1010// Created On       : Mon May 13 15:00:00 2019
    11 // Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sun Dec 15 16:56:28 2019
    13 // Update Count     : 4
     11// Last Modified By : Andrew Beach
     12// Last Modified On : Thu Jul 23 14:16:00 2020
     13// Update Count     : 5
    1414//
    1515
     
    2222#include "Decl.hpp"
    2323#include "Init.hpp"
     24#include "Common/utility.h"      // for copy, move
    2425#include "InitTweak/InitTweak.h" // for getPointerBase
    2526#include "Tuples/Tuples.h"       // for isTtype
     
    9192
    9293// --- FunctionType
    93 
    9494namespace {
    95         bool containsTtype( const std::vector<ptr<DeclWithType>> & l ) {
     95        bool containsTtype( const std::vector<ptr<Type>> & l ) {
    9696                if ( ! l.empty() ) {
    97                         return Tuples::isTtype( l.back()->get_type() );
     97                        return Tuples::isTtype( l.back() );
    9898                }
    9999                return false;
     
    105105}
    106106
    107 // --- ReferenceToType
    108 std::vector<readonly<Decl>> ReferenceToType::lookup( const std::string& name ) const {
     107std::vector<readonly<Decl>> BaseInstType::lookup( const std::string& name ) const {
    109108        assertf( aggr(), "Must have aggregate to perform lookup" );
    110109
     
    116115}
    117116
    118 // --- StructInstType
     117// --- SueInstType (StructInstType, UnionInstType, EnumInstType)
    119118
    120 StructInstType::StructInstType( const StructDecl * b, CV::Qualifiers q,
    121         std::vector<ptr<Attribute>>&& as )
    122 : ReferenceToType( b->name, q, std::move(as) ), base( b ) {}
     119template<typename decl_t>
     120SueInstType<decl_t>::SueInstType(
     121        const decl_t * b, CV::Qualifiers q, std::vector<ptr<Attribute>>&& as )
     122: BaseInstType( b->name, q, move(as) ), base( b ) {}
    123123
    124 bool StructInstType::isComplete() const { return base ? base->body : false; }
     124template<typename decl_t>
     125SueInstType<decl_t>::SueInstType(
     126        const base_type * b, std::vector<ptr<Expr>> && params,
     127        CV::Qualifiers q, std::vector<ptr<Attribute>> && as )
     128: BaseInstType( b->name, std::move(params), q, std::move(as) ), base( b ) {}
    125129
    126 // --- UnionInstType
     130template<typename decl_t>
     131bool SueInstType<decl_t>::isComplete() const {
     132        return base ? base->body : false;
     133}
    127134
    128 UnionInstType::UnionInstType( const UnionDecl * b, CV::Qualifiers q,
    129         std::vector<ptr<Attribute>>&& as )
    130 : ReferenceToType( b->name, q, std::move(as) ), base( b ) {}
    131 
    132 bool UnionInstType::isComplete() const { return base ? base->body : false; }
    133 
    134 // --- EnumInstType
    135 
    136 EnumInstType::EnumInstType( const EnumDecl * b, CV::Qualifiers q,
    137         std::vector<ptr<Attribute>>&& as )
    138 : ReferenceToType( b->name, q, std::move(as) ), base( b ) {}
    139 
    140 bool EnumInstType::isComplete() const { return base ? base->body : false; }
     135template class SueInstType<StructDecl>;
     136template class SueInstType<UnionDecl>;
     137template class SueInstType<EnumDecl>;
    141138
    142139// --- TraitInstType
    143140
    144 TraitInstType::TraitInstType( const TraitDecl * b, CV::Qualifiers q,
    145         std::vector<ptr<Attribute>>&& as )
    146 : ReferenceToType( b->name, q, std::move(as) ), base( b ) {}
    147 
    148 // --- TypeInstType
     141TraitInstType::TraitInstType(
     142        const TraitDecl * b, CV::Qualifiers q, std::vector<ptr<Attribute>>&& as )
     143: BaseInstType( b->name, q, move(as) ), base( b ) {}
    149144
    150145void TypeInstType::set_base( const TypeDecl * b ) {
     
    158153
    159154TupleType::TupleType( std::vector<ptr<Type>> && ts, CV::Qualifiers q )
    160 : Type( q ), types( std::move(ts) ), members() {
     155: Type( q ), types( move(ts) ), members() {
    161156        // This constructor is awkward. `TupleType` needs to contain objects so that members can be
    162157        // named, but members without initializer nodes end up getting constructors, which breaks
     
    173168        for ( const Type * ty : types ) {
    174169                members.emplace_back( new ObjectDecl{
    175                         CodeLocation{}, "", ty, new ListInit( CodeLocation{}, {}, {}, MaybeConstruct ),
     170                        CodeLocation{}, "", ty, new ListInit( CodeLocation{}, {}, {}, NoConstruct ),
    176171                        Storage::Classes{}, Linkage::Cforall } );
    177172        }
     173}
     174
     175bool isUnboundType(const Type * type) {
     176        if (auto typeInst = dynamic_cast<const TypeInstType *>(type)) {
     177                // xxx - look for a type name produced by renameTyVars.
     178
     179                // TODO: once TypeInstType representation is updated, it should properly check
     180                // if the context id is filled. this is a temporary hack for now
     181                return typeInst->formal_usage > 0;
     182        }
     183        return false;
    178184}
    179185
Note: See TracChangeset for help on using the changeset viewer.