Show
Ignore:
Timestamp:
07/30/08 21:42:37 (5 months ago)
Author:
Chuck.Esterbrook
Message:

Improvements to event declarations and raise statement per hopscc.
Add missing 'event' keyword. doh!
Assign event to local var to avoid race conditions.
Other refinements.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • cobra/trunk/Source/Statements.cobra

    r1560 r1562  
    11721172 
    11731173        var _name = '' 
     1174        var _eventType as IType? 
    11741175        var _exprs as List<of Expr> 
    11751176        var _definition as BoxEvent? 
     
    12001201                        expr = _exprs[0] 
    12011202                        if expr inherits DotExpr 
    1202                                 right = expr.right 
    1203                                 if right inherits IDotRightExpr 
    1204                                         defi = (right to dynamic).definition 
    1205                                         if defi inherits BoxEvent 
    1206                                                 _definition = defi 
    1207                                                 _name = defi.name 
    1208                                         else 
    1209                                                 .throwError('Expecting an event to raise.') 
     1203                                right = expr.dotRight 
     1204                                defi = (right to dynamic).definition 
     1205                                if defi inherits BoxEvent 
     1206                                        _definition = defi 
     1207                                        _name = defi.name 
     1208                                        _eventType = defi.handlerType            
    12101209                                else 
    1211                                         assert false # should be impossible to get here since it was a dotexpr 
     1210                                        .throwError('Expecting an event to raise.') 
     1211                        else if expr inherits IdentifierExpr  # ex: raise _eventName 
     1212                                _name = expr.name 
     1213                                assert expr.potentialType 
     1214                                _eventType = expr.potentialType 
    12121215                        else 
    12131216                                .throwError('Invalid expression for raising events. Try "raise .someEvent, args" or "throw SomeException(args)".') 
     
    12161219                base.writeSharpDef(sw) 
    12171220                name = Utils.capped(.name) 
    1218                 sw.write('if (this.[name]!=null) this.[name](') 
     1221                localName = '_lh_event_[.serialNum]' 
     1222                sw.write('{ [_eventType.sharpRef] [localName] = this.[name]; if ([localName]!=null) [localName](') 
    12191223                sep = '' 
     1224                # Assuming usual argsList case is 2 args (sender, eventArgs). If have fewer than this 
     1225                # presume the first arg - sender ('this') -  is elided 
     1226                # TODO: need to compare to the actual count of the parameter list instead of assuming this 
     1227                if _exprs.count == 2  
     1228                        sep = 'this, ' 
    12201229                for expr in _exprs[1:] 
    12211230                        sw.write(sep) 
    12221231                        expr.writeSharpDef(sw, false) 
    12231232                        sep = ', ' 
    1224                 sw.write(');\n') 
    1225  
     1233                sw.write('); }\n') 
     1234                 
    12261235 
    12271236class ReturnStmt