Changes in / [3cd5fdd:99d4584]


Ignore:
Location:
src
Files:
1 deleted
8 edited

Legend:

Unmodified
Added
Removed
  • src/AST/Convert.cpp

    r3cd5fdd r99d4584  
    749749                        break;
    750750                case ast::ConstantExpr::String:
    751                         rslt = new ConstantExpr{Constant{
    752                                 get<Type>().accept1( node->result ),
    753                                 node->rep,
    754                                 (long long unsigned int)0
    755                         }};
     751                        rslt = new ConstantExpr{Constant::from_string( node->rep )};
    756752                        break;
    757753                }
     
    21542150                                GET_ACCEPT_1(result, Type),
    21552151                                old->constant.get_value(),
    2156                                 (unsigned long long) old->intValue(),
    2157                                 ast::ConstantExpr::Kind::Integer
     2152                                (unsigned long long) old->intValue()
    21582153                        );
    21592154                } else if (isFloatlikeConstantType(old->result)) {
     
    21652160                        );
    21662161                } else if (isStringlikeConstantType(old->result)) {
    2167                         rslt = new ast::ConstantExpr(
    2168                                 old->location,
    2169                                 GET_ACCEPT_1(result, Type),
    2170                                 old->constant.get_value(),
    2171                                 0,
    2172                                 ast::ConstantExpr::Kind::String
     2162                        rslt = ast::ConstantExpr::from_string(
     2163                                old->location,
     2164                                old->constant.get_value()
    21732165                        );
    21742166                }
  • src/AST/Node.cpp

    r3cd5fdd r99d4584  
    3434template< typename node_t, enum ast::Node::ref_type ref_t >
    3535void ast::ptr_base<node_t, ref_t>::_dec( const node_t * node ) { node->decrement(ref_t); }
    36 
    37 template< typename node_t, enum ast::Node::ref_type ref_t >
    38 void ast::ptr_base<node_t, ref_t>::_check() const { if(node) assert(node->was_ever_strong == false || node->strong_count > 0); }
    3936
    4037template< typename node_t, enum ast::Node::ref_type ref_t >
  • src/AST/Node.hpp

    r3cd5fdd r99d4584  
    4646        };
    4747
    48         bool unique() const { return strong_count == 1; }
    49 
    5048private:
    5149        /// Make a copy of this node; should be overridden in subclass with more precise return type
     
    5856        mutable size_t strong_count = 0;
    5957        mutable size_t weak_count = 0;
    60         mutable bool was_ever_strong = false;
    6158
    6259        void increment(ref_type ref) const {
    6360                switch (ref) {
    64                         case ref_type::strong: strong_count++; was_ever_strong = true; break;
     61                        case ref_type::strong: strong_count++; break;
    6562                        case ref_type::weak  : weak_count  ++; break;
    6663                }
     
    179176        }
    180177
    181         const node_t * get() const { _check(); return  node; }
    182         const node_t * operator->() const { _check(); return  node; }
    183         const node_t & operator* () const { _check(); return *node; }
    184         explicit operator bool() const { _check(); return node; }
    185         operator const node_t * () const { _check(); return node; }
     178        const node_t * get() const { return  node; }
     179        const node_t * operator->() const { return  node; }
     180        const node_t & operator* () const { return *node; }
     181        explicit operator bool() const { return node; }
     182        operator const node_t * () const { return node; }
    186183
    187184        /// wrapper for convenient access to dynamic_cast
    188185        template<typename o_node_t>
    189         const o_node_t * as() const { _check(); return dynamic_cast<const o_node_t *>(node); }
     186        const o_node_t * as() const { return dynamic_cast<const o_node_t *>(node); }
    190187
    191188        /// wrapper for convenient access to strict_dynamic_cast
     
    211208        void _inc( const node_t * other );
    212209        void _dec( const node_t * other );
    213         void _check() const;
    214210
    215211protected:
  • src/ResolvExpr/Resolver.cc

    r3cd5fdd r99d4584  
    2929#include "typeops.h"                     // for extractResultType
    3030#include "Unify.h"                       // for unify
    31 #include "AST/Chain.hpp"
    3231#include "AST/Decl.hpp"
    3332#include "AST/Init.hpp"
     
    411410
    412411        void Resolver_old::previsit( ObjectDecl * objectDecl ) {
    413                 // To handle initialization of routine pointers, e.g., int (*fp)(int) = foo(), means that
    414                 // class-variable initContext is changed multiple time because the LHS is analysed twice.
    415                 // The second analysis changes initContext because of a function type can contain object
    416                 // declarations in the return and parameter types. So each value of initContext is
     412                // To handle initialization of routine pointers, e.g., int (*fp)(int) = foo(), means that 
     413                // class-variable initContext is changed multiple time because the LHS is analysed twice. 
     414                // The second analysis changes initContext because of a function type can contain object 
     415                // declarations in the return and parameter types. So each value of initContext is 
    417416                // retained, so the type on the first analysis is preserved and used for selecting the RHS.
    418417                GuardValue( currentObject );
     
    451450
    452451        void Resolver_old::postvisit( FunctionDecl * functionDecl ) {
    453                 // default value expressions have an environment which shouldn't be there and trips up
     452                // default value expressions have an environment which shouldn't be there and trips up 
    454453                // later passes.
    455454                // xxx - it might be necessary to somehow keep the information from this environment, but I
     
    11191118        }
    11201119
    1121         class Resolver_new final
    1122         : public ast::WithSymbolTable, public ast::WithGuards,
    1123           public ast::WithVisitorRef<Resolver_new>, public ast::WithShortCircuiting,
     1120        class Resolver_new final 
     1121        : public ast::WithSymbolTable, public ast::WithGuards, 
     1122          public ast::WithVisitorRef<Resolver_new>, public ast::WithShortCircuiting, 
    11241123          public ast::WithStmtsToAdd<> {
    1125 
     1124       
    11261125                ast::ptr< ast::Type > functionReturn = nullptr;
    11271126                // ast::CurrentObject currentObject = nullptr;
    11281127                bool inEnumDecl = false;
    11291128
    1130         public:
     1129        public: 
    11311130                Resolver_new() = default;
    11321131                Resolver_new( const ast::SymbolTable & syms ) { symtab = syms; }
     
    11711170
    11721171        const ast::FunctionDecl * Resolver_new::postvisit( const ast::FunctionDecl * functionDecl ) {
    1173                 // default value expressions have an environment which shouldn't be there and trips up
     1172                // default value expressions have an environment which shouldn't be there and trips up 
    11741173                // later passes.
    11751174                ast::ptr< ast::FunctionDecl > ret = functionDecl;
    11761175                for ( unsigned i = 0; i < functionDecl->type->params.size(); ++i ) {
    11771176                        const ast::ptr<ast::DeclWithType> & d = functionDecl->type->params[i];
    1178 
     1177                       
    11791178                        if ( const ast::ObjectDecl * obj = d.as< ast::ObjectDecl >() ) {
    11801179                                if ( const ast::SingleInit * init = obj->init.as< ast::SingleInit >() ) {
    11811180                                        if ( init->value->env == nullptr ) continue;
    11821181                                        // clone initializer minus the initializer environment
    1183                                         ast::chain_mutate( ret )
    1184                                                 ( &ast::FunctionDecl::type )
    1185                                                         ( &ast::FunctionType::params )[i]
    1186                                                                 ( &ast::ObjectDecl::init )
    1187                                                                         ( &ast::SingleInit::value )->env = nullptr;
    1188 
    1189                                         assert( functionDecl != ret.get() || functionDecl->unique() );
    1190                                         assert( ! ret->type->params[i].strict_as< ast::ObjectDecl >()->init.strict_as< ast::SingleInit >()->value->env );
     1182                                        strict_dynamic_cast< ast::SingleInit * >(
     1183                                                strict_dynamic_cast< ast::ObjectDecl * >(
     1184                                                        ret.get_and_mutate()->type.get_and_mutate()->params[i].get_and_mutate()
     1185                                                )->init.get_and_mutate()
     1186                                        )->value.get_and_mutate()->env = nullptr;
    11911187                                }
    11921188                        }
  • src/SynTree/BaseSyntaxNode.h

    r3cd5fdd r99d4584  
    4141  /// * Expressions should not finish with a newline, since the expression's parent has better information.
    4242        virtual void print( std::ostream & os, Indenter indent = {} ) const = 0;
     43  // void print( std::ostream & os, unsigned int indent ) {
     44  //   print( os, Indenter{ indent });
     45  // }
    4346};
    4447
  • src/SynTree/DeclReplacer.cc

    r3cd5fdd r99d4584  
    3030                        bool debug;
    3131                public:
    32                         size_t replaced;
    33 
    34                 public:
    3532                        DeclReplacer( const DeclMap & declMap, const TypeMap & typeMap, bool debug = false );
    3633
     
    4845                        bool debug;
    4946                public:
    50                         size_t replaced;
    51 
    52                 public:
    5347                        ExprDeclReplacer( const ExprMap & exprMap, bool debug = false );
    5448
     
    5852        }
    5953
    60         size_t replace( BaseSyntaxNode * node, const DeclMap & declMap, const TypeMap & typeMap, bool debug ) {
     54        void replace( BaseSyntaxNode * node, const DeclMap & declMap, const TypeMap & typeMap, bool debug ) {
    6155                PassVisitor<DeclReplacer> replacer( declMap, typeMap, debug );
    6256                maybeAccept( node, replacer );
    63                 return replacer.pass.replaced;
    6457        }
    6558
    66         size_t replace( BaseSyntaxNode * node, const DeclMap & declMap, bool debug ) {
     59        void replace( BaseSyntaxNode * node, const DeclMap & declMap, bool debug ) {
    6760                TypeMap typeMap;
    68                 return replace( node, declMap, typeMap, debug );
     61                replace( node, declMap, typeMap, debug );
    6962        }
    7063
    71         size_t replace( BaseSyntaxNode * node, const TypeMap & typeMap, bool debug ) {
     64        void replace( BaseSyntaxNode * node, const TypeMap & typeMap, bool debug ) {
    7265                DeclMap declMap;
    73                 return replace( node, declMap, typeMap, debug );
     66                replace( node, declMap, typeMap, debug );
    7467        }
    7568
    76         size_t replace( BaseSyntaxNode *& node, const ExprMap & exprMap, bool debug ) {
     69        void replace( BaseSyntaxNode *& node, const ExprMap & exprMap, bool debug ) {
    7770                PassVisitor<ExprDeclReplacer> replacer( exprMap, debug );
    7871                node = maybeMutate( node, replacer );
    79                 return replacer.pass.replaced;
    8072        }
    8173
    8274        namespace {
    83                 DeclReplacer::DeclReplacer( const DeclMap & declMap, const TypeMap & typeMap, bool debug ) : declMap( declMap ), typeMap( typeMap ) , debug( debug ), replaced( 0 ) {}
     75                DeclReplacer::DeclReplacer( const DeclMap & declMap, const TypeMap & typeMap, bool debug ) : declMap( declMap ), typeMap( typeMap ) , debug( debug ) {}
    8476
    8577                // replace variable with new node from decl map
     
    8779                        // xxx - assertions and parameters aren't accounted for in this... (i.e. they aren't inserted into the map when it's made, only DeclStmts are)
    8880                        if ( declMap.count( varExpr->var ) ) {
    89                                 replaced++;
    9081                                auto replacement = declMap.at( varExpr->var );
    9182                                if ( debug ) {
     
    9889                void DeclReplacer::previsit( TypeInstType * inst ) {
    9990                        if ( typeMap.count( inst->baseType ) ) {
    100                                 replaced++;
    10191                                auto replacement = typeMap.at( inst->baseType );
    10292                                if ( debug ) {
     
    10797                }
    10898
    109                 ExprDeclReplacer::ExprDeclReplacer( const ExprMap & exprMap, bool debug ) : exprMap( exprMap ), debug( debug ), replaced( 0 ) {}
     99                ExprDeclReplacer::ExprDeclReplacer( const ExprMap & exprMap, bool debug ) : exprMap( exprMap ), debug( debug ) {}
    110100
    111101                Expression * ExprDeclReplacer::postmutate( VariableExpr * varExpr ) {
    112102                        if ( exprMap.count( varExpr->var ) ) {
    113                                 replaced++;
    114103                                Expression * replacement = exprMap.at( varExpr->var )->clone();
    115104                                if ( debug ) {
  • src/SynTree/DeclReplacer.h

    r3cd5fdd r99d4584  
    2828        typedef std::map< DeclarationWithType *, Expression * > ExprMap;
    2929
    30         size_t replace( BaseSyntaxNode * node, const DeclMap & declMap, bool debug = false );
    31         size_t replace( BaseSyntaxNode * node, const TypeMap & typeMap, bool debug = false );
    32         size_t replace( BaseSyntaxNode * node, const DeclMap & declMap, const TypeMap & typeMap, bool debug = false );
     30        void replace( BaseSyntaxNode * node, const DeclMap & declMap, bool debug = false );
     31        void replace( BaseSyntaxNode * node, const TypeMap & typeMap, bool debug = false );
     32        void replace( BaseSyntaxNode * node, const DeclMap & declMap, const TypeMap & typeMap, bool debug = false );
    3333
    34         size_t replace( BaseSyntaxNode *& node, const ExprMap & exprMap, bool debug = false);
     34        void replace( BaseSyntaxNode *& node, const ExprMap & exprMap, bool debug = false);
    3535        template<typename T>
    3636                void replace( T *& node, const ExprMap & exprMap, bool debug = false ) {
  • src/main.cc

    r3cd5fdd r99d4584  
    1010// Created On       : Fri May 15 23:12:02 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Wed Jun  5 13:48:41 2019
    13 // Update Count     : 600
     12// Last Modified On : Fri May  3 16:10:52 2019
     13// Update Count     : 599
    1414//
    1515
     
    406406
    407407
    408 static const char optstring[] = ":hlLmNnpP:S:twW:D:F:";
     408static const char optstring[] = ":hlLmNn:pP:S:twW:D:F:";
    409409
    410410enum { PreludeDir = 128 };
Note: See TracChangeset for help on using the changeset viewer.