Changeset 1048b31 for src/SymTab


Ignore:
Timestamp:
May 2, 2016, 3:28:16 PM (10 years ago)
Author:
Rob Schluntz <rschlunt@…>
Branches:
ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, ctor, deferred_resn, demangler, enum, forall-pointer-decay, gc_noraii, jacob/cs343-translation, jenkins-sandbox, master, memory, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, stuck-waitfor-destruct, with_gc
Children:
1b7ea43
Parents:
1f6e009 (diff), e945826 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'master' into global-init

Location:
src/SymTab
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • src/SymTab/AddVisit.h

    r1f6e009 r1048b31  
    99// Author           : Richard C. Bilson
    1010// Created On       : Sun May 17 16:14:32 2015
    11 // Last Modified By : Rob Schluntz
    12 // Last Modified On : Tue Jul 14 12:26:17 2015
    13 // Update Count     : 4
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Thu Apr  7 14:42:21 2016
     13// Update Count     : 5
    1414//
    1515
     
    2727
    2828        template< typename Visitor >
    29         inline void addVisitStatement( Statement *stmt, Visitor &visitor ) {
    30                 maybeAccept( stmt, visitor );
    31 ///   if ( ! declsToAdd.empty() ) {
    32 ///     CompoundStmt *compound = new CompoundStmt( noLabels );
    33 ///     compound->get_kids().push_back( stmt );
    34 ///     addDecls( declsToAdd, compound->get_kids(), compound->get_kids().end() );
    35 ///   }
    36         }
    37 
    38         template< typename Visitor >
    3929        inline void addVisit(CompoundStmt *compoundStmt, Visitor &visitor) {
    4030                addVisitStatementList( compoundStmt->get_kids(), visitor );
    41         }
    42 
    43         template< typename Visitor >
    44         inline void addVisit(IfStmt *ifStmt, Visitor &visitor) {
    45                 addVisitStatement( ifStmt->get_thenPart(), visitor );
    46                 addVisitStatement( ifStmt->get_elsePart(), visitor );
    47                 maybeAccept( ifStmt->get_condition(), visitor );
    48         }
    49 
    50         template< typename Visitor >
    51         inline void addVisit(WhileStmt *whileStmt, Visitor &visitor) {
    52                 addVisitStatement( whileStmt->get_body(), visitor );
    53                 maybeAccept( whileStmt->get_condition(), visitor );
    54         }
    55 
    56         template< typename Visitor >
    57         inline void addVisit(ForStmt *forStmt, Visitor &visitor) {
    58                 addVisitStatement( forStmt->get_body(), visitor );
    59                 acceptAll( forStmt->get_initialization(), visitor );
    60                 maybeAccept( forStmt->get_condition(), visitor );
    61                 maybeAccept( forStmt->get_increment(), visitor );
    6231        }
    6332
     
    7443        }
    7544
    76         template< typename Visitor >
    77         inline void addVisit(CaseStmt *caseStmt, Visitor &visitor) {
    78                 addVisitStatementList( caseStmt->get_statements(), visitor );
    79                 maybeAccept( caseStmt->get_condition(), visitor );
    80         }
    81 
    82         template< typename Visitor >
    83         inline void addVisit(CatchStmt *cathStmt, Visitor &visitor) {
    84                 addVisitStatement( cathStmt->get_body(), visitor );
    85                 maybeAccept( cathStmt->get_decl(), visitor );
    86         }
     45        // template< typename Visitor >
     46        // inline void addVisit(CaseStmt *caseStmt, Visitor &visitor) {
     47        //      addVisitStatementList( caseStmt->get_statements(), visitor );
     48        //      maybeAccept( caseStmt->get_condition(), visitor );
     49        // }
    8750} // namespace SymTab
    8851
  • src/SymTab/Indexer.cc

    r1f6e009 r1048b31  
    55// file "LICENCE" distributed with Cforall.
    66//
    7 // Indexer.cc -- 
     7// Indexer.cc --
    88//
    99// Author           : Richard C. Bilson
    1010// Created On       : Sun May 17 21:37:33 2015
    11 // Last Modified By : Peter A. Buhr
    12 // Last Modified On : Wed Mar  2 17:31:29 2016
     11// Last Modified By : Rob Schluntz
     12// Last Modified On : Fri Apr 22 15:25:43 2016
    1313// Update Count     : 11
    1414//
     
    5959                }
    6060        }
    61        
     61
    6262        template< typename Decl >
    6363        void dump( const std::unordered_map< std::string, Decl* > &table, std::ostream &os ) {
     
    6666                } // for
    6767        }
    68        
     68
    6969        struct Indexer::Impl {
    7070                Impl( unsigned long _scope ) : refCount(1), scope( _scope ), size( 0 ), base(),
     
    7676                unsigned long size;       ///< Number of elements stored in this table
    7777                const Indexer base;       ///< Base indexer this extends
    78                
     78
    7979                IdTable idTable;          ///< Identifier namespace
    8080                TypeTable typeTable;      ///< Type namespace
     
    213213        void Indexer::visit( StructDecl *aggregateDecl ) {
    214214                // make up a forward declaration and add it before processing the members
    215                 StructDecl fwdDecl( aggregateDecl->get_name() );
     215                // needs to be on the heap because addStruct saves the pointer
     216                StructDecl &fwdDecl = *new StructDecl( aggregateDecl->get_name() );
    216217                cloneAll( aggregateDecl->get_parameters(), fwdDecl.get_parameters() );
    217218                debugPrint( "Adding fwd decl for struct " << fwdDecl.get_name() << std::endl );
    218219                addStruct( &fwdDecl );
    219  
     220
    220221                enterScope();
    221222                acceptAll( aggregateDecl->get_parameters(), *this );
    222223                acceptAll( aggregateDecl->get_members(), *this );
    223224                leaveScope();
    224  
     225
    225226                debugPrint( "Adding struct " << aggregateDecl->get_name() << std::endl );
    226227                // this addition replaces the forward declaration
     
    234235                debugPrint( "Adding fwd decl for union " << fwdDecl.get_name() << std::endl );
    235236                addUnion( &fwdDecl );
    236  
     237
    237238                enterScope();
    238239                acceptAll( aggregateDecl->get_parameters(), *this );
    239240                acceptAll( aggregateDecl->get_members(), *this );
    240241                leaveScope();
    241  
     242
    242243                debugPrint( "Adding union " << aggregateDecl->get_name() << std::endl );
    243244                addUnion( aggregateDecl );
     
    256257                acceptAll( aggregateDecl->get_members(), *this );
    257258                leaveScope();
    258  
     259
    259260                debugPrint( "Adding context " << aggregateDecl->get_name() << std::endl );
    260261                addTrait( aggregateDecl );
     
    344345                maybeAccept( offsetofExpr->get_type(), *this );
    345346                maybeAccept( offsetofExpr->get_member(), *this );
     347        }
     348
     349        void Indexer::visit( OffsetPackExpr *offsetPackExpr ) {
     350                acceptAllNewScope( offsetPackExpr->get_results(), *this );
     351                maybeAccept( offsetPackExpr->get_type(), *this );
    346352        }
    347353
     
    433439        }
    434440
    435        
     441
    436442
    437443        void Indexer::lookupId( const std::string &id, std::list< DeclarationWithType* > &out ) const {
    438444                std::unordered_set< std::string > foundMangleNames;
    439                
     445
    440446                Indexer::Impl *searchTables = tables;
    441447                while ( searchTables ) {
     
    447453                                        // mark the mangled name as found, skipping this insertion if a declaration for that name has already been found
    448454                                        if ( foundMangleNames.insert( decl->first ).second == false ) continue;
    449                                        
     455
    450456                                        out.push_back( decl->second );
    451457                                }
    452458                        }
    453                        
     459
    454460                        // get declarations from base indexers
    455461                        searchTables = searchTables->base.tables;
     
    506512        }
    507513
    508         bool Indexer::hasIncompatibleCDecl( const std::string &id, const std::string &mangleName ) const {
     514        bool Indexer::hasIncompatibleCDecl( const std::string &id, const std::string &mangleName, unsigned long scope ) const {
    509515                if ( ! tables ) return false;
     516                if ( tables->scope < scope ) return false;
    510517
    511518                IdTable::const_iterator decls = tables->idTable.find( id );
     
    513520                        const MangleTable &mangleTable = decls->second;
    514521                        for ( MangleTable::const_iterator decl = mangleTable.begin(); decl != mangleTable.end(); ++decl ) {
    515                                 // check for C decls with the same name, skipping 
     522                                // check for C decls with the same name, skipping
    516523                                // those with a compatible type (by mangleName)
    517524                                if ( decl->second->get_linkage() == LinkageSpec::C && decl->first != mangleName ) return true;
     
    519526                }
    520527
    521                 return tables->base.hasIncompatibleCDecl( id, mangleName );
    522         }
    523        
     528                return tables->base.hasIncompatibleCDecl( id, mangleName, scope );
     529        }
     530
    524531        NamedTypeDecl *Indexer::lookupTypeAtScope( const std::string &id, unsigned long scope ) const {
    525532                if ( ! tables ) return 0;
     
    529536                return ret != tables->typeTable.end() ? ret->second : tables->base.lookupTypeAtScope( id, scope );
    530537        }
    531        
     538
    532539        StructDecl *Indexer::lookupStructAtScope( const std::string &id, unsigned long scope ) const {
    533540                if ( ! tables ) return 0;
     
    537544                return ret != tables->structTable.end() ? ret->second : tables->base.lookupStructAtScope( id, scope );
    538545        }
    539        
     546
    540547        EnumDecl *Indexer::lookupEnumAtScope( const std::string &id, unsigned long scope ) const {
    541548                if ( ! tables ) return 0;
     
    545552                return ret != tables->enumTable.end() ? ret->second : tables->base.lookupEnumAtScope( id, scope );
    546553        }
    547        
     554
    548555        UnionDecl *Indexer::lookupUnionAtScope( const std::string &id, unsigned long scope ) const {
    549556                if ( ! tables ) return 0;
     
    553560                return ret != tables->unionTable.end() ? ret->second : tables->base.lookupUnionAtScope( id, scope );
    554561        }
    555        
     562
    556563        TraitDecl *Indexer::lookupTraitAtScope( const std::string &id, unsigned long scope ) const {
    557564                if ( ! tables ) return 0;
     
    596603                return true;
    597604        }
    598        
     605
    599606        void Indexer::addId( DeclarationWithType *decl ) {
    600607                makeWritable();
     
    612619                DeclarationWithType *existing = lookupIdAtScope( name, mangleName, scope );
    613620                if ( ! existing || ! addedIdConflicts( existing, decl ) ) {
    614                         // this ensures that no two declarations with the same unmangled name both have C linkage
    615                         if ( decl->get_linkage() == LinkageSpec::C && hasIncompatibleCDecl( name, mangleName ) ) {
     621                        // this ensures that no two declarations with the same unmangled name at the same scope both have C linkage
     622                        if ( decl->get_linkage() == LinkageSpec::C && hasIncompatibleCDecl( name, mangleName, scope ) ) {
    616623                                throw SemanticError( "invalid overload of C function ", decl );
    617                         } // NOTE this is broken in Richard's original code in such a way that it never triggers (it 
    618                           // doesn't check decls that have the same manglename, and all C-linkage decls are defined to 
     624                        } // NOTE this is broken in Richard's original code in such a way that it never triggers (it
     625                          // doesn't check decls that have the same manglename, and all C-linkage decls are defined to
    619626                          // have their name as their manglename, hence the error can never trigger).
    620                           // The code here is closer to correct, but name mangling would have to be completely 
     627                          // The code here is closer to correct, but name mangling would have to be completely
    621628                          // isomorphic to C type-compatibility, which it may not be.
    622                        
     629
    623630                        tables->idTable[ name ][ mangleName ] = decl;
    624631                        ++tables->size;
     
    635642                }
    636643        }
    637        
     644
    638645        void Indexer::addType( NamedTypeDecl *decl ) {
    639646                makeWritable();
     
    666673                addStruct( new StructDecl( id ) );
    667674        }
    668        
     675
    669676        void Indexer::addStruct( StructDecl *decl ) {
    670677                makeWritable();
     
    684691                }
    685692        }
    686        
     693
    687694        void Indexer::addEnum( EnumDecl *decl ) {
    688695                makeWritable();
     
    706713                addUnion( new UnionDecl( id ) );
    707714        }
    708        
     715
    709716        void Indexer::addUnion( UnionDecl *decl ) {
    710717                makeWritable();
     
    724731                }
    725732        }
    726        
     733
    727734        void Indexer::addTrait( TraitDecl *decl ) {
    728735                makeWritable();
     
    745752        void Indexer::enterScope() {
    746753                ++scope;
    747                
     754
    748755                if ( doDebug ) {
    749756                        std::cout << "--- Entering scope " << scope << std::endl;
     
    778785            using std::cerr;
    779786
    780             cerr << "===idTable===" << std::endl;
    781             if ( tables ) dump( tables->idTable, os );
    782             cerr << "===typeTable===" << std::endl;
    783             if ( tables ) dump( tables->typeTable, os );
    784             cerr << "===structTable===" << std::endl;
    785             if ( tables ) dump( tables->structTable, os );
    786             cerr << "===enumTable===" << std::endl;
    787             if ( tables ) dump( tables->enumTable, os );
    788             cerr << "===unionTable===" << std::endl;
    789             if ( tables ) dump( tables->unionTable, os );
    790             cerr << "===contextTable===" << std::endl;
    791             if ( tables ) dump( tables->traitTable, os );
     787                if ( tables ) {
     788                        os << "--- scope " << tables->scope << " ---" << std::endl;
     789
     790                        os << "===idTable===" << std::endl;
     791                        dump( tables->idTable, os );
     792                        os << "===typeTable===" << std::endl;
     793                        dump( tables->typeTable, os );
     794                        os << "===structTable===" << std::endl;
     795                        dump( tables->structTable, os );
     796                        os << "===enumTable===" << std::endl;
     797                        dump( tables->enumTable, os );
     798                        os << "===unionTable===" << std::endl;
     799                        dump( tables->unionTable, os );
     800                        os << "===contextTable===" << std::endl;
     801                        dump( tables->traitTable, os );
     802
     803                        tables->base.print( os, indent );
     804                } else {
     805                        os << "--- end ---" << std::endl;
     806                }
     807
    792808        }
    793809} // namespace SymTab
  • src/SymTab/Indexer.h

    r1f6e009 r1048b31  
    5959                virtual void visit( UntypedOffsetofExpr *offsetofExpr );
    6060                virtual void visit( OffsetofExpr *offsetofExpr );
     61                virtual void visit( OffsetPackExpr *offsetPackExpr );
    6162                virtual void visit( AttrExpr *attrExpr );
    6263                virtual void visit( LogicalExpr *logicalExpr );
     
    9899                DeclarationWithType *lookupIdAtScope( const std::string &id, const std::string &mangleName, unsigned long scope ) const;
    99100                /// returns true if there exists a declaration with C linkage and the given name with a different mangled name
    100                 bool hasIncompatibleCDecl( const std::string &id, const std::string &mangleName ) const;
     101                bool hasIncompatibleCDecl( const std::string &id, const std::string &mangleName, unsigned long scope ) const;
    101102                // equivalents to lookup functions that only look at tables at scope `scope` (which should be >= tables->scope)
    102103                NamedTypeDecl *lookupTypeAtScope( const std::string &id, unsigned long scope ) const;
  • src/SymTab/Validate.cc

    r1f6e009 r1048b31  
    1010// Created On       : Sun May 17 21:50:04 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Wed Mar  2 17:31:39 2016
    13 // Update Count     : 226
     12// Last Modified On : Wed Apr 13 16:39:30 2016
     13// Update Count     : 251
    1414//
    1515
     
    4040#include <list>
    4141#include <iterator>
     42#include "Common/utility.h"
     43#include "Common/UniqueName.h"
    4244#include "Validate.h"
    4345#include "SynTree/Visitor.h"
    4446#include "SynTree/Mutator.h"
    4547#include "SynTree/Type.h"
     48#include "SynTree/Expression.h"
    4649#include "SynTree/Statement.h"
    4750#include "SynTree/TypeSubstitution.h"
     
    4952#include "FixFunction.h"
    5053// #include "ImplementationType.h"
    51 #include "Common/utility.h"
    52 #include "Common/UniqueName.h"
     54#include "GenPoly/DeclMutator.h"
    5355#include "AddVisit.h"
    5456#include "MakeLibCfa.h"
     
    7072
    7173                virtual void visit( CompoundStmt *compoundStmt );
    72                 virtual void visit( IfStmt *ifStmt );
    73                 virtual void visit( WhileStmt *whileStmt );
    74                 virtual void visit( ForStmt *forStmt );
    7574                virtual void visit( SwitchStmt *switchStmt );
    7675                virtual void visit( ChooseStmt *chooseStmt );
    77                 virtual void visit( CaseStmt *caseStmt );
    78                 virtual void visit( CatchStmt *catchStmt );
     76                // virtual void visit( CaseStmt *caseStmt );
    7977          private:
    8078                HoistStruct();
     
    144142
    145143                virtual void visit( CompoundStmt *compoundStmt );
    146                 virtual void visit( IfStmt *ifStmt );
    147                 virtual void visit( WhileStmt *whileStmt );
    148                 virtual void visit( ForStmt *forStmt );
    149144                virtual void visit( SwitchStmt *switchStmt );
    150145                virtual void visit( ChooseStmt *chooseStmt );
    151                 virtual void visit( CaseStmt *caseStmt );
    152                 virtual void visit( CatchStmt *catchStmt );
     146                // virtual void visit( CaseStmt *caseStmt );
    153147
    154148                AutogenerateRoutines() : functionNesting( 0 ) {}
     
    166160                /// and return something if the return type is non-void.
    167161                static void checkFunctionReturns( std::list< Declaration * > & translationUnit );
    168 
    169162          private:
    170163                virtual void visit( FunctionDecl * functionDecl );
     
    197190                AggDecl *handleAggregate( AggDecl * aggDecl );
    198191
     192                template<typename AggDecl>
     193                void addImplicitTypedef( AggDecl * aggDecl );
     194               
    199195                typedef std::map< std::string, std::pair< TypedefDecl *, int > > TypedefMap;
    200196                TypedefMap typedefNames;
     
    202198        };
    203199
     200        class CompoundLiteral : public GenPoly::DeclMutator {
     201                DeclarationNode::StorageClass storageclass = DeclarationNode::NoStorageClass;
     202
     203                virtual DeclarationWithType * mutate( ObjectDecl *objectDecl );
     204                virtual Expression *mutate( CompoundLiteralExpr *compLitExpr );
     205        };
     206
    204207        void validate( std::list< Declaration * > &translationUnit, bool doDebug ) {
    205208                Pass1 pass1;
    206209                Pass2 pass2( doDebug, 0 );
    207210                Pass3 pass3( 0 );
     211                CompoundLiteral compoundliteral;
     212
    208213                EliminateTypedef::eliminateTypedef( translationUnit );
    209214                HoistStruct::hoistStruct( translationUnit );
     
    211216                acceptAll( translationUnit, pass2 );
    212217                ReturnChecker::checkFunctionReturns( translationUnit );
     218                mutateAll( translationUnit, compoundliteral );
    213219                AutogenerateRoutines::autogenerateRoutines( translationUnit );
    214220                acceptAll( translationUnit, pass3 );
     
    292298        }
    293299
    294         void HoistStruct::visit( IfStmt *ifStmt ) {
    295                 addVisit( ifStmt, *this );
    296         }
    297 
    298         void HoistStruct::visit( WhileStmt *whileStmt ) {
    299                 addVisit( whileStmt, *this );
    300         }
    301 
    302         void HoistStruct::visit( ForStmt *forStmt ) {
    303                 addVisit( forStmt, *this );
    304         }
    305 
    306300        void HoistStruct::visit( SwitchStmt *switchStmt ) {
    307301                addVisit( switchStmt, *this );
     
    312306        }
    313307
    314         void HoistStruct::visit( CaseStmt *caseStmt ) {
    315                 addVisit( caseStmt, *this );
    316         }
    317 
    318         void HoistStruct::visit( CatchStmt *cathStmt ) {
    319                 addVisit( cathStmt, *this );
    320         }
     308        // void HoistStruct::visit( CaseStmt *caseStmt ) {
     309        //      addVisit( caseStmt, *this );
     310        // }
    321311
    322312        void Pass1::visit( EnumDecl *enumDecl ) {
     
    874864        }
    875865
    876         void AutogenerateRoutines::visit( IfStmt *ifStmt ) {
    877                 visitStatement( ifStmt );
    878         }
    879 
    880         void AutogenerateRoutines::visit( WhileStmt *whileStmt ) {
    881                 visitStatement( whileStmt );
    882         }
    883 
    884         void AutogenerateRoutines::visit( ForStmt *forStmt ) {
    885                 visitStatement( forStmt );
    886         }
    887 
    888866        void AutogenerateRoutines::visit( SwitchStmt *switchStmt ) {
    889867                visitStatement( switchStmt );
     
    894872        }
    895873
    896         void AutogenerateRoutines::visit( CaseStmt *caseStmt ) {
    897                 visitStatement( caseStmt );
    898         }
    899 
    900         void AutogenerateRoutines::visit( CatchStmt *cathStmt ) {
    901                 visitStatement( cathStmt );
    902         }
     874        // void AutogenerateRoutines::visit( CaseStmt *caseStmt ) {
     875        //      visitStatement( caseStmt );
     876        // }
    903877
    904878        void ReturnChecker::checkFunctionReturns( std::list< Declaration * > & translationUnit ) {
     
    947921                                }
    948922                                rtt->get_parameters().clear();
    949                                 cloneAll(typeInst->get_parameters(), rtt->get_parameters());
     923                                cloneAll( typeInst->get_parameters(), rtt->get_parameters() );
     924                                mutateAll( rtt->get_parameters(), *this );  // recursively fix typedefs on parameters
    950925                        } // if
    951926                        delete typeInst;
     
    10431018        }
    10441019
    1045         // there may be typedefs nested within aggregates
    1046         // in order for everything to work properly, these
    1047         // should be removed as well
     1020        // there may be typedefs nested within aggregates in order for everything to work properly, these should be removed
     1021        // as well
    10481022        template<typename AggDecl>
    10491023        AggDecl *EliminateTypedef::handleAggregate( AggDecl * aggDecl ) {
     
    10591033                return aggDecl;
    10601034        }
    1061 
     1035       
     1036        template<typename AggDecl>
     1037        void EliminateTypedef::addImplicitTypedef( AggDecl * aggDecl ) {
     1038                if ( typedefNames.count( aggDecl->get_name() ) == 0 ) {
     1039                        Type *type;
     1040                        if ( StructDecl * newDeclStructDecl = dynamic_cast< StructDecl * >( aggDecl ) ) {
     1041                                type = new StructInstType( Type::Qualifiers(), newDeclStructDecl->get_name() );
     1042                        } else if ( UnionDecl * newDeclUnionDecl = dynamic_cast< UnionDecl * >( aggDecl ) ) {
     1043                                type = new UnionInstType( Type::Qualifiers(), newDeclUnionDecl->get_name() );
     1044                        } else if ( EnumDecl * newDeclEnumDecl = dynamic_cast< EnumDecl * >( aggDecl )  ) {
     1045                                type = new EnumInstType( Type::Qualifiers(), newDeclEnumDecl->get_name() );
     1046                        } // if
     1047                        TypedefDecl * tyDecl = new TypedefDecl( aggDecl->get_name(), DeclarationNode::NoStorageClass, type );
     1048                        typedefNames[ aggDecl->get_name() ] = std::make_pair( tyDecl, scopeLevel );
     1049                } // if
     1050        }
    10621051        Declaration *EliminateTypedef::mutate( StructDecl * structDecl ) {
     1052                addImplicitTypedef( structDecl );
    10631053                Mutator::mutate( structDecl );
    10641054                return handleAggregate( structDecl );
     
    10661056
    10671057        Declaration *EliminateTypedef::mutate( UnionDecl * unionDecl ) {
     1058                addImplicitTypedef( unionDecl );
    10681059                Mutator::mutate( unionDecl );
    10691060                return handleAggregate( unionDecl );
     
    10711062
    10721063        Declaration *EliminateTypedef::mutate( EnumDecl * enumDecl ) {
     1064                addImplicitTypedef( enumDecl );
    10731065                Mutator::mutate( enumDecl );
    10741066                return handleAggregate( enumDecl );
    10751067        }
    10761068
    1077                 Declaration *EliminateTypedef::mutate( TraitDecl * contextDecl ) {
     1069        Declaration *EliminateTypedef::mutate( TraitDecl * contextDecl ) {
    10781070                Mutator::mutate( contextDecl );
    10791071                return handleAggregate( contextDecl );
    10801072        }
    10811073
     1074        DeclarationWithType * CompoundLiteral::mutate( ObjectDecl *objectDecl ) {
     1075                storageclass = objectDecl->get_storageClass();
     1076                DeclarationWithType * temp = Mutator::mutate( objectDecl );
     1077                storageclass = DeclarationNode::NoStorageClass;
     1078                return temp;
     1079        }
     1080
     1081        Expression *CompoundLiteral::mutate( CompoundLiteralExpr *compLitExpr ) {
     1082                // transform [storage_class] ... (struct S){ 3, ... };
     1083                // into [storage_class] struct S temp =  { 3, ... };
     1084                static UniqueName indexName( "_compLit" );
     1085
     1086                ObjectDecl *tempvar = new ObjectDecl( indexName.newName(), storageclass, LinkageSpec::C, 0, compLitExpr->get_type(), compLitExpr->get_initializer() );
     1087                compLitExpr->set_type( 0 );
     1088                compLitExpr->set_initializer( 0 );
     1089                delete compLitExpr;
     1090                DeclarationWithType * newtempvar = mutate( tempvar );
     1091                addDeclaration( newtempvar );                                   // add modified temporary to current block
     1092                return new VariableExpr( newtempvar );
     1093        }
    10821094} // namespace SymTab
    10831095
Note: See TracChangeset for help on using the changeset viewer.