Changeset 10a1225


Ignore:
Timestamp:
May 17, 2019, 12:09:51 PM (2 years ago)
Author:
Thierry Delisle <tdelisle@…>
Branches:
arm-eh, cleanup-dtors, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr
Children:
896737b
Parents:
77bfc80
Message:

Many errors and warning fixes.
More visit implementation

Location:
src/AST
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • src/AST/Decl.hpp

    r77bfc80 r10a1225  
    101101        ptr<Expr> bitfieldWidth;
    102102
    103         ObjectDecl( const CodeLocation& loc, const std::string& name, Type* type, Init* init = nullptr,
    104                 Storage::Classes storage = {}, Linkage::Spec linkage = Linkage::C, Expr* bitWd = nullptr,
    105                 std::vector<ptr<Attribute>>&& attrs = {}, Function::Specs fs = {})
     103        ObjectDecl( const CodeLocation & loc, const std::string & name, const Type * type, Init * init = nullptr,
     104                Storage::Classes storage = {}, Linkage::Spec linkage = Linkage::C, Expr * bitWd = nullptr,
     105                std::vector< ptr<Attribute> > && attrs = {}, Function::Specs fs = {})
    106106        : DeclWithType( loc, name, storage, linkage, std::move(attrs), fs ), type( type ),
    107107          init( init ), bitfieldWidth( bitWd ) {}
  • src/AST/DeclReplacer.cpp

    r77bfc80 r10a1225  
    1414//
    1515
    16 #error unimplemented
     16#warning unimplemented
    1717
    1818// Local Variables: //
  • src/AST/Expr.cpp

    r77bfc80 r10a1225  
    9595        Type * addrType( const Type * type ) {
    9696                if ( const ReferenceType * refType = dynamic_cast< const ReferenceType * >( type ) ) {
    97                         CV::Qualifiers quals = refType->qualifiers;
    9897                        return new ReferenceType{ addrType( refType->base ), refType->qualifiers };
    9998                } else {
     
    118117                                result = res;
    119118                        } else {
    120                                 SemanticError( loc, arg->result,
     119                                SemanticError( loc, arg->result.get(),
    121120                                        "Attempt to take address of non-lvalue expression: " );
    122121                        }
     
    283282// --- ConstructorExpr
    284283
    285 ConstructorExpr::ConstructorExpr( const CodeLocation & loc, const Expr * call ) 
     284ConstructorExpr::ConstructorExpr( const CodeLocation & loc, const Expr * call )
    286285: Expr( loc ), callExpr( call ) {
    287         // allow resolver to type a constructor used as an expression if it has the same type as its 
     286        // allow resolver to type a constructor used as an expression if it has the same type as its
    288287        // first argument
    289288        assert( callExpr );
     
    310309TupleIndexExpr::TupleIndexExpr( const CodeLocation & loc, const Expr * t, unsigned i )
    311310: Expr( loc ), tuple( t ), index( i ) {
    312         const TupleType * type = strict_dynamic_cast< const TupleType * >( tuple->result );
     311        const TupleType * type = strict_dynamic_cast< const TupleType * >( tuple->result.get() );
    313312        assertf( type->size() > index, "TupleIndexExpr index out of bounds: tuple size %d, requested "
    314313                "index %d in expr %s", type->size(), index, toString( tuple ).c_str() );
     
    319318// --- TupleAssignExpr
    320319
    321 TupleAssignExpr::TupleAssignExpr( 
    322         const CodeLocation & loc, std::vector<ptr<Expr>> && assigns, 
     320TupleAssignExpr::TupleAssignExpr(
     321        const CodeLocation & loc, std::vector<ptr<Expr>> && assigns,
    323322        std::vector<ptr<ObjectDecl>> && tempDecls )
    324323: Expr( loc, Tuples::makeTupleType( assigns ) ), stmtExpr() {
    325         // convert internally into a StmtExpr which contains the declarations and produces the tuple of 
     324        // convert internally into a StmtExpr which contains the declarations and produces the tuple of
    326325        // the assignments
    327326        std::list<ptr<Stmt>> stmts;
     
    337336// --- StmtExpr
    338337
    339 StmtExpr::StmtExpr( const CodeLocation & loc, const CompoundStmt * ss ) 
     338StmtExpr::StmtExpr( const CodeLocation & loc, const CompoundStmt * ss )
    340339: Expr( loc ), stmts( ss ), returnDecls(), dtors() { computeResult(); }
    341340
     
    344343        const std::list<ptr<Stmt>> & body = stmts->kids;
    345344        if ( ! returnDecls.empty() ) {
    346                 // prioritize return decl for result type, since if a return decl exists, then the StmtExpr 
     345                // prioritize return decl for result type, since if a return decl exists, then the StmtExpr
    347346                // is currently in an intermediate state where the body will always give a void result type
    348347                result = returnDecls.front()->get_type();
     
    360359unsigned long long UniqueExpr::nextId = 0;
    361360
    362 UniqueExpr::UniqueExpr( const CodeLocation & loc, const Expr * e, unsigned long long i = -1 )
     361UniqueExpr::UniqueExpr( const CodeLocation & loc, const Expr * e, unsigned long long i )
    363362: Expr( loc, e->result ), id( i ) {
    364363        assert( expr );
    365         if ( id == -1 ) {
    366                 assert( nextId != -1 );
     364        if ( id == -1ull ) {
     365                assert( nextId != -1ull );
    367366                id = nextId++;
    368367        }
     368}
     369
    369370}
    370371
  • src/AST/Fwd.hpp

    r77bfc80 r10a1225  
    125125class ConstructorInit;
    126126
    127 class Constant;
    128 
    129127class Label;
    130128
     
    135133std::string toString( const Node * );
    136134
     135template < typename ... Params >
     136std::string toString( const Params & ... params );
     137
    137138typedef unsigned int UniqueId;
    138139
  • src/AST/Node.cpp

    r77bfc80 r10a1225  
    1616#include "Node.hpp"
    1717#include "Fwd.hpp"
     18
     19#include "Attribute.hpp"
    1820#include "Decl.hpp"
    1921#include "Expr.hpp"
     22#include "Init.hpp"
    2023#include "Stmt.hpp"
    2124#include "Type.hpp"
     25#include "TypeSubstitution.hpp"
    2226
    2327template< typename node_t, enum ast::Node::ref_type ref_t >
     
    2630template< typename node_t, enum ast::Node::ref_type ref_t >
    2731void ast::ptr_base<node_t, ref_t>::_dec( const node_t * node ) { node->decrement(ref_t); }
     32
     33/// Sets this pointer to a mutated version of a pointer (possibly) owned elsehere.
     34/// Returns a mutable version of the pointer in this node.
     35template< typename node_t, enum ast::Node::ref_type ref_t >
     36node_t * ast::ptr_base<node_t, ref_t>::set_and_mutate( const node_t * n ) {
     37        // ensure ownership of `n` by this node to avoid spurious single-owner mutates
     38        assign( n );
     39        // get mutable version of `n`
     40        auto r = mutate( node );
     41        // re-assign mutable version in case `mutate()` produced a new pointer
     42        assign( r );
     43        return r;
     44}
    2845
    2946template class ast::ptr_base< ast::Node, ast::Node::ref_type::weak >;
     
    227244template class ast::ptr_base< ast::ConstructorInit, ast::Node::ref_type::weak >;
    228245template class ast::ptr_base< ast::ConstructorInit, ast::Node::ref_type::strong >;
    229 template class ast::ptr_base< ast::Constant, ast::Node::ref_type::weak >;
    230 template class ast::ptr_base< ast::Constant, ast::Node::ref_type::strong >;
    231246template class ast::ptr_base< ast::Attribute, ast::Node::ref_type::weak >;
    232247template class ast::ptr_base< ast::Attribute, ast::Node::ref_type::strong >;
  • src/AST/Node.hpp

    r77bfc80 r10a1225  
    143143        /// Sets this pointer to a mutated version of a pointer (possibly) owned elsehere.
    144144        /// Returns a mutable version of the pointer in this node.
    145         node_t * set_and_mutate( const node_t * n ) {
    146                 // ensure ownership of `n` by this node to avoid spurious single-owner mutates
    147                 assign( n );
    148                 // get mutable version of `n`
    149                 auto r = mutate( node );
    150                 // re-assign mutable version in case `mutate()` produced a new pointer
    151                 assign( r );
    152                 return r;
    153         }
     145        node_t * set_and_mutate( const node_t * n );
    154146
    155147        using ptr = const node_t *;
  • src/AST/Pass.hpp

    r77bfc80 r10a1225  
    175175        const ast::Init *             visit( const ast::ListInit             * ) override final;
    176176        const ast::Init *             visit( const ast::ConstructorInit      * ) override final;
    177         const ast::Constant *         visit( const ast::Constant             * ) override final;
    178177        const ast::Attribute *        visit( const ast::Attribute            * ) override final;
    179178        const ast::TypeSubstitution * visit( const ast::TypeSubstitution     * ) override final;
  • src/AST/Pass.impl.hpp

    r77bfc80 r10a1225  
    791791
    792792//--------------------------------------------------------------------------
     793// CatchStmt
     794template< typename pass_t >
     795const ast::Stmt * ast::Pass< pass_t >::visit( const ast::CatchStmt * node ) {
     796        VISIT_START( node );
     797
     798        VISIT({
     799                // catch statements introduce a level of scope (for the caught exception)
     800                guard_indexer guard { *this };
     801                maybe_accept( node, &CatchStmt::decl );
     802                maybe_accept( node, &CatchStmt::cond );
     803                maybe_accept( node, &CatchStmt::body );
     804        })
     805
     806        VISIT_END( Stmt, node );
     807}
     808
     809//--------------------------------------------------------------------------
     810// FinallyStmt
     811template< typename pass_t >
     812const ast::Stmt * ast::Pass< pass_t >::visit( const ast::FinallyStmt * node ) {
     813        VISIT_START( node );
     814
     815        VISIT(
     816                maybe_accept( node, &FinallyStmt::body );
     817        )
     818
     819        VISIT_END( Stmt, node );
     820}
     821
     822//--------------------------------------------------------------------------
     823// WaitForStmt
     824template< typename pass_t >
     825const ast::Stmt * ast::Pass< pass_t >::visit( const ast::WaitForStmt * node ) {
     826        VISIT_START( node );
     827                // for( auto & clause : node->clauses ) {
     828                //      maybeAccept_impl( clause.target.function, *this );
     829                //      maybeAccept_impl( clause.target.arguments, *this );
     830
     831                //      maybeAccept_impl( clause.statement, *this );
     832                //      maybeAccept_impl( clause.condition, *this );
     833                // }
     834
     835        #define maybe_accept(field) \
     836                if(node->field) { \
     837                        auto nval = call_accept( node->field ); \
     838                        if(nval != node->field ) { \
     839                                auto nparent = mutate(node); \
     840                                nparent->field = nval; \
     841                                node = nparent; \
     842                        } \
     843                }
     844
     845        VISIT(
     846                maybe_accept( timeout.time );
     847                maybe_accept( timeout.stmt );
     848                maybe_accept( timeout.cond );
     849                maybe_accept( orElse.stmt  );
     850                maybe_accept( orElse.cond  );
     851        )
     852
     853        #undef maybe_accept
     854
     855        VISIT_END( Stmt, node );
     856}
     857
     858//--------------------------------------------------------------------------
     859// WithStmt
     860template< typename pass_t >
     861const ast::Stmt * ast::Pass< pass_t >::visit( const ast::WithStmt * node ) {
     862        VISIT_START( node );
     863
     864        VISIT(
     865                maybe_accept( node, &WithStmt::exprs );
     866                {
     867                        // catch statements introduce a level of scope (for the caught exception)
     868                        guard_indexer guard { *this };
     869                        __pass::indexer::addWith( pass, 0, node->exprs, node );
     870                        maybe_accept( node, &WithStmt::stmt );
     871                }
     872        )
     873        VISIT_END( Stmt, node );
     874}
     875
     876//--------------------------------------------------------------------------
     877// NullStmt
     878template< typename pass_t >
     879const ast::NullStmt * ast::Pass< pass_t >::visit( const ast::NullStmt * node ) {
     880        VISIT_START( node );
     881        VISIT_END( NullStmt, node );
     882}
     883
     884//--------------------------------------------------------------------------
     885// DeclStmt
     886template< typename pass_t >
     887const ast::Stmt * ast::Pass< pass_t >::visit( const ast::DeclStmt * node ) {
     888        VISIT_START( node );
     889
     890        VISIT(
     891                maybe_accept( node, &DeclStmt::decl );
     892        )
     893
     894        VISIT_END( Stmt, node );
     895}
     896
     897//--------------------------------------------------------------------------
     898// ImplicitCtorDtorStmt
     899template< typename pass_t >
     900const ast::Stmt * ast::Pass< pass_t >::visit( const ast::ImplicitCtorDtorStmt * node ) {
     901        VISIT_START( node );
     902
     903        // For now this isn't visited, it is unclear if this causes problem
     904        // if all tests are known to pass, remove this code
     905        // VISIT(
     906        //      maybe_accept( node, &ImplicitCtorDtorStmt::callStmt );
     907        // )
     908
     909        VISIT_END( Stmt, node );
     910}
     911
     912
     913
     914
     915
     916
     917//--------------------------------------------------------------------------
    793918// SingleInit
    794919template< typename pass_t >
  • src/AST/Pass.proto.hpp

    r77bfc80 r10a1225  
    241241                INDEXER_FUNC1( addUnion  , const UnionDecl *     );
    242242                INDEXER_FUNC1( addTrait  , const TraitDecl *     );
    243                 INDEXER_FUNC2( addWith   , const std::list< ptr<Expr> > &, const Node * );
     243                INDEXER_FUNC2( addWith   , const std::vector< ptr<Expr> > &, const Node * );
     244                INDEXER_FUNC2( addWith   , const std::list  < ptr<Expr> > &, const Node * );
    244245
    245246                // A few extra functions have more complicated behaviour, they are hand written
  • src/AST/Visitor.hpp

    r77bfc80 r10a1225  
    111111    virtual const ast::Init *             visit( const ast::ListInit             * ) = 0;
    112112    virtual const ast::Init *             visit( const ast::ConstructorInit      * ) = 0;
    113     virtual const ast::Constant *         visit( const ast::Constant             * ) = 0;
    114113    virtual const ast::Attribute *        visit( const ast::Attribute            * ) = 0;
    115114    virtual const ast::TypeSubstitution * visit( const ast::TypeSubstitution     * ) = 0;
Note: See TracChangeset for help on using the changeset viewer.