Changeset 7770cc8 for src/AST


Ignore:
Timestamp:
Nov 24, 2021, 9:47:56 PM (4 years ago)
Author:
Michael Brooks <mlbrooks@…>
Branches:
ADT, ast-experimental, enum, master, pthread-emulation, qualifiedEnum, stuck-waitfor-destruct
Children:
5235d49
Parents:
94647b0b (diff), 3cc1111 (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
11 edited

Legend:

Unmodified
Added
Removed
  • src/AST/Convert.cpp

    r94647b0b r7770cc8  
    10411041
    10421042        const ast::Expr * visit( const ast::StmtExpr * node ) override final {
    1043                 auto stmts = node->stmts;
    1044                 // disable sharing between multiple StmtExprs explicitly.
    1045                 // this should no longer be true.
    1046 
    10471043                auto rslt = new StmtExpr(
    1048                         get<CompoundStmt>().accept1(stmts)
     1044                        get<CompoundStmt>().accept1(node->stmts)
    10491045                );
    10501046
    10511047                rslt->returnDecls = get<ObjectDecl>().acceptL(node->returnDecls);
    10521048                rslt->dtors       = get<Expression>().acceptL(node->dtors);
    1053                 if (node->resultExpr) {
    1054                         // this MUST be found by children visit
    1055                         rslt->resultExpr  = strict_dynamic_cast<ExprStmt *>(readonlyCache.at(node->resultExpr));
    1056                 }
     1049
     1050                // is this even used after convert?
     1051                //if (tmp->resultExpr) {
     1052                //      // this MUST be found by children visit
     1053                //      rslt->resultExpr  = strict_dynamic_cast<ExprStmt *>(readonlyCache.at(tmp->resultExpr));
     1054                //}
    10571055
    10581056                auto expr = visitBaseExpr( node, rslt );
     
    14461444
    14471445std::list< Declaration * > convert( const ast::TranslationUnit && translationUnit ) {
     1446        // Copy values from the global store to the local static variables.
     1447        ast::sizeType = translationUnit.global.sizeType;
     1448        ast::dereferenceOperator = translationUnit.global.dereference;
     1449        ast::dtorStruct = translationUnit.global.dtorStruct;
     1450        ast::dtorStructDestroy = translationUnit.global.dtorDestroy;
     1451
    14481452        ConverterNewToOld c;
    14491453        std::list< Declaration * > decls;
  • src/AST/Copy.hpp

    r94647b0b r7770cc8  
    1010// Created On       : Wed Jul 10 16:13:00 2019
    1111// Last Modified By : Andrew Beach
    12 // Last Modified On : Fri Jun 19 16:43:00 2020
    13 // Update Count     : 1
     12// Last Modified On : Thr Nov 11  9:22:00 2021
     13// Update Count     : 2
    1414//
    1515
    1616#pragma once
    1717
    18 #include "Decl.hpp"
    19 #include "Expr.hpp"
    20 #include "Pass.hpp"
    21 #include "Stmt.hpp"
    22 #include "Type.hpp"
    23 #include <unordered_set>
    24 #include <unordered_map>
     18#include "Node.hpp"
     19#include <cassert>
    2520
    2621namespace ast {
     
    4338 */
    4439
    45 class DeepCopyCore {
    46         std::unordered_map< const Node *, const Node * > nodeCache;
    47         std::unordered_set< readonly<Node> * > readonlyCache;
    48 
    49         template<typename node_t>
    50         void readonlyInsert( const readonly<node_t> * ptrptr ) {
    51                 readonlyCache.insert( (readonly<Node> *) ptrptr );
    52         }
    53 
    54 public:
    55         template<typename node_t>
    56         const node_t * previsit( const node_t * node ) {
    57                 const node_t * copy = shallowCopy( node );
    58                 nodeCache.insert( std::make_pair( node, copy ) );
    59                 return copy;
    60         }
    61 
    62         void postvisit( const AggregateDecl * node ) {
    63                 readonlyInsert( &node->parent );
    64         }
    65 
    66         void postvisit( const StructInstType * node ) {
    67                 readonlyInsert( &node->base );
    68         }
    69 
    70         void postvisit( const UnionInstType * node ) {
    71                 readonlyInsert( &node->base );
    72         }
    73 
    74         void postvisit( const EnumInstType * node ) {
    75                 readonlyInsert( &node->base );
    76         }
    77 
    78         void postvisit( const TraitInstType * node ) {
    79                 readonlyInsert( &node->base );
    80         }
    81 
    82         void postvisit( const TypeInstType * node ) {
    83                 readonlyInsert( &node->base );
    84         }
    85 
    86         void postvisit( const ImplicitCtorDtorStmt * node ) {
    87                 readonlyInsert( (const readonly<Stmt> *) &node->callStmt );
    88         }
    89 
    90         void postvisit( const MemberExpr * node ) {
    91                 readonlyInsert( &node->member );
    92         }
    93 
    94         void postvisit( const VariableExpr * node ) {
    95                 readonlyInsert( &node->var );
    96         }
    97 
    98         void postvisit( const OffsetofExpr * node ) {
    99                 readonlyInsert( &node->member );
    100         }
    101 
    102         void postvisit( const DeletedExpr * node ) {
    103                 readonlyInsert( &node->deleteStmt );
    104         }
    105 
    106         void readonlyUpdates() {
    107                 for ( readonly<Node> * ptr : readonlyCache ) {
    108                         auto it = nodeCache.find( ptr->get() );
    109                         if ( nodeCache.end() != it ) {
    110                                 *ptr = it->second;
    111                         }
    112                 }
    113         }
    114 };
    115 
     40// Implementations:
    11641template<typename node_t>
    11742node_t * shallowCopy( const node_t * localRoot ) {
     
    12146template<typename node_t>
    12247node_t * deepCopy( const node_t * localRoot ) {
    123         Pass< DeepCopyCore > dc;
    124         node_t const * newRoot = localRoot->accept( dc );
    125         dc.core.readonlyUpdates();
    126         return const_cast< node_t * >( newRoot );
     48        return strict_dynamic_cast<node_t *>( deepCopy<Node>( localRoot ) );
    12749}
     50
     51template<>
     52Node * deepCopy<Node>( const Node * localRoot );
    12853
    12954}
  • src/AST/Decl.hpp

    r94647b0b r7770cc8  
    131131        // declared type, derived from parameter declarations
    132132        ptr<FunctionType> type;
     133        /// Null for the forward declaration of a function.
    133134        ptr<CompoundStmt> stmts;
    134135        std::vector< ptr<Expr> > withExprs;
     
    269270        : AggregateDecl( loc, name, std::move(attrs), linkage ), kind( kind ) {}
    270271
    271         bool is_coroutine() { return kind == Coroutine; }
    272         bool is_generator() { return kind == Generator; }
    273         bool is_monitor  () { return kind == Monitor  ; }
    274         bool is_thread   () { return kind == Thread   ; }
     272        bool is_coroutine() const { return kind == Coroutine; }
     273        bool is_generator() const { return kind == Generator; }
     274        bool is_monitor  () const { return kind == Monitor  ; }
     275        bool is_thread   () const { return kind == Thread   ; }
    275276
    276277        const Decl * accept( Visitor & v ) const override { return v.visit( this ); }
  • src/AST/Init.hpp

    r94647b0b r7770cc8  
    9898        const_iterator begin() const { return initializers.begin(); }
    9999        const_iterator end() const { return initializers.end(); }
     100        size_t size() const { return initializers.size(); }
    100101
    101102        const Init * accept( Visitor & v ) const override { return v.visit( this ); }
  • src/AST/Pass.hpp

    r94647b0b r7770cc8  
    109109        static auto read( node_type const * node, Args&&... args ) {
    110110                Pass<core_t> visitor( std::forward<Args>( args )... );
    111                 node_type const * temp = node->accept( visitor );
     111                auto const * temp = node->accept( visitor );
    112112                assert( temp == node );
    113113                return visitor.get_result();
     
    124124        static auto read( node_type const * node ) {
    125125                Pass<core_t> visitor;
    126                 node_type const * temp = node->accept( visitor );
     126                auto const * temp = node->accept( visitor );
    127127                assert( temp == node );
    128128                return visitor.get_result();
     
    348348
    349349        /// When this node is finished being visited, restore the value of a variable
     350        /// You may assign to the return value to set the new value in the same statement.
    350351        template< typename T >
    351         void GuardValue( T& val ) {
     352        T& GuardValue( T& val ) {
    352353                at_cleanup( [ val ]( void * newVal ) {
    353354                        * static_cast< T * >( newVal ) = val;
    354355                }, static_cast< void * >( & val ) );
     356                return val;
    355357        }
    356358
     
    394396};
    395397
     398/// Used to get a pointer to the wrapping TranslationUnit.
     399struct WithConstTranslationUnit {
     400        const TranslationUnit * translationUnit = nullptr;
     401
     402        const TranslationUnit & transUnit() const {
     403                assertf( translationUnit, "WithConstTranslationUnit not set-up." );
     404                return *translationUnit;
     405        }
     406};
     407
    396408}
    397409
  • src/AST/Pass.impl.hpp

    r94647b0b r7770cc8  
    420420template< typename core_t >
    421421inline void ast::accept_all( ast::TranslationUnit & unit, ast::Pass< core_t > & visitor ) {
    422         return ast::accept_all( unit.decls, visitor );
     422        if ( auto ptr = __pass::translation_unit::get_cptr( visitor.core, 0 ) ) {
     423                ValueGuard<const TranslationUnit *> guard( *ptr );
     424                *ptr = &unit;
     425                return ast::accept_all( unit.decls, visitor );
     426        } else {
     427                return ast::accept_all( unit.decls, visitor );
     428        }
    423429}
    424430
  • src/AST/Pass.proto.hpp

    r94647b0b r7770cc8  
    426426        } // namespace forall
    427427
     428        // For passes that need access to the global context. Sreaches `translationUnit`
     429        namespace translation_unit {
     430                template<typename core_t>
     431                static inline auto get_cptr( core_t & core, int )
     432                                -> decltype( &core.translationUnit ) {
     433                        return &core.translationUnit;
     434                }
     435
     436                template<typename core_t>
     437                static inline const TranslationUnit ** get_cptr( core_t &, long ) {
     438                        return nullptr;
     439                }
     440        }
     441
    428442        template<typename core_t>
    429443        static inline auto get_result( core_t & core, char ) -> decltype( core.result() ) {
  • src/AST/Stmt.hpp

    r94647b0b r7770cc8  
    175175class CaseStmt final : public Stmt {
    176176public:
     177        /// Null for the default label.
    177178        ptr<Expr> cond;
    178179        std::vector<ptr<Stmt>> stmts;
  • src/AST/TranslationUnit.hpp

    r94647b0b r7770cc8  
    2626        std::list< ptr< Decl > > decls;
    2727
    28         struct Globals {
     28        struct Global {
    2929                std::map< UniqueId, Decl * > idMap;
    3030
    31                 const Type * sizeType;
     31                ptr<Type> sizeType;
    3232                const FunctionDecl * dereference;
    3333                const StructDecl * dtorStruct;
  • src/AST/module.mk

    r94647b0b r7770cc8  
    2424        AST/Convert.cpp \
    2525        AST/Convert.hpp \
     26        AST/Copy.cpp \
    2627        AST/Copy.hpp \
    2728        AST/CVQualifiers.hpp \
  • src/AST/porting.md

    r94647b0b r7770cc8  
    9898        * `Initializer` => `ast::Init`
    9999    * `Statement` => `ast::Stmt`
     100    * `ReferenceToType` => `ast::BaseInstType`
    100101        * any field names should follow a similar renaming
    101102  * because they don't really belong to `Type` (and for consistency with `Linkage::Spec`):
Note: See TracChangeset for help on using the changeset viewer.