Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/SymTab/FixFunction.cc

    rc1ed2ee r4bda2cf  
    1818#include <list>                   // for list
    1919
    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
    2421#include "SynTree/Declaration.h"  // for FunctionDecl, ObjectDecl, Declarati...
    2522#include "SynTree/Expression.h"   // for Expression
     
    2724
    2825namespace SymTab {
    29         class FixFunction_old : public WithShortCircuiting {
    30                 typedef Mutator Parent;
    31           public:
    32                 FixFunction_old() : isVoid( false ) {}
     26        FixFunction::FixFunction() : isVoid( false ) {}
    3327
    34                 void premutate(FunctionDecl *functionDecl);
    35                 DeclarationWithType* postmutate(FunctionDecl *functionDecl);
    3628
    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) {
    5730                // can't delete function type because it may contain assertions, so transfer ownership to new object
    5831                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;
    6032                functionDecl->attributes.clear();
    6133                functionDecl->type = nullptr;
     
    6840        // does not cause an error
    6941
    70         Type * FixFunction_old::postmutate(ArrayType *arrayType) {
     42        Type * FixFunction::postmutate(ArrayType *arrayType) {
    7143                // need to recursively mutate the base type in order for multi-dimensional arrays to work.
    7244                PointerType *pointerType = new PointerType( arrayType->get_qualifiers(), arrayType->base, arrayType->dimension, arrayType->isVarLen, arrayType->isStatic );
    73                 pointerType->location = arrayType->location;
    7445                arrayType->base = nullptr;
    7546                arrayType->dimension = nullptr;
     
    7849        }
    7950
    80         void FixFunction_old::premutate(VoidType *) {
     51        void FixFunction::premutate(VoidType *) {
    8152                isVoid = true;
    8253        }
    8354
    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; }
    9768
    9869        bool fixFunction( DeclarationWithType *& dwt ) {
    99                 PassVisitor<FixFunction_old> fixer;
     70                PassVisitor<FixFunction> fixer;
    10071                dwt = dwt->acceptMutator( fixer );
    10172                return fixer.pass.isVoid;
    10273        }
    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 namespace
    139 
    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 
    14774} // namespace SymTab
    14875
Note: See TracChangeset for help on using the changeset viewer.