Changeset 2c04369


Ignore:
Timestamp:
May 28, 2019, 12:04:43 PM (5 years ago)
Author:
Andrew Beach <ajbeach@…>
Branches:
ADT, arm-eh, ast-experimental, cleanup-dtors, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
Children:
0d70e0d
Parents:
a7d50b6
Message:

Fixed some problems in convert. One of which was better solved by removing the FindSpecialDeclarations? hack.

Location:
src
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • src/AST/Convert.cpp

    ra7d50b6 r2c04369  
    1010// Created On       : Thu May 09 15::37::05 2019
    1111// Last Modified By : Andrew Beach
    12 // Last Modified On : Thu May 23 16:59:00 2019
    13 // Update Count     : 6
     12// Last Modified On : Tue May 28 12:00:00 2019
     13// Update Count     : 7
    1414//
    1515
     
    13411341                if ( ! old ) return nullptr;
    13421342                old->accept(*this);
    1343                 return strict_dynamic_cast< NewT * >( node );
     1343                ast::Node * ret = node;
     1344                node = nullptr;
     1345                return strict_dynamic_cast< NewT * >( ret );
    13441346        }
    13451347
     
    13541356                        a->accept( *this );
    13551357                        ret.emplace_back( strict_dynamic_cast< NewT * >(node) );
     1358                        node = nullptr;
    13561359                }
    13571360                return ret;
     
    18771880                        GET_LABELS_V(old->labels)
    18781881                );
     1882                cache.emplace( old, stmt );
     1883                stmt->callStmt = GET_ACCEPT_1(callStmt, Stmt);
    18791884                this->node = stmt;
    1880                 cache.emplace( old, this->node );
    1881                 stmt->callStmt = GET_ACCEPT_1(callStmt, Stmt);
    18821885        }
    18831886
  • src/GenPoly/Lvalue.cc

    ra7d50b6 r2c04369  
    99// Author           : Richard C. Bilson
    1010// Created On       : Mon May 18 07:44:20 2015
    11 // Last Modified By : Peter A. Buhr
    12 // Last Modified On : Fri Mar 17 09:11:18 2017
    13 // Update Count     : 5
     11// Last Modified By : Andrew Beach
     12// Last Modified On : Tue May 28 11:07:00 2019
     13// Update Count     : 6
    1414//
    1515
     
    4242namespace GenPoly {
    4343        namespace {
    44                 // TODO: fold this into the general createDeref function??
    45                 Expression * mkDeref( Expression * arg ) {
    46                         if ( SymTab::dereferenceOperator ) {
    47                                 // note: reference depth can be arbitrarily deep here, so peel off the outermost pointer/reference, not just pointer because they are effecitvely equivalent in this pass
    48                                 VariableExpr * deref = new VariableExpr( SymTab::dereferenceOperator );
    49                                 deref->result = new PointerType( Type::Qualifiers(), deref->result );
    50                                 Type * base = InitTweak::getPointerBase( arg->result );
    51                                 assertf( base, "expected pointer type in dereference (type was %s)", toString( arg->result ).c_str() );
    52                                 ApplicationExpr * ret = new ApplicationExpr( deref, { arg } );
    53                                 delete ret->result;
    54                                 ret->result = base->clone();
    55                                 ret->result->set_lvalue( true );
    56                                 return ret;
    57                         } else {
    58                                 return UntypedExpr::createDeref( arg );
    59                         }
    60                 }
    61 
    62                 struct ReferenceConversions final : public WithStmtsToAdd {
     44                /// Local helper for pass visitors that need to add reference operations.
     45                struct WithDerefOp {
     46                        FunctionDecl * dereferenceOperator = nullptr;
     47
     48                        // TODO: fold this into the general createDeref function??
     49                        Expression * mkDeref( Expression * arg ) {
     50                                if ( dereferenceOperator ) {
     51                                        // note: reference depth can be arbitrarily deep here, so peel off the
     52                                        // outermost pointer/reference, not just pointer because they are effecitvely
     53                                        // equivalent in this pass
     54                                        VariableExpr * deref = new VariableExpr( dereferenceOperator );
     55                                        deref->result = new PointerType( Type::Qualifiers(), deref->result );
     56                                        Type * base = InitTweak::getPointerBase( arg->result );
     57                                        assertf( base, "expected pointer type in dereference (type was %s)",
     58                                                toString( arg->result ).c_str() );
     59                                        ApplicationExpr * ret = new ApplicationExpr( deref, { arg } );
     60                                        delete ret->result;
     61                                        ret->result = base->clone();
     62                                        ret->result->set_lvalue( true );
     63                                        return ret;
     64                                } else {
     65                                        return UntypedExpr::createDeref( arg );
     66                                }
     67                        }
     68
     69                        void previsit( FunctionDecl * funcDecl ) {
     70                                if ( dereferenceOperator ) return;
     71                                if ( funcDecl->get_name() != "*?" ) return;
     72                                if ( funcDecl->get_linkage() == LinkageSpec::Intrinsic ) return;
     73                                FunctionType * ftype = funcDecl->get_functionType();
     74                                if ( ftype->get_parameters().size() != 1 ) return;
     75                                DeclarationWithType * arg0 = ftype->get_parameters().front();
     76                                if ( arg0->get_type()->get_qualifiers() == Type::Qualifiers() ) return;
     77                                dereferenceOperator = funcDecl;
     78                        }
     79                };
     80
     81                struct ReferenceConversions final : public WithStmtsToAdd, public WithDerefOp {
    6382                        Expression * postmutate( CastExpr * castExpr );
    6483                        Expression * postmutate( AddressExpr * addrExpr );
     
    6685
    6786                /// Intrinsic functions that take reference parameters don't REALLY take reference parameters -- their reference arguments must always be implicitly dereferenced.
    68                 struct FixIntrinsicArgs final {
     87                struct FixIntrinsicArgs final : public WithDerefOp {
    6988                        Expression * postmutate( ApplicationExpr * appExpr );
    7089                };
     
    98117                };
    99118
    100                 struct AddrRef final : public WithGuards, public WithVisitorRef<AddrRef>, public WithShortCircuiting {
     119                struct AddrRef final : public WithGuards, public WithVisitorRef<AddrRef>,
     120                                public WithShortCircuiting, public WithDerefOp {
    101121                        void premutate( AddressExpr * addrExpr );
    102122                        Expression * postmutate( AddressExpr * addrExpr );
  • src/SymTab/Autogen.h

    ra7d50b6 r2c04369  
    99// Author           : Rob Schluntz
    1010// Created On       : Sun May 17 21:53:34 2015
    11 // Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sat Jul 22 09:50:25 2017
    13 // Update Count     : 15
     11// Last Modified By : Andrew Beach
     12// Last Modified On : Tue May 28 11:04:00 2019
     13// Update Count     : 16
    1414//
    1515
     
    4040        /// such as in determining array dimension type
    4141        extern Type * SizeType;
    42 
    43         /// intrinsic dereference operator for unqualified types - set when *? function is seen in FindSpecialDeclarations.
    44         /// Useful for creating dereference ApplicationExprs without a full resolver pass.
    45         extern FunctionDecl * dereferenceOperator;
    4642
    4743        // generate the type of an assignment function for paramType
  • src/SymTab/Validate.cc

    ra7d50b6 r2c04369  
    99// Author           : Richard C. Bilson
    1010// Created On       : Sun May 17 21:50:04 2015
    11 // Last Modified By : Peter A. Buhr
    12 // Last Modified On : Mon Aug 28 13:47:23 2017
    13 // Update Count     : 359
     11// Last Modified By : Andrew Beach
     12// Last Modified On : Tue May 28 11:07:00 2019
     13// Update Count     : 360
    1414//
    1515
     
    288288        };
    289289
    290         FunctionDecl * dereferenceOperator = nullptr;
    291         struct FindSpecialDeclarations final {
    292                 void previsit( FunctionDecl * funcDecl );
    293         };
    294 
    295290        void validate( std::list< Declaration * > &translationUnit, __attribute__((unused)) bool doDebug ) {
    296291                PassVisitor<EnumAndPointerDecay> epc;
     
    299294                PassVisitor<CompoundLiteral> compoundliteral;
    300295                PassVisitor<ValidateGenericParameters> genericParams;
    301                 PassVisitor<FindSpecialDeclarations> finder;
    302296                PassVisitor<LabelAddressFixer> labelAddrFixer;
    303297                PassVisitor<HoistTypeDecls> hoistDecls;
     
    376370                        Stats::Time::TimeBlock("Array Length", [&]() {
    377371                                ArrayLength::computeLength( translationUnit );
    378                         });
    379                         Stats::Time::TimeBlock("Find Special Declarations", [&]() {
    380                                 acceptAll( translationUnit, finder ); // xxx - remove this pass soon
    381372                        });
    382373                        Stats::Time::TimeBlock("Fix Label Address", [&]() {
     
    13721363                return addrExpr;
    13731364        }
    1374 
    1375         void FindSpecialDeclarations::previsit( FunctionDecl * funcDecl ) {
    1376                 if ( ! dereferenceOperator ) {
    1377                         if ( funcDecl->get_name() == "*?" && funcDecl->get_linkage() == LinkageSpec::Intrinsic ) {
    1378                                 FunctionType * ftype = funcDecl->get_functionType();
    1379                                 if ( ftype->get_parameters().size() == 1 && ftype->get_parameters().front()->get_type()->get_qualifiers() == Type::Qualifiers() ) {
    1380                                         dereferenceOperator = funcDecl;
    1381                                 }
    1382                         }
    1383                 }
    1384         }
    13851365} // namespace SymTab
    13861366
Note: See TracChangeset for help on using the changeset viewer.