Changeset 7a80113 for src


Ignore:
Timestamp:
Sep 22, 2020, 11:29:12 AM (5 years ago)
Author:
Thierry Delisle <tdelisle@…>
Branches:
ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast-unique-expr, pthread-emulation, qualifiedEnum, stuck-waitfor-destruct
Children:
0a945fd
Parents:
1c507eb (diff), 08f3ad3 (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

Location:
src
Files:
6 added
24 edited

Legend:

Unmodified
Added
Removed
  • src/AST/Convert.cpp

    r1c507eb r7a80113  
    11621162        }
    11631163
    1164         const ast::Type * postvisit( const ast::ReferenceToType * old, ReferenceToType * ty ) {
     1164        const ast::Type * postvisit( const ast::BaseInstType * old, ReferenceToType * ty ) {
    11651165                ty->forall = get<TypeDecl>().acceptL( old->forall );
    11661166                ty->parameters = get<Expression>().acceptL( old->params );
     
    25212521        }
    25222522
    2523         void postvisit( const ReferenceToType * old, ast::ReferenceToType * ty ) {
     2523        void postvisit( const ReferenceToType * old, ast::BaseInstType * ty ) {
    25242524                ty->forall = GET_ACCEPT_V( forall, TypeDecl );
    25252525                ty->params = GET_ACCEPT_V( parameters, Expr );
  • src/AST/Fwd.hpp

    r1c507eb r7a80113  
    107107class QualifiedType;
    108108class FunctionType;
    109 class ReferenceToType;
     109class BaseInstType;
    110110template<typename decl_t> class SueInstType;
    111111using StructInstType = SueInstType<StructDecl>;
  • src/AST/GenericSubstitution.cpp

    r1c507eb r7a80113  
    4242        private:
    4343                // make substitution for generic type
    44                 void makeSub( const ReferenceToType * ty ) {
     44                void makeSub( const BaseInstType * ty ) {
    4545                        visit_children = false;
    4646                        const AggregateDecl * aggr = ty->aggr();
  • src/AST/Node.cpp

    r1c507eb r7a80113  
    266266template class ast::ptr_base< ast::FunctionType, ast::Node::ref_type::weak >;
    267267template class ast::ptr_base< ast::FunctionType, ast::Node::ref_type::strong >;
    268 template class ast::ptr_base< ast::ReferenceToType, ast::Node::ref_type::weak >;
    269 template class ast::ptr_base< ast::ReferenceToType, ast::Node::ref_type::strong >;
     268template class ast::ptr_base< ast::BaseInstType, ast::Node::ref_type::weak >;
     269template class ast::ptr_base< ast::BaseInstType, ast::Node::ref_type::strong >;
    270270template class ast::ptr_base< ast::StructInstType, ast::Node::ref_type::weak >;
    271271template class ast::ptr_base< ast::StructInstType, ast::Node::ref_type::strong >;
  • src/AST/Pass.hpp

    r1c507eb r7a80113  
    5050// | PureVisitor           - makes the visitor pure, it never modifies nodes in place and always
    5151//                           clones nodes it needs to make changes to
    52 // | WithTypeSubstitution  - provides polymorphic const TypeSubstitution * env for the
     52// | WithConstTypeSubstitution - provides polymorphic const TypeSubstitution * typeSubs for the
    5353//                           current expression
    5454// | WithStmtsToAdd        - provides the ability to insert statements before or after the current
     
    6767// | WithSymbolTable       - provides symbol table functionality
    6868// | WithForallSubstitutor - maintains links between TypeInstType and TypeDecl under mutation
     69//
     70// Other Special Members:
     71// | result                - Either a method that takes no parameters or a field. If a method (or
     72//                           callable field) get_result calls it, otherwise the value is returned.
    6973//-------------------------------------------------------------------------------------------------
    7074template< typename core_t >
     
    8993        virtual ~Pass() = default;
    9094
     95        /// Storage for the actual pass.
     96        core_t core;
     97
     98        /// If the core defines a result, call it if possible, otherwise return it.
     99        inline auto get_result() -> decltype( __pass::get_result( core, '0' ) ) {
     100                return __pass::get_result( core, '0' );
     101        }
     102
    91103        /// Construct and run a pass on a translation unit.
    92104        template< typename... Args >
     
    96108        }
    97109
     110        /// Contruct and run a pass on a pointer to extract a value.
     111        template< typename node_type, typename... Args >
     112        static auto read( node_type const * node, Args&&... args ) {
     113                Pass<core_t> visitor( std::forward<Args>( args )... );
     114                node_type const * temp = node->accept( visitor );
     115                assert( temp == node );
     116                return visitor.get_result();
     117        }
     118
     119        // Versions of the above for older compilers.
    98120        template< typename... Args >
    99121        static void run( std::list< ptr<Decl> > & decls ) {
     
    102124        }
    103125
    104         /// Storage for the actual pass
    105         core_t core;
     126        template< typename node_type, typename... Args >
     127        static auto read( node_type const * node ) {
     128                Pass<core_t> visitor;
     129                node_type const * temp = node->accept( visitor );
     130                assert( temp == node );
     131                return visitor.get_result();
     132        }
    106133
    107134        /// Visit function declarations
     
    267294//-------------------------------------------------------------------------------------------------
    268295
    269 /// Keep track of the polymorphic const TypeSubstitution * env for the current expression
    270 
    271296/// If used the visitor will always clone nodes.
    272297struct PureVisitor {};
    273298
     299/// Keep track of the polymorphic const TypeSubstitution * typeSubs for the current expression.
    274300struct WithConstTypeSubstitution {
    275         const TypeSubstitution * env = nullptr;
     301        const TypeSubstitution * typeSubs = nullptr;
    276302};
    277303
  • src/AST/Pass.impl.hpp

    r1c507eb r7a80113  
    154154                __pedantic_pass_assert( expr );
    155155
    156                 const ast::TypeSubstitution ** env_ptr = __pass::env( core, 0);
    157                 if ( env_ptr && expr->env ) {
    158                         *env_ptr = expr->env;
     156                const ast::TypeSubstitution ** typeSubs_ptr = __pass::typeSubs( core, 0 );
     157                if ( typeSubs_ptr && expr->env ) {
     158                        *typeSubs_ptr = expr->env;
    159159                }
    160160
     
    177177
    178178                // These may be modified by subnode but most be restored once we exit this statemnet.
    179                 ValueGuardPtr< const ast::TypeSubstitution * > __old_env         ( __pass::env( core, 0) );
     179                ValueGuardPtr< const ast::TypeSubstitution * > __old_env         ( __pass::typeSubs( core, 0 ) );
    180180                ValueGuardPtr< typename std::remove_pointer< decltype(stmts_before) >::type > __old_decls_before( stmts_before );
    181181                ValueGuardPtr< typename std::remove_pointer< decltype(stmts_after ) >::type > __old_decls_after ( stmts_after  );
     
    14881488
    14891489                // These may be modified by subnode but most be restored once we exit this statemnet.
    1490                 ValueGuardPtr< const ast::TypeSubstitution * > __old_env( __pass::env( core, 0) );
     1490                ValueGuardPtr< const ast::TypeSubstitution * > __old_env( __pass::typeSubs( core, 0 ) );
    14911491                ValueGuardPtr< typename std::remove_pointer< decltype(stmts_before) >::type > __old_decls_before( stmts_before );
    14921492                ValueGuardPtr< typename std::remove_pointer< decltype(stmts_after ) >::type > __old_decls_after ( stmts_after  );
  • src/AST/Pass.proto.hpp

    r1c507eb r7a80113  
    236236
    237237        // List of fields and their expected types
    238         FIELD_PTR( env, const ast::TypeSubstitution * )
     238        FIELD_PTR( typeSubs, const ast::TypeSubstitution * )
    239239        FIELD_PTR( stmtsToAddBefore, std::list< ast::ptr< ast::Stmt > > )
    240240        FIELD_PTR( stmtsToAddAfter , std::list< ast::ptr< ast::Stmt > > )
     
    421421
    422422        } // namespace forall
     423
     424        template<typename core_t>
     425        static inline auto get_result( core_t & core, char ) -> decltype( core.result() ) {
     426                return core.result();
     427        }
     428
     429        template<typename core_t>
     430        static inline auto get_result( core_t & core, int ) -> decltype( core.result ) {
     431                return core.result;
     432        }
     433
     434        template<typename core_t>
     435        static inline void get_result( core_t &, long ) {}
    423436} // namespace __pass
    424437} // namespace ast
  • src/AST/Print.cpp

    r1c507eb r7a80113  
    270270        }
    271271
    272         void preprint( const ast::ReferenceToType * node ) {
     272        void preprint( const ast::BaseInstType * node ) {
    273273                print( node->forall );
    274274                print( node->attributes );
  • src/AST/SymbolTable.cpp

    r1c507eb r7a80113  
    313313                if ( ! expr->result ) continue;
    314314                const Type * resTy = expr->result->stripReferences();
    315                 auto aggrType = dynamic_cast< const ReferenceToType * >( resTy );
     315                auto aggrType = dynamic_cast< const BaseInstType * >( resTy );
    316316                assertf( aggrType, "WithStmt expr has non-aggregate type: %s",
    317317                        toString( expr->result ).c_str() );
     
    654654                        if ( dwt->name == "" ) {
    655655                                const Type * t = dwt->get_type()->stripReferences();
    656                                 if ( auto rty = dynamic_cast<const ReferenceToType *>( t ) ) {
     656                                if ( auto rty = dynamic_cast<const BaseInstType *>( t ) ) {
    657657                                        if ( ! dynamic_cast<const StructInstType *>(rty)
    658658                                                && ! dynamic_cast<const UnionInstType *>(rty) ) continue;
  • src/AST/Type.cpp

    r1c507eb r7a80113  
    124124}
    125125
    126 // --- ReferenceToType
    127 
    128 void ReferenceToType::initWithSub( const ReferenceToType & o, Pass< ForallSubstitutor > & sub ) {
     126// --- BaseInstType
     127
     128void BaseInstType::initWithSub( const BaseInstType & o, Pass< ForallSubstitutor > & sub ) {
    129129        ParameterizedType::initWithSub( o, sub ); // initialize substitution
    130130        params = sub.core( o.params );            // apply to parameters
    131131}
    132132
    133 ReferenceToType::ReferenceToType( const ReferenceToType & o )
     133BaseInstType::BaseInstType( const BaseInstType & o )
    134134: ParameterizedType( o.qualifiers, copy( o.attributes ) ), params(), name( o.name ),
    135135  hoistType( o.hoistType ) {
     
    138138}
    139139
    140 std::vector<readonly<Decl>> ReferenceToType::lookup( const std::string& name ) const {
     140std::vector<readonly<Decl>> BaseInstType::lookup( const std::string& name ) const {
    141141        assertf( aggr(), "Must have aggregate to perform lookup" );
    142142
     
    153153SueInstType<decl_t>::SueInstType(
    154154        const decl_t * b, CV::Qualifiers q, std::vector<ptr<Attribute>>&& as )
    155 : ReferenceToType( b->name, q, move(as) ), base( b ) {}
     155: BaseInstType( b->name, q, move(as) ), base( b ) {}
    156156
    157157template<typename decl_t>
     
    168168TraitInstType::TraitInstType(
    169169        const TraitDecl * b, CV::Qualifiers q, std::vector<ptr<Attribute>>&& as )
    170 : ReferenceToType( b->name, q, move(as) ), base( b ) {}
     170: BaseInstType( b->name, q, move(as) ), base( b ) {}
    171171
    172172// --- TypeInstType
    173173
    174174TypeInstType::TypeInstType( const TypeInstType & o )
    175 : ReferenceToType( o.name, o.qualifiers, copy( o.attributes ) ), base(), kind( o.kind ) {
     175: BaseInstType( o.name, o.qualifiers, copy( o.attributes ) ), base(), kind( o.kind ) {
    176176        Pass< ForallSubstitutor > sub;
    177177        initWithSub( o, sub );      // initialize substitution
  • src/AST/Type.hpp

    r1c507eb r7a80113  
    329329
    330330/// base class for types that refer to types declared elsewhere (aggregates and typedefs)
    331 class ReferenceToType : public ParameterizedType {
     331class BaseInstType : public ParameterizedType {
    332332protected:
    333333        /// Initializes forall and parameters based on substitutor
    334         void initWithSub( const ReferenceToType & o, Pass< ForallSubstitutor > & sub );
     334        void initWithSub( const BaseInstType & o, Pass< ForallSubstitutor > & sub );
    335335public:
    336336        std::vector<ptr<Expr>> params;
     
    338338        bool hoistType = false;
    339339
    340         ReferenceToType(
     340        BaseInstType(
    341341                const std::string& n, CV::Qualifiers q = {}, std::vector<ptr<Attribute>> && as = {} )
    342342        : ParameterizedType(q, std::move(as)), params(), name(n) {}
    343343
    344         ReferenceToType( const ReferenceToType & o );
     344        BaseInstType( const BaseInstType & o );
    345345
    346346        /// Gets aggregate declaration this type refers to
     
    350350
    351351private:
    352         virtual ReferenceToType * clone() const override = 0;
     352        virtual BaseInstType * clone() const override = 0;
    353353        MUTATE_FRIEND
    354354};
     
    356356// Common implementation for the SUE instance types. Not to be used directly.
    357357template<typename decl_t>
    358 class SueInstType final : public ReferenceToType {
     358class SueInstType final : public BaseInstType {
    359359public:
    360360        using base_type = decl_t;
     
    363363        SueInstType(
    364364                const std::string& n, CV::Qualifiers q = {}, std::vector<ptr<Attribute>> && as = {} )
    365         : ReferenceToType( n, q, std::move(as) ), base() {}
     365        : BaseInstType( n, q, std::move(as) ), base() {}
    366366
    367367        SueInstType(
     
    388388
    389389/// An instance of a trait type.
    390 class TraitInstType final : public ReferenceToType {
     390class TraitInstType final : public BaseInstType {
    391391public:
    392392        readonly<TraitDecl> base;
     
    394394        TraitInstType(
    395395                const std::string& n, CV::Qualifiers q = {}, std::vector<ptr<Attribute>> && as = {} )
    396         : ReferenceToType( n, q, std::move(as) ), base() {}
     396        : BaseInstType( n, q, std::move(as) ), base() {}
    397397
    398398        TraitInstType(
     
    411411
    412412/// instance of named type alias (typedef or variable)
    413 class TypeInstType final : public ReferenceToType {
     413class TypeInstType final : public BaseInstType {
    414414public:
    415415        readonly<TypeDecl> base;
     
    419419                const std::string& n, const TypeDecl * b, CV::Qualifiers q = {},
    420420                std::vector<ptr<Attribute>> && as = {} )
    421         : ReferenceToType( n, q, std::move(as) ), base( b ), kind( b->kind ) {}
     421        : BaseInstType( n, q, std::move(as) ), base( b ), kind( b->kind ) {}
    422422        TypeInstType( const std::string& n, TypeDecl::Kind k, CV::Qualifiers q = {},
    423423                std::vector<ptr<Attribute>> && as = {} )
    424         : ReferenceToType( n, q, std::move(as) ), base(), kind( k ) {}
     424        : BaseInstType( n, q, std::move(as) ), base(), kind( k ) {}
    425425
    426426        TypeInstType( const TypeInstType & o );
  • src/AST/TypeSubstitution.cpp

    r1c507eb r7a80113  
    176176}
    177177
    178 void TypeSubstitution::Substituter::handleAggregateType( const ReferenceToType * type ) {
     178void TypeSubstitution::Substituter::handleAggregateType( const BaseInstType * type ) {
    179179        GuardValue( boundVars );
    180180        // bind type variables from forall-qualifiers
  • src/AST/TypeSubstitution.hpp

    r1c507eb r7a80113  
    169169                void previsit( const ParameterizedType * type );
    170170                /// Records type variable bindings from forall-statements and instantiations of generic types
    171                 void handleAggregateType( const ReferenceToType * type );
     171                void handleAggregateType( const BaseInstType * type );
    172172
    173173                void previsit( const StructInstType * aggregateUseType );
  • src/Common/Stats/Stats.cc

    r1c507eb r7a80113  
    3535        }
    3636
     37        namespace ResolveTime {
     38                bool enabled = false;
     39        }
     40
    3741        struct {
    3842                const char * const opt;
     
    4347                { "heap"    , Heap::enabled },
    4448                { "time"    , Time::enabled },
     49                { "resolve" , ResolveTime::enabled },
    4550        };
    4651
  • src/Common/module.mk

    r1c507eb r7a80113  
    2222      Common/ErrorObjects.h \
    2323      Common/Eval.cc \
     24      Common/Examine.cc \
     25      Common/Examine.h \
    2426      Common/FilterCombos.h \
    2527      Common/Indenter.h \
     
    3840      Common/Stats/Heap.cc \
    3941      Common/Stats/Heap.h \
     42      Common/Stats/ResolveTime.cc \
     43      Common/Stats/ResolveTime.h \
    4044      Common/Stats/Stats.cc \
    4145      Common/Stats/Time.cc \
  • src/Concurrency/Keywords.cc

    r1c507eb r7a80113  
    1919#include <string>                         // for string, operator==
    2020
     21#include <iostream>
     22
     23#include "Common/Examine.h"               // for isMainFor
    2124#include "Common/PassVisitor.h"           // for PassVisitor
    2225#include "Common/SemanticError.h"         // for SemanticError
     
    3437#include "SynTree/Type.h"                 // for StructInstType, Type, PointerType
    3538#include "SynTree/Visitor.h"              // for Visitor, acceptAll
     39#include "Virtual/Tables.h"
    3640
    3741class Attribute;
    3842
    3943namespace Concurrency {
     44        inline static std::string getVTableName( std::string const & exception_name ) {
     45                return exception_name.empty() ? std::string() : Virtual::vtableTypeName(exception_name);
     46        }
     47
    4048        //=============================================================================================
    4149        // Pass declarations
     
    5462          public:
    5563
    56                 ConcurrentSueKeyword( std::string&& type_name, std::string&& field_name, std::string&& getter_name, std::string&& context_error, bool needs_main, AggregateDecl::Aggregate cast_target ) :
    57                   type_name( type_name ), field_name( field_name ), getter_name( getter_name ), context_error( context_error ), needs_main( needs_main ), cast_target( cast_target ) {}
     64                ConcurrentSueKeyword( std::string&& type_name, std::string&& field_name,
     65                        std::string&& getter_name, std::string&& context_error, std::string&& exception_name,
     66                        bool needs_main, AggregateDecl::Aggregate cast_target ) :
     67                  type_name( type_name ), field_name( field_name ), getter_name( getter_name ),
     68                  context_error( context_error ), vtable_name( getVTableName( exception_name ) ),
     69                  needs_main( needs_main ), cast_target( cast_target ) {}
    5870
    5971                virtual ~ConcurrentSueKeyword() {}
     
    6375
    6476                void handle( StructDecl * );
     77                void addVtableForward( StructDecl * );
    6578                FunctionDecl * forwardDeclare( StructDecl * );
    6679                ObjectDecl * addField( StructDecl * );
     
    7689                const std::string getter_name;
    7790                const std::string context_error;
     91                const std::string vtable_name;
    7892                bool needs_main;
    7993                AggregateDecl::Aggregate cast_target;
     
    8195                StructDecl   * type_decl = nullptr;
    8296                FunctionDecl * dtor_decl = nullptr;
     97                StructDecl * vtable_decl = nullptr;
    8398        };
    8499
     
    101116                        "get_thread",
    102117                        "thread keyword requires threads to be in scope, add #include <thread.hfa>\n",
     118                        "",
    103119                        true,
    104120                        AggregateDecl::Thread
     
    133149                        "get_coroutine",
    134150                        "coroutine keyword requires coroutines to be in scope, add #include <coroutine.hfa>\n",
     151                        "CoroutineCancelled",
    135152                        true,
    136153                        AggregateDecl::Coroutine
     
    167184                        "get_monitor",
    168185                        "monitor keyword requires monitors to be in scope, add #include <monitor.hfa>\n",
     186                        "",
    169187                        false,
    170188                        AggregateDecl::Monitor
     
    198216                        "get_generator",
    199217                        "Unable to find builtin type $generator\n",
     218                        "",
    200219                        true,
    201220                        AggregateDecl::Generator
     
    231250
    232251        private:
    233                 DeclarationWithType * is_main( FunctionDecl * );
    234252                bool is_real_suspend( FunctionDecl * );
    235253
     
    359377                        handle( decl );
    360378                }
     379                else if ( !vtable_decl && vtable_name == decl->name && decl->body ) {
     380                        vtable_decl = decl;
     381                }
     382                // Might be able to get ride of is target.
     383                assert( is_target(decl) == (cast_target == decl->kind) );
    361384                return decl;
    362385        }
    363386
    364387        DeclarationWithType * ConcurrentSueKeyword::postmutate( FunctionDecl * decl ) {
    365                 if( !type_decl ) return decl;
    366                 if( !CodeGen::isDestructor( decl->name ) ) return decl;
    367 
    368                 auto params = decl->type->parameters;
    369                 if( params.size() != 1 ) return decl;
    370 
    371                 auto type = dynamic_cast<ReferenceType*>( params.front()->get_type() );
    372                 if( !type ) return decl;
    373 
    374                 auto stype = dynamic_cast<StructInstType*>( type->base );
    375                 if( !stype ) return decl;
    376                 if( stype->baseStruct != type_decl ) return decl;
    377 
    378                 if( !dtor_decl ) dtor_decl = decl;
     388                if ( type_decl && isDestructorFor( decl, type_decl ) )
     389                        dtor_decl = decl;
     390                else if ( vtable_name.empty() )
     391                        ;
     392                else if ( auto param = isMainFor( decl, cast_target ) ) {
     393                        // This should never trigger.
     394                        assert( vtable_decl );
     395                        // Should be safe because of isMainFor.
     396                        StructInstType * struct_type = static_cast<StructInstType *>(
     397                                static_cast<ReferenceType *>( param->get_type() )->base );
     398                        assert( struct_type );
     399
     400                        declsToAddAfter.push_back( Virtual::makeVtableInstance( vtable_decl, {
     401                                new TypeExpr( struct_type->clone() ),
     402                        }, struct_type, nullptr ) );
     403                }
     404
    379405                return decl;
    380406        }
     
    400426                if( !dtor_decl ) SemanticError( decl, context_error );
    401427
     428                addVtableForward( decl );
    402429                FunctionDecl * func = forwardDeclare( decl );
    403430                ObjectDecl * field = addField( decl );
    404431                addRoutines( field, func );
     432        }
     433
     434        void ConcurrentSueKeyword::addVtableForward( StructDecl * decl ) {
     435                if ( vtable_decl ) {
     436                        declsToAddBefore.push_back( Virtual::makeVtableForward( vtable_decl, {
     437                                new TypeExpr( new StructInstType( noQualifiers, decl ) ),
     438                        } ) );
     439                // Its only an error if we want a vtable and don't have one.
     440                } else if ( ! vtable_name.empty() ) {
     441                        SemanticError( decl, context_error );
     442                }
    405443        }
    406444
     
    528566        // Suspend keyword implementation
    529567        //=============================================================================================
    530         DeclarationWithType * SuspendKeyword::is_main( FunctionDecl * func) {
    531                 if(func->name != "main") return nullptr;
    532                 if(func->type->parameters.size() != 1) return nullptr;
    533 
    534                 auto param = func->type->parameters.front();
    535 
    536                 auto type  = dynamic_cast<ReferenceType * >(param->get_type());
    537                 if(!type) return nullptr;
    538 
    539                 auto obj   = dynamic_cast<StructInstType *>(type->base);
    540                 if(!obj) return nullptr;
    541 
    542                 if(!obj->baseStruct->is_generator()) return nullptr;
    543 
    544                 return param;
    545         }
    546 
    547568        bool SuspendKeyword::is_real_suspend( FunctionDecl * func ) {
    548569                if(isMangled(func->linkage)) return false; // the real suspend isn't mangled
     
    565586
    566587                // Is this the main of a generator?
    567                 auto param = is_main( func );
     588                auto param = isMainFor( func, AggregateDecl::Aggregate::Generator );
    568589                if(!param) return;
    569590
     
    910931                                        {
    911932                                                new SingleInit( new AddressExpr( new VariableExpr( monitors ) ) ),
    912                                                 new SingleInit( new CastExpr( new VariableExpr( func ), generic_func->clone(), false ) )
     933                                                new SingleInit( new CastExpr( new VariableExpr( func ), generic_func->clone(), false ) ),
     934                                                new SingleInit( new ConstantExpr( Constant::from_bool( false ) ) )
    913935                                        },
    914936                                        noDesignators,
     
    10331055// tab-width: 4 //
    10341056// End: //
     1057
  • src/ResolvExpr/CandidateFinder.cpp

    r1c507eb r7a80113  
    816816                /// Adds aggregate member interpretations
    817817                void addAggMembers(
    818                         const ast::ReferenceToType * aggrInst, const ast::Expr * expr,
     818                        const ast::BaseInstType * aggrInst, const ast::Expr * expr,
    819819                        const Candidate & cand, const Cost & addedCost, const std::string & name
    820820                ) {
     
    12631263
    12641264                void postvisit( const ast::UntypedOffsetofExpr * offsetofExpr ) {
    1265                         const ast::ReferenceToType * aggInst;
     1265                        const ast::BaseInstType * aggInst;
    12661266                        if (( aggInst = offsetofExpr->type.as< ast::StructInstType >() )) ;
    12671267                        else if (( aggInst = offsetofExpr->type.as< ast::UnionInstType >() )) ;
  • src/ResolvExpr/ConversionCost.cc

    r1c507eb r7a80113  
    520520                return convertToReferenceCost( src, refType, srcIsLvalue, symtab, env, localPtrsAssignable );
    521521        } else {
    522                 ast::Pass<ConversionCost_new> converter( dst, srcIsLvalue, symtab, env, localConversionCost );
    523                 src->accept( converter );
    524                 return converter.core.cost;
     522                return ast::Pass<ConversionCost_new>::read( src, dst, srcIsLvalue, symtab, env, localConversionCost );
    525523        }
    526524}
     
    563561                        }
    564562                } else {
    565                         ast::Pass<ConversionCost_new> converter( dst, srcIsLvalue, symtab, env, localConversionCost );
    566                         src->accept( converter );
    567                         return converter.core.cost;
     563                        return ast::Pass<ConversionCost_new>::read( src, dst, srcIsLvalue, symtab, env, localConversionCost );
    568564                }
    569565        } else {
  • src/ResolvExpr/ConversionCost.h

    r1c507eb r7a80113  
    8888        static size_t traceId;
    8989        Cost cost;
     90        Cost result() { return cost; }
    9091
    9192        ConversionCost_new( const ast::Type * dst, bool srcIsLvalue, const ast::SymbolTable & symtab,
  • src/ResolvExpr/CurrentObject.cc

    r1c507eb r7a80113  
    923923
    924924        MemberIterator * createMemberIterator( const CodeLocation & loc, const Type * type ) {
    925                 if ( auto aggr = dynamic_cast< const ReferenceToType * >( type ) ) {
     925                if ( auto aggr = dynamic_cast< const BaseInstType * >( type ) ) {
    926926                        if ( auto sit = dynamic_cast< const StructInstType * >( aggr ) ) {
    927927                                return new StructIterator{ loc, sit };
     
    932932                                        dynamic_cast< const EnumInstType * >( type )
    933933                                                || dynamic_cast< const TypeInstType * >( type ),
    934                                         "Encountered unhandled ReferenceToType in createMemberIterator: %s",
     934                                        "Encountered unhandled BaseInstType in createMemberIterator: %s",
    935935                                                toString( type ).c_str() );
    936936                                return new SimpleIterator{ loc, type };
     
    965965                                        DesignatorChain & d = *dit;
    966966                                        PRINT( std::cerr << "____actual: " << t << std::endl; )
    967                                         if ( auto refType = dynamic_cast< const ReferenceToType * >( t ) ) {
     967                                        if ( auto refType = dynamic_cast< const BaseInstType * >( t ) ) {
    968968                                                // concatenate identical field names
    969969                                                for ( const Decl * mem : refType->lookup( nexpr->name ) ) {
  • src/ResolvExpr/Resolver.cc

    r1c507eb r7a80113  
    3838#include "Common/PassVisitor.h"          // for PassVisitor
    3939#include "Common/SemanticError.h"        // for SemanticError
     40#include "Common/Stats/ResolveTime.h"    // for ResolveTime::start(), ResolveTime::stop()
    4041#include "Common/utility.h"              // for ValueGuard, group_iterate
    4142#include "InitTweak/GenInit.h"
     
    965966                /// Finds deleted expressions in an expression tree
    966967                struct DeleteFinder_new final : public ast::WithShortCircuiting {
    967                         const ast::DeletedExpr * delExpr = nullptr;
     968                        const ast::DeletedExpr * result = nullptr;
    968969
    969970                        void previsit( const ast::DeletedExpr * expr ) {
    970                                 if ( delExpr ) { visit_children = false; }
    971                                 else { delExpr = expr; }
     971                                if ( result ) { visit_children = false; }
     972                                else { result = expr; }
    972973                        }
    973974
    974975                        void previsit( const ast::Expr * ) {
    975                                 if ( delExpr ) { visit_children = false; }
     976                                if ( result ) { visit_children = false; }
    976977                        }
    977978                };
     
    980981        /// Check if this expression is or includes a deleted expression
    981982        const ast::DeletedExpr * findDeletedExpr( const ast::Expr * expr ) {
    982                 ast::Pass<DeleteFinder_new> finder;
    983                 expr->accept( finder );
    984                 return finder.core.delExpr;
     983                return ast::Pass<DeleteFinder_new>::read( expr );
    985984        }
    986985
     
    11711170                        const ast::Expr * untyped, const ast::SymbolTable & symtab
    11721171                ) {
    1173                         return findKindExpression( untyped, symtab );
     1172                        Stats::ResolveTime::start( untyped );
     1173                        auto res = findKindExpression( untyped, symtab );
     1174                        Stats::ResolveTime::stop();
     1175                        return res;
    11741176                }
    11751177        } // anonymous namespace
     
    12611263                const ast::ThrowStmt *       previsit( const ast::ThrowStmt * );
    12621264                const ast::CatchStmt *       previsit( const ast::CatchStmt * );
     1265                const ast::CatchStmt *       postvisit( const ast::CatchStmt * );
    12631266                const ast::WaitForStmt *     previsit( const ast::WaitForStmt * );
    12641267
     
    14931496
    14941497        const ast::CatchStmt * Resolver_new::previsit( const ast::CatchStmt * catchStmt ) {
    1495                 // TODO: This will need a fix for the decl/cond scoping problem.
     1498                // Until we are very sure this invarent (ifs that move between passes have thenPart)
     1499                // holds, check it. This allows a check for when to decode the mangling.
     1500                if ( auto ifStmt = catchStmt->body.as<ast::IfStmt>() ) {
     1501                        assert( ifStmt->thenPart );
     1502                }
     1503                // Encode the catchStmt so the condition can see the declaration.
    14961504                if ( catchStmt->cond ) {
    1497                         ast::ptr< ast::Type > boolType = new ast::BasicType{ ast::BasicType::Bool };
    1498                         catchStmt = ast::mutate_field(
    1499                                 catchStmt, &ast::CatchStmt::cond,
    1500                                 findSingleExpression( catchStmt->cond, boolType, symtab ) );
     1505                        ast::CatchStmt * stmt = mutate( catchStmt );
     1506                        stmt->body = new ast::IfStmt( stmt->location, stmt->cond, nullptr, stmt->body );
     1507                        stmt->cond = nullptr;
     1508                        return stmt;
     1509                }
     1510                return catchStmt;
     1511        }
     1512
     1513        const ast::CatchStmt * Resolver_new::postvisit( const ast::CatchStmt * catchStmt ) {
     1514                // Decode the catchStmt so everything is stored properly.
     1515                const ast::IfStmt * ifStmt = catchStmt->body.as<ast::IfStmt>();
     1516                if ( nullptr != ifStmt && nullptr == ifStmt->thenPart ) {
     1517                        assert( ifStmt->cond );
     1518                        assert( ifStmt->elsePart );
     1519                        ast::CatchStmt * stmt = ast::mutate( catchStmt );
     1520                        stmt->cond = ifStmt->cond;
     1521                        stmt->body = ifStmt->elsePart;
     1522                        // ifStmt should be implicately deleted here.
     1523                        return stmt;
    15011524                }
    15021525                return catchStmt;
  • src/SymTab/Mangler.cc

    r1c507eb r7a80113  
    437437                  private:
    438438                        void mangleDecl( const ast::DeclWithType *declaration );
    439                         void mangleRef( const ast::ReferenceToType *refType, std::string prefix );
     439                        void mangleRef( const ast::BaseInstType *refType, std::string prefix );
    440440
    441441                        void printQualifiers( const ast::Type *type );
     
    560560                }
    561561
    562                 void Mangler_new::mangleRef( const ast::ReferenceToType * refType, std::string prefix ) {
     562                void Mangler_new::mangleRef( const ast::BaseInstType * refType, std::string prefix ) {
    563563                        printQualifiers( refType );
    564564
  • src/SymTab/Validate.cc

    r1c507eb r7a80113  
    960960        }
    961961
     962        static bool isNonParameterAttribute( Attribute * attr ) {
     963                static const std::vector<std::string> bad_names = {
     964                        "aligned", "__aligned__",
     965                };
     966                for ( auto name : bad_names ) {
     967                        if ( name == attr->name ) {
     968                                return true;
     969                        }
     970                }
     971                return false;
     972        }
     973
    962974        Type * ReplaceTypedef::postmutate( TypeInstType * typeInst ) {
    963975                // instances of typedef types will come here. If it is an instance
     
    968980                        ret->location = typeInst->location;
    969981                        ret->get_qualifiers() |= typeInst->get_qualifiers();
    970                         // attributes are not carried over from typedef to function parameters/return values
    971                         if ( ! inFunctionType ) {
    972                                 ret->attributes.splice( ret->attributes.end(), typeInst->attributes );
    973                         } else {
    974                                 deleteAll( ret->attributes );
    975                                 ret->attributes.clear();
    976                         }
     982                        // GCC ignores certain attributes if they arrive by typedef, this mimics that.
     983                        if ( inFunctionType ) {
     984                                ret->attributes.remove_if( isNonParameterAttribute );
     985                        }
     986                        ret->attributes.splice( ret->attributes.end(), typeInst->attributes );
    977987                        // place instance parameters on the typedef'd type
    978988                        if ( ! typeInst->parameters.empty() ) {
     
    15081518                }
    15091519
    1510                 void checkGenericParameters( const ast::ReferenceToType * inst ) {
     1520                void checkGenericParameters( const ast::BaseInstType * inst ) {
    15111521                        for ( const ast::Expr * param : inst->params ) {
    15121522                                if ( ! dynamic_cast< const ast::TypeExpr * >( param ) ) {
  • src/Virtual/module.mk

    r1c507eb r7a80113  
    1515###############################################################################
    1616
    17 SRC += Virtual/ExpandCasts.cc Virtual/ExpandCasts.h
     17SRC += Virtual/ExpandCasts.cc Virtual/ExpandCasts.h \
     18        Virtual/Tables.cc Virtual/Tables.h
     19
     20SRCDEMANGLE += Virtual/Tables.cc
Note: See TracChangeset for help on using the changeset viewer.