Ignore:
Timestamp:
Feb 23, 2024, 6:52:33 PM (4 months ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
master
Children:
3d5a8cb
Parents:
624ba3a5
Message:

first attempt at correct distribution of attributes for aggregates

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Parser/TypeData.cc

    r624ba3a5 r4eb3a7c5  
    1010// Created On       : Sat May 16 15:12:51 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Thu Dec 14 18:59:12 2023
    13 // Update Count     : 684
     12// Last Modified On : Fri Feb 23 08:58:30 2024
     13// Update Count     : 734
    1414//
    1515
     
    2020
    2121#include "AST/Decl.hpp"            // for AggregateDecl, ObjectDecl, TypeDe...
     22#include "AST/Attribute.hpp"       // for Attribute
    2223#include "AST/Init.hpp"            // for SingleInit, ListInit
    2324#include "AST/Print.hpp"           // for print
    2425#include "Common/SemanticError.h"  // for SemanticError
    2526#include "Common/utility.h"        // for splice, spliceBegin
     27#include "Common/Iterate.hpp"      // for reverseIterate
    2628#include "Parser/ExpressionNode.h" // for ExpressionNode
    2729#include "Parser/StatementNode.h"  // for StatementNode
     
    199201                newtype->aggregate.kind = aggregate.kind;
    200202                newtype->aggregate.name = aggregate.name ? new string( *aggregate.name ) : nullptr;
     203                newtype->aggregate.parent = aggregate.parent ? new string( *aggregate.parent ) : nullptr;
    201204                newtype->aggregate.params = maybeCopy( aggregate.params );
    202205                newtype->aggregate.actuals = maybeCopy( aggregate.actuals );
    203206                newtype->aggregate.fields = maybeCopy( aggregate.fields );
     207                newtype->aggregate.attributes = aggregate.attributes;
    204208                newtype->aggregate.body = aggregate.body;
    205209                newtype->aggregate.anon = aggregate.anon;
    206210                newtype->aggregate.tagged = aggregate.tagged;
    207                 newtype->aggregate.parent = aggregate.parent ? new string( *aggregate.parent ) : nullptr;
    208211                break;
    209212        case AggregateInst:
     
    336339                } // if
    337340                if ( aggregate.body ) {
    338                         os << string( indent + 2, ' ' ) << " with body" << endl;
     341                        os << string( indent + 2, ' ' ) << "with body" << endl;
     342                } // if
     343                if ( ! aggregate.attributes.empty() ) {
     344                        os << string( indent + 2, ' ' ) << "with attributes" << endl;
     345                        for ( ast::ptr<ast::Attribute> const & attr : reverseIterate( aggregate.attributes ) ) {
     346                                os << string( indent + 4, ' ' );
     347                                ast::print( os, attr, indent + 2 );
     348                        } // for
    339349                } // if
    340350                break;
     
    358368                } // if
    359369                if ( enumeration.body ) {
    360                         os << string( indent + 2, ' ' ) << " with body" << endl;
     370                        os << string( indent + 2, ' ' ) << "with body" << endl;
    361371                } // if
    362372                if ( base ) {
     
    10881098
    10891099ast::BaseInstType * buildComAggInst(
    1090                 const TypeData * type,
     1100                const TypeData * td,
    10911101                std::vector<ast::ptr<ast::Attribute>> && attributes,
    10921102                ast::Linkage::Spec linkage ) {
    1093         switch ( type->kind ) {
     1103        switch ( td->kind ) {
    10941104        case TypeData::Enum:
    1095                 if ( type->enumeration.body ) {
     1105                if ( td->enumeration.body ) {
    10961106                        ast::EnumDecl * typedecl =
    1097                                 buildEnum( type, std::move( attributes ), linkage );
     1107                                buildEnum( td, std::move( attributes ), linkage );
    10981108                        return new ast::EnumInstType(
    10991109                                typedecl,
    1100                                 buildQualifiers( type )
     1110                                buildQualifiers( td )
    11011111                        );
    11021112                } else {
    11031113                        return new ast::EnumInstType(
    1104                                 *type->enumeration.name,
    1105                                 buildQualifiers( type )
     1114                                *td->enumeration.name,
     1115                                buildQualifiers( td )
    11061116                        );
    11071117                } // if
    11081118                break;
    11091119        case TypeData::Aggregate:
    1110                 if ( type->aggregate.body ) {
     1120                if ( td->aggregate.body ) {
    11111121                        ast::AggregateDecl * typedecl =
    1112                                 buildAggregate( type, std::move( attributes ), linkage );
    1113                         switch ( type->aggregate.kind ) {
     1122                                buildAggregate( td, std::move( attributes ), linkage );
     1123                        switch ( td->aggregate.kind ) {
    11141124                        case ast::AggregateDecl::Struct:
    11151125                        case ast::AggregateDecl::Coroutine:
     
    11181128                                return new ast::StructInstType(
    11191129                                        strict_dynamic_cast<ast::StructDecl *>( typedecl ),
    1120                                         buildQualifiers( type )
     1130                                        buildQualifiers( td )
    11211131                                );
    11221132                        case ast::AggregateDecl::Union:
    11231133                                return new ast::UnionInstType(
    11241134                                        strict_dynamic_cast<ast::UnionDecl *>( typedecl ),
    1125                                         buildQualifiers( type )
     1135                                        buildQualifiers( td )
    11261136                                );
    11271137                        case ast::AggregateDecl::Trait:
     
    11321142                        } // switch
    11331143                } else {
    1134                         switch ( type->aggregate.kind ) {
     1144                        switch ( td->aggregate.kind ) {
    11351145                        case ast::AggregateDecl::Struct:
    11361146                        case ast::AggregateDecl::Coroutine:
     
    11381148                        case ast::AggregateDecl::Thread:
    11391149                                return new ast::StructInstType(
    1140                                         *type->aggregate.name,
    1141                                         buildQualifiers( type )
     1150                                        *td->aggregate.name,
     1151                                        buildQualifiers( td )
    11421152                                );
    11431153                        case ast::AggregateDecl::Union:
    11441154                                return new ast::UnionInstType(
    1145                                         *type->aggregate.name,
    1146                                         buildQualifiers( type )
     1155                                        *td->aggregate.name,
     1156                                        buildQualifiers( td )
    11471157                                );
    11481158                        case ast::AggregateDecl::Trait:
    11491159                                return new ast::TraitInstType(
    1150                                         *type->aggregate.name,
    1151                                         buildQualifiers( type )
     1160                                        *td->aggregate.name,
     1161                                        buildQualifiers( td )
    11521162                                );
    11531163                        default:
Note: See TracChangeset for help on using the changeset viewer.