Changeset bff227f
- Timestamp:
- Jul 21, 2017, 3:57:11 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:
- 9191a8e
- Parents:
- 53a8e68
- Location:
- src
- Files:
-
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
TabularUnified src/CodeGen/OperatorTable.cc ¶
r53a8e68 rbff227f 14 14 // 15 15 16 #include <map> // for map, _Rb_tree_const_iterator, map<>::const_iterator 17 #include <utility> // for pair 16 #include <algorithm> // for any_of 17 #include <map> // for map, _Rb_tree_const_iterator, map<>::const_iterator 18 #include <utility> // for pair 18 19 19 20 #include "OperatorTable.h" … … 91 92 } // if 92 93 } 94 95 /// determines if a given function name is one of the operator types between [begin, end) 96 template<typename Iterator> 97 bool isOperatorType( const std::string & funcName, Iterator begin, Iterator end ) { 98 OperatorInfo info; 99 if ( operatorLookup( funcName, info ) ) { 100 return std::find( begin, end, info.type ) != end; 101 } 102 return false; 103 } 104 105 bool isConstructor( const std::string & funcName ) { 106 static OperatorType types[] = { OT_CTOR }; 107 return isOperatorType( funcName, std::begin(types), std::end(types) ); 108 } 109 110 bool isDestructor( const std::string & funcName ) { 111 static OperatorType types[] = { OT_DTOR }; 112 return isOperatorType( funcName, std::begin(types), std::end(types) ); 113 } 114 115 bool isAssignment( const std::string & funcName ) { 116 static OperatorType types[] = { OT_PREFIXASSIGN, OT_POSTFIXASSIGN, OT_INFIXASSIGN }; 117 return isOperatorType( funcName, std::begin(types), std::end(types) ); 118 } 119 120 bool isCtorDtor( const std::string & funcName ) { 121 static OperatorType types[] = { OT_CTOR, OT_DTOR }; 122 return isOperatorType( funcName, std::begin(types), std::end(types) ); 123 } 124 125 bool isCtorDtorAssign( const std::string & funcName ) { 126 static OperatorType types[] = { OT_CTOR, OT_DTOR, OT_PREFIXASSIGN, OT_POSTFIXASSIGN, OT_INFIXASSIGN }; 127 return isOperatorType( funcName, std::begin(types), std::end(types) ); 128 } 93 129 } // namespace CodeGen 94 130 -
TabularUnified src/CodeGen/OperatorTable.h ¶
r53a8e68 rbff227f 5 5 // file "LICENCE" distributed with Cforall. 6 6 // 7 // OperatorTable.h -- 7 // OperatorTable.h -- 8 8 // 9 9 // Author : Richard C. Bilson … … 43 43 44 44 bool operatorLookup( std::string funcName, OperatorInfo &info ); 45 46 bool isConstructor( const std::string & ); 47 bool isDestructor( const std::string & ); 48 bool isAssignment( const std::string & ); 49 bool isCtorDtor( const std::string & ); 50 bool isCtorDtorAssign( const std::string & ); 45 51 } // namespace CodeGen 46 52 -
TabularUnified src/Concurrency/Keywords.cc ¶
r53a8e68 rbff227f 22 22 #include "Common/SemanticError.h" // for SemanticError 23 23 #include "Common/utility.h" // for deleteAll, map_range 24 #include "InitTweak/InitTweak.h" // for isConstructor 24 #include "CodeGen/OperatorTable.h" // for isConstructor 25 #include "InitTweak/InitTweak.h" // for getPointerBase 25 26 #include "Parser/LinkageSpec.h" // for Cforall 26 27 #include "SymTab/AddVisit.h" // for acceptAndAdd … … 522 523 Visitor::visit(decl); 523 524 524 if( ! InitTweak::isConstructor(decl->get_name()) ) return;525 if( ! CodeGen::isConstructor(decl->get_name()) ) return; 525 526 526 527 DeclarationWithType * param = decl->get_functionType()->get_parameters().front(); -
TabularUnified src/GenPoly/Box.cc ¶
r53a8e68 rbff227f 55 55 #include "Common/UniqueName.h" 56 56 #include "Common/utility.h" 57 58 #include "CodeGen/OperatorTable.h" 57 59 58 60 #include "InitTweak/InitTweak.h" … … 567 569 // To compound the issue, the right side can be *x, etc. because of lvalue-returning functions 568 570 if ( UntypedExpr * assign = dynamic_cast< UntypedExpr * >( commaExpr->get_arg1() ) ) { 569 if ( InitTweak::isAssignment( InitTweak::getFunctionName( assign ) ) ) {571 if ( CodeGen::isAssignment( InitTweak::getFunctionName( assign ) ) ) { 570 572 assert( assign->get_args().size() == 2 ); 571 573 if ( ApplicationExpr * appExpr = dynamic_cast< ApplicationExpr * > ( assign->get_args().back() ) ) { -
TabularUnified src/InitTweak/FixInit.cc ¶
r53a8e68 rbff227f 26 26 #include "FixGlobalInit.h" 27 27 #include "CodeGen/GenType.h" // for warning/error messages 28 #include "CodeGen/OperatorTable.h" 28 29 #include "Common/PassVisitor.h" 29 30 #include "GenPoly/DeclMutator.h" … … 363 364 FunctionType * ftype = dynamic_cast< FunctionType * >( GenPoly::getFunctionType( funcDecl->get_type() ) ); 364 365 assert( ftype ); 365 if ( isConstructor( funcDecl->get_name() ) && ftype->get_parameters().size() == 2 ) {366 if ( CodeGen::isConstructor( funcDecl->get_name() ) && ftype->get_parameters().size() == 2 ) { 366 367 Type * t1 = getPointerBase( ftype->get_parameters().front()->get_type() ); 367 368 Type * t2 = ftype->get_parameters().back()->get_type(); … … 372 373 return appExpr; 373 374 } // if 374 } else if ( isDestructor( funcDecl->get_name() ) ) {375 } else if ( CodeGen::isDestructor( funcDecl->get_name() ) ) { 375 376 // correctness: never copy construct arguments to a destructor 376 377 return appExpr; … … 975 976 if ( ! funcDecl ) return false; 976 977 if ( ! funcDecl->get_statements() ) return false; 977 return isCtorDtor( funcDecl->get_name() ) && ! LinkageSpec::isOverridable( funcDecl->get_linkage() );978 return CodeGen::isCtorDtor( funcDecl->get_name() ) && ! LinkageSpec::isOverridable( funcDecl->get_linkage() ); 978 979 } 979 980 … … 992 993 993 994 function = funcDecl; 994 isCtor = isConstructor( function->get_name() );995 isCtor = CodeGen::isConstructor( function->get_name() ); 995 996 if ( checkWarnings( function ) ) { 996 997 FunctionType * type = function->get_functionType(); -
TabularUnified src/InitTweak/GenInit.cc ¶
r53a8e68 rbff227f 21 21 22 22 #include "Common/PassVisitor.h" 23 #include "CodeGen/OperatorTable.h" 23 24 24 25 #include "GenPoly/DeclMutator.h" … … 235 236 void CtorDtor::handleDWT( DeclarationWithType * dwt ) { 236 237 // if this function is a user-defined constructor or destructor, mark down the type as "managed" 237 if ( ! LinkageSpec::isOverridable( dwt->get_linkage() ) && isCtorDtor( dwt->get_name() ) ) {238 if ( ! LinkageSpec::isOverridable( dwt->get_linkage() ) && CodeGen::isCtorDtor( dwt->get_name() ) ) { 238 239 std::list< DeclarationWithType * > & params = GenPoly::getFunctionType( dwt->get_type() )->get_parameters(); 239 240 assert( ! params.empty() ); -
TabularUnified src/InitTweak/InitTweak.h ¶
r53a8e68 rbff227f 26 26 // helper functions for initialization 27 27 namespace InitTweak { 28 bool isConstructor( const std::string & );29 bool isDestructor( const std::string & );30 bool isAssignment( const std::string & );31 bool isCtorDtor( const std::string & );32 bool isCtorDtorAssign( const std::string & );33 34 28 FunctionDecl * isAssignment( Declaration * decl ); 35 29 FunctionDecl * isDestructor( Declaration * decl ); -
TabularUnified src/SymTab/Autogen.cc ¶
r53a8e68 rbff227f 21 21 #include "SynTree/TypeSubstitution.h" 22 22 #include "Common/utility.h" 23 #include "CodeGen/OperatorTable.h" 23 24 #include "AddVisit.h" 24 25 #include "MakeLibCfa.h" … … 223 224 FunctionType * ftype = data.genType( refType ); 224 225 225 if(concurrent_type && InitTweak::isDestructor( data.fname )) {226 if(concurrent_type && CodeGen::isDestructor( data.fname )) { 226 227 ftype->get_parameters().front()->get_type()->set_mutex( true ); 227 228 } … … 407 408 408 409 // field ctors are only generated if default constructor and copy constructor are both generated 409 unsigned numCtors = std::count_if( newFuncs.begin(), newFuncs.end(), [](FunctionDecl * dcl) { return InitTweak::isConstructor( dcl->get_name() ); } );410 unsigned numCtors = std::count_if( newFuncs.begin(), newFuncs.end(), [](FunctionDecl * dcl) { return CodeGen::isConstructor( dcl->get_name() ); } ); 410 411 411 412 if ( functionNesting == 0 ) { … … 422 423 // generate appropriate calls to member ctor, assignment 423 424 // destructor needs to do everything in reverse, so pass "forward" based on whether the function is a destructor 424 if ( ! InitTweak::isDestructor( dcl->get_name() ) ) {425 if ( ! CodeGen::isDestructor( dcl->get_name() ) ) { 425 426 makeStructFunctionBody( aggregateDecl->get_members().begin(), aggregateDecl->get_members().end(), dcl, isDynamicLayout ); 426 427 } else { 427 428 makeStructFunctionBody( aggregateDecl->get_members().rbegin(), aggregateDecl->get_members().rend(), dcl, isDynamicLayout, false ); 428 429 } 429 if ( InitTweak::isAssignment( dcl->get_name() ) ) {430 if ( CodeGen::isAssignment( dcl->get_name() ) ) { 430 431 // assignment needs to return a value 431 432 FunctionType * assignType = dcl->get_functionType(); … … 486 487 487 488 makeUnionFieldsAssignment( srcParam, dstParam, back_inserter( funcDecl->get_statements()->get_kids() ) ); 488 if ( InitTweak::isAssignment( funcDecl->get_name() ) ) {489 if ( CodeGen::isAssignment( funcDecl->get_name() ) ) { 489 490 // also generate return statement in assignment 490 491 funcDecl->get_statements()->get_kids().push_back( new ReturnStmt( noLabels, new VariableExpr( srcParam ) ) ); -
TabularUnified src/SymTab/Indexer.cc ¶
r53a8e68 rbff227f 26 26 27 27 #include "Common/utility.h" 28 29 #include "CodeGen/OperatorTable.h" 28 30 29 31 #include "ResolvExpr/typeops.h" … … 112 114 void Indexer::removeSpecialOverrides( const std::string &id, std::list< DeclarationWithType * > & out ) const { 113 115 // only need to perform this step for constructors, destructors, and assignment functions 114 if ( ! InitTweak::isCtorDtorAssign( id ) ) return;116 if ( ! CodeGen::isCtorDtorAssign( id ) ) return; 115 117 116 118 // helpful data structure … … 140 142 decls.push_back( DeclBall{ function, isUserDefinedFunc, isDefaultCtor, isDtor, isCopyFunc } ); 141 143 existsUserDefinedFunc = existsUserDefinedFunc || isUserDefinedFunc; 142 existsUserDefinedCtor = existsUserDefinedCtor || (isUserDefinedFunc && InitTweak::isConstructor( function->get_name() ) );144 existsUserDefinedCtor = existsUserDefinedCtor || (isUserDefinedFunc && CodeGen::isConstructor( function->get_name() ) ); 143 145 existsUserDefinedDtor = existsUserDefinedDtor || (isUserDefinedFunc && isDtor); 144 146 existsUserDefinedCopyFunc = existsUserDefinedCopyFunc || (isUserDefinedFunc && isCopyFunc); -
TabularUnified src/SymTab/Validate.cc ¶
r53a8e68 rbff227f 43 43 44 44 #include "CodeGen/CodeGenerator.h" 45 #include "CodeGen/OperatorTable.h" 45 46 46 47 #include "Common/PassVisitor.h" … … 52 53 53 54 #include "GenPoly/DeclMutator.h" 54 55 #include "InitTweak/InitTweak.h"56 55 57 56 #include "AddVisit.h" … … 827 826 std::list< DeclarationWithType * > ¶ms = funcType->get_parameters(); 828 827 829 if ( InitTweak::isCtorDtorAssign( funcDecl->get_name() ) ) {828 if ( CodeGen::isCtorDtorAssign( funcDecl->get_name() ) ) { // TODO: also check /=, etc. 830 829 if ( params.size() == 0 ) { 831 830 throw SemanticError( "Constructors, destructors, and assignment functions require at least one parameter ", funcDecl ); … … 835 834 throw SemanticError( "First parameter of a constructor, destructor, or assignment function must be a reference ", funcDecl ); 836 835 } 837 if ( InitTweak::isCtorDtor( funcDecl->get_name() ) && returnVals.size() != 0 ) {836 if ( CodeGen::isCtorDtor( funcDecl->get_name() ) && returnVals.size() != 0 ) { 838 837 throw SemanticError( "Constructors and destructors cannot have explicit return values ", funcDecl ); 839 838 } -
TabularUnified src/Tuples/TupleAssignment.cc ¶
r53a8e68 rbff227f 22 22 #include "Explode.h" 23 23 #include "Common/SemanticError.h" 24 #include "CodeGen/OperatorTable.h" 24 25 #include "InitTweak/InitTweak.h" 25 26 #include "InitTweak/GenInit.h" … … 110 111 void TupleAssignSpotter::spot( UntypedExpr * expr, const std::list<ResolvExpr::AltList> &possibilities ) { 111 112 if ( NameExpr *op = dynamic_cast< NameExpr * >(expr->get_function()) ) { 112 if ( InitTweak::isCtorDtorAssign( op->get_name() ) ) {113 if ( CodeGen::isCtorDtorAssign( op->get_name() ) ) { 113 114 fname = op->get_name(); 114 115 for ( std::list<ResolvExpr::AltList>::const_iterator ali = possibilities.begin(); ali != possibilities.end(); ++ali ) { 115 116 if ( ali->size() == 0 ) continue; // AlternativeFinder will natrually handle this case, if it's legal 116 if ( ali->size() <= 1 && InitTweak::isAssignment( op->get_name() ) ) {117 if ( ali->size() <= 1 && CodeGen::isAssignment( op->get_name() ) ) { 117 118 // what does it mean if an assignment takes 1 argument? maybe someone defined such a function, in which case AlternativeFinder will naturally handle it 118 119 continue;
Note: See TracChangeset
for help on using the changeset viewer.