Changeset 312029a for src/AST


Ignore:
Timestamp:
Dec 11, 2019, 8:52:38 PM (4 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

Location:
src/AST
Files:
5 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 ); }
Note: See TracChangeset for help on using the changeset viewer.