Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Tuples/TupleExpansion.cc

    rb4f8808 raee472e  
    99// Author           : Rodolfo G. Esteves
    1010// Created On       : Mon May 18 07:44:20 2015
    11 // Last Modified By : Andrew Beach
    12 // Last Modified On : Fri Jul 19 14:39:00 2019
    13 // Update Count     : 22
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Wed Jun 21 17:35:04 2017
     13// Update Count     : 19
    1414//
    1515
     
    1717#include <cassert>                // for assert
    1818#include <list>                   // for list
    19 #include <vector>
    20 
    21 #include "AST/CVQualifiers.hpp"
    22 #include "AST/Expr.hpp"
    23 #include "AST/Node.hpp"
    24 #include "AST/Type.hpp"
     19
    2520#include "Common/PassVisitor.h"   // for PassVisitor, WithDeclsToAdd, WithGu...
    2621#include "Common/ScopedMap.h"     // for ScopedMap
     
    6358                };
    6459
    65                 struct TupleTypeReplacer : public WithDeclsToAdd, public WithGuards, public WithConstTypeSubstitution {
     60                struct TupleTypeReplacer : public WithDeclsToAdd, public WithGuards, public WithTypeSubstitution {
    6661                        Type * postmutate( TupleType * tupleType );
    6762
     
    304299                // produce the TupleType which aggregates the types of the exprs
    305300                std::list< Type * > types;
    306                 Type::Qualifiers qualifiers( Type::Const | Type::Volatile | Type::Restrict | Type::Atomic | Type::Mutex );
     301                Type::Qualifiers qualifiers( Type::Const | Type::Volatile | Type::Restrict | Type::Lvalue | Type::Atomic | Type::Mutex );
    307302                for ( Expression * expr : exprs ) {
    308303                        assert( expr->get_result() );
     
    319314                return new TupleType( qualifiers, types );
    320315        }
    321         const ast::Type * makeTupleType( const std::vector<ast::ptr<ast::Expr>> & exprs ) {
    322                 // produce the TupleType which aggregates the types of the exprs
    323                 std::vector<ast::ptr<ast::Type>> types;
    324                 ast::CV::Qualifiers quals{
    325                         ast::CV::Const | ast::CV::Volatile | ast::CV::Restrict | ast::CV::Lvalue |
    326                         ast::CV::Atomic | ast::CV::Mutex };
    327 
    328                 for ( const ast::Expr * expr : exprs ) {
    329                         assert( expr->result );
    330                         // if the type of any expr is void, the type of the entire tuple is void
    331                         if ( expr->result->isVoid() ) return new ast::VoidType{};
    332 
    333                         // qualifiers on the tuple type are the qualifiers that exist on all components
    334                         quals &= expr->result->qualifiers;
    335 
    336                         types.emplace_back( expr->result );
    337                 }
    338 
    339                 if ( exprs.empty() ) { quals = ast::CV::Qualifiers{}; }
    340                 return new ast::TupleType{ std::move(types), quals };
    341         }
    342316
    343317        TypeInstType * isTtype( Type * type ) {
     
    350324        }
    351325
    352         const TypeInstType * isTtype( const Type * type ) {
    353                 if ( const TypeInstType * inst = dynamic_cast< const TypeInstType * >( type ) ) {
    354                         if ( inst->baseType && inst->baseType->kind == TypeDecl::Ttype ) {
    355                                 return inst;
    356                         }
    357                 }
    358                 return nullptr;
    359         }
    360 
    361         const ast::TypeInstType * isTtype( const ast::Type * type ) {
    362                 if ( const ast::TypeInstType * inst = dynamic_cast< const ast::TypeInstType * >( type ) ) {
    363                         if ( inst->base && inst->base->kind == ast::TypeVar::Ttype ) {
    364                                 return inst;
    365                         }
    366                 }
    367                 return nullptr;
    368         }
    369 
    370326        namespace {
    371327                /// determines if impurity (read: side-effects) may exist in a piece of code. Currently gives a very crude approximation, wherein any function call expression means the code may be impure
     
    373329                        ImpurityDetector( bool ignoreUnique ) : ignoreUnique( ignoreUnique ) {}
    374330
    375                         void previsit( const ApplicationExpr * appExpr ) {
     331                        void previsit( ApplicationExpr * appExpr ) {
    376332                                visit_children = false;
    377                                 if ( const DeclarationWithType * function = InitTweak::getFunction( appExpr ) ) {
    378                                         if ( function->linkage == LinkageSpec::Intrinsic ) {
    379                                                 if ( function->name == "*?" || function->name == "?[?]" ) {
     333                                if ( DeclarationWithType * function = InitTweak::getFunction( appExpr ) ) {
     334                                        if ( function->get_linkage() == LinkageSpec::Intrinsic ) {
     335                                                if ( function->get_name() == "*?" || function->get_name() == "?[?]" ) {
    380336                                                        // intrinsic dereference, subscript are pure, but need to recursively look for impurity
    381337                                                        visit_children = true;
     
    386342                                maybeImpure = true;
    387343                        }
    388                         void previsit( const UntypedExpr * ) { maybeImpure = true; visit_children = false; }
    389                         void previsit( const UniqueExpr * ) {
     344                        void previsit( UntypedExpr * ) { maybeImpure = true; visit_children = false; }
     345                        void previsit( UniqueExpr * ) {
    390346                                if ( ignoreUnique ) {
    391347                                        // bottom out at unique expression.
     
    402358        } // namespace
    403359
    404         bool maybeImpure( const Expression * expr ) {
     360        bool maybeImpure( Expression * expr ) {
    405361                PassVisitor<ImpurityDetector> detector( false );
    406362                expr->accept( detector );
     
    408364        }
    409365
    410         bool maybeImpureIgnoreUnique( const Expression * expr ) {
     366        bool maybeImpureIgnoreUnique( Expression * expr ) {
    411367                PassVisitor<ImpurityDetector> detector( true );
    412368                expr->accept( detector );
Note: See TracChangeset for help on using the changeset viewer.