Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/AST/Decl.hpp

    r07de76b re67991f  
    99// Author           : Aaron B. Moss
    1010// Created On       : Thu May 9 10:00:00 2019
    11 // Last Modified By : Peter A. Buhr
    12 // Last Modified On : Fri Dec 13 17:38:33 2019
    13 // Update Count     : 29
     11// Last Modified By : Aaron B. Moss
     12// Last Modified On : Thu May 9 10:00:00 2019
     13// Update Count     : 1
    1414//
    1515
     
    2020#include <unordered_map>
    2121#include <vector>
    22 #include <algorithm>
    2322
    2423#include "FunctionSpec.hpp"
     
    2827#include "ParseNode.hpp"
    2928#include "StorageClasses.hpp"
     29#include "TypeVar.hpp"
    3030#include "Visitor.hpp"
    31 #include "Common/utility.h"
    32 #include "Common/SemanticError.h"                                               // error_str
     31#include "Parser/ParseNode.h"  // for DeclarationNode::Aggregate
    3332
    3433// Must be included in *all* AST classes; should be #undef'd at the end of the file
     
    126125        std::vector< ptr<Expr> > withExprs;
    127126
    128         FunctionDecl( const CodeLocation & loc, const std::string & name, FunctionType * type,
     127        FunctionDecl( const CodeLocation & loc, const std::string &name, FunctionType * type,
    129128                CompoundStmt * stmts, Storage::Classes storage = {}, Linkage::Spec linkage = Linkage::C,
    130129                std::vector<ptr<Attribute>>&& attrs = {}, Function::Specs fs = {})
     
    137136        bool has_body() const { return stmts; }
    138137
    139         const DeclWithType * accept( Visitor & v ) const override { return v.visit( this ); }
     138        const DeclWithType * accept( Visitor &v ) const override { return v.visit( this ); }
    140139private:
    141140        FunctionDecl * clone() const override { return new FunctionDecl( *this ); }
     
    155154
    156155        /// Produces a name for the kind of alias
    157         virtual const char * typeString() const = 0;
     156        virtual std::string typeString() const = 0;
    158157
    159158private:
     
    164163/// Cforall type variable: `dtype T`
    165164class TypeDecl final : public NamedTypeDecl {
    166   public:
    167         enum Kind { Dtype, Otype, Ftype, Ttype, NUMBER_OF_KINDS };
    168 
    169         Kind kind;
     165public:
     166        TypeVar::Kind kind;
    170167        bool sized;
    171168        ptr<Type> init;
     
    173170        /// Data extracted from a type decl
    174171        struct Data {
    175                 Kind kind;
     172                TypeVar::Kind kind;
    176173                bool isComplete;
    177174
    178                 Data() : kind( NUMBER_OF_KINDS ), isComplete( false ) {}
     175                Data() : kind( (TypeVar::Kind)-1 ), isComplete( false ) {}
    179176                Data( const TypeDecl * d ) : kind( d->kind ), isComplete( d->sized ) {}
    180                 Data( Kind k, bool c ) : kind( k ), isComplete( c ) {}
     177                Data( TypeVar::Kind k, bool c ) : kind( k ), isComplete( c ) {}
    181178                Data( const Data & d1, const Data & d2 )
    182                         : kind( d1.kind ), isComplete( d1.isComplete || d2.isComplete ) {}
    183 
    184                 bool operator==( const Data & o ) const { return kind == o.kind && isComplete == o.isComplete; }
    185                 bool operator!=( const Data & o ) const { return !(*this == o); }
     179                : kind( d1.kind ), isComplete( d1.isComplete || d2.isComplete ) {}
     180
     181                bool operator== ( const Data & o ) const {
     182                        return kind == o.kind && isComplete == o.isComplete;
     183                }
     184                bool operator!= ( const Data & o ) const { return !(*this == o); }
    186185        };
    187186
    188         TypeDecl( const CodeLocation & loc, const std::string & name, Storage::Classes storage, Type * b,
    189                           Kind k, bool s, Type * i = nullptr )
    190                 : NamedTypeDecl( loc, name, storage, b ), kind( k ), sized( k == Ttype || s ),
    191                 init( i ) {}
    192 
    193         const char * typeString() const override;
     187        TypeDecl( const CodeLocation& loc, const std::string& name, Storage::Classes storage, Type* b,
     188                TypeVar::Kind k, bool s, Type* i = nullptr )
     189        : NamedTypeDecl( loc, name, storage, b ), kind( k ), sized( k == TypeVar::Ttype || s ),
     190          init( i ) {}
     191
     192        std::string typeString() const override;
    194193        /// Produces a name for generated code
    195         const char * genTypeString() const;
     194        std::string genTypeString() const;
    196195
    197196        /// convenience accessor to match Type::isComplete()
     
    199198
    200199        const Decl * accept( Visitor & v ) const override { return v.visit( this ); }
    201   private:
     200private:
    202201        TypeDecl * clone() const override { return new TypeDecl{ *this }; }
    203202        MUTATE_FRIEND
     
    213212        : NamedTypeDecl( loc, name, storage, b, spec ) {}
    214213
    215         const char * typeString() const override { return "typedef"; }
     214        std::string typeString() const override { return "typedef"; }
    216215
    217216        const Decl * accept( Visitor & v ) const override { return v.visit( this ); }
     
    224223class AggregateDecl : public Decl {
    225224public:
    226         enum Aggregate { Struct, Union, Enum, Exception, Trait, Generator, Coroutine, Monitor, Thread, NoAggregate };
    227         static const char * aggrString( Aggregate aggr );
    228 
    229225        std::vector<ptr<Decl>> members;
    230226        std::vector<ptr<TypeDecl>> params;
     
    241237
    242238        /// Produces a name for the kind of aggregate
    243         virtual const char * typeString() const = 0;
     239        virtual std::string typeString() const = 0;
    244240
    245241private:
     
    251247class StructDecl final : public AggregateDecl {
    252248public:
    253         Aggregate kind;
     249        DeclarationNode::Aggregate kind;
    254250
    255251        StructDecl( const CodeLocation& loc, const std::string& name,
    256                 Aggregate kind = Struct,
     252                DeclarationNode::Aggregate kind = DeclarationNode::Struct,
    257253                std::vector<ptr<Attribute>>&& attrs = {}, Linkage::Spec linkage = Linkage::Cforall )
    258254        : AggregateDecl( loc, name, std::move(attrs), linkage ), kind( kind ) {}
    259255
    260         bool is_coroutine() { return kind == Coroutine; }
    261         bool is_monitor() { return kind == Monitor; }
    262         bool is_thread() { return kind == Thread; }
    263 
    264         const Decl * accept( Visitor & v ) const override { return v.visit( this ); }
    265 
    266         const char * typeString() const override { return aggrString( kind ); }
     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"; }
    267263
    268264private:
     
    280276        const Decl * accept( Visitor& v ) const override { return v.visit( this ); }
    281277
    282         const char * typeString() const override { return aggrString( Union ); }
     278        std::string typeString() const override { return "union"; }
    283279
    284280private:
     
    299295        const Decl * accept( Visitor & v ) const override { return v.visit( this ); }
    300296
    301         const char * typeString() const override { return aggrString( Enum ); }
     297        std::string typeString() const override { return "enum"; }
    302298
    303299private:
     
    318314        const Decl * accept( Visitor & v ) const override { return v.visit( this ); }
    319315
    320         const char * typeString() const override { return "trait"; }
     316        std::string typeString() const override { return "trait"; }
    321317
    322318private:
     
    344340        ptr<AsmStmt> stmt;
    345341
    346         AsmDecl( const CodeLocation & loc, AsmStmt * stmt )
     342        AsmDecl( const CodeLocation & loc, AsmStmt *stmt )
    347343        : Decl( loc, "", {}, {} ), stmt(stmt) {}
    348344
    349         const AsmDecl * accept( Visitor & v ) const override { return v.visit( this ); }
    350 private:
    351         AsmDecl * clone() const override { return new AsmDecl( *this ); }
     345        const AsmDecl * accept( Visitor &v ) const override { return v.visit( this ); }
     346private:
     347        AsmDecl *clone() const override { return new AsmDecl( *this ); }
    352348        MUTATE_FRIEND
    353349};
     
    361357        : Decl( loc, "", {}, {} ), cond( condition ), msg( msg ) {}
    362358
    363         const StaticAssertDecl * accept( Visitor & v ) const override { return v.visit( this ); }
     359        const StaticAssertDecl * accept( Visitor &v ) const override { return v.visit( this ); }
    364360private:
    365361        StaticAssertDecl * clone() const override { return new StaticAssertDecl( *this ); }
Note: See TracChangeset for help on using the changeset viewer.