Changes in src/SymTab/FixFunction.cc [0bd3faf:b2ecd48]
- File:
-
- 1 edited
-
src/SymTab/FixFunction.cc (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/SymTab/FixFunction.cc
r0bd3faf rb2ecd48 22 22 #include "AST/Type.hpp" 23 23 #include "Common/utility.h" // for copy 24 #include "SynTree/Declaration.h" // for FunctionDecl, ObjectDecl, Declarati... 25 #include "SynTree/Expression.h" // for Expression 26 #include "SynTree/Type.h" // for ArrayType, PointerType, Type, Basic... 24 27 25 28 namespace SymTab { 29 class FixFunction_old : public WithShortCircuiting { 30 typedef Mutator Parent; 31 public: 32 FixFunction_old() : isVoid( false ) {} 33 34 void premutate(FunctionDecl *functionDecl); 35 DeclarationWithType* postmutate(FunctionDecl *functionDecl); 36 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) { 57 // can't delete function type because it may contain assertions, so transfer ownership to new object 58 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 functionDecl->attributes.clear(); 61 functionDecl->type = nullptr; 62 delete functionDecl; 63 return pointer; 64 } 65 66 // xxx - this passes on void[], e.g. 67 // void foo(void [10]); 68 // does not cause an error 69 70 Type * FixFunction_old::postmutate(ArrayType *arrayType) { 71 // need to recursively mutate the base type in order for multi-dimensional arrays to work. 72 PointerType *pointerType = new PointerType( arrayType->get_qualifiers(), arrayType->base, arrayType->dimension, arrayType->isVarLen, arrayType->isStatic ); 73 pointerType->location = arrayType->location; 74 arrayType->base = nullptr; 75 arrayType->dimension = nullptr; 76 delete arrayType; 77 return pointerType; 78 } 79 80 void FixFunction_old::premutate(VoidType *) { 81 isVoid = true; 82 } 83 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; } 97 98 bool fixFunction( DeclarationWithType *& dwt ) { 99 PassVisitor<FixFunction_old> fixer; 100 dwt = dwt->acceptMutator( fixer ); 101 return fixer.pass.isVoid; 102 } 26 103 27 104 namespace { 28 struct FixFunction final : public ast::WithShortCircuiting {105 struct FixFunction_new final : public ast::WithShortCircuiting { 29 106 bool isVoid = false; 30 107 … … 70 147 71 148 const ast::DeclWithType * fixFunction( const ast::DeclWithType * dwt, bool & isVoid ) { 72 ast::Pass< FixFunction > fixer;149 ast::Pass< FixFunction_new > fixer; 73 150 dwt = dwt->accept( fixer ); 74 151 isVoid |= fixer.core.isVoid; … … 77 154 78 155 const ast::Type * fixFunction( const ast::Type * type, bool & isVoid ) { 79 ast::Pass< FixFunction > fixer;156 ast::Pass< FixFunction_new > fixer; 80 157 type = type->accept( fixer ); 81 158 isVoid |= fixer.core.isVoid;
Note:
See TracChangeset
for help on using the changeset viewer.