Changeset 8d182b1 for src/ResolvExpr/AdjustExprType.cc
- Timestamp:
- Nov 14, 2023, 12:19:09 PM (23 months ago)
- Branches:
- master
- Children:
- 1ccae59, 89a8bab
- Parents:
- df8ba61a (diff), 5625427 (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. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/ResolvExpr/AdjustExprType.cc
rdf8ba61a r8d182b1 19 19 #include "AST/Type.hpp" 20 20 #include "AST/TypeEnvironment.hpp" 21 #include "Common/PassVisitor.h"22 #include "SymTab/Indexer.h" // for Indexer23 #include "SynTree/Declaration.h" // for TypeDecl, TypeDecl::Kind::Ftype24 #include "SynTree/Mutator.h" // for Mutator25 #include "SynTree/Type.h" // for PointerType, TypeInstType, Type26 #include "TypeEnvironment.h" // for EqvClass, TypeEnvironment27 21 28 22 namespace ResolvExpr { 29 23 30 24 namespace { 31 class AdjustExprType_old final : public WithShortCircuiting { 32 public: 33 AdjustExprType_old( const TypeEnvironment & env, const SymTab::Indexer & indexer ); 34 void premutate( VoidType * ) { visit_children = false; } 35 void premutate( BasicType * ) { visit_children = false; } 36 void premutate( PointerType * ) { visit_children = false; } 37 void premutate( ArrayType * ) { visit_children = false; } 38 void premutate( FunctionType * ) { visit_children = false; } 39 void premutate( StructInstType * ) { visit_children = false; } 40 void premutate( UnionInstType * ) { visit_children = false; } 41 void premutate( EnumInstType * ) { visit_children = false; } 42 void premutate( TraitInstType * ) { visit_children = false; } 43 void premutate( TypeInstType * ) { visit_children = false; } 44 void premutate( TupleType * ) { visit_children = false; } 45 void premutate( VarArgsType * ) { visit_children = false; } 46 void premutate( ZeroType * ) { visit_children = false; } 47 void premutate( OneType * ) { visit_children = false; } 48 49 Type * postmutate( ArrayType * arrayType ); 50 Type * postmutate( FunctionType * functionType ); 51 Type * postmutate( TypeInstType * aggregateUseType ); 52 53 private: 54 const TypeEnvironment & env; 55 const SymTab::Indexer & indexer; 56 }; 57 58 AdjustExprType_old::AdjustExprType_old( const TypeEnvironment &env, const SymTab::Indexer &indexer ) 59 : env( env ), indexer( indexer ) { 60 } 61 62 Type * AdjustExprType_old::postmutate( ArrayType * arrayType ) { 63 PointerType * pointerType = new PointerType{ arrayType->get_qualifiers(), arrayType->base }; 64 arrayType->base = nullptr; 65 delete arrayType; 66 return pointerType; 67 } 68 69 Type * AdjustExprType_old::postmutate( FunctionType * functionType ) { 70 return new PointerType{ Type::Qualifiers(), functionType }; 71 } 72 73 Type * AdjustExprType_old::postmutate( TypeInstType * typeInst ) { 74 if ( const EqvClass * eqvClass = env.lookup( typeInst->get_name() ) ) { 75 if ( eqvClass->data.kind == TypeDecl::Ftype ) { 76 return new PointerType{ Type::Qualifiers(), typeInst }; 77 } 78 } else if ( const NamedTypeDecl * ntDecl = indexer.lookupType( typeInst->get_name() ) ) { 79 if ( const TypeDecl * tyDecl = dynamic_cast< const TypeDecl * >( ntDecl ) ) { 80 if ( tyDecl->get_kind() == TypeDecl::Ftype ) { 81 return new PointerType{ Type::Qualifiers(), typeInst }; 82 } // if 83 } // if 84 } // if 85 return typeInst; 86 } 87 } // anonymous namespace 88 89 void adjustExprType( Type *&type, const TypeEnvironment &env, const SymTab::Indexer &indexer ) { 90 PassVisitor<AdjustExprType_old> adjuster( env, indexer ); 91 Type * newType = type->acceptMutator( adjuster ); 92 type = newType; 93 } 94 95 void adjustExprType( Type *& type ) { 96 TypeEnvironment env; 97 SymTab::Indexer indexer; 98 adjustExprType( type, env, indexer ); 99 } 100 101 namespace { 102 class AdjustExprType_new final : public ast::WithShortCircuiting { 25 class AdjustExprType final : public ast::WithShortCircuiting { 103 26 const ast::SymbolTable & symtab; 104 27 public: 105 28 const ast::TypeEnvironment & tenv; 106 29 107 AdjustExprType _new( const ast::TypeEnvironment & e, const ast::SymbolTable & syms )30 AdjustExprType( const ast::TypeEnvironment & e, const ast::SymbolTable & syms ) 108 31 : symtab( syms ), tenv( e ) {} 109 32 … … 152 75 const ast::Type * type, const ast::TypeEnvironment & env, const ast::SymbolTable & symtab 153 76 ) { 154 ast::Pass<AdjustExprType _new> adjuster{ env, symtab };77 ast::Pass<AdjustExprType> adjuster{ env, symtab }; 155 78 return type->accept( adjuster ); 156 79 }
Note:
See TracChangeset
for help on using the changeset viewer.