Changeset 1cbca6e


Ignore:
Timestamp:
Oct 7, 2015, 12:38:48 PM (9 years ago)
Author:
Rob Schluntz <rschlunt@…>
Branches:
ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, ctor, deferred_resn, demangler, enum, forall-pointer-decay, gc_noraii, jacob/cs343-translation, jenkins-sandbox, master, memory, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, string, with_gc
Children:
1521de20
Parents:
02e5ab6
Message:

check length, etc. in unification of arrays, switch typedef equality for typesCompatible

Location:
src
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • src/ResolvExpr/Unify.cc

    r02e5ab6 r1cbca6e  
    99// Author           : Richard C. Bilson
    1010// Created On       : Sun May 17 12:27:10 2015
    11 // Last Modified By : Peter A. Buhr
    12 // Last Modified On : Fri Jun 26 14:57:05 2015
    13 // Update Count     : 7
     11// Last Modified By : Rob Schluntz
     12// Last Modified On : Wed Sep 02 14:43:22 2015
     13// Update Count     : 36
    1414//
    1515
     
    2828
    2929
    30 //#define DEBUG
     30// #define DEBUG
    3131
    3232namespace ResolvExpr {
     
    8080        bool typesCompatible( Type *first, Type *second, const SymTab::Indexer &indexer, const TypeEnvironment &env ) {
    8181                TypeEnvironment newEnv;
    82                 OpenVarSet openVars;
     82                OpenVarSet openVars, closedVars; // added closedVars
    8383                AssertionSet needAssertions, haveAssertions;
    8484                Type *newFirst = first->clone(), *newSecond = second->clone();
    8585                env.apply( newFirst );
    8686                env.apply( newSecond );
     87
     88                // do we need to do this? Seems like we do, types should be able to be compatible if they
     89                // have free variables that can unify
     90                findOpenVars( newFirst, openVars, closedVars, needAssertions, haveAssertions, false );
     91                findOpenVars( newSecond, openVars, closedVars, needAssertions, haveAssertions, true );
     92
    8793                bool result = unifyExact( newFirst, newSecond, newEnv, needAssertions, haveAssertions, openVars, WidenMode( false, false ), indexer );
    8894                delete newFirst;
     
    425431
    426432        void Unify::visit(ArrayType *arrayType) {
    427                 // XXX -- compare array dimension
    428433                ArrayType *otherArray = dynamic_cast< ArrayType* >( type2 );
    429                 if ( otherArray && arrayType->get_isVarLen() == otherArray->get_isVarLen() ) {
     434                // to unify, array types must both be VLA or both not VLA
     435                // and must both have a dimension expression or not have a dimension
     436                if ( otherArray && arrayType->get_isVarLen() == otherArray->get_isVarLen()
     437                                && ((arrayType->get_dimension() != 0 && otherArray->get_dimension() != 0)
     438                                        || (arrayType->get_dimension() == 0 && otherArray->get_dimension() == 0))) {
     439
     440                        // not positive this is correct in all cases, but it's needed for typedefs
     441                        if ( arrayType->get_isVarLen() || otherArray->get_isVarLen() ) {
     442                                return;
     443                        }
     444
     445                        if ( ! arrayType->get_isVarLen() && ! otherArray->get_isVarLen() &&
     446                                arrayType->get_dimension() != 0 && otherArray->get_dimension() != 0 ) {
     447                                ConstantExpr * ce1 = dynamic_cast< ConstantExpr * >( arrayType->get_dimension() );
     448                                ConstantExpr * ce2 = dynamic_cast< ConstantExpr * >( otherArray->get_dimension() );
     449                                assert(ce1 && ce2);
     450
     451                                Constant * c1 = ce1->get_constant();
     452                                Constant * c2 = ce2->get_constant();
     453
     454                                if ( c1->get_value() != c2->get_value() ) {
     455                                        // does not unify if the dimension is different
     456                                        return;
     457                                }
     458                        }
     459
    430460                        result = unifyExact( arrayType->get_base(), otherArray->get_base(), env, needAssertions, haveAssertions, openVars, WidenMode( false, false ), indexer );
    431461                } // if
     
    435465        bool unifyDeclList( Iterator1 list1Begin, Iterator1 list1End, Iterator2 list2Begin, Iterator2 list2End, TypeEnvironment &env, AssertionSet &needAssertions, AssertionSet &haveAssertions, const OpenVarSet &openVars, const SymTab::Indexer &indexer ) {
    436466                for ( ; list1Begin != list1End && list2Begin != list2End; ++list1Begin, ++list2Begin ) {
     467                        // Type * commonType;
     468                        // if ( ! unifyInexact( (*list1Begin)->get_type(), (*list2Begin)->get_type(), env, needAssertions, haveAssertions, openVars, WidenMode( true, true ), indexer, commonType ) ) {
    437469                        if ( ! unifyExact( (*list1Begin)->get_type(), (*list2Begin)->get_type(), env, needAssertions, haveAssertions, openVars, WidenMode( false, false ), indexer ) ) {
    438470                                return false;
     
    449481                FunctionType *otherFunction = dynamic_cast< FunctionType* >( type2 );
    450482                if ( otherFunction && functionType->get_isVarArgs() == otherFunction->get_isVarArgs() ) {
    451  
     483
    452484                        if ( unifyDeclList( functionType->get_parameters().begin(), functionType->get_parameters().end(), otherFunction->get_parameters().begin(), otherFunction->get_parameters().end(), env, needAssertions, haveAssertions, openVars, indexer ) ) {
    453485       
  • src/SymTab/Validate.cc

    r02e5ab6 r1cbca6e  
    5454#include "MakeLibCfa.h"
    5555#include "TypeEquality.h"
     56#include "ResolvExpr/typeops.h"
    5657
    5758#define debugPrint( x ) if ( doDebug ) { std::cout << x; }
     
    851852                        Type * t1 = tyDecl->get_base();
    852853                        Type * t2 = typedefNames[ tyDecl->get_name() ].first->get_base();
    853                         if ( ! typeEquals( t1, t2, true ) ) {
     854                        if ( ! ResolvExpr::typesCompatible( t1, t2, Indexer() ) ) {
    854855                                throw SemanticError( "cannot redefine typedef: " + tyDecl->get_name() );
    855856                        }
  • src/SynTree/ObjectDecl.cc

    r02e5ab6 r1cbca6e  
    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 : Mon Jul 13 18:08:27 2015
    13 // Update Count     : 16
     11// Last Modified By : Rob Schluntz
     12// Last Modified On : Tue Sep 29 14:13:01 2015
     13// Update Count     : 18
    1414//
    1515
     
    5252                get_type()->print( os, indent );
    5353        } else {
    54                 os << "untyped entity ";
     54                os << " untyped entity ";
    5555        } // if
    5656
    5757        if ( init ) {
    58                 os << "with initializer ";
     58                os << " with initializer ";
    5959                init->print( os, indent );
    6060        } // if
    6161
    6262        if ( bitfieldWidth ) {
    63                 os << "with bitfield width ";
     63                os << " with bitfield width ";
    6464                bitfieldWidth->print( os );
    6565        } // if
Note: See TracChangeset for help on using the changeset viewer.