Changes in / [6380f78:d8938622]


Ignore:
Location:
src
Files:
1 deleted
10 edited

Legend:

Unmodified
Added
Removed
  • src/AST/Convert.cpp

    r6380f78 rd8938622  
    13261326
    13271327        const ast::Attribute * visit( const ast::Attribute * node ) override final {
    1328                 auto attr = new Attribute(
    1329                         node->name,
    1330                         get<Expression>().acceptL(node->parameters)
    1331                 );
    1332                 this->node = attr;
     1328                (void)node;
    13331329                return nullptr;
    13341330        }
    13351331
    13361332        const ast::TypeSubstitution * visit( const ast::TypeSubstitution * node ) override final {
    1337                 // Handled by convertTypeSubstitution helper instead.
    1338                 // TypeSubstitution is not a node in the old model, so the conversion result wouldn't fit in this->node.
    1339                 assert( 0 );
     1333                (void)node;
    13401334                return nullptr;
    13411335        }
     
    26762670
    26772671        virtual void visit( Constant * ) override final {
    2678                 // Handled in visit( ConstantEpxr * ).
    2679                 // In the new tree, Constant fields are inlined into containing ConstantExpression.
     2672
     2673        }
     2674
     2675        virtual void visit( Attribute * ) override final {
     2676
     2677        }
     2678
     2679        virtual void visit( AttrExpr * ) override final {
     2680
    26802681                assert( 0 );
    2681         }
    2682 
    2683         virtual void visit( Attribute * old ) override final {
    2684                 this->node = new ast::Attribute(
    2685                         old->name,
    2686                         GET_ACCEPT_V( parameters, Expr )
    2687                 );
    2688         }
    2689 
    2690         virtual void visit( AttrExpr * ) override final {
    2691                 assertf( false, "AttrExpr deprecated in new AST." );
    26922682        }
    26932683};
  • src/AST/Decl.hpp

    r6380f78 rd8938622  
    232232        AggregateDecl* set_body( bool b ) { body = b; return this; }
    233233
     234private:
     235        AggregateDecl * clone() const override = 0;
     236        MUTATE_FRIEND
     237
     238protected:
    234239        /// Produces a name for the kind of aggregate
    235240        virtual std::string typeString() const = 0;
    236 
    237 private:
    238         AggregateDecl * clone() const override = 0;
    239         MUTATE_FRIEND
    240241};
    241242
     
    255256
    256257        const Decl * accept( Visitor & v ) const override { return v.visit( this ); }
     258private:
     259        StructDecl * clone() const override { return new StructDecl{ *this }; }
     260        MUTATE_FRIEND
    257261
    258262        std::string typeString() const override { return "struct"; }
    259 
    260 private:
    261         StructDecl * clone() const override { return new StructDecl{ *this }; }
    262         MUTATE_FRIEND
    263263};
    264264
     
    271271
    272272        const Decl * accept( Visitor& v ) const override { return v.visit( this ); }
     273private:
     274        UnionDecl * clone() const override { return new UnionDecl{ *this }; }
     275        MUTATE_FRIEND
    273276
    274277        std::string typeString() const override { return "union"; }
    275 
    276 private:
    277         UnionDecl * clone() const override { return new UnionDecl{ *this }; }
    278         MUTATE_FRIEND
    279278};
    280279
     
    290289
    291290        const Decl * accept( Visitor & v ) const override { return v.visit( this ); }
     291private:
     292        EnumDecl * clone() const override { return new EnumDecl{ *this }; }
     293        MUTATE_FRIEND
    292294
    293295        std::string typeString() const override { return "enum"; }
    294 
    295 private:
    296         EnumDecl * clone() const override { return new EnumDecl{ *this }; }
    297         MUTATE_FRIEND
    298296
    299297        /// Map from names to enumerator values; kept private for lazy initialization
     
    309307
    310308        const Decl * accept( Visitor & v ) const override { return v.visit( this ); }
     309private:
     310        TraitDecl * clone() const override { return new TraitDecl{ *this }; }
     311        MUTATE_FRIEND
    311312
    312313        std::string typeString() const override { return "trait"; }
    313 
    314 private:
    315         TraitDecl * clone() const override { return new TraitDecl{ *this }; }
    316         MUTATE_FRIEND
    317314};
    318315
  • src/AST/DeclReplacer.cpp

    r6380f78 rd8938622  
    1414//
    1515
    16 #include "DeclReplacer.hpp"
    17 #include "Expr.hpp"
    18 #include "Type.hpp"
    19 
    20 #include "Pass.hpp"
    21 
    22 namespace ast {
    23 
    24 namespace DeclReplacer {
    25         namespace {
    26                 struct DeclReplacer {
    27                 private:
    28                         const DeclMap & declMap;
    29                         const TypeMap & typeMap;
    30                         bool debug;
    31 
    32                 public:
    33                         DeclReplacer(const DeclMap & declMap, const TypeMap & typeMap, bool debug)
    34                                 : declMap( declMap ), typeMap( typeMap ), debug( debug )
    35                         {}
    36 
    37                         const ast::VariableExpr * previsit( const ast::VariableExpr * );
    38                         const ast::TypeInstType * previsit( const ast::TypeInstType * );
    39                 };
    40         }
    41 
    42         const ast::Node * replace( const ast::Node * node, const DeclMap & declMap, const TypeMap & typeMap, bool debug ) {
    43                 if(!node) return nullptr;
    44                 Pass<DeclReplacer> replacer = { declMap, typeMap, debug };
    45                 return node->accept( replacer );
    46         }
    47 
    48         const ast::Node * replace( const ast::Node * node, const DeclMap & declMap, bool debug ) {
    49                 TypeMap typeMap;
    50                 return replace( node, declMap, typeMap, debug );
    51         }
    52 
    53         const ast::Node * replace( const ast::Node * node, const TypeMap & typeMap, bool debug ) {
    54                 DeclMap declMap;
    55                 return replace( node, declMap, typeMap, debug );
    56         }
    57 
    58         namespace {
    59                 // replace variable with new node from decl map
    60                 const ast::VariableExpr * DeclReplacer::previsit( const VariableExpr * varExpr ) {
    61                         // 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)
    62                         if ( !declMap.count( varExpr->var ) ) return varExpr;
    63 
    64                         auto replacement = declMap.at( varExpr->var );
    65                         if ( debug ) {
    66                                 std::cerr << "replacing variable reference: "
    67                                         << (void*)varExpr->var.get() << " " << varExpr->var
    68                                         << " with " << (void*)replacement << " " << replacement
    69                                         << std::endl;
    70                         }
    71                         auto nexpr = mutate(varExpr);
    72                         nexpr->var = replacement;
    73                         return nexpr;
    74                 }
    75 
    76                 const TypeInstType * DeclReplacer::previsit( const TypeInstType * inst ) {
    77                         if ( !typeMap.count( inst->base ) ) return inst;
    78 
    79                         auto replacement = typeMap.at( inst->base );
    80                         if ( debug ) {
    81                                 std::cerr << "replacing type reference: "
    82                                         << (void*)inst->base.get() << " " << inst->base
    83                                         << " with " << (void*)replacement << " " << replacement
    84                                         << std::endl;
    85                         }
    86                         auto ninst = mutate(inst);
    87                         ninst->base = replacement;
    88                         return ninst;
    89                 }
    90         }
    91 }
    92 
    93 }
     16#warning unimplemented
    9417
    9518// Local Variables: //
  • src/AST/DeclReplacer.hpp

    r6380f78 rd8938622  
    2525
    2626        namespace DeclReplacer {
    27                 using DeclMap = std::unordered_map< const DeclWithType *, const DeclWithType * >;
    28                 using TypeMap = std::unordered_map< const TypeDecl *, const TypeDecl * >;
     27                using DeclMap = std::unordered_map< DeclWithType*, DeclWithType* >;
     28                using TypeMap = std::unordered_map< TypeDecl*, TypeDecl* >;
    2929
    30                 const Node * replace( const Node * node, const DeclMap & declMap, bool debug = false );
    31                 const Node * replace( const Node * node, const TypeMap & typeMap, bool debug = false );
    32                 const Node * replace( const Node * node, const DeclMap & declMap, const TypeMap & typeMap, bool debug = false );
     30                void replace( Node* node, const DeclMap& declMap );
     31                void replace( Node* node, const TypeMap& typeMap );
     32                void replace( Node* node, const DeclMap& declMap, const TypeMap& typeMap );
    3333        }
    3434}
  • src/AST/Pass.impl.hpp

    r6380f78 rd8938622  
    841841                for( const auto & clause : node->clauses ) {
    842842
    843                         const Expr * func = clause.target.func ? clause.target.func->accept(*this) : nullptr;
     843                        Expr * func = clause.target.func ? clause.target.func->accept(*this) : nullptr;
    844844                        if(func != clause.target.func) mutated = true;
    845845
     
    852852                        }
    853853
    854                         const Stmt * stmt = clause.stmt ? clause.stmt->accept(*this) : nullptr;
     854                        Stmt * stmt = clause.stmt ? clause.stmt->accept(*this) : nullptr;
    855855                        if(stmt != clause.stmt) mutated = true;
    856856
    857                         const Expr * cond = clause.cond ? clause.cond->accept(*this) : nullptr;
     857                        Expr * cond = clause.cond ? clause.cond->accept(*this) : nullptr;
    858858                        if(cond != clause.cond) mutated = true;
    859859
     
    15671567                bool mutated = false;
    15681568                for( const auto & assoc : node->associations ) {
    1569                         const Type * type = nullptr;
     1569                        Type * type = nullptr;
    15701570                        if( assoc.type ) {
    15711571                                guard_indexer guard { *this };
     
    15731573                                if( type != assoc.type ) mutated = true;
    15741574                        }
    1575                         const Expr * expr = nullptr;
     1575                        Expr * expr = nullptr;
    15761576                        if( assoc.expr ) {
    15771577                                expr = assoc.expr->accept( *this );
     
    16851685        VISIT_START( node );
    16861686
    1687         __pass::indexer::addStruct( pass, 0, node->name );
     1687        __pass::indexer::addStruct( node->name, 0, pass );
    16881688
    16891689        VISIT({
     
    17021702        VISIT_START( node );
    17031703
    1704         __pass::indexer::addStruct( pass, 0, node->name );
     1704        __pass::indexer::addStruct( node->name, 0, pass );
    17051705
    17061706        {
     
    18851885}
    18861886
    1887 //--------------------------------------------------------------------------
    1888 // TypeSubstitution
    1889 template< typename pass_t >
    1890 const ast::TypeSubstitution * ast::Pass< pass_t >::visit( const ast::TypeSubstitution * node ) {
    1891         VISIT_START( node );
    1892 
    1893         VISIT(
    1894                 {
    1895                         bool mutated = false;
    1896                         std::unordered_map< std::string, ast::ptr< ast::Type > > new_map;
    1897                         for ( const auto & p : node->typeEnv ) {
    1898                                 guard_indexer guard { *this };
    1899                                 auto new_node = p.second->accept( *this );
    1900                                 if (new_node != p.second) mutated = false;
    1901                                 new_map.insert({ p.first, new_node });
    1902                         }
    1903                         if (mutated) {
    1904                                 auto new_node = mutate( node );
    1905                                 new_node->typeEnv.swap( new_map );
    1906                                 node = new_node;
    1907                         }
    1908                 }
    1909 
    1910                 {
    1911                         bool mutated = false;
    1912                         std::unordered_map< std::string, ast::ptr< ast::Expr > > new_map;
    1913                         for ( const auto & p : node->varEnv ) {
    1914                                 guard_indexer guard { *this };
    1915                                 auto new_node = p.second->accept( *this );
    1916                                 if (new_node != p.second) mutated = false;
    1917                                 new_map.insert({ p.first, new_node });
    1918                         }
    1919                         if (mutated) {
    1920                                 auto new_node = mutate( node );
    1921                                 new_node->varEnv.swap( new_map );
    1922                                 node = new_node;
    1923                         }
    1924                 }
    1925         )
    1926 
    1927         VISIT_END( TypeSubstitution, node );
    1928 }
     1887// //--------------------------------------------------------------------------
     1888// // TypeSubstitution
     1889// template< typename pass_t >
     1890// const ast::TypeSubstitution * ast::Pass< pass_t >::visit( const ast::TypeSubstitution * node ) {
     1891//      VISIT_START( node );
     1892
     1893//      VISIT(
     1894//              {
     1895//                      bool mutated = false;
     1896//                      std::unordered_map< std::string, ast::ptr< ast::Type > > new_map;
     1897//                      for ( const auto & p : node->typeEnv ) {
     1898//                              guard_indexer guard { *this };
     1899//                              auto new_node = p.second->accept( *this );
     1900//                              if (new_node != p.second) mutated = false;
     1901//                              new_map.insert({ p.first, new_node });
     1902//                      }
     1903//                      if (mutated) {
     1904//                              auto new_node = mutate( node );
     1905//                              new_node->typeEnv.swap( new_map );
     1906//                              node = new_node;
     1907//                      }
     1908//              }
     1909
     1910//              {
     1911//                      bool mutated = false;
     1912//                      std::unordered_map< std::string, ast::ptr< ast::Expr > > new_map;
     1913//                      for ( const auto & p : node->varEnv ) {
     1914//                              guard_indexer guard { *this };
     1915//                              auto new_node = p.second->accept( *this );
     1916//                              if (new_node != p.second) mutated = false;
     1917//                              new_map.insert({ p.first, new_node });
     1918//                      }
     1919//                      if (mutated) {
     1920//                              auto new_node = mutate( node );
     1921//                              new_node->varEnv.swap( new_map );
     1922//                              node = new_node;
     1923//                      }
     1924//              }
     1925//      )
     1926
     1927//      VISIT_END( TypeSubstitution, node );
     1928// }
    19291929
    19301930#undef VISIT_START
  • src/AST/Pass.proto.hpp

    r6380f78 rd8938622  
    126126        template<typename pass_t, typename node_t>
    127127        static inline auto previsit( pass_t & pass, const node_t * & node, int ) -> decltype( pass.previsit( node ), void() ) {
    128                 static_assert(
    129                         std::is_base_of<const node_t, typename std::remove_pointer<decltype( pass.previsit( node ) )>::type >::value,
    130                         "Previsit may not change the type of the node. Use postvisit instead."
    131                 );
    132128                node = pass.previsit( node );
    133129                assert(node);
  • src/AST/Stmt.cpp

    r6380f78 rd8938622  
    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#   warning unimplemented
     25        assert(!"implemented");
    5526}
    5627
  • src/AST/module.mk

    r6380f78 rd8938622  
    2525        AST/LinkageSpec.cpp \
    2626        AST/Node.cpp \
    27         AST/Pass.cpp \
    2827        AST/Print.cpp \
    2928        AST/Stmt.cpp \
  • src/Makefile.in

    r6380f78 rd8938622  
    169169        AST/Expr.$(OBJEXT) AST/GenericSubstitution.$(OBJEXT) \
    170170        AST/Init.$(OBJEXT) AST/LinkageSpec.$(OBJEXT) \
    171         AST/Node.$(OBJEXT) AST/Pass.$(OBJEXT) AST/Print.$(OBJEXT) \
    172         AST/Stmt.$(OBJEXT) AST/Type.$(OBJEXT) \
    173         AST/TypeSubstitution.$(OBJEXT)
     171        AST/Node.$(OBJEXT) AST/Print.$(OBJEXT) AST/Stmt.$(OBJEXT) \
     172        AST/Type.$(OBJEXT) AST/TypeSubstitution.$(OBJEXT)
    174173am__objects_2 = CodeGen/CodeGenerator.$(OBJEXT) \
    175174        CodeGen/FixMain.$(OBJEXT) CodeGen/GenType.$(OBJEXT) \
     
    579578        AST/LinkageSpec.cpp \
    580579        AST/Node.cpp \
    581         AST/Pass.cpp \
    582580        AST/Print.cpp \
    583581        AST/Stmt.cpp \
     
    747745        AST/$(DEPDIR)/$(am__dirstamp)
    748746AST/Node.$(OBJEXT): AST/$(am__dirstamp) AST/$(DEPDIR)/$(am__dirstamp)
    749 AST/Pass.$(OBJEXT): AST/$(am__dirstamp) AST/$(DEPDIR)/$(am__dirstamp)
    750747AST/Print.$(OBJEXT): AST/$(am__dirstamp) AST/$(DEPDIR)/$(am__dirstamp)
    751748AST/Stmt.$(OBJEXT): AST/$(am__dirstamp) AST/$(DEPDIR)/$(am__dirstamp)
     
    11811178@AMDEP_TRUE@@am__include@ @am__quote@AST/$(DEPDIR)/LinkageSpec.Po@am__quote@
    11821179@AMDEP_TRUE@@am__include@ @am__quote@AST/$(DEPDIR)/Node.Po@am__quote@
    1183 @AMDEP_TRUE@@am__include@ @am__quote@AST/$(DEPDIR)/Pass.Po@am__quote@
    11841180@AMDEP_TRUE@@am__include@ @am__quote@AST/$(DEPDIR)/Print.Po@am__quote@
    11851181@AMDEP_TRUE@@am__include@ @am__quote@AST/$(DEPDIR)/Stmt.Po@am__quote@
  • src/SynTree/Declaration.h

    r6380f78 rd8938622  
    286286        AggregateDecl * set_body( bool body ) { AggregateDecl::body = body; return this; }
    287287
    288         virtual void print( std::ostream &os, Indenter indent = {} ) const override final;
     288        virtual void print( std::ostream &os, Indenter indent = {} ) const override;
    289289        virtual void printShort( std::ostream &os, Indenter indent = {} ) const override;
    290290  protected:
Note: See TracChangeset for help on using the changeset viewer.