Changeset 083cf31 for src/SymTab


Ignore:
Timestamp:
Jan 7, 2016, 11:28:48 AM (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, with_gc
Children:
1e9d87b
Parents:
267cb3d (diff), de91427b (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 with master

Location:
src/SymTab
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • src/SymTab/Indexer.cc

    r267cb3d r083cf31  
    215215                } else {
    216216                        maybeAccept( sizeofExpr->get_expr(), *this );
     217                }
     218        }
     219
     220        void Indexer::visit( AlignofExpr *alignofExpr ) {
     221                acceptAllNewScope( alignofExpr->get_results(), *this );
     222                if ( alignofExpr->get_isType() ) {
     223                        maybeAccept( alignofExpr->get_type(), *this );
     224                } else {
     225                        maybeAccept( alignofExpr->get_expr(), *this );
    217226                }
    218227        }
  • src/SymTab/Indexer.h

    r267cb3d r083cf31  
    5454                virtual void visit( ConstantExpr *constantExpr );
    5555                virtual void visit( SizeofExpr *sizeofExpr );
     56                virtual void visit( AlignofExpr *alignofExpr );
    5657                virtual void visit( AttrExpr *attrExpr );
    5758                virtual void visit( LogicalExpr *logicalExpr );
  • src/SymTab/Mangler.cc

    r267cb3d r083cf31  
    3030
    3131namespace SymTab {
    32         Mangler::Mangler( bool mangleOverridable ) : nextVarNum( 0 ), isTopLevel( true ), mangleOverridable( mangleOverridable ) {
    33         }
    34 
    35 //Mangler::Mangler( const Mangler & )
    36 //  : mangleName(), varNums( varNums ), nextVarNum( nextVarNum ), isTopLevel( isTopLevel )
    37 //{
    38 //}
     32        std::string Mangler::mangleType( Type *ty ) {
     33                Mangler mangler( false, true );
     34                maybeAccept( ty, mangler );
     35                return mangler.get_mangleName();
     36        }
     37       
     38        Mangler::Mangler( bool mangleOverridable, bool typeMode )
     39                : nextVarNum( 0 ), isTopLevel( true ), mangleOverridable( mangleOverridable ), typeMode( typeMode ) {}
     40               
    3941        Mangler::Mangler( const Mangler &rhs ) : mangleName() {
    4042                varNums = rhs.varNums;
     
    4244                isTopLevel = rhs.isTopLevel;
    4345                mangleOverridable = rhs.mangleOverridable;
     46                typeMode = rhs.typeMode;
    4447        }
    4548
     
    152155        void Mangler::mangleRef( ReferenceToType *refType, std::string prefix ) {
    153156                printQualifiers( refType );
     157
    154158                mangleName << ( refType->get_name().length() + prefix.length() ) << prefix << refType->get_name();
    155159        }
    156160
     161        void Mangler::mangleGenericRef( ReferenceToType *refType, std::string prefix ) {
     162                printQualifiers( refType );
     163
     164                std::ostringstream oldName( mangleName.str() );
     165                mangleName.clear();
     166
     167                mangleName << prefix << refType->get_name();
     168
     169                std::list< Expression* >& params = refType->get_parameters();
     170                if ( ! params.empty() ) {
     171                        mangleName << "_";
     172                        for ( std::list< Expression* >::const_iterator param = params.begin(); param != params.end(); ++param ) {
     173                                TypeExpr *paramType = dynamic_cast< TypeExpr* >( *param );
     174                                assert(paramType && "Aggregate parameters should be type expressions");
     175                                maybeAccept( paramType->get_type(), *this );
     176                        }
     177                        mangleName << "_";
     178                }
     179
     180                oldName << mangleName.str().length() << mangleName.str();
     181                mangleName.str( oldName.str() );
     182        }
     183
    157184        void Mangler::visit( StructInstType *aggregateUseType ) {
    158                 mangleRef( aggregateUseType, "s" );
     185                if ( typeMode ) mangleGenericRef( aggregateUseType, "s" );
     186                else mangleRef( aggregateUseType, "s" );
    159187        }
    160188
    161189        void Mangler::visit( UnionInstType *aggregateUseType ) {
    162                 mangleRef( aggregateUseType, "u" );
     190                if ( typeMode ) mangleGenericRef( aggregateUseType, "u" );
     191                else mangleRef( aggregateUseType, "u" );
    163192        }
    164193
     
    209238
    210239        void Mangler::printQualifiers( Type *type ) {
     240                // skip if not including qualifiers
     241                if ( typeMode ) return;
     242               
    211243                if ( ! type->get_forall().empty() ) {
    212244                        std::list< std::string > assertionNames;
     
    227259                                varNums[ (*i )->get_name() ] = std::pair< int, int >( nextVarNum++, (int )(*i )->get_kind() );
    228260                                for ( std::list< DeclarationWithType* >::iterator assert = (*i )->get_assertions().begin(); assert != (*i )->get_assertions().end(); ++assert ) {
    229                                         Mangler sub_mangler( mangleOverridable );
     261                                        Mangler sub_mangler( mangleOverridable, typeMode );
    230262                                        sub_mangler.nextVarNum = nextVarNum;
    231263                                        sub_mangler.isTopLevel = false;
  • src/SymTab/Mangler.h

    r267cb3d r083cf31  
    2222
    2323namespace SymTab {
     24        /// Mangles names to a unique C identifier
    2425        class Mangler : public Visitor {
    2526          public:
     27                /// Mangle syntax tree object; primary interface to clients
    2628                template< typename SynTreeClass >
    27             static std::string mangle( SynTreeClass *decl, bool mangleOverridable = true ); // interface to clients
     29            static std::string mangle( SynTreeClass *decl, bool mangleOverridable = true );
     30                /// Mangle a type name; secondary interface
     31                static std::string mangleType( Type* ty );
    2832
    29 ///   using Visitor::visit;
    3033                virtual void visit( ObjectDecl *declaration );
    3134                virtual void visit( FunctionDecl *declaration );
     
    4548                std::string get_mangleName() { return mangleName.str(); }
    4649          private:
    47                 std::ostringstream mangleName;
     50                std::ostringstream mangleName;  ///< Mangled name being constructed
    4851                typedef std::map< std::string, std::pair< int, int > > VarMapType;
    49                 VarMapType varNums;
    50                 int nextVarNum;
    51                 bool isTopLevel;
    52                 bool mangleOverridable;
     52                VarMapType varNums;             ///< Map of type variables to indices
     53                int nextVarNum;                 ///< Next type variable index
     54                bool isTopLevel;                ///< Is the Mangler at the top level
     55                bool mangleOverridable;         ///< Specially mangle overridable built-in methods
     56                bool typeMode;                  ///< Produce a unique mangled name for a type
    5357 
    54                 Mangler( bool mangleOverridable );
     58                Mangler( bool mangleOverridable, bool typeMode );
    5559                Mangler( const Mangler & );
    5660 
    5761                void mangleDecl( DeclarationWithType *declaration );
    5862                void mangleRef( ReferenceToType *refType, std::string prefix );
     63                void mangleGenericRef( ReferenceToType *refType, std::string prefix );
    5964 
    6065                void printQualifiers( Type *type );
     
    6368        template< typename SynTreeClass >
    6469        std::string Mangler::mangle( SynTreeClass *decl, bool mangleOverridable ) {
    65                 Mangler mangler( mangleOverridable );
     70                Mangler mangler( mangleOverridable, false );
    6671                maybeAccept( decl, mangler );
    6772                return mangler.get_mangleName();
  • src/SymTab/Validate.cc

    r267cb3d r083cf31  
    1010// Created On       : Sun May 17 21:50:04 2015
    1111// Last Modified By : Rob Schluntz
    12 // Last Modified On : Fri Dec 18 14:32:59 2015
    13 // Update Count     : 268
     12// Last Modified On : Thu Jan 07 11:27:49 2016
     13// Update Count     : 269
    1414//
    1515
     
    8686        };
    8787
    88         /// Replaces enum types by int, and function or array types in function parameter and return lists by appropriate pointers
     88        /// Replaces enum types by int, and function or array types in function parameter and return lists by appropriate pointers.
    8989        class Pass1 : public Visitor {
    9090                typedef Visitor Parent;
     
    161161        };
    162162
     163        class ReturnChecker : public Visitor {
     164          public:
     165                /// Checks that return statements return nothing if their return type is void
     166                /// and return something if the return type is non-void.
     167                static void checkFunctionReturns( std::list< Declaration * > & translationUnit );
     168
     169          private:
     170                virtual void visit( FunctionDecl * functionDecl );
     171
     172                virtual void visit( ReturnStmt * returnStmt );
     173
     174                std::list< DeclarationWithType * > returnVals;
     175        };
     176
    163177        class EliminateTypedef : public Mutator {
    164178          public:
    165           EliminateTypedef() : scopeLevel( 0 ) {}
    166             /// Replaces typedefs by forward declarations
     179                EliminateTypedef() : scopeLevel( 0 ) {}
     180                /// Replaces typedefs by forward declarations
    167181                static void eliminateTypedef( std::list< Declaration * > &translationUnit );
    168182          private:
     
    209223                acceptAll( translationUnit, pass1 );
    210224                acceptAll( translationUnit, pass2 );
     225                ReturnChecker::checkFunctionReturns( translationUnit );
    211226                AutogenerateRoutines::autogenerateRoutines( translationUnit );
    212227                acceptAll( translationUnit, pass3 );
     
    850865        }
    851866
     867        void ReturnChecker::checkFunctionReturns( std::list< Declaration * > & translationUnit ) {
     868                ReturnChecker checker;
     869                acceptAll( translationUnit, checker );
     870        }
     871
     872        void ReturnChecker::visit( FunctionDecl * functionDecl ) {
     873                std::list< DeclarationWithType * > oldReturnVals = returnVals;
     874                returnVals = functionDecl->get_functionType()->get_returnVals();
     875                Visitor::visit( functionDecl );
     876                returnVals = oldReturnVals;
     877        }
     878
     879        void ReturnChecker::visit( ReturnStmt * returnStmt ) {
     880                if ( returnStmt->get_expr() == NULL && returnVals.size() != 0 ) {
     881                        throw SemanticError( "Non-void function returns no values: " , returnStmt );
     882                } else if ( returnStmt->get_expr() != NULL && returnVals.size() == 0 ) {
     883                        throw SemanticError( "void function returns values: " , returnStmt );
     884                }
     885        }
     886
     887
    852888        bool isTypedef( Declaration *decl ) {
    853889                return dynamic_cast< TypedefDecl * >( decl );
Note: See TracChangeset for help on using the changeset viewer.