Changeset 1cdfa82 for src/ResolvExpr


Ignore:
Timestamp:
Apr 25, 2018, 4:55:53 PM (6 years ago)
Author:
Aaron Moss <a3moss@…>
Branches:
new-env, with_gc
Children:
42107b4
Parents:
2efe4b8 (diff), 9d5fb67 (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 remote-tracking branch 'origin/master' into with_gc

Location:
src/ResolvExpr
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • src/ResolvExpr/AlternativeFinder.cc

    r2efe4b8 r1cdfa82  
    12381238        }
    12391239
    1240         Expression * restructureCast( Expression * argExpr, Type * toType ) {
     1240        Expression * restructureCast( Expression * argExpr, Type * toType, bool isGenerated ) {
    12411241                if ( argExpr->get_result()->size() > 1 && ! toType->isVoid() && ! dynamic_cast<ReferenceType *>( toType ) ) {
    12421242                        // Argument expression is a tuple and the target type is not void and not a reference type.
     
    12531253                                // cast each component
    12541254                                TupleIndexExpr * idx = new TupleIndexExpr( argExpr->clone(), i );
    1255                                 componentExprs.push_back( restructureCast( idx, toType->getComponent( i ) ) );
     1255                                componentExprs.push_back( restructureCast( idx, toType->getComponent( i ), isGenerated ) );
    12561256                        }
    12571257                        assert( componentExprs.size() > 0 );
     
    12601260                } else {
    12611261                        // handle normally
    1262                         return new CastExpr( argExpr, toType->clone() );
     1262                        CastExpr * ret = new CastExpr( argExpr, toType->clone() );
     1263                        ret->isGenerated = isGenerated;
     1264                        return ret;
    12631265                }
    12641266        }
     
    13041306                                // count one safe conversion for each value that is thrown away
    13051307                                thisCost.incSafe( discardedValues );
    1306                                 Alternative newAlt( restructureCast( alt.expr->clone(), toType ), alt.env,
     1308                                Alternative newAlt( restructureCast( alt.expr->clone(), toType, castExpr->isGenerated ), alt.env,
    13071309                                        alt.cost, thisCost );
    13081310                                inferParameters( needAssertions, haveAssertions, newAlt, openVars,
     
    17271729                                        // count one safe conversion for each value that is thrown away
    17281730                                        thisCost.incSafe( discardedValues );
    1729                                         Alternative newAlt( new InitExpr( restructureCast( alt.expr->clone(), toType ), initAlt.designation->clone() ), newEnv, alt.cost, thisCost );
     1731                                        Alternative newAlt( new InitExpr( restructureCast( alt.expr->clone(), toType, true ), initAlt.designation->clone() ), newEnv, alt.cost, thisCost );
    17301732                                        inferParameters( needAssertions, haveAssertions, newAlt, openVars, back_inserter( candidates ) );
    17311733                                }
  • src/ResolvExpr/CommonType.cc

    r2efe4b8 r1cdfa82  
    2828
    2929// #define DEBUG
     30#ifdef DEBUG
     31#define PRINT(x) x
     32#else
     33#define PRINT(x)
     34#endif
    3035
    3136namespace ResolvExpr {
     
    7075                // need unify to bind type variables
    7176                if ( unify( t1, t2, env, have, need, newOpen, indexer, common ) ) {
    72                         // std::cerr << "unify success: " << widenFirst << " " << widenSecond << std::endl;
     77                        PRINT(
     78                                std::cerr << "unify success: " << widenFirst << " " << widenSecond << std::endl;
     79                        )
    7380                        if ( (widenFirst || t2->get_qualifiers() <= t1->get_qualifiers()) && (widenSecond || t1->get_qualifiers() <= t2->get_qualifiers()) ) {
    74                                 // std::cerr << "widen okay" << std::endl;
     81                                PRINT(
     82                                        std::cerr << "widen okay" << std::endl;
     83                                )
    7584                                common->get_qualifiers() |= t1->get_qualifiers();
    7685                                common->get_qualifiers() |= t2->get_qualifiers();
     
    7887                        }
    7988                }
    80                 // std::cerr << "exact unify failed: " << t1 << " " << t2 << std::endl;
     89                PRINT(
     90                        std::cerr << "exact unify failed: " << t1 << " " << t2 << std::endl;
     91                )
    8192                return nullptr;
    8293        }
     
    90101                        int diff = depth1-depth2;
    91102                        // TODO: should it be possible for commonType to generate complicated conversions? I would argue no, only conversions that involve types of the same reference level or a difference of 1 should be allowed.
    92                         if ( diff > 1 || diff < -1 ) return nullptr;
     103                        // if ( diff > 1 || diff < -1 ) return nullptr;
    93104
    94105                        // special case where one type has a reference depth of 1 larger than the other
    95106                        if ( diff > 0 || diff < 0 ) {
    96                                 // std::cerr << "reference depth diff: " << diff << std::endl;
     107                                PRINT(
     108                                        std::cerr << "reference depth diff: " << diff << std::endl;
     109                                )
    97110                                Type * result = nullptr;
    98111                                ReferenceType * ref1 = dynamic_cast< ReferenceType * >( type1 );
     
    109122                                if ( result && ref1 ) {
    110123                                        // formal is reference, so result should be reference
    111                                         // std::cerr << "formal is reference; result should be reference" << std::endl;
     124                                        PRINT(
     125                                                std::cerr << "formal is reference; result should be reference" << std::endl;
     126                                        )
    112127                                        result = new ReferenceType( ref1->get_qualifiers(), result );
    113128                                }
    114                                 // std::cerr << "common type of reference [" << type1 << "] and [" << type2 << "] is [" << result << "]" << std::endl;
     129                                PRINT(
     130                                        std::cerr << "common type of reference [" << type1 << "] and [" << type2 << "] is [" << result << "]" << std::endl;
     131                                )
    115132                                return result;
    116133                        }
  • src/ResolvExpr/ConversionCost.cc

    r2efe4b8 r1cdfa82  
    276276                        // xxx - not positive this is correct, but appears to allow casting int => enum
    277277                        cost = Cost::unsafe;
    278                 } else if ( dynamic_cast< ZeroType* >( dest ) != nullptr || dynamic_cast< OneType* >( dest ) != nullptr ) {
    279                         cost = Cost::unsafe;
    280                 } // if
     278                } // if
     279                // no cases for zero_t/one_t because it should not be possible to convert int, etc. to zero_t/one_t.
    281280        }
    282281
     
    310309                                // assignResult == 0 means Cost::Infinity
    311310                        } // if
    312                 } else if ( dynamic_cast< ZeroType * >( dest ) ) {
    313                         cost = Cost::unsafe;
     311                        // case case for zero_t because it should not be possible to convert pointers to zero_t.
    314312                } // if
    315313        }
  • src/ResolvExpr/Resolver.cc

    r2efe4b8 r1cdfa82  
    6060                void previsit( TypeDecl *typeDecl );
    6161                void previsit( EnumDecl * enumDecl );
     62                void previsit( StaticAssertDecl * assertDecl );
    6263
    6364                void previsit( ArrayType * at );
     
    365366        }
    366367
     368        void Resolver::previsit( StaticAssertDecl * assertDecl ) {
     369                findIntegralExpression( assertDecl->condition, indexer );
     370        }
     371
    367372        void Resolver::previsit( ExprStmt *exprStmt ) {
    368373                visit_children = false;
Note: See TracChangeset for help on using the changeset viewer.