Ignore:
Timestamp:
Oct 29, 2019, 4:01:24 PM (6 years ago)
Author:
Thierry Delisle <tdelisle@…>
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:
773db65, 9421f3d8
Parents:
7951100 (diff), 8364209 (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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Tuples/TupleExpansion.cc

    r7951100 rb067d9b  
    99// Author           : Rodolfo G. Esteves
    1010// Created On       : Mon May 18 07:44:20 2015
    11 // Last Modified By : Peter A. Buhr
    12 // Last Modified On : Wed Jun 21 17:35:04 2017
    13 // Update Count     : 19
     11// Last Modified By : Andrew Beach
     12// Last Modified On : Fri Jul 19 14:39:00 2019
     13// Update Count     : 22
    1414//
    1515
     
    1717#include <cassert>                // for assert
    1818#include <list>                   // for list
    19 
     19#include <vector>
     20
     21#include "AST/CVQualifiers.hpp"
     22#include "AST/Expr.hpp"
     23#include "AST/Node.hpp"
     24#include "AST/Type.hpp"
    2025#include "Common/PassVisitor.h"   // for PassVisitor, WithDeclsToAdd, WithGu...
    2126#include "Common/ScopedMap.h"     // for ScopedMap
     
    5863                };
    5964
    60                 struct TupleTypeReplacer : public WithDeclsToAdd, public WithGuards, public WithTypeSubstitution {
     65                struct TupleTypeReplacer : public WithDeclsToAdd, public WithGuards, public WithConstTypeSubstitution {
    6166                        Type * postmutate( TupleType * tupleType );
    6267
     
    299304                // produce the TupleType which aggregates the types of the exprs
    300305                std::list< Type * > types;
    301                 Type::Qualifiers qualifiers( Type::Const | Type::Volatile | Type::Restrict | Type::Lvalue | Type::Atomic | Type::Mutex );
     306                Type::Qualifiers qualifiers( Type::Const | Type::Volatile | Type::Restrict | Type::Atomic | Type::Mutex );
    302307                for ( Expression * expr : exprs ) {
    303308                        assert( expr->get_result() );
     
    314319                return new TupleType( qualifiers, types );
    315320        }
     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        }
    316342
    317343        TypeInstType * isTtype( Type * type ) {
     
    324350        }
    325351
     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
    326370        namespace {
    327371                /// 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
     
    329373                        ImpurityDetector( bool ignoreUnique ) : ignoreUnique( ignoreUnique ) {}
    330374
    331                         void previsit( ApplicationExpr * appExpr ) {
     375                        void previsit( const ApplicationExpr * appExpr ) {
    332376                                visit_children = false;
    333                                 if ( DeclarationWithType * function = InitTweak::getFunction( appExpr ) ) {
    334                                         if ( function->get_linkage() == LinkageSpec::Intrinsic ) {
    335                                                 if ( function->get_name() == "*?" || function->get_name() == "?[?]" ) {
     377                                if ( const DeclarationWithType * function = InitTweak::getFunction( appExpr ) ) {
     378                                        if ( function->linkage == LinkageSpec::Intrinsic ) {
     379                                                if ( function->name == "*?" || function->name == "?[?]" ) {
    336380                                                        // intrinsic dereference, subscript are pure, but need to recursively look for impurity
    337381                                                        visit_children = true;
     
    342386                                maybeImpure = true;
    343387                        }
    344                         void previsit( UntypedExpr * ) { maybeImpure = true; visit_children = false; }
    345                         void previsit( UniqueExpr * ) {
     388                        void previsit( const UntypedExpr * ) { maybeImpure = true; visit_children = false; }
     389                        void previsit( const UniqueExpr * ) {
    346390                                if ( ignoreUnique ) {
    347391                                        // bottom out at unique expression.
     
    358402        } // namespace
    359403
    360         bool maybeImpure( Expression * expr ) {
     404        bool maybeImpure( const Expression * expr ) {
    361405                PassVisitor<ImpurityDetector> detector( false );
    362406                expr->accept( detector );
     
    364408        }
    365409
    366         bool maybeImpureIgnoreUnique( Expression * expr ) {
     410        bool maybeImpureIgnoreUnique( const Expression * expr ) {
    367411                PassVisitor<ImpurityDetector> detector( true );
    368412                expr->accept( detector );
Note: See TracChangeset for help on using the changeset viewer.