Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/SymTab/Validate.cc

    r42107b4 r25fcb84  
    4848#include "CodeGen/CodeGenerator.h"     // for genName
    4949#include "CodeGen/OperatorTable.h"     // for isCtorDtor, isCtorDtorAssign
    50 #include "Common/GC.h"                 // for new_static_root, register_static_root
     50#include "ControlStruct/Mutate.h"      // for ForExprMutator
    5151#include "Common/PassVisitor.h"        // for PassVisitor, WithDeclsToAdd
    5252#include "Common/ScopedMap.h"          // for ScopedMap
     
    7777class SwitchStmt;
    7878
    79 
    8079#define debugPrint( x ) if ( doDebug ) { std::cout << x; }
    8180
     
    200199                void addImplicitTypedef( AggDecl * aggDecl );
    201200
    202                 typedef ScopedMap< std::string, std::pair< TypedefDecl*, int > > TypedefMap;
     201                typedef std::unique_ptr<TypedefDecl> TypedefDeclPtr;
     202                typedef ScopedMap< std::string, std::pair< TypedefDeclPtr, int > > TypedefMap;
    203203                typedef std::map< std::string, TypeDecl * > TypeDeclMap;
    204204                TypedefMap typedefNames;
     
    275275                Concurrency::applyKeywords( translationUnit );
    276276                acceptAll( translationUnit, fpd ); // must happen before autogenerateRoutines, after Concurrency::applyKeywords because uniqueIds must be set on declaration before resolution
     277                ControlStruct::hoistControlDecls( translationUnit );  // hoist initialization out of for statements; must happen before autogenerateRoutines
    277278                autogenerateRoutines( translationUnit ); // moved up, used to be below compoundLiteral - currently needs EnumAndPointerDecay
    278279                Concurrency::implementMutexFuncs( translationUnit );
     
    312313                } // if
    313314                // Always remove the hoisted aggregate from the inner structure.
    314                 GuardAction( [aggregateDecl]() { filter( aggregateDecl->members, shouldHoist ); } );
     315                GuardAction( [aggregateDecl]() { filter( aggregateDecl->members, shouldHoist, false ); } );
    315316        }
    316317
     
    373374                        // one void is the only thing in the list; remove it.
    374375                        if ( containsVoid ) {
     376                                delete dwts.front();
    375377                                dwts.clear();
    376378                        }
     
    499501                                }
    500502                        }
     503                        deleteAll( td->assertions );
    501504                        td->assertions.clear();
    502505                } // for
     
    614617                                        // expand trait instance into all of its members
    615618                                        expandAssertions( traitInst, back_inserter( type->assertions ) );
     619                                        delete traitInst;
    616620                                } else {
    617621                                        // pass other assertions through
     
    685689                        // grab and remember declaration of size_t
    686690                        SizeType = eliminator.pass.typedefNames["size_t"].first->get_base()->clone();
    687                         GC::get().register_static_root( SizeType );
    688691                } else {
    689692                        // xxx - missing global typedef for size_t - default to long unsigned int, even though that may be wrong
    690693                        // eventually should have a warning for this case.
    691                         SizeType =
    692                                 new_static_root<BasicType>( Type::Qualifiers(), BasicType::LongUnsignedInt );
    693                 }
    694                 filter( translationUnit, isTypedef );
     694                        SizeType = new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt );
     695                }
     696                filter( translationUnit, isTypedef, true );
    695697        }
    696698
     
    706708                                ret->attributes.splice( ret->attributes.end(), typeInst->attributes );
    707709                        } else {
     710                                deleteAll( ret->attributes );
    708711                                ret->attributes.clear();
    709712                        }
     
    718721                                mutateAll( rtt->parameters, *visitor );  // recursively fix typedefs on parameters
    719722                        } // if
     723                        delete typeInst;
    720724                        return ret;
    721725                } else {
     
    759763                        }
    760764                } else {
    761                         typedefNames[ tyDecl->get_name() ] = std::make_pair( tyDecl, scopeLevel );
     765                        typedefNames[ tyDecl->get_name() ] = std::make_pair( TypedefDeclPtr( tyDecl ), scopeLevel );
    762766                } // if
    763767
     
    803807                if ( FunctionType *funtype = dynamic_cast<FunctionType *>( objDecl->get_type() ) ) { // function type?
    804808                        // replace the current object declaration with a function declaration
    805                         return new FunctionDecl{
    806                                 objDecl->get_name(), objDecl->get_storageClasses(), objDecl->get_linkage(),
    807                                 funtype, 0, objDecl->get_attributes(), objDecl->get_funcSpec() };
     809                        FunctionDecl * newDecl = new FunctionDecl( objDecl->get_name(), objDecl->get_storageClasses(), objDecl->get_linkage(), funtype, 0, objDecl->get_attributes(), objDecl->get_funcSpec() );
     810                        objDecl->get_attributes().clear();
     811                        objDecl->set_type( nullptr );
     812                        delete objDecl;
     813                        return newDecl;
    808814                } // if
    809815                return objDecl;
     
    829835                        } // if
    830836                        return false;
    831                 } );
     837                }, true);
    832838                return compoundStmt;
    833839        }
     
    837843        template<typename AggDecl>
    838844        AggDecl *EliminateTypedef::handleAggregate( AggDecl * aggDecl ) {
    839                 filter( aggDecl->members, isTypedef );
     845                filter( aggDecl->members, isTypedef, true );
    840846                return aggDecl;
    841847        }
     
    852858                                type = new EnumInstType( Type::Qualifiers(), newDeclEnumDecl->get_name() );
    853859                        } // if
    854                         TypedefDecl* tyDecl = new TypedefDecl{ aggDecl->get_name(), aggDecl->location, Type::StorageClasses(), type, aggDecl->get_linkage() };
    855                         typedefNames[ aggDecl->get_name() ] = std::make_pair( tyDecl, scopeLevel );
     860                        TypedefDeclPtr tyDecl( new TypedefDecl( aggDecl->get_name(), aggDecl->location, Type::StorageClasses(), type, aggDecl->get_linkage() ) );
     861                        typedefNames[ aggDecl->get_name() ] = std::make_pair( std::move( tyDecl ), scopeLevel );
    856862                } // if
    857863        }
     
    967973                static UniqueName indexName( "_compLit" );
    968974
    969                 ObjectDecl * tempvar = new ObjectDecl{
    970                         indexName.newName(), storageClasses, LinkageSpec::C, nullptr, compLitExpr->get_result(), compLitExpr->get_initializer() };
     975                ObjectDecl *tempvar = new ObjectDecl( indexName.newName(), storageClasses, LinkageSpec::C, nullptr, compLitExpr->get_result(), compLitExpr->get_initializer() );
     976                compLitExpr->set_result( nullptr );
     977                compLitExpr->set_initializer( nullptr );
     978                delete compLitExpr;
    971979                declsToAddBefore.push_back( tempvar );                                  // add modified temporary to current block
    972980                return new VariableExpr( tempvar );
     
    10041012                        // ensure return value is not destructed by explicitly creating an empty ListInit node wherein maybeConstruct is false.
    10051013                        ObjectDecl * newRet = new ObjectDecl( "", Type::StorageClasses(), LinkageSpec::Cforall, 0, tupleType, new ListInit( std::list<Initializer*>(), noDesignators, false ) );
     1014                        deleteAll( retVals );
    10061015                        retVals.clear();
    10071016                        retVals.push_back( newRet );
     
    10441053                        if ( NameExpr * nameExpr = dynamic_cast< NameExpr * >( inner->arg ) ) {
    10451054                                if ( labels.count( nameExpr->name ) ) {
    1046                                         return new LabelAddressExpr{ nameExpr->name };
     1055                                        Label name = nameExpr->name;
     1056                                        delete addrExpr;
     1057                                        return new LabelAddressExpr( name );
    10471058                                }
    10481059                        }
Note: See TracChangeset for help on using the changeset viewer.