- Timestamp:
- Dec 15, 2015, 2:56:43 PM (9 years ago)
- 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:
- 4389966, ffad73a
- Parents:
- 5e92fee
- Location:
- src
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
src/GenPoly/Box.cc
r5e92fee r78dd0da 640 640 } 641 641 642 Expression *makeIncrDecrExpr( ApplicationExpr *appExpr, std::string polyName, bool isIncr ) {642 Expression *makeIncrDecrExpr( ApplicationExpr *appExpr, Type *polyType, bool isIncr ) { 643 643 NameExpr *opExpr; 644 644 if ( isIncr ) { … … 653 653 addAssign->get_args().push_back( appExpr->get_args().front() ); 654 654 } // if 655 addAssign->get_args().push_back( new NameExpr( s td::string("_sizeof_") + polyName) );655 addAssign->get_args().push_back( new NameExpr( sizeofName( polyType ) ) ); 656 656 addAssign->get_results().front() = appExpr->get_results().front()->clone(); 657 657 if ( appExpr->get_env() ) { … … 680 680 UntypedExpr *multiply = new UntypedExpr( new NameExpr( "?*?" ) ); 681 681 multiply->get_args().push_back( appExpr->get_args().back() ); 682 multiply->get_args().push_back( new NameExpr( s td::string("_sizeof_") + typeInst1->get_name() ) );682 multiply->get_args().push_back( new NameExpr( sizeofName( typeInst1 ) ) ); 683 683 ret->get_args().push_back( appExpr->get_args().front() ); 684 684 ret->get_args().push_back( multiply ); … … 686 686 UntypedExpr *multiply = new UntypedExpr( new NameExpr( "?*?" ) ); 687 687 multiply->get_args().push_back( appExpr->get_args().front() ); 688 multiply->get_args().push_back( new NameExpr( s td::string("_sizeof_") + typeInst2->get_name() ) );688 multiply->get_args().push_back( new NameExpr( sizeofName( typeInst2 ) ) ); 689 689 ret->get_args().push_back( multiply ); 690 690 ret->get_args().push_back( appExpr->get_args().back() ); … … 732 732 assignExpr->get_args().push_back( appExpr->get_args().front()->clone() ); 733 733 } // if 734 CommaExpr *firstComma = new CommaExpr( assignExpr, makeIncrDecrExpr( appExpr, typeInst ->get_name(), varExpr->get_var()->get_name() == "?++" ) );734 CommaExpr *firstComma = new CommaExpr( assignExpr, makeIncrDecrExpr( appExpr, typeInst, varExpr->get_var()->get_name() == "?++" ) ); 735 735 return new CommaExpr( firstComma, tempExpr ); 736 736 } // if … … 739 739 assert( appExpr->get_args().size() == 1 ); 740 740 if ( TypeInstType *typeInst = isPolyPtr( appExpr->get_results().front(), env, scopeTyVars ) ) { 741 return makeIncrDecrExpr( appExpr, typeInst ->get_name(), varExpr->get_var()->get_name() == "++?" );741 return makeIncrDecrExpr( appExpr, typeInst, varExpr->get_var()->get_name() == "++?" ); 742 742 } // if 743 743 } else if ( varExpr->get_var()->get_name() == "?+?" || varExpr->get_var()->get_name() == "?-?" ) { … … 749 749 UntypedExpr *divide = new UntypedExpr( new NameExpr( "?/?" ) ); 750 750 divide->get_args().push_back( appExpr ); 751 divide->get_args().push_back( new NameExpr( s td::string("_sizeof_") + typeInst1->get_name() ) );751 divide->get_args().push_back( new NameExpr( sizeofName( typeInst1 ) ) ); 752 752 divide->get_results().push_front( appExpr->get_results().front()->clone() ); 753 753 if ( appExpr->get_env() ) { … … 759 759 UntypedExpr *multiply = new UntypedExpr( new NameExpr( "?*?" ) ); 760 760 multiply->get_args().push_back( appExpr->get_args().back() ); 761 multiply->get_args().push_back( new NameExpr( s td::string("_sizeof_") + typeInst1->get_name() ) );761 multiply->get_args().push_back( new NameExpr( sizeofName( typeInst1 ) ) ); 762 762 appExpr->get_args().back() = multiply; 763 763 } else if ( typeInst2 ) { 764 764 UntypedExpr *multiply = new UntypedExpr( new NameExpr( "?*?" ) ); 765 765 multiply->get_args().push_back( appExpr->get_args().front() ); 766 multiply->get_args().push_back( new NameExpr( s td::string("_sizeof_") + typeInst2->get_name() ) );766 multiply->get_args().push_back( new NameExpr( sizeofName( typeInst2 ) ) ); 767 767 appExpr->get_args().front() = multiply; 768 768 } // if … … 774 774 UntypedExpr *multiply = new UntypedExpr( new NameExpr( "?*?" ) ); 775 775 multiply->get_args().push_back( appExpr->get_args().back() ); 776 multiply->get_args().push_back( new NameExpr( s td::string("_sizeof_") + typeInst->get_name() ) );776 multiply->get_args().push_back( new NameExpr( sizeofName( typeInst ) ) ); 777 777 appExpr->get_args().back() = multiply; 778 778 } // if … … 1009 1009 std::list< DeclarationWithType *>::iterator last = funcType->get_parameters().begin(); 1010 1010 std::list< DeclarationWithType *> inferredParams; 1011 ObjectDecl *newObj = new ObjectDecl( "", DeclarationNode::NoStorageClass, LinkageSpec::C, 0, new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ), 0 );1011 ObjectDecl newObj( "", DeclarationNode::NoStorageClass, LinkageSpec::C, 0, new BasicType( Type::Qualifiers(), BasicType::LongUnsignedInt ), 0 ); 1012 1012 // ObjectDecl *newFunPtr = new ObjectDecl( "", DeclarationNode::NoStorageClass, LinkageSpec::Cforall, 0, new PointerType( Type::Qualifiers(), new FunctionType( Type::Qualifiers(), true ) ), 0 ); 1013 1013 for ( std::list< TypeDecl *>::const_iterator tyParm = funcType->get_forall().begin(); tyParm != funcType->get_forall().end(); ++tyParm ) { … … 1015 1015 // add all size and alignment parameters to parameter list 1016 1016 if ( (*tyParm)->get_kind() == TypeDecl::Any ) { 1017 sizeParm = newObj->clone(); 1018 sizeParm->set_name( std::string("_sizeof_") + (*tyParm)->get_name() ); 1017 TypeInstType parmType( Type::Qualifiers(), (*tyParm)->get_name(), *tyParm ); 1018 1019 sizeParm = newObj.clone(); 1020 sizeParm->set_name( sizeofName( &parmType ) ); 1019 1021 last = funcType->get_parameters().insert( last, sizeParm ); 1020 1022 ++last; 1021 alignParm = newObj->clone(); 1022 alignParm->set_name( std::string("_alignof_") + (*tyParm)->get_name() ); 1023 1024 alignParm = newObj.clone(); 1025 alignParm->set_name( alignofName( &parmType ) ); 1023 1026 last = funcType->get_parameters().insert( last, alignParm ); 1024 1027 ++last; … … 1031 1034 (*tyParm)->get_assertions().clear(); 1032 1035 } 1033 delete newObj;1034 1036 funcType->get_parameters().splice( last, inferredParams ); 1035 1037 addAdapters( funcType ); … … 1108 1110 assert( typeInst ); 1109 1111 UntypedExpr *alloc = new UntypedExpr( new NameExpr( "__builtin_alloca" ) ); 1110 alloc->get_args().push_back( new NameExpr( s td::string("_sizeof_") + typeInst->get_name() ) );1112 alloc->get_args().push_back( new NameExpr( sizeofName( typeInst ) ) ); 1111 1113 1112 1114 delete objectDecl->get_init(); -
src/GenPoly/ScrubTyVars.cc
r5e92fee r78dd0da 14 14 // 15 15 16 #include <sstream> 16 17 #include <string> 17 18 18 19 #include "GenPoly.h" 19 20 #include "ScrubTyVars.h" 21 22 #include "SymTab/Mangler.h" 20 23 21 24 #include "SynTree/Mutator.h" … … 46 49 // sizeof( T ) => _sizeof_T parameter, which is the size of T 47 50 if ( TypeInstType *typeInst = dynamic_cast< TypeInstType * >( szeof->get_type() ) ) { 48 Expression *expr = new NameExpr( s td::string("_sizeof_") + typeInst->get_name() );51 Expression *expr = new NameExpr( sizeofName( typeInst ) ); 49 52 return expr; 50 53 } else { … … 56 59 // alignof( T ) => _alignof_T parameter, which is the alignment of T 57 60 if ( TypeInstType *typeInst = dynamic_cast< TypeInstType * >( algnof->get_type() ) ) { 58 Expression *expr = new NameExpr( std::string("_alignof_") + typeInst->get_name() );61 Expression *expr = new NameExpr( alignofName( typeInst ) ); 59 62 return expr; 60 63 } else { … … 75 78 return Mutator::mutate( pointer ); 76 79 } 80 81 std::string sizeofName( Type *ty ) { 82 return std::string( "_sizeof_" ) + SymTab::Mangler::mangle( ty, false, false ); 83 } 84 85 std::string alignofName( Type *ty ) { 86 return std::string( "_alignof_" ) + SymTab::Mangler::mangle( ty, false, false ); 87 } 77 88 } // namespace GenPoly 78 89 -
src/GenPoly/ScrubTyVars.h
r5e92fee r78dd0da 16 16 #ifndef _SCRUBTYVARS_H 17 17 #define _SCRUBTYVARS_H 18 19 #include <string> 18 20 19 21 #include "GenPoly.h" … … 57 59 return static_cast< SynTreeClass* >( target->acceptMutator( scrubber ) ); 58 60 } 61 62 /// Gets the name of the sizeof parameter for the type 63 std::string sizeofName( Type *ty ); 64 65 /// Gets the name of the alignof parameter for the type 66 std::string alignofName( Type *ty ); 59 67 } // namespace GenPoly 60 68 -
src/SymTab/Mangler.cc
r5e92fee r78dd0da 30 30 31 31 namespace 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 Mangler::Mangler( bool mangleOverridable, bool includeQualifiers ) 33 : nextVarNum( 0 ), isTopLevel( true ), mangleOverridable( mangleOverridable ), includeQualifiers(includeQualifiers) {} 34 39 35 Mangler::Mangler( const Mangler &rhs ) : mangleName() { 40 36 varNums = rhs.varNums; … … 42 38 isTopLevel = rhs.isTopLevel; 43 39 mangleOverridable = rhs.mangleOverridable; 40 includeQualifiers = rhs.includeQualifiers; 44 41 } 45 42 … … 209 206 210 207 void Mangler::printQualifiers( Type *type ) { 208 // skip if not including qualifiers 209 if ( ! includeQualifiers ) return; 210 211 211 if ( ! type->get_forall().empty() ) { 212 212 std::list< std::string > assertionNames; … … 227 227 varNums[ (*i )->get_name() ] = std::pair< int, int >( nextVarNum++, (int )(*i )->get_kind() ); 228 228 for ( std::list< DeclarationWithType* >::iterator assert = (*i )->get_assertions().begin(); assert != (*i )->get_assertions().end(); ++assert ) { 229 Mangler sub_mangler( mangleOverridable );229 Mangler sub_mangler( mangleOverridable, includeQualifiers ); 230 230 sub_mangler.nextVarNum = nextVarNum; 231 231 sub_mangler.isTopLevel = false; -
src/SymTab/Mangler.h
r5e92fee r78dd0da 22 22 23 23 namespace SymTab { 24 /// Mangles names to a unique C identifier 24 25 class Mangler : public Visitor { 25 26 public: 26 27 template< typename SynTreeClass > 27 static std::string mangle( SynTreeClass *decl, bool mangleOverridable = true ); // interface to clients28 static std::string mangle( SynTreeClass *decl, bool mangleOverridable = true, bool includeQualifiers = true ); // interface to clients 28 29 29 /// using Visitor::visit;30 30 virtual void visit( ObjectDecl *declaration ); 31 31 virtual void visit( FunctionDecl *declaration ); … … 45 45 std::string get_mangleName() { return mangleName.str(); } 46 46 private: 47 std::ostringstream mangleName; 47 std::ostringstream mangleName; ///< Mangled name being constructed 48 48 typedef std::map< std::string, std::pair< int, int > > VarMapType; 49 VarMapType varNums; 50 int nextVarNum; 51 bool isTopLevel; 52 bool mangleOverridable; 49 VarMapType varNums; ///< Map of type variables to indices 50 int nextVarNum; ///< Next type variable index 51 bool isTopLevel; ///< Is the Mangler at the top level 52 bool mangleOverridable; ///< Specially mangle overridable built-in methods 53 bool includeQualifiers; ///< Include type qualifiers in mangled name 53 54 54 Mangler( bool mangleOverridable );55 Mangler( bool mangleOverridable, bool includeQualifiers ); 55 56 Mangler( const Mangler & ); 56 57 … … 62 63 63 64 template< typename SynTreeClass > 64 std::string Mangler::mangle( SynTreeClass *decl, bool mangleOverridable ) {65 Mangler mangler( mangleOverridable );65 std::string Mangler::mangle( SynTreeClass *decl, bool mangleOverridable, bool includeQualifiers ) { 66 Mangler mangler( mangleOverridable, includeQualifiers ); 66 67 maybeAccept( decl, mangler ); 67 68 return mangler.get_mangleName();
Note: See TracChangeset
for help on using the changeset viewer.