Changeset 1cbca6e
- Timestamp:
- Oct 7, 2015, 12:38:48 PM (9 years ago)
- 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
- Location:
- src
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
src/ResolvExpr/Unify.cc
r02e5ab6 r1cbca6e 9 9 // Author : Richard C. Bilson 10 10 // Created On : Sun May 17 12:27:10 2015 11 // Last Modified By : Peter A. Buhr12 // Last Modified On : Fri Jun 26 14:57:05201513 // Update Count : 711 // Last Modified By : Rob Schluntz 12 // Last Modified On : Wed Sep 02 14:43:22 2015 13 // Update Count : 36 14 14 // 15 15 … … 28 28 29 29 30 // #define DEBUG30 // #define DEBUG 31 31 32 32 namespace ResolvExpr { … … 80 80 bool typesCompatible( Type *first, Type *second, const SymTab::Indexer &indexer, const TypeEnvironment &env ) { 81 81 TypeEnvironment newEnv; 82 OpenVarSet openVars ;82 OpenVarSet openVars, closedVars; // added closedVars 83 83 AssertionSet needAssertions, haveAssertions; 84 84 Type *newFirst = first->clone(), *newSecond = second->clone(); 85 85 env.apply( newFirst ); 86 86 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 87 93 bool result = unifyExact( newFirst, newSecond, newEnv, needAssertions, haveAssertions, openVars, WidenMode( false, false ), indexer ); 88 94 delete newFirst; … … 425 431 426 432 void Unify::visit(ArrayType *arrayType) { 427 // XXX -- compare array dimension428 433 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 430 460 result = unifyExact( arrayType->get_base(), otherArray->get_base(), env, needAssertions, haveAssertions, openVars, WidenMode( false, false ), indexer ); 431 461 } // if … … 435 465 bool unifyDeclList( Iterator1 list1Begin, Iterator1 list1End, Iterator2 list2Begin, Iterator2 list2End, TypeEnvironment &env, AssertionSet &needAssertions, AssertionSet &haveAssertions, const OpenVarSet &openVars, const SymTab::Indexer &indexer ) { 436 466 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 ) ) { 437 469 if ( ! unifyExact( (*list1Begin)->get_type(), (*list2Begin)->get_type(), env, needAssertions, haveAssertions, openVars, WidenMode( false, false ), indexer ) ) { 438 470 return false; … … 449 481 FunctionType *otherFunction = dynamic_cast< FunctionType* >( type2 ); 450 482 if ( otherFunction && functionType->get_isVarArgs() == otherFunction->get_isVarArgs() ) { 451 483 452 484 if ( unifyDeclList( functionType->get_parameters().begin(), functionType->get_parameters().end(), otherFunction->get_parameters().begin(), otherFunction->get_parameters().end(), env, needAssertions, haveAssertions, openVars, indexer ) ) { 453 485 -
src/SymTab/Validate.cc
r02e5ab6 r1cbca6e 54 54 #include "MakeLibCfa.h" 55 55 #include "TypeEquality.h" 56 #include "ResolvExpr/typeops.h" 56 57 57 58 #define debugPrint( x ) if ( doDebug ) { std::cout << x; } … … 851 852 Type * t1 = tyDecl->get_base(); 852 853 Type * t2 = typedefNames[ tyDecl->get_name() ].first->get_base(); 853 if ( ! typeEquals( t1, t2, true) ) {854 if ( ! ResolvExpr::typesCompatible( t1, t2, Indexer() ) ) { 854 855 throw SemanticError( "cannot redefine typedef: " + tyDecl->get_name() ); 855 856 } -
src/SynTree/ObjectDecl.cc
r02e5ab6 r1cbca6e 9 9 // Author : Richard C. Bilson 10 10 // Created On : Mon May 18 07:44:20 2015 11 // Last Modified By : Peter A. Buhr12 // Last Modified On : Mon Jul 13 18:08:27201513 // Update Count : 1 611 // Last Modified By : Rob Schluntz 12 // Last Modified On : Tue Sep 29 14:13:01 2015 13 // Update Count : 18 14 14 // 15 15 … … 52 52 get_type()->print( os, indent ); 53 53 } else { 54 os << " untyped entity ";54 os << " untyped entity "; 55 55 } // if 56 56 57 57 if ( init ) { 58 os << " with initializer ";58 os << " with initializer "; 59 59 init->print( os, indent ); 60 60 } // if 61 61 62 62 if ( bitfieldWidth ) { 63 os << " with bitfield width ";63 os << " with bitfield width "; 64 64 bitfieldWidth->print( os ); 65 65 } // if
Note: See TracChangeset
for help on using the changeset viewer.