Changeset ce55a81 for src/AST


Ignore:
Timestamp:
Sep 4, 2020, 2:14:10 PM (5 years ago)
Author:
Thierry Delisle <tdelisle@…>
Branches:
ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast-unique-expr, pthread-emulation, qualifiedEnum
Children:
14d8a9b
Parents:
56c44dc (diff), 2801829 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'master' of plg.uwaterloo.ca:software/cfa/cfa-cc

Location:
src/AST
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • src/AST/Convert.cpp

    r56c44dc rce55a81  
    705705                        new KeywordCastExpr(
    706706                                get<Expression>().accept1(node->arg),
    707                                 castTarget
     707                                castTarget,
     708                                {node->concrete_target.field, node->concrete_target.getter}
    708709                        )
    709710                );
     
    20872088                                old->location,
    20882089                                GET_ACCEPT_1(arg, Expr),
    2089                                 castTarget
     2090                                castTarget,
     2091                                {old->concrete_target.field, old->concrete_target.getter}
    20902092                        )
    20912093                );
  • src/AST/Copy.hpp

    r56c44dc rce55a81  
    2121#include "Stmt.hpp"
    2222#include "Type.hpp"
     23#include <unordered_set>
     24#include <unordered_map>
    2325
    2426namespace ast {
  • src/AST/Expr.hpp

    r56c44dc rce55a81  
    312312public:
    313313        ptr<Expr> arg;
     314        struct Concrete {
     315                std::string field;
     316                std::string getter;
     317
     318                Concrete() = default;
     319                Concrete(const Concrete &) = default;
     320        };
    314321        ast::AggregateDecl::Aggregate target;
     322        Concrete concrete_target;
     323
    315324
    316325        KeywordCastExpr( const CodeLocation & loc, const Expr * a, ast::AggregateDecl::Aggregate t )
    317326        : Expr( loc ), arg( a ), target( t ) {}
     327
     328        KeywordCastExpr( const CodeLocation & loc, const Expr * a, ast::AggregateDecl::Aggregate t, const Concrete & ct )
     329        : Expr( loc ), arg( a ), target( t ), concrete_target( ct ) {}
    318330
    319331        /// Get a name for the target type
  • src/AST/Pass.hpp

    r56c44dc rce55a81  
    4848//
    4949// Several additional features are available through inheritance
     50// | PureVisitor           - makes the visitor pure, it never modifies nodes in place and always
     51//                           clones nodes it needs to make changes to
    5052// | WithTypeSubstitution  - provides polymorphic const TypeSubstitution * env for the
    5153//                           current expression
     
    266268
    267269/// Keep track of the polymorphic const TypeSubstitution * env for the current expression
     270
     271/// If used the visitor will always clone nodes.
     272struct PureVisitor {};
     273
    268274struct WithConstTypeSubstitution {
    269275        const TypeSubstitution * env = nullptr;
  • src/AST/Pass.impl.hpp

    r56c44dc rce55a81  
    5757
    5858namespace ast {
     59        template<typename node_t>
     60        node_t * shallowCopy( const node_t * node );
     61
    5962        namespace __pass {
    6063                // Check if this is either a null pointer or a pointer to an empty container
     
    6265                static inline bool empty( T * ptr ) {
    6366                        return !ptr || ptr->empty();
     67                }
     68
     69                template< typename core_t, typename node_t >
     70                static inline node_t* mutate(const node_t *node) {
     71                        return std::is_base_of<PureVisitor, core_t>::value ? ::ast::shallowCopy(node) : ::ast::mutate(node);
    6472                }
    6573
     
    320328
    321329                if( __pass::differs(old_val, new_val) ) {
    322                         auto new_parent = mutate(parent);
     330                        auto new_parent = __pass::mutate<core_t>(parent);
    323331                        new_parent->*child = new_val;
    324332                        parent = new_parent;
     
    334342                        if ( node->forall.empty() ) return;
    335343
    336                         node_t * mut = mutate( node );
     344                        node_t * mut = __pass::mutate<core_t>( node );
    337345                        mut->forall = subs->clone( node->forall, *this );
    338346                        node = mut;
     
    894902
    895903                if(mutated) {
    896                         auto n = mutate(node);
     904                        auto n = __pass::mutate<core_t>(node);
    897905                        n->clauses = std::move( new_clauses );
    898906                        node = n;
     
    904912                        auto nval = call_accept( node->field ); \
    905913                        if(nval != node->field ) { \
    906                                 auto nparent = mutate(node); \
     914                                auto nparent = __pass::mutate<core_t>(node); \
    907915                                nparent->field = nval; \
    908916                                node = nparent; \
     
    16101618
    16111619                if(mutated) {
    1612                         auto n = mutate(node);
     1620                        auto n = __pass::mutate<core_t>(node);
    16131621                        n->associations = std::move( new_kids );
    16141622                        node = n;
     
    19401948                        }
    19411949                        if (mutated) {
    1942                                 auto new_node = mutate( node );
     1950                                auto new_node = __pass::mutate<core_t>( node );
    19431951                                new_node->typeEnv.swap( new_map );
    19441952                                node = new_node;
     
    19561964                        }
    19571965                        if (mutated) {
    1958                                 auto new_node = mutate( node );
     1966                                auto new_node = __pass::mutate<core_t>( node );
    19591967                                new_node->varEnv.swap( new_map );
    19601968                                node = new_node;
  • src/AST/Pass.proto.hpp

    r56c44dc rce55a81  
    2222template<typename core_t>
    2323class Pass;
     24
     25struct PureVisitor;
    2426
    2527namespace __pass {
  • src/AST/Print.cpp

    r56c44dc rce55a81  
    2121#include "Type.hpp"
    2222#include "TypeSubstitution.hpp"
     23#include "CompilationState.h"
    2324
    2425#include "Common/utility.h" // for group_iterate
     
    239240
    240241                if ( node->result ) {
    241                         os << endl << indent << "... with resolved type:" << endl;
    242                         ++indent;
    243                         os << indent;
    244                         node->result->accept( *this );
    245                         --indent;
     242                        if (!deterministic_output) {
     243                                os << endl << indent << "... with resolved type:" << endl;
     244                                ++indent;
     245                                os << indent;
     246                                node->result->accept( *this );
     247                                --indent;
     248                        }
    246249                }
    247250
  • src/AST/TypeSubstitution.hpp

    r56c44dc rce55a81  
    4646        template< typename SynTreeClass >
    4747        struct ApplyResult {
    48                 // const SynTreeClass * node;
    4948                ast::ptr<SynTreeClass> node;
    5049                int count;
     
    159158
    160159// definitition must happen after PassVisitor is included so that WithGuards can be used
    161 struct TypeSubstitution::Substituter : public WithGuards, public WithVisitorRef<Substituter> {
     160struct TypeSubstitution::Substituter : public WithGuards, public WithVisitorRef<Substituter>, public PureVisitor {
    162161                static size_t traceId;
    163162
     
    187186        assert( input );
    188187        Pass<Substituter> sub( *this, false );
    189         input = strict_dynamic_cast< const SynTreeClass * >( deepCopy(input)->accept( sub ) );
     188        input = strict_dynamic_cast< const SynTreeClass * >( input->accept( sub ) );
    190189        return { input, sub.core.subCount };
    191190}
     
    195194        assert( input );
    196195        Pass<Substituter> sub( *this, true );
    197         input = strict_dynamic_cast< const SynTreeClass * >( deepCopy(input)->accept( sub ) );
     196        input = strict_dynamic_cast< const SynTreeClass * >( input->accept( sub ) );
    198197        return { input, sub.core.subCount };
    199198}
  • src/AST/module.mk

    r56c44dc rce55a81  
    1717SRC_AST = \
    1818        AST/AssertAcyclic.cpp \
     19        AST/AssertAcyclic.hpp \
    1920        AST/Attribute.cpp \
     21        AST/Attribute.hpp \
     22        AST/Bitfield.hpp \
     23        AST/Chain.hpp \
    2024        AST/Convert.cpp \
     25        AST/Convert.hpp \
     26        AST/Copy.hpp \
     27        AST/CVQualifiers.hpp \
    2128        AST/Decl.cpp \
     29        AST/Decl.hpp \
    2230        AST/DeclReplacer.cpp \
     31        AST/DeclReplacer.hpp \
     32        AST/Eval.hpp \
    2333        AST/Expr.cpp \
     34        AST/Expr.hpp \
    2435        AST/ForallSubstitutionTable.cpp \
     36        AST/ForallSubstitutionTable.hpp \
     37        AST/ForallSubstitutor.hpp \
     38        AST/FunctionSpec.hpp \
     39        AST/Fwd.hpp \
    2540        AST/GenericSubstitution.cpp \
     41        AST/GenericSubstitution.hpp \
    2642        AST/Init.cpp \
     43        AST/Init.hpp \
     44        AST/Label.hpp \
    2745        AST/LinkageSpec.cpp \
     46        AST/LinkageSpec.hpp \
    2847        AST/Node.cpp \
     48        AST/Node.hpp \
     49        AST/ParseNode.hpp \
    2950        AST/Pass.cpp \
     51        AST/Pass.hpp \
     52        AST/Pass.impl.hpp \
     53        AST/Pass.proto.hpp \
    3054        AST/Print.cpp \
     55        AST/Print.hpp \
    3156        AST/Stmt.cpp \
     57        AST/Stmt.hpp \
     58        AST/StorageClasses.hpp \
    3259        AST/SymbolTable.cpp \
     60        AST/SymbolTable.hpp \
    3361        AST/Type.cpp \
     62        AST/Type.hpp \
    3463        AST/TypeEnvironment.cpp \
    35         AST/TypeSubstitution.cpp
     64        AST/TypeEnvironment.hpp \
     65        AST/TypeSubstitution.cpp \
     66        AST/TypeSubstitution.hpp \
     67        AST/Visitor.hpp
    3668
    3769SRC += $(SRC_AST)
Note: See TracChangeset for help on using the changeset viewer.