Changeset 353d168 for src/SymTab


Ignore:
Timestamp:
Aug 19, 2015, 3:59:45 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:
830c21a
Parents:
18997b9 (diff), 4aa0858 (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 'override-autogen' into ctor

Conflicts:

src/Parser/ParseNode.h

Location:
src/SymTab
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • src/SymTab/IdTable.cc

    r18997b9 r353d168  
    99// Author           : Richard C. Bilson
    1010// Created On       : Sun May 17 17:04:02 2015
    11 // Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sun May 17 17:07:43 2015
    13 // Update Count     : 3
     11// Last Modified By : Rob Schluntz
     12// Last Modified On : Wed Aug 19 15:47:58 2015
     13// Update Count     : 38
    1414//
    1515
     
    5252                if ( decl->get_linkage() == LinkageSpec::C ) {
    5353                        manglename = name;
     54                } else if ( LinkageSpec::isOverridable( decl->get_linkage() ) ) {
     55                        // mangle the name without including the appropriate suffix
     56                        // this will make it so that overridable routines are placed
     57                        // into the same "bucket" as their user defined versions.
     58                        manglename = Mangler::mangle( decl, false );
    5459                } else {
    5560                        manglename = Mangler::mangle( decl );
     
    6469                        std::stack< DeclEntry >& entry = it->second;
    6570                        if ( ! entry.empty() && entry.top().second == scopeLevel ) {
     71                                // typesCompatible doesn't really do the right thing here. When checking compatibility of function types,
     72                                // we should ignore outermost pointer qualifiers, except _Atomic?
     73
    6674                                if ( decl->get_linkage() != LinkageSpec::C || ResolvExpr::typesCompatible( decl->get_type(), entry.top().first->get_type(), Indexer() ) ) {
    6775                                        FunctionDecl *newentry = dynamic_cast< FunctionDecl* >( decl );
    6876                                        FunctionDecl *old = dynamic_cast< FunctionDecl* >( entry.top().first );
    69                                         if ( newentry && old && newentry->get_statements() && old->get_statements() ) {
    70                                                 throw SemanticError( "duplicate function definition for ", decl );
     77                                        if ( LinkageSpec::isOverridable( old->get_linkage() ) ) {
     78                                                // new definition shadows the autogenerated one, even at the same scope
     79                                                declTable[ manglename ].push( DeclEntry( decl, scopeLevel ) );
     80                                        } else if ( newentry && old && newentry->get_statements() && old->get_statements() ) {
     81                                                throw SemanticError( "duplicate function definition for 1 ", decl );
    7182                                        } else {
     83                                                // two objects with the same mangled name defined in the same scope.
     84                                                // both objects must be marked extern for this to be okay
    7285                                                ObjectDecl *newobj = dynamic_cast< ObjectDecl* >( decl );
    7386                                                ObjectDecl *oldobj = dynamic_cast< ObjectDecl* >( entry.top().first );
    74                                                 if ( newobj && oldobj && newobj->get_init() && oldobj->get_init() ) {
     87                                                if ( newobj && oldobj && newobj->get_storageClass() != DeclarationNode::Extern && oldobj->get_storageClass() != DeclarationNode::Extern ) {
    7588                                                        throw SemanticError( "duplicate definition for ", decl );
    7689                                                } // if
    7790                                        } // if
    7891                                } else {
    79                                         throw SemanticError( "duplicate definition for ", decl );
     92                                        // C definitions with the same name but incompatible types
     93                                        throw SemanticError( "duplicate definition for 2 ", decl );
    8094                                } // if
    8195                        } else {
     
    8498                } // if
    8599                // ensure the set of routines with C linkage cannot be overloaded
     100                // this ensures that no two declarations with the same unmangled name both have C linkage
    86101                for ( InnerTableType::iterator i = declTable.begin(); i != declTable.end(); ++i ) {
    87102                        if ( ! i->second.empty() && i->second.top().first->get_linkage() == LinkageSpec::C && declTable.size() > 1 ) {
  • src/SymTab/Indexer.cc

    r18997b9 r353d168  
    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 : Fri Jun  5 08:05:17 2015
    13 // Update Count     : 5
     11// Last Modified By : Rob Schluntz
     12// Last Modified On : Wed Aug 05 13:52:42 2015
     13// Update Count     : 10
    1414//
    1515
     
    2626
    2727namespace SymTab {
     28        template< typename Container, typename VisitorType >
     29        inline void acceptAllNewScope( Container &container, VisitorType &visitor ) {
     30                visitor.enterScope();
     31                acceptAll( container, visitor );
     32                visitor.leaveScope();
     33        }
     34
    2835        Indexer::Indexer( bool useDebug ) : doDebug( useDebug ) {}
    2936
     
    3138
    3239        void Indexer::visit( ObjectDecl *objectDecl ) {
     40                enterScope();
    3341                maybeAccept( objectDecl->get_type(), *this );
     42                leaveScope();
    3443                maybeAccept( objectDecl->get_init(), *this );
    3544                maybeAccept( objectDecl->get_bitfieldWidth(), *this );
     
    149158                leaveScope();
    150159        }
     160
     161
     162        void Indexer::visit( ApplicationExpr *applicationExpr ) {
     163                acceptAllNewScope( applicationExpr->get_results(), *this );
     164                maybeAccept( applicationExpr->get_function(), *this );
     165                acceptAll( applicationExpr->get_args(), *this );
     166        }
     167
     168        void Indexer::visit( UntypedExpr *untypedExpr ) {
     169                acceptAllNewScope( untypedExpr->get_results(), *this );
     170                acceptAll( untypedExpr->get_args(), *this );
     171        }
     172
     173        void Indexer::visit( NameExpr *nameExpr ) {
     174                acceptAllNewScope( nameExpr->get_results(), *this );
     175        }
     176
     177        void Indexer::visit( AddressExpr *addressExpr ) {
     178                acceptAllNewScope( addressExpr->get_results(), *this );
     179                maybeAccept( addressExpr->get_arg(), *this );
     180        }
     181
     182        void Indexer::visit( LabelAddressExpr *labAddressExpr ) {
     183                acceptAllNewScope( labAddressExpr->get_results(), *this );
     184                maybeAccept( labAddressExpr->get_arg(), *this );
     185        }
     186
     187        void Indexer::visit( CastExpr *castExpr ) {
     188                acceptAllNewScope( castExpr->get_results(), *this );
     189                maybeAccept( castExpr->get_arg(), *this );
     190        }
     191
     192        void Indexer::visit( UntypedMemberExpr *memberExpr ) {
     193                acceptAllNewScope( memberExpr->get_results(), *this );
     194                maybeAccept( memberExpr->get_aggregate(), *this );
     195        }
     196
     197        void Indexer::visit( MemberExpr *memberExpr ) {
     198                acceptAllNewScope( memberExpr->get_results(), *this );
     199                maybeAccept( memberExpr->get_aggregate(), *this );
     200        }
     201
     202        void Indexer::visit( VariableExpr *variableExpr ) {
     203                acceptAllNewScope( variableExpr->get_results(), *this );
     204        }
     205
     206        void Indexer::visit( ConstantExpr *constantExpr ) {
     207                acceptAllNewScope( constantExpr->get_results(), *this );
     208                maybeAccept( constantExpr->get_constant(), *this );
     209        }
     210
     211        void Indexer::visit( SizeofExpr *sizeofExpr ) {
     212                acceptAllNewScope( sizeofExpr->get_results(), *this );
     213                if ( sizeofExpr->get_isType() ) {
     214                        maybeAccept( sizeofExpr->get_type(), *this );
     215                } else {
     216                        maybeAccept( sizeofExpr->get_expr(), *this );
     217                }
     218        }
     219
     220        void Indexer::visit( AttrExpr *attrExpr ) {
     221                acceptAllNewScope( attrExpr->get_results(), *this );
     222                if ( attrExpr->get_isType() ) {
     223                        maybeAccept( attrExpr->get_type(), *this );
     224                } else {
     225                        maybeAccept( attrExpr->get_expr(), *this );
     226                }
     227        }
     228
     229        void Indexer::visit( LogicalExpr *logicalExpr ) {
     230                acceptAllNewScope( logicalExpr->get_results(), *this );
     231                maybeAccept( logicalExpr->get_arg1(), *this );
     232                maybeAccept( logicalExpr->get_arg2(), *this );
     233        }
     234
     235        void Indexer::visit( ConditionalExpr *conditionalExpr ) {
     236                acceptAllNewScope( conditionalExpr->get_results(), *this );
     237                maybeAccept( conditionalExpr->get_arg1(), *this );
     238                maybeAccept( conditionalExpr->get_arg2(), *this );
     239                maybeAccept( conditionalExpr->get_arg3(), *this );
     240        }
     241
     242        void Indexer::visit( CommaExpr *commaExpr ) {
     243                acceptAllNewScope( commaExpr->get_results(), *this );
     244                maybeAccept( commaExpr->get_arg1(), *this );
     245                maybeAccept( commaExpr->get_arg2(), *this );
     246        }
     247
     248        void Indexer::visit( TupleExpr *tupleExpr ) {
     249                acceptAllNewScope( tupleExpr->get_results(), *this );
     250                acceptAll( tupleExpr->get_exprs(), *this );
     251        }
     252
     253        void Indexer::visit( SolvedTupleExpr *tupleExpr ) {
     254                acceptAllNewScope( tupleExpr->get_results(), *this );
     255                acceptAll( tupleExpr->get_exprs(), *this );
     256        }
     257
     258        void Indexer::visit( TypeExpr *typeExpr ) {
     259                acceptAllNewScope( typeExpr->get_results(), *this );
     260                maybeAccept( typeExpr->get_type(), *this );
     261        }
     262
     263        void Indexer::visit( AsmExpr *asmExpr ) {
     264                maybeAccept( asmExpr->get_inout(), *this );
     265                maybeAccept( asmExpr->get_constraint(), *this );
     266                maybeAccept( asmExpr->get_operand(), *this );
     267        }
     268
     269        void Indexer::visit( UntypedValofExpr *valofExpr ) {
     270                acceptAllNewScope( valofExpr->get_results(), *this );
     271                maybeAccept( valofExpr->get_body(), *this );
     272        }
     273
    151274
    152275        void Indexer::visit( ContextInstType *contextInst ) {
  • src/SymTab/Indexer.h

    r18997b9 r353d168  
    99// Author           : Richard C. Bilson
    1010// Created On       : Sun May 17 21:38:55 2015
    11 // Last Modified By : Peter A. Buhr
    12 // Last Modified On : Tue May 19 16:51:21 2015
    13 // Update Count     : 3
     11// Last Modified By : Rob Schluntz
     12// Last Modified On : Wed Aug 05 13:51:39 2015
     13// Update Count     : 4
    1414//
    1515
     
    4343
    4444                virtual void visit( CompoundStmt *compoundStmt );
     45
     46                virtual void visit( ApplicationExpr *applicationExpr );
     47                virtual void visit( UntypedExpr *untypedExpr );
     48                virtual void visit( NameExpr *nameExpr );
     49                virtual void visit( CastExpr *castExpr );
     50                virtual void visit( AddressExpr *addressExpr );
     51                virtual void visit( LabelAddressExpr *labAddressExpr );
     52                virtual void visit( UntypedMemberExpr *memberExpr );
     53                virtual void visit( MemberExpr *memberExpr );
     54                virtual void visit( VariableExpr *variableExpr );
     55                virtual void visit( ConstantExpr *constantExpr );
     56                virtual void visit( SizeofExpr *sizeofExpr );
     57                virtual void visit( AttrExpr *attrExpr );
     58                virtual void visit( LogicalExpr *logicalExpr );
     59                virtual void visit( ConditionalExpr *conditionalExpr );
     60                virtual void visit( CommaExpr *commaExpr );
     61                virtual void visit( TupleExpr *tupleExpr );
     62                virtual void visit( SolvedTupleExpr *tupleExpr );
     63                virtual void visit( TypeExpr *typeExpr );
     64                virtual void visit( AsmExpr *asmExpr );
     65                virtual void visit( UntypedValofExpr *valofExpr );
    4566
    4667                virtual void visit( ContextInstType *contextInst );
  • src/SymTab/Mangler.cc

    r18997b9 r353d168  
    99// Author           : Richard C. Bilson
    1010// Created On       : Sun May 17 21:40:29 2015
    11 // Last Modified By : Peter A. Buhr
    12 // Last Modified On : Mon Jun  8 15:12:12 2015
    13 // Update Count     : 8
     11// Last Modified By : Rob Schluntz
     12// Last Modified On : Wed Aug 19 15:52:24 2015
     13// Update Count     : 19
    1414//
    1515
     
    3030
    3131namespace SymTab {
    32         Mangler::Mangler() : nextVarNum( 0 ), isTopLevel( true ) {
     32        Mangler::Mangler( bool mangleOverridable ) : nextVarNum( 0 ), isTopLevel( true ), mangleOverridable( mangleOverridable ) {
    3333        }
    3434
     
    4141                nextVarNum = rhs.nextVarNum;
    4242                isTopLevel = rhs.isTopLevel;
     43                mangleOverridable = rhs.mangleOverridable;
    4344        }
    4445
     
    5960                mangleName << "__";
    6061                maybeAccept( declaration->get_type(), *this );
     62                if ( mangleOverridable && LinkageSpec::isOverridable( declaration->get_linkage() ) ) {
     63                        // want to be able to override autogenerated and intrinsic routines,
     64                        // so they need a different name mangling
     65                        if ( declaration->get_linkage() == LinkageSpec::AutoGen ) {
     66                                mangleName << "autogen__";
     67                        } else if ( declaration->get_linkage() == LinkageSpec::Intrinsic ) {
     68                                mangleName << "intrinsic__";
     69                        } else {
     70                                // if we add another kind of overridable function, this has to change
     71                                assert( false );
     72                        } // if
     73                }
    6174                isTopLevel = wasTopLevel;
    6275        }
     
    214227                                varNums[ (*i )->get_name() ] = std::pair< int, int >( nextVarNum++, (int )(*i )->get_kind() );
    215228                                for ( std::list< DeclarationWithType* >::iterator assert = (*i )->get_assertions().begin(); assert != (*i )->get_assertions().end(); ++assert ) {
    216                                         Mangler sub_mangler;
     229                                        Mangler sub_mangler( mangleOverridable );
    217230                                        sub_mangler.nextVarNum = nextVarNum;
    218231                                        sub_mangler.isTopLevel = false;
  • src/SymTab/Mangler.h

    r18997b9 r353d168  
    99// Author           : Richard C. Bilson
    1010// Created On       : Sun May 17 21:44:03 2015
    11 // Last Modified By : Peter A. Buhr
    12 // Last Modified On : Mon Jun  8 14:47:14 2015
    13 // Update Count     : 5
     11// Last Modified By : Rob Schluntz
     12// Last Modified On : Wed Aug 19 15:48:46 2015
     13// Update Count     : 14
    1414//
    1515
     
    2525          public:
    2626                template< typename SynTreeClass >
    27             static std::string mangle( SynTreeClass *decl ); // interface to clients
     27            static std::string mangle( SynTreeClass *decl, bool mangleOverridable = true ); // interface to clients
    2828
    2929///   using Visitor::visit;
     
    5050                int nextVarNum;
    5151                bool isTopLevel;
     52                bool mangleOverridable;
    5253 
    53                 Mangler();
     54                Mangler( bool mangleOverridable );
    5455                Mangler( const Mangler & );
    5556 
     
    6162
    6263        template< typename SynTreeClass >
    63         std::string Mangler::mangle( SynTreeClass *decl ) {
    64                 Mangler mangler;
     64        std::string Mangler::mangle( SynTreeClass *decl, bool mangleOverridable ) {
     65                Mangler mangler( mangleOverridable );
    6566                maybeAccept( decl, mangler );
    6667                return mangler.get_mangleName();
  • src/SymTab/Validate.cc

    r18997b9 r353d168  
    1010// Created On       : Sun May 17 21:50:04 2015
    1111// Last Modified By : Rob Schluntz
    12 // Last Modified On : Wed Jul 22 13:16:00 2015
    13 // Update Count     : 194
     12// Last Modified On : Wed Aug 05 14:00:24 2015
     13// Update Count     : 195
    1414//
    1515
     
    162162        class EliminateTypedef : public Mutator {
    163163          public:
    164                 EliminateTypedef() : scopeLevel( 0 ) {}
     164          EliminateTypedef() : scopeLevel( 0 ) {}
     165            /// Replaces typedefs by forward declarations
    165166                static void eliminateTypedef( std::list< Declaration * > &translationUnit );
    166167          private:
     
    542543                std::list<Statement *> initList;
    543544                initList.push_back( initStmt );
    544 
     545 
    545546                UntypedExpr *cond = new UntypedExpr( new NameExpr( "?<?" ) );
    546547                cond->get_args().push_back( new VariableExpr( index ) );
     
    617618
    618619                // need to remove the prototypes, since this may be nested in a routine
    619                 for ( int start = 0, end = assigns.size() / 2; start < end; start++ ) {
     620                for (int start = 0, end = assigns.size()/2; start < end; start++) {
    620621                        delete assigns.front();
    621622                        assigns.pop_front();
     
    892893                TypedefMap oldNames = typedefNames;
    893894                DeclarationWithType *ret = Mutator::mutate( objDecl );
     895                typedefNames = oldNames;
    894896                if ( FunctionType *funtype = dynamic_cast<FunctionType *>( ret->get_type() ) ) {
    895897                        return new FunctionDecl( ret->get_name(), ret->get_storageClass(), ret->get_linkage(), funtype, 0, ret->get_isInline(), ret->get_isNoreturn() );
     
    897899                        throw SemanticError( "invalid inline or _Noreturn specification in declaration of ", objDecl );
    898900                } // if
    899                 typedefNames = oldNames;
    900901                return ret;
    901902        }
     
    960961        }
    961962
    962         Declaration *EliminateTypedef::mutate( ContextDecl * contextDecl ) {
     963                Declaration *EliminateTypedef::mutate( ContextDecl * contextDecl ) {
    963964                Mutator::mutate( contextDecl );
    964965                return handleAggregate( contextDecl );
Note: See TracChangeset for help on using the changeset viewer.