Ignore:
Timestamp:
Apr 6, 2020, 4:46:28 PM (5 years ago)
Author:
Thierry Delisle <tdelisle@…>
Branches:
ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
Children:
e3bc51c
Parents:
71d6bd8 (diff), 057298e (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 new-ast

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/SynTree/TypeDecl.cc

    r71d6bd8 r7030dab  
    99// Author           : Richard C. Bilson
    1010// Created On       : Mon May 18 07:44:20 2015
    11 // Last Modified By : Andrew Beach
    12 // Last Modified On : Wed Aug  9 14:35:00 2017
    13 // Update Count     : 6
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Fri Dec 13 15:26:14 2019
     13// Update Count     : 21
    1414//
    1515
     
    2121#include "Type.h"            // for Type, Type::StorageClasses
    2222
    23 TypeDecl::TypeDecl( const std::string &name, Type::StorageClasses scs, Type *type, Kind kind, bool sized, Type * init ) : Parent( name, scs, type ), init( init ), sized( kind == Ttype || sized ), kind( kind ) {
     23TypeDecl::TypeDecl( const std::string & name, Type::StorageClasses scs, Type * type, Kind kind, bool sized, Type * init ) : Parent( name, scs, type ), kind( kind ), sized( kind == Ttype || sized ), init( init ) {
    2424}
    2525
    26 TypeDecl::TypeDecl( const TypeDecl &other ) : Parent( other ), init( maybeClone( other.init ) ), sized( other.sized ), kind( other.kind ) {
     26TypeDecl::TypeDecl( const TypeDecl & other ) : Parent( other ), kind( other.kind ), sized( other.sized ), init( maybeClone( other.init ) ) {
    2727}
    2828
    2929TypeDecl::~TypeDecl() {
    30   delete init;
     30        delete init;
    3131}
    3232
    33 std::string TypeDecl::typeString() const {
    34         static const std::string kindNames[] = { "object type", "function type", "tuple type" };
    35         assertf( sizeof(kindNames)/sizeof(kindNames[0]) == DeclarationNode::NoTypeClass-1, "typeString: kindNames is out of sync." );
    36         assertf( kind < sizeof(kindNames)/sizeof(kindNames[0]), "TypeDecl's kind is out of bounds." );
    37         return (isComplete() ? "sized " : "") + kindNames[ kind ];
     33const char * TypeDecl::typeString() const {
     34        static const char * kindNames[] = { "sized data type", "sized object type", "sized function type", "sized tuple type" };
     35        static_assert( sizeof(kindNames)/sizeof(kindNames[0]) == TypeDecl::NUMBER_OF_KINDS, "typeString: kindNames is out of sync." );
     36        assertf( kind < TypeDecl::NUMBER_OF_KINDS, "TypeDecl kind is out of bounds." );
     37        return isComplete() ? kindNames[ kind ] : &kindNames[ kind ][ sizeof("sized") ]; // sizeof includes '\0'
    3838}
    3939
    40 std::string TypeDecl::genTypeString() const {
    41         static const std::string kindNames[] = { "dtype", "ftype", "ttype" };
    42         assertf( sizeof(kindNames)/sizeof(kindNames[0]) == DeclarationNode::NoTypeClass-1, "genTypeString: kindNames is out of sync." );
    43         assertf( kind < sizeof(kindNames)/sizeof(kindNames[0]), "TypeDecl's kind is out of bounds." );
     40const char * TypeDecl::genTypeString() const {
     41        static const char * kindNames[] = { "dtype", "otype", "ftype", "ttype" };
     42        static_assert( sizeof(kindNames)/sizeof(kindNames[0]) == TypeDecl::NUMBER_OF_KINDS, "genTypeString: kindNames is out of sync." );
     43        assertf( kind < TypeDecl::NUMBER_OF_KINDS, "TypeDecl kind is out of bounds." );
    4444        return kindNames[ kind ];
    4545}
    4646
    4747void TypeDecl::print( std::ostream &os, Indenter indent ) const {
    48   NamedTypeDecl::print( os, indent );
    49   if ( init ) {
    50     os << std::endl << indent << "with type initializer: ";
    51     init->print( os, indent + 1 );
    52   }
     48        NamedTypeDecl::print( os, indent );
     49        if ( init ) {
     50                os << std::endl << indent << "with type initializer: ";
     51                init->print( os, indent + 1 );
     52        } // if
    5353}
    5454
    55 
    5655std::ostream & operator<<( std::ostream & os, const TypeDecl::Data & data ) {
    57   return os << data.kind << ", " << data.isComplete;
     56        return os << data.kind << ", " << data.isComplete;
    5857}
    5958
Note: See TracChangeset for help on using the changeset viewer.