Changes in / [62194cb:178e4ec]
- Location:
- src
- Files:
-
- 1 added
- 31 edited
Legend:
- Unmodified
- Added
- Removed
-
src/GenPoly/Box.cc
r62194cb r178e4ec 167 167 Expression *postmutate( OffsetofExpr *offsetofExpr ); 168 168 Expression *postmutate( OffsetPackExpr *offsetPackExpr ); 169 void premutate( StructDecl * ); 170 void premutate( UnionDecl * ); 169 171 170 172 void beginScope(); … … 178 180 /// adds type parameters to the layout call; will generate the appropriate parameters if needed 179 181 void addOtypeParamsToLayoutCall( UntypedExpr *layoutCall, const std::list< Type* > &otypeParams ); 182 /// change the type of generic aggregate members to char[] 183 void mutateMembers( AggregateDecl * aggrDecl ); 180 184 181 185 /// Enters a new scope for type-variables, adding the type variables from ty … … 1414 1418 1415 1419 void PolyGenericCalculator::premutate( TypedefDecl *typedefDecl ) { 1420 assert(false); 1416 1421 beginTypeScope( typedefDecl->get_base() ); 1417 1422 } … … 1460 1465 } 1461 1466 1467 /// converts polymorphic type T into a suitable monomorphic representation, currently: __attribute__((aligned(8)) char[size_T] 1468 Type * polyToMonoType( Type * declType ) { 1469 Type * charType = new BasicType( Type::Qualifiers(), BasicType::Kind::Char); 1470 Expression * size = new NameExpr( sizeofName( mangleType(declType) ) ); 1471 Attribute * aligned = new Attribute( "aligned", std::list<Expression*>{ new ConstantExpr( Constant::from_int(8) ) } ); 1472 return new ArrayType( Type::Qualifiers(), charType, size, 1473 true, false, std::list<Attribute *>{ aligned } ); 1474 } 1475 1476 void PolyGenericCalculator::mutateMembers( AggregateDecl * aggrDecl ) { 1477 std::set< std::string > genericParams; 1478 for ( TypeDecl * td : aggrDecl->parameters ) { 1479 genericParams.insert( td->name ); 1480 } 1481 for ( Declaration * decl : aggrDecl->members ) { 1482 if ( ObjectDecl * field = dynamic_cast< ObjectDecl * >( decl ) ) { 1483 Type * ty = replaceTypeInst( field->type, env ); 1484 if ( TypeInstType *typeInst = dynamic_cast< TypeInstType* >( ty ) ) { 1485 // do not try to monomorphize generic parameters 1486 if ( scopeTyVars.find( typeInst->get_name() ) != scopeTyVars.end() && ! genericParams.count( typeInst->name ) ) { 1487 // polymorphic aggregate members should be converted into monomorphic members. 1488 // Using char[size_T] here respects the expected sizing rules of an aggregate type. 1489 Type * newType = polyToMonoType( field->type ); 1490 delete field->type; 1491 field->type = newType; 1492 } 1493 } 1494 } 1495 } 1496 } 1497 1498 void PolyGenericCalculator::premutate( StructDecl * structDecl ) { 1499 mutateMembers( structDecl ); 1500 } 1501 1502 void PolyGenericCalculator::premutate( UnionDecl * unionDecl ) { 1503 mutateMembers( unionDecl ); 1504 } 1505 1462 1506 void PolyGenericCalculator::premutate( DeclStmt *declStmt ) { 1463 1507 if ( ObjectDecl *objectDecl = dynamic_cast< ObjectDecl *>( declStmt->get_decl() ) ) { … … 1465 1509 // change initialization of a polymorphic value object to allocate via a VLA 1466 1510 // (alloca was previously used, but can't be safely used in loops) 1467 Type *declType = objectDecl->get_type(); 1468 ObjectDecl *newBuf = new ObjectDecl( bufNamer.newName(), Type::StorageClasses(), LinkageSpec::C, 0, 1469 new ArrayType( Type::Qualifiers(), new BasicType( Type::Qualifiers(), BasicType::Kind::Char), new NameExpr( sizeofName( mangleType(declType) ) ), 1470 true, false, std::list<Attribute*>{ new Attribute( "aligned", std::list<Expression*>{ new ConstantExpr( Constant::from_int(8) ) } ) } ), 0 ); 1511 ObjectDecl *newBuf = ObjectDecl::newObject( bufNamer.newName(), polyToMonoType( objectDecl->type ), nullptr ); 1471 1512 stmtsToAddBefore.push_back( new DeclStmt( noLabels, newBuf ) ); 1472 1513 -
src/GenPoly/InstantiateGeneric.cc
r62194cb r178e4ec 27 27 #include "Common/utility.h" // for deleteAll, cloneAll 28 28 #include "GenPoly.h" // for isPolyType, typesPolyCompatible 29 #include "ResolvExpr/typeops.h" 29 30 #include "ScopedSet.h" // for ScopedSet, ScopedSet<>::iterator 30 31 #include "ScrubTyVars.h" // for ScrubTyVars … … 151 152 return gt; 152 153 } 154 155 /// Add cast to dtype-static member expressions so that type information is not lost in GenericInstantiator 156 struct FixDtypeStatic final { 157 Expression * postmutate( MemberExpr * memberExpr ); 158 159 template<typename AggrInst> 160 Expression * fixMemberExpr( AggrInst * inst, MemberExpr * memberExpr ); 161 }; 153 162 154 163 /// Mutator pass that replaces concrete instantiations of generic types with actual struct declarations, scoped appropriately … … 198 207 199 208 void instantiateGeneric( std::list< Declaration* > &translationUnit ) { 209 PassVisitor<FixDtypeStatic> fixer; 200 210 PassVisitor<GenericInstantiator> instantiator; 211 212 mutateAll( translationUnit, fixer ); 201 213 mutateAll( translationUnit, instantiator ); 214 } 215 216 bool isDtypeStatic( const std::list< TypeDecl* >& baseParams ) { 217 return std::all_of( baseParams.begin(), baseParams.end(), []( TypeDecl * td ) { return ! td->isComplete(); } ); 202 218 } 203 219 … … 479 495 } 480 496 497 template< typename AggrInst > 498 Expression * FixDtypeStatic::fixMemberExpr( AggrInst * inst, MemberExpr * memberExpr ) { 499 // need to cast dtype-static member expressions to their actual type before that type is erased. 500 auto & baseParams = *inst->get_baseParameters(); 501 if ( isDtypeStatic( baseParams ) ) { 502 if ( ! ResolvExpr::typesCompatible( memberExpr->result, memberExpr->member->get_type(), SymTab::Indexer() ) ) { 503 // type of member and type of expression differ, so add cast to actual type 504 return new CastExpr( memberExpr, memberExpr->result->clone() ); 505 } 506 } 507 return memberExpr; 508 } 509 510 Expression * FixDtypeStatic::postmutate( MemberExpr * memberExpr ) { 511 Type * aggrType = memberExpr->aggregate->result; 512 if ( isGenericType( aggrType ) ) { 513 if ( StructInstType * inst = dynamic_cast< StructInstType * >( aggrType ) ) { 514 return fixMemberExpr( inst, memberExpr ); 515 } else if ( UnionInstType * inst = dynamic_cast< UnionInstType * >( aggrType ) ) { 516 return fixMemberExpr( inst, memberExpr ); 517 } 518 } 519 return memberExpr; 520 } 521 481 522 } // namespace GenPoly 482 523 -
src/InitTweak/FixInit.cc
r62194cb r178e4ec 393 393 if ( skipCopyConstruct( result ) ) return; // skip certain non-copyable types 394 394 395 // type may involve type variables, so apply type substitution to get temporary variable's actual type. 395 // type may involve type variables, so apply type substitution to get temporary variable's actual type, 396 // since result type may not be substituted (e.g., if the type does not appear in the parameter list) 396 397 // Use applyFree so that types bound in function pointers are not substituted, e.g. in forall(dtype T) void (*)(T). 397 result = result->clone();398 398 env->applyFree( result ); 399 399 ObjectDecl * tmp = ObjectDecl::newObject( "__tmp", result, nullptr ); … … 570 570 571 571 if ( returnDecl ) { 572 UntypedExpr * assign = new UntypedExpr( new NameExpr( "?=?" ) ); 573 assign->get_args().push_back( new VariableExpr( returnDecl ) ); 574 assign->get_args().push_back( callExpr ); 575 // know the result type of the assignment is the type of the LHS (minus the pointer), so 576 // add that onto the assignment expression so that later steps have the necessary information 577 assign->set_result( returnDecl->get_type()->clone() ); 578 572 ApplicationExpr * assign = createBitwiseAssignment( new VariableExpr( returnDecl ), callExpr ); 579 573 Expression * retExpr = new CommaExpr( assign, new VariableExpr( returnDecl ) ); 580 574 // move env from callExpr to retExpr … … 943 937 } 944 938 945 void addIds( SymTab::Indexer & indexer, const std::list< DeclarationWithType * > & decls ) {946 for ( auto d : decls ) {947 indexer.addId( d );948 }949 }950 951 void addTypes( SymTab::Indexer & indexer, const std::list< TypeDecl * > & tds ) {952 for ( auto td : tds ) {953 indexer.addType( td );954 addIds( indexer, td->assertions );955 }956 }957 958 939 void GenStructMemberCalls::previsit( FunctionDecl * funcDecl ) { 959 940 GuardValue( function ); … … 1012 993 // need to explicitly re-add function parameters to the indexer in order to resolve copy constructors 1013 994 auto guard = makeFuncGuard( [this]() { indexer.enterScope(); }, [this]() { indexer.leaveScope(); } ); 1014 addTypes( indexer, function->type->forall ); 1015 addIds( indexer, function->type->returnVals ); 1016 addIds( indexer, function->type->parameters ); 995 indexer.addFunctionType( function->type ); 1017 996 1018 997 // need to iterate through members in reverse in order for … … 1029 1008 // insert and resolve default/copy constructor call for each field that's unhandled 1030 1009 std::list< Statement * > stmt; 1031 Expression * arg2 = 0;1010 Expression * arg2 = nullptr; 1032 1011 if ( isCopyConstructor( function ) ) { 1033 1012 // if copy ctor, need to pass second-param-of-this-function.field … … 1161 1140 assert( ctorExpr->result && ctorExpr->get_result()->size() == 1 ); 1162 1141 1163 // xxx - ideally we would reuse the temporary generated from the copy constructor passes from within firstArg if it exists and not generate a temporary if it's unnecessary.1164 ObjectDecl * tmp = ObjectDecl::newObject( tempNamer.newName(), ctorExpr->get_result()->clone(), nullptr );1165 declsToAddBefore.push_back( tmp );1166 1167 1142 // xxx - this can be TupleAssignExpr now. Need to properly handle this case. 1168 1143 ApplicationExpr * callExpr = strict_dynamic_cast< ApplicationExpr * > ( ctorExpr->get_callExpr() ); … … 1170 1145 ctorExpr->set_callExpr( nullptr ); 1171 1146 ctorExpr->set_env( nullptr ); 1147 1148 // xxx - ideally we would reuse the temporary generated from the copy constructor passes from within firstArg if it exists and not generate a temporary if it's unnecessary. 1149 ObjectDecl * tmp = ObjectDecl::newObject( tempNamer.newName(), callExpr->args.front()->result->clone(), nullptr ); 1150 declsToAddBefore.push_back( tmp ); 1172 1151 delete ctorExpr; 1173 1152 -
src/InitTweak/InitTweak.cc
r62194cb r178e4ec 12 12 #include "Parser/LinkageSpec.h" // for Spec, isBuiltin, Intrinsic 13 13 #include "ResolvExpr/typeops.h" // for typesCompatibleIgnoreQualifiers 14 #include "SymTab/Autogen.h" 14 15 #include "SymTab/Indexer.h" // for Indexer 15 16 #include "SynTree/Attribute.h" // for Attribute … … 524 525 } 525 526 527 ApplicationExpr * createBitwiseAssignment( Expression * dst, Expression * src ) { 528 static FunctionDecl * assign = nullptr; 529 if ( ! assign ) { 530 // temporary? Generate a fake assignment operator to represent bitwise assignments. 531 // This operator could easily exist as a real function, but it's tricky because nothing should resolve to this function. 532 TypeDecl * td = new TypeDecl( "T", noStorageClasses, nullptr, TypeDecl::Dtype, true ); 533 assign = new FunctionDecl( "?=?", noStorageClasses, LinkageSpec::Intrinsic, SymTab::genAssignType( new TypeInstType( noQualifiers, td->name, td ) ), nullptr ); 534 } 535 if ( dynamic_cast< ReferenceType * >( dst->result ) ) { 536 dst = new AddressExpr( dst ); 537 } else { 538 dst = new CastExpr( dst, new ReferenceType( noQualifiers, dst->result->clone() ) ); 539 } 540 if ( dynamic_cast< ReferenceType * >( src->result ) ) { 541 src = new CastExpr( src, new ReferenceType( noQualifiers, src->result->stripReferences()->clone() ) ); 542 } 543 return new ApplicationExpr( VariableExpr::functionPointer( assign ), { dst, src } ); 544 } 545 526 546 class ConstExprChecker : public Visitor { 527 547 public: -
src/InitTweak/InitTweak.h
r62194cb r178e4ec 35 35 /// returns the first parameter of a constructor/destructor/assignment function 36 36 ObjectDecl * getParamThis( FunctionType * ftype ); 37 38 /// generate a bitwise assignment operation. 39 ApplicationExpr * createBitwiseAssignment( Expression * dst, Expression * src ); 37 40 38 41 /// transform Initializer into an argument list that can be passed to a call expression -
src/ResolvExpr/AlternativeFinder.cc
r62194cb r178e4ec 187 187 expr->accept( *this ); 188 188 if ( failFast && alternatives.empty() ) { 189 PRINT( 190 std::cerr << "No reasonable alternatives for expression " << expr << std::endl; 191 ) 189 192 throw SemanticError( "No reasonable alternatives for expression ", expr ); 190 193 } … … 579 582 /// State to iteratively build a match of parameter expressions to arguments 580 583 struct ArgPack { 581 std::size_t parent; ///< Index of parent pack 584 std::size_t parent; ///< Index of parent pack 582 585 std::unique_ptr<Expression> expr; ///< The argument stored here 583 586 Cost cost; ///< The cost of this argument … … 590 593 unsigned nextExpl; ///< Index of next exploded element 591 594 unsigned explAlt; ///< Index of alternative for nextExpl > 0 592 595 593 596 ArgPack() 594 597 : parent(0), expr(), cost(Cost::zero), env(), need(), have(), openVars(), nextArg(0), 598 595 599 tupleStart(0), nextExpl(0), explAlt(0) {} 596 597 ArgPack(const TypeEnvironment& env, const AssertionSet& need, const AssertionSet& have, 600 601 ArgPack(const TypeEnvironment& env, const AssertionSet& need, const AssertionSet& have, 598 602 const OpenVarSet& openVars) 599 : parent(0), expr(), cost(Cost::zero), env(env), need(need), have(have), 603 : parent(0), expr(), cost(Cost::zero), env(env), need(need), have(have), 600 604 openVars(openVars), nextArg(0), tupleStart(0), nextExpl(0), explAlt(0) {} 601 602 ArgPack(std::size_t parent, Expression* expr, TypeEnvironment&& env, AssertionSet&& need, 603 AssertionSet&& have, OpenVarSet&& openVars, unsigned nextArg, 604 unsigned tupleStart = 0, Cost cost = Cost::zero, unsigned nextExpl = 0, 605 606 ArgPack(std::size_t parent, Expression* expr, TypeEnvironment&& env, AssertionSet&& need, 607 AssertionSet&& have, OpenVarSet&& openVars, unsigned nextArg, 608 unsigned tupleStart = 0, Cost cost = Cost::zero, unsigned nextExpl = 0, 605 609 unsigned explAlt = 0 ) 606 : parent(parent), expr(expr->clone()), cost(cost), env(move(env)), need(move(need)), 610 : parent(parent), expr(expr->clone()), cost(cost), env(move(env)), need(move(need)), 607 611 have(move(have)), openVars(move(openVars)), nextArg(nextArg), tupleStart(tupleStart), 608 612 nextExpl(nextExpl), explAlt(explAlt) {} 609 610 ArgPack(const ArgPack& o, TypeEnvironment&& env, AssertionSet&& need, AssertionSet&& have, 613 614 ArgPack(const ArgPack& o, TypeEnvironment&& env, AssertionSet&& need, AssertionSet&& have, 611 615 OpenVarSet&& openVars, unsigned nextArg, Cost added ) 612 : parent(o.parent), expr(o.expr ? o.expr->clone() : nullptr), cost(o.cost + added), 613 env(move(env)), need(move(need)), have(move(have)), openVars(move(openVars)), 616 : parent(o.parent), expr(o.expr ? o.expr->clone() : nullptr), cost(o.cost + added), 617 env(move(env)), need(move(need)), have(move(have)), openVars(move(openVars)), 614 618 nextArg(nextArg), tupleStart(o.tupleStart), nextExpl(0), explAlt(0) {} 615 619 616 620 /// true iff this pack is in the middle of an exploded argument 617 621 bool hasExpl() const { return nextExpl > 0; } … … 621 625 return args[nextArg-1][explAlt]; 622 626 } 623 627 624 628 /// Ends a tuple expression, consolidating the appropriate actuals 625 629 void endTuple( const std::vector<ArgPack>& packs ) { … … 641 645 642 646 /// Instantiates an argument to match a formal, returns false if no results left 643 bool instantiateArgument( Type* formalType, Initializer* initializer, 644 const ExplodedArgs& args, std::vector<ArgPack>& results, std::size_t& genStart, 647 bool instantiateArgument( Type* formalType, Initializer* initializer, 648 const ExplodedArgs& args, std::vector<ArgPack>& results, std::size_t& genStart, 645 649 const SymTab::Indexer& indexer, unsigned nTuples = 0 ) { 646 650 if ( TupleType* tupleType = dynamic_cast<TupleType*>( formalType ) ) { … … 649 653 for ( Type* type : *tupleType ) { 650 654 // xxx - dropping initializer changes behaviour from previous, but seems correct 651 if ( ! instantiateArgument( 652 type, nullptr, args, results, genStart, indexer, nTuples ) ) 655 if ( ! instantiateArgument( 656 type, nullptr, args, results, genStart, indexer, nTuples ) ) 653 657 return false; 654 658 nTuples = 0; … … 679 683 if ( results[i].hasExpl() ) { 680 684 const ExplodedActual& expl = results[i].getExpl( args ); 681 685 682 686 unsigned nextExpl = results[i].nextExpl + 1; 683 687 if ( nextExpl == expl.exprs.size() ) { … … 686 690 687 691 results.emplace_back( 688 i, expl.exprs[results[i].nextExpl].get(), copy(results[i].env), 689 copy(results[i].need), copy(results[i].have), 690 copy(results[i].openVars), nextArg, nTuples, Cost::zero, nextExpl, 692 i, expl.exprs[results[i].nextExpl].get(), copy(results[i].env), 693 copy(results[i].need), copy(results[i].have), 694 copy(results[i].openVars), nextArg, nTuples, Cost::zero, nextExpl, 691 695 results[i].explAlt ); 692 696 693 697 continue; 694 698 } 695 699 696 700 // finish result when out of arguments 697 701 if ( nextArg >= args.size() ) { 698 ArgPack newResult{ 699 results[i].env, results[i].need, results[i].have, 702 ArgPack newResult{ 703 results[i].env, results[i].need, results[i].have, 700 704 results[i].openVars }; 701 705 newResult.nextArg = nextArg; … … 717 721 718 722 if ( results[i].tupleStart > 0 && Tuples::isTtype( argType ) ) { 719 // the case where a ttype value is passed directly is special, 723 // the case where a ttype value is passed directly is special, 720 724 // e.g. for argument forwarding purposes 721 // xxx - what if passing multiple arguments, last of which is 725 // xxx - what if passing multiple arguments, last of which is 722 726 // ttype? 723 // xxx - what would happen if unify was changed so that unifying 724 // tuple 725 // types flattened both before unifying lists? then pass in 727 // xxx - what would happen if unify was changed so that unifying 728 // tuple 729 // types flattened both before unifying lists? then pass in 726 730 // TupleType (ttype) below. 727 731 --newResult.tupleStart; … … 734 738 735 739 // check unification for ttype before adding to final 736 if ( unify( ttype, argType, newResult.env, newResult.need, newResult.have, 740 if ( unify( ttype, argType, newResult.env, newResult.need, newResult.have, 737 741 newResult.openVars, indexer ) ) { 738 742 finalResults.push_back( move(newResult) ); 739 743 } 740 744 741 745 continue; 742 746 } … … 745 749 for ( std::size_t j = 0; j < args[nextArg].size(); ++j ) { 746 750 const ExplodedActual& expl = args[nextArg][j]; 747 751 748 752 // fresh copies of parent parameters for this iteration 749 753 TypeEnvironment env = results[i].env; … … 755 759 if ( expl.exprs.empty() ) { 756 760 results.emplace_back( 757 results[i], move(env), copy(results[i].need), 761 results[i], move(env), copy(results[i].need), 758 762 copy(results[i].have), move(openVars), nextArg + 1, expl.cost ); 759 763 760 764 continue; 761 765 } … … 763 767 // add new result 764 768 results.emplace_back( 765 i, expl.exprs.front().get(), move(env), copy(results[i].need), 766 copy(results[i].have), move(openVars), nextArg + 1, 769 i, expl.exprs.front().get(), move(env), copy(results[i].need), 770 copy(results[i].have), move(openVars), nextArg + 1, 767 771 nTuples, expl.cost, expl.exprs.size() == 1 ? 0 : 1, j ); 768 772 } … … 790 794 const ExplodedActual& expl = results[i].getExpl( args ); 791 795 Expression* expr = expl.exprs[results[i].nextExpl].get(); 792 796 793 797 TypeEnvironment env = results[i].env; 794 798 AssertionSet need = results[i].need, have = results[i].have; … … 804 808 std::cerr << std::endl; 805 809 ) 806 810 807 811 if ( unify( formalType, actualType, env, need, have, openVars, indexer ) ) { 808 812 unsigned nextExpl = results[i].nextExpl + 1; … … 810 814 nextExpl = 0; 811 815 } 812 813 results.emplace_back( 814 i, expr, move(env), move(need), move(have), move(openVars), nextArg, 816 817 results.emplace_back( 818 i, expr, move(env), move(need), move(have), move(openVars), nextArg, 815 819 nTuples, Cost::zero, nextExpl, results[i].explAlt ); 816 820 } … … 818 822 continue; 819 823 } 820 824 821 825 // use default initializers if out of arguments 822 826 if ( nextArg >= args.size() ) { … … 827 831 OpenVarSet openVars = results[i].openVars; 828 832 829 if ( unify( formalType, cnst->get_type(), env, need, have, openVars, 833 if ( unify( formalType, cnst->get_type(), env, need, have, openVars, 830 834 indexer ) ) { 831 835 results.emplace_back( 832 i, cnstExpr, move(env), move(need), move(have), 836 i, cnstExpr, move(env), move(need), move(have), 833 837 move(openVars), nextArg, nTuples ); 834 838 } … … 849 853 850 854 env.addActual( expl.env, openVars ); 851 855 852 856 // skip empty tuple arguments by (near-)cloning parent into next gen 853 857 if ( expl.exprs.empty() ) { 854 858 results.emplace_back( 855 results[i], move(env), move(need), move(have), move(openVars), 859 results[i], move(env), move(need), move(have), move(openVars), 856 860 nextArg + 1, expl.cost ); 857 861 … … 875 879 // add new result 876 880 results.emplace_back( 877 i, expr, move(env), move(need), move(have), move(openVars), nextArg + 1, 881 i, expr, move(env), move(need), move(have), move(openVars), nextArg + 1, 878 882 nTuples, expl.cost, expl.exprs.size() == 1 ? 0 : 1, j ); 879 883 } … … 883 887 // reset for next parameter 884 888 genStart = genEnd; 885 889 886 890 return genEnd != results.size(); 887 891 } 888 892 889 893 template<typename OutputIterator> 890 void AlternativeFinder::validateFunctionAlternative( const Alternative &func, ArgPack& result, 894 void AlternativeFinder::validateFunctionAlternative( const Alternative &func, ArgPack& result, 891 895 const std::vector<ArgPack>& results, OutputIterator out ) { 892 896 ApplicationExpr *appExpr = new ApplicationExpr( func.expr->clone() ); … … 938 942 for ( DeclarationWithType* formal : funcType->get_parameters() ) { 939 943 ObjectDecl* obj = strict_dynamic_cast< ObjectDecl* >( formal ); 940 if ( ! instantiateArgument( 944 if ( ! instantiateArgument( 941 945 obj->get_type(), obj->get_init(), args, results, genStart, indexer ) ) 942 946 return; … … 956 960 if ( results[i].hasExpl() ) { 957 961 const ExplodedActual& expl = results[i].getExpl( args ); 958 962 959 963 unsigned nextExpl = results[i].nextExpl + 1; 960 964 if ( nextExpl == expl.exprs.size() ) { … … 963 967 964 968 results.emplace_back( 965 i, expl.exprs[results[i].nextExpl].get(), copy(results[i].env), 966 copy(results[i].need), copy(results[i].have), 967 copy(results[i].openVars), nextArg, 0, Cost::zero, nextExpl, 969 i, expl.exprs[results[i].nextExpl].get(), copy(results[i].env), 970 copy(results[i].need), copy(results[i].have), 971 copy(results[i].openVars), nextArg, 0, Cost::zero, nextExpl, 968 972 results[i].explAlt ); 969 973 970 974 continue; 971 975 } … … 990 994 // skip empty tuple arguments by (near-)cloning parent into next gen 991 995 if ( expl.exprs.empty() ) { 992 results.emplace_back( 993 results[i], move(env), copy(results[i].need), 996 results.emplace_back( 997 results[i], move(env), copy(results[i].need), 994 998 copy(results[i].have), move(openVars), nextArg + 1, expl.cost ); 995 999 996 1000 continue; 997 1001 } … … 999 1003 // add new result 1000 1004 results.emplace_back( 1001 i, expl.exprs.front().get(), move(env), copy(results[i].need), 1002 copy(results[i].have), move(openVars), nextArg + 1, 0, 1005 i, expl.exprs.front().get(), move(env), copy(results[i].need), 1006 copy(results[i].have), move(openVars), nextArg + 1, 0, 1003 1007 expl.cost, expl.exprs.size() == 1 ? 0 : 1, j ); 1004 1008 } … … 1050 1054 auto& argE = argExpansions.back(); 1051 1055 argE.reserve( arg.alternatives.size() ); 1052 1056 1053 1057 for ( const Alternative& actual : arg ) { 1054 1058 argE.emplace_back( actual, indexer ); … … 1150 1154 findMinCost( candidates.begin(), candidates.end(), std::back_inserter( winners ) ); 1151 1155 1152 // function may return struct or union value, in which case we need to add alternatives 1153 // for implicitconversions to each of the anonymous members, must happen after findMinCost 1156 // function may return struct or union value, in which case we need to add alternatives 1157 // for implicitconversions to each of the anonymous members, must happen after findMinCost 1154 1158 // since anon conversions are never the cheapest expression 1155 1159 for ( const Alternative & alt : winners ) { … … 1182 1186 for ( Alternative& alt : finder.alternatives ) { 1183 1187 if ( isLvalue( alt.expr ) ) { 1184 alternatives.push_back( 1188 alternatives.push_back( 1185 1189 Alternative{ new AddressExpr( alt.expr->clone() ), alt.env, alt.cost } ); 1186 1190 } // if … … 1231 1235 1232 1236 AltList candidates; 1233 for ( Alternative & alt : finder.alternatives ) {1237 for ( Alternative & alt : finder.alternatives ) { 1234 1238 AssertionSet needAssertions, haveAssertions; 1235 1239 OpenVarSet openVars; … … 1244 1248 // allow casting a tuple to an atomic type (e.g. (int)([1, 2, 3])) 1245 1249 // unification run for side-effects 1246 unify( castExpr->get_result(), alt.expr->get_result(), alt.env, needAssertions, 1250 unify( castExpr->get_result(), alt.expr->get_result(), alt.env, needAssertions, 1247 1251 haveAssertions, openVars, indexer ); 1248 Cost thisCost = castCost( alt.expr->get_result(), castExpr->get_result(), indexer, 1252 Cost thisCost = castCost( alt.expr->get_result(), castExpr->get_result(), indexer, 1249 1253 alt.env ); 1254 PRINT( 1255 std::cerr << "working on cast with result: " << castExpr->result << std::endl; 1256 std::cerr << "and expr type: " << alt.expr->result << std::endl; 1257 std::cerr << "env: " << alt.env << std::endl; 1258 ) 1250 1259 if ( thisCost != Cost::infinity ) { 1260 PRINT( 1261 std::cerr << "has finite cost." << std::endl; 1262 ) 1251 1263 // count one safe conversion for each value that is thrown away 1252 1264 thisCost.incSafe( discardedValues ); 1253 Alternative newAlt( restructureCast( alt.expr->clone(), toType ), alt.env, 1265 Alternative newAlt( restructureCast( alt.expr->clone(), toType ), alt.env, 1254 1266 alt.cost, thisCost ); 1255 inferParameters( needAssertions, haveAssertions, newAlt, openVars, 1267 inferParameters( needAssertions, haveAssertions, newAlt, openVars, 1256 1268 back_inserter( candidates ) ); 1257 1269 } // if … … 1542 1554 void AlternativeFinder::visit( UntypedTupleExpr *tupleExpr ) { 1543 1555 std::vector< AlternativeFinder > subExprAlternatives; 1544 findSubExprs( tupleExpr->get_exprs().begin(), tupleExpr->get_exprs().end(), 1556 findSubExprs( tupleExpr->get_exprs().begin(), tupleExpr->get_exprs().end(), 1545 1557 back_inserter( subExprAlternatives ) ); 1546 1558 std::vector< AltList > possibilities; 1547 combos( subExprAlternatives.begin(), subExprAlternatives.end(), 1559 combos( subExprAlternatives.begin(), subExprAlternatives.end(), 1548 1560 back_inserter( possibilities ) ); 1549 1561 for ( const AltList& alts : possibilities ) { … … 1553 1565 TypeEnvironment compositeEnv; 1554 1566 simpleCombineEnvironments( alts.begin(), alts.end(), compositeEnv ); 1555 alternatives.push_back( 1567 alternatives.push_back( 1556 1568 Alternative{ new TupleExpr( exprs ), compositeEnv, sumCost( alts ) } ); 1557 1569 } // for -
src/ResolvExpr/AlternativeFinder.h
r62194cb r178e4ec 32 32 33 33 namespace ResolvExpr { 34 classArgPack;35 36 /// First index is which argument, second index is which alternative for that argument, 34 struct ArgPack; 35 36 /// First index is which argument, second index is which alternative for that argument, 37 37 /// third index is which exploded element of that alternative 38 38 using ExplodedArgs = std::vector< std::vector< ExplodedActual > >; 39 39 40 40 class AlternativeFinder : public Visitor { 41 41 public: … … 43 43 44 44 AlternativeFinder( const AlternativeFinder& o ) 45 : indexer(o.indexer), alternatives(o.alternatives), env(o.env), 45 : indexer(o.indexer), alternatives(o.alternatives), env(o.env), 46 46 targetType(o.targetType) {} 47 47 48 48 AlternativeFinder( AlternativeFinder&& o ) 49 : indexer(o.indexer), alternatives(std::move(o.alternatives)), env(o.env), 49 : indexer(o.indexer), alternatives(std::move(o.alternatives)), env(o.env), 50 50 targetType(o.targetType) {} 51 51 52 52 AlternativeFinder& operator= ( const AlternativeFinder& o ) { 53 53 if (&o == this) return *this; 54 54 55 55 // horrific nasty hack to rebind references... 56 56 alternatives.~AltList(); … … 61 61 AlternativeFinder& operator= ( AlternativeFinder&& o ) { 62 62 if (&o == this) return *this; 63 63 64 64 // horrific nasty hack to rebind references... 65 65 alternatives.~AltList(); -
src/ResolvExpr/PtrsAssignable.cc
r62194cb r178e4ec 68 68 69 69 void PtrsAssignable::visit( __attribute((unused)) VoidType *voidType ) { 70 if ( ! dynamic_cast< FunctionType* >( dest ) ) { 71 // T * = void * is safe for any T that is not a function type. 72 // xxx - this should be unsafe... 73 result = 1; 74 } // if 70 // T * = void * is disallowed - this is a change from C, where any 71 // void * can be assigned or passed to a non-void pointer without a cast. 75 72 } 76 73 -
src/ResolvExpr/TypeEnvironment.cc
r62194cb r178e4ec 212 212 } 213 213 214 std::ostream & operator<<( std::ostream & out, const TypeEnvironment & env ) { 215 env.print( out ); 216 return out; 217 } 214 218 } // namespace ResolvExpr 215 219 -
src/ResolvExpr/TypeEnvironment.h
r62194cb r178e4ec 86 86 TypeEnvironment *clone() const { return new TypeEnvironment( *this ); } 87 87 88 /// Iteratively adds the environment of a new actual (with allowWidening = false), 88 /// Iteratively adds the environment of a new actual (with allowWidening = false), 89 89 /// and extracts open variables. 90 90 void addActual( const TypeEnvironment& actualEnv, OpenVarSet& openVars ); … … 114 114 return sub.applyFree( type ); 115 115 } 116 117 std::ostream & operator<<( std::ostream & out, const TypeEnvironment & env ); 116 118 } // namespace ResolvExpr 117 119 -
src/SymTab/Autogen.cc
r62194cb r178e4ec 62 62 void previsit( FunctionDecl * functionDecl ); 63 63 64 void previsit( FunctionType * ftype );65 void previsit( PointerType * ptype );66 67 64 void previsit( CompoundStmt * compoundStmt ); 68 65 … … 72 69 unsigned int functionNesting = 0; // current level of nested functions 73 70 74 InitTweak::ManagedTypes managedTypes;75 71 std::vector< FuncData > data; 76 72 }; … … 622 618 // generate ctor/dtors/assign for typedecls, e.g., otype T = int *; 623 619 void AutogenerateRoutines::previsit( TypeDecl * typeDecl ) { 624 visit_children = false;625 620 if ( ! typeDecl->base ) return; 626 621 … … 628 623 TypeFuncGenerator gen( typeDecl, &refType, data, functionNesting, indexer ); 629 624 generateFunctions( gen, declsToAddAfter ); 630 } 631 632 void AutogenerateRoutines::previsit( FunctionType *) { 633 // ensure that we don't add assignment ops for types defined as part of the function 634 visit_children = false; 635 } 636 637 void AutogenerateRoutines::previsit( PointerType *) { 638 // ensure that we don't add assignment ops for types defined as part of the pointer 639 visit_children = false; 625 640 626 } 641 627 … … 645 631 } 646 632 647 void AutogenerateRoutines::previsit( FunctionDecl * functionDecl ) { 648 visit_children = false; 649 // record the existence of this function as appropriate 650 managedTypes.handleDWT( functionDecl ); 651 652 maybeAccept( functionDecl->type, *visitor ); 633 void AutogenerateRoutines::previsit( FunctionDecl * ) { 634 // Track whether we're currently in a function. 635 // Can ignore function type idiosyncrasies, because function type can never 636 // declare a new type. 653 637 functionNesting += 1; 654 maybeAccept( functionDecl->statements, *visitor ); 655 functionNesting -= 1; 638 GuardAction( [this]() { functionNesting -= 1; } ); 656 639 } 657 640 658 641 void AutogenerateRoutines::previsit( CompoundStmt * ) { 659 GuardScope( managedTypes );660 642 GuardScope( structsDone ); 661 643 } -
src/SymTab/Autogen.h
r62194cb r178e4ec 56 56 /// inserts into out a generated call expression to function fname with arguments dstParam and srcParam. Intended to be used with generated ?=?, ?{}, and ^?{} calls. 57 57 template< typename OutputIterator > 58 Statement * genCall( InitTweak::InitExpander & srcParam, Expression * dstParam, const std::string & fname, OutputIterator out, Type * type, bool addCast = false, bool forward = true );58 Statement * genCall( InitTweak::InitExpander & srcParam, Expression * dstParam, const std::string & fname, OutputIterator out, Type * type, Type * addCast = nullptr, bool forward = true ); 59 59 60 60 /// inserts into out a generated call expression to function fname with arguments dstParam and srcParam. Should only be called with non-array types. 61 61 /// optionally returns a statement which must be inserted prior to the containing loop, if there is one 62 62 template< typename OutputIterator > 63 Statement * genScalarCall( InitTweak::InitExpander & srcParam, Expression * dstParam, std::string fname, OutputIterator out, Type * type, bool addCast = false) {63 Statement * genScalarCall( InitTweak::InitExpander & srcParam, Expression * dstParam, std::string fname, OutputIterator out, Type * type, Type * addCast = nullptr ) { 64 64 bool isReferenceCtorDtor = false; 65 65 if ( dynamic_cast< ReferenceType * >( type ) && CodeGen::isCtorDtor( fname ) ) { … … 68 68 fname = "?=?"; 69 69 dstParam = new AddressExpr( dstParam ); 70 addCast = false;70 addCast = nullptr; 71 71 isReferenceCtorDtor = true; 72 72 } … … 83 83 // remove lvalue as a qualifier, this can change to 84 84 // type->get_qualifiers() = Type::Qualifiers(); 85 assert( type ); 86 Type * castType = type->clone(); 85 Type * castType = addCast->clone(); 87 86 castType->get_qualifiers() -= Type::Qualifiers( Type::Lvalue | Type::Const | Type::Volatile | Type::Restrict | Type::Atomic ); 88 87 // castType->set_lvalue( true ); // xxx - might not need this … … 115 114 /// If forward is true, loop goes from 0 to N-1, else N-1 to 0 116 115 template< typename OutputIterator > 117 void genArrayCall( InitTweak::InitExpander & srcParam, Expression *dstParam, const std::string & fname, OutputIterator out, ArrayType *array, bool addCast = false, bool forward = true ) {116 void genArrayCall( InitTweak::InitExpander & srcParam, Expression *dstParam, const std::string & fname, OutputIterator out, ArrayType *array, Type * addCast = nullptr, bool forward = true ) { 118 117 static UniqueName indexName( "_index" ); 119 118 120 119 // for a flexible array member nothing is done -- user must define own assignment 121 if ( ! array->get_dimension() ) return ; 120 if ( ! array->get_dimension() ) return; 121 122 if ( addCast ) { 123 // peel off array layer from cast 124 ArrayType * at = strict_dynamic_cast< ArrayType * >( addCast ); 125 addCast = at->base; 126 } 122 127 123 128 Expression * begin, * end, * update, * cmp; … … 171 176 172 177 template< typename OutputIterator > 173 Statement * genCall( InitTweak::InitExpander & srcParam, Expression * dstParam, const std::string & fname, OutputIterator out, Type * type, booladdCast, bool forward ) {178 Statement * genCall( InitTweak::InitExpander & srcParam, Expression * dstParam, const std::string & fname, OutputIterator out, Type * type, Type * addCast, bool forward ) { 174 179 if ( ArrayType * at = dynamic_cast< ArrayType * >( type ) ) { 175 180 genArrayCall( srcParam, dstParam, fname, out, at, addCast, forward ); … … 191 196 if ( isUnnamedBitfield( obj ) ) return; 192 197 193 bool addCast = (fname == "?{}" || fname == "^?{}") && ( !obj || ( obj && ! obj->get_bitfieldWidth() ) ); 198 Type * addCast = nullptr; 199 if ( (fname == "?{}" || fname == "^?{}") && ( !obj || ( obj && ! obj->get_bitfieldWidth() ) ) ) { 200 assert( dstParam->result ); 201 addCast = dstParam->result; 202 } 194 203 std::list< Statement * > stmts; 195 204 genCall( srcParam, dstParam, fname, back_inserter( stmts ), obj->type, addCast, forward ); -
src/SymTab/Indexer.cc
r62194cb r178e4ec 567 567 } 568 568 569 void Indexer::addIds( const std::list< DeclarationWithType * > & decls ) { 570 for ( auto d : decls ) { 571 addId( d ); 572 } 573 } 574 575 void Indexer::addTypes( const std::list< TypeDecl * > & tds ) { 576 for ( auto td : tds ) { 577 addType( td ); 578 addIds( td->assertions ); 579 } 580 } 581 582 void Indexer::addFunctionType( FunctionType * ftype ) { 583 addTypes( ftype->forall ); 584 addIds( ftype->returnVals ); 585 addIds( ftype->parameters ); 586 } 587 569 588 void Indexer::enterScope() { 570 589 ++scope; -
src/SymTab/Indexer.h
r62194cb r178e4ec 76 76 void addTrait( TraitDecl *decl ); 77 77 78 /// convenience function for adding a list of Ids to the indexer 79 void addIds( const std::list< DeclarationWithType * > & decls ); 80 81 /// convenience function for adding a list of forall parameters to the indexer 82 void addTypes( const std::list< TypeDecl * > & tds ); 83 84 /// convenience function for adding all of the declarations in a function type to the indexer 85 void addFunctionType( FunctionType * ftype ); 86 78 87 bool doDebug = false; ///< Display debugging trace? 79 88 private: -
src/SymTab/Validate.cc
r62194cb r178e4ec 124 124 125 125 /// Associates forward declarations of aggregates with their definitions 126 struct LinkReferenceToTypes final : public WithIndexer {126 struct LinkReferenceToTypes final : public WithIndexer, public WithGuards { 127 127 LinkReferenceToTypes( const Indexer *indexer ); 128 128 void postvisit( TypeInstType *typeInst ); … … 137 137 void postvisit( UnionDecl *unionDecl ); 138 138 void postvisit( TraitDecl * traitDecl ); 139 140 void previsit( StructDecl *structDecl ); 141 void previsit( UnionDecl *unionDecl ); 142 143 void renameGenericParams( std::list< TypeDecl * > & params ); 139 144 140 145 private: … … 147 152 ForwardStructsType forwardStructs; 148 153 ForwardUnionsType forwardUnions; 154 /// true if currently in a generic type body, so that type parameter instances can be renamed appropriately 155 bool inGeneric = false; 149 156 }; 150 157 … … 561 568 } 562 569 570 void LinkReferenceToTypes::renameGenericParams( std::list< TypeDecl * > & params ) { 571 // rename generic type parameters uniquely so that they do not conflict with user-defined function forall parameters, e.g. 572 // forall(otype T) 573 // struct Box { 574 // T x; 575 // }; 576 // forall(otype T) 577 // void f(Box(T) b) { 578 // ... 579 // } 580 // The T in Box and the T in f are different, so internally the naming must reflect that. 581 GuardValue( inGeneric ); 582 inGeneric = ! params.empty(); 583 for ( TypeDecl * td : params ) { 584 td->name = "__" + td->name + "_generic_"; 585 } 586 } 587 588 void LinkReferenceToTypes::previsit( StructDecl * structDecl ) { 589 renameGenericParams( structDecl->parameters ); 590 } 591 592 void LinkReferenceToTypes::previsit( UnionDecl * unionDecl ) { 593 renameGenericParams( unionDecl->parameters ); 594 } 595 563 596 void LinkReferenceToTypes::postvisit( StructDecl *structDecl ) { 564 597 // visit struct members first so that the types of self-referencing members are updated properly … … 588 621 589 622 void LinkReferenceToTypes::postvisit( TypeInstType *typeInst ) { 623 // ensure generic parameter instances are renamed like the base type 624 if ( inGeneric && typeInst->baseType ) typeInst->name = typeInst->baseType->name; 590 625 if ( NamedTypeDecl *namedTypeDecl = local_indexer->lookupType( typeInst->get_name() ) ) { 591 626 if ( TypeDecl *typeDecl = dynamic_cast< TypeDecl * >( namedTypeDecl ) ) { -
src/SynTree/Expression.cc
r62194cb r178e4ec 324 324 return makeSub( refType->get_base() ); 325 325 } else if ( StructInstType * aggInst = dynamic_cast< StructInstType * >( t ) ) { 326 return TypeSubstitution( aggInst->get_baseParameters()->begin(), aggInst->get_baseParameters()->end(), aggInst-> get_parameters().begin() );326 return TypeSubstitution( aggInst->get_baseParameters()->begin(), aggInst->get_baseParameters()->end(), aggInst->parameters.begin() ); 327 327 } else if ( UnionInstType * aggInst = dynamic_cast< UnionInstType * >( t ) ) { 328 return TypeSubstitution( aggInst->get_baseParameters()->begin(), aggInst->get_baseParameters()->end(), aggInst-> get_parameters().begin() );328 return TypeSubstitution( aggInst->get_baseParameters()->begin(), aggInst->get_baseParameters()->end(), aggInst->parameters.begin() ); 329 329 } else { 330 330 assertf( false, "makeSub expects struct or union type for aggregate, but got: %s", toString( t ).c_str() ); -
src/libcfa/concurrency/kernel
r62194cb r178e4ec 120 120 #ifdef __CFA_DEBUG__ 121 121 // Last function to enable preemption on this processor 122 c har * last_enable;122 const char * last_enable; 123 123 #endif 124 124 }; -
src/libcfa/concurrency/monitor.c
r62194cb r178e4ec 823 823 this.monitor_count = thrd->monitors.size; 824 824 825 this.monitors = malloc( this.monitor_count * sizeof( *this.monitors ) );825 this.monitors = (monitor_desc **)malloc( this.monitor_count * sizeof( *this.monitors ) ); 826 826 for( int i = 0; i < this.monitor_count; i++ ) { 827 827 this.monitors[i] = thrd->monitors.list[i]; -
src/libcfa/stdhdr/stddef.h
r62194cb r178e4ec 4 4 // The contents of this file are covered under the licence agreement in the 5 5 // file "LICENCE" distributed with Cforall. 6 // 7 // stddef.h -- 8 // 6 // 7 // stddef.h -- 8 // 9 9 // Author : Peter A. Buhr 10 10 // Created On : Mon Jul 4 23:25:26 2016 … … 12 12 // Last Modified On : Tue Jul 5 20:40:01 2016 13 13 // Update Count : 12 14 // 14 // 15 15 16 16 extern "C" { 17 #include_next <stddef.h> // has internal check for multiple expansion 17 #include_next <stddef.h> // has internal check for multiple expansion 18 #undef NULL 19 #define NULL 0 // define NULL as 0 rather than (void*)0 to take advantage of zero_t 18 20 } // extern "C" 19 21 -
src/libcfa/stdlib
r62194cb r178e4ec 77 77 //printf( "X8\n" ); 78 78 T * ptr = (T *)(void *)malloc( (size_t)sizeof(T) ); // C malloc 79 return memset( ptr, (int)fill, sizeof(T) ); // initial with fill value79 return (T *)memset( ptr, (int)fill, sizeof(T) ); // initial with fill value 80 80 } // alloc 81 81 … … 87 87 //printf( "X10\n" ); 88 88 T * ptr = (T *)(void *)malloc( dim * (size_t)sizeof(T) ); // C malloc 89 return memset( ptr, (int)fill, dim * sizeof(T) );89 return (T *)memset( ptr, (int)fill, dim * sizeof(T) ); 90 90 } // alloc 91 91 92 92 static inline forall( dtype T | sized(T) ) T * alloc( T ptr[], size_t dim ) { 93 93 //printf( "X11\n" ); 94 return ( void *)realloc( (void *)ptr, dim * (size_t)sizeof(T) ); // C realloc94 return (T *)(void *)realloc( (void *)ptr, dim * (size_t)sizeof(T) ); // C realloc 95 95 } // alloc 96 96 forall( dtype T | sized(T) ) T * alloc( T ptr[], size_t dim, char fill ); … … 103 103 //printf( "X14\n" ); 104 104 T * ptr = (T *)memalign( align, sizeof(T) ); 105 return memset( ptr, (int)fill, sizeof(T) );105 return (T *)memset( ptr, (int)fill, sizeof(T) ); 106 106 } // align_alloc 107 107 … … 113 113 //printf( "X16\n" ); 114 114 T * ptr = (T *)memalign( align, dim * sizeof(T) ); 115 return memset( ptr, (int)fill, dim * sizeof(T) );115 return (T *)memset( ptr, (int)fill, dim * sizeof(T) ); 116 116 } // align_alloc 117 117 … … 120 120 static inline forall( dtype T | sized(T) ) T * memset( T * dest, char c ) { 121 121 //printf( "X17\n" ); 122 return memset( dest, c, sizeof(T) );122 return (T *)memset( dest, c, sizeof(T) ); 123 123 } // memset 124 124 extern "C" { void * memcpy( void * dest, const void * src, size_t size ); } // use default C routine for void * 125 125 static inline forall( dtype T | sized(T) ) T * memcpy( T * dest, const T * src ) { 126 126 //printf( "X18\n" ); 127 return memcpy( dest, src, sizeof(T) );127 return (T *)memcpy( dest, src, sizeof(T) ); 128 128 } // memcpy 129 129 … … 131 131 static inline forall( dtype T | sized(T) ) T * memset( T dest[], size_t dim, char c ) { 132 132 //printf( "X19\n" ); 133 return ( void *)memset( dest, c, dim * sizeof(T) ); // C memset133 return (T *)(void *)memset( dest, c, dim * sizeof(T) ); // C memset 134 134 } // memset 135 135 static inline forall( dtype T | sized(T) ) T * memcpy( T dest[], const T src[], size_t dim ) { 136 136 //printf( "X20\n" ); 137 return ( void *)memcpy( dest, src, dim * sizeof(T) ); // C memcpy137 return (T *)(void *)memcpy( dest, src, dim * sizeof(T) ); // C memcpy 138 138 } // memcpy 139 139 -
src/prelude/prelude.cf
r62194cb r178e4ec 403 403 forall( dtype DT ) const volatile DT * ?=?( const volatile DT * volatile &, const volatile DT * ); 404 404 405 forall( dtype DT ) DT * ?=?( DT * &, void * );406 forall( dtype DT ) DT * ?=?( DT * volatile &, void * );407 forall( dtype DT ) const DT * ?=?( const DT * &, void * );408 forall( dtype DT ) const DT * ?=?( const DT * volatile &, void * );409 forall( dtype DT ) const DT * ?=?( const DT * &, const void * );410 forall( dtype DT ) const DT * ?=?( const DT * volatile &, const void * );411 forall( dtype DT ) volatile DT * ?=?( volatile DT * &, void * );412 forall( dtype DT ) volatile DT * ?=?( volatile DT * volatile &, void * );413 forall( dtype DT ) volatile DT * ?=?( volatile DT * &, volatile void * );414 forall( dtype DT ) volatile DT * ?=?( volatile DT * volatile &, volatile void * );415 416 forall( dtype DT ) const volatile DT * ?=?( const volatile DT * &, void * );417 forall( dtype DT ) const volatile DT * ?=?( const volatile DT * volatile &, void * );418 forall( dtype DT ) const volatile DT * ?=?( const volatile DT * &, const void * );419 forall( dtype DT ) const volatile DT * ?=?( const volatile DT * volatile &, const void * );420 forall( dtype DT ) const volatile DT * ?=?( const volatile DT * &, volatile void * );421 forall( dtype DT ) const volatile DT * ?=?( const volatile DT * volatile &, volatile void * );422 forall( dtype DT ) const volatile DT * ?=?( const volatile DT * &, const volatile void * );423 forall( dtype DT ) const volatile DT * ?=?( const volatile DT * volatile &, const volatile void * );424 425 405 forall( dtype DT ) void * ?=?( void * &, DT * ); 426 406 forall( dtype DT ) void * ?=?( void * volatile &, DT * ); … … 441 421 forall( dtype DT ) const volatile void * ?=?( const volatile void * &, const volatile DT * ); 442 422 forall( dtype DT ) const volatile void * ?=?( const volatile void * volatile &, const volatile DT * ); 443 444 void * ?=?( void * &, void * );445 void * ?=?( void * volatile &, void * );446 const void * ?=?( const void * &, void * );447 const void * ?=?( const void * volatile &, void * );448 const void * ?=?( const void * &, const void * );449 const void * ?=?( const void * volatile &, const void * );450 volatile void * ?=?( volatile void * &, void * );451 volatile void * ?=?( volatile void * volatile &, void * );452 volatile void * ?=?( volatile void * &, volatile void * );453 volatile void * ?=?( volatile void * volatile &, volatile void * );454 const volatile void * ?=?( const volatile void * &, void * );455 const volatile void * ?=?( const volatile void * volatile &, void * );456 const volatile void * ?=?( const volatile void * &, const void * );457 const volatile void * ?=?( const volatile void * volatile &, const void * );458 const volatile void * ?=?( const volatile void * &, volatile void * );459 const volatile void * ?=?( const volatile void * volatile &, volatile void * );460 const volatile void * ?=?( const volatile void * &, const volatile void * );461 const volatile void * ?=?( const volatile void * volatile &, const volatile void * );462 423 463 424 //forall( dtype DT ) DT * ?=?( DT * &, zero_t ); … … 781 742 forall( dtype DT ) void ?{}( const volatile DT * &, const volatile DT * ); 782 743 783 forall( dtype DT ) void ?{}( DT * &, void * );784 forall( dtype DT ) void ?{}( const DT * &, void * );785 forall( dtype DT ) void ?{}( const DT * &, const void * );786 forall( dtype DT ) void ?{}( volatile DT * &, void * );787 forall( dtype DT ) void ?{}( volatile DT * &, volatile void * );788 789 forall( dtype DT ) void ?{}( const volatile DT * &, void * );790 forall( dtype DT ) void ?{}( const volatile DT * &, const void * );791 forall( dtype DT ) void ?{}( const volatile DT * &, volatile void * );792 forall( dtype DT ) void ?{}( const volatile DT * &, const volatile void * );793 794 744 forall( dtype DT ) void ?{}( void * &, DT * ); 795 745 forall( dtype DT ) void ?{}( const void * &, DT * ); … … 802 752 forall( dtype DT ) void ?{}( const volatile void * &, const volatile DT * ); 803 753 804 void ?{}( void * &, void * );805 void ?{}( const void * &, void * );806 void ?{}( const void * &, const void * );807 void ?{}( volatile void * &, void * );808 void ?{}( volatile void * &, volatile void * );809 void ?{}( const volatile void * &, void * );810 void ?{}( const volatile void * &, const void * );811 void ?{}( const volatile void * &, volatile void * );812 void ?{}( const volatile void * &, const volatile void * );813 814 754 //forall( dtype DT ) void ?{}( DT * &, zero_t ); 815 755 //forall( dtype DT ) void ?{}( DT * volatile &, zero_t ); -
src/tests/.expect/completeTypeError.txt
r62194cb r178e4ec 1 completeTypeError.c:3 4:1 error: No reasonable alternatives for expression Applying untyped:1 completeTypeError.c:33:1 error: No reasonable alternatives for expression Applying untyped: 2 2 Name: *? 3 3 ...to: 4 4 Name: v 5 5 6 completeTypeError.c:34:1 error: No reasonable alternatives for expression Applying untyped: 7 Name: *? 8 ...to: 9 Name: y 10 11 completeTypeError.c:35:1 error: No reasonable alternatives for expression Applying untyped: 12 Name: foo 13 ...to: 14 Name: v 6 15 7 16 completeTypeError.c:36:1 error: No reasonable alternatives for expression Applying untyped: … … 10 19 Name: v 11 20 12 13 21 completeTypeError.c:37:1 error: No reasonable alternatives for expression Applying untyped: 14 22 Name: quux 15 23 ...to: 16 24 Name: v 17 18 25 19 26 completeTypeError.c:58:1 error: No reasonable alternatives for expression Applying untyped: … … 22 29 Name: y 23 30 24 25 31 completeTypeError.c:59:1 error: No reasonable alternatives for expression Applying untyped: 26 32 Name: quux 27 33 ...to: 28 34 Name: y 29 30 35 31 36 completeTypeError.c:60:1 error: No reasonable alternatives for expression Applying untyped: … … 34 39 Name: y 35 40 36 37 41 completeTypeError.c:72:1 error: No reasonable alternatives for expression Applying untyped: 38 42 Name: baz … … 40 44 Name: z 41 45 42 -
src/tests/Makefile.am
r62194cb r178e4ec 141 141 typedefRedef-ERR1: typedefRedef.c @CFA_BINDIR@/@CFA_NAME@ 142 142 ${CC} ${AM_CFLAGS} ${CFLAGS} -DERR1 ${<} -o ${@} 143 144 alloc-ERROR: alloc.c @CFA_BINDIR@/@CFA_NAME@ 145 ${CC} ${AM_CFLAGS} ${CFLAGS} -DERR1 ${<} -o ${@} -
src/tests/Makefile.in
r62194cb r178e4ec 895 895 ${CC} ${AM_CFLAGS} ${CFLAGS} -DERR1 ${<} -o ${@} 896 896 897 alloc-ERROR: alloc.c @CFA_BINDIR@/@CFA_NAME@ 898 ${CC} ${AM_CFLAGS} ${CFLAGS} -DERR1 ${<} -o ${@} 899 897 900 # Tell versions [3.59,3.63) of GNU make to not export all variables. 898 901 # Otherwise a system limit (for SysV at least) may be exceeded. -
src/tests/alloc.c
r62194cb r178e4ec 32 32 // allocation, non-array types 33 33 34 p = ( void *)malloc( sizeof(*p) ); // C malloc, type unsafe34 p = (int *)(void *)malloc( sizeof(*p) ); // C malloc, type unsafe 35 35 *p = 0xdeadbeef; 36 36 printf( "C malloc %#x\n", *p ); … … 54 54 printf( "\n" ); 55 55 56 p = calloc( dim, sizeof( *p ) ); // C array calloc, type unsafe56 p = (int *)calloc( dim, sizeof( *p ) ); // C array calloc, type unsafe 57 57 printf( "C array calloc, fill 0\n" ); 58 58 for ( int i = 0; i < dim; i += 1 ) { printf( "%#x ", p[i] ); } … … 83 83 printf( "\n" ); 84 84 85 p = ( void *)realloc( p, dim * sizeof(*p) ); // C realloc85 p = (int *)(void *)realloc( p, dim * sizeof(*p) ); // C realloc 86 86 for ( int i = 0; i < dim; i += 1 ) { p[i] = 0xdeadbeef; } 87 87 printf( "C realloc\n" ); … … 256 256 stp = malloc(); 257 257 printf( "\nSHOULD FAIL\n" ); 258 #ifdef ERR1 258 259 p = alloc( stp, dim * sizeof(*stp) ); 259 260 p = memset( stp, 10 ); 260 261 p = memcpy( &st1, &st ); 262 #endif 261 263 } // main 262 264 -
src/tests/completeTypeError.c
r62194cb r178e4ec 12 12 void *v; 13 13 14 //A * x;15 //A * y;16 //B * x;17 //B * z;14 A * x; 15 A * y; 16 B * x; 17 B * z; 18 18 19 19 // okay 20 20 *i; 21 //*x; // picks B22 //*z;21 *x; // picks B 22 *z; 23 23 foo(i); 24 24 bar(i); … … 29 29 bar(v); 30 30 qux(v); 31 foo(v); // questionable, but works at the moment for C compatibility32 31 33 32 // bad 34 33 *v; 35 // *y; 34 *y; 35 foo(v); 36 36 baz(v); 37 37 quux(v); -
src/tests/dtor-early-exit.c
r62194cb r178e4ec 22 22 23 23 struct A { 24 c har * name;24 const char * name; 25 25 int * x; 26 26 }; -
src/tests/init_once.c
r62194cb r178e4ec 72 72 insert( &constructed, &x ); 73 73 74 x.x = malloc(sizeof(int));74 x.x = (int *)malloc(sizeof(int)); 75 75 } 76 76 -
src/tests/multiDimension.c
r62194cb r178e4ec 7 7 printf("default constructing\n"); 8 8 (this.a){ 123 }; 9 this.ptr = malloc(sizeof(int));9 this.ptr = (int *)malloc(sizeof(int)); 10 10 } 11 11 … … 13 13 printf("copy constructing\n"); 14 14 (this.a){ other.a }; 15 this.ptr = malloc(sizeof(int));15 this.ptr = (int *)malloc(sizeof(int)); 16 16 } 17 17 … … 19 19 printf("constructing with %d\n", a); 20 20 (this.a){ a }; 21 this.ptr = malloc(sizeof(int));21 this.ptr = (int *)malloc(sizeof(int)); 22 22 } 23 23 -
src/tests/tupleVariadic.c
r62194cb r178e4ec 73 73 [a0, a1, a2, a3] = args; 74 74 a.size = 4; 75 a.data = malloc(sizeof(int)*a.size);75 a.data = (int *)malloc(sizeof(int)*a.size); 76 76 a.data[0] = a0; 77 77 a.data[1] = a1; -
src/tests/vector/vector_int.c
r62194cb r178e4ec 27 27 vec.last = -1; 28 28 vec.capacity = reserve; 29 vec.data = malloc( sizeof( int ) * reserve );29 vec.data = (int *)malloc( sizeof( int ) * reserve ); 30 30 } 31 31 … … 33 33 vec.last = other.last; 34 34 vec.capacity = other.capacity; 35 vec.data = malloc( sizeof( int ) * other.capacity );35 vec.data = (int *)malloc( sizeof( int ) * other.capacity ); 36 36 for (int i = 0; i < vec.last; i++) { 37 37 vec.data[i] = other.data[i]; … … 45 45 void reserve( vector_int *vec, int reserve ) { 46 46 if ( reserve > vec->capacity ) { 47 vec->data = realloc( vec->data, sizeof( int ) * reserve );47 vec->data = (int *)realloc( vec->data, sizeof( int ) * reserve ); 48 48 vec->capacity = reserve; 49 49 } … … 54 54 if ( vec->last == vec->capacity ) { 55 55 vec->capacity *= 2; 56 vec->data = realloc( vec->data, sizeof( int ) * vec->capacity );56 vec->data = (int *)realloc( vec->data, sizeof( int ) * vec->capacity ); 57 57 } 58 58 vec->data[ vec->last ] = element;
Note: See TracChangeset
for help on using the changeset viewer.