Changeset 21b7161


Ignore:
Timestamp:
Oct 3, 2017, 2:55:13 PM (7 years ago)
Author:
Rob Schluntz <rschlunt@…>
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
Message:

Convert FixFunction? to PassVisitor?

Location:
src/SymTab
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • src/SymTab/FixFunction.cc

    r11a2d9b r21b7161  
    2626        FixFunction::FixFunction() : isVoid( false ) {}
    2727
    28         DeclarationWithType * FixFunction::mutate(FunctionDecl *functionDecl) {
     28
     29        DeclarationWithType * FixFunction::postmutate(FunctionDecl *functionDecl) {
    2930                // 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();
    3233                functionDecl->type = nullptr;
    3334                delete functionDecl;
     
    3536        }
    3637
    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) {
    5139                // 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;
    5343                delete arrayType;
    5444                return pointerType;
    5545        }
    5646
    57         Type * FixFunction::mutate(StructInstType *aggregateUseType) {
    58                 return aggregateUseType;
     47        void FixFunction::premutate(VoidType *) {
     48                isVoid = true;
    5949        }
    6050
    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; }
    9263} // namespace SymTab
    9364
  • src/SymTab/FixFunction.h

    r11a2d9b r21b7161  
    1616#pragma once
    1717
    18 #include "SynTree/Mutator.h"  // for Mutator
    19 #include "SynTree/SynTree.h"  // for Types
     18#include "Common/PassVisitor.h" // for PassVisitor
     19#include "SynTree/SynTree.h"    // for Types
    2020
    2121namespace SymTab {
    2222        /// Replaces function and array types by equivalent pointer types.
    23         class FixFunction : public Mutator {
     23        class FixFunction : public WithShortCircuiting {
    2424                typedef Mutator Parent;
    2525          public:
    2626                FixFunction();
    2727
    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);
    3230
    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);
    4645
    4746                bool isVoid;
  • src/SymTab/Validate.cc

    r11a2d9b r21b7161  
    369369                        DWTIterator begin( dwts.begin() ), end( dwts.end() );
    370370                        if ( begin == end ) return;
    371                         FixFunction fixer;
     371                        PassVisitor<FixFunction> fixer;
    372372                        DWTIterator i = begin;
    373373                        *i = (*i)->acceptMutator( fixer );
    374                         if ( fixer.get_isVoid() ) {
     374                        if ( fixer.pass.isVoid ) {
    375375                                DWTIterator j = i;
    376376                                ++i;
     
    383383                                ++i;
    384384                                for ( ; i != end; ++i ) {
    385                                         FixFunction fixer;
     385                                        PassVisitor<FixFunction> fixer;
    386386                                        *i = (*i)->acceptMutator( fixer );
    387                                         if ( fixer.get_isVoid() ) {
     387                                        if ( fixer.pass.isVoid ) {
    388388                                                throw SemanticError( "invalid type void in function type ", func );
    389389                                        } // if
     
    597597                        // apply FixFunction to every assertion to check for invalid void type
    598598                        for ( DeclarationWithType *& assertion : type->assertions ) {
    599                                 FixFunction fixer;
     599                                PassVisitor<FixFunction> fixer;
    600600                                assertion = assertion->acceptMutator( fixer );
    601                                 if ( fixer.get_isVoid() ) {
     601                                if ( fixer.pass.isVoid ) {
    602602                                        throw SemanticError( "invalid type void in assertion of function ", node );
    603603                                } // if
Note: See TracChangeset for help on using the changeset viewer.