Changes in src/SymTab/Indexer.cc [1ba88a0:8884112]
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/SymTab/Indexer.cc
r1ba88a0 r8884112 9 9 // Author : Richard C. Bilson 10 10 // Created On : Sun May 17 21:37:33 2015 11 // Last Modified By : Peter A. Buhr12 // Last Modified On : Tue Jul 12 17:47:47201613 // Update Count : 1 211 // Last Modified By : Rob Schluntz 12 // Last Modified On : Fri Apr 22 15:25:43 2016 13 // Update Count : 11 14 14 // 15 15 … … 21 21 #include <unordered_set> 22 22 #include <utility> 23 #include <algorithm>24 23 25 24 #include "Mangler.h" … … 34 33 #include "SynTree/Initializer.h" 35 34 #include "SynTree/Statement.h" 36 37 #include "InitTweak/InitTweak.h"38 35 39 36 #define debugPrint(x) if ( doDebug ) { std::cout << x; } … … 104 101 } 105 102 106 void Indexer::removeSpecialOverrides( const std::string &id, std::list< DeclarationWithType * > & out ) const {107 // only need to perform this step for constructors and destructors108 if ( ! InitTweak::isCtorDtor( id ) ) return;109 110 // helpful data structure111 struct ValueType {112 struct DeclBall {113 FunctionDecl * decl;114 bool isUserDefinedFunc; // properties for this particular decl115 bool isDefaultFunc;116 bool isCopyFunc;117 };118 // properties for this type119 bool userDefinedFunc = false; // any user defined function found120 bool userDefinedDefaultFunc = false; // user defined default ctor found121 bool userDefinedCopyFunc = false; // user defined copy ctor found122 std::list< DeclBall > decls;123 124 // another FunctionDecl for the current type was found - determine125 // if it has special properties and update data structure accordingly126 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 }; // ValueType137 138 std::list< DeclarationWithType * > copy;139 copy.splice( copy.end(), out );140 141 // organize discovered declarations by type142 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 determine154 // the set of ctor/dtors that are seen by the requester. In particular, if the user defines155 // a default ctor, then the generated default ctor should never be seen, likewise for copy ctor156 // 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 requester162 out.push_back( ball.decl );163 }164 }165 }166 }167 168 103 void Indexer::makeWritable() { 169 104 if ( ! tables ) { … … 526 461 searchTables = searchTables->base.tables; 527 462 } 528 529 // some special functions, e.g. constructors and destructors530 // remove autogenerated functions when they are defined so that531 // they can never be matched532 removeSpecialOverrides( id, out );533 463 } 534 464 … … 590 520 const MangleTable &mangleTable = decls->second; 591 521 for ( MangleTable::const_iterator decl = mangleTable.begin(); decl != mangleTable.end(); ++decl ) { 592 // check for C decls with the same name, skipping those with a compatible type (by mangleName) 522 // check for C decls with the same name, skipping 523 // those with a compatible type (by mangleName) 593 524 if ( decl->second->get_linkage() == LinkageSpec::C && decl->first != mangleName ) return true; 594 525 }
Note: See TracChangeset
for help on using the changeset viewer.