Changeset 7030dab for src/AST/Decl.hpp


Ignore:
Timestamp:
Apr 6, 2020, 4:46:28 PM (4 years ago)
Author:
Thierry Delisle <tdelisle@…>
Branches:
ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
Children:
e3bc51c
Parents:
71d6bd8 (diff), 057298e (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'master' into new-ast

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/AST/Decl.hpp

    r71d6bd8 r7030dab  
    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 : Fri Dec 13 17:38:33 2019
     13// Update Count     : 29
    1414//
    1515
     
    2020#include <unordered_map>
    2121#include <vector>
     22#include <algorithm>
    2223
    2324#include "FunctionSpec.hpp"
     
    2728#include "ParseNode.hpp"
    2829#include "StorageClasses.hpp"
    29 #include "TypeVar.hpp"
    3030#include "Visitor.hpp"
    31 #include "Parser/ParseNode.h"  // for DeclarationNode::Aggregate
     31#include "Common/utility.h"
     32#include "Common/SemanticError.h"                                               // error_str
    3233
    3334// Must be included in *all* AST classes; should be #undef'd at the end of the file
     
    127128        std::vector< ptr<Expr> > withExprs;
    128129
    129         FunctionDecl( const CodeLocation & loc, const std::string &name, FunctionType * type,
     130        FunctionDecl( const CodeLocation & loc, const std::string & name, FunctionType * type,
    130131                CompoundStmt * stmts, Storage::Classes storage = {}, Linkage::Spec linkage = Linkage::C,
    131132                std::vector<ptr<Attribute>>&& attrs = {}, Function::Specs fs = {})
     
    138139        bool has_body() const { return stmts; }
    139140
    140         const DeclWithType * accept( Visitor &v ) const override { return v.visit( this ); }
     141        const DeclWithType * accept( Visitor & v ) const override { return v.visit( this ); }
    141142private:
    142143        FunctionDecl * clone() const override { return new FunctionDecl( *this ); }
     
    151152        std::vector<ptr<DeclWithType>> assertions;
    152153
    153         NamedTypeDecl( 
     154        NamedTypeDecl(
    154155                const CodeLocation & loc, const std::string & name, Storage::Classes storage,
    155156                const Type * b, Linkage::Spec spec = Linkage::Cforall )
     
    157158
    158159        /// Produces a name for the kind of alias
    159         virtual std::string typeString() const = 0;
     160        virtual const char * typeString() const = 0;
    160161
    161162private:
     
    166167/// Cforall type variable: `dtype T`
    167168class TypeDecl final : public NamedTypeDecl {
    168 public:
    169         TypeVar::Kind kind;
     169  public:
     170        enum Kind { Dtype, Otype, Ftype, Ttype, NUMBER_OF_KINDS };
     171
     172        Kind kind;
    170173        bool sized;
    171174        ptr<Type> init;
     
    173176        /// Data extracted from a type decl
    174177        struct Data {
    175                 TypeVar::Kind kind;
     178                Kind kind;
    176179                bool isComplete;
    177180
    178                 Data() : kind( (TypeVar::Kind)-1 ), isComplete( false ) {}
     181                Data() : kind( NUMBER_OF_KINDS ), isComplete( false ) {}
    179182                Data( const TypeDecl * d ) : kind( d->kind ), isComplete( d->sized ) {}
    180                 Data( TypeVar::Kind k, bool c ) : kind( k ), isComplete( c ) {}
     183                Data( Kind k, bool c ) : kind( k ), isComplete( c ) {}
    181184                Data( const Data & d1, const Data & d2 )
    182                 : kind( d1.kind ), isComplete( d1.isComplete || d2.isComplete ) {}
    183 
    184                 bool operator== ( const Data & o ) const {
    185                         return kind == o.kind && isComplete == o.isComplete;
    186                 }
    187                 bool operator!= ( const Data & o ) const { return !(*this == o); }
     185                        : kind( d1.kind ), isComplete( d1.isComplete || d2.isComplete ) {}
     186
     187                bool operator==( const Data & o ) const { return kind == o.kind && isComplete == o.isComplete; }
     188                bool operator!=( const Data & o ) const { return !(*this == o); }
    188189        };
    189190
    190         TypeDecl( 
    191                 const CodeLocation & loc, const std::string & name, Storage::Classes storage, 
     191        TypeDecl(
     192                const CodeLocation & loc, const std::string & name, Storage::Classes storage,
    192193                const Type * b, TypeVar::Kind k, bool s, const Type * i = nullptr )
    193194        : NamedTypeDecl( loc, name, storage, b ), kind( k ), sized( k == TypeVar::Ttype || s ),
    194195          init( i ) {}
    195196
    196         std::string typeString() const override;
     197        const char * typeString() const override;
    197198        /// Produces a name for generated code
    198         std::string genTypeString() const;
     199        const char * genTypeString() const;
    199200
    200201        /// convenience accessor to match Type::isComplete()
     
    202203
    203204        const Decl * accept( Visitor & v ) const override { return v.visit( this ); }
    204 private:
     205  private:
    205206        TypeDecl * clone() const override { return new TypeDecl{ *this }; }
    206207        MUTATE_FRIEND
     
    216217        : NamedTypeDecl( loc, name, storage, b, spec ) {}
    217218
    218         std::string typeString() const override { return "typedef"; }
     219        const char * typeString() const override { return "typedef"; }
    219220
    220221        const Decl * accept( Visitor & v ) const override { return v.visit( this ); }
     
    227228class AggregateDecl : public Decl {
    228229public:
     230        enum Aggregate { Struct, Union, Enum, Exception, Trait, Generator, Coroutine, Monitor, Thread, NoAggregate };
     231        static const char * aggrString( Aggregate aggr );
     232
    229233        std::vector<ptr<Decl>> members;
    230234        std::vector<ptr<TypeDecl>> params;
     
    241245
    242246        /// Produces a name for the kind of aggregate
    243         virtual std::string typeString() const = 0;
     247        virtual const char * typeString() const = 0;
    244248
    245249private:
     
    251255class StructDecl final : public AggregateDecl {
    252256public:
    253         DeclarationNode::Aggregate kind;
     257        Aggregate kind;
    254258
    255259        StructDecl( const CodeLocation& loc, const std::string& name,
    256                 DeclarationNode::Aggregate kind = DeclarationNode::Struct,
     260                Aggregate kind = Struct,
    257261                std::vector<ptr<Attribute>>&& attrs = {}, Linkage::Spec linkage = Linkage::Cforall )
    258262        : AggregateDecl( loc, name, std::move(attrs), linkage ), kind( kind ) {}
    259263
    260         bool is_coroutine() { return kind == DeclarationNode::Coroutine; }
    261         bool is_monitor() { return kind == DeclarationNode::Monitor; }
    262         bool is_thread() { return kind == DeclarationNode::Thread; }
    263 
    264         const Decl * accept( Visitor & v ) const override { return v.visit( this ); }
    265 
    266         std::string typeString() const override { return "struct"; }
     264        bool is_coroutine() { return kind == Coroutine; }
     265        bool is_generator() { return kind == Generator; }
     266        bool is_monitor  () { return kind == Monitor  ; }
     267        bool is_thread   () { return kind == Thread   ; }
     268
     269        const Decl * accept( Visitor & v ) const override { return v.visit( this ); }
     270
     271        const char * typeString() const override { return aggrString( kind ); }
    267272
    268273private:
     
    280285        const Decl * accept( Visitor& v ) const override { return v.visit( this ); }
    281286
    282         std::string typeString() const override { return "union"; }
     287        const char * typeString() const override { return aggrString( Union ); }
    283288
    284289private:
     
    299304        const Decl * accept( Visitor & v ) const override { return v.visit( this ); }
    300305
    301         std::string typeString() const override { return "enum"; }
     306        const char * typeString() const override { return aggrString( Enum ); }
    302307
    303308private:
     
    318323        const Decl * accept( Visitor & v ) const override { return v.visit( this ); }
    319324
    320         std::string typeString() const override { return "trait"; }
     325        const char * typeString() const override { return "trait"; }
    321326
    322327private:
     
    344349        ptr<AsmStmt> stmt;
    345350
    346         AsmDecl( const CodeLocation & loc, AsmStmt *stmt )
     351        AsmDecl( const CodeLocation & loc, AsmStmt * stmt )
    347352        : Decl( loc, "", {}, {} ), stmt(stmt) {}
    348353
    349         const AsmDecl * accept( Visitor &v ) const override { return v.visit( this ); }
    350 private:
    351         AsmDecl *clone() const override { return new AsmDecl( *this ); }
     354        const AsmDecl * accept( Visitor & v ) const override { return v.visit( this ); }
     355private:
     356        AsmDecl * clone() const override { return new AsmDecl( *this ); }
    352357        MUTATE_FRIEND
    353358};
     
    361366        : Decl( loc, "", {}, {} ), cond( condition ), msg( msg ) {}
    362367
    363         const StaticAssertDecl * accept( Visitor &v ) const override { return v.visit( this ); }
     368        const StaticAssertDecl * accept( Visitor & v ) const override { return v.visit( this ); }
    364369private:
    365370        StaticAssertDecl * clone() const override { return new StaticAssertDecl( *this ); }
Note: See TracChangeset for help on using the changeset viewer.