Changeset 1ced874 for src/SymTab/Indexer.cc
- Timestamp:
- Sep 6, 2016, 4:36:29 PM (8 years ago)
- 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:
- e76acbe
- Parents:
- 0362d42 (diff), f04a8b81 (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. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/SymTab/Indexer.cc
r0362d42 r1ced874 21 21 #include <unordered_set> 22 22 #include <utility> 23 #include <algorithm> 23 24 24 25 #include "Mangler.h" … … 33 34 #include "SynTree/Initializer.h" 34 35 #include "SynTree/Statement.h" 36 37 #include "InitTweak/InitTweak.h" 35 38 36 39 #define debugPrint(x) if ( doDebug ) { std::cout << x; } … … 99 102 100 103 if ( --toFree->refCount == 0 ) delete toFree; 104 } 105 106 void Indexer::removeSpecialOverrides( const std::string &id, std::list< DeclarationWithType * > & out ) const { 107 // only need to perform this step for constructors and destructors 108 if ( ! InitTweak::isCtorDtor( id ) ) return; 109 110 // helpful data structure 111 struct ValueType { 112 struct DeclBall { 113 FunctionDecl * decl; 114 bool isUserDefinedFunc; // properties for this particular decl 115 bool isDefaultFunc; 116 bool isCopyFunc; 117 }; 118 // properties for this type 119 bool userDefinedFunc = false; // any user defined function found 120 bool userDefinedDefaultFunc = false; // user defined default ctor found 121 bool userDefinedCopyFunc = false; // user defined copy ctor found 122 std::list< DeclBall > decls; 123 124 // another FunctionDecl for the current type was found - determine 125 // if it has special properties and update data structure accordingly 126 ValueType & operator+=( FunctionDecl * function ) { 127 bool isUserDefinedFunc = ! LinkageSpec::isOverridable( function->get_linkage() ); 128 bool isDefaultFunc = function->get_functionType()->get_parameters().size() == 1; 129 bool isCopyFunc = InitTweak::isCopyConstructor( function ); 130 decls.push_back( DeclBall{ function, isUserDefinedFunc, isDefaultFunc, isCopyFunc } ); 131 userDefinedFunc = userDefinedFunc || isUserDefinedFunc; 132 userDefinedDefaultFunc = userDefinedDefaultFunc || (isUserDefinedFunc && isDefaultFunc); 133 userDefinedCopyFunc = userDefinedCopyFunc || (isUserDefinedFunc && isCopyFunc); 134 return *this; 135 } 136 }; // ValueType 137 138 std::list< DeclarationWithType * > copy; 139 copy.splice( copy.end(), out ); 140 141 // organize discovered declarations by type 142 std::unordered_map< std::string, ValueType > funcMap; 143 for ( DeclarationWithType * decl : copy ) { 144 if ( FunctionDecl * function = dynamic_cast< FunctionDecl * >( decl ) ) { 145 std::list< DeclarationWithType * > params = function->get_functionType()->get_parameters(); 146 assert( ! params.empty() ); 147 funcMap[ Mangler::mangle( params.front()->get_type() ) ] += function; 148 } else { 149 out.push_back( decl ); 150 } 151 } 152 153 // if a type contains user defined ctor/dtors, then special rules trigger, which determine 154 // the set of ctor/dtors that are seen by the requester. In particular, if the user defines 155 // a default ctor, then the generated default ctor should never be seen, likewise for copy ctor 156 // and dtor. If the user defines any ctor/dtor, then no generated field ctors should be seen. 157 for ( std::pair< const std::string, ValueType > & pair : funcMap ) { 158 ValueType & val = pair.second; 159 for ( ValueType::DeclBall ball : val.decls ) { 160 if ( ! val.userDefinedFunc || ball.isUserDefinedFunc || (! val.userDefinedDefaultFunc && ball.isDefaultFunc) || (! val.userDefinedCopyFunc && ball.isCopyFunc) ) { 161 // decl conforms to the rules described above, so it should be seen by the requester 162 out.push_back( ball.decl ); 163 } 164 } 165 } 101 166 } 102 167 … … 461 526 searchTables = searchTables->base.tables; 462 527 } 528 529 // some special functions, e.g. constructors and destructors 530 // remove autogenerated functions when they are defined so that 531 // they can never be matched 532 removeSpecialOverrides( id, out ); 463 533 } 464 534
Note: See TracChangeset
for help on using the changeset viewer.