Changes in / [54d4c0e:7c608d5]
- Location:
- src
- Files:
-
- 1 deleted
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
src/AST/Node.cpp
r54d4c0e r7c608d5 34 34 template< typename node_t, enum ast::Node::ref_type ref_t > 35 35 void 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); }39 36 40 37 template< typename node_t, enum ast::Node::ref_type ref_t > -
src/AST/Node.hpp
r54d4c0e r7c608d5 46 46 }; 47 47 48 bool unique() const { return strong_count == 1; }49 50 48 private: 51 49 /// Make a copy of this node; should be overridden in subclass with more precise return type … … 58 56 mutable size_t strong_count = 0; 59 57 mutable size_t weak_count = 0; 60 mutable bool was_ever_strong = false;61 58 62 59 void increment(ref_type ref) const { 63 60 switch (ref) { 64 case ref_type::strong: strong_count++; was_ever_strong = true;break;61 case ref_type::strong: strong_count++; break; 65 62 case ref_type::weak : weak_count ++; break; 66 63 } … … 179 176 } 180 177 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; } 186 183 187 184 /// wrapper for convenient access to dynamic_cast 188 185 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); } 190 187 191 188 /// wrapper for convenient access to strict_dynamic_cast … … 211 208 void _inc( const node_t * other ); 212 209 void _dec( const node_t * other ); 213 void _check() const;214 210 215 211 protected: -
src/ResolvExpr/Resolver.cc
r54d4c0e r7c608d5 27 27 #include "typeops.h" // for extractResultType 28 28 #include "Unify.h" // for unify 29 #include "AST/Chain.hpp"30 29 #include "AST/Decl.hpp" 31 30 #include "AST/Init.hpp" … … 408 407 409 408 void Resolver_old::previsit( ObjectDecl * objectDecl ) { 410 // To handle initialization of routine pointers, e.g., int (*fp)(int) = foo(), means that 411 // class-variable initContext is changed multiple time because the LHS is analysed twice. 412 // The second analysis changes initContext because of a function type can contain object 413 // declarations in the return and parameter types. So each value of initContext is 409 // To handle initialization of routine pointers, e.g., int (*fp)(int) = foo(), means that 410 // class-variable initContext is changed multiple time because the LHS is analysed twice. 411 // The second analysis changes initContext because of a function type can contain object 412 // declarations in the return and parameter types. So each value of initContext is 414 413 // retained, so the type on the first analysis is preserved and used for selecting the RHS. 415 414 GuardValue( currentObject ); … … 448 447 449 448 void Resolver_old::postvisit( FunctionDecl * functionDecl ) { 450 // default value expressions have an environment which shouldn't be there and trips up 449 // default value expressions have an environment which shouldn't be there and trips up 451 450 // later passes. 452 451 // xxx - it might be necessary to somehow keep the information from this environment, but I … … 940 939 /////////////////////////////////////////////////////////////////////////// 941 940 942 class Resolver_new final 943 : public ast::WithSymbolTable, public ast::WithGuards, 944 public ast::WithVisitorRef<Resolver_new>, public ast::WithShortCircuiting, 941 class Resolver_new final 942 : public ast::WithSymbolTable, public ast::WithGuards, 943 public ast::WithVisitorRef<Resolver_new>, public ast::WithShortCircuiting, 945 944 public ast::WithStmtsToAdd<> { 946 945 947 946 ast::ptr< ast::Type > functionReturn = nullptr; 948 947 // ast::CurrentObject currentObject = nullptr; 949 948 // bool inEnumDecl = false; 950 949 951 public: 950 public: 952 951 Resolver_new() = default; 953 952 Resolver_new( const ast::SymbolTable & syms ) { symtab = syms; } … … 992 991 993 992 const ast::FunctionDecl * Resolver_new::postvisit( const ast::FunctionDecl * functionDecl ) { 994 // default value expressions have an environment which shouldn't be there and trips up 993 // default value expressions have an environment which shouldn't be there and trips up 995 994 // later passes. 996 995 ast::ptr< ast::FunctionDecl > ret = functionDecl; 997 996 for ( unsigned i = 0; i < functionDecl->type->params.size(); ++i ) { 998 997 const ast::ptr<ast::DeclWithType> & d = functionDecl->type->params[i]; 999 998 1000 999 if ( const ast::ObjectDecl * obj = d.as< ast::ObjectDecl >() ) { 1001 1000 if ( const ast::SingleInit * init = obj->init.as< ast::SingleInit >() ) { 1002 1001 if ( init->value->env == nullptr ) continue; 1003 1002 // clone initializer minus the initializer environment 1004 ast::chain_mutate( ret ) 1005 ( &ast::FunctionDecl::type ) 1006 ( &ast::FunctionType::params ) 1007 [i] 1008 ( &ast::ObjectDecl::init ) 1009 ( &ast::SingleInit::value )->env = nullptr; 1010 1011 assert( functionDecl != ret.get() || functionDecl->unique() ); 1012 assert( ! ret->type->params[i].strict_as< ast::ObjectDecl >()->init.strict_as< ast::SingleInit >()->value->env ); 1003 strict_dynamic_cast< ast::SingleInit * >( 1004 strict_dynamic_cast< ast::ObjectDecl * >( 1005 ret.get_and_mutate()->type.get_and_mutate()->params[i].get_and_mutate() 1006 )->init.get_and_mutate() 1007 )->value.get_and_mutate()->env = nullptr; 1013 1008 } 1014 1009 } -
src/SynTree/DeclReplacer.cc
r54d4c0e r7c608d5 30 30 bool debug; 31 31 public: 32 size_t replaced;33 34 public:35 32 DeclReplacer( const DeclMap & declMap, const TypeMap & typeMap, bool debug = false ); 36 33 … … 48 45 bool debug; 49 46 public: 50 size_t replaced;51 52 public:53 47 ExprDeclReplacer( const ExprMap & exprMap, bool debug = false ); 54 48 … … 58 52 } 59 53 60 size_treplace( BaseSyntaxNode * node, const DeclMap & declMap, const TypeMap & typeMap, bool debug ) {54 void replace( BaseSyntaxNode * node, const DeclMap & declMap, const TypeMap & typeMap, bool debug ) { 61 55 PassVisitor<DeclReplacer> replacer( declMap, typeMap, debug ); 62 56 maybeAccept( node, replacer ); 63 return replacer.pass.replaced;64 57 } 65 58 66 size_treplace( BaseSyntaxNode * node, const DeclMap & declMap, bool debug ) {59 void replace( BaseSyntaxNode * node, const DeclMap & declMap, bool debug ) { 67 60 TypeMap typeMap; 68 re turn replace( node, declMap, typeMap, debug );61 replace( node, declMap, typeMap, debug ); 69 62 } 70 63 71 size_treplace( BaseSyntaxNode * node, const TypeMap & typeMap, bool debug ) {64 void replace( BaseSyntaxNode * node, const TypeMap & typeMap, bool debug ) { 72 65 DeclMap declMap; 73 re turn replace( node, declMap, typeMap, debug );66 replace( node, declMap, typeMap, debug ); 74 67 } 75 68 76 size_treplace( BaseSyntaxNode *& node, const ExprMap & exprMap, bool debug ) {69 void replace( BaseSyntaxNode *& node, const ExprMap & exprMap, bool debug ) { 77 70 PassVisitor<ExprDeclReplacer> replacer( exprMap, debug ); 78 71 node = maybeMutate( node, replacer ); 79 return replacer.pass.replaced;80 72 } 81 73 82 74 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 ) {} 84 76 85 77 // replace variable with new node from decl map … … 87 79 // 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) 88 80 if ( declMap.count( varExpr->var ) ) { 89 replaced++;90 81 auto replacement = declMap.at( varExpr->var ); 91 82 if ( debug ) { … … 98 89 void DeclReplacer::previsit( TypeInstType * inst ) { 99 90 if ( typeMap.count( inst->baseType ) ) { 100 replaced++;101 91 auto replacement = typeMap.at( inst->baseType ); 102 92 if ( debug ) { … … 107 97 } 108 98 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 ) {} 110 100 111 101 Expression * ExprDeclReplacer::postmutate( VariableExpr * varExpr ) { 112 102 if ( exprMap.count( varExpr->var ) ) { 113 replaced++;114 103 Expression * replacement = exprMap.at( varExpr->var )->clone(); 115 104 if ( debug ) { -
src/SynTree/DeclReplacer.h
r54d4c0e r7c608d5 28 28 typedef std::map< DeclarationWithType *, Expression * > ExprMap; 29 29 30 size_treplace( BaseSyntaxNode * node, const DeclMap & declMap, bool debug = false );31 size_treplace( BaseSyntaxNode * node, const TypeMap & typeMap, bool debug = false );32 size_treplace( 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 ); 33 33 34 size_treplace( BaseSyntaxNode *& node, const ExprMap & exprMap, bool debug = false);34 void replace( BaseSyntaxNode *& node, const ExprMap & exprMap, bool debug = false); 35 35 template<typename T> 36 36 void replace( T *& node, const ExprMap & exprMap, bool debug = false ) {
Note: See TracChangeset
for help on using the changeset viewer.