Changeset 1562

Show
Ignore:
Timestamp:
07/30/08 21:42:37 (4 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.

Location:
cobra/trunk
Files:
1 added
5 modified

Legend:

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

    r1557 r1562  
    917917                        _dotRightExpr = right to IDotRightExpr 
    918918                        _isImplicit = isImplicit 
     919 
     920        get dotRight as IDotRightExpr 
     921                """ 
     922                Returns .right but with the more narrow type of IDotRightExpr. 
     923                """ 
     924                return _dotRightExpr 
    919925 
    920926        pro isImplicit from var 
  • cobra/trunk/Source/CobraParser.cobra

    r1560 r1562  
    20632063                token = .expect('RAISE') 
    20642064                exprs = .commaSepExprs('EOL') 
     2065                assert .last.which=='EOL' 
     2066                .undo  # need EOL 
    20652067                if exprs.count == 0 
    20662068                        .throwError('Expecting one or more expressions after "raise", starting with the event. If you meant to throw the currently caught exception, use "throw" instead.') 
  • cobra/trunk/Source/Expr.cobra

    r1558 r1562  
    989989                        if defi inherits IType 
    990990                                return defi 
    991                         else 
     991                        else if defi inherits BoxEvent 
     992                                return defi.handlerType 
     993                        else     
    992994                                throw FallThroughException(defi) 
    993995                else 
  • cobra/trunk/Source/Members.cobra

    r1560 r1562  
    379379 
    380380        get defaultAccessLevel as String is override 
    381                 return 'public' 
     381                return if(.name.startsWith('_'), 'protected', 'public') 
    382382 
    383383        get englishName as String is override 
     
    432432                .writeSharpAttribs(sw) 
    433433                .writeSharpIsNames(sw) 
     434                sw.write('event ') 
    434435                sw.write(.handlerType.sharpRef) 
    435436                sw.write(' [.sharpName]') 
  • 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