Changeset b7778c1 for src/ResolvExpr
- Timestamp:
- Oct 4, 2017, 3:31:43 PM (8 years ago)
- Branches:
- ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
- Children:
- 3364962
- Parents:
- 3628765 (diff), bb9d8e8 (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. - Location:
- src/ResolvExpr
- Files:
-
- 8 edited
-
AdjustExprType.cc (modified) (5 diffs)
-
Alternative.cc (modified) (1 diff)
-
Alternative.h (modified) (1 diff)
-
AlternativeFinder.cc (modified) (5 diffs)
-
ResolveTypeof.cc (modified) (3 diffs)
-
TypeEnvironment.cc (modified) (2 diffs)
-
TypeEnvironment.h (modified) (2 diffs)
-
Unify.cc (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/ResolvExpr/AdjustExprType.cc
r3628765 rb7778c1 14 14 // 15 15 16 #include "Common/PassVisitor.h" 16 17 #include "SymTab/Indexer.h" // for Indexer 17 18 #include "SynTree/Declaration.h" // for TypeDecl, TypeDecl::Kind::Ftype … … 21 22 22 23 namespace ResolvExpr { 23 class AdjustExprType : public Mutator { 24 typedef Mutator Parent; 25 using Parent::mutate; 24 class AdjustExprType : public WithShortCircuiting { 26 25 public: 27 26 AdjustExprType( const TypeEnvironment &env, const SymTab::Indexer &indexer ); 27 void premutate( VoidType * ) { visit_children = false; } 28 void premutate( BasicType * ) { visit_children = false; } 29 void premutate( PointerType * ) { visit_children = false; } 30 void premutate( FunctionType * ) { visit_children = false; } 31 void premutate( StructInstType * ) { visit_children = false; } 32 void premutate( UnionInstType * ) { visit_children = false; } 33 void premutate( EnumInstType * ) { visit_children = false; } 34 void premutate( TraitInstType * ) { visit_children = false; } 35 void premutate( TypeInstType * ) { visit_children = false; } 36 void premutate( TupleType * ) { visit_children = false; } 37 void premutate( VarArgsType * ) { visit_children = false; } 38 void premutate( ZeroType * ) { visit_children = false; } 39 void premutate( OneType * ) { visit_children = false; } 40 41 Type * postmutate( ArrayType *arrayType ); 42 Type * postmutate( FunctionType *functionType ); 43 Type * postmutate( TypeInstType *aggregateUseType ); 44 28 45 private: 29 virtual Type* mutate( VoidType *voidType );30 virtual Type* mutate( BasicType *basicType );31 virtual Type* mutate( PointerType *pointerType );32 virtual Type* mutate( ArrayType *arrayType );33 virtual Type* mutate( FunctionType *functionType );34 virtual Type* mutate( StructInstType *aggregateUseType );35 virtual Type* mutate( UnionInstType *aggregateUseType );36 virtual Type* mutate( EnumInstType *aggregateUseType );37 virtual Type* mutate( TraitInstType *aggregateUseType );38 virtual Type* mutate( TypeInstType *aggregateUseType );39 virtual Type* mutate( TupleType *tupleType );40 virtual Type* mutate( VarArgsType *varArgsType );41 virtual Type* mutate( ZeroType *zeroType );42 virtual Type* mutate( OneType *oneType );43 44 46 const TypeEnvironment &env; 45 47 const SymTab::Indexer &indexer; … … 47 49 48 50 void adjustExprType( Type *&type, const TypeEnvironment &env, const SymTab::Indexer &indexer ) { 49 AdjustExprTypeadjuster( env, indexer );51 PassVisitor<AdjustExprType> adjuster( env, indexer ); 50 52 Type *newType = type->acceptMutator( adjuster ); 51 53 type = newType; … … 56 58 } 57 59 58 Type *AdjustExprType::mutate( VoidType *voidType ) { 59 return voidType; 60 } 61 62 Type *AdjustExprType::mutate( BasicType *basicType ) { 63 return basicType; 64 } 65 66 Type *AdjustExprType::mutate( PointerType *pointerType ) { 67 return pointerType; 68 } 69 70 Type *AdjustExprType::mutate( ArrayType *arrayType ) { 60 Type * AdjustExprType::postmutate( ArrayType * arrayType ) { 71 61 // need to recursively mutate the base type in order for multi-dimensional arrays to work. 72 PointerType *pointerType = new PointerType( arrayType->get_qualifiers(), arrayType->get_base()->clone()->acceptMutator( *this ) ); 62 PointerType *pointerType = new PointerType( arrayType->get_qualifiers(), arrayType->base ); 63 arrayType->base = nullptr; 73 64 delete arrayType; 74 65 return pointerType; 75 66 } 76 67 77 Type *AdjustExprType::mutate( FunctionType *functionType ) { 78 PointerType *pointerType = new PointerType( Type::Qualifiers(), functionType ); 79 return pointerType; 68 Type * AdjustExprType::postmutate( FunctionType * functionType ) { 69 return new PointerType( Type::Qualifiers(), functionType ); 80 70 } 81 71 82 Type *AdjustExprType::mutate( StructInstType *aggregateUseType ) { 83 return aggregateUseType; 84 } 85 86 Type *AdjustExprType::mutate( UnionInstType *aggregateUseType ) { 87 return aggregateUseType; 88 } 89 90 Type *AdjustExprType::mutate( EnumInstType *aggregateUseType ) { 91 return aggregateUseType; 92 } 93 94 Type *AdjustExprType::mutate( TraitInstType *aggregateUseType ) { 95 return aggregateUseType; 96 } 97 98 Type *AdjustExprType::mutate( TypeInstType *typeInst ) { 72 Type * AdjustExprType::postmutate( TypeInstType * typeInst ) { 99 73 EqvClass eqvClass; 100 74 if ( env.lookup( typeInst->get_name(), eqvClass ) ) { … … 113 87 return typeInst; 114 88 } 115 116 Type *AdjustExprType::mutate( TupleType *tupleType ) {117 return tupleType;118 }119 120 Type *AdjustExprType::mutate( VarArgsType *varArgsType ) {121 return varArgsType;122 }123 124 Type *AdjustExprType::mutate( ZeroType *zeroType ) {125 return zeroType;126 }127 128 Type *AdjustExprType::mutate( OneType *oneType ) {129 return oneType;130 }131 89 } // namespace ResolvExpr 132 90 -
src/ResolvExpr/Alternative.cc
r3628765 rb7778c1 66 66 } 67 67 68 void Alternative::print( std::ostream &os, intindent ) const {69 os << std::string( indent, ' ' ) <<"Cost " << cost << ": ";68 void Alternative::print( std::ostream &os, Indenter indent ) const { 69 os << "Cost " << cost << ": "; 70 70 if ( expr ) { 71 expr->print( os, indent );72 os << "(types:" << std::endl;73 os << std::string( indent+4, ' ' );74 expr-> get_result()->print( os, indent + 4);75 os << std::endl << ")" << std::endl;71 expr->print( os, indent+1 ); 72 os << std::endl << indent << "(types:" << std::endl; 73 os << indent+1; 74 expr->result->print( os, indent+1 ); 75 os << std::endl << indent << ")" << std::endl; 76 76 } else { 77 77 os << "Null expression!" << std::endl; 78 78 } // if 79 os << std::string( indent, ' ' )<< "Environment: ";80 env.print( os, indent+ 2);79 os << indent << "Environment: "; 80 env.print( os, indent+1 ); 81 81 os << std::endl; 82 82 } -
src/ResolvExpr/Alternative.h
r3628765 rb7778c1 39 39 ~Alternative(); 40 40 41 void print( std::ostream &os, int indent = 0) const;41 void print( std::ostream &os, Indenter indent = {} ) const; 42 42 43 43 Cost cost; -
src/ResolvExpr/AlternativeFinder.cc
r3628765 rb7778c1 75 75 76 76 namespace { 77 void printAlts( const AltList &list, std::ostream &os, int indent = 0 ) { 77 void printAlts( const AltList &list, std::ostream &os, unsigned int indentAmt = 0 ) { 78 Indenter indent = { Indenter::tabsize, indentAmt }; 78 79 for ( AltList::const_iterator i = list.begin(); i != list.end(); ++i ) { 79 80 i->print( os, indent ); … … 195 196 AltList winners; 196 197 findMinCost( alternatives.begin(), alternatives.end(), back_inserter( winners ) ); 197 stream << "Cannot choose between " << winners.size() << " alternatives for expression ";198 stream << "Cannot choose between " << winners.size() << " alternatives for expression\n"; 198 199 expr->print( stream ); 199 stream << "Alternatives are: ";200 printAlts( winners, stream, 8);200 stream << "Alternatives are:\n"; 201 printAlts( winners, stream, 1 ); 201 202 throw SemanticError( stream.str() ); 202 203 } … … 728 729 PRINT( 729 730 std::cerr << "known function ops:" << std::endl; 730 printAlts( funcOpFinder.alternatives, std::cerr, 8);731 printAlts( funcOpFinder.alternatives, std::cerr, 1 ); 731 732 ) 732 733 … … 838 839 bool isLvalue( Expression *expr ) { 839 840 // xxx - recurse into tuples? 840 return expr-> has_result()&& ( expr->get_result()->get_lvalue() || dynamic_cast< ReferenceType * >( expr->get_result() ) );841 return expr->result && ( expr->get_result()->get_lvalue() || dynamic_cast< ReferenceType * >( expr->get_result() ) ); 841 842 } 842 843 … … 972 973 PRINT( std::cerr << "nameExpr is " << nameExpr->get_name() << std::endl; ) 973 974 for ( std::list< DeclarationWithType* >::iterator i = declList.begin(); i != declList.end(); ++i ) { 974 VariableExpr newExpr( *i , nameExpr->get_argName());975 VariableExpr newExpr( *i ); 975 976 alternatives.push_back( Alternative( newExpr.clone(), env, Cost::zero ) ); 976 977 PRINT( -
src/ResolvExpr/ResolveTypeof.cc
r3628765 rb7778c1 18 18 #include <cassert> // for assert 19 19 20 #include "Common/PassVisitor.h" // for PassVisitor 20 21 #include "Resolver.h" // for resolveInVoidContext 21 22 #include "SynTree/Expression.h" // for Expression … … 41 42 } 42 43 43 class ResolveTypeof : public Mutator{44 class ResolveTypeof : public WithShortCircuiting { 44 45 public: 45 46 ResolveTypeof( const SymTab::Indexer &indexer ) : indexer( indexer ) {} 46 Type *mutate( TypeofType *typeofType ); 47 void premutate( TypeofType *typeofType ); 48 Type * postmutate( TypeofType *typeofType ); 47 49 48 50 private: … … 50 52 }; 51 53 52 Type * resolveTypeof( Type *type, const SymTab::Indexer &indexer ) {53 ResolveTypeofmutator( indexer );54 Type * resolveTypeof( Type *type, const SymTab::Indexer &indexer ) { 55 PassVisitor<ResolveTypeof> mutator( indexer ); 54 56 return type->acceptMutator( mutator ); 55 57 } 56 58 57 Type *ResolveTypeof::mutate( TypeofType *typeofType ) { 59 void ResolveTypeof::premutate( TypeofType * ) { 60 visit_children = false; 61 } 62 63 Type * ResolveTypeof::postmutate( TypeofType *typeofType ) { 58 64 #if 0 59 std::c out<< "resolving typeof: ";60 typeofType->print( std::c out);61 std::c out<< std::endl;65 std::cerr << "resolving typeof: "; 66 typeofType->print( std::cerr ); 67 std::cerr << std::endl; 62 68 #endif 63 if ( typeofType-> get_expr()) {64 Expression * newExpr = resolveInVoidContext( typeofType->get_expr(), indexer );65 assert( newExpr-> has_result() && ! newExpr->get_result()->isVoid() );66 Type * newType = newExpr->get_result();67 newExpr-> set_result( nullptr );69 if ( typeofType->expr ) { 70 Expression * newExpr = resolveInVoidContext( typeofType->expr, indexer ); 71 assert( newExpr->result && ! newExpr->result->isVoid() ); 72 Type * newType = newExpr->result; 73 newExpr->result = nullptr; 68 74 delete typeofType; 69 75 delete newExpr; -
src/ResolvExpr/TypeEnvironment.cc
r3628765 rb7778c1 68 68 } 69 69 70 void EqvClass::print( std::ostream &os, intindent ) const {71 os << std::string( indent, ' ' ) <<"( ";70 void EqvClass::print( std::ostream &os, Indenter indent ) const { 71 os << "( "; 72 72 std::copy( vars.begin(), vars.end(), std::ostream_iterator< std::string >( os, " " ) ); 73 73 os << ")"; 74 74 if ( type ) { 75 75 os << " -> "; 76 type->print( os, indent );76 type->print( os, indent+1 ); 77 77 } // if 78 78 if ( ! allowWidening ) { … … 144 144 } 145 145 146 void TypeEnvironment::print( std::ostream &os, intindent ) const {146 void TypeEnvironment::print( std::ostream &os, Indenter indent ) const { 147 147 for ( std::list< EqvClass >::const_iterator i = env.begin(); i != env.end(); ++i ) { 148 148 i->print( os, indent ); -
src/ResolvExpr/TypeEnvironment.h
r3628765 rb7778c1 68 68 EqvClass &operator=( const EqvClass &other ); 69 69 ~EqvClass(); 70 void print( std::ostream &os, int indent = 0) const;70 void print( std::ostream &os, Indenter indent = {} ) const; 71 71 }; 72 72 … … 80 80 void makeSubstitution( TypeSubstitution &result ) const; 81 81 bool isEmpty() const { return env.empty(); } 82 void print( std::ostream &os, int indent = 0) const;82 void print( std::ostream &os, Indenter indent = {} ) const; 83 83 void combine( const TypeEnvironment &second, Type *(*combineFunc)( Type*, Type* ) ); 84 84 void simpleCombine( const TypeEnvironment &second ); -
src/ResolvExpr/Unify.cc
r3628765 rb7778c1 22 22 #include <utility> // for pair 23 23 24 #include "Common/PassVisitor.h" // for PassVisitor 24 25 #include "FindOpenVars.h" // for findOpenVars 25 26 #include "Parser/LinkageSpec.h" // for C … … 537 538 /// If this isn't done then argument lists can have wildly different 538 539 /// size and structure, when they should be compatible. 539 struct TtypeExpander : public Mutator { 540 TypeEnvironment & env; 541 TtypeExpander( TypeEnvironment & env ) : env( env ) {} 542 Type * mutate( TypeInstType * typeInst ) { 540 struct TtypeExpander : public WithShortCircuiting { 541 TypeEnvironment & tenv; 542 TtypeExpander( TypeEnvironment & tenv ) : tenv( tenv ) {} 543 void premutate( TypeInstType * ) { visit_children = false; } 544 Type * postmutate( TypeInstType * typeInst ) { 543 545 EqvClass eqvClass; 544 if ( env.lookup( typeInst->get_name(), eqvClass ) ) {546 if ( tenv.lookup( typeInst->get_name(), eqvClass ) ) { 545 547 if ( eqvClass.data.kind == TypeDecl::Ttype ) { 546 548 // expand ttype parameter into its actual type … … 560 562 dst.clear(); 561 563 for ( DeclarationWithType * dcl : src ) { 562 TtypeExpanderexpander( env );564 PassVisitor<TtypeExpander> expander( env ); 563 565 dcl->acceptMutator( expander ); 564 566 std::list< Type * > types; … … 750 752 std::list<Type *> types1, types2; 751 753 752 TtypeExpanderexpander( env );754 PassVisitor<TtypeExpander> expander( env ); 753 755 flat1->acceptMutator( expander ); 754 756 flat2->acceptMutator( expander );
Note:
See TracChangeset
for help on using the changeset viewer.