Changeset f7e4f8e8 for src/AST


Ignore:
Timestamp:
Oct 30, 2020, 12:36:16 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:
0ab3b73, 36d0a80
Parents:
b9537e6 (diff), 4ae78c1 (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:
1 added
16 edited

Legend:

Unmodified
Added
Removed
  • src/AST/Convert.cpp

    rb9537e6 rf7e4f8e8  
    4747
    4848//================================================================================================
    49 namespace {
     49namespace ast {
    5050
    5151// This is to preserve the FindSpecialDecls hack. It does not (and perhaps should not)
    5252// allow us to use the same stratagy in the new ast.
     53// xxx - since convert back pass works, this concern seems to be unnecessary.
     54
     55// these need to be accessed in new FixInit now
    5356ast::Type * sizeType = nullptr;
    5457ast::FunctionDecl * dereferenceOperator = nullptr;
     
    6366        using Cache = std::unordered_map< const ast::Node *, BaseSyntaxNode * >;
    6467        Cache cache;
     68
     69        // Statements can no longer be shared.
     70        // however, since StmtExprResult is now implemented, need to still maintain
     71        // readonly references.
     72        Cache readonlyCache;
    6573
    6674        template<typename T>
     
    154162        }
    155163
    156         const ast::DeclWithType * visit( const ast::ObjectDecl * node ) override final {
    157                 auto&& bfwd = get<Expression>().accept1( node->bitfieldWidth );
    158                 auto&& type = get<Type>().accept1( node->type );
    159                 auto&& init = get<Initializer>().accept1( node->init );
    160                 auto&& attr = get<Attribute>().acceptL( node->attributes );
     164        const ast::DeclWithType * visit( const ast::ObjectDecl * node ) override final {       
    161165                if ( inCache( node ) ) {
    162166                        return nullptr;
    163167                }
     168                auto bfwd = get<Expression>().accept1( node->bitfieldWidth );
     169                auto type = get<Type>().accept1( node->type );
     170                auto attr = get<Attribute>().acceptL( node->attributes );
     171
    164172                auto decl = new ObjectDecl(
    165173                        node->name,
     
    168176                        bfwd,
    169177                        type->clone(),
    170                         init,
     178                        nullptr, // prevent infinite loop
    171179                        attr,
    172180                        Type::FuncSpecifiers( node->funcSpec.val )
    173181                );
    174                 return declWithTypePostamble( decl, node );
     182
     183                // handles the case where node->init references itself
     184                // xxx - does it really happen?
     185                declWithTypePostamble(decl, node);
     186                auto init = get<Initializer>().accept1( node->init );
     187                decl->init = init;
     188               
     189                this->node = decl;
     190                return nullptr;
    175191        }
    176192
     
    205221                decl->statements = get<CompoundStmt>().accept1( node->stmts );
    206222                decl->withExprs = get<Expression>().acceptL( node->withExprs );
    207                 if ( dereferenceOperator == node ) {
     223                if ( ast::dereferenceOperator == node ) {
    208224                        Validate::dereferenceOperator = decl;
    209225                }
    210                 if ( dtorStructDestroy == node ) {
     226                if ( ast::dtorStructDestroy == node ) {
    211227                        Validate::dtorStructDestroy = decl;
    212228                }
     
    267283                );
    268284
    269                 if ( dtorStruct == node ) {
     285                if ( ast::dtorStruct == node ) {
    270286                        Validate::dtorStruct = decl;
    271287                }
     
    320336
    321337        const ast::Stmt * stmtPostamble( Statement * stmt, const ast::Stmt * node ) {
    322                 cache.emplace( node, stmt );
     338                // force statements in old tree to be unique.
     339                // cache.emplace( node, stmt );
     340                readonlyCache.emplace( node, stmt );
    323341                stmt->location = node->location;
    324342                stmt->labels = makeLabelL( stmt, node->labels );
     
    337355                if ( inCache( node ) ) return nullptr;
    338356                auto stmt = new ExprStmt( nullptr );
    339                 cache.emplace( node, stmt );
    340357                stmt->expr = get<Expression>().accept1( node->expr );
    341358                return stmtPostamble( stmt, node );
     
    10111028                auto stmts = node->stmts;
    10121029                // disable sharing between multiple StmtExprs explicitly.
    1013                 if (inCache(stmts)) {
    1014                         stmts = ast::deepCopy(stmts.get());
    1015                 }
     1030                // this should no longer be true.
     1031
    10161032                auto rslt = new StmtExpr(
    10171033                        get<CompoundStmt>().accept1(stmts)
     
    10201036                rslt->returnDecls = get<ObjectDecl>().acceptL(node->returnDecls);
    10211037                rslt->dtors       = get<Expression>().acceptL(node->dtors);
     1038                if (node->resultExpr) {
     1039                        // this MUST be found by children visit
     1040                        rslt->resultExpr  = strict_dynamic_cast<ExprStmt *>(readonlyCache.at(node->resultExpr));
     1041                }
    10221042
    10231043                auto expr = visitBaseExpr( node, rslt );
     
    10361056
    10371057                auto expr = visitBaseExpr( node, rslt );
    1038                 this->node = expr;
     1058                this->node = expr->clone();
    10391059                return nullptr;
    10401060        }
     
    11261146                auto type = new BasicType{ cv( node ), (BasicType::Kind)(unsigned)node->kind };
    11271147                // I believe this should always be a BasicType.
    1128                 if ( sizeType == node ) {
     1148                if ( ast::sizeType == node ) {
    11291149                        Validate::SizeType = type;
    11301150                }
     
    15291549
    15301550                // function type is now derived from parameter decls instead of storing them
     1551
     1552                /*
    15311553                auto ftype = new ast::FunctionType((ast::ArgumentFlag)old->type->isVarArgs, cv(old->type));
    15321554                ftype->params.reserve(paramVars.size());
     
    15401562                }
    15411563                ftype->forall = std::move(forall);
    1542                 visitType(old->type, ftype);
     1564                */
     1565
     1566                // can function type have attributes? seems not to be the case.
     1567                // visitType(old->type, ftype);
    15431568
    15441569                auto decl = new ast::FunctionDecl{
     
    15461571                        old->name,
    15471572                        // GET_ACCEPT_1(type, FunctionType),
     1573                        std::move(forall),
    15481574                        std::move(paramVars),
    15491575                        std::move(returnVars),
     
    15521578                        { old->linkage.val },
    15531579                        GET_ACCEPT_V(attributes, Attribute),
    1554                         { old->get_funcSpec().val }
     1580                        { old->get_funcSpec().val },
     1581                        old->type->isVarArgs
    15551582                };
    15561583
    1557                 decl->type = ftype;
     1584                // decl->type = ftype;
    15581585                cache.emplace( old, decl );
    15591586
     
    15701597
    15711598                if ( Validate::dereferenceOperator == old ) {
    1572                         dereferenceOperator = decl;
     1599                        ast::dereferenceOperator = decl;
    15731600                }
    15741601
    15751602                if ( Validate::dtorStructDestroy == old ) {
    1576                         dtorStructDestroy = decl;
     1603                        ast::dtorStructDestroy = decl;
    15771604                }
    15781605        }
     
    15991626
    16001627                if ( Validate::dtorStruct == old ) {
    1601                         dtorStruct = decl;
     1628                        ast::dtorStruct = decl;
    16021629                }
    16031630        }
     
    25312558                // I believe this should always be a BasicType.
    25322559                if ( Validate::SizeType == old ) {
    2533                         sizeType = type;
     2560                        ast::sizeType = type;
    25342561                }
    25352562                visitType( old, type );
  • src/AST/Decl.cpp

    rb9537e6 rf7e4f8e8  
    4848
    4949// --- FunctionDecl
     50
     51FunctionDecl::FunctionDecl( const CodeLocation & loc, const std::string & name,
     52                std::vector<ptr<TypeDecl>>&& forall,
     53                std::vector<ptr<DeclWithType>>&& params, std::vector<ptr<DeclWithType>>&& returns,
     54                CompoundStmt * stmts, Storage::Classes storage, Linkage::Spec linkage,
     55                std::vector<ptr<Attribute>>&& attrs, Function::Specs fs, bool isVarArgs)
     56        : DeclWithType( loc, name, storage, linkage, std::move(attrs), fs ), params(std::move(params)), returns(std::move(returns)),
     57          stmts( stmts ) {
     58                  FunctionType * ftype = new FunctionType(static_cast<ArgumentFlag>(isVarArgs));
     59                  for (auto & param : this->params) {
     60                          ftype->params.emplace_back(param->get_type());
     61                  }
     62                  for (auto & ret : this->returns) {
     63                          ftype->returns.emplace_back(ret->get_type());
     64                  }
     65                  ftype->forall = std::move(forall);
     66                  this->type = ftype;
     67          }
     68
    5069
    5170const Type * FunctionDecl::get_type() const { return type.get(); }
  • src/AST/Decl.hpp

    rb9537e6 rf7e4f8e8  
    131131        std::vector< ptr<Expr> > withExprs;
    132132
    133         FunctionDecl( const CodeLocation & loc, const std::string & name,
     133        FunctionDecl( const CodeLocation & loc, const std::string & name, std::vector<ptr<TypeDecl>>&& forall,
    134134                std::vector<ptr<DeclWithType>>&& params, std::vector<ptr<DeclWithType>>&& returns,
    135135                CompoundStmt * stmts, Storage::Classes storage = {}, Linkage::Spec linkage = Linkage::C,
    136                 std::vector<ptr<Attribute>>&& attrs = {}, Function::Specs fs = {})
    137         : DeclWithType( loc, name, storage, linkage, std::move(attrs), fs ), params(std::move(params)), returns(std::move(returns)),
    138           stmts( stmts ) {}
     136                std::vector<ptr<Attribute>>&& attrs = {}, Function::Specs fs = {}, bool isVarArgs = false);
     137        // : DeclWithType( loc, name, storage, linkage, std::move(attrs), fs ), params(std::move(params)), returns(std::move(returns)),
     138        //  stmts( stmts ) {}
    139139
    140140        const Type * get_type() const override;
  • src/AST/DeclReplacer.cpp

    rb9537e6 rf7e4f8e8  
    3838                        const ast::TypeInstType * previsit( const ast::TypeInstType * );
    3939                };
     40
     41                struct VarExprReplacer {
     42                private:
     43                        const ExprMap & exprMap;
     44                       
     45                public:
     46                        VarExprReplacer(const ExprMap & exprMap): exprMap (exprMap) {}
     47
     48                        const Expr * postvisit (const VariableExpr *);
     49                };
    4050        }
    4151
     
    5464                DeclMap declMap;
    5565                return replace( node, declMap, typeMap, debug );
     66        }
     67
     68        const ast::Node * replace( const ast::Node * node, const ExprMap & exprMap) {
     69                Pass<VarExprReplacer> replacer = {exprMap};
     70                return node->accept( replacer );
    5671        }
    5772
     
    88103                        return ninst;
    89104                }
     105
     106                const Expr * VarExprReplacer::postvisit( const VariableExpr * expr ) {
     107                        if (!exprMap.count(expr->var)) return expr;
     108
     109                        return exprMap.at(expr->var);
     110                }
     111
    90112        }
    91113}
  • src/AST/DeclReplacer.hpp

    rb9537e6 rf7e4f8e8  
    2323        class DeclWithType;
    2424        class TypeDecl;
     25        class Expr;
    2526
    2627        namespace DeclReplacer {
    2728                using DeclMap = std::unordered_map< const DeclWithType *, const DeclWithType * >;
    2829                using TypeMap = std::unordered_map< const TypeDecl *, const TypeDecl * >;
     30                using ExprMap = std::unordered_map< const DeclWithType *, const Expr * >;
    2931
    3032                const Node * replace( const Node * node, const DeclMap & declMap, bool debug = false );
    3133                const Node * replace( const Node * node, const TypeMap & typeMap, bool debug = false );
    3234                const Node * replace( const Node * node, const DeclMap & declMap, const TypeMap & typeMap, bool debug = false );
     35                const Node * replace( const Node * node, const ExprMap & exprMap);
    3336        }
    3437}
  • src/AST/Expr.cpp

    rb9537e6 rf7e4f8e8  
    6767// --- UntypedExpr
    6868
    69 UntypedExpr * UntypedExpr::createDeref( const CodeLocation & loc, Expr * arg ) {
     69UntypedExpr * UntypedExpr::createDeref( const CodeLocation & loc, const Expr * arg ) {
    7070        assert( arg );
    7171
     
    9292}
    9393
    94 UntypedExpr * UntypedExpr::createAssign( const CodeLocation & loc, Expr * lhs, Expr * rhs ) {
     94UntypedExpr * UntypedExpr::createAssign( const CodeLocation & loc, const Expr * lhs, const Expr * rhs ) {
    9595        assert( lhs && rhs );
    9696
     
    102102        }
    103103        return ret;
     104}
     105
     106// --- VariableExpr
     107
     108VariableExpr::VariableExpr( const CodeLocation & loc )
     109: Expr( loc ), var( nullptr ) {}
     110
     111VariableExpr::VariableExpr( const CodeLocation & loc, const DeclWithType * v )
     112: Expr( loc ), var( v ) {
     113        assert( var );
     114        assert( var->get_type() );
     115        result = shallowCopy( var->get_type() );
     116}
     117
     118bool VariableExpr::get_lvalue() const {
     119        // It isn't always an lvalue, but it is never an rvalue.
     120        return true;
     121}
     122
     123VariableExpr * VariableExpr::functionPointer(
     124                const CodeLocation & loc, const FunctionDecl * decl ) {
     125        // wrap usually-determined result type in a pointer
     126        VariableExpr * funcExpr = new VariableExpr{ loc, decl };
     127        funcExpr->result = new PointerType{ funcExpr->result };
     128        return funcExpr;
    104129}
    105130
     
    238263}
    239264
    240 // --- VariableExpr
    241 
    242 VariableExpr::VariableExpr( const CodeLocation & loc )
    243 : Expr( loc ), var( nullptr ) {}
    244 
    245 VariableExpr::VariableExpr( const CodeLocation & loc, const DeclWithType * v )
    246 : Expr( loc ), var( v ) {
    247         assert( var );
    248         assert( var->get_type() );
    249         result = shallowCopy( var->get_type() );
    250 }
    251 
    252 bool VariableExpr::get_lvalue() const {
    253         // It isn't always an lvalue, but it is never an rvalue.
    254         return true;
    255 }
    256 
    257 VariableExpr * VariableExpr::functionPointer(
    258                 const CodeLocation & loc, const FunctionDecl * decl ) {
    259         // wrap usually-determined result type in a pointer
    260         VariableExpr * funcExpr = new VariableExpr{ loc, decl };
    261         funcExpr->result = new PointerType{ funcExpr->result };
    262         return funcExpr;
    263 }
    264 
    265265// --- ConstantExpr
    266266
  • src/AST/Expr.hpp

    rb9537e6 rf7e4f8e8  
    226226
    227227        /// Creates a new dereference expression
    228         static UntypedExpr * createDeref( const CodeLocation & loc, Expr * arg );
     228        static UntypedExpr * createDeref( const CodeLocation & loc, const Expr * arg );
    229229        /// Creates a new assignment expression
    230         static UntypedExpr * createAssign( const CodeLocation & loc, Expr * lhs, Expr * rhs );
     230        static UntypedExpr * createAssign( const CodeLocation & loc, const Expr * lhs, const Expr * rhs );
    231231
    232232        const Expr * accept( Visitor & v ) const override { return v.visit( this ); }
     
    247247private:
    248248        NameExpr * clone() const override { return new NameExpr{ *this }; }
     249        MUTATE_FRIEND
     250};
     251
     252/// A reference to a named variable.
     253class VariableExpr final : public Expr {
     254public:
     255        readonly<DeclWithType> var;
     256
     257        VariableExpr( const CodeLocation & loc );
     258        VariableExpr( const CodeLocation & loc, const DeclWithType * v );
     259
     260        bool get_lvalue() const final;
     261
     262        /// generates a function pointer for a given function
     263        static VariableExpr * functionPointer( const CodeLocation & loc, const FunctionDecl * decl );
     264
     265        const Expr * accept( Visitor & v ) const override { return v.visit( this ); }
     266private:
     267        VariableExpr * clone() const override { return new VariableExpr{ *this }; }
    249268        MUTATE_FRIEND
    250269};
     
    392411};
    393412
    394 /// A reference to a named variable.
    395 class VariableExpr final : public Expr {
    396 public:
    397         readonly<DeclWithType> var;
    398 
    399         VariableExpr( const CodeLocation & loc );
    400         VariableExpr( const CodeLocation & loc, const DeclWithType * v );
    401 
    402         bool get_lvalue() const final;
    403 
    404         /// generates a function pointer for a given function
    405         static VariableExpr * functionPointer( const CodeLocation & loc, const FunctionDecl * decl );
    406 
    407         const Expr * accept( Visitor & v ) const override { return v.visit( this ); }
    408 private:
    409         VariableExpr * clone() const override { return new VariableExpr{ *this }; }
    410         MUTATE_FRIEND
    411 };
    412 
    413413/// A compile-time constant.
    414414/// Mostly carries C-source text from parse to code-gen, without interpretation.  E.g. strings keep their outer quotes and never have backslashes interpreted.
     
    422422                const CodeLocation & loc, const Type * ty, const std::string & r,
    423423                        std::optional<unsigned long long> i )
    424         : Expr( loc, ty ), rep( r ), ival( i ) {}
     424        : Expr( loc, ty ), rep( r ), ival( i ), underlyer(ty) {}
    425425
    426426        /// Gets the integer value of this constant, if one is appropriate to its type.
     
    617617
    618618        ImplicitCopyCtorExpr( const CodeLocation& loc, const ApplicationExpr * call )
    619         : Expr( loc, call->result ) { assert( call ); }
     619        : Expr( loc, call->result ), callExpr(call) { assert( call ); assert(call->result); }
    620620
    621621        const Expr * accept( Visitor & v ) const override { return v.visit( this ); }
     
    742742        std::vector<ptr<Expr>> dtors;              ///< destructor(s) for return variable(s)
    743743
     744        readonly<ExprStmt> resultExpr;
     745
    744746        StmtExpr( const CodeLocation & loc, const CompoundStmt * ss );
    745747
  • src/AST/Fwd.hpp

    rb9537e6 rf7e4f8e8  
    137137typedef unsigned int UniqueId;
    138138
     139extern Type * sizeType;
     140extern FunctionDecl * dereferenceOperator;
     141extern StructDecl   * dtorStruct;
     142extern FunctionDecl * dtorStructDestroy;
     143
    139144}
  • src/AST/Node.hpp

    rb9537e6 rf7e4f8e8  
    4949
    5050        bool unique() const { return strong_count == 1; }
     51        bool isManaged() const {return strong_count > 0; }
    5152
    5253private:
  • src/AST/Pass.hpp

    rb9537e6 rf7e4f8e8  
    228228        template<typename core_type>
    229229        friend void accept_all( std::list< ptr<Decl> > & decls, Pass<core_type>& visitor );
     230
     231        bool isInFunction() const {
     232                return inFunction;
     233        }
     234
    230235private:
    231236
     
    235240        const ast::Stmt * call_accept( const ast::Stmt * );
    236241        const ast::Expr * call_accept( const ast::Expr * );
     242
     243        // requests WithStmtsToAdd directly add to this statement, as if it is a compound.
     244
     245        const ast::Stmt * call_accept_as_compound(const ast::Stmt *);
    237246
    238247        template< typename node_t >
     
    257266        template<typename node_t, typename parent_t, typename child_t>
    258267        void maybe_accept(const node_t * &, child_t parent_t::* child);
     268
     269        template<typename node_t, typename parent_t, typename child_t>
     270        void maybe_accept_as_compound(const node_t * &, child_t parent_t::* child);
    259271
    260272private:
     
    284296private:
    285297        bool inFunction = false;
     298        bool atFunctionTop = false;
    286299};
    287300
     
    371384struct WithVisitorRef {
    372385        Pass<core_t> * const visitor = nullptr;
     386
     387        bool isInFunction() const {
     388                return visitor->isInFunction();
     389        }
    373390};
    374391
  • src/AST/Pass.impl.hpp

    rb9537e6 rf7e4f8e8  
    167167                __pedantic_pass_assert( stmt );
    168168
     169                return stmt->accept( *this );
     170        }
     171
     172        template< typename core_t >
     173        const ast::Stmt * ast::Pass< core_t >::call_accept_as_compound( const ast::Stmt * stmt ) {
     174                __pedantic_pass_assert( __visit_children() );
     175                __pedantic_pass_assert( stmt );
     176
    169177                // add a few useful symbols to the scope
    170178                using __pass::empty;
     
    324332
    325333                auto new_val = call_accept( old_val );
     334
     335                static_assert( !std::is_same<const ast::Node *, decltype(new_val)>::value || std::is_same<int, decltype(old_val)>::value, "ERROR");
     336
     337                if( __pass::differs(old_val, new_val) ) {
     338                        auto new_parent = __pass::mutate<core_t>(parent);
     339                        new_parent->*child = new_val;
     340                        parent = new_parent;
     341                }
     342        }
     343
     344        template< typename core_t >
     345        template<typename node_t, typename parent_t, typename child_t>
     346        void ast::Pass< core_t >::maybe_accept_as_compound(
     347                const node_t * & parent,
     348                child_t parent_t::*child
     349        ) {
     350                static_assert( std::is_base_of<parent_t, node_t>::value, "Error deducing member object" );
     351
     352                if(__pass::skip(parent->*child)) return;
     353                const auto & old_val = __pass::get(parent->*child, 0);
     354
     355                static_assert( !std::is_same<const ast::Node * &, decltype(old_val)>::value, "ERROR");
     356
     357                auto new_val = call_accept_as_compound( old_val );
    326358
    327359                static_assert( !std::is_same<const ast::Node *, decltype(new_val)>::value || std::is_same<int, decltype(old_val)>::value, "ERROR");
     
    470502                                // foralls are still in function type
    471503                                maybe_accept( node, &FunctionDecl::type );
    472                                 // function body needs to have the same scope as parameters - CompoundStmt will not enter
    473                                 // a new scope if inFunction is true
     504                                // First remember that we are now within a function.
    474505                                ValueGuard< bool > oldInFunction( inFunction );
    475506                                inFunction = true;
     507                                // The function body needs to have the same scope as parameters.
     508                                // A CompoundStmt will not enter a new scope if atFunctionTop is true.
     509                                ValueGuard< bool > oldAtFunctionTop( atFunctionTop );
     510                                atFunctionTop = true;
    476511                                maybe_accept( node, &FunctionDecl::stmts );
    477512                                maybe_accept( node, &FunctionDecl::attributes );
     
    640675        VISIT_START( node );
    641676        VISIT({
    642                 // do not enter a new scope if inFunction is true - needs to check old state before the assignment
    643                 auto guard1 = makeFuncGuard( [this, inFunctionCpy = this->inFunction]() {
    644                         if ( ! inFunctionCpy ) __pass::symtab::enter(core, 0);
    645                 }, [this, inFunctionCpy = this->inFunction]() {
    646                         if ( ! inFunctionCpy ) __pass::symtab::leave(core, 0);
     677                // Do not enter (or leave) a new scope if atFunctionTop. Remember to save the result.
     678                auto guard1 = makeFuncGuard( [this, enterScope = !this->atFunctionTop]() {
     679                        if ( enterScope ) __pass::symtab::enter(core, 0);
     680                }, [this, leaveScope = !this->atFunctionTop]() {
     681                        if ( leaveScope ) __pass::symtab::leave(core, 0);
    647682                });
    648683                ValueGuard< bool > guard2( inFunction );
     
    703738                maybe_accept( node, &IfStmt::inits    );
    704739                maybe_accept( node, &IfStmt::cond     );
    705                 maybe_accept( node, &IfStmt::thenPart );
    706                 maybe_accept( node, &IfStmt::elsePart );
     740                maybe_accept_as_compound( node, &IfStmt::thenPart );
     741                maybe_accept_as_compound( node, &IfStmt::elsePart );
    707742        })
    708743
     
    721756                maybe_accept( node, &WhileStmt::inits );
    722757                maybe_accept( node, &WhileStmt::cond  );
    723                 maybe_accept( node, &WhileStmt::body  );
     758                maybe_accept_as_compound( node, &WhileStmt::body  );
    724759        })
    725760
     
    736771                // for statements introduce a level of scope (for the initialization)
    737772                guard_symtab guard { *this };
     773                // xxx - old ast does not create WithStmtsToAdd scope for loop inits. should revisit this later.
    738774                maybe_accept( node, &ForStmt::inits );
    739775                maybe_accept( node, &ForStmt::cond  );
    740776                maybe_accept( node, &ForStmt::inc   );
    741                 maybe_accept( node, &ForStmt::body  );
     777                maybe_accept_as_compound( node, &ForStmt::body  );
    742778        })
    743779
     
    834870                maybe_accept( node, &CatchStmt::decl );
    835871                maybe_accept( node, &CatchStmt::cond );
    836                 maybe_accept( node, &CatchStmt::body );
     872                maybe_accept_as_compound( node, &CatchStmt::body );
    837873        })
    838874
  • src/AST/SymbolTable.cpp

    rb9537e6 rf7e4f8e8  
    335335}
    336336
    337 /*
    338 void SymbolTable::addFunctionType( const FunctionType * ftype ) {
    339         addTypes( ftype->forall );
    340         addIds( ftype->returns );
    341         addIds( ftype->params );
    342 }
    343 */
     337
     338void SymbolTable::addFunction( const FunctionDecl * func ) {
     339        addTypes( func->type->forall );
     340        addIds( func->returns );
     341        addIds( func->params );
     342}
     343
    344344
    345345void SymbolTable::lazyInitScope() {
  • src/AST/SymbolTable.hpp

    rb9537e6 rf7e4f8e8  
    145145
    146146        /// convenience function for adding all of the declarations in a function type to the indexer
    147         // void addFunctionType( const FunctionType * ftype );
     147        void addFunction( const FunctionDecl * );
    148148
    149149private:
  • src/AST/Type.cpp

    rb9537e6 rf7e4f8e8  
    157157
    158158template<typename decl_t>
     159SueInstType<decl_t>::SueInstType(
     160        const base_type * b, std::vector<ptr<Expr>> && params,
     161        CV::Qualifiers q, std::vector<ptr<Attribute>> && as )
     162: BaseInstType( b->name, std::move(params), q, std::move(as) ), base( b ) {}
     163
     164template<typename decl_t>
    159165bool SueInstType<decl_t>::isComplete() const {
    160166        return base ? base->body : false;
  • src/AST/Type.hpp

    rb9537e6 rf7e4f8e8  
    302302class FunctionType final : public ParameterizedType {
    303303public:
    304 //      std::vector<ptr<DeclWithType>> returns;
    305 //      std::vector<ptr<DeclWithType>> params;
    306 
    307304        std::vector<ptr<Type>> returns;
    308305        std::vector<ptr<Type>> params;
     
    345342        : ParameterizedType(q, std::move(as)), params(), name(n) {}
    346343
     344        BaseInstType(
     345                const std::string& n, std::vector<ptr<Expr>> && params,
     346                CV::Qualifiers q = {}, std::vector<ptr<Attribute>> && as = {} )
     347        : ParameterizedType(q, std::move(as)), params(std::move(params)), name(n) {}
     348
    347349        BaseInstType( const BaseInstType & o );
    348350
     
    369371
    370372        SueInstType(
    371                 const decl_t * b, CV::Qualifiers q = {}, std::vector<ptr<Attribute>> && as = {} );
     373                const base_type * b, CV::Qualifiers q = {}, std::vector<ptr<Attribute>> && as = {} );
     374
     375        SueInstType(
     376                const base_type * b, std::vector<ptr<Expr>> && params,
     377                CV::Qualifiers q = {}, std::vector<ptr<Attribute>> && as = {} );
    372378
    373379        bool isComplete() const override;
  • src/AST/porting.md

    rb9537e6 rf7e4f8e8  
    3030  * Base nodes now override `const Node * accept( Visitor & v ) const = 0` with, e.g. `const Stmt * accept( Visitor & v ) const override = 0`
    3131* `PassVisitor` is replaced with `ast::Pass`
     32  * Most one shot uses can use `ast::Pass::run` and `ast::Pass::read`.
     33
     34`WithConstTypeSubstitution`
     35* `env` => `typeSubs`
    3236
    3337## Structural Changes ##
     
    146150  * allows `newObject` as just default settings
    147151
     152`FunctionDecl`
     153* `params` and `returns` added.
     154  * Contain the declarations of the parameters and return variables.
     155  * Types should match (even be shared with) the fields of `type`.
     156
    148157`NamedTypeDecl`
    149158* `parameters` => `params`
     
    154163`AggregateDecl`
    155164* `parameters` => `params`
     165
     166`StructDecl`
     167* `makeInst` replaced by better constructor on `StructInstType`.
    156168
    157169`Expr`
     
    245257* **TODO** move `kind`, `typeNames` into code generator
    246258
    247 `ReferenceToType`
     259`ReferenceToType` => `BaseInstType`
    248260* deleted `get_baseParameters()` from children
    249261  * replace with `aggr() ? aggr()->params : nullptr`
     
    261273* `returnVals` => `returns`
    262274* `parameters` => `params`
     275  * Both now just point at types.
    263276* `bool isVarArgs;` => `enum ArgumentFlag { FixedArgs, VariableArgs }; ArgumentFlag isVarArgs;`
     277
     278`SueInstType`
     279* Template class, with specializations and using to implement some other types:
     280  * `StructInstType`, `UnionInstType` & `EnumInstType`
    264281
    265282`TypeInstType`
Note: See TracChangeset for help on using the changeset viewer.