Changes in src/SymTab/FixFunction.cc [c1ed2ee:4bda2cf]
- File:
-
- 1 edited
-
src/SymTab/FixFunction.cc (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/SymTab/FixFunction.cc
rc1ed2ee r4bda2cf 18 18 #include <list> // for list 19 19 20 #include "AST/Decl.hpp" 21 #include "AST/Pass.hpp" 22 #include "AST/Type.hpp" 23 #include "Common/utility.h" // for maybeClone, copy 20 #include "Common/utility.h" // for maybeClone 24 21 #include "SynTree/Declaration.h" // for FunctionDecl, ObjectDecl, Declarati... 25 22 #include "SynTree/Expression.h" // for Expression … … 27 24 28 25 namespace SymTab { 29 class FixFunction_old : public WithShortCircuiting { 30 typedef Mutator Parent; 31 public: 32 FixFunction_old() : isVoid( false ) {} 26 FixFunction::FixFunction() : isVoid( false ) {} 33 27 34 void premutate(FunctionDecl *functionDecl);35 DeclarationWithType* postmutate(FunctionDecl *functionDecl);36 28 37 Type * postmutate(ArrayType * arrayType); 38 39 void premutate(ArrayType * arrayType); 40 void premutate(VoidType * voidType); 41 void premutate(BasicType * basicType); 42 void premutate(PointerType * pointerType); 43 void premutate(StructInstType * aggregateUseType); 44 void premutate(UnionInstType * aggregateUseType); 45 void premutate(EnumInstType * aggregateUseType); 46 void premutate(TraitInstType * aggregateUseType); 47 void premutate(TypeInstType * aggregateUseType); 48 void premutate(TupleType * tupleType); 49 void premutate(VarArgsType * varArgsType); 50 void premutate(ZeroType * zeroType); 51 void premutate(OneType * oneType); 52 53 bool isVoid; 54 }; 55 56 DeclarationWithType * FixFunction_old::postmutate(FunctionDecl *functionDecl) { 29 DeclarationWithType * FixFunction::postmutate(FunctionDecl *functionDecl) { 57 30 // can't delete function type because it may contain assertions, so transfer ownership to new object 58 31 ObjectDecl *pointer = new ObjectDecl( functionDecl->name, functionDecl->get_storageClasses(), functionDecl->linkage, nullptr, new PointerType( Type::Qualifiers(), functionDecl->type ), nullptr, functionDecl->attributes ); 59 pointer->location = functionDecl->location;60 32 functionDecl->attributes.clear(); 61 33 functionDecl->type = nullptr; … … 68 40 // does not cause an error 69 41 70 Type * FixFunction _old::postmutate(ArrayType *arrayType) {42 Type * FixFunction::postmutate(ArrayType *arrayType) { 71 43 // need to recursively mutate the base type in order for multi-dimensional arrays to work. 72 44 PointerType *pointerType = new PointerType( arrayType->get_qualifiers(), arrayType->base, arrayType->dimension, arrayType->isVarLen, arrayType->isStatic ); 73 pointerType->location = arrayType->location;74 45 arrayType->base = nullptr; 75 46 arrayType->dimension = nullptr; … … 78 49 } 79 50 80 void FixFunction _old::premutate(VoidType *) {51 void FixFunction::premutate(VoidType *) { 81 52 isVoid = true; 82 53 } 83 54 84 void FixFunction _old::premutate(FunctionDecl *) { visit_children = false; }85 void FixFunction _old::premutate(ArrayType *) { visit_children = false; }86 void FixFunction _old::premutate(BasicType *) { visit_children = false; }87 void FixFunction _old::premutate(PointerType *) { visit_children = false; }88 void FixFunction _old::premutate(StructInstType *) { visit_children = false; }89 void FixFunction _old::premutate(UnionInstType *) { visit_children = false; }90 void FixFunction _old::premutate(EnumInstType *) { visit_children = false; }91 void FixFunction _old::premutate(TraitInstType *) { visit_children = false; }92 void FixFunction _old::premutate(TypeInstType *) { visit_children = false; }93 void FixFunction _old::premutate(TupleType *) { visit_children = false; }94 void FixFunction _old::premutate(VarArgsType *) { visit_children = false; }95 void FixFunction _old::premutate(ZeroType *) { visit_children = false; }96 void FixFunction _old::premutate(OneType *) { visit_children = false; }55 void FixFunction::premutate(FunctionDecl *) { visit_children = false; } 56 void FixFunction::premutate(ArrayType *) { visit_children = false; } 57 void FixFunction::premutate(BasicType *) { visit_children = false; } 58 void FixFunction::premutate(PointerType *) { visit_children = false; } 59 void FixFunction::premutate(StructInstType *) { visit_children = false; } 60 void FixFunction::premutate(UnionInstType *) { visit_children = false; } 61 void FixFunction::premutate(EnumInstType *) { visit_children = false; } 62 void FixFunction::premutate(TraitInstType *) { visit_children = false; } 63 void FixFunction::premutate(TypeInstType *) { visit_children = false; } 64 void FixFunction::premutate(TupleType *) { visit_children = false; } 65 void FixFunction::premutate(VarArgsType *) { visit_children = false; } 66 void FixFunction::premutate(ZeroType *) { visit_children = false; } 67 void FixFunction::premutate(OneType *) { visit_children = false; } 97 68 98 69 bool fixFunction( DeclarationWithType *& dwt ) { 99 PassVisitor<FixFunction _old> fixer;70 PassVisitor<FixFunction> fixer; 100 71 dwt = dwt->acceptMutator( fixer ); 101 72 return fixer.pass.isVoid; 102 73 } 103 104 namespace {105 struct FixFunction_new final : public ast::WithShortCircuiting {106 bool isVoid = false;107 108 void premutate( const ast::FunctionDecl * ) { visit_children = false; }109 110 const ast::DeclWithType * postmutate( const ast::FunctionDecl * func ) {111 return new ast::ObjectDecl{112 func->location, func->name, new ast::PointerType{ func->type }, nullptr,113 func->storage, func->linkage, nullptr, copy( func->attributes ) };114 }115 116 void premutate( const ast::ArrayType * ) { visit_children = false; }117 118 const ast::Type * postmutate( const ast::ArrayType * array ) {119 return new ast::PointerType{120 array->base, array->dimension, array->isVarLen, array->isStatic,121 array->qualifiers };122 }123 124 void premutate( const ast::VoidType * ) { isVoid = true; }125 126 void premutate( const ast::BasicType * ) { visit_children = false; }127 void premutate( const ast::PointerType * ) { visit_children = false; }128 void premutate( const ast::StructInstType * ) { visit_children = false; }129 void premutate( const ast::UnionInstType * ) { visit_children = false; }130 void premutate( const ast::EnumInstType * ) { visit_children = false; }131 void premutate( const ast::TraitInstType * ) { visit_children = false; }132 void premutate( const ast::TypeInstType * ) { visit_children = false; }133 void premutate( const ast::TupleType * ) { visit_children = false; }134 void premutate( const ast::VarArgsType * ) { visit_children = false; }135 void premutate( const ast::ZeroType * ) { visit_children = false; }136 void premutate( const ast::OneType * ) { visit_children = false; }137 };138 } // anonymous namespace139 140 const ast::DeclWithType * fixFunction( const ast::DeclWithType * dwt, bool & isVoid ) {141 ast::Pass< FixFunction_new > fixer;142 dwt = dwt->accept( fixer );143 isVoid |= fixer.pass.isVoid;144 return dwt;145 }146 147 74 } // namespace SymTab 148 75
Note:
See TracChangeset
for help on using the changeset viewer.