Changeset 7030dab for src/SynTree


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

Location:
src/SynTree
Files:
1 added
19 edited
1 moved

Legend:

Unmodified
Added
Removed
  • src/SynTree/AggregateDecl.cc

    r71d6bd8 r7030dab  
    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 : Mon Dec 16 15:07:20 2019
     13// Update Count     : 31
    1414//
    1515
     
    2121#include "Common/utility.h"      // for printAll, cloneAll, deleteAll
    2222#include "Declaration.h"         // for AggregateDecl, TypeDecl, Declaration
    23 #include "Parser/LinkageSpec.h"  // for Spec, linkageName, Cforall
     23#include "Initializer.h"
     24#include "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 ) {
     
    4755        os << typeString() << " " << name << ":";
    4856        if ( get_linkage() != LinkageSpec::Cforall ) {
    49                 os << " " << LinkageSpec::linkageName( linkage );
     57                os << " " << LinkageSpec::name( linkage );
    5058        } // if
    5159        os << " with body " << has_body();
     
    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/Attribute.h

    r71d6bd8 r7030dab  
    1010// Created On       : Mon May 18 07:44:20 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sat Jul 22 09:54:14 2017
    13 // Update Count     : 39
     12// Last Modified On : Thu Feb 13 21:34:08 2020
     13// Update Count     : 40
    1414//
    1515
     
    3838        virtual ~Attribute();
    3939
    40         std::string get_name() const { return name; }
     40        const std::string & get_name() const { return name; }
    4141        void set_name( const std::string & newValue ) { name = newValue; }
    4242        std::list< Expression * > & get_parameters() { return parameters; }
  • src/SynTree/Declaration.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: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

    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 : Thr May  2 10:47:00 2019
    13 // Update Count     : 135
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Fri Dec 13 23:11:22 2019
     13// Update Count     : 157
    1414//
    1515
     
    2424#include "BaseSyntaxNode.h"      // for BaseSyntaxNode
    2525#include "Mutator.h"             // for Mutator
    26 #include "Parser/LinkageSpec.h"  // for Spec, Cforall
    27 #include "Parser/ParseNode.h"    // for DeclarationNode, DeclarationNode::Ag...
     26#include "LinkageSpec.h"         // for Spec, Cforall
    2827#include "SynTree.h"             // for UniqueId
    2928#include "SynTree/Type.h"        // for Type, Type::StorageClasses, Type::Fu...
     
    4443        bool extension = false;
    4544
    46         Declaration( const std::string &name, Type::StorageClasses scs, LinkageSpec::Spec linkage );
    47         Declaration( const Declaration &other );
     45        Declaration( const std::string & name, Type::StorageClasses scs, LinkageSpec::Spec linkage );
     46        Declaration( const Declaration & other );
    4847        virtual ~Declaration();
    4948
    50         const std::string &get_name() const { return name; }
     49        const std::string & get_name() const { return name; }
    5150        void set_name( std::string newValue ) { name = newValue; }
    5251
     
    5958
    6059        bool get_extension() const { return extension; }
    61         Declaration *set_extension( bool exten ) { extension = exten; return this; }
     60        Declaration * set_extension( bool exten ) { extension = exten; return this; }
    6261
    6362        void fixUniqueId( void );
    64         virtual Declaration *clone() const override = 0;
     63        virtual Declaration * clone() const override = 0;
    6564        virtual void accept( Visitor & v ) override = 0;
    6665        virtual void accept( Visitor & v ) const override = 0;
    67         virtual Declaration *acceptMutator( Mutator &m ) override = 0;
    68         virtual void print( std::ostream &os, Indenter indent = {} ) const override = 0;
    69         virtual void printShort( std::ostream &os, Indenter indent = {} ) const = 0;
     66        virtual Declaration * acceptMutator( Mutator & m ) override = 0;
     67        virtual void print( std::ostream & os, Indenter indent = {} ) const override = 0;
     68        virtual void printShort( std::ostream & os, Indenter indent = {} ) const = 0;
    7069
    7170        UniqueId uniqueId;
     
    8180        int scopeLevel = 0;
    8281
    83         Expression *asmName;
     82        Expression * asmName;
    8483        std::list< Attribute * > attributes;
    8584        bool isDeleted = false;
    8685
    87         DeclarationWithType( const std::string &name, Type::StorageClasses scs, LinkageSpec::Spec linkage, const std::list< Attribute * > & attributes, Type::FuncSpecifiers fs );
    88         DeclarationWithType( const DeclarationWithType &other );
     86        DeclarationWithType( const std::string & name, Type::StorageClasses scs, LinkageSpec::Spec linkage, const std::list< Attribute * > & attributes, Type::FuncSpecifiers fs );
     87        DeclarationWithType( const DeclarationWithType & other );
    8988        virtual ~DeclarationWithType();
    9089
     
    9796        DeclarationWithType * set_scopeLevel( int newValue ) { scopeLevel = newValue; return this; }
    9897
    99         Expression *get_asmName() const { return asmName; }
    100         DeclarationWithType * set_asmName( Expression *newValue ) { asmName = newValue; return this; }
     98        Expression * get_asmName() const { return asmName; }
     99        DeclarationWithType * set_asmName( Expression * newValue ) { asmName = newValue; return this; }
    101100
    102101        std::list< Attribute * >& get_attributes() { return attributes; }
     
    106105        //void set_functionSpecifiers( Type::FuncSpecifiers newValue ) { fs = newValue; }
    107106
    108         virtual DeclarationWithType *clone() const override = 0;
    109         virtual DeclarationWithType *acceptMutator( Mutator &m )  override = 0;
     107        virtual DeclarationWithType * clone() const override = 0;
     108        virtual DeclarationWithType * acceptMutator( Mutator & m )  override = 0;
    110109
    111110        virtual Type * get_type() const = 0;
     
    119118        typedef DeclarationWithType Parent;
    120119  public:
    121         Type *type;
    122         Initializer *init;
    123         Expression *bitfieldWidth;
    124 
    125         ObjectDecl( const std::string &name, Type::StorageClasses scs, LinkageSpec::Spec linkage, Expression *bitfieldWidth, Type *type, Initializer *init,
     120        Type * type;
     121        Initializer * init;
     122        Expression * bitfieldWidth;
     123
     124        ObjectDecl( const std::string & name, Type::StorageClasses scs, LinkageSpec::Spec linkage, Expression * bitfieldWidth, Type * type, Initializer * init,
    126125                                const std::list< Attribute * > attributes = std::list< Attribute * >(), Type::FuncSpecifiers fs = Type::FuncSpecifiers() );
    127         ObjectDecl( const ObjectDecl &other );
     126        ObjectDecl( const ObjectDecl & other );
    128127        virtual ~ObjectDecl();
    129128
    130129        virtual Type * get_type() const override { return type; }
    131         virtual void set_type(Type *newType) override { type = newType; }
    132 
    133         Initializer *get_init() const { return init; }
    134         void set_init( Initializer *newValue ) { init = newValue; }
    135 
    136         Expression *get_bitfieldWidth() const { return bitfieldWidth; }
    137         void set_bitfieldWidth( Expression *newValue ) { bitfieldWidth = newValue; }
     130        virtual void set_type(Type * newType) override { type = newType; }
     131
     132        Initializer * get_init() const { return init; }
     133        void set_init( Initializer * newValue ) { init = newValue; }
     134
     135        Expression * get_bitfieldWidth() const { return bitfieldWidth; }
     136        void set_bitfieldWidth( Expression * newValue ) { bitfieldWidth = newValue; }
    138137
    139138        static ObjectDecl * newObject( const std::string & name, Type * type, Initializer * init );
    140139
    141         virtual ObjectDecl *clone() const override { return new ObjectDecl( *this ); }
    142         virtual void accept( Visitor & v ) override { v.visit( this ); }
    143         virtual void accept( Visitor & v ) const override { v.visit( this ); }
    144         virtual DeclarationWithType *acceptMutator( Mutator &m )  override { return m.mutate( this ); }
    145         virtual void print( std::ostream &os, Indenter indent = {} ) const override;
    146         virtual void printShort( std::ostream &os, Indenter indent = {} ) const override;
     140        virtual ObjectDecl * clone() const override { return new ObjectDecl( *this ); }
     141        virtual void accept( Visitor & v ) override { v.visit( this ); }
     142        virtual void accept( Visitor & v ) const override { v.visit( this ); }
     143        virtual DeclarationWithType * acceptMutator( Mutator & m )  override { return m.mutate( this ); }
     144        virtual void print( std::ostream & os, Indenter indent = {} ) const override;
     145        virtual void printShort( std::ostream & os, Indenter indent = {} ) const override;
    147146};
    148147
     
    150149        typedef DeclarationWithType Parent;
    151150  public:
    152         FunctionType *type;
    153         CompoundStmt *statements;
     151        FunctionType * type;
     152        CompoundStmt * statements;
    154153        std::list< Expression * > withExprs;
    155154
    156         FunctionDecl( const std::string &name, Type::StorageClasses scs, LinkageSpec::Spec linkage, FunctionType *type, CompoundStmt *statements,
     155        FunctionDecl( const std::string & name, Type::StorageClasses scs, LinkageSpec::Spec linkage, FunctionType * type, CompoundStmt * statements,
    157156                                  const std::list< Attribute * > attributes = std::list< Attribute * >(), Type::FuncSpecifiers fs = Type::FuncSpecifiers() );
    158         FunctionDecl( const FunctionDecl &other );
     157        FunctionDecl( const FunctionDecl & other );
    159158        virtual ~FunctionDecl();
    160159
     
    163162
    164163        FunctionType * get_functionType() const { return type; }
    165         void set_functionType( FunctionType *newValue ) { type = newValue; }
    166         CompoundStmt *get_statements() const { return statements; }
    167         void set_statements( CompoundStmt *newValue ) { statements = newValue; }
     164        void set_functionType( FunctionType * newValue ) { type = newValue; }
     165        CompoundStmt * get_statements() const { return statements; }
     166        void set_statements( CompoundStmt * newValue ) { statements = newValue; }
    168167        bool has_body() const { return NULL != statements; }
    169168
    170169        static FunctionDecl * newFunction( const std::string & name, FunctionType * type, CompoundStmt * statements );
    171170
    172         virtual FunctionDecl *clone() const override { return new FunctionDecl( *this ); }
    173         virtual void accept( Visitor & v ) override { v.visit( this ); }
    174         virtual void accept( Visitor & v ) const override { v.visit( this ); }
    175         virtual DeclarationWithType *acceptMutator( Mutator &m )  override { return m.mutate( this ); }
    176         virtual void print( std::ostream &os, Indenter indent = {} ) const override;
    177         virtual void printShort( std::ostream &os, Indenter indent = {} ) const override;
     171        virtual FunctionDecl * clone() const override { return new FunctionDecl( *this ); }
     172        virtual void accept( Visitor & v ) override { v.visit( this ); }
     173        virtual void accept( Visitor & v ) const override { v.visit( this ); }
     174        virtual DeclarationWithType * acceptMutator( Mutator & m )  override { return m.mutate( this ); }
     175        virtual void print( std::ostream & os, Indenter indent = {} ) const override;
     176        virtual void printShort( std::ostream & os, Indenter indent = {} ) const override;
    178177};
    179178
     
    181180        typedef Declaration Parent;
    182181  public:
    183         Type *base;
    184         std::list< TypeDecl* > parameters;
    185         std::list< DeclarationWithType* > assertions;
    186 
    187         NamedTypeDecl( const std::string &name, Type::StorageClasses scs, Type *type );
    188         NamedTypeDecl( const NamedTypeDecl &other );
     182        Type * base;
     183        std::list< TypeDecl * > parameters;
     184        std::list< DeclarationWithType * > assertions;
     185
     186        NamedTypeDecl( const std::string & name, Type::StorageClasses scs, Type * type );
     187        NamedTypeDecl( const NamedTypeDecl & other );
    189188        virtual ~NamedTypeDecl();
    190189
    191         Type *get_base() const { return base; }
    192         void set_base( Type *newValue ) { base = newValue; }
    193         std::list< TypeDecl* >& get_parameters() { return parameters; }
    194         std::list< DeclarationWithType* >& get_assertions() { return assertions; }
    195 
    196         virtual std::string typeString() const = 0;
    197 
    198         virtual NamedTypeDecl *clone() const override = 0;
    199         virtual void print( std::ostream &os, Indenter indent = {} ) const override;
    200         virtual void printShort( std::ostream &os, Indenter indent = {} ) const override;
     190        Type * get_base() const { return base; }
     191        void set_base( Type * newValue ) { base = newValue; }
     192        std::list< TypeDecl* > & get_parameters() { return parameters; }
     193        std::list< DeclarationWithType * >& get_assertions() { return assertions; }
     194
     195        virtual const char * typeString() const = 0;
     196
     197        virtual NamedTypeDecl * clone() const override = 0;
     198        virtual void print( std::ostream & os, Indenter indent = {} ) const override;
     199        virtual void printShort( std::ostream & os, Indenter indent = {} ) const override;
    201200};
    202201
     
    204203        typedef NamedTypeDecl Parent;
    205204  public:
    206         enum Kind { Dtype, Ftype, Ttype, NUMBER_OF_KINDS };
    207 
     205        enum Kind { Dtype, Otype, Ftype, Ttype, NUMBER_OF_KINDS };
     206
     207        Kind kind;
     208        bool sized;
    208209        Type * init;
    209         bool sized;
    210210
    211211        /// Data extracted from a type decl
    212212        struct Data {
    213                 TypeDecl::Kind kind;
     213                Kind kind;
    214214                bool isComplete;
    215215
    216                 Data() : kind( (TypeDecl::Kind)-1 ), isComplete( false ) {}
    217                 Data( TypeDecl * typeDecl ) : Data( typeDecl->get_kind(), typeDecl->isComplete() ) {}
     216                Data() : kind( NUMBER_OF_KINDS ), isComplete( false ) {}
     217                Data( const TypeDecl * typeDecl ) : Data( typeDecl->get_kind(), typeDecl->isComplete() ) {}
    218218                Data( Kind kind, bool isComplete ) : kind( kind ), isComplete( isComplete ) {}
    219                 Data( const Data& d1, const Data& d2 )
    220                 : kind( d1.kind ), isComplete ( d1.isComplete || d2.isComplete ) {}
    221 
    222                 bool operator==(const Data & other) const { return kind == other.kind && isComplete == other.isComplete; }
    223                 bool operator!=(const Data & other) const { return !(*this == other);}
     219                Data( const Data & d1, const Data & d2 )
     220                        : kind( d1.kind ), isComplete( d1.isComplete || d2.isComplete ) {}
     221
     222                bool operator==( const Data & other ) const { return kind == other.kind && isComplete == other.isComplete; }
     223                bool operator!=( const Data & other ) const { return !(*this == other);}
    224224        };
    225225
    226         TypeDecl( const std::string &name, Type::StorageClasses scs, Type *type, Kind kind, bool sized, Type * init = nullptr );
    227         TypeDecl( const TypeDecl &other );
     226        TypeDecl( const std::string & name, Type::StorageClasses scs, Type * type, Kind kind, bool sized, Type * init = nullptr );
     227        TypeDecl( const TypeDecl & other );
    228228        virtual ~TypeDecl();
    229229
     
    237237        TypeDecl * set_sized( bool newValue ) { sized = newValue; return this; }
    238238
    239         virtual std::string typeString() const override;
    240         virtual std::string genTypeString() const;
    241 
    242         virtual TypeDecl *clone() const override { return new TypeDecl( *this ); }
    243         virtual void accept( Visitor & v ) override { v.visit( this ); }
    244         virtual void accept( Visitor & v ) const override { v.visit( this ); }
    245         virtual Declaration *acceptMutator( Mutator &m )  override { return m.mutate( this ); }
    246         virtual void print( std::ostream &os, Indenter indent = {} ) const override;
    247 
    248         Kind kind;
     239        virtual const char * typeString() const override;
     240        virtual const char * genTypeString() const;
     241
     242        virtual TypeDecl * clone() const override { return new TypeDecl( *this ); }
     243        virtual void accept( Visitor & v ) override { v.visit( this ); }
     244        virtual void accept( Visitor & v ) const override { v.visit( this ); }
     245        virtual Declaration * acceptMutator( Mutator & m )  override { return m.mutate( this ); }
     246        virtual void print( std::ostream & os, Indenter indent = {} ) const override;
    249247};
    250248
     
    252250        typedef NamedTypeDecl Parent;
    253251  public:
    254         TypedefDecl( const std::string &name, CodeLocation location, Type::StorageClasses scs, Type *type, LinkageSpec::Spec spec = LinkageSpec::Cforall )
     252        TypedefDecl( const std::string & name, CodeLocation location, Type::StorageClasses scs, Type * type, LinkageSpec::Spec spec = LinkageSpec::Cforall )
    255253                : Parent( name, scs, type ) { set_linkage( spec ); this->location = location; }
    256254
    257         TypedefDecl( const TypedefDecl &other ) : Parent( other ) {}
    258 
    259         virtual std::string typeString() const override;
    260 
    261         virtual TypedefDecl *clone() const override { return new TypedefDecl( *this ); }
    262         virtual void accept( Visitor & v ) override { v.visit( this ); }
    263         virtual void accept( Visitor & v ) const override { v.visit( this ); }
    264         virtual Declaration *acceptMutator( Mutator &m )  override { return m.mutate( this ); }
     255        TypedefDecl( const TypedefDecl & other ) : Parent( other ) {}
     256
     257        virtual const char * typeString() const override;
     258
     259        virtual TypedefDecl * clone() const override { return new TypedefDecl( *this ); }
     260        virtual void accept( Visitor & v ) override { v.visit( this ); }
     261        virtual void accept( Visitor & v ) const override { v.visit( this ); }
     262        virtual Declaration * acceptMutator( Mutator & m )  override { return m.mutate( this ); }
    265263  private:
    266264};
     
    269267        typedef Declaration Parent;
    270268  public:
     269        enum Aggregate { Struct, Union, Enum, Exception, Trait, Generator, Coroutine, Monitor, Thread, NoAggregate };
     270        static const char * aggrString( Aggregate aggr );
     271
    271272        std::list<Declaration*> members;
    272273        std::list<TypeDecl*> parameters;
     
    275276        AggregateDecl * parent = nullptr;
    276277
    277         AggregateDecl( const std::string &name, const std::list< Attribute * > & attributes = std::list< class Attribute * >(), LinkageSpec::Spec linkage = LinkageSpec::Cforall );
    278         AggregateDecl( const AggregateDecl &other );
     278        AggregateDecl( const std::string & name, const std::list< Attribute * > & attributes = std::list< class Attribute * >(), LinkageSpec::Spec linkage = LinkageSpec::Cforall );
     279        AggregateDecl( const AggregateDecl & other );
    279280        virtual ~AggregateDecl();
    280281
     
    288289        AggregateDecl * set_body( bool body ) { AggregateDecl::body = body; return this; }
    289290
    290         virtual void print( std::ostream &os, Indenter indent = {} ) const override final;
    291         virtual void printShort( std::ostream &os, Indenter indent = {} ) const override;
     291        virtual void print( std::ostream & os, Indenter indent = {} ) const override final;
     292        virtual void printShort( std::ostream & os, Indenter indent = {} ) const override;
    292293  protected:
    293         virtual std::string typeString() const = 0;
     294        virtual const char * typeString() const = 0;
    294295};
    295296
     
    297298        typedef AggregateDecl Parent;
    298299  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 ) {}
    300         StructDecl( const StructDecl &other ) : Parent( other ), kind( other.kind ) {}
    301 
    302         bool is_coroutine() { return kind == DeclarationNode::Coroutine; }
    303         bool is_monitor() { return kind == DeclarationNode::Monitor; }
    304         bool is_thread() { return kind == DeclarationNode::Thread; }
    305 
    306         virtual StructDecl *clone() const override { return new StructDecl( *this ); }
    307         virtual void accept( Visitor & v ) override { v.visit( this ); }
    308         virtual void accept( Visitor & v ) const override { v.visit( this ); }
    309         virtual Declaration *acceptMutator( Mutator &m )  override { return m.mutate( this ); }
    310         DeclarationNode::Aggregate kind;
    311   private:
    312         virtual std::string typeString() const override;
     300        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 ) {}
     301        StructDecl( const StructDecl & other ) : Parent( other ), kind( other.kind ) {}
     302
     303        bool is_coroutine() { return kind == Coroutine; }
     304        bool is_generator() { return kind == Generator; }
     305        bool is_monitor  () { return kind == Monitor  ; }
     306        bool is_thread   () { return kind == Thread   ; }
     307
     308        virtual StructDecl * clone() const override { return new StructDecl( *this ); }
     309        virtual void accept( Visitor & v ) override { v.visit( this ); }
     310        virtual void accept( Visitor & v ) const override { v.visit( this ); }
     311        virtual Declaration * acceptMutator( Mutator & m )  override { return m.mutate( this ); }
     312        Aggregate kind;
     313  private:
     314        virtual const char * typeString() const override;
    313315};
    314316
     
    316318        typedef AggregateDecl Parent;
    317319  public:
    318         UnionDecl( const std::string &name, const std::list< Attribute * > & attributes = std::list< class Attribute * >(), LinkageSpec::Spec linkage = LinkageSpec::Cforall ) : Parent( name, attributes, linkage ) {}
    319         UnionDecl( const UnionDecl &other ) : Parent( other ) {}
    320 
    321         virtual UnionDecl *clone() const override { return new UnionDecl( *this ); }
    322         virtual void accept( Visitor & v ) override { v.visit( this ); }
    323         virtual void accept( Visitor & v ) const override { v.visit( this ); }
    324         virtual Declaration *acceptMutator( Mutator &m )  override { return m.mutate( this ); }
    325   private:
    326         virtual std::string typeString() const override;
     320        UnionDecl( const std::string & name, const std::list< Attribute * > & attributes = std::list< class Attribute * >(), LinkageSpec::Spec linkage = LinkageSpec::Cforall ) : Parent( name, attributes, linkage ) {}
     321        UnionDecl( const UnionDecl & other ) : Parent( other ) {}
     322
     323        virtual UnionDecl * clone() const override { return new UnionDecl( *this ); }
     324        virtual void accept( Visitor & v ) override { v.visit( this ); }
     325        virtual void accept( Visitor & v ) const override { v.visit( this ); }
     326        virtual Declaration * acceptMutator( Mutator & m )  override { return m.mutate( this ); }
     327  private:
     328        virtual const char * typeString() const override;
    327329};
    328330
     
    330332        typedef AggregateDecl Parent;
    331333  public:
    332         EnumDecl( const std::string &name, const std::list< Attribute * > & attributes = std::list< class Attribute * >(), LinkageSpec::Spec linkage = LinkageSpec::Cforall ) : Parent( name, attributes, linkage ) {}
    333         EnumDecl( const EnumDecl &other ) : Parent( other ) {}
     334        EnumDecl( const std::string & name, const std::list< Attribute * > & attributes = std::list< class Attribute * >(), LinkageSpec::Spec linkage = LinkageSpec::Cforall ) : Parent( name, attributes, linkage ) {}
     335        EnumDecl( const EnumDecl & other ) : Parent( other ) {}
    334336
    335337        bool valueOf( Declaration * enumerator, long long int & value );
    336338
    337         virtual EnumDecl *clone() const override { return new EnumDecl( *this ); }
    338         virtual void accept( Visitor & v ) override { v.visit( this ); }
    339         virtual void accept( Visitor & v ) const override { v.visit( this ); }
    340         virtual Declaration *acceptMutator( Mutator &m )  override { return m.mutate( this ); }
     339        virtual EnumDecl * clone() const override { return new EnumDecl( *this ); }
     340        virtual void accept( Visitor & v ) override { v.visit( this ); }
     341        virtual void accept( Visitor & v ) const override { v.visit( this ); }
     342        virtual Declaration * acceptMutator( Mutator & m )  override { return m.mutate( this ); }
    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
     
    347349        typedef AggregateDecl Parent;
    348350  public:
    349         TraitDecl( const std::string &name, const std::list< Attribute * > & attributes, LinkageSpec::Spec linkage ) : Parent( name, attributes, linkage ) {
     351        TraitDecl( const std::string & name, const std::list< Attribute * > & attributes, LinkageSpec::Spec linkage ) : Parent( name, attributes, linkage ) {
    350352                assertf( attributes.empty(), "attribute unsupported for traits" );
    351353        }
    352         TraitDecl( const TraitDecl &other ) : Parent( other ) {}
    353 
    354         virtual TraitDecl *clone() const override { return new TraitDecl( *this ); }
    355         virtual void accept( Visitor & v ) override { v.visit( this ); }
    356         virtual void accept( Visitor & v ) const override { v.visit( this ); }
    357         virtual Declaration *acceptMutator( Mutator &m )  override { return m.mutate( this ); }
    358   private:
    359         virtual std::string typeString() const override;
     354        TraitDecl( const TraitDecl & other ) : Parent( other ) {}
     355
     356        virtual TraitDecl * clone() const override { return new TraitDecl( *this ); }
     357        virtual void accept( Visitor & v ) override { v.visit( this ); }
     358        virtual void accept( Visitor & v ) const override { v.visit( this ); }
     359        virtual Declaration * acceptMutator( Mutator & m )  override { return m.mutate( this ); }
     360  private:
     361        virtual const char * typeString() const override;
    360362};
    361363
     
    379381class AsmDecl : public Declaration {
    380382  public:
    381         AsmStmt *stmt;
    382 
    383         AsmDecl( AsmStmt *stmt );
    384         AsmDecl( const AsmDecl &other );
     383        AsmStmt * stmt;
     384
     385        AsmDecl( AsmStmt * stmt );
     386        AsmDecl( const AsmDecl & other );
    385387        virtual ~AsmDecl();
    386388
    387         AsmStmt *get_stmt() { return stmt; }
    388         void set_stmt( AsmStmt *newValue ) { stmt = newValue; }
    389 
    390         virtual AsmDecl *clone() const override { return new AsmDecl( *this ); }
    391         virtual void accept( Visitor & v ) override { v.visit( this ); }
    392         virtual void accept( Visitor & v ) const override { v.visit( this ); }
    393         virtual AsmDecl *acceptMutator( Mutator &m )  override { return m.mutate( this ); }
    394         virtual void print( std::ostream &os, Indenter indent = {} ) const override;
    395         virtual void printShort( std::ostream &os, Indenter indent = {} ) const override;
     389        AsmStmt * get_stmt() { return stmt; }
     390        void set_stmt( AsmStmt * newValue ) { stmt = newValue; }
     391
     392        virtual AsmDecl * clone() const override { return new AsmDecl( *this ); }
     393        virtual void accept( Visitor & v ) override { v.visit( this ); }
     394        virtual void accept( Visitor & v ) const override { v.visit( this ); }
     395        virtual AsmDecl * acceptMutator( Mutator & m )  override { return m.mutate( this ); }
     396        virtual void print( std::ostream & os, Indenter indent = {} ) const override;
     397        virtual void printShort( std::ostream & os, Indenter indent = {} ) const override;
    396398};
    397399
     
    408410        virtual void accept( Visitor & v ) override { v.visit( this ); }
    409411        virtual void accept( Visitor & v ) const override { v.visit( this ); }
    410         virtual StaticAssertDecl * acceptMutator( Mutator &m )  override { return m.mutate( this ); }
    411         virtual void print( std::ostream &os, Indenter indent = {} ) const override;
    412         virtual void printShort( std::ostream &os, Indenter indent = {} ) const override;
     412        virtual StaticAssertDecl * acceptMutator( Mutator & m )  override { return m.mutate( this ); }
     413        virtual void print( std::ostream & os, Indenter indent = {} ) const override;
     414        virtual void printShort( std::ostream & os, Indenter indent = {} ) const override;
    413415};
    414416
  • src/SynTree/DeclarationWithType.cc

    r71d6bd8 r7030dab  
    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:34:35 2017
    13 // Update Count     : 25
     12// Last Modified On : Fri Dec 13 23:45:16 2019
     13// Update Count     : 26
    1414//
    1515
     
    2020#include "Common/utility.h"      // for cloneAll, deleteAll, maybeClone
    2121#include "Declaration.h"         // for DeclarationWithType, Declaration
    22 #include "Parser/LinkageSpec.h"  // for Spec
    23 #include "SynTree/Expression.h"  // for ConstantExpr
     22#include "LinkageSpec.h"         // for Spec
     23#include "Expression.h"          // for ConstantExpr
    2424#include "Type.h"                // for Type, Type::FuncSpecifiers, Type::St...
    2525
  • src/SynTree/Expression.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 : 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

    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 : 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         } target;
    234 
    235         KeywordCastExpr( Expression * arg, Target target );
     232        struct Concrete {
     233                std::string field;
     234                std::string getter;
     235        };
     236        AggregateDecl::Aggregate target;
     237        Concrete concrete_target;
     238
     239        KeywordCastExpr( Expression * arg, AggregateDecl::Aggregate target );
    236240        KeywordCastExpr( const KeywordCastExpr & other );
    237241        virtual ~KeywordCastExpr();
    238242
    239         const std::string & targetString() const;
     243        const char * targetString() const;
    240244
    241245        virtual KeywordCastExpr * clone() const override { return new KeywordCastExpr( * this ); }
  • src/SynTree/FunctionDecl.cc

    r71d6bd8 r7030dab  
    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 : Mon Dec 16 15:11:20 2019
     13// Update Count     : 77
    1414//
    1515
     
    2323#include "Common/utility.h"      // for maybeClone, printAll
    2424#include "Declaration.h"         // for FunctionDecl, FunctionDecl::Parent
    25 #include "Parser/LinkageSpec.h"  // for Spec, linkageName, Cforall
     25#include "Expression.h"
     26#include "LinkageSpec.h"         // for Spec, linkageName, Cforall
    2627#include "Statement.h"           // for CompoundStmt
    2728#include "Type.h"                // for Type, FunctionType, Type::FuncSpecif...
     
    7273        } // if
    7374        if ( linkage != LinkageSpec::Cforall ) {
    74                 os << LinkageSpec::linkageName( linkage ) << " ";
     75                os << LinkageSpec::name( linkage ) << " ";
    7576        } // if
    7677
  • src/SynTree/LinkageSpec.h

    r71d6bd8 r7030dab  
    99// Author           : Rodolfo G. Esteves
    1010// Created On       : Sat May 16 13:24:28 2015
    11 // Last Modified By : Peter A. Buhr
    12 // Last Modified On : Wed Jul 10 16:02:34 2019
    13 // Update Count     : 18
     11// Last Modified By : Andrew Beach
     12// Last Modified On : Mon Mar  2 16:13:00 2020
     13// Update Count     : 21
    1414//
    1515
     
    1818#include <string>
    1919
    20 #include "Common/CodeLocation.h"
     20struct CodeLocation;
    2121
    2222namespace LinkageSpec {
    23         // All linkage specs are some combination of these flags:
    24         enum { Mangle = 1 << 0, Generate = 1 << 1, Overrideable = 1 << 2, Builtin = 1 << 3, GccBuiltin = 1 << 4, NoOfSpecs = 1 << 5, };
     23        // Bitflags for linkage specifiers
     24        enum {
     25                Mangle = 1 << 0,
     26                Generate = 1 << 1,
     27                Overrideable = 1 << 2,
     28                Builtin = 1 << 3,
     29                GccBuiltin = 1 << 4,
     30        };
    2531
     32        // Bitflag type for storage classes
    2633        union Spec {
    2734                unsigned int val;
     
    4249
    4350
    44         Spec linkageUpdate( CodeLocation location, Spec old_spec, const std::string * cmd );
    45         /* If cmd = "C" returns a Spec that is old_spec with is_mangled = false
    46          * If cmd = "Cforall" returns old_spec Spec with is_mangled = true
    47          */
     51        Spec update( CodeLocation location, Spec spec, const std::string * cmd );
     52        // If cmd = "C" returns a Spec that is old_spec with is_mangled = false
     53        // If cmd = "Cforall" returns old_spec Spec with is_mangled = true
    4854
    49         std::string linkageName( Spec );
     55        std::string name( Spec );
    5056
    5157        // To Update: LinkageSpec::isXyz( cur_spec ) -> cur_spec.is_xyz
  • src/SynTree/Mutator.h

    r71d6bd8 r7030dab  
    5151        virtual Statement * mutate( CatchStmt * catchStmt ) = 0;
    5252        virtual Statement * mutate( FinallyStmt * catchStmt ) = 0;
     53        virtual Statement * mutate( SuspendStmt * suspendStmt ) = 0;
    5354        virtual Statement * mutate( WaitForStmt * waitforStmt ) = 0;
    5455        virtual Declaration * mutate( WithStmt * withStmt ) = 0;
  • src/SynTree/NamedTypeDecl.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 13:28:00 2017
    13 // Update Count     : 14
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Mon Dec 16 15:11:40 2019
     13// Update Count     : 17
    1414//
    1515
     
    2020#include "Common/utility.h"      // for printAll, cloneAll, deleteAll, maybe...
    2121#include "Declaration.h"         // for NamedTypeDecl, DeclarationWithType
    22 #include "Parser/LinkageSpec.h"  // for Spec, Cforall, linkageName
     22#include "LinkageSpec.h"         // for Spec, Cforall, linkageName
    2323#include "Type.h"                // for Type, Type::StorageClasses
    2424
     
    4444
    4545        if ( linkage != LinkageSpec::Cforall ) {
    46                 os << LinkageSpec::linkageName( linkage ) << " ";
     46                os << LinkageSpec::name( linkage ) << " ";
    4747        } // if
    4848        get_storageClasses().print( os );
     
    7878}
    7979
    80 std::string TypedefDecl::typeString() const { return "typedef"; }
     80const char * TypedefDecl::typeString() const { return "typedef"; }
    8181
    8282// Local Variables: //
  • src/SynTree/ObjectDecl.cc

    r71d6bd8 r7030dab  
    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:34:27 2017
    13 // Update Count     : 59
     12// Last Modified On : Mon Dec 16 15:12:03 2019
     13// Update Count     : 61
    1414//
    1515
     
    2323#include "Expression.h"          // for Expression
    2424#include "Initializer.h"         // for Initializer
    25 #include "Parser/LinkageSpec.h"  // for Spec, linkageName, Cforall
     25#include "LinkageSpec.h"         // for Spec, linkageName, Cforall
    2626#include "Type.h"                // for Type, Type::StorageClasses, Type::Fu...
    2727
     
    4848
    4949        if ( linkage != LinkageSpec::Cforall ) {
    50                 os << LinkageSpec::linkageName( linkage ) << " ";
     50                os << LinkageSpec::name( linkage ) << " ";
    5151        } // if
    5252
  • src/SynTree/Statement.cc

    r71d6bd8 r7030dab  
    99// Author           : Richard C. Bilson
    1010// Created On       : Mon May 18 07:44:20 2015
    11 // Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sun Sep  3 20:46:44 2017
    13 // Update Count     : 68
     11// Last Modified By : Andrew Beach
     12// Last Modified On : Mon Jan 20 16:03:00 2020
     13// Update Count     : 71
    1414//
    1515
     
    4646Statement::~Statement() {}
    4747
    48 ExprStmt::ExprStmt( Expression *expr ) : Statement(), expr( expr ) {}
    49 
    50 ExprStmt::ExprStmt( const ExprStmt &other ) : Statement( other ), expr( maybeClone( other.expr ) ) {}
     48ExprStmt::ExprStmt( Expression * expr ) : Statement(), expr( expr ) {}
     49
     50ExprStmt::ExprStmt( const ExprStmt & other ) : Statement( other ), expr( maybeClone( other.expr ) ) {}
    5151
    5252ExprStmt::~ExprStmt() {
     
    5454}
    5555
    56 void ExprStmt::print( std::ostream &os, Indenter indent ) const {
     56void ExprStmt::print( std::ostream & os, Indenter indent ) const {
    5757        os << "Expression Statement:" << endl << indent+1;
    5858        expr->print( os, indent+1 );
     
    6060
    6161
    62 AsmStmt::AsmStmt( bool voltile, Expression *instruction, std::list<Expression *> output, std::list<Expression *> input, std::list<ConstantExpr *> clobber, std::list<Label> gotolabels ) : Statement(), voltile( voltile ), instruction( instruction ), output( output ), input( input ), clobber( clobber ), gotolabels( gotolabels ) {}
     62AsmStmt::AsmStmt( bool voltile, Expression * instruction, std::list<Expression *> output, std::list<Expression *> input, std::list<ConstantExpr *> clobber, std::list<Label> gotolabels ) : Statement(), voltile( voltile ), instruction( instruction ), output( output ), input( input ), clobber( clobber ), gotolabels( gotolabels ) {}
    6363
    6464AsmStmt::AsmStmt( const AsmStmt & other ) : Statement( other ), voltile( other.voltile ), instruction( maybeClone( other.instruction ) ), gotolabels( other.gotolabels ) {
     
    7575}
    7676
    77 void AsmStmt::print( std::ostream &os, Indenter indent ) const {
     77void AsmStmt::print( std::ostream & os, Indenter indent ) const {
    7878        os << "Assembler Statement:" << endl;
    7979        os << indent+1 << "instruction: " << endl << indent;
     
    9696DirectiveStmt::DirectiveStmt( const std::string & directive ) : Statement(), directive( directive ) {}
    9797
    98 void DirectiveStmt::print( std::ostream &os, Indenter ) const {
     98void DirectiveStmt::print( std::ostream & os, Indenter ) const {
    9999        os << "GCC Directive:" << directive << endl;
    100100}
    101101
    102102
    103 const char *BranchStmt::brType[] = { "Goto", "Break", "Continue" };
     103const char * BranchStmt::brType[] = {
     104        "Goto", "Break", "Continue", "Fall Through", "Fall Through Default",
     105};
    104106
    105107BranchStmt::BranchStmt( Label target, Type type ) throw ( SemanticErrorException ) :
     
    111113}
    112114
    113 BranchStmt::BranchStmt( Expression *computedTarget, Type type ) throw ( SemanticErrorException ) :
     115BranchStmt::BranchStmt( Expression * computedTarget, Type type ) throw ( SemanticErrorException ) :
    114116        Statement(), computedTarget( computedTarget ), type( type ) {
    115117        if ( type != BranchStmt::Goto || computedTarget == nullptr ) {
     
    118120}
    119121
    120 void BranchStmt::print( std::ostream &os, Indenter indent ) const {
     122void BranchStmt::print( std::ostream & os, Indenter indent ) const {
     123        assert(type < 5);
    121124        os << "Branch (" << brType[type] << ")" << endl ;
    122125        if ( target != "" ) os << indent+1 << "with target: " << target << endl;
     
    125128}
    126129
    127 ReturnStmt::ReturnStmt( Expression *expr ) : Statement(), expr( expr ) {}
     130ReturnStmt::ReturnStmt( Expression * expr ) : Statement(), expr( expr ) {}
    128131
    129132ReturnStmt::ReturnStmt( const ReturnStmt & other ) : Statement( other ), expr( maybeClone( other.expr ) ) {}
     
    133136}
    134137
    135 void ReturnStmt::print( std::ostream &os, Indenter indent ) const {
     138void ReturnStmt::print( std::ostream & os, Indenter indent ) const {
    136139        os << "Return Statement, returning: ";
    137140        if ( expr != nullptr ) {
     
    142145}
    143146
    144 IfStmt::IfStmt( Expression *condition, Statement *thenPart, Statement *elsePart, std::list<Statement *> initialization ):
     147IfStmt::IfStmt( Expression * condition, Statement * thenPart, Statement * elsePart, std::list<Statement *> initialization ):
    145148        Statement(), condition( condition ), thenPart( thenPart ), elsePart( elsePart ), initialization( initialization ) {}
    146149
     
    157160}
    158161
    159 void IfStmt::print( std::ostream &os, Indenter indent ) const {
     162void IfStmt::print( std::ostream & os, Indenter indent ) const {
    160163        os << "If on condition: " << endl;
    161164        os << indent+1;
     
    176179        thenPart->print( os, indent+1 );
    177180
    178         if ( elsePart != 0 ) {
     181        if ( elsePart != nullptr ) {
    179182                os << indent << "... else: " << endl;
    180183                os << indent+1;
     
    183186}
    184187
    185 SwitchStmt::SwitchStmt( Expression * condition, const std::list<Statement *> &statements ):
     188SwitchStmt::SwitchStmt( Expression * condition, const std::list<Statement *> & statements ):
    186189        Statement(), condition( condition ), statements( statements ) {
    187190}
     
    198201}
    199202
    200 void SwitchStmt::print( std::ostream &os, Indenter indent ) const {
     203void SwitchStmt::print( std::ostream & os, Indenter indent ) const {
    201204        os << "Switch on condition: ";
    202205        condition->print( os );
     
    208211}
    209212
    210 CaseStmt::CaseStmt( Expression *condition, const std::list<Statement *> &statements, bool deflt ) throw ( SemanticErrorException ) :
     213CaseStmt::CaseStmt( Expression * condition, const std::list<Statement *> & statements, bool deflt ) throw ( SemanticErrorException ) :
    211214        Statement(), condition( condition ), stmts( statements ), _isDefault( deflt ) {
    212         if ( isDefault() && condition != 0 ) SemanticError( condition, "default case with condition: " );
     215        if ( isDefault() && condition != nullptr ) SemanticError( condition, "default case with condition: " );
    213216}
    214217
     
    229232}
    230233
    231 void CaseStmt::print( std::ostream &os, Indenter indent ) const {
     234void CaseStmt::print( std::ostream & os, Indenter indent ) const {
    232235        if ( isDefault() ) os << indent << "Default ";
    233236        else {
     
    243246}
    244247
    245 WhileStmt::WhileStmt( Expression *condition, Statement *body, std::list< Statement * > & initialization, bool isDoWhile ):
     248WhileStmt::WhileStmt( Expression * condition, Statement * body, std::list< Statement * > & initialization, bool isDoWhile ):
    246249        Statement(), condition( condition), body( body), initialization( initialization ), isDoWhile( isDoWhile) {
    247250}
     
    256259}
    257260
    258 void WhileStmt::print( std::ostream &os, Indenter indent ) const {
     261void WhileStmt::print( std::ostream & os, Indenter indent ) const {
    259262        os << "While on condition: " << endl ;
    260263        condition->print( os, indent+1 );
     
    262265        os << indent << "... with body: " << endl;
    263266
    264         if ( body != 0 ) body->print( os, indent+1 );
    265 }
    266 
    267 ForStmt::ForStmt( std::list<Statement *> initialization, Expression *condition, Expression *increment, Statement *body ):
     267        if ( body != nullptr ) body->print( os, indent+1 );
     268}
     269
     270ForStmt::ForStmt( std::list<Statement *> initialization, Expression * condition, Expression * increment, Statement * body ):
    268271        Statement(), initialization( initialization ), condition( condition ), increment( increment ), body( body ) {
    269272}
     
    282285}
    283286
    284 void ForStmt::print( std::ostream &os, Indenter indent ) const {
     287void ForStmt::print( std::ostream & os, Indenter indent ) const {
    285288        Statement::print( os, indent ); // print labels
    286289
     
    305308        }
    306309
    307         if ( body != 0 ) {
     310        if ( body != nullptr ) {
    308311                os << "\n" << indent << "... with body: \n" << indent+1;
    309312                body->print( os, indent+1 );
     
    317320}
    318321
    319 ThrowStmt::ThrowStmt( const ThrowStmt &other ) :
     322ThrowStmt::ThrowStmt( const ThrowStmt & other ) :
    320323        Statement ( other ), kind( other.kind ), expr( maybeClone( other.expr ) ), target( maybeClone( other.target ) ) {
    321324}
     
    326329}
    327330
    328 void ThrowStmt::print( std::ostream &os, Indenter indent) const {
     331void ThrowStmt::print( std::ostream & os, Indenter indent) const {
    329332        if ( target ) os << "Non-Local ";
    330333        os << "Throw Statement, raising: ";
     
    336339}
    337340
    338 TryStmt::TryStmt( CompoundStmt *tryBlock, std::list<CatchStmt *> &handlers, FinallyStmt *finallyBlock ) :
     341TryStmt::TryStmt( CompoundStmt * tryBlock, std::list<CatchStmt *> & handlers, FinallyStmt * finallyBlock ) :
    339342        Statement(), block( tryBlock ),  handlers( handlers ), finallyBlock( finallyBlock ) {
    340343}
    341344
    342 TryStmt::TryStmt( const TryStmt &other ) : Statement( other ), block( maybeClone( other.block ) ), finallyBlock( maybeClone( other.finallyBlock ) ) {
     345TryStmt::TryStmt( const TryStmt & other ) : Statement( other ), block( maybeClone( other.block ) ), finallyBlock( maybeClone( other.finallyBlock ) ) {
    343346        cloneAll( other.handlers, handlers );
    344347}
     
    350353}
    351354
    352 void TryStmt::print( std::ostream &os, Indenter indent ) const {
     355void TryStmt::print( std::ostream & os, Indenter indent ) const {
    353356        os << "Try Statement" << endl;
    354357        os << indent << "... with block:" << endl << indent+1;
     
    363366
    364367        // finally block
    365         if ( finallyBlock != 0 ) {
     368        if ( finallyBlock != nullptr ) {
    366369                os << indent << "... and finally:" << endl << indent+1;
    367370                finallyBlock->print( os, indent+1 );
     
    369372}
    370373
    371 CatchStmt::CatchStmt( Kind kind, Declaration *decl, Expression *cond, Statement *body ) :
     374CatchStmt::CatchStmt( Kind kind, Declaration * decl, Expression * cond, Statement * body ) :
    372375        Statement(), kind ( kind ), decl ( decl ), cond ( cond ), body( body ) {
    373376                assertf( decl, "Catch clause must have a declaration." );
     
    383386}
    384387
    385 void CatchStmt::print( std::ostream &os, Indenter indent ) const {
     388void CatchStmt::print( std::ostream & os, Indenter indent ) const {
    386389        os << "Catch " << ((Terminate == kind) ? "Terminate" : "Resume") << " Statement" << endl;
    387390
     
    401404
    402405
    403 FinallyStmt::FinallyStmt( CompoundStmt *block ) : Statement(), block( block ) {
     406FinallyStmt::FinallyStmt( CompoundStmt * block ) : Statement(), block( block ) {
    404407}
    405408
     
    411414}
    412415
    413 void FinallyStmt::print( std::ostream &os, Indenter indent ) const {
     416void FinallyStmt::print( std::ostream & os, Indenter indent ) const {
    414417        os << "Finally Statement" << endl;
    415418        os << indent << "... with block:" << endl << indent+1;
    416419        block->print( os, indent+1 );
     420}
     421
     422SuspendStmt::SuspendStmt( const SuspendStmt & other )
     423        : Statement( other )
     424        , then( maybeClone(other.then) )
     425{}
     426
     427SuspendStmt::~SuspendStmt() {
     428        delete then;
     429}
     430
     431void SuspendStmt::print( std::ostream & os, Indenter indent ) const {
     432        os << "Suspend Statement";
     433        switch (type) {
     434                case None     : os << " with implicit target"; break;
     435                case Generator: os << " for generator"       ; break;
     436                case Coroutine: os << " for coroutine"       ; break;
     437        }
     438        os << endl;
     439        indent += 1;
     440
     441        if(then) {
     442                os << indent << " with post statement :" << endl;
     443                then->print( os, indent + 1);
     444        }
    417445}
    418446
     
    458486}
    459487
    460 void WaitForStmt::print( std::ostream &os, Indenter indent ) const {
     488void WaitForStmt::print( std::ostream & os, Indenter indent ) const {
    461489        os << "Waitfor Statement" << endl;
    462490        indent += 1;
     
    514542}
    515543
    516 void NullStmt::print( std::ostream &os, Indenter indent ) const {
     544void NullStmt::print( std::ostream & os, Indenter indent ) const {
    517545        os << "Null Statement" << endl;
    518546        Statement::print( os, indent );
     
    530558}
    531559
    532 void ImplicitCtorDtorStmt::print( std::ostream &os, Indenter indent ) const {
     560void ImplicitCtorDtorStmt::print( std::ostream & os, Indenter indent ) const {
    533561        os << "Implicit Ctor Dtor Statement" << endl;
    534562        os << indent << "... with Ctor/Dtor: ";
  • src/SynTree/Statement.h

    r71d6bd8 r7030dab  
    1010// Created On       : Mon May 18 07:44:20 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Tue Mar 12 09:01:53 2019
    13 // Update Count     : 83
     12// Last Modified On : Fri Jan 10 14:13:24 2020
     13// Update Count     : 85
    1414//
    1515
     
    257257        Statement * body;
    258258
    259         ForStmt( std::list<Statement *> initialization, Expression * condition = 0, Expression * increment = 0, Statement * body = 0 );
     259        ForStmt( std::list<Statement *> initialization, Expression * condition = nullptr, Expression * increment = nullptr, Statement * body = nullptr );
    260260        ForStmt( const ForStmt & other );
    261261        virtual ~ForStmt();
     
    357357        FinallyStmt * finallyBlock;
    358358
    359         TryStmt( CompoundStmt * tryBlock, std::list<CatchStmt *> & handlers, FinallyStmt * finallyBlock = 0 );
     359        TryStmt( CompoundStmt * tryBlock, std::list<CatchStmt *> & handlers, FinallyStmt * finallyBlock = nullptr );
    360360        TryStmt( const TryStmt & other );
    361361        virtual ~TryStmt();
     
    422422};
    423423
     424class SuspendStmt : public Statement {
     425  public:
     426        CompoundStmt * then = nullptr;
     427        enum Type { None, Coroutine, Generator } type = None;
     428
     429        SuspendStmt() = default;
     430        SuspendStmt( const SuspendStmt & );
     431        virtual ~SuspendStmt();
     432
     433        virtual SuspendStmt * clone() const override { return new SuspendStmt( *this ); }
     434        virtual void accept( Visitor & v ) override { v.visit( this ); }
     435        virtual void accept( Visitor & v ) const override { v.visit( this ); }
     436        virtual Statement * acceptMutator( Mutator & m )  override { return m.mutate( this ); }
     437        virtual void print( std::ostream & os, Indenter indent = {} ) const override;
     438};
     439
    424440class WaitForStmt : public Statement {
    425441  public:
  • src/SynTree/SynTree.h

    r71d6bd8 r7030dab  
    5454class CatchStmt;
    5555class FinallyStmt;
     56class SuspendStmt;
    5657class WaitForStmt;
    5758class WithStmt;
  • src/SynTree/TupleType.cc

    r71d6bd8 r7030dab  
    1010// Created On       : Mon May 18 07:44:20 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Wed Feb  1 17:10:58 2017
    13 // Update Count     : 3
     12// Last Modified On : Fri Dec 13 23:44:38 2019
     13// Update Count     : 4
    1414//
    1515
     
    2020#include "Declaration.h"         // for Declaration, ObjectDecl
    2121#include "Initializer.h"         // for ListInit
    22 #include "Parser/LinkageSpec.h"  // for Cforall
     22#include "LinkageSpec.h"         // for Cforall
    2323#include "Type.h"                // for TupleType, Type, Type::Qualifiers
    2424
  • src/SynTree/Type.cc

    r71d6bd8 r7030dab  
    1010// Created On       : Mon May 18 07:44:20 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sun Aug  4 21:05:07 2019
    13 // Update Count     : 45
     12// Last Modified On : Sun Dec 15 16:52:37 2019
     13// Update Count     : 49
    1414//
    1515#include "Type.h"
     
    2424using namespace std;
    2525
     26// GENERATED START, DO NOT EDIT
     27// GENERATED BY BasicTypes-gen.cc
    2628const char * BasicType::typeNames[] = {
    2729        "_Bool",
     
    4547        "float",
    4648        "float _Complex",
    47         //"float _Imaginary",
    4849        "_Float32x",
    4950        "_Float32x _Complex",
     
    5253        "double",
    5354        "double _Complex",
    54         //"double _Imaginary",
    5555        "_Float64x",
    5656        "_Float64x _Complex",
     
    6161        "long double",
    6262        "long double _Complex",
    63         //"long double _Imaginary",
    6463        "_Float128x",
    6564        "_Float128x _Complex",
    6665};
    67 static_assert(
    68         sizeof(BasicType::typeNames) / sizeof(BasicType::typeNames[0]) == BasicType::NUMBER_OF_BASIC_TYPES,
    69         "Each basic type name should have a corresponding kind enum value"
    70 );
     66// GENERATED END
    7167
    7268Type::Type( const Qualifiers &tq, const std::list< Attribute * > & attributes ) : tq( tq ), attributes( attributes ) {}
  • 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
  • src/SynTree/Visitor.h

    r71d6bd8 r7030dab  
    7878        virtual void visit( FinallyStmt * node ) { visit( const_cast<const FinallyStmt *>(node) ); }
    7979        virtual void visit( const FinallyStmt * finallyStmt ) = 0;
     80        virtual void visit( SuspendStmt * node ) { visit( const_cast<const SuspendStmt *>(node) ); }
     81        virtual void visit( const SuspendStmt * suspendStmt ) = 0;
    8082        virtual void visit( WaitForStmt * node ) { visit( const_cast<const WaitForStmt *>(node) ); }
    8183        virtual void visit( const WaitForStmt * waitforStmt ) = 0;
  • src/SynTree/module.mk

    r71d6bd8 r7030dab  
    1111## Created On       : Mon Jun  1 17:49:17 2015
    1212## Last Modified By : Peter A. Buhr
    13 ## Last Modified On : Mon Jun  1 17:54:09 2015
    14 ## Update Count     : 1
     13## Last Modified On : Sat Dec 14 07:26:43 2019
     14## Update Count     : 2
    1515###############################################################################
    1616
    1717SRC_SYNTREE = \
    18       SynTree/Type.cc \
    19       SynTree/VoidType.cc \
     18      SynTree/AddressExpr.cc \
     19      SynTree/AggregateDecl.cc \
     20      SynTree/ApplicationExpr.cc \
     21      SynTree/ArrayType.cc \
     22      SynTree/AttrType.cc \
     23      SynTree/Attribute.cc \
    2024      SynTree/BasicType.cc \
    21       SynTree/PointerType.cc \
    22       SynTree/ArrayType.cc \
    23       SynTree/ReferenceType.cc \
    24       SynTree/FunctionType.cc \
    25       SynTree/ReferenceToType.cc \
    26       SynTree/TupleType.cc \
    27       SynTree/TypeofType.cc \
    28       SynTree/AttrType.cc \
    29       SynTree/VarArgsType.cc \
    30       SynTree/ZeroOneType.cc \
     25      SynTree/CommaExpr.cc \
     26      SynTree/CompoundStmt.cc \
    3127      SynTree/Constant.cc \
    32       SynTree/Expression.cc \
    33       SynTree/TupleExpr.cc \
    34       SynTree/CommaExpr.cc \
    35       SynTree/TypeExpr.cc \
    36       SynTree/ApplicationExpr.cc \
    37       SynTree/AddressExpr.cc \
    38       SynTree/Statement.cc \
    39       SynTree/CompoundStmt.cc \
     28      SynTree/DeclReplacer.cc \
    4029      SynTree/DeclStmt.cc \
    4130      SynTree/Declaration.cc \
    4231      SynTree/DeclarationWithType.cc \
     32      SynTree/Expression.cc \
     33      SynTree/FunctionDecl.cc \
     34      SynTree/FunctionType.cc \
     35      SynTree/Initializer.cc \
     36      SynTree/LinkageSpec.cc \
     37      SynTree/NamedTypeDecl.cc \
    4338      SynTree/ObjectDecl.cc \
    44       SynTree/FunctionDecl.cc \
    45       SynTree/AggregateDecl.cc \
    46       SynTree/NamedTypeDecl.cc \
     39      SynTree/PointerType.cc \
     40      SynTree/ReferenceToType.cc \
     41      SynTree/ReferenceType.cc \
     42      SynTree/Statement.cc \
     43      SynTree/TupleExpr.cc \
     44      SynTree/TupleType.cc \
     45      SynTree/Type.cc \
    4746      SynTree/TypeDecl.cc \
    48       SynTree/Initializer.cc \
     47      SynTree/TypeExpr.cc \
    4948      SynTree/TypeSubstitution.cc \
    50       SynTree/Attribute.cc \
    51       SynTree/DeclReplacer.cc
     49      SynTree/TypeofType.cc \
     50      SynTree/VarArgsType.cc \
     51      SynTree/VoidType.cc \
     52      SynTree/ZeroOneType.cc
    5253
    5354SRC += $(SRC_SYNTREE)
Note: See TracChangeset for help on using the changeset viewer.