Changeset 172d9342


Ignore:
Timestamp:
May 17, 2019, 4:01:50 PM (5 years ago)
Author:
Michael Brooks <mlbrooks@…>
Branches:
ADT, arm-eh, ast-experimental, cleanup-dtors, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
Children:
f6964ef
Parents:
74dbbf6
Message:

added old-to-new conversion for TypeSubstitution?, within a framework for expressions

Location:
src
Files:
1 added
6 edited

Legend:

Unmodified
Added
Removed
  • src/AST/Convert.cpp

    r74dbbf6 r172d9342  
    1616#include "Convert.hpp"
    1717
    18 #include "AST/Pass.hpp"
    19 
    2018#include "AST/Attribute.hpp"
    2119#include "AST/Decl.hpp"
     
    2321#include "AST/Init.hpp"
    2422#include "AST/Stmt.hpp"
    25 
     23#include "AST/TypeSubstitution.hpp"
    2624
    2725#include "SynTree/Attribute.h"
    2826#include "SynTree/Declaration.h"
     27#include "SynTree/TypeSubstitution.h"
    2928
    3029//================================================================================================
     
    496495
    497496        const ast::Init * visit( const ast::ConstructorInit * node ) override final {
    498                 (void)node;
    499                 return nullptr;
    500         }
    501 
    502         const ast::Constant * visit( const ast::Constant * node ) override final {
    503497                (void)node;
    504498                return nullptr;
     
    970964        }
    971965
     966        ast::TypeSubstitution * convertTypeSubstitution(const TypeSubstitution * old) {
     967
     968                ast::TypeSubstitution *rslt = new ast::TypeSubstitution();
     969
     970                for (decltype(old->begin()) old_i = old->begin(); old_i != old->end(); old_i++) {
     971                        rslt->add( old_i->first,
     972                                   getAccept1<ast::Type>(old_i->second) );
     973                }
     974
     975                for (decltype(old->beginVar()) old_i = old->beginVar(); old_i != old->endVar(); old_i++) {
     976                        rslt->addVar( old_i->first,
     977                                      getAccept1<ast::Expr>(old_i->second) );
     978                }
     979        }
     980
     981        void convertInferUnion(ast::Expr::InferUnion &nwInferred, InferredParams oldInferParams, const std::vector<UniqueId> &oldResnSlots) {
     982               
     983                (void) nwInferred;
     984                (void) oldInferParams;
     985                (void) oldResnSlots;
     986               
     987                // TODO
     988        }
     989
     990        ast::Expr * visitBaseExpr(Expression * old, ast::Expr * nw) {
     991
     992                nw->result = GET_ACCEPT_1(result, Type);
     993                nw->env    = convertTypeSubstitution(old->env);
     994
     995                nw->extension = old->extension;
     996                convertInferUnion(nw->inferred, old->inferParams, old->resnSlots);
     997
     998                return nw;
     999        }
     1000
    9721001        virtual void visit( ApplicationExpr * ) override final {
    973 
     1002                // TODO
    9741003        }
    9751004
    9761005        virtual void visit( UntypedExpr * ) override final {
    977 
    978         }
    979 
    980         virtual void visit( NameExpr * ) override final {
    981 
     1006                // TODO
     1007        }
     1008
     1009        virtual void visit( NameExpr * old ) override final {
     1010                this->node = visitBaseExpr( old,
     1011                        new ast::NameExpr(
     1012                                old->location,
     1013                                old->get_name()
     1014                        )
     1015                );
    9821016        }
    9831017
    9841018        virtual void visit( CastExpr * ) override final {
    985 
     1019                // TODO ... (rest)
    9861020        }
    9871021
  • src/AST/Pass.hpp

    r74dbbf6 r172d9342  
    300300#include "Common/Stats.h"
    301301
     302namespace ast {
    302303extern struct PassVisitorStats {
    303304        size_t depth = 0;
     
    305306        Stats::Counters::AverageCounter<double> * avg = nullptr;
    306307} pass_visitor_stats;
     308}
    307309
    308310#include "AST/Pass.impl.hpp"
  • src/AST/TypeSubstitution.cpp

    r74dbbf6 r172d9342  
    5858void TypeSubstitution::add( std::string formalType, const Type *actualType ) {
    5959        typeEnv[ formalType ] = actualType;
     60}
     61
     62void TypeSubstitution::addVar( std::string formalExpr, const Expr *actualExpr ) {
     63        varEnv[ formalExpr ] = actualExpr;
    6064}
    6165
  • src/AST/TypeSubstitution.hpp

    r74dbbf6 r172d9342  
    5252        bool empty() const;
    5353
     54        void addVar( std::string formalExpr, const Expr *actualExpr );
     55
    5456        template< typename FormalIterator, typename ActualIterator >
    5557        void add( FormalIterator formalBegin, FormalIterator formalEnd, ActualIterator actualBegin );
     
    8789        auto begin() const -> decltype( typeEnv.begin() ) { return typeEnv.begin(); }
    8890        auto   end() const -> decltype( typeEnv.  end() ) { return typeEnv.  end(); }
     91
     92        auto beginVar()       -> decltype( varEnv.begin() ) { return varEnv.begin(); }
     93        auto   endVar()       -> decltype( varEnv.  end() ) { return varEnv.  end(); }
     94        auto beginVar() const -> decltype( varEnv.begin() ) { return varEnv.begin(); }
     95        auto   endVar() const -> decltype( varEnv.  end() ) { return varEnv.  end(); }
    8996};
    9097
  • src/SynTree/TypeSubstitution.cc

    r74dbbf6 r172d9342  
    6262        } // if
    6363        typeEnv[ formalType ] = actualType->clone();
     64}
     65
     66void TypeSubstitution::addVar( std::string formalExpr, Expression *actualExpr ) {
     67        varEnv[ formalExpr ] = actualExpr;
    6468}
    6569
  • src/SynTree/TypeSubstitution.h

    r74dbbf6 r172d9342  
    4848        bool empty() const;
    4949
     50        void addVar( std::string formalExpr, Expression *actualExpr );
     51
    5052        template< typename FormalIterator, typename ActualIterator >
    5153        void add( FormalIterator formalBegin, FormalIterator formalEnd, ActualIterator actualBegin );
     
    8991        auto begin() const -> decltype( typeEnv.begin() ) { return typeEnv.begin(); }
    9092        auto   end() const -> decltype( typeEnv.  end() ) { return typeEnv.  end(); }
     93
     94        auto beginVar()       -> decltype( varEnv.begin() ) { return varEnv.begin(); }
     95        auto   endVar()       -> decltype( varEnv.  end() ) { return varEnv.  end(); }
     96        auto beginVar() const -> decltype( varEnv.begin() ) { return varEnv.begin(); }
     97        auto   endVar() const -> decltype( varEnv.  end() ) { return varEnv.  end(); }
    9198};
    9299
Note: See TracChangeset for help on using the changeset viewer.