Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Concurrency/Actors.cpp

    r3830c84 r046ba23  
    4545    // finds and sets a ptr to the actor, message, and request structs, which are needed in the next pass
    4646    void previsit( const StructDecl * decl ) {
    47         if ( !decl->body ) return;
    48         if ( decl->name == "actor" ) {
    49             actorStructDecls.insert( decl ); // skip inserting fwd decl
     47        GuardValue(insideStruct);
     48        insideStruct = true;
     49        parentDecl = mutate( decl );
     50        if( decl->name == "actor" ) {
     51            if ( actorDecl ) actorStructDecls.insert( decl ); // skip inserting fwd decl
    5052            *actorDecl = decl;
    51         } else if( decl->name == "message" ) {
    52             messageStructDecls.insert( decl ); // skip inserting fwd decl
     53        }
     54        if( decl->name == "message" ) {
     55            if ( msgDecl ) messageStructDecls.insert( decl ); // skip inserting fwd decl
    5356            *msgDecl = decl;
    54         } else if( decl->name == "request" ) *requestDecl = decl;
    55         else {
    56             GuardValue(insideStruct);
    57             insideStruct = true;
    58             parentDecl = mutate( decl );
    59         }
     57        }
     58        if( decl->name == "request" ) *requestDecl = decl;
    6059        }
    6160
     
    7170    }
    7271
    73     // this collects the derived actor and message struct decl ptrs
     72    // this collects the valid actor and message struct decl pts
    7473    void postvisit( const StructInstType * node ) {
    7574        if ( ! *actorDecl || ! *msgDecl ) return;
    7675        if ( insideStruct && !namedDecl ) {
    77             auto actorIter = actorStructDecls.find( node->aggr() );   
    78             if ( actorIter != actorStructDecls.end() ) {
     76            if ( node->aggr() == *actorDecl ) {
    7977                actorStructDecls.insert( parentDecl );
    80                 return;
    81             }
    82             auto messageIter = messageStructDecls.find( node->aggr() );
    83             if ( messageIter != messageStructDecls.end() ) {
     78            } else if ( node->aggr() == *msgDecl ) {
    8479                messageStructDecls.insert( parentDecl );
    8580            }
     
    191186};
    192187
    193 // generates the definitions of send operators for actors
    194 // collects data needed for next pass that does the circular defn resolution
    195 //     for message send operators (via table above)
    196 struct GenFuncsCreateTables : public ast::WithDeclsToAdd<> {
     188struct GenReceiveDecls : public ast::WithDeclsToAdd<> {
    197189    unordered_set<const StructDecl *> & actorStructDecls;
    198190    unordered_set<const StructDecl *>  & messageStructDecls;
     
    203195    FwdDeclTable & forwardDecls;
    204196
    205     // generates the operator for actor message sends
    206197        void postvisit( const FunctionDecl * decl ) {
    207198        // return if not of the form receive( param1, param2 ) or if it is a forward decl
     
    222213        auto messageIter = messageStructDecls.find( arg2InstType->aggr() );
    223214        if ( actorIter != actorStructDecls.end() && messageIter != messageStructDecls.end() ) {
     215
     216            // check that we have found all the decls we need from <actor.hfa>
     217            if ( !*allocationDecl || !*requestDecl )
     218                SemanticError( decl->location, "using actors requires a header, add #include <actor.hfa>\n" );
     219
    224220            //////////////////////////////////////////////////////////////////////
    225221            // The following generates this send message operator routine for all receive(derived_actor &, derived_msg &) functions
     
    351347            // forward decls to resolve use before decl problem for '|' routines
    352348            forwardDecls.insertDecl( *actorIter, *messageIter , ast::deepCopy( sendOperatorFunction ) );
     349            // forwardDecls.push_back( ast::deepCopy( sendOperatorFunction ) );
    353350
    354351            sendOperatorFunction->stmts = sendBody;
     
    358355
    359356  public:
    360     GenFuncsCreateTables( unordered_set<const StructDecl *> & actorStructDecls, unordered_set<const StructDecl *> & messageStructDecls,
     357    GenReceiveDecls( unordered_set<const StructDecl *> & actorStructDecls, unordered_set<const StructDecl *> & messageStructDecls,
    361358        const StructDecl ** requestDecl, const EnumDecl ** allocationDecl, const StructDecl ** actorDecl, const StructDecl ** msgDecl,
    362359        FwdDeclTable & forwardDecls ) : actorStructDecls(actorStructDecls), messageStructDecls(messageStructDecls),
     
    364361};
    365362
    366 
    367 // separate pass is needed since this pass resolves circular defn issues
    368 // generates the forward declarations of the send operator for actor routines
    369 struct FwdDeclOperator : public ast::WithDeclsToAdd<> {
     363struct GenFwdDecls : public ast::WithDeclsToAdd<> {
    370364    unordered_set<const StructDecl *> & actorStructDecls;
    371365    unordered_set<const StructDecl *>  & messageStructDecls;
    372366    FwdDeclTable & forwardDecls;
    373367
    374     // handles forward declaring the message operator
    375368    void postvisit( const StructDecl * decl ) {
    376369        list<FunctionDecl *> toAddAfter;
     
    399392
    400393  public:
    401     FwdDeclOperator( unordered_set<const StructDecl *> & actorStructDecls, unordered_set<const StructDecl *> & messageStructDecls,
    402         FwdDeclTable & forwardDecls ) : actorStructDecls(actorStructDecls), messageStructDecls(messageStructDecls), forwardDecls(forwardDecls) {}
     394    GenFwdDecls( unordered_set<const StructDecl *> & actorStructDecls, unordered_set<const StructDecl *> & messageStructDecls,
     395        FwdDeclTable & forwardDecls ) : actorStructDecls(actorStructDecls), messageStructDecls(messageStructDecls),
     396        forwardDecls(forwardDecls) {}
    403397};
    404398
     
    426420    Pass<CollectactorStructDecls>::run( translationUnit, actorStructDecls, messageStructDecls, requestDecl,
    427421        allocationDecl, actorDecl, msgDecl );
    428 
    429     // check that we have found all the decls we need from <actor.hfa>, if not no need to run the rest of this pass
    430     if ( !allocationDeclPtr || !requestDeclPtr || !actorDeclPtr || !msgDeclPtr )
    431         return;
    432 
     422       
    433423    // second pass locates all receive() routines that overload the generic receive fn
    434424    // it then generates the appropriate operator '|' send routines for the receive routines
    435     Pass<GenFuncsCreateTables>::run( translationUnit, actorStructDecls, messageStructDecls, requestDecl,
     425    Pass<GenReceiveDecls>::run( translationUnit, actorStructDecls, messageStructDecls, requestDecl,
    436426        allocationDecl, actorDecl, msgDecl, forwardDecls );
    437427
    438428    // The third pass forward declares operator '|' send routines
    439     Pass<FwdDeclOperator>::run( translationUnit, actorStructDecls, messageStructDecls, forwardDecls );
     429    Pass<GenFwdDecls>::run( translationUnit, actorStructDecls, messageStructDecls, forwardDecls );
    440430}
    441431
Note: See TracChangeset for help on using the changeset viewer.