Changeset 546e712 for src/AST


Ignore:
Timestamp:
Jun 6, 2019, 3:01:46 PM (5 years ago)
Author:
Thierry Delisle <tdelisle@…>
Branches:
ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
Children:
8c0d801, f46bfd2f
Parents:
2a54479
Message:

Fix for 1 bug of N

Location:
src/AST
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • src/AST/Convert.cpp

    r2a54479 r546e712  
    148148
    149149        const ast::DeclWithType * visit( const ast::ObjectDecl * node ) override final {
    150                 if ( inCache( node ) ) return nullptr;
     150                auto&& bfwd = get<Expression>().accept1( node->bitfieldWidth );
     151                auto&& type = get<Type>().accept1( node->type );
     152                auto&& init = get<Initializer>().accept1( node->init );
     153                auto&& attr = get<Attribute>().acceptL( node->attributes );
     154                if ( inCache( node ) ) {
     155                        if(node->name == "tmp") {
     156                                std::cerr << (void*)node << "(new) in cache " << (void*)this->node << "(old)" << std::endl;
     157                        }
     158                        return nullptr;
     159                }
    151160                auto decl = new ObjectDecl(
    152161                        node->name,
    153162                        Type::StorageClasses( node->storage.val ),
    154163                        LinkageSpec::Spec( node->linkage.val ),
    155                         get<Expression>().accept1( node->bitfieldWidth ),
    156                         get<Type>().accept1( node->type ),
    157                         get<Initializer>().accept1( node->init ),
    158                         get<Attribute>().acceptL( node->attributes ),
     164                        bfwd,
     165                        type,
     166                        init,
     167                        attr,
    159168                        Type::FuncSpecifiers( node->funcSpec.val )
    160169                );
     170                if(node->name == "tmp") {
     171                        std::cerr << (void*)node << "(new) created " << (void*)decl << "(old)" << std::endl;
     172                }
    161173                return declWithTypePostamble( decl, node );
    162174        }
     
    719731
    720732        const ast::Expr * visit( const ast::VariableExpr * node ) override final {
    721                 auto expr = visitBaseExpr( node,
    722                         new VariableExpr(
    723                                 get<DeclarationWithType>().accept1(node->var)
    724                         )
    725                 );
     733                auto expr = new VariableExpr();
     734                visitBaseExpr( node, expr );
     735                expr->var = get<DeclarationWithType>().accept1(node->var);
     736                Type * type = expr->var->get_type()->clone();
     737                type->set_lvalue( true );
     738                expr->set_result( type );
    726739                this->node = expr;
    727740                return nullptr;
     
    13561369                return strict_dynamic_cast< ast::Decl * >( node );
    13571370        }
     1371
     1372        ConverterOldToNew() = default;
     1373        ConverterOldToNew(const ConverterOldToNew &) = delete;
     1374        ConverterOldToNew(ConverterOldToNew &&) = delete;
    13581375private:
    13591376        /// conversion output
    1360         ast::Node * node;
     1377        ast::Node * node = nullptr;
    13611378        /// cache of nodes that might be referenced by readonly<> for de-duplication
    1362         std::unordered_map< BaseSyntaxNode *, ast::Node * > cache;
     1379        std::unordered_map< BaseSyntaxNode *, ast::Node * > cache = {};
    13631380
    13641381        // Local Utilities:
     1382
     1383        #define construct(T, key, ...) ({ \
     1384                void * data = ::operator new(sizeof(T)); \
     1385                cache.emplace( key, (T*)data ); \
     1386                new (data) T( __VA_ARGS__ ); \
     1387        })
    13651388
    13661389        template<typename NewT, typename OldT>
     
    14241447
    14251448        virtual void visit( ObjectDecl * old ) override final {
    1426                 if ( inCache( old ) ) return;
     1449                if( old->name == "tmp" ) {
     1450                        std::cerr << "building parameters for" << (void*)old << std::endl;
     1451                }
     1452                auto&& type = GET_ACCEPT_1(type, Type);
     1453                auto&& init = GET_ACCEPT_1(init, Init);
     1454                auto&& bfwd = GET_ACCEPT_1(bitfieldWidth, Expr);
     1455                auto&& attr = GET_ACCEPT_V(attributes, Attribute);
     1456                if( old->name == "tmp" ) {
     1457                        std::cerr << "checking cache for " << (void*)old << std::endl;
     1458                }
     1459                if ( inCache( old ) ) {
     1460                        if( old->name == "tmp" ) {
     1461                                std::cerr << (void*)old << "(old) in cache " << (void*)this->node << "(new)" << std::endl;
     1462                        }
     1463                        return;
     1464                }
    14271465                auto decl = new ast::ObjectDecl(
    14281466                        old->location,
    14291467                        old->name,
    1430                         GET_ACCEPT_1(type, Type),
    1431                         GET_ACCEPT_1(init, Init),
     1468                        type,
     1469                        init,
    14321470                        { old->get_storageClasses().val },
    14331471                        { old->linkage.val },
    1434                         GET_ACCEPT_1(bitfieldWidth, Expr),
    1435                         GET_ACCEPT_V(attributes, Attribute),
     1472                        bfwd,
     1473                        std::move(attr),
    14361474                        { old->get_funcSpec().val }
    14371475                );
    1438                 cache.emplace( old, decl );
     1476                cache.emplace(old, decl);
     1477                if( old->name == "tmp" ) {
     1478                        std::cerr << (void*)old << "(old) added to cache with " << (void*)decl << "(new)" << std::endl;
     1479                }
     1480                assert(cache.find( old ) != cache.end());
    14391481                decl->scopeLevel = old->scopeLevel;
    14401482                decl->mangleName = old->mangleName;
     
    14441486
    14451487                this->node = decl;
     1488
     1489                if( old->name == "tmp" ) {
     1490                        std::cerr << (void*)old << "(old) created " << (void*)this->node << "(new)" << std::endl;
     1491                }
    14461492        }
    14471493
     
    20992145
    21002146        virtual void visit( VariableExpr * old ) override final {
    2101                 this->node = visitBaseExpr( old,
    2102                         new ast::VariableExpr(
    2103                                 old->location,
    2104                                 GET_ACCEPT_1(var, DeclWithType)
    2105                         )
    2106                 );
     2147                auto expr = new ast::VariableExpr(
     2148                        old->location
     2149                );
     2150
     2151                visitBaseExpr( old,
     2152                        expr
     2153                );
     2154
     2155                expr->var = GET_ACCEPT_1(var, DeclWithType);
     2156                expr->result = expr->var->get_type();
     2157                add_qualifiers( expr->result, ast::CV::Lvalue );
     2158                this->node = expr;
    21072159        }
    21082160
  • src/AST/Expr.cpp

    r2a54479 r546e712  
    170170// --- VariableExpr
    171171
     172VariableExpr::VariableExpr( const CodeLocation & loc )
     173: Expr( loc ), var( nullptr ) {}
     174
    172175VariableExpr::VariableExpr( const CodeLocation & loc, const DeclWithType * v )
    173176: Expr( loc ), var( v ) {
  • src/AST/Expr.hpp

    r2a54479 r546e712  
    315315        readonly<DeclWithType> var;
    316316
     317        VariableExpr( const CodeLocation & loc );
    317318        VariableExpr( const CodeLocation & loc, const DeclWithType * v );
    318319
  • src/AST/Node.hpp

    r2a54479 r546e712  
    191191        /// wrapper for convenient access to strict_dynamic_cast
    192192        template<typename o_node_t>
    193         const o_node_t * strict_as() const { return strict_dynamic_cast<const o_node_t *>(node); }
     193        const o_node_t * strict_as() const { _check(); return strict_dynamic_cast<const o_node_t *>(node); }
    194194
    195195        /// Returns a mutable version of the pointer in this node.
Note: See TracChangeset for help on using the changeset viewer.