Changeset 3249dd8


Ignore:
Timestamp:
Nov 11, 2021, 9:43:09 AM (8 months ago)
Author:
Andrew Beach <ajbeach@…>
Branches:
enum, forall-pointer-decay, master
Children:
5dcb881
Parents:
b7fd9daf
Message:

Some clean-up. DeepCopyCore? lost its already tenous reason to be in the header so I moved it.

Location:
src/AST
Files:
1 added
3 edited

Legend:

Unmodified
Added
Removed
  • src/AST/Copy.hpp

    rb7fd9daf r3249dd8  
    1010// Created On       : Wed Jul 10 16:13:00 2019
    1111// Last Modified By : Andrew Beach
    12 // Last Modified On : Fri Jun 19 16:43:00 2020
    13 // Update Count     : 1
     12// Last Modified On : Thr Nov 11  9:22:00 2021
     13// Update Count     : 2
    1414//
    1515
    1616#pragma once
    1717
    18 #include "Decl.hpp"
    19 #include "Expr.hpp"
    20 #include "Pass.hpp"
    21 #include "Stmt.hpp"
    22 #include "Type.hpp"
    23 #include <unordered_set>
    24 #include <unordered_map>
     18#include "Node.hpp"
     19#include <cassert>
    2520
    2621namespace ast {
     
    4338 */
    4439
    45 class DeepCopyCore {
    46         std::unordered_map< const Node *, const Node * > nodeCache;
    47         std::unordered_set< readonly<Node> * > readonlyCache;
    48 
    49         template<typename node_t>
    50         void readonlyInsert( const readonly<node_t> * ptrptr ) {
    51                 readonlyCache.insert( (readonly<Node> *) ptrptr );
    52         }
    53 
    54 public:
    55         template<typename node_t>
    56         const node_t * previsit( const node_t * node ) {
    57                 const node_t * copy = shallowCopy( node );
    58                 nodeCache.insert( std::make_pair( node, copy ) );
    59                 return copy;
    60         }
    61 
    62         void postvisit( const AggregateDecl * node ) {
    63                 readonlyInsert( &node->parent );
    64         }
    65 
    66         void postvisit( const StructInstType * node ) {
    67                 readonlyInsert( &node->base );
    68         }
    69 
    70         void postvisit( const UnionInstType * node ) {
    71                 readonlyInsert( &node->base );
    72         }
    73 
    74         void postvisit( const EnumInstType * node ) {
    75                 readonlyInsert( &node->base );
    76         }
    77 
    78         void postvisit( const TraitInstType * node ) {
    79                 readonlyInsert( &node->base );
    80         }
    81 
    82         void postvisit( const TypeInstType * node ) {
    83                 readonlyInsert( &node->base );
    84         }
    85 
    86         void postvisit( const ImplicitCtorDtorStmt * node ) {
    87                 readonlyInsert( (const readonly<Stmt> *) &node->callStmt );
    88         }
    89 
    90         void postvisit( const StmtExpr * node ) {
    91                 readonlyInsert( &node->resultExpr );
    92         }
    93 
    94         void postvisit( const MemberExpr * node ) {
    95                 readonlyInsert( &node->member );
    96         }
    97 
    98         void postvisit( const VariableExpr * node ) {
    99                 readonlyInsert( &node->var );
    100         }
    101 
    102         void postvisit( const OffsetofExpr * node ) {
    103                 readonlyInsert( &node->member );
    104         }
    105 
    106         void postvisit( const DeletedExpr * node ) {
    107                 readonlyInsert( &node->deleteStmt );
    108         }
    109 
    110         void readonlyUpdates() {
    111                 for ( readonly<Node> * ptr : readonlyCache ) {
    112                         auto it = nodeCache.find( ptr->get() );
    113                         if ( nodeCache.end() != it ) {
    114                                 *ptr = it->second;
    115                         }
    116                 }
    117         }
    118 };
    119 
     40// Implementations:
    12041template<typename node_t>
    12142node_t * shallowCopy( const node_t * localRoot ) {
     
    12344}
    12445
     46Node * deepCopyNode( const Node * node );
     47
    12548template<typename node_t>
    12649node_t * deepCopy( const node_t * localRoot ) {
    127         Pass< DeepCopyCore > dc;
    128         node_t const * newRoot = strict_dynamic_cast<node_t const*>(localRoot->accept( dc ));
    129         dc.core.readonlyUpdates();
    130         return const_cast< node_t * >( newRoot );
     50        return strict_dynamic_cast<node_t *>( deepCopyNode( localRoot ) );
    13151}
    13252
  • src/AST/Expr.hpp

    rb7fd9daf r3249dd8  
    767767
    768768/// An expression which must only be evaluated once
    769 class
    770 UniqueExpr final : public Expr {
     769class UniqueExpr final : public Expr {
    771770        static unsigned long long nextId;
    772771public:
  • src/AST/module.mk

    rb7fd9daf r3249dd8  
    2424        AST/Convert.cpp \
    2525        AST/Convert.hpp \
     26        AST/Copy.cpp \
    2627        AST/Copy.hpp \
    2728        AST/CVQualifiers.hpp \
Note: See TracChangeset for help on using the changeset viewer.