Changeset 21b7161
- Timestamp:
- Oct 3, 2017, 2:55:13 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:
- 7821d6c
- Parents:
- 11a2d9b
- Location:
- src/SymTab
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
src/SymTab/FixFunction.cc
r11a2d9b r21b7161 26 26 FixFunction::FixFunction() : isVoid( false ) {} 27 27 28 DeclarationWithType * FixFunction::mutate(FunctionDecl *functionDecl) { 28 29 DeclarationWithType * FixFunction::postmutate(FunctionDecl *functionDecl) { 29 30 // can't delete function type because it may contain assertions, so transfer ownership to new object 30 ObjectDecl *pointer = new ObjectDecl( functionDecl-> get_name(), functionDecl->get_storageClasses(), functionDecl->get_linkage(), 0, new PointerType( Type::Qualifiers(), functionDecl->get_type() ), 0, functionDecl->get_attributes());31 functionDecl-> get_attributes().clear();31 ObjectDecl *pointer = new ObjectDecl( functionDecl->name, functionDecl->get_storageClasses(), functionDecl->linkage, nullptr, new PointerType( Type::Qualifiers(), functionDecl->type ), nullptr, functionDecl->attributes ); 32 functionDecl->attributes.clear(); 32 33 functionDecl->type = nullptr; 33 34 delete functionDecl; … … 35 36 } 36 37 37 Type * FixFunction::mutate(VoidType *voidType) { 38 isVoid = true; 39 return voidType; 40 } 41 42 Type * FixFunction::mutate(BasicType *basicType) { 43 return basicType; 44 } 45 46 Type * FixFunction::mutate(PointerType *pointerType) { 47 return pointerType; 48 } 49 50 Type * FixFunction::mutate(ArrayType *arrayType) { 38 Type * FixFunction::postmutate(ArrayType *arrayType) { 51 39 // need to recursively mutate the base type in order for multi-dimensional arrays to work. 52 PointerType *pointerType = new PointerType( arrayType->get_qualifiers(), arrayType->get_base()->clone()->acceptMutator( *this ), maybeClone( arrayType->get_dimension() ), arrayType->get_isVarLen(), arrayType->get_isStatic() ); 40 PointerType *pointerType = new PointerType( arrayType->get_qualifiers(), arrayType->base, arrayType->dimension, arrayType->isVarLen, arrayType->isStatic ); 41 arrayType->base = nullptr; 42 arrayType->dimension = nullptr; 53 43 delete arrayType; 54 44 return pointerType; 55 45 } 56 46 57 Type * FixFunction::mutate(StructInstType *aggregateUseType) {58 return aggregateUseType;47 void FixFunction::premutate(VoidType *) { 48 isVoid = true; 59 49 } 60 50 61 Type * FixFunction::mutate(UnionInstType *aggregateUseType) { 62 return aggregateUseType; 63 } 64 65 Type * FixFunction::mutate(EnumInstType *aggregateUseType) { 66 return aggregateUseType; 67 } 68 69 Type * FixFunction::mutate(TraitInstType *aggregateUseType) { 70 return aggregateUseType; 71 } 72 73 Type * FixFunction::mutate(TypeInstType *aggregateUseType) { 74 return aggregateUseType; 75 } 76 77 Type * FixFunction::mutate(TupleType *tupleType) { 78 return tupleType; 79 } 80 81 Type * FixFunction::mutate(VarArgsType *varArgsType) { 82 return varArgsType; 83 } 84 85 Type * FixFunction::mutate(ZeroType *zeroType) { 86 return zeroType; 87 } 88 89 Type * FixFunction::mutate(OneType *oneType) { 90 return oneType; 91 } 51 void FixFunction::premutate(FunctionDecl *) { visit_children = false; } 52 void FixFunction::premutate(BasicType *) { visit_children = false; } 53 void FixFunction::premutate(PointerType *) { visit_children = false; } 54 void FixFunction::premutate(StructInstType *) { visit_children = false; } 55 void FixFunction::premutate(UnionInstType *) { visit_children = false; } 56 void FixFunction::premutate(EnumInstType *) { visit_children = false; } 57 void FixFunction::premutate(TraitInstType *) { visit_children = false; } 58 void FixFunction::premutate(TypeInstType *) { visit_children = false; } 59 void FixFunction::premutate(TupleType *) { visit_children = false; } 60 void FixFunction::premutate(VarArgsType *) { visit_children = false; } 61 void FixFunction::premutate(ZeroType *) { visit_children = false; } 62 void FixFunction::premutate(OneType *) { visit_children = false; } 92 63 } // namespace SymTab 93 64 -
src/SymTab/FixFunction.h
r11a2d9b r21b7161 16 16 #pragma once 17 17 18 #include " SynTree/Mutator.h" // for Mutator19 #include "SynTree/SynTree.h" // for Types18 #include "Common/PassVisitor.h" // for PassVisitor 19 #include "SynTree/SynTree.h" // for Types 20 20 21 21 namespace SymTab { 22 22 /// Replaces function and array types by equivalent pointer types. 23 class FixFunction : public Mutator{23 class FixFunction : public WithShortCircuiting { 24 24 typedef Mutator Parent; 25 25 public: 26 26 FixFunction(); 27 27 28 bool get_isVoid() const { return isVoid; } 29 void set_isVoid( bool newValue ) { isVoid = newValue; } 30 private: 31 virtual DeclarationWithType* mutate(FunctionDecl *functionDecl); 28 void premutate(FunctionDecl *functionDecl); 29 DeclarationWithType* postmutate(FunctionDecl *functionDecl); 32 30 33 virtual Type* mutate(VoidType *voidType); 34 virtual Type* mutate(BasicType *basicType); 35 virtual Type* mutate(PointerType *pointerType); 36 virtual Type* mutate(ArrayType *arrayType); 37 virtual Type* mutate(StructInstType *aggregateUseType); 38 virtual Type* mutate(UnionInstType *aggregateUseType); 39 virtual Type* mutate(EnumInstType *aggregateUseType); 40 virtual Type* mutate(TraitInstType *aggregateUseType); 41 virtual Type* mutate(TypeInstType *aggregateUseType); 42 virtual Type* mutate(TupleType *tupleType); 43 virtual Type* mutate(VarArgsType *varArgsType); 44 virtual Type* mutate(ZeroType *zeroType); 45 virtual Type* mutate(OneType *oneType); 31 Type * postmutate(ArrayType * arrayType); 32 33 void premutate(VoidType * voidType); 34 void premutate(BasicType * basicType); 35 void premutate(PointerType * pointerType); 36 void premutate(StructInstType * aggregateUseType); 37 void premutate(UnionInstType * aggregateUseType); 38 void premutate(EnumInstType * aggregateUseType); 39 void premutate(TraitInstType * aggregateUseType); 40 void premutate(TypeInstType * aggregateUseType); 41 void premutate(TupleType * tupleType); 42 void premutate(VarArgsType * varArgsType); 43 void premutate(ZeroType * zeroType); 44 void premutate(OneType * oneType); 46 45 47 46 bool isVoid; -
src/SymTab/Validate.cc
r11a2d9b r21b7161 369 369 DWTIterator begin( dwts.begin() ), end( dwts.end() ); 370 370 if ( begin == end ) return; 371 FixFunctionfixer;371 PassVisitor<FixFunction> fixer; 372 372 DWTIterator i = begin; 373 373 *i = (*i)->acceptMutator( fixer ); 374 if ( fixer. get_isVoid()) {374 if ( fixer.pass.isVoid ) { 375 375 DWTIterator j = i; 376 376 ++i; … … 383 383 ++i; 384 384 for ( ; i != end; ++i ) { 385 FixFunctionfixer;385 PassVisitor<FixFunction> fixer; 386 386 *i = (*i)->acceptMutator( fixer ); 387 if ( fixer. get_isVoid()) {387 if ( fixer.pass.isVoid ) { 388 388 throw SemanticError( "invalid type void in function type ", func ); 389 389 } // if … … 597 597 // apply FixFunction to every assertion to check for invalid void type 598 598 for ( DeclarationWithType *& assertion : type->assertions ) { 599 FixFunctionfixer;599 PassVisitor<FixFunction> fixer; 600 600 assertion = assertion->acceptMutator( fixer ); 601 if ( fixer. get_isVoid()) {601 if ( fixer.pass.isVoid ) { 602 602 throw SemanticError( "invalid type void in assertion of function ", node ); 603 603 } // if
Note: See TracChangeset
for help on using the changeset viewer.