Changeset 07de76b for src/AST


Ignore:
Timestamp:
Dec 16, 2019, 2:30:41 PM (4 years ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
Children:
bffcd66
Parents:
ab5c0008
git-author:
Peter A. Buhr <pabuhr@…> (12/16/19 14:23:00)
git-committer:
Peter A. Buhr <pabuhr@…> (12/16/19 14:30:41)
Message:

remove file TypeVar?.h* and put TypeVar::Kind into TypeDecl?, move LinkageSpec?.* from directory Parse to SynTree?

Location:
src/AST
Files:
1 deleted
8 edited

Legend:

Unmodified
Added
Removed
  • src/AST/Convert.cpp

    rab5c0008 r07de76b  
    1010// Created On       : Thu May 09 15::37::05 2019
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Tue Dec 10 22:20:10 2019
    13 // Update Count     : 32
     12// Last Modified On : Wed Dec 11 21:39:32 2019
     13// Update Count     : 33
    1414//
    1515
     
    12231223                                cv( node ),
    12241224                                node->name,
    1225                                 node->kind == ast::TypeVar::Ftype,
     1225                                node->kind == ast::TypeDecl::Ftype,
    12261226                                get<Attribute>().acceptL( node->attributes )
    12271227                        };
     
    15781578                        { old->storageClasses.val },
    15791579                        GET_ACCEPT_1(base, Type),
    1580                         (ast::TypeVar::Kind)(unsigned)old->kind,
     1580                        (ast::TypeDecl::Kind)(unsigned)old->kind,
    15811581                        old->sized,
    15821582                        GET_ACCEPT_1(init, Type)
     
    25612561                        ty = new ast::TypeInstType{
    25622562                                old->name,
    2563                                 old->isFtype ? ast::TypeVar::Ftype : ast::TypeVar::Dtype,
     2563                                old->isFtype ? ast::TypeDecl::Ftype : ast::TypeDecl::Dtype,
    25642564                                cv( old ),
    25652565                                GET_ACCEPT_V( attributes, Attribute )
  • src/AST/Decl.cpp

    rab5c0008 r07de76b  
    1010// Created On       : Thu May 9 10:00:00 2019
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Wed Dec 11 16:41:39 2019
    13 // Update Count     : 18
     12// Last Modified On : Fri Dec 13 16:23:15 2019
     13// Update Count     : 20
    1414//
    1515
     
    2626#include "Node.hpp"            // for readonly
    2727#include "Type.hpp"            // for readonly
    28 #include "Parser/ParseNode.h"  // for DeclarationNode
    2928
    3029namespace ast {
     
    5655
    5756const char * TypeDecl::typeString() const {
    58         static const char * kindNames[] = { "sized object type", "sized function type", "sized tuple type" };
    59         assertf( sizeof(kindNames)/sizeof(kindNames[0]) == DeclarationNode::NoTypeClass-1,
    60                 "typeString: kindNames is out of sync." );
    61         assertf( kind < sizeof(kindNames)/sizeof(kindNames[0]), "TypeDecl's kind is out of bounds." );
     57        static const char * kindNames[] = { "sized data type", "sized object type", "sized function type", "sized tuple type" };
     58        static_assert( sizeof(kindNames)/sizeof(kindNames[0]) == TypeDecl::NUMBER_OF_KINDS, "typeString: kindNames is out of sync." );
     59        assertf( kind < TypeDecl::NUMBER_OF_KINDS, "TypeDecl kind is out of bounds." );
    6260        return sized ? kindNames[ kind ] : &kindNames[ kind ][ sizeof("sized") ]; // sizeof includes '\0'
    6361}
    6462
    6563const char * TypeDecl::genTypeString() const {
    66         static const char * kindNames[] = { "dtype", "ftype", "ttype" };
    67         assertf( sizeof(kindNames)/sizeof(kindNames[0]) == DeclarationNode::NoTypeClass-1, "genTypeString: kindNames is out of sync." );
    68         assertf( kind < sizeof(kindNames)/sizeof(kindNames[0]), "TypeDecl's kind is out of bounds." );
     64        static const char * kindNames[] = { "dtype", "otype", "ftype", "ttype" };
     65        static_assert( sizeof(kindNames)/sizeof(kindNames[0]) == TypeDecl::NUMBER_OF_KINDS, "genTypeString: kindNames is out of sync." );
     66        assertf( kind < TypeDecl::NUMBER_OF_KINDS, "TypeDecl kind is out of bounds." );
    6967        return kindNames[ kind ];
    7068}
  • src/AST/Decl.hpp

    rab5c0008 r07de76b  
    1010// Created On       : Thu May 9 10:00:00 2019
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Wed Dec 11 08:20:20 2019
    13 // Update Count     : 16
     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 ); }
     
    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 ) {}
     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 ) {}
    191192
    192193        const char * typeString() const override;
     
    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
     
    343344        ptr<AsmStmt> stmt;
    344345
    345         AsmDecl( const CodeLocation & loc, AsmStmt *stmt )
     346        AsmDecl( const CodeLocation & loc, AsmStmt * stmt )
    346347        : Decl( loc, "", {}, {} ), stmt(stmt) {}
    347348
    348         const AsmDecl * accept( Visitor &v ) const override { return v.visit( this ); }
    349 private:
    350         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 ); }
    351352        MUTATE_FRIEND
    352353};
     
    360361        : Decl( loc, "", {}, {} ), cond( condition ), msg( msg ) {}
    361362
    362         const StaticAssertDecl * accept( Visitor &v ) const override { return v.visit( this ); }
     363        const StaticAssertDecl * accept( Visitor & v ) const override { return v.visit( this ); }
    363364private:
    364365        StaticAssertDecl * clone() const override { return new StaticAssertDecl( *this ); }
  • src/AST/Print.cpp

    rab5c0008 r07de76b  
    13591359                preprint( node );
    13601360                os << "instance of type " << node->name
    1361                    << " (" << (node->kind == ast::TypeVar::Ftype ? "" : "not ") << "function type)";
     1361                   << " (" << (node->kind == ast::TypeDecl::Ftype ? "" : "not ") << "function type)";
    13621362                print( node->params );
    13631363
  • src/AST/Type.hpp

    rab5c0008 r07de76b  
    99// Author           : Aaron B. Moss
    1010// Created On       : Thu May 9 10:00:00 2019
    11 // Last Modified By : Aaron B. Moss
    12 // Last Modified On : Thu May 9 10:00:00 2019
    13 // Update Count     : 1
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Wed Dec 11 21:56:46 2019
     13// Update Count     : 5
    1414//
    1515
     
    2626#include "Fwd.hpp"
    2727#include "Node.hpp"          // for Node, ptr, ptr_base
    28 #include "TypeVar.hpp"
    2928#include "Visitor.hpp"
    3029
     
    423422public:
    424423        readonly<TypeDecl> base;
    425         TypeVar::Kind kind;
     424        TypeDecl::Kind kind;
    426425
    427426        TypeInstType( const std::string& n, const TypeDecl * b, CV::Qualifiers q = {},
    428427                std::vector<ptr<Attribute>> && as = {} )
    429428        : ReferenceToType( n, q, std::move(as) ), base( b ), kind( b->kind ) {}
    430         TypeInstType( const std::string& n, TypeVar::Kind k, CV::Qualifiers q = {},
     429        TypeInstType( const std::string& n, TypeDecl::Kind k, CV::Qualifiers q = {},
    431430                std::vector<ptr<Attribute>> && as = {} )
    432431        : ReferenceToType( n, q, std::move(as) ), base(), kind( k ) {}
  • src/AST/TypeEnvironment.cpp

    rab5c0008 r07de76b  
    99// Author           : Aaron B. Moss
    1010// Created On       : Wed May 29 11:00:00 2019
    11 // Last Modified By : Aaron B. Moss
    12 // Last Modified On : Wed May 29 11:00:00 2019
    13 // Update Count     : 1
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Wed Dec 11 21:49:13 2019
     13// Update Count     : 4
    1414//
    1515
     
    240240                return true;
    241241        } else if ( auto typeInst = dynamic_cast< const TypeInstType * >( type ) ) {
    242                 return typeInst->kind == TypeVar::Ftype;
     242                return typeInst->kind == TypeDecl::Ftype;
    243243        } else return false;
    244244}
     
    248248        bool tyVarCompatible( const TypeDecl::Data & data, const Type * type ) {
    249249                switch ( data.kind ) {
    250                   case TypeVar::Dtype:
     250                  case TypeDecl::Dtype:
    251251                        // to bind to an object type variable, the type must not be a function type.
    252252                        // if the type variable is specified to be a complete type then the incoming
     
    254254                        // xxx - should this also check that type is not a tuple type and that it's not a ttype?
    255255                        return ! isFtype( type ) && ( ! data.isComplete || type->isComplete() );
    256                   case TypeVar::Ftype:
     256                  case TypeDecl::Ftype:
    257257                        return isFtype( type );
    258                   case TypeVar::Ttype:
     258                  case TypeDecl::Ttype:
    259259                        // ttype unifies with any tuple type
    260260                        return dynamic_cast< const TupleType * >( type ) || Tuples::isTtype( type );
  • src/AST/TypeEnvironment.hpp

    rab5c0008 r07de76b  
    99// Author           : Aaron B. Moss
    1010// Created On       : Wed May 29 11:00:00 2019
    11 // Last Modified By : Aaron B. Moss
    12 // Last Modified On : Wed May 29 11:00:00 2019
    13 // Update Count     : 1
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Wed Dec 11 21:55:54 2019
     13// Update Count     : 3
    1414//
    1515
     
    2828#include "Type.hpp"
    2929#include "TypeSubstitution.hpp"
    30 #include "TypeVar.hpp"
    3130#include "Common/Indenter.h"
    3231#include "ResolvExpr/WidenMode.h"
     
    107106        /// Singleton class constructor from substitution
    108107        EqvClass( const std::string & v, const Type * b )
    109         : vars{ v }, bound( b ), allowWidening( false ), data( TypeVar::Dtype, false ) {}
     108        : vars{ v }, bound( b ), allowWidening( false ), data( TypeDecl::Dtype, false ) {}
    110109
    111110        /// Single-var constructor (strips qualifiers from bound type)
  • src/AST/module.mk

    rab5c0008 r07de76b  
    1010## Author           : Thierry Delisle
    1111## Created On       : Thu May 09 16:05:36 2019
    12 ## Last Modified By :
    13 ## Last Modified On :
    14 ## Update Count     :
     12## Last Modified By : Peter A. Buhr
     13## Last Modified On : Sat Dec 14 07:29:10 2019
     14## Update Count     : 3
    1515###############################################################################
    1616
     
    3434        AST/TypeSubstitution.cpp
    3535
    36 
    37 
    3836SRC += $(SRC_AST)
    3937SRCDEMANGLE += $(SRC_AST)
Note: See TracChangeset for help on using the changeset viewer.