Changes in / [178e4ec:62194cb]


Ignore:
Location:
src
Files:
1 deleted
31 edited

Legend:

Unmodified
Added
Removed
  • src/GenPoly/Box.cc

    r178e4ec r62194cb  
    167167                        Expression *postmutate( OffsetofExpr *offsetofExpr );
    168168                        Expression *postmutate( OffsetPackExpr *offsetPackExpr );
    169                         void premutate( StructDecl * );
    170                         void premutate( UnionDecl * );
    171169
    172170                        void beginScope();
     
    180178                        /// adds type parameters to the layout call; will generate the appropriate parameters if needed
    181179                        void addOtypeParamsToLayoutCall( UntypedExpr *layoutCall, const std::list< Type* > &otypeParams );
    182                         /// change the type of generic aggregate members to char[]
    183                         void mutateMembers( AggregateDecl * aggrDecl );
    184180
    185181                        /// Enters a new scope for type-variables, adding the type variables from ty
     
    14181414
    14191415                void PolyGenericCalculator::premutate( TypedefDecl *typedefDecl ) {
    1420                         assert(false);
    14211416                        beginTypeScope( typedefDecl->get_base() );
    14221417                }
     
    14651460                }
    14661461
    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 
    15061462                void PolyGenericCalculator::premutate( DeclStmt *declStmt ) {
    15071463                        if ( ObjectDecl *objectDecl = dynamic_cast< ObjectDecl *>( declStmt->get_decl() ) ) {
     
    15091465                                        // change initialization of a polymorphic value object to allocate via a VLA
    15101466                                        // (alloca was previously used, but can't be safely used in loops)
    1511                                         ObjectDecl *newBuf = ObjectDecl::newObject( bufNamer.newName(), polyToMonoType( objectDecl->type ), nullptr );
     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 );
    15121471                                        stmtsToAddBefore.push_back( new DeclStmt( noLabels, newBuf ) );
    15131472
  • src/GenPoly/InstantiateGeneric.cc

    r178e4ec r62194cb  
    2727#include "Common/utility.h"            // for deleteAll, cloneAll
    2828#include "GenPoly.h"                   // for isPolyType, typesPolyCompatible
    29 #include "ResolvExpr/typeops.h"
    3029#include "ScopedSet.h"                 // for ScopedSet, ScopedSet<>::iterator
    3130#include "ScrubTyVars.h"               // for ScrubTyVars
     
    152151                return gt;
    153152        }
    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         };
    162153
    163154        /// Mutator pass that replaces concrete instantiations of generic types with actual struct declarations, scoped appropriately
     
    207198
    208199        void instantiateGeneric( std::list< Declaration* > &translationUnit ) {
    209                 PassVisitor<FixDtypeStatic> fixer;
    210200                PassVisitor<GenericInstantiator> instantiator;
    211 
    212                 mutateAll( translationUnit, fixer );
    213201                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(); } );
    218202        }
    219203
     
    495479        }
    496480
    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 
    522481} // namespace GenPoly
    523482
  • src/InitTweak/FixInit.cc

    r178e4ec r62194cb  
    393393                        if ( skipCopyConstruct( result ) ) return; // skip certain non-copyable types
    394394
    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)
     395                        // type may involve type variables, so apply type substitution to get temporary variable's actual type.
    397396                        // Use applyFree so that types bound in function pointers are not substituted, e.g. in forall(dtype T) void (*)(T).
     397                        result = result->clone();
    398398                        env->applyFree( result );
    399399                        ObjectDecl * tmp = ObjectDecl::newObject( "__tmp", result, nullptr );
     
    570570
    571571                        if ( returnDecl ) {
    572                                 ApplicationExpr * assign = createBitwiseAssignment( new VariableExpr( returnDecl ), callExpr );
     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
    573579                                Expression * retExpr = new CommaExpr( assign, new VariableExpr( returnDecl ) );
    574580                                // move env from callExpr to retExpr
     
    937943                }
    938944
     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
    939958                void GenStructMemberCalls::previsit( FunctionDecl * funcDecl ) {
    940959                        GuardValue( function );
     
    9931012                                // need to explicitly re-add function parameters to the indexer in order to resolve copy constructors
    9941013                                auto guard = makeFuncGuard( [this]() { indexer.enterScope(); }, [this]() { indexer.leaveScope(); } );
    995                                 indexer.addFunctionType( function->type );
     1014                                addTypes( indexer, function->type->forall );
     1015                                addIds( indexer, function->type->returnVals );
     1016                                addIds( indexer, function->type->parameters );
    9961017
    9971018                                // need to iterate through members in reverse in order for
     
    10081029                                        // insert and resolve default/copy constructor call for each field that's unhandled
    10091030                                        std::list< Statement * > stmt;
    1010                                         Expression * arg2 = nullptr;
     1031                                        Expression * arg2 = 0;
    10111032                                        if ( isCopyConstructor( function ) ) {
    10121033                                                // if copy ctor, need to pass second-param-of-this-function.field
     
    11401161                        assert( ctorExpr->result && ctorExpr->get_result()->size() == 1 );
    11411162
     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
    11421167                        // xxx - this can be TupleAssignExpr now. Need to properly handle this case.
    11431168                        ApplicationExpr * callExpr = strict_dynamic_cast< ApplicationExpr * > ( ctorExpr->get_callExpr() );
     
    11451170                        ctorExpr->set_callExpr( nullptr );
    11461171                        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 );
    11511172                        delete ctorExpr;
    11521173
  • src/InitTweak/InitTweak.cc

    r178e4ec r62194cb  
    1212#include "Parser/LinkageSpec.h"    // for Spec, isBuiltin, Intrinsic
    1313#include "ResolvExpr/typeops.h"    // for typesCompatibleIgnoreQualifiers
    14 #include "SymTab/Autogen.h"
    1514#include "SymTab/Indexer.h"        // for Indexer
    1615#include "SynTree/Attribute.h"     // for Attribute
     
    525524        }
    526525
    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 
    546526        class ConstExprChecker : public Visitor {
    547527        public:
  • src/InitTweak/InitTweak.h

    r178e4ec r62194cb  
    3535        /// returns the first parameter of a constructor/destructor/assignment function
    3636        ObjectDecl * getParamThis( FunctionType * ftype );
    37 
    38         /// generate a bitwise assignment operation.
    39         ApplicationExpr * createBitwiseAssignment( Expression * dst, Expression * src );
    4037
    4138        /// transform Initializer into an argument list that can be passed to a call expression
  • src/ResolvExpr/AlternativeFinder.cc

    r178e4ec r62194cb  
    187187                expr->accept( *this );
    188188                if ( failFast && alternatives.empty() ) {
    189                         PRINT(
    190                                 std::cerr << "No reasonable alternatives for expression " << expr << std::endl;
    191                         )
    192189                        throw SemanticError( "No reasonable alternatives for expression ", expr );
    193190                }
     
    582579        /// State to iteratively build a match of parameter expressions to arguments
    583580        struct ArgPack {
    584                 std::size_t parent;                ///< Index of parent pack
     581                std::size_t parent;                ///< Index of parent pack 
    585582                std::unique_ptr<Expression> expr;  ///< The argument stored here
    586583                Cost cost;                         ///< The cost of this argument
     
    593590                unsigned nextExpl;                 ///< Index of next exploded element
    594591                unsigned explAlt;                  ///< Index of alternative for nextExpl > 0
    595 
     592               
    596593                ArgPack()
    597594                        : parent(0), expr(), cost(Cost::zero), env(), need(), have(), openVars(), nextArg(0),
    598 
    599595                          tupleStart(0), nextExpl(0), explAlt(0) {}
    600 
    601                 ArgPack(const TypeEnvironment& env, const AssertionSet& need, const AssertionSet& have,
     596               
     597                ArgPack(const TypeEnvironment& env, const AssertionSet& need, const AssertionSet& have, 
    602598                                const OpenVarSet& openVars)
    603                         : parent(0), expr(), cost(Cost::zero), env(env), need(need), have(have),
     599                        : parent(0), expr(), cost(Cost::zero), env(env), need(need), have(have), 
    604600                          openVars(openVars), nextArg(0), tupleStart(0), nextExpl(0), explAlt(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,
     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, 
    609605                                unsigned explAlt = 0 )
    610                         : parent(parent), expr(expr->clone()), cost(cost), env(move(env)), need(move(need)),
     606                        : parent(parent), expr(expr->clone()), cost(cost), env(move(env)), need(move(need)), 
    611607                          have(move(have)), openVars(move(openVars)), nextArg(nextArg), tupleStart(tupleStart),
    612608                          nextExpl(nextExpl), explAlt(explAlt) {}
    613 
    614                 ArgPack(const ArgPack& o, TypeEnvironment&& env, AssertionSet&& need, AssertionSet&& have,
     609               
     610                ArgPack(const ArgPack& o, TypeEnvironment&& env, AssertionSet&& need, AssertionSet&& have, 
    615611                                OpenVarSet&& openVars, unsigned nextArg, Cost added )
    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)),
     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)), 
    618614                          nextArg(nextArg), tupleStart(o.tupleStart), nextExpl(0), explAlt(0) {}
    619 
     615               
    620616                /// true iff this pack is in the middle of an exploded argument
    621617                bool hasExpl() const { return nextExpl > 0; }
     
    625621                        return args[nextArg-1][explAlt];
    626622                }
    627 
     623                         
    628624                /// Ends a tuple expression, consolidating the appropriate actuals
    629625                void endTuple( const std::vector<ArgPack>& packs ) {
     
    645641
    646642        /// Instantiates an argument to match a formal, returns false if no results left
    647         bool instantiateArgument( Type* formalType, Initializer* initializer,
    648                         const ExplodedArgs& args, std::vector<ArgPack>& results, std::size_t& genStart,
     643        bool instantiateArgument( Type* formalType, Initializer* initializer, 
     644                        const ExplodedArgs& args, std::vector<ArgPack>& results, std::size_t& genStart, 
    649645                        const SymTab::Indexer& indexer, unsigned nTuples = 0 ) {
    650646                if ( TupleType* tupleType = dynamic_cast<TupleType*>( formalType ) ) {
     
    653649                        for ( Type* type : *tupleType ) {
    654650                                // xxx - dropping initializer changes behaviour from previous, but seems correct
    655                                 if ( ! instantiateArgument(
    656                                                 type, nullptr, args, results, genStart, indexer, nTuples ) )
     651                                if ( ! instantiateArgument( 
     652                                                type, nullptr, args, results, genStart, indexer, nTuples ) ) 
    657653                                        return false;
    658654                                nTuples = 0;
     
    683679                                        if ( results[i].hasExpl() ) {
    684680                                                const ExplodedActual& expl = results[i].getExpl( args );
    685 
     681                                               
    686682                                                unsigned nextExpl = results[i].nextExpl + 1;
    687683                                                if ( nextExpl == expl.exprs.size() ) {
     
    690686
    691687                                                results.emplace_back(
    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,
     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, 
    695691                                                        results[i].explAlt );
    696 
     692                                               
    697693                                                continue;
    698694                                        }
    699 
     695                                       
    700696                                        // finish result when out of arguments
    701697                                        if ( nextArg >= args.size() ) {
    702                                                 ArgPack newResult{
    703                                                         results[i].env, results[i].need, results[i].have,
     698                                                ArgPack newResult{ 
     699                                                        results[i].env, results[i].need, results[i].have, 
    704700                                                        results[i].openVars };
    705701                                                newResult.nextArg = nextArg;
     
    721717
    722718                                                        if ( results[i].tupleStart > 0 && Tuples::isTtype( argType ) ) {
    723                                                                 // the case where a ttype value is passed directly is special,
     719                                                                // the case where a ttype value is passed directly is special, 
    724720                                                                // e.g. for argument forwarding purposes
    725                                                                 // xxx - what if passing multiple arguments, last of which is
     721                                                                // xxx - what if passing multiple arguments, last of which is 
    726722                                                                //       ttype?
    727                                                                 // xxx - what would happen if unify was changed so that unifying
    728                                                                 //       tuple
    729                                                                 // types flattened both before unifying lists? then pass in
     723                                                                // xxx - what would happen if unify was changed so that unifying 
     724                                                                //       tuple 
     725                                                                // types flattened both before unifying lists? then pass in 
    730726                                                                // TupleType (ttype) below.
    731727                                                                --newResult.tupleStart;
     
    738734
    739735                                                // check unification for ttype before adding to final
    740                                                 if ( unify( ttype, argType, newResult.env, newResult.need, newResult.have,
     736                                                if ( unify( ttype, argType, newResult.env, newResult.need, newResult.have, 
    741737                                                                newResult.openVars, indexer ) ) {
    742738                                                        finalResults.push_back( move(newResult) );
    743739                                                }
    744 
     740                                               
    745741                                                continue;
    746742                                        }
     
    749745                                        for ( std::size_t j = 0; j < args[nextArg].size(); ++j ) {
    750746                                                const ExplodedActual& expl = args[nextArg][j];
    751 
     747                                       
    752748                                                // fresh copies of parent parameters for this iteration
    753749                                                TypeEnvironment env = results[i].env;
     
    759755                                                if ( expl.exprs.empty() ) {
    760756                                                        results.emplace_back(
    761                                                                 results[i], move(env), copy(results[i].need),
     757                                                                results[i], move(env), copy(results[i].need), 
    762758                                                                copy(results[i].have), move(openVars), nextArg + 1, expl.cost );
    763 
     759                                                       
    764760                                                        continue;
    765761                                                }
     
    767763                                                // add new result
    768764                                                results.emplace_back(
    769                                                         i, expl.exprs.front().get(), move(env), copy(results[i].need),
    770                                                         copy(results[i].have), move(openVars), nextArg + 1,
     765                                                        i, expl.exprs.front().get(), move(env), copy(results[i].need), 
     766                                                        copy(results[i].have), move(openVars), nextArg + 1, 
    771767                                                        nTuples, expl.cost, expl.exprs.size() == 1 ? 0 : 1, j );
    772768                                        }
     
    794790                                const ExplodedActual& expl = results[i].getExpl( args );
    795791                                Expression* expr = expl.exprs[results[i].nextExpl].get();
    796 
     792                               
    797793                                TypeEnvironment env = results[i].env;
    798794                                AssertionSet need = results[i].need, have = results[i].have;
     
    808804                                        std::cerr << std::endl;
    809805                                )
    810 
     806                               
    811807                                if ( unify( formalType, actualType, env, need, have, openVars, indexer ) ) {
    812808                                        unsigned nextExpl = results[i].nextExpl + 1;
     
    814810                                                nextExpl = 0;
    815811                                        }
    816 
    817                                         results.emplace_back(
    818                                                 i, expr, move(env), move(need), move(have), move(openVars), nextArg,
     812                                       
     813                                        results.emplace_back( 
     814                                                i, expr, move(env), move(need), move(have), move(openVars), nextArg, 
    819815                                                nTuples, Cost::zero, nextExpl, results[i].explAlt );
    820816                                }
     
    822818                                continue;
    823819                        }
    824 
     820                       
    825821                        // use default initializers if out of arguments
    826822                        if ( nextArg >= args.size() ) {
     
    831827                                                OpenVarSet openVars = results[i].openVars;
    832828
    833                                                 if ( unify( formalType, cnst->get_type(), env, need, have, openVars,
     829                                                if ( unify( formalType, cnst->get_type(), env, need, have, openVars, 
    834830                                                                indexer ) ) {
    835831                                                        results.emplace_back(
    836                                                                 i, cnstExpr, move(env), move(need), move(have),
     832                                                                i, cnstExpr, move(env), move(need), move(have), 
    837833                                                                move(openVars), nextArg, nTuples );
    838834                                                }
     
    853849
    854850                                env.addActual( expl.env, openVars );
    855 
     851                               
    856852                                // skip empty tuple arguments by (near-)cloning parent into next gen
    857853                                if ( expl.exprs.empty() ) {
    858854                                        results.emplace_back(
    859                                                 results[i], move(env), move(need), move(have), move(openVars),
     855                                                results[i], move(env), move(need), move(have), move(openVars), 
    860856                                                nextArg + 1, expl.cost );
    861857
     
    879875                                        // add new result
    880876                                        results.emplace_back(
    881                                                 i, expr, move(env), move(need), move(have), move(openVars), nextArg + 1,
     877                                                i, expr, move(env), move(need), move(have), move(openVars), nextArg + 1, 
    882878                                                nTuples, expl.cost, expl.exprs.size() == 1 ? 0 : 1, j );
    883879                                }
     
    887883                // reset for next parameter
    888884                genStart = genEnd;
    889 
     885               
    890886                return genEnd != results.size();
    891887        }
    892888
    893889        template<typename OutputIterator>
    894         void AlternativeFinder::validateFunctionAlternative( const Alternative &func, ArgPack& result,
     890        void AlternativeFinder::validateFunctionAlternative( const Alternative &func, ArgPack& result, 
    895891                        const std::vector<ArgPack>& results, OutputIterator out ) {
    896892                ApplicationExpr *appExpr = new ApplicationExpr( func.expr->clone() );
     
    942938                for ( DeclarationWithType* formal : funcType->get_parameters() ) {
    943939                        ObjectDecl* obj = strict_dynamic_cast< ObjectDecl* >( formal );
    944                         if ( ! instantiateArgument(
     940                        if ( ! instantiateArgument( 
    945941                                        obj->get_type(), obj->get_init(), args, results, genStart, indexer ) )
    946942                                return;
     
    960956                                        if ( results[i].hasExpl() ) {
    961957                                                const ExplodedActual& expl = results[i].getExpl( args );
    962 
     958                                               
    963959                                                unsigned nextExpl = results[i].nextExpl + 1;
    964960                                                if ( nextExpl == expl.exprs.size() ) {
     
    967963
    968964                                                results.emplace_back(
    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,
     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, 
    972968                                                        results[i].explAlt );
    973 
     969                                               
    974970                                                continue;
    975971                                        }
     
    994990                                                // skip empty tuple arguments by (near-)cloning parent into next gen
    995991                                                if ( expl.exprs.empty() ) {
    996                                                         results.emplace_back(
    997                                                                 results[i], move(env), copy(results[i].need),
     992                                                        results.emplace_back( 
     993                                                                results[i], move(env), copy(results[i].need), 
    998994                                                                copy(results[i].have), move(openVars), nextArg + 1, expl.cost );
    999 
     995                                                       
    1000996                                                        continue;
    1001997                                                }
     
    1003999                                                // add new result
    10041000                                                results.emplace_back(
    1005                                                         i, expl.exprs.front().get(), move(env), copy(results[i].need),
    1006                                                         copy(results[i].have), move(openVars), nextArg + 1, 0,
     1001                                                        i, expl.exprs.front().get(), move(env), copy(results[i].need), 
     1002                                                        copy(results[i].have), move(openVars), nextArg + 1, 0, 
    10071003                                                        expl.cost, expl.exprs.size() == 1 ? 0 : 1, j );
    10081004                                        }
     
    10541050                        auto& argE = argExpansions.back();
    10551051                        argE.reserve( arg.alternatives.size() );
    1056 
     1052                       
    10571053                        for ( const Alternative& actual : arg ) {
    10581054                                argE.emplace_back( actual, indexer );
     
    11541150                findMinCost( candidates.begin(), candidates.end(), std::back_inserter( winners ) );
    11551151
    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
     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 
    11581154                // since anon conversions are never the cheapest expression
    11591155                for ( const Alternative & alt : winners ) {
     
    11861182                for ( Alternative& alt : finder.alternatives ) {
    11871183                        if ( isLvalue( alt.expr ) ) {
    1188                                 alternatives.push_back(
     1184                                alternatives.push_back( 
    11891185                                        Alternative{ new AddressExpr( alt.expr->clone() ), alt.env, alt.cost } );
    11901186                        } // if
     
    12351231
    12361232                AltList candidates;
    1237                 for ( Alternative & alt : finder.alternatives ) {
     1233                for ( Alternative& alt : finder.alternatives ) {
    12381234                        AssertionSet needAssertions, haveAssertions;
    12391235                        OpenVarSet openVars;
     
    12481244                        // allow casting a tuple to an atomic type (e.g. (int)([1, 2, 3]))
    12491245                        // unification run for side-effects
    1250                         unify( castExpr->get_result(), alt.expr->get_result(), alt.env, needAssertions,
     1246                        unify( castExpr->get_result(), alt.expr->get_result(), alt.env, needAssertions, 
    12511247                                haveAssertions, openVars, indexer );
    1252                         Cost thisCost = castCost( alt.expr->get_result(), castExpr->get_result(), indexer,
     1248                        Cost thisCost = castCost( alt.expr->get_result(), castExpr->get_result(), indexer, 
    12531249                                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                         )
    12591250                        if ( thisCost != Cost::infinity ) {
    1260                                 PRINT(
    1261                                         std::cerr << "has finite cost." << std::endl;
    1262                                 )
    12631251                                // count one safe conversion for each value that is thrown away
    12641252                                thisCost.incSafe( discardedValues );
    1265                                 Alternative newAlt( restructureCast( alt.expr->clone(), toType ), alt.env,
     1253                                Alternative newAlt( restructureCast( alt.expr->clone(), toType ), alt.env, 
    12661254                                        alt.cost, thisCost );
    1267                                 inferParameters( needAssertions, haveAssertions, newAlt, openVars,
     1255                                inferParameters( needAssertions, haveAssertions, newAlt, openVars, 
    12681256                                        back_inserter( candidates ) );
    12691257                        } // if
     
    15541542        void AlternativeFinder::visit( UntypedTupleExpr *tupleExpr ) {
    15551543                std::vector< AlternativeFinder > subExprAlternatives;
    1556                 findSubExprs( tupleExpr->get_exprs().begin(), tupleExpr->get_exprs().end(),
     1544                findSubExprs( tupleExpr->get_exprs().begin(), tupleExpr->get_exprs().end(), 
    15571545                        back_inserter( subExprAlternatives ) );
    15581546                std::vector< AltList > possibilities;
    1559                 combos( subExprAlternatives.begin(), subExprAlternatives.end(),
     1547                combos( subExprAlternatives.begin(), subExprAlternatives.end(), 
    15601548                        back_inserter( possibilities ) );
    15611549                for ( const AltList& alts : possibilities ) {
     
    15651553                        TypeEnvironment compositeEnv;
    15661554                        simpleCombineEnvironments( alts.begin(), alts.end(), compositeEnv );
    1567                         alternatives.push_back(
     1555                        alternatives.push_back( 
    15681556                                Alternative{ new TupleExpr( exprs ), compositeEnv, sumCost( alts ) } );
    15691557                } // for
  • src/ResolvExpr/AlternativeFinder.h

    r178e4ec r62194cb  
    3232
    3333namespace ResolvExpr {
    34         struct ArgPack;
    35 
    36         /// First index is which argument, second index is which alternative for that argument,
     34        class ArgPack;
     35       
     36        /// First index is which argument, second index is which alternative for that argument, 
    3737        /// third index is which exploded element of that alternative
    3838        using ExplodedArgs = std::vector< std::vector< ExplodedActual > >;
    39 
     39       
    4040        class AlternativeFinder : public Visitor {
    4141          public:
     
    4343
    4444                AlternativeFinder( const AlternativeFinder& o )
    45                         : indexer(o.indexer), alternatives(o.alternatives), env(o.env),
     45                        : indexer(o.indexer), alternatives(o.alternatives), env(o.env), 
    4646                          targetType(o.targetType) {}
    47 
     47               
    4848                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), 
    5050                          targetType(o.targetType) {}
    51 
     51               
    5252                AlternativeFinder& operator= ( const AlternativeFinder& o ) {
    5353                        if (&o == this) return *this;
    54 
     54                       
    5555                        // horrific nasty hack to rebind references...
    5656                        alternatives.~AltList();
     
    6161                AlternativeFinder& operator= ( AlternativeFinder&& o ) {
    6262                        if (&o == this) return *this;
    63 
     63                       
    6464                        // horrific nasty hack to rebind references...
    6565                        alternatives.~AltList();
  • src/ResolvExpr/PtrsAssignable.cc

    r178e4ec r62194cb  
    6868
    6969        void PtrsAssignable::visit( __attribute((unused)) VoidType *voidType ) {
    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.
     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
    7275        }
    7376
  • src/ResolvExpr/TypeEnvironment.cc

    r178e4ec r62194cb  
    212212        }
    213213
    214         std::ostream & operator<<( std::ostream & out, const TypeEnvironment & env ) {
    215                 env.print( out );
    216                 return out;
    217         }
    218214} // namespace ResolvExpr
    219215
  • src/ResolvExpr/TypeEnvironment.h

    r178e4ec r62194cb  
    8686                TypeEnvironment *clone() const { return new TypeEnvironment( *this ); }
    8787
    88                 /// Iteratively adds the environment of a new actual (with allowWidening = false),
     88                /// Iteratively adds the environment of a new actual (with allowWidening = false), 
    8989                /// and extracts open variables.
    9090                void addActual( const TypeEnvironment& actualEnv, OpenVarSet& openVars );
     
    114114                return sub.applyFree( type );
    115115        }
    116 
    117         std::ostream & operator<<( std::ostream & out, const TypeEnvironment & env );
    118116} // namespace ResolvExpr
    119117
  • src/SymTab/Autogen.cc

    r178e4ec r62194cb  
    6262                void previsit( FunctionDecl * functionDecl );
    6363
     64                void previsit( FunctionType * ftype );
     65                void previsit( PointerType * ptype );
     66
    6467                void previsit( CompoundStmt * compoundStmt );
    6568
     
    6972                unsigned int functionNesting = 0;     // current level of nested functions
    7073
     74                InitTweak::ManagedTypes managedTypes;
    7175                std::vector< FuncData > data;
    7276        };
     
    618622        // generate ctor/dtors/assign for typedecls, e.g., otype T = int *;
    619623        void AutogenerateRoutines::previsit( TypeDecl * typeDecl ) {
     624                visit_children = false;
    620625                if ( ! typeDecl->base ) return;
    621626
     
    623628                TypeFuncGenerator gen( typeDecl, &refType, data, functionNesting, indexer );
    624629                generateFunctions( gen, declsToAddAfter );
    625 
     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;
    626640        }
    627641
     
    631645        }
    632646
    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.
     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 );
    637653                functionNesting += 1;
    638                 GuardAction( [this]()  { functionNesting -= 1; } );
     654                maybeAccept( functionDecl->statements, *visitor );
     655                functionNesting -= 1;
    639656        }
    640657
    641658        void AutogenerateRoutines::previsit( CompoundStmt * ) {
     659                GuardScope( managedTypes );
    642660                GuardScope( structsDone );
    643661        }
  • src/SymTab/Autogen.h

    r178e4ec r62194cb  
    5656        /// inserts into out a generated call expression to function fname with arguments dstParam and srcParam. Intended to be used with generated ?=?, ?{}, and ^?{} calls.
    5757        template< typename OutputIterator >
    58         Statement * genCall( InitTweak::InitExpander & srcParam, Expression * dstParam, const std::string & fname, OutputIterator out, Type * type, Type * addCast = nullptr, bool forward = true );
     58        Statement * genCall( InitTweak::InitExpander & srcParam, Expression * dstParam, const std::string & fname, OutputIterator out, Type * type, bool addCast = false, bool forward = true );
    5959
    6060        /// inserts into out a generated call expression to function fname with arguments dstParam and srcParam. Should only be called with non-array types.
    6161        /// optionally returns a statement which must be inserted prior to the containing loop, if there is one
    6262        template< typename OutputIterator >
    63         Statement * genScalarCall( InitTweak::InitExpander & srcParam, Expression * dstParam, std::string fname, OutputIterator out, Type * type, Type * addCast = nullptr ) {
     63        Statement * genScalarCall( InitTweak::InitExpander & srcParam, Expression * dstParam, std::string fname, OutputIterator out, Type * type, bool addCast = false ) {
    6464                bool isReferenceCtorDtor = false;
    6565                if ( dynamic_cast< ReferenceType * >( type ) && CodeGen::isCtorDtor( fname ) ) {
     
    6868                        fname = "?=?";
    6969                        dstParam = new AddressExpr( dstParam );
    70                         addCast = nullptr;
     70                        addCast = false;
    7171                        isReferenceCtorDtor = true;
    7272                }
     
    8383                        // remove lvalue as a qualifier, this can change to
    8484                        //   type->get_qualifiers() = Type::Qualifiers();
    85                         Type * castType = addCast->clone();
     85                        assert( type );
     86                        Type * castType = type->clone();
    8687                        castType->get_qualifiers() -= Type::Qualifiers( Type::Lvalue | Type::Const | Type::Volatile | Type::Restrict | Type::Atomic );
    8788                        // castType->set_lvalue( true ); // xxx - might not need this
     
    114115        /// If forward is true, loop goes from 0 to N-1, else N-1 to 0
    115116        template< typename OutputIterator >
    116         void genArrayCall( InitTweak::InitExpander & srcParam, Expression *dstParam, const std::string & fname, OutputIterator out, ArrayType *array, Type * addCast = nullptr, bool forward = true ) {
     117        void genArrayCall( InitTweak::InitExpander & srcParam, Expression *dstParam, const std::string & fname, OutputIterator out, ArrayType *array, bool addCast = false, bool forward = true ) {
    117118                static UniqueName indexName( "_index" );
    118119
    119120                // for a flexible array member nothing is done -- user must define own assignment
    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                 }
     121                if ( ! array->get_dimension() ) return ;
    127122
    128123                Expression * begin, * end, * update, * cmp;
     
    176171
    177172        template< typename OutputIterator >
    178         Statement * genCall( InitTweak::InitExpander & srcParam, Expression * dstParam, const std::string & fname, OutputIterator out, Type * type, Type * addCast, bool forward ) {
     173        Statement * genCall( InitTweak::InitExpander & srcParam, Expression * dstParam, const std::string & fname, OutputIterator out, Type * type, bool addCast, bool forward ) {
    179174                if ( ArrayType * at = dynamic_cast< ArrayType * >( type ) ) {
    180175                        genArrayCall( srcParam, dstParam, fname, out, at, addCast, forward );
     
    196191                if ( isUnnamedBitfield( obj ) ) return;
    197192
    198                 Type * addCast = nullptr;
    199                 if ( (fname == "?{}" || fname == "^?{}") && ( !obj || ( obj && ! obj->get_bitfieldWidth() ) ) ) {
    200                         assert( dstParam->result );
    201                         addCast = dstParam->result;
    202                 }
     193                bool addCast = (fname == "?{}" || fname == "^?{}") && ( !obj || ( obj && ! obj->get_bitfieldWidth() ) );
    203194                std::list< Statement * > stmts;
    204195                genCall( srcParam, dstParam, fname, back_inserter( stmts ), obj->type, addCast, forward );
  • src/SymTab/Indexer.cc

    r178e4ec r62194cb  
    567567        }
    568568
    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 
    588569        void Indexer::enterScope() {
    589570                ++scope;
  • src/SymTab/Indexer.h

    r178e4ec r62194cb  
    7676                void addTrait( TraitDecl *decl );
    7777
    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 
    8778                bool doDebug = false; ///< Display debugging trace?
    8879          private:
  • src/SymTab/Validate.cc

    r178e4ec r62194cb  
    124124
    125125        /// Associates forward declarations of aggregates with their definitions
    126         struct LinkReferenceToTypes final : public WithIndexer, public WithGuards {
     126        struct LinkReferenceToTypes final : public WithIndexer {
    127127                LinkReferenceToTypes( const Indexer *indexer );
    128128                void postvisit( TypeInstType *typeInst );
     
    137137                void postvisit( UnionDecl *unionDecl );
    138138                void postvisit( TraitDecl * traitDecl );
    139 
    140                 void previsit( StructDecl *structDecl );
    141                 void previsit( UnionDecl *unionDecl );
    142 
    143                 void renameGenericParams( std::list< TypeDecl * > & params );
    144139
    145140          private:
     
    152147                ForwardStructsType forwardStructs;
    153148                ForwardUnionsType forwardUnions;
    154                 /// true if currently in a generic type body, so that type parameter instances can be renamed appropriately
    155                 bool inGeneric = false;
    156149        };
    157150
     
    568561        }
    569562
    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 
    596563        void LinkReferenceToTypes::postvisit( StructDecl *structDecl ) {
    597564                // visit struct members first so that the types of self-referencing members are updated properly
     
    621588
    622589        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;
    625590                if ( NamedTypeDecl *namedTypeDecl = local_indexer->lookupType( typeInst->get_name() ) ) {
    626591                        if ( TypeDecl *typeDecl = dynamic_cast< TypeDecl * >( namedTypeDecl ) ) {
  • src/SynTree/Expression.cc

    r178e4ec r62194cb  
    324324                        return makeSub( refType->get_base() );
    325325                } else if ( StructInstType * aggInst = dynamic_cast< StructInstType * >( t ) ) {
    326                         return TypeSubstitution( aggInst->get_baseParameters()->begin(), aggInst->get_baseParameters()->end(), aggInst->parameters.begin() );
     326                        return TypeSubstitution( aggInst->get_baseParameters()->begin(), aggInst->get_baseParameters()->end(), aggInst->get_parameters().begin() );
    327327                } else if ( UnionInstType * aggInst = dynamic_cast< UnionInstType * >( t ) ) {
    328                         return TypeSubstitution( aggInst->get_baseParameters()->begin(), aggInst->get_baseParameters()->end(), aggInst->parameters.begin() );
     328                        return TypeSubstitution( aggInst->get_baseParameters()->begin(), aggInst->get_baseParameters()->end(), aggInst->get_parameters().begin() );
    329329                } else {
    330330                        assertf( false, "makeSub expects struct or union type for aggregate, but got: %s", toString( t ).c_str() );
  • src/libcfa/concurrency/kernel

    r178e4ec r62194cb  
    120120#ifdef __CFA_DEBUG__
    121121        // Last function to enable preemption on this processor
    122         const char * last_enable;
     122        char * last_enable;
    123123#endif
    124124};
  • src/libcfa/concurrency/monitor.c

    r178e4ec r62194cb  
    823823                this.monitor_count = thrd->monitors.size;
    824824
    825                 this.monitors = (monitor_desc **)malloc( this.monitor_count * sizeof( *this.monitors ) );
     825                this.monitors = malloc( this.monitor_count * sizeof( *this.monitors ) );
    826826                for( int i = 0; i < this.monitor_count; i++ ) {
    827827                        this.monitors[i] = thrd->monitors.list[i];
  • src/libcfa/stdhdr/stddef.h

    r178e4ec r62194cb  
    44// The contents of this file are covered under the licence agreement in the
    55// file "LICENCE" distributed with Cforall.
    6 //
    7 // stddef.h --
    8 //
     6// 
     7// stddef.h -- 
     8// 
    99// Author           : Peter A. Buhr
    1010// Created On       : Mon Jul  4 23:25:26 2016
     
    1212// Last Modified On : Tue Jul  5 20:40:01 2016
    1313// Update Count     : 12
    14 //
     14// 
    1515
    1616extern "C" {
    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
     17#include_next <stddef.h>                                                                // has internal check for multiple expansion
    2018} // extern "C"
    2119
  • src/libcfa/stdlib

    r178e4ec r62194cb  
    7777        //printf( "X8\n" );
    7878        T * ptr = (T *)(void *)malloc( (size_t)sizeof(T) );     // C malloc
    79     return (T *)memset( ptr, (int)fill, sizeof(T) );                    // initial with fill value
     79    return memset( ptr, (int)fill, sizeof(T) );                 // initial with fill value
    8080} // alloc
    8181
     
    8787        //printf( "X10\n" );
    8888        T * ptr = (T *)(void *)malloc( dim * (size_t)sizeof(T) ); // C malloc
    89     return (T *)memset( ptr, (int)fill, dim * sizeof(T) );
     89    return memset( ptr, (int)fill, dim * sizeof(T) );
    9090} // alloc
    9191
    9292static inline forall( dtype T | sized(T) ) T * alloc( T ptr[], size_t dim ) {
    9393        //printf( "X11\n" );
    94         return (T *)(void *)realloc( (void *)ptr, dim * (size_t)sizeof(T) ); // C realloc
     94        return (void *)realloc( (void *)ptr, dim * (size_t)sizeof(T) ); // C realloc
    9595} // alloc
    9696forall( dtype T | sized(T) ) T * alloc( T ptr[], size_t dim, char fill );
     
    103103        //printf( "X14\n" );
    104104    T * ptr = (T *)memalign( align, sizeof(T) );
    105     return (T *)memset( ptr, (int)fill, sizeof(T) );
     105    return memset( ptr, (int)fill, sizeof(T) );
    106106} // align_alloc
    107107
     
    113113        //printf( "X16\n" );
    114114    T * ptr = (T *)memalign( align, dim * sizeof(T) );
    115     return (T *)memset( ptr, (int)fill, dim * sizeof(T) );
     115    return memset( ptr, (int)fill, dim * sizeof(T) );
    116116} // align_alloc
    117117
     
    120120static inline forall( dtype T | sized(T) ) T * memset( T * dest, char c ) {
    121121        //printf( "X17\n" );
    122         return (T *)memset( dest, c, sizeof(T) );
     122        return memset( dest, c, sizeof(T) );
    123123} // memset
    124124extern "C" { void * memcpy( void * dest, const void * src, size_t size ); } // use default C routine for void *
    125125static inline forall( dtype T | sized(T) ) T * memcpy( T * dest, const T * src ) {
    126126        //printf( "X18\n" );
    127         return (T *)memcpy( dest, src, sizeof(T) );
     127        return memcpy( dest, src, sizeof(T) );
    128128} // memcpy
    129129
     
    131131static inline forall( dtype T | sized(T) ) T * memset( T dest[], size_t dim, char c ) {
    132132        //printf( "X19\n" );
    133         return (T *)(void *)memset( dest, c, dim * sizeof(T) ); // C memset
     133        return (void *)memset( dest, c, dim * sizeof(T) );      // C memset
    134134} // memset
    135135static inline forall( dtype T | sized(T) ) T * memcpy( T dest[], const T src[], size_t dim ) {
    136136        //printf( "X20\n" );
    137         return (T *)(void *)memcpy( dest, src, dim * sizeof(T) ); // C memcpy
     137        return (void *)memcpy( dest, src, dim * sizeof(T) ); // C memcpy
    138138} // memcpy
    139139
  • src/prelude/prelude.cf

    r178e4ec r62194cb  
    403403forall( dtype DT ) const volatile DT *  ?=?( const volatile  DT * volatile &, const volatile    DT * );
    404404
     405forall( dtype DT ) DT *                 ?=?(                 DT *          &,                   void * );
     406forall( dtype DT ) DT *                 ?=?(                 DT * volatile &,                   void * );
     407forall( dtype DT ) const DT *           ?=?( const           DT *          &,                   void * );
     408forall( dtype DT ) const DT *           ?=?( const           DT * volatile &,                   void * );
     409forall( dtype DT ) const DT *           ?=?( const           DT *          &, const             void * );
     410forall( dtype DT ) const DT *           ?=?( const           DT * volatile &, const             void * );
     411forall( dtype DT ) volatile DT *        ?=?(       volatile  DT *          &,                   void * );
     412forall( dtype DT ) volatile DT *        ?=?(       volatile  DT * volatile &,                   void * );
     413forall( dtype DT ) volatile DT *        ?=?(       volatile  DT *          &,       volatile    void * );
     414forall( dtype DT ) volatile DT *        ?=?(       volatile  DT * volatile &,       volatile    void * );
     415
     416forall( dtype DT ) const volatile DT *  ?=?( const volatile  DT *          &,                   void * );
     417forall( dtype DT ) const volatile DT *  ?=?( const volatile  DT * volatile &,                   void * );
     418forall( dtype DT ) const volatile DT *  ?=?( const volatile  DT *          &, const             void * );
     419forall( dtype DT ) const volatile DT *  ?=?( const volatile  DT * volatile &, const             void * );
     420forall( dtype DT ) const volatile DT *  ?=?( const volatile  DT *          &,       volatile    void * );
     421forall( dtype DT ) const volatile DT *  ?=?( const volatile  DT * volatile &,       volatile    void * );
     422forall( dtype DT ) const volatile DT *  ?=?( const volatile  DT *          &, const volatile    void * );
     423forall( dtype DT ) const volatile DT *  ?=?( const volatile  DT * volatile &, const volatile    void * );
     424
    405425forall( dtype DT ) void *                ?=?(                void *          &,                 DT * );
    406426forall( dtype DT ) void *                ?=?(                void * volatile &,                 DT * );
     
    421441forall( dtype DT ) const volatile void * ?=?( const volatile void *          &, const volatile  DT * );
    422442forall( dtype DT ) const volatile void * ?=?( const volatile void * volatile &, const volatile  DT * );
     443
     444void *                  ?=?(                void *          &,                void * );
     445void *                  ?=?(                void * volatile &,                void * );
     446const void *            ?=?( const          void *          &,                void * );
     447const void *            ?=?( const          void * volatile &,                void * );
     448const void *            ?=?( const          void *          &, const          void * );
     449const void *            ?=?( const          void * volatile &, const          void * );
     450volatile void *         ?=?(       volatile void *          &,                void * );
     451volatile void *         ?=?(       volatile void * volatile &,                void * );
     452volatile void *         ?=?(       volatile void *          &,       volatile void * );
     453volatile void *         ?=?(       volatile void * volatile &,       volatile void * );
     454const volatile void *   ?=?( const volatile void *          &,                void * );
     455const volatile void *   ?=?( const volatile void * volatile &,                void * );
     456const volatile void *   ?=?( const volatile void *          &, const          void * );
     457const volatile void *   ?=?( const volatile void * volatile &, const          void * );
     458const volatile void *   ?=?( const volatile void *          &,       volatile void * );
     459const volatile void *   ?=?( const volatile void * volatile &,       volatile void * );
     460const volatile void *   ?=?( const volatile void *          &, const volatile void * );
     461const volatile void *   ?=?( const volatile void * volatile &, const volatile void * );
    423462
    424463//forall( dtype DT ) DT *                       ?=?(                DT *          &, zero_t );
     
    742781forall( dtype DT ) void ?{}( const volatile  DT *          &, const volatile    DT * );
    743782
     783forall( dtype DT ) void ?{}(                 DT *          &,                   void * );
     784forall( dtype DT ) void ?{}( const           DT *          &,                   void * );
     785forall( dtype DT ) void ?{}( const           DT *          &, const             void * );
     786forall( dtype DT ) void ?{}(       volatile  DT *          &,                   void * );
     787forall( dtype DT ) void ?{}(       volatile  DT *          &,       volatile    void * );
     788
     789forall( dtype DT ) void ?{}( const volatile  DT *          &,                   void * );
     790forall( dtype DT ) void ?{}( const volatile  DT *          &, const             void * );
     791forall( dtype DT ) void ?{}( const volatile  DT *          &,       volatile    void * );
     792forall( dtype DT ) void ?{}( const volatile  DT *          &, const volatile    void * );
     793
    744794forall( dtype DT ) void ?{}(                 void *          &,                 DT * );
    745795forall( dtype DT ) void ?{}( const           void *          &,                 DT * );
     
    752802forall( dtype DT ) void ?{}( const volatile void *           &, const volatile  DT * );
    753803
     804void    ?{}(                void *          &,                void * );
     805void    ?{}( const          void *          &,                void * );
     806void    ?{}( const          void *          &, const          void * );
     807void    ?{}(       volatile void *          &,                void * );
     808void    ?{}(       volatile void *          &,       volatile void * );
     809void    ?{}( const volatile void *          &,                void * );
     810void    ?{}( const volatile void *          &, const          void * );
     811void    ?{}( const volatile void *          &,       volatile void * );
     812void    ?{}( const volatile void *          &, const volatile void * );
     813
    754814//forall( dtype DT ) void ?{}(              DT *          &, zero_t );
    755815//forall( dtype DT ) void ?{}(              DT * volatile &, zero_t );
  • src/tests/.expect/completeTypeError.txt

    r178e4ec r62194cb  
    1 completeTypeError.c:33:1 error: No reasonable alternatives for expression Applying untyped:
     1completeTypeError.c:34:1 error: No reasonable alternatives for expression Applying untyped:
    22  Name: *?
    33...to:
    44  Name: v
    55
    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
    156
    167completeTypeError.c:36:1 error: No reasonable alternatives for expression Applying untyped:
     
    1910  Name: v
    2011
     12
    2113completeTypeError.c:37:1 error: No reasonable alternatives for expression Applying untyped:
    2214  Name: quux
    2315...to:
    2416  Name: v
     17
    2518
    2619completeTypeError.c:58:1 error: No reasonable alternatives for expression Applying untyped:
     
    2922  Name: y
    3023
     24
    3125completeTypeError.c:59:1 error: No reasonable alternatives for expression Applying untyped:
    3226  Name: quux
    3327...to:
    3428  Name: y
     29
    3530
    3631completeTypeError.c:60:1 error: No reasonable alternatives for expression Applying untyped:
     
    3934  Name: y
    4035
     36
    4137completeTypeError.c:72:1 error: No reasonable alternatives for expression Applying untyped:
    4238  Name: baz
     
    4440  Name: z
    4541
     42
  • src/tests/Makefile.am

    r178e4ec r62194cb  
    141141typedefRedef-ERR1: typedefRedef.c @CFA_BINDIR@/@CFA_NAME@
    142142        ${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

    r178e4ec r62194cb  
    895895        ${CC} ${AM_CFLAGS} ${CFLAGS} -DERR1 ${<} -o ${@}
    896896
    897 alloc-ERROR: alloc.c @CFA_BINDIR@/@CFA_NAME@
    898         ${CC} ${AM_CFLAGS} ${CFLAGS} -DERR1 ${<} -o ${@}
    899 
    900897# Tell versions [3.59,3.63) of GNU make to not export all variables.
    901898# Otherwise a system limit (for SysV at least) may be exceeded.
  • src/tests/alloc.c

    r178e4ec r62194cb  
    3232        // allocation, non-array types
    3333
    34         p = (int *)(void *)malloc( sizeof(*p) );                   // C malloc, type unsafe
     34        p = (void *)malloc( sizeof(*p) );                   // C malloc, type unsafe
    3535        *p = 0xdeadbeef;
    3636        printf( "C   malloc %#x\n", *p );
     
    5454        printf( "\n" );
    5555
    56         p = (int *)calloc( dim, sizeof( *p ) );                    // C array calloc, type unsafe
     56        p = calloc( dim, sizeof( *p ) );                    // C array calloc, type unsafe
    5757        printf( "C   array calloc, fill 0\n" );
    5858        for ( int i = 0; i < dim; i += 1 ) { printf( "%#x ", p[i] ); }
     
    8383        printf( "\n" );
    8484
    85         p = (int *)(void *)realloc( p, dim * sizeof(*p) );         // C realloc
     85        p = (void *)realloc( p, dim * sizeof(*p) );         // C realloc
    8686        for ( int i = 0; i < dim; i += 1 ) { p[i] = 0xdeadbeef; }
    8787        printf( "C   realloc\n" );
     
    256256        stp = malloc();
    257257        printf( "\nSHOULD FAIL\n" );
    258 #ifdef ERR1
    259258        p = alloc( stp, dim * sizeof(*stp) );
    260259        p = memset( stp, 10 );
    261260        p = memcpy( &st1, &st );
    262 #endif
    263261} // main
    264262
  • src/tests/completeTypeError.c

    r178e4ec r62194cb  
    1212        void *v;
    1313
    14         A * x;
    15         A * y;
    16         B * x;
    17         B * z;
     14        // A * x;
     15        // A * y;
     16        // B * x;
     17        // B * z;
    1818
    1919        // okay
    2020        *i;
    21         *x; // picks B
    22         *z;
     21        // *x; // picks B
     22        // *z;
    2323        foo(i);
    2424        bar(i);
     
    2929        bar(v);
    3030        qux(v);
     31        foo(v); // questionable, but works at the moment for C compatibility
    3132
    3233        // bad
    3334        *v;
    34         *y;
    35         foo(v);
     35        // *y;
    3636        baz(v);
    3737        quux(v);
  • src/tests/dtor-early-exit.c

    r178e4ec r62194cb  
    2222
    2323struct A {
    24         const char * name;
     24        char * name;
    2525        int * x;
    2626};
  • src/tests/init_once.c

    r178e4ec r62194cb  
    7272        insert( &constructed, &x );
    7373
    74         x.x = (int *)malloc(sizeof(int));
     74        x.x = malloc(sizeof(int));
    7575}
    7676
  • src/tests/multiDimension.c

    r178e4ec r62194cb  
    77  printf("default constructing\n");
    88  (this.a){ 123 };
    9   this.ptr = (int *)malloc(sizeof(int));
     9  this.ptr = malloc(sizeof(int));
    1010}
    1111
     
    1313  printf("copy constructing\n");
    1414  (this.a){ other.a };
    15   this.ptr = (int *)malloc(sizeof(int));
     15  this.ptr = malloc(sizeof(int));
    1616}
    1717
     
    1919  printf("constructing with %d\n", a);
    2020  (this.a){ a };
    21   this.ptr = (int *)malloc(sizeof(int));
     21  this.ptr = malloc(sizeof(int));
    2222}
    2323
  • src/tests/tupleVariadic.c

    r178e4ec r62194cb  
    7373        [a0, a1, a2, a3] = args;
    7474        a.size = 4;
    75         a.data = (int *)malloc(sizeof(int)*a.size);
     75        a.data = malloc(sizeof(int)*a.size);
    7676        a.data[0] = a0;
    7777        a.data[1] = a1;
  • src/tests/vector/vector_int.c

    r178e4ec r62194cb  
    2727        vec.last = -1;
    2828        vec.capacity = reserve;
    29         vec.data = (int *)malloc( sizeof( int ) * reserve );
     29        vec.data = malloc( sizeof( int ) * reserve );
    3030}
    3131
     
    3333        vec.last = other.last;
    3434        vec.capacity = other.capacity;
    35         vec.data = (int *)malloc( sizeof( int ) * other.capacity );
     35        vec.data = malloc( sizeof( int ) * other.capacity );
    3636        for (int i = 0; i < vec.last; i++) {
    3737                vec.data[i] = other.data[i];
     
    4545void reserve( vector_int *vec, int reserve ) {
    4646        if ( reserve > vec->capacity ) {
    47                 vec->data = (int *)realloc( vec->data, sizeof( int ) * reserve );
     47                vec->data = realloc( vec->data, sizeof( int ) * reserve );
    4848                vec->capacity = reserve;
    4949        }
     
    5454        if ( vec->last == vec->capacity ) {
    5555                vec->capacity *= 2;
    56                 vec->data = (int *)realloc( vec->data, sizeof( int ) * vec->capacity );
     56                vec->data = realloc( vec->data, sizeof( int ) * vec->capacity );
    5757        }
    5858        vec->data[ vec->last ] = element;
Note: See TracChangeset for help on using the changeset viewer.