Changeset 8c0d801 for src/AST


Ignore:
Timestamp:
Jun 6, 2019, 3:40:56 PM (5 years ago)
Author:
Aaron Moss <a3moss@…>
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:
1a4323e
Parents:
b7d92b96 (diff), 546e712 (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:
4 edited

Legend:

Unmodified
Added
Removed
  • src/AST/Convert.cpp

    rb7d92b96 r8c0d801  
    1010// Created On       : Thu May 09 15::37::05 2019
    1111// Last Modified By : Andrew Beach
    12 // Last Modified On : Wed May 29 17:05:00 2019
    13 // Update Count     : 9
     12// Last Modified On : Thu May 06 19:51:00 2019
     13// Update Count     : 10
    1414//
    1515
     
    4949// This is to preserve the FindSpecialDecls hack. It does not (and perhaps should not)
    5050// allow us to use the same stratagy in the new ast.
     51ast::Type * sizeType = nullptr;
    5152ast::FunctionDecl * dereferenceOperator = nullptr;
    5253ast::StructDecl   * dtorStruct = nullptr;
     
    147148
    148149        const ast::DeclWithType * visit( const ast::ObjectDecl * node ) override final {
    149                 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                }
    150160                auto decl = new ObjectDecl(
    151161                        node->name,
    152162                        Type::StorageClasses( node->storage.val ),
    153163                        LinkageSpec::Spec( node->linkage.val ),
    154                         get<Expression>().accept1( node->bitfieldWidth ),
    155                         get<Type>().accept1( node->type ),
    156                         get<Initializer>().accept1( node->init ),
    157                         get<Attribute>().acceptL( node->attributes ),
     164                        bfwd,
     165                        type,
     166                        init,
     167                        attr,
    158168                        Type::FuncSpecifiers( node->funcSpec.val )
    159169                );
     170                if(node->name == "tmp") {
     171                        std::cerr << (void*)node << "(new) created " << (void*)decl << "(old)" << std::endl;
     172                }
    160173                return declWithTypePostamble( decl, node );
    161174        }
     
    709722                auto expr = visitBaseExpr( node,
    710723                        new MemberExpr(
    711                                 inCache(node->member) ?
    712                                         dynamic_cast<DeclarationWithType *>(this->node) :
    713                                         get<DeclarationWithType>().accept1(node->member),
     724                                get<DeclarationWithType>().accept1(node->member),
    714725                                get<Expression>().accept1(node->aggregate)
    715726                        )
     
    720731
    721732        const ast::Expr * visit( const ast::VariableExpr * node ) override final {
    722                 auto expr = visitBaseExpr( node,
    723                         new VariableExpr(
    724                                 inCache(node->var) ?
    725                                         dynamic_cast<DeclarationWithType *>(this->node) :
    726                                         get<DeclarationWithType>().accept1(node->var)
    727                         )
    728                 );
     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 );
    729739                this->node = expr;
    730740                return nullptr;
     
    819829                        new OffsetofExpr(
    820830                                get<Type>().accept1(node->type),
    821                                 inCache(node->member) ?
    822                                         dynamic_cast<DeclarationWithType *>(this->node) :
    823                                         get<DeclarationWithType>().accept1(node->member)
     831                                get<DeclarationWithType>().accept1(node->member)
    824832                        )
    825833                );
     
    10821090
    10831091        const ast::Type * visit( const ast::BasicType * node ) override final {
    1084                 this->node = new BasicType{ cv( node ), (BasicType::Kind)(unsigned)node->kind };
     1092                auto type = new BasicType{ cv( node ), (BasicType::Kind)(unsigned)node->kind };
     1093                // I believe this should always be a BasicType.
     1094                if ( sizeType == node ) {
     1095                        Validate::SizeType = type;
     1096                }
     1097                this->node = type;
    10851098                return nullptr;
    10861099        }
     
    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
     
    20922138                        new ast::MemberExpr(
    20932139                                old->location,
    2094                                 inCache(old->member) ?
    2095                                         dynamic_cast<ast::DeclWithType *>(this->node) :
    2096                                         GET_ACCEPT_1(member, DeclWithType),
     2140                                GET_ACCEPT_1(member, DeclWithType),
    20972141                                GET_ACCEPT_1(aggregate, Expr)
    20982142                        )
     
    21012145
    21022146        virtual void visit( VariableExpr * old ) override final {
    2103                 this->node = visitBaseExpr( old,
    2104                         new ast::VariableExpr(
    2105                                 old->location,
    2106                                 inCache(old->var) ?
    2107                                         dynamic_cast<ast::DeclWithType *>(this->node) :
    2108                                         GET_ACCEPT_1(var, DeclWithType)
    2109                         )
    2110                 );
     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;
    21112159        }
    21122160
     
    22342282                                old->location,
    22352283                                GET_ACCEPT_1(type, Type),
    2236                                 inCache(old->member) ?
    2237                                         dynamic_cast<ast::DeclWithType *>(this->node) :
    2238                                         GET_ACCEPT_1(member, DeclWithType)
     2284                                GET_ACCEPT_1(member, DeclWithType)
    22392285                        )
    22402286                );
     
    24722518
    24732519        virtual void visit( BasicType * old ) override final {
    2474                 this->node = new ast::BasicType{ (ast::BasicType::Kind)(unsigned)old->kind, cv( old ) };
     2520                auto type = new ast::BasicType{ (ast::BasicType::Kind)(unsigned)old->kind, cv( old ) };
     2521                // I believe this should always be a BasicType.
     2522                if ( Validate::SizeType == old ) {
     2523                        sizeType = type;
     2524                }
     2525                this->node = type;
    24752526        }
    24762527
  • src/AST/Expr.cpp

    rb7d92b96 r8c0d801  
    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

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

    rb7d92b96 r8c0d801  
    206206        /// wrapper for convenient access to strict_dynamic_cast
    207207        template<typename o_node_t>
    208         const o_node_t * strict_as() const { return strict_dynamic_cast<const o_node_t *>(node); }
     208        const o_node_t * strict_as() const { _check(); return strict_dynamic_cast<const o_node_t *>(node); }
    209209
    210210        /// Returns a mutable version of the pointer in this node.
Note: See TracChangeset for help on using the changeset viewer.