Wiki

Ticket #179: static-class.patch

File static-class.patch, 4.7 KB (added by hopscc, 14 years ago)
  • Source/Members.cobra

     
    224224    def _bindInt is override 
    225225        base._bindInt 
    226226        isNames = Set<of String>() 
     227 
     228        # Make them explicitly set all members shared on a shared class since while we support shared classes we 
     229        # dont want to encourage or make use of such classes really easy. 
     230        #if  .parentBox.typeOf is Class and 'shared' in .parentBox.isNames  and 'shared' not in _isNames 
     231        #   .compiler.warning(this, 'All members in a shared class must also be shared.') 
     232        #Implicitly set all members in a shared class to be also shared 
     233        if  .parentBox.typeOf is Class and 'shared' in .parentBox.isNames  
     234            _isNames.add('shared') 
     235             
    227236        for name in _isNames 
    228237            if name in isNames and not .parentBox.isFromBinaryLibrary 
    229238                .compiler.warning(this, 'Duplicate modifier "[name]". You can remove it.') 
  • Source/BackEndClr/SharpGenerator.cobra

     
    10391039    get sharpInvariantVisibility as String is abstract 
    10401040 
    10411041    def writeSharpInvariantMethod(sw as CurlyWriter) 
    1042         if .compiler.options['contracts'] <> 'none' 
     1042        if .compiler.options['contracts'] <> 'none' and not 'shared' in _isNames 
    10431043            sw.write('\nint _ih_invariantGuard;\n\n') 
    10441044        if .compiler.options['contracts'] <> 'methods' 
    10451045            return 
  • Tests/120-classes/250-shared-classes/200-static-class-dup.cobra

     
     1class MClass is shared 
     2    var log = ''    # .warning. Duplicate modifier "shared" 
     3        is shared 
     4     
     5    cue init is shared  # .warning. Duplicate modifier "shared" 
     6        .addLog('static initializer called.')    
     7         
     8    def xx as String is shared # .warning. Duplicate modifier "shared" 
     9        v ='foo magoo.' 
     10        .addLog(v)  
     11        return v 
     12 
     13    def addLog( s as String) is shared # .warning. Duplicate modifier "shared" 
     14        .log += s  
     15        .log += '\n' 
     16         
     17    #get getLog from log is shared   
     18    pro getLog as String is shared # .warning. Duplicate modifier "shared" 
     19        get  
     20            return .log 
     21         
     22class EPoint 
     23    def main is shared 
     24        assert MClass.xx == 'foo magoo.' 
     25        assert MClass.getLog.trimEnd.startsWith('static initializer called') 
     26        assert MClass.getLog.trimEnd.endsWith('foo magoo.') 
  • Tests/120-classes/250-shared-classes/110-static-class-private.cobra

     
     1# shared on class names, implicit shared on all members, implicit private class var 
     2class MClass is shared 
     3    var __log = '' 
     4     
     5    cue init 
     6        .addLog('static initializer called.')    
     7         
     8    def xx as String 
     9        v ='foo magoo.' 
     10        .addLog(v)  
     11        return v 
     12 
     13    def addLog(s as String) 
     14        __log += s  
     15        __log += '\n' 
     16         
     17    get getLog from __log   # backing variable must be _ prefixed 
     18    #pro getLog from mlog   # backing variable must be _ prefixed 
     19    #pro getLog as String 
     20    #   get 
     21    #       return __log 
     22         
     23class EPoint 
     24    def main is shared 
     25        assert MClass.xx == 'foo magoo.' 
     26        assert MClass.getLog.trimEnd.startsWith('static initializer called') 
     27        assert MClass.getLog.trimEnd.endsWith('foo magoo.') 
     28         
  • Tests/120-classes/250-shared-classes/100-static-class.cobra

     
     1# shared on class names, all memebers implicitly also shared 
     2class MClass is shared 
     3    var log = '' 
     4        #is protected 
     5     
     6    cue init 
     7        .addLog('static initializer called.')    
     8         
     9    def xx as String 
     10        v ='foo magoo.' 
     11        .addLog(v)  
     12        return v 
     13 
     14    def addLog(s as String) 
     15        .log += s  
     16        .log += '\n' 
     17         
     18    #get getLog from mlog   # backing variable must be _ prefixed 
     19    #pro getLog from mlog   # backing variable must be _ prefixed 
     20    pro getLog as String 
     21        get 
     22            return .log 
     23         
     24class EPoint 
     25    def main is shared 
     26        assert MClass.xx == 'foo magoo.' 
     27        assert MClass.getLog.trimEnd.startsWith('static initializer called') 
     28        assert MClass.getLog.trimEnd.endsWith('foo magoo.') 
     29