Changeset fe26fbf for src/SymTab


Ignore:
Timestamp:
Feb 7, 2017, 1:01:34 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:
35b1bf4
Parents:
dbe8f244 (diff), b4d65c7 (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' of plg.uwaterloo.ca:/u/cforall/software/cfa/cfa-cc

Location:
src/SymTab
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • src/SymTab/AddVisit.h

    rdbe8f244 rfe26fbf  
    1010// Created On       : Sun May 17 16:14:32 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Thu Aug  4 11:22:01 2016
    13 // Update Count     : 9
     12// Last Modified On : Thu Feb  2 16:36:02 2017
     13// Update Count     : 14
    1414//
    1515
     
    1818
    1919        template< typename Visitor >
    20         inline void addVisitStatementList( std::list< Statement* > &statements, Visitor &visitor ) {
    21                 for ( std::list< Statement* >::iterator i = statements.begin(); i != statements.end(); ++i ) {
    22                         addDecls( visitor.get_declsToAdd(), statements, i );
    23                         (*i)->accept( visitor );
    24                 } // for
    25                 addDecls( visitor.get_declsToAdd(), statements, statements.end() );
     20        inline void addVisitStatementList( std::list< Statement* > &stmts, Visitor &visitor ) {
     21                for ( std::list< Statement* >::iterator stmt = stmts.begin(); ; ++stmt ) {
     22                        // add any new declarations after the previous statement
     23                        for ( std::list< Declaration* >::iterator decl = visitor.declsToAddAfter.begin(); decl != visitor.declsToAddAfter.end(); ++decl ) {
     24                                DeclStmt *declStmt = new DeclStmt( noLabels, *decl );
     25                                stmts.insert( stmt, declStmt );
     26                        }
     27                        visitor.declsToAddAfter.clear();
     28
     29                        if ( stmt == stmts.end() ) break;
     30                       
     31                        // run mutator on statement
     32                        maybeAccept( *stmt, visitor );
     33
     34                        // add any new declarations before the statement
     35                        for ( std::list< Declaration* >::iterator decl = visitor.declsToAdd.begin(); decl != visitor.declsToAdd.end(); ++decl ) {
     36                                DeclStmt *declStmt = new DeclStmt( noLabels, *decl );
     37                                stmts.insert( stmt, declStmt );
     38                        }
     39                        visitor.declsToAdd.clear();
     40                }
    2641        }
    2742
     
    3853
    3954        template< typename Visitor >
    40         void acceptAndAdd( std::list< Declaration * > &translationUnit, Visitor &visitor, bool addBefore ) {
    41                 std::list< Declaration * >::iterator i = translationUnit.begin();
    42                 while ( i != translationUnit.end() ) {
    43                         (*i)->accept( visitor );
    44                         std::list< Declaration * >::iterator next = i;
    45                         next++;
    46                         if ( ! visitor.get_declsToAdd().empty() ) {
    47                                 translationUnit.splice( addBefore ? i : next, visitor.get_declsToAdd() );
    48                         } // if
    49                         i = next;
    50                 } // while
     55        void acceptAndAdd( std::list< Declaration * > &translationUnit, Visitor &visitor ) {
     56                for ( std::list< Declaration* >::iterator decl = translationUnit.begin(); ; ++decl ) {
     57                        // splice in new declarations after previous decl
     58                        translationUnit.splice( decl, visitor.declsToAddAfter );
     59
     60                        if ( decl == translationUnit.end() ) break;
     61                       
     62                        // run mutator on declaration
     63                        maybeAccept( *decl, visitor );
     64
     65                        // splice in new declarations before current decl
     66                        translationUnit.splice( decl, visitor.declsToAdd );
     67                }
    5168        }
    5269
  • src/SymTab/Autogen.cc

    rdbe8f244 rfe26fbf  
    1010// Created On       : Thu Mar 03 15:45:56 2016
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Tue Jul 12 17:47:17 2016
    13 // Update Count     : 2
     12// Last Modified On : Thu Feb  2 18:04:40 2017
     13// Update Count     : 11
    1414//
    1515
     
    4343
    4444        class AutogenerateRoutines final : public Visitor {
     45            template< typename Visitor >
     46            friend void acceptAndAdd( std::list< Declaration * > &translationUnit, Visitor &visitor );
     47            template< typename Visitor >
     48            friend void addVisitStatementList( std::list< Statement* > &stmts, Visitor &visitor );
    4549          public:
    4650                std::list< Declaration * > &get_declsToAdd() { return declsToAdd; }
     
    6771                template< typename StmtClass > void visitStatement( StmtClass *stmt );
    6872
    69                 std::list< Declaration * > declsToAdd;
     73                std::list< Declaration * > declsToAdd, declsToAddAfter;
    7074                std::set< std::string > structsDone;
    7175                unsigned int functionNesting = 0;     // current level of nested functions
     
    98102        void autogenerateRoutines( std::list< Declaration * > &translationUnit ) {
    99103                AutogenerateRoutines generator;
    100                 acceptAndAdd( translationUnit, generator, false );
     104                acceptAndAdd( translationUnit, generator );
    101105
    102106                // needs to be done separately because AutogenerateRoutines skips types that appear as function arguments, etc.
     
    567571                        EnumInstType *enumInst = new EnumInstType( Type::Qualifiers(), enumDecl->get_name() );
    568572                        // enumInst->set_baseEnum( enumDecl );
    569                         // declsToAdd.push_back(
    570                         makeEnumFunctions( enumDecl, enumInst, functionNesting, declsToAdd );
     573                        makeEnumFunctions( enumDecl, enumInst, functionNesting, declsToAddAfter );
    571574                }
    572575        }
     
    581584                        }
    582585                        structInst.set_baseStruct( structDecl );
    583                         makeStructFunctions( structDecl, &structInst, functionNesting, declsToAdd, data );
     586                        makeStructFunctions( structDecl, &structInst, functionNesting, declsToAddAfter, data );
    584587                        structsDone.insert( structDecl->get_name() );
    585588                } // if
     
    593596                                unionInst.get_parameters().push_back( new TypeExpr( new TypeInstType( Type::Qualifiers(), typeDecl->get_name(), typeDecl ) ) );
    594597                        }
    595                         makeUnionFunctions( unionDecl, &unionInst, functionNesting, declsToAdd );
     598                        makeUnionFunctions( unionDecl, &unionInst, functionNesting, declsToAddAfter );
    596599                } // if
    597600        }
     
    618621                FunctionDecl *func = genFunc( "?=?", type, functionNesting );
    619622                func->get_statements()->get_kids() = stmts;
    620                 declsToAdd.push_back( func );
     623                declsToAddAfter.push_back( func );
    621624        }
    622625
     
    763766        }
    764767} // SymTab
     768
     769// Local Variables: //
     770// tab-width: 4 //
     771// mode: c++ //
     772// compile-command: "make install" //
     773// End: //
  • src/SymTab/Autogen.h

    rdbe8f244 rfe26fbf  
    99// Author           : Rob Schluntz
    1010// Created On       : Sun May 17 21:53:34 2015
    11 // Last Modified By : Rob Schluntz
    12 // Last Modified On : Tue May 19 16:49:43 2015
    13 // Update Count     : 1
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Wed Feb  1 16:31:00 2017
     13// Update Count     : 2
    1414//
    1515
     
    5858                        assert( type );
    5959                        Type * castType = type->clone();
    60                         castType->get_qualifiers() -= Type::Qualifiers(true, true, true, false, true, true);
     60                        castType->get_qualifiers() -= Type::Qualifiers(true, true, true, false, true);
    6161                        castType->set_isLvalue( true ); // xxx - might not need this
    6262                        dstParam = new CastExpr( dstParam, new PointerType( Type::Qualifiers(), castType ) );
  • src/SymTab/Validate.cc

    rdbe8f244 rfe26fbf  
    1010// Created On       : Sun May 17 21:50:04 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Tue Jul 12 17:49:21 2016
    13 // Update Count     : 298
     12// Last Modified On : Thu Feb  2 17:47:54 2017
     13// Update Count     : 312
    1414//
    1515
     
    6767namespace SymTab {
    6868        class HoistStruct final : public Visitor {
     69                template< typename Visitor >
     70                friend void acceptAndAdd( std::list< Declaration * > &translationUnit, Visitor &visitor );
     71            template< typename Visitor >
     72            friend void addVisitStatementList( std::list< Statement* > &stmts, Visitor &visitor );
    6973          public:
    7074                /// Flattens nested struct types
     
    7377                std::list< Declaration * > &get_declsToAdd() { return declsToAdd; }
    7478
     79                virtual void visit( EnumInstType *enumInstType );
     80                virtual void visit( StructInstType *structInstType );
     81                virtual void visit( UnionInstType *unionInstType );
    7582                virtual void visit( StructDecl *aggregateDecl );
    7683                virtual void visit( UnionDecl *aggregateDecl );
     
    8390                template< typename AggDecl > void handleAggregate( AggDecl *aggregateDecl );
    8491
    85                 std::list< Declaration * > declsToAdd;
     92                std::list< Declaration * > declsToAdd, declsToAddAfter;
    8693                bool inStruct;
    8794        };
     
    115122          private:
    116123                using Parent::visit;
     124                void visit( EnumInstType *enumInst ) final;
    117125                void visit( StructInstType *structInst ) final;
    118126                void visit( UnionInstType *unionInst ) final;
    119127                void visit( TraitInstType *contextInst ) final;
     128                void visit( EnumDecl *enumDecl ) final;
    120129                void visit( StructDecl *structDecl ) final;
    121130                void visit( UnionDecl *unionDecl ) final;
     
    124133                const Indexer *indexer;
    125134
     135                typedef std::map< std::string, std::list< EnumInstType * > > ForwardEnumsType;
    126136                typedef std::map< std::string, std::list< StructInstType * > > ForwardStructsType;
    127137                typedef std::map< std::string, std::list< UnionInstType * > > ForwardUnionsType;
     138                ForwardEnumsType forwardEnums;
    128139                ForwardStructsType forwardStructs;
    129140                ForwardUnionsType forwardUnions;
     
    236247        void HoistStruct::hoistStruct( std::list< Declaration * > &translationUnit ) {
    237248                HoistStruct hoister;
    238                 acceptAndAdd( translationUnit, hoister, true );
     249                acceptAndAdd( translationUnit, hoister );
    239250        }
    240251
     
    260271                return dynamic_cast< StructDecl * >( decl ) || dynamic_cast< UnionDecl * >( decl );
    261272        }
    262         // xxx - shouldn't this be declsToAddBefore?
     273
    263274        template< typename AggDecl >
    264275        void HoistStruct::handleAggregate( AggDecl *aggregateDecl ) {
     
    276287        }
    277288
     289        void HoistStruct::visit( EnumInstType *structInstType ) {
     290                if ( structInstType->get_baseEnum() ) {
     291                        declsToAdd.push_front( structInstType->get_baseEnum() );
     292                }
     293        }
     294
     295        void HoistStruct::visit( StructInstType *structInstType ) {
     296                if ( structInstType->get_baseStruct() ) {
     297                        declsToAdd.push_front( structInstType->get_baseStruct() );
     298                }
     299        }
     300
     301        void HoistStruct::visit( UnionInstType *structInstType ) {
     302                if ( structInstType->get_baseUnion() ) {
     303                        declsToAdd.push_front( structInstType->get_baseUnion() );
     304                }
     305        }
     306
    278307        void HoistStruct::visit( StructDecl *aggregateDecl ) {
    279308                handleAggregate( aggregateDecl );
     
    297326                        ObjectDecl * obj = dynamic_cast< ObjectDecl * >( *i );
    298327                        assert( obj );
    299                         obj->set_type( new EnumInstType( Type::Qualifiers( true, false, false, false, false, false ), enumDecl->get_name() ) );
     328                        obj->set_type( new EnumInstType( Type::Qualifiers( true, false, false, false, false ), enumDecl->get_name() ) );
    300329                } // for
    301330                Parent::visit( enumDecl );
     
    349378        }
    350379
     380        void LinkReferenceToTypes::visit( EnumInstType *enumInst ) {
     381                Parent::visit( enumInst );
     382                EnumDecl *st = indexer->lookupEnum( enumInst->get_name() );
     383                // it's not a semantic error if the enum is not found, just an implicit forward declaration
     384                if ( st ) {
     385                        //assert( ! enumInst->get_baseEnum() || enumInst->get_baseEnum()->get_members().empty() || ! st->get_members().empty() );
     386                        enumInst->set_baseEnum( st );
     387                } // if
     388                if ( ! st || st->get_members().empty() ) {
     389                        // use of forward declaration
     390                        forwardEnums[ enumInst->get_name() ].push_back( enumInst );
     391                } // if
     392        }
     393
    351394        void LinkReferenceToTypes::visit( StructInstType *structInst ) {
    352395                Parent::visit( structInst );
     
    419462                        }
    420463                }
     464        }
     465
     466        void LinkReferenceToTypes::visit( EnumDecl *enumDecl ) {
     467                // visit enum members first so that the types of self-referencing members are updated properly
     468                Parent::visit( enumDecl );
     469                if ( ! enumDecl->get_members().empty() ) {
     470                        ForwardEnumsType::iterator fwds = forwardEnums.find( enumDecl->get_name() );
     471                        if ( fwds != forwardEnums.end() ) {
     472                                for ( std::list< EnumInstType * >::iterator inst = fwds->second.begin(); inst != fwds->second.end(); ++inst ) {
     473                                        (*inst )->set_baseEnum( enumDecl );
     474                                } // for
     475                                forwardEnums.erase( fwds );
     476                        } // if
     477                } // if
    421478        }
    422479
Note: See TracChangeset for help on using the changeset viewer.