Changeset 312029a


Ignore:
Timestamp:
Dec 11, 2019, 8:52:38 PM (5 years ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
Children:
737c98a
Parents:
98d6965d
Message:

move enum Aggregate from DeclarationNode? to AggregateDecl?, add control-keyword field-dereference to replace control-keyword cast

Files:
23 edited

Legend:

Unmodified
Added
Removed
  • src/AST/Convert.cpp

    r98d6965d r312029a  
    1010// Created On       : Thu May 09 15::37::05 2019
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Thu Jul 25 22:21:46 2019
    13 // Update Count     : 13
     12// Last Modified On : Tue Dec 10 22:20:10 2019
     13// Update Count     : 32
    1414//
    1515
     
    245245                auto decl = new StructDecl(
    246246                        node->name,
    247                         node->kind,
     247                        (AggregateDecl::Aggregate)node->kind,
    248248                        get<Attribute>().acceptL( node->attributes ),
    249249                        LinkageSpec::Spec( node->linkage.val )
     
    675675
    676676        const ast::Expr * visit( const ast::KeywordCastExpr * node ) override final {
    677                 KeywordCastExpr::Target castTarget = KeywordCastExpr::NUMBER_OF_TARGETS;
    678                 switch (node->target) {
    679                         case ast::KeywordCastExpr::Coroutine:
    680                                 castTarget = KeywordCastExpr::Coroutine;
    681                                 break;
    682                         case ast::KeywordCastExpr::Thread:
    683                                 castTarget = KeywordCastExpr::Thread;
    684                                 break;
    685                         case ast::KeywordCastExpr::Monitor:
    686                                 castTarget = KeywordCastExpr::Monitor;
    687                                 break;
    688                         default:
    689                                 break;
    690                 }
    691                 assert ( castTarget < KeywordCastExpr::NUMBER_OF_TARGETS );
     677                AggregateDecl::Aggregate castTarget = (AggregateDecl::Aggregate)node->target;
     678                assert( AggregateDecl::Generator <= castTarget && castTarget <= AggregateDecl::Thread );
    692679                auto expr = visitBaseExpr( node,
    693680                        new KeywordCastExpr(
     
    15041491                        old->location,
    15051492                        old->name,
    1506                         old->kind,
     1493                        (ast::AggregateDecl::Aggregate)old->kind,
    15071494                        GET_ACCEPT_V(attributes, Attribute),
    15081495                        { old->linkage.val }
     
    20452032        }
    20462033
    2047         virtual void visit( const KeywordCastExpr * old) override final {
    2048                 ast::KeywordCastExpr::Target castTarget = ast::KeywordCastExpr::NUMBER_OF_TARGETS;
    2049                 switch (old->target) {
    2050                         case KeywordCastExpr::Coroutine:
    2051                                 castTarget = ast::KeywordCastExpr::Coroutine;
    2052                                 break;
    2053                         case KeywordCastExpr::Thread:
    2054                                 castTarget = ast::KeywordCastExpr::Thread;
    2055                                 break;
    2056                         case KeywordCastExpr::Monitor:
    2057                                 castTarget = ast::KeywordCastExpr::Monitor;
    2058                                 break;
    2059                         default:
    2060                                 break;
    2061                 }
    2062                 assert ( castTarget < ast::KeywordCastExpr::NUMBER_OF_TARGETS );
     2034        virtual void visit( const KeywordCastExpr * old ) override final {
     2035                ast::AggregateDecl::Aggregate castTarget = (ast::AggregateDecl::Aggregate)old->target;
     2036                assert( ast::AggregateDecl::Generator <= castTarget && castTarget <= ast::AggregateDecl::Thread );
    20632037                this->node = visitBaseExpr( old,
    20642038                        new ast::KeywordCastExpr(
  • src/AST/Decl.cpp

    r98d6965d r312029a  
    99// Author           : Aaron B. Moss
    1010// Created On       : Thu May 9 10:00:00 2019
    11 // Last Modified By : Aaron B. Moss
    12 // Last Modified On : Thu May 9 10:00:00 2019
    13 // Update Count     : 1
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Wed Dec 11 16:41:39 2019
     13// Update Count     : 18
    1414//
    1515
     
    1818#include <cassert>             // for assert, strict_dynamic_cast
    1919#include <iostream>
    20 #include <string>
    2120#include <unordered_map>
    2221
     
    5655// --- TypeDecl
    5756
    58 std::string TypeDecl::typeString() const {
    59         static const std::string kindNames[] = { "object type", "function type", "tuple type" };
     57const char * TypeDecl::typeString() const {
     58        static const char * kindNames[] = { "sized object type", "sized function type", "sized tuple type" };
    6059        assertf( sizeof(kindNames)/sizeof(kindNames[0]) == DeclarationNode::NoTypeClass-1,
    6160                "typeString: kindNames is out of sync." );
    6261        assertf( kind < sizeof(kindNames)/sizeof(kindNames[0]), "TypeDecl's kind is out of bounds." );
    63         return (sized ? "sized " : "") + kindNames[ kind ];
     62        return sized ? kindNames[ kind ] : &kindNames[ kind ][ sizeof("sized") ]; // sizeof includes '\0'
    6463}
    6564
    66 std::string TypeDecl::genTypeString() const {
    67         static const std::string kindNames[] = { "dtype", "ftype", "ttype" };
     65const char * TypeDecl::genTypeString() const {
     66        static const char * kindNames[] = { "dtype", "ftype", "ttype" };
    6867        assertf( sizeof(kindNames)/sizeof(kindNames[0]) == DeclarationNode::NoTypeClass-1, "genTypeString: kindNames is out of sync." );
    6968        assertf( kind < sizeof(kindNames)/sizeof(kindNames[0]), "TypeDecl's kind is out of bounds." );
     
    7372std::ostream & operator<< ( std::ostream & out, const TypeDecl::Data & data ) {
    7473        return out << data.kind << ", " << data.isComplete;
     74}
     75
     76// --- AggregateDecl
     77
     78// These must harmonize with the corresponding AggregateDecl::Aggregate enumerations.
     79static const char * aggregateNames[] = { "struct", "union", "enum", "exception", "trait", "generator", "coroutine", "monitor", "thread", "NoAggregateName" };
     80
     81const char * AggregateDecl::aggrString( AggregateDecl::Aggregate aggr ) {
     82        return aggregateNames[aggr];
    7583}
    7684
  • src/AST/Decl.hpp

    r98d6965d r312029a  
    99// Author           : Aaron B. Moss
    1010// Created On       : Thu May 9 10:00:00 2019
    11 // Last Modified By : Aaron B. Moss
    12 // Last Modified On : Thu May 9 10:00:00 2019
    13 // Update Count     : 1
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Wed Dec 11 08:20:20 2019
     13// Update Count     : 16
    1414//
    1515
     
    154154
    155155        /// Produces a name for the kind of alias
    156         virtual std::string typeString() const = 0;
     156        virtual const char * typeString() const = 0;
    157157
    158158private:
     
    190190          init( i ) {}
    191191
    192         std::string typeString() const override;
     192        const char * typeString() const override;
    193193        /// Produces a name for generated code
    194         std::string genTypeString() const;
     194        const char * genTypeString() const;
    195195
    196196        /// convenience accessor to match Type::isComplete()
     
    212212        : NamedTypeDecl( loc, name, storage, b, spec ) {}
    213213
    214         std::string typeString() const override { return "typedef"; }
     214        const char * typeString() const override { return "typedef"; }
    215215
    216216        const Decl * accept( Visitor & v ) const override { return v.visit( this ); }
     
    223223class AggregateDecl : public Decl {
    224224public:
     225        enum Aggregate { Struct, Union, Enum, Exception, Trait, Generator, Coroutine, Monitor, Thread, NoAggregate };
     226        static const char * aggrString( Aggregate aggr );
     227
    225228        std::vector<ptr<Decl>> members;
    226229        std::vector<ptr<TypeDecl>> params;
     
    237240
    238241        /// Produces a name for the kind of aggregate
    239         virtual std::string typeString() const = 0;
     242        virtual const char * typeString() const = 0;
    240243
    241244private:
     
    247250class StructDecl final : public AggregateDecl {
    248251public:
    249         DeclarationNode::Aggregate kind;
     252        Aggregate kind;
    250253
    251254        StructDecl( const CodeLocation& loc, const std::string& name,
    252                 DeclarationNode::Aggregate kind = DeclarationNode::Struct,
     255                Aggregate kind = Struct,
    253256                std::vector<ptr<Attribute>>&& attrs = {}, Linkage::Spec linkage = Linkage::Cforall )
    254257        : AggregateDecl( loc, name, std::move(attrs), linkage ), kind( kind ) {}
    255258
    256         bool is_coroutine() { return kind == DeclarationNode::Coroutine; }
    257         bool is_monitor() { return kind == DeclarationNode::Monitor; }
    258         bool is_thread() { return kind == DeclarationNode::Thread; }
    259 
    260         const Decl * accept( Visitor & v ) const override { return v.visit( this ); }
    261 
    262         std::string typeString() const override { return "struct"; }
     259        bool is_coroutine() { return kind == Coroutine; }
     260        bool is_monitor() { return kind == Monitor; }
     261        bool is_thread() { return kind == Thread; }
     262
     263        const Decl * accept( Visitor & v ) const override { return v.visit( this ); }
     264
     265        const char * typeString() const override { return aggrString( kind ); }
    263266
    264267private:
     
    276279        const Decl * accept( Visitor& v ) const override { return v.visit( this ); }
    277280
    278         std::string typeString() const override { return "union"; }
     281        const char * typeString() const override { return aggrString( Union ); }
    279282
    280283private:
     
    295298        const Decl * accept( Visitor & v ) const override { return v.visit( this ); }
    296299
    297         std::string typeString() const override { return "enum"; }
     300        const char * typeString() const override { return aggrString( Enum ); }
    298301
    299302private:
     
    314317        const Decl * accept( Visitor & v ) const override { return v.visit( this ); }
    315318
    316         std::string typeString() const override { return "trait"; }
     319        const char * typeString() const override { return "trait"; }
    317320
    318321private:
  • src/AST/Expr.cpp

    r98d6965d r312029a  
    99// Author           : Aaron B. Moss
    1010// Created On       : Wed May 15 17:00:00 2019
    11 // Last Modified By : Andrew Beach
     11// Last Modified By : Peter A. Buhr
    1212// Created On       : Thr Jun 13 13:38:00 2019
    13 // Update Count     : 2
     13// Update Count     : 6
    1414//
    1515
     
    141141// --- KeywordCastExpr
    142142
    143 const std::string & KeywordCastExpr::targetString() const {
    144         static const std::string targetStrs[] = {
    145                 "coroutine", "thread", "monitor"
    146         };
    147         static_assert(
    148                 (sizeof(targetStrs) / sizeof(targetStrs[0])) == ((unsigned long)NUMBER_OF_TARGETS),
    149                 "Each KeywordCastExpr::Target should have a corresponding string representation"
    150         );
    151         return targetStrs[(unsigned long)target];
     143const char * KeywordCastExpr::targetString() const {
     144        return AggregateDecl::aggrString( target );
    152145}
    153146
  • src/AST/Expr.hpp

    r98d6965d r312029a  
    99// Author           : Aaron B. Moss
    1010// Created On       : Fri May 10 10:30:00 2019
    11 // Last Modified By : Aaron B. Moss
     11// Last Modified By : Peter A. Buhr
    1212// Created On       : Fri May 10 10:30:00 2019
    13 // Update Count     : 1
     13// Update Count     : 7
    1414//
    1515
     
    2626#include "Fwd.hpp"        // for UniqueId
    2727#include "Label.hpp"
     28#include "Decl.hpp"
    2829#include "ParseNode.hpp"
    2930#include "Visitor.hpp"
     
    300301public:
    301302        ptr<Expr> arg;
    302         enum Target { Coroutine, Thread, Monitor, NUMBER_OF_TARGETS } target;
    303 
    304         KeywordCastExpr( const CodeLocation & loc, const Expr * a, Target t )
     303        ast::AggregateDecl::Aggregate target;
     304
     305        KeywordCastExpr( const CodeLocation & loc, const Expr * a, ast::AggregateDecl::Aggregate t )
    305306        : Expr( loc ), arg( a ), target( t ) {}
    306307
    307308        /// Get a name for the target type
    308         const std::string& targetString() const;
     309        const char * targetString() const;
    309310
    310311        const Expr * accept( Visitor & v ) const override { return v.visit( this ); }
  • src/Concurrency/Keywords.cc

    r98d6965d r312029a  
    1111// Last Modified By :
    1212// Last Modified On :
    13 // Update Count     : 5
     13// Update Count     : 9
    1414//
    1515
     
    5353          public:
    5454
    55                 ConcurrentSueKeyword( std::string&& type_name, std::string&& field_name, std::string&& getter_name, std::string&& context_error, bool needs_main, KeywordCastExpr::Target cast_target ) :
     55                ConcurrentSueKeyword( std::string&& type_name, std::string&& field_name, std::string&& getter_name, std::string&& context_error, bool needs_main, AggregateDecl::Aggregate cast_target ) :
    5656                  type_name( type_name ), field_name( field_name ), getter_name( getter_name ), context_error( context_error ), needs_main( needs_main ), cast_target( cast_target ) {}
    5757
     
    7676                const std::string context_error;
    7777                bool needs_main;
    78                 KeywordCastExpr::Target cast_target;
     78                AggregateDecl::Aggregate cast_target;
    7979
    8080                StructDecl   * type_decl = nullptr;
     
    101101                        "thread keyword requires threads to be in scope, add #include <thread.hfa>\n",
    102102                        true,
    103                         KeywordCastExpr::Thread
     103                        AggregateDecl::Thread
    104104                )
    105105                {}
     
    133133                        "coroutine keyword requires coroutines to be in scope, add #include <coroutine.hfa>\n",
    134134                        true,
    135                         KeywordCastExpr::Coroutine
     135                        AggregateDecl::Coroutine
    136136                )
    137137                {}
     
    165165                        "monitor keyword requires monitors to be in scope, add #include <monitor.hfa>\n",
    166166                        false,
    167                         KeywordCastExpr::Monitor
     167                        AggregateDecl::Monitor
    168168                )
    169169                {}
  • src/Concurrency/Waitfor.cc

    r98d6965d r312029a  
    1111// Last Modified By :
    1212// Last Modified On :
    13 // Update Count     : 7
     13// Update Count     : 10
    1414//
    1515
     
    2323#include "Common/PassVisitor.h"    // for PassVisitor
    2424#include "Common/SemanticError.h"  // for SemanticError
     25#include "Common/UniqueName.h"     // for UniqueName
    2526#include "Common/utility.h"        // for deleteAll, map_range
    2627#include "CodeGen/OperatorTable.h" // for isConstructor
  • src/Parser/DeclarationNode.cc

    r98d6965d r312029a  
    1010// Created On       : Sat May 16 12:34:05 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Thu Jul 25 22:17:10 2019
    13 // Update Count     : 1116
     12// Last Modified On : Wed Dec 11 07:40:14 2019
     13// Update Count     : 1123
    1414//
    1515
     
    4747const char * DeclarationNode::signednessNames[] = { "signed", "unsigned", "NoSignednessNames" };
    4848const char * DeclarationNode::lengthNames[] = { "short", "long", "long long", "NoLengthNames" };
    49 const char * DeclarationNode::aggregateNames[] = { "struct", "union", "trait", "coroutine", "monitor", "thread", "NoAggregateNames" };
    5049const char * DeclarationNode::typeClassNames[] = { "otype", "dtype", "ftype", "NoTypeClassNames" };
    5150const char * DeclarationNode::builtinTypeNames[] = { "__builtin_va_list", "__auto_type", "zero_t", "one_t", "NoBuiltinTypeNames" };
     
    267266}
    268267
    269 DeclarationNode * DeclarationNode::newAggregate( Aggregate kind, const string * name, ExpressionNode * actuals, DeclarationNode * fields, bool body ) {
     268DeclarationNode * DeclarationNode::newAggregate( AggregateDecl::Aggregate kind, const string * name, ExpressionNode * actuals, DeclarationNode * fields, bool body ) {
    270269        DeclarationNode * newnode = new DeclarationNode;
    271270        newnode->type = new TypeData( TypeData::Aggregate );
     
    328327        newnode->type = new TypeData( TypeData::Aggregate );
    329328        newnode->type->aggregate.name = name;
    330         newnode->type->aggregate.kind = Trait;
     329        newnode->type->aggregate.kind = AggregateDecl::Trait;
    331330        newnode->type->aggregate.params = params;
    332331        newnode->type->aggregate.fields = asserts;
     
    338337        newnode->type = new TypeData( TypeData::AggregateInst );
    339338        newnode->type->aggInst.aggregate = new TypeData( TypeData::Aggregate );
    340         newnode->type->aggInst.aggregate->aggregate.kind = Trait;
     339        newnode->type->aggInst.aggregate->aggregate.kind = AggregateDecl::Trait;
    341340        newnode->type->aggInst.aggregate->aggregate.name = name;
    342341        newnode->type->aggInst.params = params;
  • src/Parser/ExpressionNode.cc

    r98d6965d r312029a  
    1010// Created On       : Sat May 16 13:17:07 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sun Aug  4 20:57:55 2019
    13 // Update Count     : 978
     12// Last Modified On : Tue Dec 10 23:01:47 2019
     13// Update Count     : 980
    1414//
    1515
     
    434434} // build_cast
    435435
    436 Expression * build_keyword_cast( KeywordCastExpr::Target target, ExpressionNode * expr_node ) {
     436Expression * build_keyword_cast( AggregateDecl::Aggregate target, ExpressionNode * expr_node ) {
    437437        return new KeywordCastExpr( maybeMoveBuild< Expression >(expr_node), target );
    438438}
  • src/Parser/ParseNode.h

    r98d6965d r312029a  
    1010// Created On       : Sat May 16 13:28:16 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Thu Jul 25 22:17:10 2019
    13 // Update Count     : 876
     12// Last Modified On : Wed Dec 11 07:40:07 2019
     13// Update Count     : 882
    1414//
    1515
     
    2929#include "Common/utility.h"        // for maybeClone, maybeBuild
    3030#include "Parser/LinkageSpec.h"    // for Spec
     31#include "SynTree/Declaration.h"   // for Aggregate
    3132#include "SynTree/Expression.h"    // for Expression, ConstantExpr (ptr only)
    3233#include "SynTree/Label.h"         // for Label
     
    184185
    185186Expression * build_cast( DeclarationNode * decl_node, ExpressionNode * expr_node );
    186 Expression * build_keyword_cast( KeywordCastExpr::Target target, ExpressionNode * expr_node );
     187Expression * build_keyword_cast( AggregateDecl::Aggregate target, ExpressionNode * expr_node );
    187188Expression * build_virtual_cast( DeclarationNode * decl_node, ExpressionNode * expr_node );
    188189Expression * build_fieldSel( ExpressionNode * expr_node, Expression * member );
     
    217218        enum Length { Short, Long, LongLong, NoLength };
    218219        static const char * lengthNames[];
    219         enum Aggregate { Struct, Union, Exception, Trait, Coroutine, Monitor, Thread, NoAggregate };
    220         static const char * aggregateNames[];
    221220        enum TypeClass { Otype, Dtype, Ftype, Ttype, NoTypeClass };
    222221        static const char * typeClassNames[];
     
    237236        static DeclarationNode * newQualifiedType( DeclarationNode *, DeclarationNode * );
    238237        static DeclarationNode * newFunction( const std::string * name, DeclarationNode * ret, DeclarationNode * param, StatementNode * body );
    239         static DeclarationNode * newAggregate( Aggregate kind, const std::string * name, ExpressionNode * actuals, DeclarationNode * fields, bool body );
     238        static DeclarationNode * newAggregate( AggregateDecl::Aggregate kind, const std::string * name, ExpressionNode * actuals, DeclarationNode * fields, bool body );
    240239        static DeclarationNode * newEnum( const std::string * name, DeclarationNode * constants, bool body );
    241240        static DeclarationNode * newEnumConstant( const std::string * name, ExpressionNode * constant );
  • src/Parser/TypeData.cc

    r98d6965d r312029a  
    1010// Created On       : Sat May 16 15:12:51 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Wed Feb 13 18:16:23 2019
    13 // Update Count     : 649
     12// Last Modified On : Wed Dec 11 07:48:33 2019
     13// Update Count     : 659
    1414//
    1515
     
    6767          case Aggregate:
    6868                // aggregate = new Aggregate_t;
    69                 aggregate.kind = DeclarationNode::NoAggregate;
     69                aggregate.kind = AggregateDecl::NoAggregate;
    7070                aggregate.name = nullptr;
    7171                aggregate.params = nullptr;
     
    345345                break;
    346346          case Aggregate:
    347                 os << DeclarationNode::aggregateNames[ aggregate.kind ] << ' ' << *aggregate.name << endl;
     347                os << AggregateDecl::aggrString( aggregate.kind ) << ' ' << *aggregate.name << endl;
    348348                if ( aggregate.params ) {
    349349                        os << string( indent + 2, ' ' ) << "with type parameters" << endl;
     
    768768        AggregateDecl * at;
    769769        switch ( td->aggregate.kind ) {
    770           case DeclarationNode::Struct:
    771           case DeclarationNode::Coroutine:
    772           case DeclarationNode::Monitor:
    773           case DeclarationNode::Thread:
     770          case AggregateDecl::Struct:
     771          case AggregateDecl::Coroutine:
     772          case AggregateDecl::Monitor:
     773          case AggregateDecl::Thread:
    774774                at = new StructDecl( *td->aggregate.name, td->aggregate.kind, attributes, linkage );
    775775                buildForall( td->aggregate.params, at->get_parameters() );
    776776                break;
    777           case DeclarationNode::Union:
     777          case AggregateDecl::Union:
    778778                at = new UnionDecl( *td->aggregate.name, attributes, linkage );
    779779                buildForall( td->aggregate.params, at->get_parameters() );
    780780                break;
    781           case DeclarationNode::Trait:
     781          case AggregateDecl::Trait:
    782782                at = new TraitDecl( *td->aggregate.name, attributes, linkage );
    783783                buildList( td->aggregate.params, at->get_parameters() );
     
    809809                          AggregateDecl * typedecl = buildAggregate( type, attributes, linkage );
    810810                          switch ( type->aggregate.kind ) {
    811                                 case DeclarationNode::Struct:
    812                                 case DeclarationNode::Coroutine:
    813                                 case DeclarationNode::Monitor:
    814                                 case DeclarationNode::Thread:
     811                                case AggregateDecl::Struct:
     812                                case AggregateDecl::Coroutine:
     813                                case AggregateDecl::Monitor:
     814                                case AggregateDecl::Thread:
    815815                                  ret = new StructInstType( buildQualifiers( type ), (StructDecl *)typedecl );
    816816                                  break;
    817                                 case DeclarationNode::Union:
     817                                case AggregateDecl::Union:
    818818                                  ret = new UnionInstType( buildQualifiers( type ), (UnionDecl *)typedecl );
    819819                                  break;
    820                                 case DeclarationNode::Trait:
     820                                case AggregateDecl::Trait:
    821821                                  assert( false );
    822822                                  //ret = new TraitInstType( buildQualifiers( type ), (TraitDecl *)typedecl );
     
    827827                  } else {
    828828                          switch ( type->aggregate.kind ) {
    829                                 case DeclarationNode::Struct:
    830                                 case DeclarationNode::Coroutine:
    831                                 case DeclarationNode::Monitor:
    832                                 case DeclarationNode::Thread:
     829                                case AggregateDecl::Struct:
     830                                case AggregateDecl::Coroutine:
     831                                case AggregateDecl::Monitor:
     832                                case AggregateDecl::Thread:
    833833                                  ret = new StructInstType( buildQualifiers( type ), *type->aggregate.name );
    834834                                  break;
    835                                 case DeclarationNode::Union:
     835                                case AggregateDecl::Union:
    836836                                  ret = new UnionInstType( buildQualifiers( type ), *type->aggregate.name );
    837837                                  break;
    838                                 case DeclarationNode::Trait:
     838                                case AggregateDecl::Trait:
    839839                                  ret = new TraitInstType( buildQualifiers( type ), *type->aggregate.name );
    840840                                  break;
     
    863863          case TypeData::Aggregate: {
    864864                  switch ( type->aggregate.kind ) {
    865                         case DeclarationNode::Struct:
    866                         case DeclarationNode::Coroutine:
    867                         case DeclarationNode::Monitor:
    868                         case DeclarationNode::Thread:
     865                        case AggregateDecl::Struct:
     866                        case AggregateDecl::Coroutine:
     867                        case AggregateDecl::Monitor:
     868                        case AggregateDecl::Thread:
    869869                          ret = new StructInstType( buildQualifiers( type ), *type->aggregate.name );
    870870                          break;
    871                         case DeclarationNode::Union:
     871                        case AggregateDecl::Union:
    872872                          ret = new UnionInstType( buildQualifiers( type ), *type->aggregate.name );
    873873                          break;
    874                         case DeclarationNode::Trait:
     874                        case AggregateDecl::Trait:
    875875                          ret = new TraitInstType( buildQualifiers( type ), *type->aggregate.name );
    876876                          break;
  • src/Parser/TypeData.h

    r98d6965d r312029a  
    1010// Created On       : Sat May 16 15:18:36 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Thu Nov  1 20:56:46 2018
    13 // Update Count     : 196
     12// Last Modified On : Tue Dec 10 23:01:07 2019
     13// Update Count     : 198
    1414//
    1515
     
    3030
    3131        struct Aggregate_t {
    32                 DeclarationNode::Aggregate kind;
     32                AggregateDecl::Aggregate kind;
    3333                const std::string * name = nullptr;
    3434                DeclarationNode * params = nullptr;
  • src/Parser/parser.yy

    r98d6965d r312029a  
    1010// Created On       : Sat Sep  1 20:22:55 2001
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sat Dec  7 10:43:44 2019
    13 // Update Count     : 4394
     12// Last Modified On : Tue Dec 10 23:07:17 2019
     13// Update Count     : 4400
    1414//
    1515
     
    5151using namespace std;
    5252
     53#include "SynTree/Declaration.h"
    5354#include "ParseNode.h"
    5455#include "TypedefTable.h"
     
    211212} // forCtrl
    212213
    213 KeywordCastExpr::Target Aggregate2Target( DeclarationNode::Aggregate aggr ) {
    214         KeywordCastExpr::Target target;
    215         switch ( aggr ) {
    216           case DeclarationNode::Coroutine: target = KeywordCastExpr::Coroutine; break;
    217           case DeclarationNode::Monitor: target = KeywordCastExpr::Monitor; break;
    218           case DeclarationNode::Thread: target = KeywordCastExpr::Thread; break;
    219           default: abort();
    220         } // switch
    221         return target;
    222 } // Aggregate2Target
    223 
    224 
    225214bool forall = false, yyy = false;                                               // aggregate have one or more forall qualifiers ?
    226215
     
    248237        ExpressionNode * en;
    249238        DeclarationNode * decl;
    250         DeclarationNode::Aggregate aggKey;
     239        AggregateDecl::Aggregate aggKey;
    251240        DeclarationNode::TypeClass tclass;
    252241        StatementNode * sn;
     
    662651                { $$ = new ExpressionNode( build_fieldSel( $1, build_tuple( $4 ) ) ); }
    663652        | postfix_expression '.' aggregate_control
    664                 { $$ = new ExpressionNode( build_keyword_cast( Aggregate2Target( $3 ), $1 ) ); }
     653                { $$ = new ExpressionNode( build_keyword_cast( $3, $1 ) ); }
    665654        | postfix_expression ARROW identifier
    666655                { $$ = new ExpressionNode( build_pfieldSel( $1, build_varref( $3 ) ) ); }
     
    807796                { $$ = new ExpressionNode( build_cast( $2, $4 ) ); }
    808797        | '(' aggregate_control '&' ')' cast_expression         // CFA
    809                 { $$ = new ExpressionNode( build_keyword_cast( Aggregate2Target( $2 ), $5 ) ); }
     798                { $$ = new ExpressionNode( build_keyword_cast( $2, $5 ) ); }
    810799                // VIRTUAL cannot be opt because of look ahead issues
    811800        | '(' VIRTUAL ')' cast_expression                                       // CFA
     
    20712060aggregate_data:
    20722061        STRUCT
    2073                 { yyy = true; $$ = DeclarationNode::Struct; }
     2062                { yyy = true; $$ = AggregateDecl::Struct; }
    20742063        | UNION
    2075                 { yyy = true; $$ = DeclarationNode::Union; }
     2064                { yyy = true; $$ = AggregateDecl::Union; }
    20762065        | EXCEPTION                                                                                     // CFA
    2077                 { yyy = true; $$ = DeclarationNode::Exception; }
     2066                { yyy = true; $$ = AggregateDecl::Exception; }
    20782067        ;
    20792068
    20802069aggregate_control:                                                                              // CFA
    20812070        GENERATOR
    2082                 { yyy = true; $$ = DeclarationNode::Coroutine; }
     2071                { yyy = true; $$ = AggregateDecl::Coroutine; }
    20832072        | COROUTINE
    2084                 { yyy = true; $$ = DeclarationNode::Coroutine; }
     2073                { yyy = true; $$ = AggregateDecl::Coroutine; }
    20852074        | MONITOR
    2086                 { yyy = true; $$ = DeclarationNode::Monitor; }
     2075                { yyy = true; $$ = AggregateDecl::Monitor; }
    20872076        | THREAD
    2088                 { yyy = true; $$ = DeclarationNode::Thread; }
     2077                { yyy = true; $$ = AggregateDecl::Thread; }
    20892078        ;
    20902079
  • src/SymTab/Validate.cc

    r98d6965d r312029a  
    99// Author           : Richard C. Bilson
    1010// Created On       : Sun May 17 21:50:04 2015
    11 // Last Modified By : Andrew Beach
    12 // Last Modified On : Wed Aug  7 6:42:00 2019
    13 // Update Count     : 360
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Tue Dec 10 22:22:01 2019
     13// Update Count     : 362
    1414//
    1515
     
    10491049                Type * designatorType = tyDecl->base->stripDeclarator();
    10501050                if ( StructInstType * aggDecl = dynamic_cast< StructInstType * >( designatorType ) ) {
    1051                         declsToAddBefore.push_back( new StructDecl( aggDecl->name, DeclarationNode::Struct, noAttributes, tyDecl->linkage ) );
     1051                        declsToAddBefore.push_back( new StructDecl( aggDecl->name, AggregateDecl::Struct, noAttributes, tyDecl->linkage ) );
    10521052                } else if ( UnionInstType * aggDecl = dynamic_cast< UnionInstType * >( designatorType ) ) {
    10531053                        declsToAddBefore.push_back( new UnionDecl( aggDecl->name, noAttributes, tyDecl->linkage ) );
  • src/SynTree/AggregateDecl.cc

    r98d6965d r312029a  
    99// Author           : Richard C. Bilson
    1010// Created On       : Sun May 17 23:56:39 2015
    11 // Last Modified By : Andrew Beach
    12 // Last Modified On : Fri Aug  4 14:22:00 2017
    13 // Update Count     : 22
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Wed Dec 11 16:31:55 2019
     13// Update Count     : 29
    1414//
    1515
     
    2121#include "Common/utility.h"      // for printAll, cloneAll, deleteAll
    2222#include "Declaration.h"         // for AggregateDecl, TypeDecl, Declaration
     23#include "Initializer.h"
    2324#include "Parser/LinkageSpec.h"  // for Spec, linkageName, Cforall
    2425#include "Type.h"                // for Type, Type::StorageClasses
    2526
     27
     28// These must harmonize with the corresponding AggregateDecl::Aggregate enumerations.
     29static const char * aggregateNames[] = { "struct", "union", "enum", "exception", "trait", "generator", "coroutine", "monitor", "thread", "NoAggregateName" };
     30
     31const char * AggregateDecl::aggrString( AggregateDecl::Aggregate aggr ) {
     32        return aggregateNames[aggr];
     33}
    2634
    2735AggregateDecl::AggregateDecl( const std::string &name, const std::list< Attribute * > & attributes, LinkageSpec::Spec linkage ) : Parent( name, Type::StorageClasses(), linkage ), body( false ), attributes( attributes ) {
     
    7886}
    7987
    80 std::string StructDecl::typeString() const { return "struct"; }
     88const char * StructDecl::typeString() const { return aggrString( kind ); }
    8189
    82 std::string UnionDecl::typeString() const { return "union"; }
     90const char * UnionDecl::typeString() const { return aggrString( Union ); }
    8391
    84 std::string EnumDecl::typeString() const { return "enum"; }
     92const char * EnumDecl::typeString() const { return aggrString( Enum ); }
    8593
    86 std::string TraitDecl::typeString() const { return "trait"; }
     94const char * TraitDecl::typeString() const { return aggrString( Trait ); }
    8795
    8896bool EnumDecl::valueOf( Declaration * enumerator, long long int & value ) {
  • src/SynTree/Declaration.cc

    r98d6965d r312029a  
    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:38:00 2017
    13 // Update Count     : 25
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Wed Dec 11 16:39:56 2019
     13// Update Count     : 36
    1414//
    1515
     
    2424#include "SynTree/Statement.h"       // for AsmStmt
    2525#include "SynTree/SynTree.h"         // for UniqueId
     26#include "SynTree/Expression.h"
    2627#include "Type.h"                    // for Type, Type::StorageClasses
    2728
     29// To canonicalize declarations
    2830static UniqueId lastUniqueId = 0;
    2931
  • src/SynTree/Declaration.h

    r98d6965d r312029a  
    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 : Thr May  2 10:47:00 2019
    13 // Update Count     : 135
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Wed Dec 11 16:48:20 2019
     13// Update Count     : 149
    1414//
    1515
     
    2525#include "Mutator.h"             // for Mutator
    2626#include "Parser/LinkageSpec.h"  // for Spec, Cforall
    27 #include "Parser/ParseNode.h"    // for DeclarationNode, DeclarationNode::Ag...
    2827#include "SynTree.h"             // for UniqueId
    2928#include "SynTree/Type.h"        // for Type, Type::StorageClasses, Type::Fu...
     
    194193        std::list< DeclarationWithType* >& get_assertions() { return assertions; }
    195194
    196         virtual std::string typeString() const = 0;
     195        virtual const char * typeString() const = 0;
    197196
    198197        virtual NamedTypeDecl *clone() const override = 0;
     
    237236        TypeDecl * set_sized( bool newValue ) { sized = newValue; return this; }
    238237
    239         virtual std::string typeString() const override;
    240         virtual std::string genTypeString() const;
     238        virtual const char * typeString() const override;
     239        virtual const char * genTypeString() const;
    241240
    242241        virtual TypeDecl *clone() const override { return new TypeDecl( *this ); }
     
    257256        TypedefDecl( const TypedefDecl &other ) : Parent( other ) {}
    258257
    259         virtual std::string typeString() const override;
     258        virtual const char * typeString() const override;
    260259
    261260        virtual TypedefDecl *clone() const override { return new TypedefDecl( *this ); }
     
    269268        typedef Declaration Parent;
    270269  public:
     270        enum Aggregate { Struct, Union, Enum, Exception, Trait, Generator, Coroutine, Monitor, Thread, NoAggregate };
     271        static const char * aggrString( Aggregate aggr );
     272
    271273        std::list<Declaration*> members;
    272274        std::list<TypeDecl*> parameters;
     
    291293        virtual void printShort( std::ostream &os, Indenter indent = {} ) const override;
    292294  protected:
    293         virtual std::string typeString() const = 0;
     295        virtual const char * typeString() const = 0;
    294296};
    295297
     
    297299        typedef AggregateDecl Parent;
    298300  public:
    299         StructDecl( const std::string &name, DeclarationNode::Aggregate kind = DeclarationNode::Struct, const std::list< Attribute * > & attributes = std::list< class Attribute * >(), LinkageSpec::Spec linkage = LinkageSpec::Cforall ) : Parent( name, attributes, linkage ), kind( kind ) {}
     301        StructDecl( const std::string &name, Aggregate kind = Struct, const std::list< Attribute * > & attributes = std::list< class Attribute * >(), LinkageSpec::Spec linkage = LinkageSpec::Cforall ) : Parent( name, attributes, linkage ), kind( kind ) {}
    300302        StructDecl( const StructDecl &other ) : Parent( other ), kind( other.kind ) {}
    301303
    302         bool is_coroutine() { return kind == DeclarationNode::Coroutine; }
    303         bool is_monitor() { return kind == DeclarationNode::Monitor; }
    304         bool is_thread() { return kind == DeclarationNode::Thread; }
     304        bool is_coroutine() { return kind == Coroutine; }
     305        bool is_monitor() { return kind == Monitor; }
     306        bool is_thread() { return kind == Thread; }
    305307
    306308        virtual StructDecl *clone() const override { return new StructDecl( *this ); }
     
    308310        virtual void accept( Visitor & v ) const override { v.visit( this ); }
    309311        virtual Declaration *acceptMutator( Mutator &m )  override { return m.mutate( this ); }
    310         DeclarationNode::Aggregate kind;
    311   private:
    312         virtual std::string typeString() const override;
     312        Aggregate kind;
     313  private:
     314        virtual const char * typeString() const override;
    313315};
    314316
     
    324326        virtual Declaration *acceptMutator( Mutator &m )  override { return m.mutate( this ); }
    325327  private:
    326         virtual std::string typeString() const override;
     328        virtual const char * typeString() const override;
    327329};
    328330
     
    341343  private:
    342344        std::unordered_map< std::string, long long int > enumValues;
    343         virtual std::string typeString() const override;
     345        virtual const char * typeString() const override;
    344346};
    345347
     
    357359        virtual Declaration *acceptMutator( Mutator &m )  override { return m.mutate( this ); }
    358360  private:
    359         virtual std::string typeString() const override;
     361        virtual const char * typeString() const override;
    360362};
    361363
  • src/SynTree/Expression.cc

    r98d6965d r312029a  
    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 : Thr Aug 15 13:43:00 2019
    13 // Update Count     : 64
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Wed Dec 11 07:55:15 2019
     13// Update Count     : 70
    1414//
    1515
     
    2222
    2323#include "Common/utility.h"          // for maybeClone, cloneAll, deleteAll
    24 #include "Declaration.h"             // for ObjectDecl, DeclarationWithType
    2524#include "Expression.h"              // for Expression, ImplicitCopyCtorExpr
    2625#include "InitTweak/InitTweak.h"     // for getCallArg, getPointerBase
     
    294293}
    295294
    296 KeywordCastExpr::KeywordCastExpr( Expression * arg, Target target ) : Expression(), arg(arg), target( target ) {
     295KeywordCastExpr::KeywordCastExpr( Expression * arg, AggregateDecl::Aggregate target ) : Expression(), arg(arg), target( target ) {
    297296}
    298297
     
    304303}
    305304
    306 const std::string & KeywordCastExpr::targetString() const {
    307         static const std::string targetStrs[] = {
    308                 "coroutine", "thread", "monitor"
    309         };
    310         static_assert(
    311                 (sizeof(targetStrs) / sizeof(targetStrs[0])) == ((unsigned long)NUMBER_OF_TARGETS),
    312                 "Each KeywordCastExpr::Target should have a corresponding string representation"
    313         );
    314         return targetStrs[(unsigned long)target];
     305const char * KeywordCastExpr::targetString() const {
     306        return AggregateDecl::aggrString( target );
    315307}
    316308
  • src/SynTree/Expression.h

    r98d6965d r312029a  
    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 : Thr Aug 15 13:46:00 2019
    13 // Update Count     : 54
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Wed Dec 11 16:50:19 2019
     13// Update Count     : 60
    1414//
    1515
     
    2828#include "Label.h"                // for Label
    2929#include "Mutator.h"              // for Mutator
     30#include "Declaration.h"          // for Aggregate
    3031#include "SynTree.h"              // for UniqueId
    3132#include "Visitor.h"              // for Visitor
     
    229230public:
    230231        Expression * arg;
    231         enum Target {
    232                 Coroutine, Thread, Monitor, NUMBER_OF_TARGETS
    233         };
    234232        struct Concrete {
    235233                std::string field;
    236234                std::string getter;
    237235        };
    238         Target target;
     236        AggregateDecl::Aggregate target;
    239237        Concrete concrete_target;
    240238
    241         KeywordCastExpr( Expression * arg, Target target );
     239        KeywordCastExpr( Expression * arg, AggregateDecl::Aggregate target );
    242240        KeywordCastExpr( const KeywordCastExpr & other );
    243241        virtual ~KeywordCastExpr();
    244242
    245         const std::string & targetString() const;
     243        const char * targetString() const;
    246244
    247245        virtual KeywordCastExpr * clone() const override { return new KeywordCastExpr( * this ); }
  • src/SynTree/FunctionDecl.cc

    r98d6965d r312029a  
    1010// Created On       : Mon May 18 07:44:20 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Thu Mar 16 08:33:41 2017
    13 // Update Count     : 74
     12// Last Modified On : Sat Dec  7 17:40:09 2019
     13// Update Count     : 75
    1414//
    1515
     
    2323#include "Common/utility.h"      // for maybeClone, printAll
    2424#include "Declaration.h"         // for FunctionDecl, FunctionDecl::Parent
     25#include "Expression.h"
    2526#include "Parser/LinkageSpec.h"  // for Spec, linkageName, Cforall
    2627#include "Statement.h"           // for CompoundStmt
  • src/SynTree/NamedTypeDecl.cc

    r98d6965d r312029a  
    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 13:28:00 2017
    13 // Update Count     : 14
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Wed Dec 11 08:26:17 2019
     13// Update Count     : 15
    1414//
    1515
     
    7878}
    7979
    80 std::string TypedefDecl::typeString() const { return "typedef"; }
     80const char * TypedefDecl::typeString() const { return "typedef"; }
    8181
    8282// Local Variables: //
  • src/SynTree/TypeDecl.cc

    r98d6965d r312029a  
    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 : Wed Dec 11 17:56:30 2019
     13// Update Count     : 10
    1414//
    1515
     
    1818
    1919#include "Common/utility.h"  // for maybeClone
     20#include "Parser/ParseNode.h"
    2021#include "Declaration.h"     // for TypeDecl, TypeDecl::Data, TypeDecl::Kind...
    2122#include "Type.h"            // for Type, Type::StorageClasses
     
    3132}
    3233
    33 std::string TypeDecl::typeString() const {
    34         static const std::string kindNames[] = { "object type", "function type", "tuple type" };
     34const char * TypeDecl::typeString() const {
     35        static const char * kindNames[] = { "sized object type", "sized function type", "sized tuple type" };
    3536        assertf( sizeof(kindNames)/sizeof(kindNames[0]) == DeclarationNode::NoTypeClass-1, "typeString: kindNames is out of sync." );
    3637        assertf( kind < sizeof(kindNames)/sizeof(kindNames[0]), "TypeDecl's kind is out of bounds." );
    37         return (isComplete() ? "sized " : "") + kindNames[ kind ];
     38        return isComplete() ? kindNames[ kind ] : &kindNames[ kind ][ sizeof("sized") ]; // sizeof includes '\0'
    3839}
    3940
    40 std::string TypeDecl::genTypeString() const {
    41         static const std::string kindNames[] = { "dtype", "ftype", "ttype" };
     41const char * TypeDecl::genTypeString() const {
     42        static const char * kindNames[] = { "dtype", "ftype", "ttype" };
    4243        assertf( sizeof(kindNames)/sizeof(kindNames[0]) == DeclarationNode::NoTypeClass-1, "genTypeString: kindNames is out of sync." );
    4344        assertf( kind < sizeof(kindNames)/sizeof(kindNames[0]), "TypeDecl's kind is out of bounds." );
  • tests/concurrent/.expect/keywordErrors.txt

    r98d6965d r312029a  
    11concurrent/keywordErrors.cfa:1:1 error: thread keyword requires threads to be in scope, add #include <thread.hfa>
    2 struct A: with body 1
     2thread A: with body 1
    33
    44concurrent/keywordErrors.cfa:6:1 error: thread keyword requires threads to be in scope, add #include <thread.hfa>
    5 struct B: with body 1
     5thread B: with body 1
    66
Note: See TracChangeset for help on using the changeset viewer.