Changeset 7e23d0a for src/SymTab


Ignore:
Timestamp:
Nov 25, 2015, 2:53:26 PM (10 years ago)
Author:
Aaron Moss <a3moss@…>
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, string, with_gc
Children:
32d281d, 704c9dd
Parents:
02ec390 (diff), 5189888 (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:software/cfa/cfa-cc

Location:
src/SymTab
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • src/SymTab/IdTable.cc

    r02ec390 r7e23d0a  
    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 Oct 07 12:21:13 2015
     13// Update Count     : 73
    1414//
    1515
     
    3737                        for ( InnerTableType::iterator inner = outer->second.begin(); inner != outer->second.end(); ++inner ) {
    3838                                std::stack< DeclEntry >& entry = inner->second;
     39                                // xxx - should be while?
    3940                                if ( ! entry.empty() && entry.top().second == scopeLevel ) {
    4041                                        entry.pop();
     
    5253                if ( decl->get_linkage() == LinkageSpec::C ) {
    5354                        manglename = name;
     55                } else if ( LinkageSpec::isOverridable( decl->get_linkage() ) ) {
     56                        // mangle the name without including the appropriate suffix
     57                        // this will make it so that overridable routines are placed
     58                        // into the same "bucket" as their user defined versions.
     59                        manglename = Mangler::mangle( decl, false );
    5460                } else {
    5561                        manglename = Mangler::mangle( decl );
     
    6066
    6167                if ( it == declTable.end() ) {
     68                        // first time this name mangling has been defined
    6269                        declTable[ manglename ].push( DeclEntry( decl, scopeLevel ) );
    6370                } else {
    6471                        std::stack< DeclEntry >& entry = it->second;
    6572                        if ( ! entry.empty() && entry.top().second == scopeLevel ) {
    66                                 if ( decl->get_linkage() != LinkageSpec::C || ResolvExpr::typesCompatible( decl->get_type(), entry.top().first->get_type(), Indexer() ) ) {
     73                                // if we're giving the same name mangling to things of
     74                                //  different types then there is something wrong
     75                                Declaration *old = entry.top().first;
     76                                assert( (dynamic_cast<ObjectDecl*>( decl ) && dynamic_cast<ObjectDecl*>( old ) )
     77                                  || (dynamic_cast<FunctionDecl*>( decl ) && dynamic_cast<FunctionDecl*>( old ) ) );
     78
     79                                if ( LinkageSpec::isOverridable( old->get_linkage() ) ) {
     80                                        // new definition shadows the autogenerated one, even at the same scope
     81                                        declTable[ manglename ].push( DeclEntry( decl, scopeLevel ) );
     82                                } else if ( decl->get_linkage() != LinkageSpec::C || ResolvExpr::typesCompatible( decl->get_type(), entry.top().first->get_type(), Indexer() ) ) {
     83                                        // typesCompatible doesn't really do the right thing here. When checking compatibility of function types,
     84                                        // we should ignore outermost pointer qualifiers, except _Atomic?
    6785                                        FunctionDecl *newentry = dynamic_cast< FunctionDecl* >( decl );
    68                                         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 );
     86                                        FunctionDecl *oldentry = dynamic_cast< FunctionDecl* >( old );
     87                                        if ( newentry && oldentry ) {
     88                                                if ( newentry->get_statements() && oldentry->get_statements() ) {
     89                                                        throw SemanticError( "duplicate function definition for 1 ", decl );
     90                                                } // if
    7191                                        } else {
     92                                                // two objects with the same mangled name defined in the same scope.
     93                                                // both objects must be marked extern or both must be intrinsic for this to be okay
     94                                                // xxx - perhaps it's actually if either is intrinsic then this is okay?
     95                                                //       might also need to be same storage class?
    7296                                                ObjectDecl *newobj = dynamic_cast< ObjectDecl* >( decl );
    73                                                 ObjectDecl *oldobj = dynamic_cast< ObjectDecl* >( entry.top().first );
    74                                                 if ( newobj && oldobj && newobj->get_init() && oldobj->get_init() ) {
    75                                                         throw SemanticError( "duplicate definition for ", decl );
     97                                                ObjectDecl *oldobj = dynamic_cast< ObjectDecl* >( old );
     98                                                if (newobj->get_storageClass() != DeclarationNode::Extern && oldobj->get_storageClass() != DeclarationNode::Extern ) {
     99                                                        throw SemanticError( "duplicate definition for 3 ", decl );
    76100                                                } // if
    77101                                        } // if
     
    80104                                } // if
    81105                        } else {
     106                                // new scope level - shadow existing definition
    82107                                declTable[ manglename ].push( DeclEntry( decl, scopeLevel ) );
    83108                        } // if
    84109                } // if
    85                 // ensure the set of routines with C linkage cannot be overloaded
     110                // this ensures that no two declarations with the same unmangled name both have C linkage
    86111                for ( InnerTableType::iterator i = declTable.begin(); i != declTable.end(); ++i ) {
    87112                        if ( ! i->second.empty() && i->second.top().first->get_linkage() == LinkageSpec::C && declTable.size() > 1 ) {
  • src/SymTab/Mangler.cc

    r02ec390 r7e23d0a  
    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

    r02ec390 r7e23d0a  
    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

    r02ec390 r7e23d0a  
    99// Author           : Richard C. Bilson
    1010// Created On       : Sun May 17 21:50:04 2015
    11 // Last Modified By : Peter A. Buhr
    12 // Last Modified On : Tue Aug 11 16:59:35 2015
    13 // Update Count     : 196
     11// Last Modified By : Rob Schluntz
     12// Last Modified On : Fri Nov 20 16:33:52 2015
     13// Update Count     : 201
    1414//
    1515
     
    5454#include "MakeLibCfa.h"
    5555#include "TypeEquality.h"
     56#include "ResolvExpr/typeops.h"
    5657
    5758#define debugPrint( x ) if ( doDebug ) { std::cout << x; }
     
    125126        };
    126127
    127         class AddStructAssignment : public Visitor {
     128        class AutogenerateRoutines : public Visitor {
    128129          public:
    129130                /// Generates assignment operators for aggregate types as required
    130                 static void addStructAssignment( std::list< Declaration * > &translationUnit );
     131                static void autogenerateRoutines( std::list< Declaration * > &translationUnit );
    131132
    132133                std::list< Declaration * > &get_declsToAdd() { return declsToAdd; }
     
    151152                virtual void visit( CatchStmt *catchStmt );
    152153
    153                 AddStructAssignment() : functionNesting( 0 ) {}
     154                AutogenerateRoutines() : functionNesting( 0 ) {}
    154155          private:
    155156                template< typename StmtClass > void visitStatement( StmtClass *stmt );
     
    195196                acceptAll( translationUnit, pass1 );
    196197                acceptAll( translationUnit, pass2 );
    197                 // need to collect all of the assignment operators prior to
    198                 // this point and only generate assignment operators if one doesn't exist
    199                 AddStructAssignment::addStructAssignment( translationUnit );
     198                AutogenerateRoutines::autogenerateRoutines( translationUnit );
    200199                acceptAll( translationUnit, pass3 );
    201200        }
     
    501500        static const std::list< std::string > noLabels;
    502501
    503         void AddStructAssignment::addStructAssignment( std::list< Declaration * > &translationUnit ) {
    504                 AddStructAssignment visitor;
     502        void AutogenerateRoutines::autogenerateRoutines( std::list< Declaration * > &translationUnit ) {
     503                AutogenerateRoutines visitor;
    505504                acceptAndAdd( translationUnit, visitor, false );
    506505        }
     
    704703        }
    705704
    706         void AddStructAssignment::visit( EnumDecl *enumDecl ) {
     705        void AutogenerateRoutines::visit( EnumDecl *enumDecl ) {
    707706                if ( ! enumDecl->get_members().empty() ) {
    708707                        EnumInstType *enumInst = new EnumInstType( Type::Qualifiers(), enumDecl->get_name() );
     
    713712        }
    714713
    715         void AddStructAssignment::visit( StructDecl *structDecl ) {
     714        void AutogenerateRoutines::visit( StructDecl *structDecl ) {
    716715                if ( ! structDecl->get_members().empty() && structsDone.find( structDecl->get_name() ) == structsDone.end() ) {
    717716                        StructInstType *structInst = new StructInstType( Type::Qualifiers(), structDecl->get_name() );
     
    722721        }
    723722
    724         void AddStructAssignment::visit( UnionDecl *unionDecl ) {
     723        void AutogenerateRoutines::visit( UnionDecl *unionDecl ) {
    725724                if ( ! unionDecl->get_members().empty() ) {
    726725                        UnionInstType *unionInst = new UnionInstType( Type::Qualifiers(), unionDecl->get_name() );
     
    730729        }
    731730
    732         void AddStructAssignment::visit( TypeDecl *typeDecl ) {
     731        void AutogenerateRoutines::visit( TypeDecl *typeDecl ) {
    733732                CompoundStmt *stmts = 0;
    734733                TypeInstType *typeInst = new TypeInstType( Type::Qualifiers(), typeDecl->get_name(), false );
     
    758757        }
    759758
    760         void AddStructAssignment::visit( FunctionType *) {
     759        void AutogenerateRoutines::visit( FunctionType *) {
    761760                // ensure that we don't add assignment ops for types defined as part of the function
    762761        }
    763762
    764         void AddStructAssignment::visit( PointerType *) {
     763        void AutogenerateRoutines::visit( PointerType *) {
    765764                // ensure that we don't add assignment ops for types defined as part of the pointer
    766765        }
    767766
    768         void AddStructAssignment::visit( ContextDecl *) {
     767        void AutogenerateRoutines::visit( ContextDecl *) {
    769768                // ensure that we don't add assignment ops for types defined as part of the context
    770769        }
    771770
    772771        template< typename StmtClass >
    773         inline void AddStructAssignment::visitStatement( StmtClass *stmt ) {
     772        inline void AutogenerateRoutines::visitStatement( StmtClass *stmt ) {
    774773                std::set< std::string > oldStructs = structsDone;
    775774                addVisit( stmt, *this );
     
    777776        }
    778777
    779         void AddStructAssignment::visit( FunctionDecl *functionDecl ) {
     778        void AutogenerateRoutines::visit( FunctionDecl *functionDecl ) {
    780779                maybeAccept( functionDecl->get_functionType(), *this );
    781780                acceptAll( functionDecl->get_oldDecls(), *this );
     
    785784        }
    786785
    787         void AddStructAssignment::visit( CompoundStmt *compoundStmt ) {
     786        void AutogenerateRoutines::visit( CompoundStmt *compoundStmt ) {
    788787                visitStatement( compoundStmt );
    789788        }
    790789
    791         void AddStructAssignment::visit( IfStmt *ifStmt ) {
     790        void AutogenerateRoutines::visit( IfStmt *ifStmt ) {
    792791                visitStatement( ifStmt );
    793792        }
    794793
    795         void AddStructAssignment::visit( WhileStmt *whileStmt ) {
     794        void AutogenerateRoutines::visit( WhileStmt *whileStmt ) {
    796795                visitStatement( whileStmt );
    797796        }
    798797
    799         void AddStructAssignment::visit( ForStmt *forStmt ) {
     798        void AutogenerateRoutines::visit( ForStmt *forStmt ) {
    800799                visitStatement( forStmt );
    801800        }
    802801
    803         void AddStructAssignment::visit( SwitchStmt *switchStmt ) {
     802        void AutogenerateRoutines::visit( SwitchStmt *switchStmt ) {
    804803                visitStatement( switchStmt );
    805804        }
    806805
    807         void AddStructAssignment::visit( ChooseStmt *switchStmt ) {
     806        void AutogenerateRoutines::visit( ChooseStmt *switchStmt ) {
    808807                visitStatement( switchStmt );
    809808        }
    810809
    811         void AddStructAssignment::visit( CaseStmt *caseStmt ) {
     810        void AutogenerateRoutines::visit( CaseStmt *caseStmt ) {
    812811                visitStatement( caseStmt );
    813812        }
    814813
    815         void AddStructAssignment::visit( CatchStmt *cathStmt ) {
     814        void AutogenerateRoutines::visit( CatchStmt *cathStmt ) {
    816815                visitStatement( cathStmt );
    817816        }
     
    857856                        Type * t1 = tyDecl->get_base();
    858857                        Type * t2 = typedefNames[ tyDecl->get_name() ].first->get_base();
    859                         if ( ! typeEquals( t1, t2, true ) ) {
     858                        if ( ! ResolvExpr::typesCompatible( t1, t2, Indexer() ) ) {
    860859                                throw SemanticError( "cannot redefine typedef: " + tyDecl->get_name() );
    861860                        }
Note: See TracChangeset for help on using the changeset viewer.