Changeset 3b56166 for src/AST/Decl.hpp


Ignore:
Timestamp:
Feb 10, 2020, 11:17:38 AM (6 years ago)
Author:
Thierry Delisle <tdelisle@…>
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:
3966d9a, 41efd33
Parents:
807a632 (diff), d231700 (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' of plg.uwaterloo.ca:software/cfa/cfa-cc

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/AST/Decl.hpp

    r807a632 r3b56166  
    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
     
    125126        std::vector< ptr<Expr> > withExprs;
    126127
    127         FunctionDecl( const CodeLocation & loc, const std::string &name, FunctionType * type,
     128        FunctionDecl( const CodeLocation & loc, const std::string & name, FunctionType * type,
    128129                CompoundStmt * stmts, Storage::Classes storage = {}, Linkage::Spec linkage = Linkage::C,
    129130                std::vector<ptr<Attribute>>&& attrs = {}, Function::Specs fs = {})
     
    136137        bool has_body() const { return stmts; }
    137138
    138         const DeclWithType * accept( Visitor &v ) const override { return v.visit( this ); }
     139        const DeclWithType * accept( Visitor & v ) const override { return v.visit( this ); }
    139140private:
    140141        FunctionDecl * clone() const override { return new FunctionDecl( *this ); }
     
    154155
    155156        /// Produces a name for the kind of alias
    156         virtual std::string typeString() const = 0;
     157        virtual const char * typeString() const = 0;
    157158
    158159private:
     
    163164/// Cforall type variable: `dtype T`
    164165class TypeDecl final : public NamedTypeDecl {
    165 public:
    166         TypeVar::Kind kind;
     166  public:
     167        enum Kind { Dtype, Otype, Ftype, Ttype, NUMBER_OF_KINDS };
     168
     169        Kind kind;
    167170        bool sized;
    168171        ptr<Type> init;
     
    170173        /// Data extracted from a type decl
    171174        struct Data {
    172                 TypeVar::Kind kind;
     175                Kind kind;
    173176                bool isComplete;
    174177
    175                 Data() : kind( (TypeVar::Kind)-1 ), isComplete( false ) {}
     178                Data() : kind( NUMBER_OF_KINDS ), isComplete( false ) {}
    176179                Data( const TypeDecl * d ) : kind( d->kind ), isComplete( d->sized ) {}
    177                 Data( TypeVar::Kind k, bool c ) : kind( k ), isComplete( c ) {}
     180                Data( Kind k, bool c ) : kind( k ), isComplete( c ) {}
    178181                Data( const Data & d1, const Data & d2 )
    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); }
     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); }
    185186        };
    186187
    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;
     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;
    193194        /// Produces a name for generated code
    194         std::string genTypeString() const;
     195        const char * genTypeString() const;
    195196
    196197        /// convenience accessor to match Type::isComplete()
     
    198199
    199200        const Decl * accept( Visitor & v ) const override { return v.visit( this ); }
    200 private:
     201  private:
    201202        TypeDecl * clone() const override { return new TypeDecl{ *this }; }
    202203        MUTATE_FRIEND
     
    212213        : NamedTypeDecl( loc, name, storage, b, spec ) {}
    213214
    214         std::string typeString() const override { return "typedef"; }
     215        const char * typeString() const override { return "typedef"; }
    215216
    216217        const Decl * accept( Visitor & v ) const override { return v.visit( this ); }
     
    223224class AggregateDecl : public Decl {
    224225public:
     226        enum Aggregate { Struct, Union, Enum, Exception, Trait, Generator, Coroutine, Monitor, Thread, NoAggregate };
     227        static const char * aggrString( Aggregate aggr );
     228
    225229        std::vector<ptr<Decl>> members;
    226230        std::vector<ptr<TypeDecl>> params;
     
    237241
    238242        /// Produces a name for the kind of aggregate
    239         virtual std::string typeString() const = 0;
     243        virtual const char * typeString() const = 0;
    240244
    241245private:
     
    247251class StructDecl final : public AggregateDecl {
    248252public:
    249         DeclarationNode::Aggregate kind;
     253        Aggregate kind;
    250254
    251255        StructDecl( const CodeLocation& loc, const std::string& name,
    252                 DeclarationNode::Aggregate kind = DeclarationNode::Struct,
     256                Aggregate kind = Struct,
    253257                std::vector<ptr<Attribute>>&& attrs = {}, Linkage::Spec linkage = Linkage::Cforall )
    254258        : AggregateDecl( loc, name, std::move(attrs), linkage ), kind( kind ) {}
    255259
    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"; }
     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 ); }
    263267
    264268private:
     
    276280        const Decl * accept( Visitor& v ) const override { return v.visit( this ); }
    277281
    278         std::string typeString() const override { return "union"; }
     282        const char * typeString() const override { return aggrString( Union ); }
    279283
    280284private:
     
    295299        const Decl * accept( Visitor & v ) const override { return v.visit( this ); }
    296300
    297         std::string typeString() const override { return "enum"; }
     301        const char * typeString() const override { return aggrString( Enum ); }
    298302
    299303private:
     
    314318        const Decl * accept( Visitor & v ) const override { return v.visit( this ); }
    315319
    316         std::string typeString() const override { return "trait"; }
     320        const char * typeString() const override { return "trait"; }
    317321
    318322private:
     
    340344        ptr<AsmStmt> stmt;
    341345
    342         AsmDecl( const CodeLocation & loc, AsmStmt *stmt )
     346        AsmDecl( const CodeLocation & loc, AsmStmt * stmt )
    343347        : Decl( loc, "", {}, {} ), stmt(stmt) {}
    344348
    345         const AsmDecl * accept( Visitor &v ) const override { return v.visit( this ); }
    346 private:
    347         AsmDecl *clone() const override { return new AsmDecl( *this ); }
     349        const AsmDecl * accept( Visitor & v ) const override { return v.visit( this ); }
     350private:
     351        AsmDecl * clone() const override { return new AsmDecl( *this ); }
    348352        MUTATE_FRIEND
    349353};
     
    357361        : Decl( loc, "", {}, {} ), cond( condition ), msg( msg ) {}
    358362
    359         const StaticAssertDecl * accept( Visitor &v ) const override { return v.visit( this ); }
     363        const StaticAssertDecl * accept( Visitor & v ) const override { return v.visit( this ); }
    360364private:
    361365        StaticAssertDecl * clone() const override { return new StaticAssertDecl( *this ); }
Note: See TracChangeset for help on using the changeset viewer.