Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/AST/Stmt.cpp

    re9b44489 r87701b6  
    1616#include "Stmt.hpp"
    1717
    18 
    1918#include "DeclReplacer.hpp"
    20 #include "Type.hpp"
    2119
    2220namespace ast {
    2321
    2422// --- CompoundStmt
    25 CompoundStmt::CompoundStmt( const CompoundStmt& other ) : Stmt(other), kids(other.kids) {
    26         // when cloning a compound statement, we may end up cloning declarations which
    27         // are referred to by VariableExprs throughout the block. Cloning a VariableExpr
    28         // does a shallow copy, so the VariableExpr will end up pointing to the original
    29         // declaration. If the original declaration is deleted, e.g. because the original
    30         // CompoundStmt is deleted, then we have a dangling pointer. To avoid this case,
    31         // find all DeclarationWithType nodes (since a VariableExpr must point to a
    32         // DeclarationWithType) in the original CompoundStmt and map them to the cloned
    33         // node in the new CompoundStmt ('this'), then replace the Declarations referred to
    34         // by each VariableExpr according to the constructed map. Note that only the declarations
    35         // in the current level are collected into the map, because child CompoundStmts will
    36         // recursively execute this routine. There may be more efficient ways of doing
    37         // this.
    38         DeclReplacer::DeclMap declMap;
    39         auto origit = other.kids.begin();
    40         for ( const Stmt * s : kids ) {
    41                 assert( origit != other.kids.end() );
    42                 const Stmt * origStmt = *origit++;
    43                 if ( const DeclStmt * declStmt = dynamic_cast< const DeclStmt * >( s ) ) {
    44                         const DeclStmt * origDeclStmt = strict_dynamic_cast< const DeclStmt * >( origStmt );
    45                         if ( const DeclWithType * dwt = dynamic_cast< const DeclWithType * > ( declStmt->decl.get() ) ) {
    46                                 const DeclWithType * origdwt = strict_dynamic_cast< const DeclWithType * > ( origDeclStmt->decl.get() );
    47                                 assert( dwt->name == origdwt->name );
    48                                 declMap[ origdwt ] = dwt;
    49                         } else assert( ! dynamic_cast< const DeclWithType * > ( origDeclStmt->decl.get() ) );
    50                 } else assert( ! dynamic_cast< const DeclStmt * > ( s ) );
    51         }
    52         if ( ! declMap.empty() ) {
    53                 DeclReplacer::replace( this, declMap );
    54         }
     23CompoundStmt::CompoundStmt( const CompoundStmt& o ) : Stmt(o), kids(o.kids) {
     24        assert(!"implemented");
    5525}
    5626
Note: See TracChangeset for help on using the changeset viewer.