- Timestamp:
- Oct 2, 2017, 5:43:58 PM (7 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:
- 9d79f93
- Parents:
- effdde0
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/ResolvExpr/AdjustExprType.cc
reffdde0 r93fe7141 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
Note: See TracChangeset
for help on using the changeset viewer.