Changes in / [934d200:d16cf16]
- Location:
- src
- Files:
-
- 14 edited
Legend:
- Unmodified
- Added
- Removed
-
src/CodeGen/CodeGenerator.cc
r934d200 rd16cf16 133 133 output << "__attribute__ (("; 134 134 for ( list< Attribute * >::iterator attr( attributes.begin() );; ) { 135 output << (*attr)-> get_name();136 if ( ! (*attr)-> get_parameters().empty() ) {135 output << (*attr)->name; 136 if ( ! (*attr)->parameters.empty() ) { 137 137 output << "("; 138 genCommaList( (*attr)-> get_parameters().begin(), (*attr)->get_parameters().end() );138 genCommaList( (*attr)->parameters.begin(), (*attr)->parameters.end() ); 139 139 output << ")"; 140 140 } // if … … 836 836 assertf( ! genC, "Deleted expressions should not reach code generation." ); 837 837 expr->expr->accept( *visitor ); 838 } 839 840 void CodeGenerator::postvisit( DefaultArgExpr * arg ) { 841 assertf( ! genC, "Default argument expressions should not reach code generation." ); 842 arg->expr->accept( *visitor ); 838 843 } 839 844 -
src/CodeGen/CodeGenerator.h
r934d200 rd16cf16 94 94 void postvisit( ConstructorExpr * ); 95 95 void postvisit( DeletedExpr * ); 96 void postvisit( DefaultArgExpr * ); 96 97 void postvisit( GenericExpr * ); 97 98 -
src/Common/Debug.h
r934d200 rd16cf16 28 28 namespace Debug { 29 29 /// debug codegen a translation unit 30 static inline void codeGen( __attribute__((unused)) const std::list< Declaration * > & translationUnit, __attribute__((unused)) const std::string & label, __attribute__((unused)) LinkageSpec::Spec linkageFilter = LinkageSpec:: Compiler) {30 static inline void codeGen( __attribute__((unused)) const std::list< Declaration * > & translationUnit, __attribute__((unused)) const std::string & label, __attribute__((unused)) LinkageSpec::Spec linkageFilter = LinkageSpec::Builtin ) { 31 31 #ifdef DEBUG 32 32 std::list< Declaration * > decls; -
src/Common/PassVisitor.h
r934d200 rd16cf16 125 125 virtual void visit( InitExpr * initExpr ) override final; 126 126 virtual void visit( DeletedExpr * delExpr ) override final; 127 virtual void visit( DefaultArgExpr * argExpr ) override final; 127 128 virtual void visit( GenericExpr * genExpr ) override final; 128 129 … … 224 225 virtual Expression * mutate( InitExpr * initExpr ) override final; 225 226 virtual Expression * mutate( DeletedExpr * delExpr ) override final; 227 virtual Expression * mutate( DefaultArgExpr * argExpr ) override final; 226 228 virtual Expression * mutate( GenericExpr * genExpr ) override final; 227 229 … … 258 260 259 261 private: 262 bool inFunction = false; 263 260 264 template<typename pass_t> friend void acceptAll( std::list< Declaration* > &decls, PassVisitor< pass_t >& visitor ); 261 265 template<typename pass_t> friend void mutateAll( std::list< Declaration* > &decls, PassVisitor< pass_t >& visitor ); -
src/Common/PassVisitor.impl.h
r934d200 rd16cf16 404 404 indexerAddId( &func ); 405 405 maybeAccept_impl( node->type, *this ); 406 // function body needs to have the same scope as parameters - CompoundStmt will not enter 407 // a new scope if inFunction is true 408 ValueGuard< bool > oldInFunction( inFunction ); 409 inFunction = true; 406 410 maybeAccept_impl( node->statements, *this ); 407 411 maybeAccept_impl( node->attributes, *this ); … … 434 438 indexerAddId( &func ); 435 439 maybeMutate_impl( node->type, *this ); 440 // function body needs to have the same scope as parameters - CompoundStmt will not enter 441 // a new scope if inFunction is true 442 ValueGuard< bool > oldInFunction( inFunction ); 443 inFunction = true; 436 444 maybeMutate_impl( node->statements, *this ); 437 445 maybeMutate_impl( node->attributes, *this ); … … 712 720 VISIT_START( node ); 713 721 { 714 auto guard1 = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } ); 722 // do not enter a new scope if inFunction is true - needs to check old state before the assignment 723 ValueGuard< bool > oldInFunction( inFunction ); 724 auto guard1 = makeFuncGuard( [this, &oldInFunction]() { if ( ! oldInFunction.old ) indexerScopeEnter(); }, [this, &oldInFunction]() { if ( ! oldInFunction.old ) indexerScopeLeave(); } ); 715 725 auto guard2 = makeFuncGuard( [this]() { call_beginScope(); }, [this]() { call_endScope(); } ); 726 inFunction = false; 716 727 visitStatementList( node->kids ); 717 728 } … … 723 734 MUTATE_START( node ); 724 735 { 725 auto guard1 = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } ); 736 // do not enter a new scope if inFunction is true - needs to check old state before the assignment 737 ValueGuard< bool > oldInFunction( inFunction ); 738 auto guard1 = makeFuncGuard( [this, &oldInFunction]() { if ( ! oldInFunction.old ) indexerScopeEnter(); }, [this, &oldInFunction]() { if ( ! oldInFunction.old ) indexerScopeLeave(); } ); 726 739 auto guard2 = makeFuncGuard( [this]() { call_beginScope(); }, [this]() { call_endScope(); } ); 740 inFunction = false; 727 741 mutateStatementList( node->kids ); 728 742 } … … 2084 2098 2085 2099 //-------------------------------------------------------------------------- 2100 // DefaultArgExpr 2101 template< typename pass_type > 2102 void PassVisitor< pass_type >::visit( DefaultArgExpr * node ) { 2103 VISIT_START( node ); 2104 2105 indexerScopedAccept( node->result, *this ); 2106 maybeAccept_impl( node->expr, *this ); 2107 2108 VISIT_END( node ); 2109 } 2110 2111 template< typename pass_type > 2112 Expression * PassVisitor< pass_type >::mutate( DefaultArgExpr * node ) { 2113 MUTATE_START( node ); 2114 2115 indexerScopedMutate( node->env, *this ); 2116 indexerScopedMutate( node->result, *this ); 2117 maybeMutate_impl( node->expr, *this ); 2118 2119 MUTATE_END( Expression, node ); 2120 } 2121 2122 //-------------------------------------------------------------------------- 2086 2123 // GenericExpr 2087 2124 template< typename pass_type > -
src/GenPoly/Lvalue.cc
r934d200 rd16cf16 146 146 147 147 namespace { 148 // true for intrinsic function calls that return a reference148 // true for intrinsic function calls that return an lvalue in C 149 149 bool isIntrinsicReference( Expression * expr ) { 150 // known intrinsic-reference prelude functions 151 static std::set<std::string> lvalueFunctions = { "*?", "?[?]" }; 150 152 if ( UntypedExpr * untyped = dynamic_cast< UntypedExpr * >( expr ) ) { 151 153 std::string fname = InitTweak::getFunctionName( untyped ); 152 // known intrinsic-reference prelude functions 153 return fname == "*?" || fname == "?[?]"; 154 return lvalueFunctions.count(fname); 154 155 } else if ( ApplicationExpr * appExpr = dynamic_cast< ApplicationExpr * > ( expr ) ) { 155 156 if ( DeclarationWithType * func = InitTweak::getFunction( appExpr ) ) { 156 // use type of return variable rather than expr result type, since it may have been changed to a pointer type 157 FunctionType * ftype = GenPoly::getFunctionType( func->get_type() ); 158 Type * ret = ftype->returnVals.empty() ? nullptr : ftype->returnVals.front()->get_type(); 159 return func->linkage == LinkageSpec::Intrinsic && dynamic_cast<ReferenceType *>( ret ); 157 return func->linkage == LinkageSpec::Intrinsic && lvalueFunctions.count(func->name); 160 158 } 161 159 } … … 212 210 // TODO: it's likely that the second condition should be ... && ! isIntrinsicReference( arg ), but this requires investigation. 213 211 214 if ( function-> get_linkage()!= LinkageSpec::Intrinsic && isIntrinsicReference( arg ) ) {212 if ( function->linkage != LinkageSpec::Intrinsic && isIntrinsicReference( arg ) ) { 215 213 // needed for definition of prelude functions, etc. 216 214 // if argument is dereference or array subscript, the result isn't REALLY a reference, but non-intrinsic functions expect a reference: take address … … 228 226 arg = new AddressExpr( arg ); 229 227 // } else if ( function->get_linkage() == LinkageSpec::Intrinsic && InitTweak::getPointerBase( arg->result ) ) { 230 } else if ( function-> get_linkage()== LinkageSpec::Intrinsic && arg->result->referenceDepth() != 0 ) {228 } else if ( function->linkage == LinkageSpec::Intrinsic && arg->result->referenceDepth() != 0 ) { 231 229 // argument is a 'real' reference, but function expects a C lvalue: add a dereference to the reference-typed argument 232 230 PRINT( -
src/ResolvExpr/AlternativeFinder.cc
r934d200 rd16cf16 176 176 selected[ mangleName ] = current; 177 177 } else if ( candidate->cost == mapPlace->second.candidate->cost ) { 178 PRINT( 179 std::cerr << "marking ambiguous" << std::endl; 180 ) 181 mapPlace->second.isAmbiguous = true; 178 // if one of the candidates contains a deleted identifier, can pick the other, since 179 // deleted expressions should not be ambiguous if there is another option that is at least as good 180 if ( findDeletedExpr( candidate->expr ) ) { 181 // do nothing 182 PRINT( std::cerr << "candidate is deleted" << std::endl; ) 183 } else if ( findDeletedExpr( mapPlace->second.candidate->expr ) ) { 184 PRINT( std::cerr << "current is deleted" << std::endl; ) 185 selected[ mangleName ] = current; 186 } else { 187 PRINT( 188 std::cerr << "marking ambiguous" << std::endl; 189 ) 190 mapPlace->second.isAmbiguous = true; 191 } 182 192 } else { 183 193 PRINT( … … 335 345 if ( ConstantExpr * constantExpr = dynamic_cast< ConstantExpr * >( member ) ) { 336 346 // get the value of the constant expression as an int, must be between 0 and the length of the tuple type to have meaning 337 // xxx - this should be improved by memoizing the value of constant exprs 338 // during parsing and reusing that information here. 339 std::stringstream ss( constantExpr->get_constant()->get_value() ); 340 int val = 0; 347 auto val = constantExpr->intValue(); 341 348 std::string tmp; 342 if ( ss >> val && ! (ss >> tmp) ) { 343 if ( val >= 0 && (unsigned int)val < tupleType->size() ) { 344 alternatives.push_back( Alternative( new TupleIndexExpr( expr->clone(), val ), env, newCost ) ); 345 } // if 349 if ( val >= 0 && (unsigned long long)val < tupleType->size() ) { 350 alternatives.push_back( Alternative( new TupleIndexExpr( expr->clone(), val ), env, newCost ) ); 346 351 } // if 347 } else if ( NameExpr * nameExpr = dynamic_cast< NameExpr * >( member ) ) {348 // xxx - temporary hack until 0/1 are int constants349 if ( nameExpr->get_name() == "0" || nameExpr->get_name() == "1" ) {350 std::stringstream ss( nameExpr->get_name() );351 int val;352 ss >> val;353 alternatives.push_back( Alternative( new TupleIndexExpr( expr->clone(), val ), env, newCost ) );354 }355 352 } // if 356 353 } … … 439 436 return Cost::infinity; 440 437 } 438 } 439 if ( DefaultArgExpr * def = dynamic_cast< DefaultArgExpr * >( *actualExpr ) ) { 440 // default arguments should be free - don't include conversion cost. 441 // Unwrap them here because they are not relevant to the rest of the system. 442 *actualExpr = def->expr; 443 ++formal; 444 continue; 441 445 } 442 446 Type * formalType = (*formal)->get_type(); … … 611 615 ConstantExpr* getDefaultValue( Initializer* init ) { 612 616 if ( SingleInit* si = dynamic_cast<SingleInit*>( init ) ) { 613 if ( CastExpr* ce = dynamic_cast<CastExpr*>( si->get_value() ) ) { 614 return dynamic_cast<ConstantExpr*>( ce->get_arg() ); 617 if ( CastExpr* ce = dynamic_cast<CastExpr*>( si->value ) ) { 618 return dynamic_cast<ConstantExpr*>( ce->arg ); 619 } else { 620 return dynamic_cast<ConstantExpr*>( si->value ); 615 621 } 616 622 } … … 873 879 indexer ) ) { 874 880 results.emplace_back( 875 i, cnstExpr, move(env), move(need), move(have),881 i, new DefaultArgExpr( cnstExpr ), move(env), move(need), move(have), 876 882 move(openVars), nextArg, nTuples ); 877 883 } … … 1065 1071 funcFinder.findWithAdjustment( untypedExpr->function ); 1066 1072 // if there are no function alternatives, then proceeding is a waste of time. 1073 // xxx - findWithAdjustment throws, so this check and others like it shouldn't be necessary. 1067 1074 if ( funcFinder.alternatives.empty() ) return; 1068 1075 -
src/ResolvExpr/Resolver.h
r934d200 rd16cf16 36 36 void resolveCtorInit( ConstructorInit * ctorInit, const SymTab::Indexer & indexer ); 37 37 void resolveStmtExpr( StmtExpr * stmtExpr, const SymTab::Indexer & indexer ); 38 /// Searches expr and returns the first DeletedExpr found, otherwise nullptr 39 DeletedExpr * findDeletedExpr( Expression * expr ); 38 40 } // namespace ResolvExpr 39 41 -
src/SymTab/Indexer.cc
r934d200 rd16cf16 126 126 decls.push_back( DeclBall{ data, isUserDefinedFunc, isCopyFunc } ); 127 127 existsUserDefinedCopyFunc = existsUserDefinedCopyFunc || (isUserDefinedFunc && isCopyFunc); 128 if ( isUserDefinedFunc && ! d ata.deleteStmt ) {128 if ( isUserDefinedFunc && ! deleteStmt ) { 129 129 // any user-defined function can act as an implicit delete statement for generated constructors. 130 130 // a delete stmt should not act as an implicit delete statement. … … 166 166 bool isCopyFunc = ball.isCopyFunc; 167 167 bool existsUserDefinedCopyFunc = val.existsUserDefinedCopyFunc; 168 // only implicitly delete non-user defined functions that are not intrinsic, and are 169 // not copy functions (assignment or copy constructor), unless a user-defined copy function exists. 170 // deleteStmt will be non-null only if a user-defined function is found. 171 if (isNotUserDefinedFunc && (! isCopyFunc || existsUserDefinedCopyFunc)) { 172 ball.decl.deleteStmt = val.deleteStmt; 168 169 // only implicitly delete non-user defined functions that are not intrinsic, and are 170 // not copy functions (assignment or copy constructor). If a user-defined copy function exists, 171 // do not pass along the non-user-defined copy functions since signatures do not have to match, 172 // and the generated functions will often be cheaper. 173 if ( isNotUserDefinedFunc ) { 174 if ( isCopyFunc ) { 175 // Skip over non-user-defined copy functions when there is a user-defined copy function. 176 // Since their signatures do not have to be exact, deleting them is the wrong choice. 177 if ( existsUserDefinedCopyFunc ) continue; 178 } else { 179 // delete non-user-defined non-copy functions if applicable. 180 // deleteStmt will be non-null only if a user-defined function is found. 181 ball.decl.deleteStmt = val.deleteStmt; 182 } 173 183 } 174 184 out.push_back( ball.decl ); -
src/SynTree/Expression.cc
r934d200 rd16cf16 746 746 os << std::endl << indent+1 << "... deleted by: "; 747 747 deleteStmt->print( os, indent+1 ); 748 } 749 750 751 DefaultArgExpr::DefaultArgExpr( Expression * expr ) : expr( expr ) { 752 assert( expr->result ); 753 result = expr->result->clone(); 754 } 755 DefaultArgExpr::DefaultArgExpr( const DefaultArgExpr & other ) : Expression( other ), expr( maybeClone( other.expr ) ) {} 756 DefaultArgExpr::~DefaultArgExpr() { 757 delete expr; 758 } 759 760 void DefaultArgExpr::print( std::ostream & os, Indenter indent ) const { 761 os << "Default Argument Expression" << std::endl << indent+1; 762 expr->print( os, indent+1 ); 748 763 } 749 764 -
src/SynTree/Expression.h
r934d200 rd16cf16 865 865 }; 866 866 867 /// expression wrapping the use of a default argument - should never make it past the resolver. 868 class DefaultArgExpr : public Expression { 869 public: 870 Expression * expr; 871 872 DefaultArgExpr( Expression * expr ); 873 DefaultArgExpr( const DefaultArgExpr & other ); 874 ~DefaultArgExpr(); 875 876 virtual DefaultArgExpr * clone() const { return new DefaultArgExpr( * this ); } 877 virtual void accept( Visitor & v ) { v.visit( this ); } 878 virtual Expression * acceptMutator( Mutator & m ) { return m.mutate( this ); } 879 virtual void print( std::ostream & os, Indenter indent = {} ) const; 880 }; 881 867 882 /// C11 _Generic expression 868 883 class GenericExpr : public Expression { -
src/SynTree/Mutator.h
r934d200 rd16cf16 93 93 virtual Expression * mutate( InitExpr * initExpr ) = 0; 94 94 virtual Expression * mutate( DeletedExpr * delExpr ) = 0; 95 virtual Expression * mutate( DefaultArgExpr * argExpr ) = 0; 95 96 virtual Expression * mutate( GenericExpr * genExpr ) = 0; 96 97 -
src/SynTree/SynTree.h
r934d200 rd16cf16 101 101 class InitExpr; 102 102 class DeletedExpr; 103 class DefaultArgExpr; 103 104 class GenericExpr; 104 105 -
src/SynTree/Visitor.h
r934d200 rd16cf16 95 95 virtual void visit( InitExpr * initExpr ) = 0; 96 96 virtual void visit( DeletedExpr * delExpr ) = 0; 97 virtual void visit( DefaultArgExpr * argExpr ) = 0; 97 98 virtual void visit( GenericExpr * genExpr ) = 0; 98 99
Note: See TracChangeset
for help on using the changeset viewer.