Wiki

Ticket #312: cond-compile-directive-ver.patch

File cond-compile-directive-ver.patch, 59.9 KB (added by hopscc, 11 years ago)
  • Source/BackEndObjC/ObjcGenerator.cobra

     
    892892    get newForObjcTest as String is override 
    893893        return if(not _baseClass.isExtern, ' new', '') 
    894894 
     895class SuppressibleBox is partial 
     896    """ 
     897    Min needed for null codegen. 
     898    Nothing in here should be used for codegen - all handled higher up       
     899    """ 
     900     
     901    get objcInit as String is override 
     902        return '' 
    895903 
     904    get objcInvariantVisibility as String is override 
     905        throw ShouldNotCallException(.getType) 
     906 
     907    get objcKeyWord as String is override 
     908        return '' 
     909 
     910         
     911         
    896912class Interface is partial 
    897913 
    898914    get objcInit as String is override 
     
    11261142 
    11271143    pass  # to-do 
    11281144 
     1145class SuppressibleStmt is partial 
     1146     
     1147    pass  # to-do 
    11291148 
    11301149class ExpectStmt is partial 
    11311150 
  • Source/Boxes.cobra

     
    16501650                m = _baseClass.memberForName(name) 
    16511651        return m 
    16521652 
     1653class SuppressibleBox inherits Box is partial 
     1654    """ 
     1655    Holder for boxdecls that are suppressible (at codegen). 
     1656    Things like @debug decls block and (TBD) platform tied Decls  
     1657    """ 
     1658     
     1659    cue init(token as IToken, idToken as IToken, name as String ) 
     1660        #base.init(token, idToken, name, paramList, isNames, attribs, baseNodes, docString) 
     1661        base.init(token, idToken, name, List<of IType>(), List<of String>(), AttributeList(), List<of ITypeProxy>(), nil) 
    16531662 
     1663    get englishName as String is override 
     1664        return 'suppressibleBox' 
     1665 
     1666    get isReference as bool is override 
     1667        return false # n/a 
     1668 
     1669    #def isDescendantOf(type as IType) as bool is override 
     1670    #   #_prepLibraryBox 
     1671    #   if this == type, return true 
     1672    #   if .superType is type or .superType.isDescendantOf(type), return true 
     1673    #   return false 
     1674 
     1675    def memberForName(name as String) as IMember? 
     1676        return base.memberForName(name) 
     1677         
     1678         
    16541679class Struct 
    16551680    is partial 
    16561681    inherits ClassOrStruct 
  • Source/CommandLine.cobra

     
    519519            'description': 'Print just the version number.', # ([.versionString]).', 
    520520            'type': 'main', 
    521521        }, 
     522        { 
     523            'name': 'versionTag', 
     524            'synonyms': ['define'], 
     525            'type': 'string', 
     526            'isAccumulator': true, 
     527            'description': 'Provide the tagName(s) for conditional compilation or versioning on user defined tags', 
     528            'args': 'TAGNAME', 
     529        }, 
    522530    ] 
    523531 
    524532 
     
    544552 
    545553    """ 
    546554 
     555    get baseVersionNumber as String is shared 
     556        """  
     557        Canonical cobra version number composed of a dot separated triplet (only). 
     558        This may be prefixed or suffixed with additional info (e.g 'post') to 
     559        provide the version string 
     560        """ 
     561        return '0.9.3' 
     562     
    547563    get versionString as String is shared 
    548564        ensure result.count(c'.') >= 2 or result.startsWith('svn:') 
    549565 
     
    551567        # not the current Source directory. And Snapshot can be a final release such as '0.7.4' for a 
    552568        # period of time where this Cobra source represents an svn-post-RELEASE. 
    553569        # Keep three components to the version number: X.Y.Z 
    554  
    555         ver = 'svn:[CompileTimeInfo.subversionRevision] (post 0.9.3) / [CompileTimeInfo.date]' 
     570        verNo = .baseVersionNumber 
     571        ver = 'svn:[CompileTimeInfo.subversionRevision] (post [verNo]) / [CompileTimeInfo.date]' 
    556572        # ver += ', informal release 2009-03-01' 
    557573        return ver 
    558574 
    559575    get platformString as String is shared 
    560         return .clrVersion + ' on ' + .opSysString 
     576        return .clrVersion + ' on ' + CobraCore.operatingSystemDescription 
    561577 
    562578    get clrVersion as String is shared 
    563579        """ Get runtime version, like '.NET CLR v4.0.30319' or 'Mono 2.6.7 CLR v2.0.50727'. """ 
     
    571587                pass  # if the above fails for any reason, that's okay 
    572588        else 
    573589            ver = '.NET' 
    574         ver += ' CLR ' + Assembly.getAssembly(Object).imageRuntimeVersion 
     590        ver += ' CLR ' + .clrVersionNumber 
    575591        return ver 
    576592 
    577     get opSysString as String is shared 
    578         # to-do: after next compiler snapshot, replace this with CobraCore.operatingSystemDescription 
    579         name = '' 
    580         if File.exists('/System/Library/CoreServices/SystemVersion.plist') 
    581             # Mac 
    582             content = File.readAllText('/System/Library/CoreServices/SystemVersion.plist') 
    583             match = Regex.match(content, r'<string>(Mac[^<]+)') 
    584             if match.success 
    585                 name += match.groups[1].toString 
    586             match = Regex.match(content, r'<string>(\d+\.[\d\.]+)') 
    587             if match.success 
    588                 name += ' ' + match.groups[1].toString 
    589         else if File.exists('/etc/lsb-release') 
    590             # Ubuntu, ... 
    591             content = File.readAllText('/etc/lsb-release') 
    592             d = Dictionary<of String, String>() 
    593             for line in content.splitLines 
    594                 line = line.trim 
    595                 if line == '' or line.startsWith('#') or '=' not in line, continue 
    596                 pair = line.split('=', 2) 
    597                 d[pair[0].trim] = pair[1].trim 
    598             if d.containsKey('DISTRIB_DESCRIPTION'), name = d['DISTRIB_DESCRIPTION'].trim 
    599             if name == '' 
    600                 try 
    601                     name = d['DISTRIB_ID'] + ' ' + d['DISTRIB_RELEASE'] 
    602                 catch 
    603                     pass 
    604             if name.startsWith('"') and name.endsWith('"'), name = name[1:-1] 
    605         else if File.exists('/etc/arch-release') 
    606             # Arch Linux 
    607             name = 'Arch Linux ' + _getCommandOutput('/bin/uname', '-r').trim 
    608             pacman = _getCommandOutput('pacman', '--version') 
    609             match = Regex.match(pacman, r'[Pp]acman v?(\d+\.[\d\.]+)') 
    610             if match.success 
    611                 name += ' (pacman ' + match.groups[1].toString.trim + ')' 
    612         else if File.exists('/etc/system-release') 
    613             # CentOS, Fedora, ... 
    614             name = File.readAllText('/etc/system-release') 
    615         else if File.exists('/etc/redhat-release') 
    616             # RedHat, ... 
    617             name = File.readAllText('/etc/redhat-release') 
    618         name = name.trim 
    619         if name == '' 
    620             # everyone else 
    621             name = Environment.osVersion.toString 
    622         return name 
    623  
     593    get clrVersionNumber as String is shared 
     594        ensure result.contains('.')  
     595        return Assembly.getAssembly(Object).imageRuntimeVersion ? '0.0' 
     596             
    624597    def _getCommandOutput(command as String, args as String) as String is shared 
    625598        p = System.Diagnostics.Process() 
    626599        p.startInfo.fileName = command 
     
    926899     
    927900        exeFileName as String? = nil 
    928901        runArgs = .options.getStringList('run-args') 
    929         # TODO: what's this? 
    930         # exeArgs = .options.getDefaultLOStr('exe-args') 
    931         # if exeArgs.count 
    932         #   exeFileName = exeArgs[0] 
    933         #   runArgs = exeArgs[1:] 
    934902        p = c.runProcess(exeFileName, runArgs) 
    935903        if _verbosity >= 1 
    936904            print 'Running: [p.startInfo.fileName] [p.startInfo.arguments]' 
     
    14751443    def _computeArgImplications(options as OptionValues) 
    14761444        if options.getDefault('target', '') == 'lib' and not options.isSpecified('compile') 
    14771445            options['compile'] = true 
    1478         if options.isSpecified('debug') and _ 
    1479             options.getDefault('debug', '') not in ['', '0', '-'] and _ 
    1480             not options.isSpecified('debugging-tips') 
    1481             # then 
     1446        if options.debugOn and not options.isSpecified('debugging-tips') 
    14821447            options['debugging-tips'] = false 
    14831448        if options.boolValue('turbo') 
    14841449            options['contracts'] = 'none' 
     
    16561621    get buildStandardLibrary as bool 
    16571622        return .boolValue('build-standard-library') 
    16581623 
     1624    get debugOn as bool 
     1625        return .getDefault('debug', '-') not in ['-', '0', 0, false] 
     1626        # set values are '+', '1', 'pdbOnly', 'full' 
     1627     
     1628    get runtimePlatform 
     1629        bkend = .getDefault('back-end', 'none') to String 
     1630        return if(bkend == 'none', CobraCore.runtimePlatform, bkend) 
     1631     
     1632    get userVersionTags as List<of String> 
     1633        return  .getStringList('versionTag') 
     1634         
    16591635    def addExtraUse(useSource as String) 
    16601636        es = .getDefault('extra-source', '') to String 
    16611637        useSource = useSource.trim 
  • Source/NameSpace.cobra

     
    77    def extensionMemberFor(box as Box, name as String) as IMember? 
    88    get isFromBinaryLibrary as bool 
    99    get isNames as String* 
    10  
    11  
     10     
    1211class NameSpace 
    1312    is partial 
    1413    inherits Container<of INameSpaceMember> 
     
    341340        if _superNameSpace 
    342341            _superNameSpace._symbolsForNameFromUseDirectives(name, members) 
    343342 
     343    def _addDeclToContainer(decl as INameSpaceMember) 
     344        """ 
     345        Add Dcl to namespace without namespace processing - pass through to Container 
     346        Used for putting dcls in a namespace from a subclass with ususal namespace processing suppressed. 
     347        """ 
     348        base.addDecl(decl) 
     349     
    344350    def addDecl(decl as INameSpaceMember) is override 
    345351        base.addDecl(decl) 
    346352        if decl inherits NameSpace 
     
    399405                    decl._unifyInto(newUniForDecl) 
    400406                else 
    401407                    uni.addDecl(decl) 
     408                     
     409class CollectingNameSpace inherits NameSpace 
     410    """ 
     411    Stand alone, Islanded namespace only for collecting/holding decls. 
     412    Such decls are either discarded or later added into a real properly 
     413    configured Namespace hierarchy. 
     414    """ 
     415    cue init( token as IToken, name as String) 
     416        base.init(token, name) 
     417         
     418    def addDecl(decl as INameSpaceMember) is override 
     419        base._addDeclToContainer(decl) 
     420                     
    402421 
    403  
    404422class UseDirective 
    405423    is partial 
    406424    inherits SyntaxNode 
  • Source/BackEndClr/SharpGenerator.cobra

     
    243243        sourceDir = Path.getDirectoryName(Assembly.getEntryAssembly.location) ? '' 
    244244        outDir = Path.getDirectoryName(outName) ? '' 
    245245        _copyFile(sourceDir, outDir, 'Cobra.Core.dll') 
    246         if .options.getDefault('debug', '') not in ['', '-', '0', 0, false] 
     246        if .options.debugOn 
    247247            if CobraCore.isRunningOnMono and File.exists(Path.combine(sourceDir, 'Cobra.Core.dll.mdb')) 
    248248                _copyFile(sourceDir, outDir, 'Cobra.Core.dll.mdb') 
    249249            else if File.exists(Path.combine(sourceDir, 'Cobra.Core.pdb')) 
     
    604604    is partial 
    605605 
    606606    get sharpInit as String is abstract 
    607  
     607        """ initialised unset value - initial value to init an item of this type to """ 
     608     
    608609    get sharpNameComponent as String 
    609610        """ 
    610         Returns a string that can be used in a C# identifier. That means it cannot have special symbols such as period or left bracket. 
     611        Returns a string that can be used in a C# identifier.  
     612        That means it cannot have special symbols such as period or left bracket. 
    611613        """ 
    612614        ensure result.length > 0  # TODO? Move to interface 
    613615        return .sharpRef 
     
    10321034        return 'this' 
    10331035 
    10341036    get sharpKeyWord as String is abstract 
    1035  
     1037        """ 
     1038        Sharp keyword name for the structure being code genned 
     1039            e.g. 'class' for cobra class 
     1040        """ 
     1041                 
    10361042    get sharpName as String is override 
    10371043        return _name.replace('<of', '<') 
    10381044 
     
    11511157        pass 
    11521158 
    11531159    get sharpInvariantVisibility as String is abstract 
    1154  
     1160        """ Default visibility for invariant guard methods in Box of this type""" 
     1161         
    11551162    def writeSharpInvariantMethod(sw as CurlyWriter) 
    11561163        if .compiler.options['contracts'] <> 'none' 
    11571164            sw.write('\nint _ih_invariantGuard;\n\n') 
     
    12341241 
    12351242    get newForSharpTest as String is override 
    12361243        return if(not _baseClass.isExtern, ' new', '') 
     1244         
     1245class SuppressibleBox is partial 
     1246    """ 
     1247    Min needed for null codegen. 
     1248    Nothing in here should be used for codegen - all handled higher up       
     1249    """ 
     1250    get sharpInit as String is override 
     1251        assert false, 'Should not be called' 
     1252        return '' 
    12371253 
     1254    get sharpInvariantVisibility as String is override 
     1255        throw ShouldNotCallException(.getType) 
    12381256 
     1257    get sharpKeyWord as String is override 
     1258        throw ShouldNotCallException(.getType) 
     1259        #return '' 
     1260     
     1261         
    12391262class Interface is partial 
    12401263 
    12411264    get sharpInit as String is override 
     
    25052528            _ifInheritsVar.ifInheritsStack.pop 
    25062529        if close 
    25072530            sw.dedent 
    2508             sw.write('}\n') 
     2531            sw.write(' }\n') 
    25092532 
    25102533 
    25112534class BreakStmt 
     
    25242547        sw.write('continue;\n') 
    25252548 
    25262549 
     2550class SuppressibleStmt is partial 
     2551    def writeSharpDef(sw as CurlyWriter) 
     2552        base.writeSharpDef(sw) 
     2553        # not exist or get to here if suppressed   #if .compiler.options.debugOn 
     2554        sw.write('// Suppressible Stmt - enabled\n') 
     2555        _stmt.writeSharpStmt(sw) 
     2556         
    25272557class ExpectStmt 
    25282558    is partial 
    25292559 
  • Source/CobraParser.cobra

     
    372372            topNS = _module.topNameSpace 
    373373            if not _fileName.endsWith('SystemInterfaces.cobra') 
    374374                .backEnd.setDefaultUseDirectives(topNS) 
    375             while .peek, .parseTopLevel 
     375            while .peek, .parseTopLevel(topNS) 
    376376        finally 
    377377            _nameSpaceStack.pop 
    378378        return _module to ! 
    379  
    380     def parseTopLevel as ISyntaxNode? 
     379         
     380    def parseTopLevel(ns as NameSpace) as ISyntaxNode? 
    381381        """ Returns the node that was parsed, but will return nil for EOL, EOF and compiler directives. """ 
    382382        what as ISyntaxNode? 
    383383        tok = .peek 
    384         if tok is nil, return nil 
     384        if tok is nil, return nil # EOF 
    385385        isGood = true 
    386386        branch tok.which 
    387             on 'AT_ID' 
    388                 .compilerDirective 
    389             on 'PERCENTPERCENT'  # deprecated 
    390                 .compilerDirective 
    391             on 'USE' 
    392                 _module.topNameSpace.addUseDirective(.useDirective) 
    393 #           on 'IMPORT' 
    394 #               what = .importDirective 
    395             on 'CLASS' 
    396                 what = .classDecl 
    397             on 'MIXIN' 
    398                 what = .mixinDecl 
    399             on 'INTERFACE' 
    400                 what = .interfaceDecl 
    401             on 'SIG' 
    402                 what = .declareMethodSig 
    403             on 'STRUCT' 
    404                 what = .structDecl 
    405             on 'ENUM' 
    406                 what = .enumDecl 
    407             on 'EXTEND' 
    408                 what = .extendDecl 
    409             on 'EOL' 
    410                 .grab 
    411             on 'NAMESPACE' 
    412                 what = .nameSpaceDecl 
     387            on 'AT_ID',          .compilerDirective(ns) 
     388            on 'PERCENTPERCENT', .compilerDirective(ns) # deprecated 
     389            on 'CLASS',     what = _nameSpaceAddDecl(ns, .classDecl) 
     390            on 'INTERFACE', what = _nameSpaceAddDecl(ns, .interfaceDecl) 
     391            on 'STRUCT',    what = _nameSpaceAddDecl(ns, .structDecl) 
     392            on 'MIXIN',     what = _nameSpaceAddDecl(ns, .mixinDecl) 
     393            on 'EXTEND',    what = _nameSpaceAddDecl(ns, .extendDecl) 
     394            on 'USE',       ns.addUseDirective(.useDirective) 
     395            on 'ENUM',      what = _nameSpaceAddDecl(ns, .enumDecl) 
     396            on 'SIG',       what = _nameSpaceAddDecl(ns, .declareMethodSig) 
     397 
     398            on 'NAMESPACE',     what = .nameSpaceDecl 
     399#           on 'IMPORT',what = .importDirective 
     400            on 'EOL',       .grab 
    413401            on 'ID' 
    414                 if tok.text == 'assembly'  # pseudo keyword 
    415                     what = .assemblyDecl 
    416                 else 
    417                     isGood = false 
    418             else 
    419                 isGood = false 
     402                branch tok.text 
     403                    on 'assembly',  what = _nameSpaceAddDecl(ns, .assemblyDecl)   # pseudo keyword 
     404                    else, isGood = false 
     405            else, isGood = false 
    420406        if not isGood 
    421407            sugg = if(tok.text.length, Compiler.suggestionFor(tok.text), nil) 
    422408            sugg = if(sugg, ' Try "[sugg]".', '') 
    423409            .throwError('Expecting use, assembly, namespace, class, interface or enum, but got [tok].[sugg]') 
    424         if what implements INameSpaceMember and not what inherits NameSpace 
    425             what = _nameSpaceAddDecl(_module.topNameSpace, what to INameSpaceMember) 
    426             if what inherits Box 
    427                 assert what.parentNameSpace 
     410        if what inherits Box, assert what.parentNameSpace 
    428411        return what 
    429  
    430     def compilerDirective 
     412         
     413    def compilerDirective(ns as NameSpace) 
    431414        if .peek.which == 'AT_ID' 
    432415            token = .grab 
    433416        else 
     
    437420        branch token.value to String 
    438421            on 'help' 
    439422                if .peek is nil, .throwError(ErrorMessages.unexpectedEndOfFile) 
    440                 node = .parseTopLevel 
     423                node = .parseTopLevel(ns) 
    441424                if node is nil, _warning(token, '@help is not implemented for this element.') 
    442425                else, node.isHelpRequested = true 
     426            on 'debug' or 'ver' or 'env'    # '@debug', '@ver',  '@env' 
     427                .suppressibleNSDecls(ns, token to !) 
    443428            on 'throw' 
    444429                # throw an internal error. used for testing that the compiler will catch and report these as internal errors 
    445430                .expect('EOL') 
     
    515500                    .throwError('Cannot set command line arguments from directive because no arguments parser is available.') 
    516501            else 
    517502                .throwError('Unknown compiler directive "[token.text]".') 
    518  
     503                 
     504    def suppressibleNSDecls(ns as NameSpace, token as IToken) 
     505        """  
     506        Handle block of optionally suppressible/conditionally compiled decls in a NameSpace.  
     507        Collect decls into tmp NS block. If condCompile on, add them to enclosing block else drop them 
     508        """ 
     509        compileBlock = .condCompile(token) 
     510        name = 'Collect_' + (token.value to String ) + '_[token.lineNum]' 
     511        tmpNS =  CollectingNameSpace(token, name) 
     512        .indent 
     513        _collectNameSpaceDecls(tmpNS, true) 
     514         
     515        if compileBlock 
     516            for dcl in tmpNS.declsInOrder  
     517                _nameSpaceAddDecl(ns, dcl)  
     518             
     519                 
    519520    def useDirective as UseDirective 
    520521        """ 
    521522        Example source: 
     
    10501051        else 
    10511052            parent = .curNameSpace to IParentSpace 
    10521053        return EnumDecl(parent, wordToken, idToken, name, isNames, attribs, storageType, docString, enumMembers) 
    1053  
     1054         
    10541055    def extendDecl as Extension 
    10551056        # TODO: extend Qualified.Name 
    10561057        wordToken = .expect('EXTEND') 
     
    11371138        try 
    11381139            indented = .optionalIndent 
    11391140            curNameSpace.addDocString(.docString) 
    1140             .zeroOrMore('EOL') 
    1141             while true 
    1142                 peek = .peek 
    1143                 if peek is nil 
    1144                     if indented, .throwError('Expecting a namespace member, but source code ended.') 
    1145                     else, break 
    1146                 tok = peek to ! 
    1147                 if tok.which == 'DEDENT', break 
    1148                 if not indented and tok.which == 'NAMESPACE', break 
    1149                 branch tok.which 
    1150                     on 'CLASS',     _nameSpaceAddDecl(curNameSpace, .classDecl) 
    1151                     on 'INTERFACE', _nameSpaceAddDecl(curNameSpace, .interfaceDecl) 
    1152                     on 'STRUCT',    _nameSpaceAddDecl(curNameSpace, .structDecl) 
    1153                     on 'MIXIN',     _nameSpaceAddDecl(curNameSpace, .mixinDecl) 
    1154                     on 'EXTEND',    _nameSpaceAddDecl(curNameSpace, .extendDecl) 
    1155                     on 'USE',       curNameSpace.addUseDirective(.useDirective) 
    1156                     on 'ENUM',      _nameSpaceAddDecl(curNameSpace, .enumDecl) 
    1157                     on 'SIG',       _nameSpaceAddDecl(curNameSpace, .declareMethodSig) 
    1158                     on 'NAMESPACE', .nameSpaceDecl 
    1159                     else, .throwError('Expecting a namespace member but got [tok].') 
    1160             if indented, .dedent 
     1141            _collectNameSpaceDecls(curNameSpace, indented <> nil) 
    11611142        finally 
    11621143            for tok in idTokens, _nameSpaceStack.pop 
    11631144        return firstNameSpace to ! 
    1164  
     1145         
     1146    def _collectNameSpaceDecls(ns as NameSpace, indented as bool) 
     1147        .zeroOrMore('EOL') 
     1148        while true 
     1149            peek = .peek 
     1150            if peek is nil 
     1151                if indented, .throwError('Expecting a namespace member, but source code ended.') 
     1152                else, break 
     1153            tok = peek to ! 
     1154            if tok.which == 'DEDENT', break 
     1155            if not indented and tok.which == 'NAMESPACE', break 
     1156            branch tok.which 
     1157                on 'CLASS',     _nameSpaceAddDecl(ns, .classDecl) 
     1158                on 'INTERFACE', _nameSpaceAddDecl(ns, .interfaceDecl) 
     1159                on 'STRUCT',    _nameSpaceAddDecl(ns, .structDecl) 
     1160                on 'MIXIN',     _nameSpaceAddDecl(ns, .mixinDecl) 
     1161                on 'EXTEND',    _nameSpaceAddDecl(ns, .extendDecl) 
     1162                on 'USE',       ns.addUseDirective(.useDirective) 
     1163                on 'ENUM',      _nameSpaceAddDecl(ns, .enumDecl) 
     1164                on 'SIG',       _nameSpaceAddDecl(ns, .declareMethodSig) 
     1165                on 'NAMESPACE', .nameSpaceDecl 
     1166                else, .throwError('Expecting a namespace member but got [tok].') 
     1167        if indented, .dedent 
     1168                 
     1169         
    11651170    def _nameSpaceAddDecl(ns as NameSpace, decl as INameSpaceMember) as INameSpaceMember 
    11661171        """ 
    11671172        Adds the decl to the given namespace or throws an error for duplicate declarations. 
     
    11711176        # TODO: complain if inheritance or is-names are different. at least for inheritance, that needs to be done post-parsing 
    11721177        checkForDups = true 
    11731178        if 'partial' in decl.isNames 
     1179            # otherDecl = _chkPartialDecl(ns, decl, inout checkForDups) 
     1180            # if otherDecl 
     1181            #   return otherDecl 
    11741182            box = decl to? Box 
    11751183            if box is nil, .throwError(decl.token, '[decl.englishName.capitalized] cannot be "partial".') 
    11761184            if not (box inherits Class or box inherits Struct or box inherits Interface) 
     
    12101218        if checkForDups 
    12111219            if ns.declForName(decl.name) 
    12121220                .throwError((decl to dynamic).token to IToken, 'The namespace "[ns.fullName]" already contains a declaration named "[decl.name]".')  # TODO: give an "error" for the location  
    1213             if ns.unifiedNameSpace.declForName(decl.name) 
     1221            if ns.unifiedNameSpace and ns.unifiedNameSpace.declForName(decl.name) 
    12141222                .throwError((decl to dynamic).token to IToken, 'The namespace "[ns.fullName]" already contains a declaration named "[decl.name]" in another file.')  # TODO: give an "error" for the location  
    12151223        ns.addDecl(decl) 
    12161224        return decl 
     
    12361244                    on 'VAR', .addDecl(box, .boxFieldDecl(true)) 
    12371245                    on 'CONST', .addDecl(box, .boxFieldDecl(false)) 
    12381246                    on 'INVARIANT', .declareInvariant 
    1239                     on 'EOL', .endOfLine 
    1240                     on 'ENUM', .addDecl(box, .enumDecl) 
     1247                    on 'EOL',   .endOfLine 
     1248                    on 'ENUM',  .addDecl(box, .enumDecl) 
    12411249                    on 'EVENT', .addDecl(box, .eventDecl) 
    1242                     on 'SIG', .addDecl(box, .declareMethodSig) 
    1243                     on 'SHARED', .bodiedBoxMemberDeclsShared(box) 
    1244                     on 'TEST', .testSection(box) 
    1245                     on 'CLASS',  .addDecl(box, .classDecl)  # nested types 
    1246                     on 'STRUCT', .addDecl(box, .structDecl) # nested types 
    1247                     else 
     1250                    on 'SIG',   .addDecl(box, .declareMethodSig) 
     1251                    on 'SHARED',.bodiedBoxMemberDeclsShared(box) 
     1252                    on 'TEST',  .testSection(box) 
     1253                    on 'CLASS', .addDecl(box, .classDecl)  # nested types 
     1254                    on 'STRUCT',.addDecl(box, .structDecl) # nested types 
     1255                    else     
     1256                        if .peek.which == 'AT_ID' 
     1257                            .suppressibleBoxMemDecls(box) 
     1258                            continue 
    12481259                        branch .peek.text 
    12491260                            on 'ensure', sugg = 'invariant' 
    12501261                            on 'void', sugg = 'def' 
     
    12711282        finally 
    12721283            _isNamesStack.pop 
    12731284 
     1285    def suppressibleBoxMemDecls(box as Box) 
     1286        """  
     1287        Handle a block of optionally suppressible or conditionally compiled box member Decls.  
     1288        Collect decls in block. If condCompile test true, add them to enclosing block else just drop them 
     1289        """ 
     1290        token = .expect('AT_ID') 
     1291        compileBlock = .condCompile(token) 
     1292        name = 'collecting_' + (token.value to String) + '_[token.lineNum]' 
     1293        tmpBox = SuppressibleBox(token, token, name) # make tmp store and slurp code block into it 
     1294        .indent 
     1295        .bodiedBoxMemberDecls(tmpBox) 
     1296         
     1297        # add to enclosing box if condCompile on, drop them otherwise 
     1298        if compileBlock 
     1299            for dcl in tmpBox.declsInOrder 
     1300                .addDecl(box, dcl) 
     1301 
    12741302    def classPass 
    12751303        if .curBox.declsInOrder.count 
    12761304            _warning('Encountered "pass" in a class that already has declared members.')  # TODO: change to an error 
     
    20282056        expectEOL = true 
    20292057        branch token.which 
    20302058            on 'AT_ID' 
    2031                 if token.text <> '@help', .throwError(token, 'Unexpected compiler directive.') 
    2032                 .grab 
    2033                 s = .stmt 
    2034                 s.isHelpRequested = true 
    2035                 return s 
     2059                return .atIdStmt(token.text) 
    20362060            on 'ASSERT' 
    20372061                s = .assertStmt 
    20382062            on 'BRANCH' 
     
    21482172    ## 
    21492173    ## Individual Statements 
    21502174    ## 
     2175     
     2176    def atIdStmt(text as String) as Stmt? 
     2177        token = .expect('AT_ID') 
     2178        if token.text == '@help' 
     2179            s = .stmt 
     2180            s.isHelpRequested = true 
     2181            return s 
    21512182 
     2183        compileBlock = .condCompile(token) 
     2184        # single stmt on same line after directive or indented block after. 
     2185        b = if(.peek.which == 'EOL', .block, BlockStmt(token, [.stmt])) 
     2186        if compileBlock 
     2187            return SuppressibleStmt(token, b)   # versioned code enabled 
     2188        return nil 
     2189        # return .stmt 
     2190         
     2191    def condCompile(token as IToken) as bool     
     2192        """ 
     2193        Check conditional compilation directive. 
     2194        Return true if condition is true (if should compile conditional code (statement or block) ), 
     2195        return false if not. 
     2196            Conditions include: 
     2197            @debug  - debug on 
     2198            @ver.<versionName>  - user spec and builtin versioning tags        e.g. ver.clr , ver.dotnet 
     2199                possibilities include clr, jvm, obj, mono, dotnet, windows, linux, mac,  
     2200                             tests, asserts, contracts, never, always 
     2201            @env.<envVar>       - env variable set or exact value 
     2202                env.VARNAME and env.VARNAME.VALUE   e.g. env.HOME and env.OS.Windows_NT 
     2203        """ 
     2204             
     2205        branch token.value to String 
     2206            on 'debug'      # '@debug' 
     2207                enableBlock = .backEnd.compiler.options.debugOn 
     2208            on 'ver'        # '@ver'     @ver.<verValue> 
     2209                .expect('DOT') 
     2210                ver = .grab #'ID' or keyword 
     2211                enableBlock = .verValueTrue(ver to !) 
     2212            on 'env'    # '@env'    @env.<envVar>[.<value>]  e.g. @env.HOME and @env.OS.Windows_NT 
     2213                .expect('DOT') 
     2214                envVar = .grab.text  
     2215                envValue as String? = nil 
     2216                if .optional('DOT')  # has value to check 
     2217                    envValue = .grab.value to String 
     2218                val = Environment.getEnvironmentVariable(envVar) 
     2219                enableBlock = (val <> nil) 
     2220                if enableBlock and envValue 
     2221                    val = Environment.getEnvironmentVariable(envVar)  
     2222                    enableBlock = (val == envValue) 
     2223            else     
     2224                .throwError(token, 'Unexpected compiler directive "[token.text]". Expecting conditional compile directive using "@debug", "@ver.VALUE" or "@env.VAR" ') 
     2225        return enableBlock 
     2226     
     2227    def verValueTrue(ver as IToken) as bool              
     2228        rtp = .backEnd.compiler.options.runtimePlatform 
     2229        branch ver.text # builtin platform environmental version identifiers 
     2230            on 'clr'      
     2231                enableBlock = (rtp == 'clr') 
     2232                if .optional('DOT') 
     2233                    verNo = .expect('INTEGER_LIT') 
     2234                    enableBlock = enableBlock and (.clrVersionPacked >= verNo.value to int ) 
     2235            on 'jvm',     enableBlock = (rtp == 'jvm')  # TODO: jvm version 
     2236            on 'objc',    enableBlock = (rtp == 'objc') # TODO: objc and objc version 
     2237            on 'mono',    enableBlock = (rtp == 'clr' and CobraCore.isRunningOnMono) 
     2238            on 'dotnet',  enableBlock = (rtp == 'clr' and not CobraCore.isRunningOnMono) 
     2239            on 'windows', enableBlock = CobraCore.isRunningOnWindows 
     2240            on 'unix',    enableBlock = CobraCore.isRunningOnUnix 
     2241            on 'mac',     enableBlock = CobraCore.isRunningOnMac 
     2242            on 'asserts', enableBlock = CobraCore.willCheckAssert 
     2243            on 'contracts', enableBlock = CobraCore.hasContracts 
     2244            on 'tests',   enableBlock = .backEnd.compiler.options.boolValue('include-tests') 
     2245            on 'never',   enableBlock = false  # disable section of code 
     2246            on 'always',  enableBlock = true   # always enabled 
     2247            # TODO: ert and  dst (??) 
     2248            on 'otherThan' # true if all version identifiers evaluate false 
     2249                enableBlock = true  
     2250                while true 
     2251                    .expect('DOT') 
     2252                    nxtVer = .grab  #'ID' or keyword 
     2253                    enableBlock = enableBlock and not .verValueTrue(nxtVer to !)  
     2254                    if not .peek.which == 'DOT' 
     2255                        break 
     2256            on 'cobra'  # cobra.<verNo> 
     2257                .expect('DOT') 
     2258                verNo = .expect('INTEGER_LIT') 
     2259                enableBlock = .cobraVersionPacked >= verNo.value to int  
     2260            else 
     2261                if ver.which == 'INTEGER_LIT'   # ver.nnnnn treat as cobra version number 
     2262                    enableBlock = .cobraVersionPacked >= ver.value to int  
     2263                # Use user tag set fm compiler cmdline ( -define:<verTag>) 
     2264                else if ver.text in .backEnd.compiler.options.userVersionTags 
     2265                    enableBlock = true 
     2266                else if ver.text.startsWith('_')    # alternatively: enforce usertags to have leading capcase 
     2267                    sugg='Standard predefined version tags include "clr", "jvm","objc", "mono", "dotnet", "windows", "linux", "mac", "tests", "asserts", "contracts", "never", "always".' 
     2268                    .throwError(ver, 'Unknown compiler directive version value "[ver.text]" in "@ver.[ver.text]". [sugg]') 
     2269     
     2270            # augment RTL and use RTL lib methods clrVersion, jvmVersion, monoVersion  
     2271             
     2272        if .verbosity > 2 
     2273            print '  versionTag "[ver.text]"', if(enableBlock, '', 'not'), 'enabled'     
     2274        return enableBlock 
     2275             
     2276    def cobraVersionPacked as int 
     2277        fcv = CommandLine.baseVersionNumber # e.g. '0.9.3' 
     2278        el = fcv.split(c'.') # '<rel>' '<major>', <minor> 
     2279        cobraVer = (int.parse(el[0])* 100) + (int.parse(el[1]) * 10) + int.parse(el[2]) 
     2280        return cobraVer 
     2281         
     2282    def clrVersionPacked as int 
     2283        """Major.minor packed into an integer: '2.0' -> 20,  '3.5'-> 35, ...""" 
     2284        fullClrVersion =  CommandLine.clrVersionNumber 
     2285        el = fullClrVersion.split(c'.') # 'v<Major>' '<minor>' '...' 
     2286        clrVer = int.parse(el[0][1:])*10 + int.parse(el[1])  
     2287        return clrVer 
     2288         
    21522289    def assertStmt as Stmt 
    21532290        token = .expect('ASSERT') 
    21542291        expr = .expression 
  • Source/BackEndJvm/JavaGenerator.cobra

     
    182182            # above should be something non platform dependent (COBRA_HOME ?)  
    183183        outDir = Path.getDirectoryName(outName) ? '' 
    184184        _copyFile(sourceDir, outDir, 'Cobra.Core.jar') 
    185         #if .options.getDefault('debug', '') not in ['', '-', '0', 0, false] 
     185        #if .options.debugOn 
    186186        # copy any debug files 
    187187        # TODO: probably also need to adjust Manifest File Class-Path for cobra RTL 
    188188             
     
    11511151        return if(not _baseClass.isExtern, ' new', '') 
    11521152 
    11531153 
     1154class SuppressibleBox is partial 
     1155    """ 
     1156    Min needed for null codegen. 
     1157    Nothing in here should be used for codegen - all handled higher up       
     1158    """ 
     1159     
     1160    get javaInit as String is override 
     1161        assert false, 'Should not be called' 
     1162        return '' 
     1163 
     1164    get javaInvariantVisibility as String is override 
     1165        throw ShouldNotCallException(.getType) 
     1166 
     1167    get javaKeyWord as String is override 
     1168        return '' 
     1169         
    11541170class Interface is partial 
    11551171 
    11561172    get javaInit as String is override 
     
    21302146            _ifInheritsVar.ifInheritsStack.pop 
    21312147        if close 
    21322148            sw.dedent 
    2133             sw.write('}\n') 
     2149            sw.write(' }\n') 
    21342150 
    21352151 
    21362152class BranchStmt is partial 
     
    22012217        base.writeJavaDef(sw) 
    22022218        sw.write('continue;\n') 
    22032219 
     2220class SuppressibleStmt is partial 
     2221    def writeJavaDef(sw as CurlyWriter) 
     2222        base.writeJavaDef(sw) 
     2223        sw.write('// Suppressible Stmt - enabled\n') 
     2224        _stmt.writeJavaStmt(sw) 
    22042225 
    22052226class ExpectStmt is partial 
    22062227 
  • Source/TestifyRunner.cobra

     
    267267            duration = DateTime.now.subtract(_startTime) 
    268268            print 
    269269            print 'Finished at', DateTime.now 
    270             print '[_testifyCount] Tests in [duration].' 
     270            print '[_testifyCount + _failureCount] Tests in [duration].' 
    271271            if _failureCount 
    272272                print '[_failureCount] Failures.' 
    273273            print 
     
    364364 
    365365    def _runtimePlatform(options as OptionValues?) as String 
    366366        if not options, options = .testifyOptions 
    367         rtp = if(options['back-end']=='none', CobraCore.runtimePlatform, options['back-end'] to String) 
    368         return rtp 
     367        return options.runtimePlatform  
    369368         
    370369    def _runSetupScript 
    371370        setUpScript = if(Utils.isRunningOnUnix, 'testify-set-up', 'testify-set-up.bat') 
     
    506505                            return 0 
    507506                    on 'clr' # mono or dotNet 
    508507                        if  rtPlatform <> 'clr'  
    509                             print 'Skipping test because requirement for "clr" is not met.' 
     508                            msg = 'Skipping test because requirement for "clr" is not met.' 
     509                            print msg 
     510                            _showSkipMsg(msg) 
    510511                            return 0 
    511512                    on 'jvm' 
    512513                        if  rtPlatform <> 'jvm' 
    513                             print 'Skipping test because requirement for "jvm" is not met.' 
     514                            msg = 'Skipping test because requirement for "jvm" is not met.' 
     515                            print msg    
     516                            _showSkipMsg(msg) 
    514517                            return 0 
    515518                    else 
    516519                        if what.endsWith('.dll') 
     
    552555                comment = firstLine[firstLine.indexOf('.skip.')+6:].trim 
    553556                if comment.length, comment = '"' + comment + '"' 
    554557                msg = 'Skipping test because of directive. [comment]'.trim 
    555                 _statusWriter.indent 
    556                 _statusWriter.writeLine(msg) 
    557                 _statusWriter.dedent 
     558                _showSkipMsg(msg) 
    558559                print msg 
    559560                return 0 
    560561 
     
    571572            throw Exception('Bad first line: [lines[0]]') 
    572573 
    573574        return 1 # continue processing in caller 
     575     
     576    def _showSkipMsg( msg as String) 
     577        _statusWriter.indent 
     578        _statusWriter.writeLine(msg) 
     579        _statusWriter.dedent 
    574580         
    575581    def _getInlineMessages(lines as List<of String>, offset as int, expectingError as out bool) as Dictionary<of int, String> 
    576582        """ Walk lines and accumulate inline warnings and error messages. """ 
  • Source/Statements.cobra

     
    362362    cue init(tok as IToken) 
    363363        base.init(tok) 
    364364 
     365class SuppressibleStmt is partial inherits Stmt 
     366    var _stmt as Stmt 
     367     
     368    cue init(token as IToken, stmt as Stmt) 
     369        base.init(token) 
     370        _stmt = stmt 
     371     
     372    def addSubFields 
     373        base.addSubFields 
     374        .addField('stmt', _stmt) 
     375     
     376    get lastToken as IToken is override 
     377        return _stmt.lastToken 
     378     
     379    def _innerClone 
     380        base._innerClone 
     381        _stmt = _stmt.clone 
     382     
     383    def _bindImp 
     384        base._bindImp 
     385        _stmt.bindImp 
    365386 
     387         
    366388class ExpectStmt inherits Stmt is partial 
    367389 
    368390    var _exceptionTypeNode as ITypeProxy 
  • Tests/200-misc/880-debug-directive/602-class-call-off.cobra

     
     1#.args. -d:0 
     2# def and class multiline Debug directive - code ignored unless debug on  
     3class DbgDir 
     4    def main is shared 
     5        a = .normX(80) 
     6        assert a == 81 
     7     
     8        a = 80 
     9        a = DbgClass.inc10(a) # .error. Cannot find "DbgClass" 
     10        assert a == 80 
     11     
     12        a = X().xx(80)  
     13        assert a == 91 
     14 
     15    def normX(a as int) as int is shared 
     16        return  a+1 
     17         
     18@debug  
     19    class DbgClass 
     20        def inc10(a as int) as int is shared 
     21            return a+10 
     22             
     23class X 
     24    def xx(a as int) as int 
     25        return a+11 
     26         
     27         
  • Tests/200-misc/880-debug-directive/581-def-and-stmt-off.cobra

     
     1#.args. -d:0 
     2# def and stmt combination Debug directive - code ignored unless debug on  
     3class DbgDir 
     4    def main is shared 
     5        a = .normX(80) 
     6        assert a == 81 
     7     
     8        a= 80 
     9        @debug a = .dbgX(a) 
     10        assert a == 80 
     11         
     12    @debug 
     13        def dbgX(a as int) as int is shared 
     14            a = a+10 
     15            return a 
     16 
     17    def normX(a as int) as int is shared 
     18        return  a+1 
     19             
  • Tests/200-misc/880-debug-directive/580-def-and-stmt-on.cobra

     
     1# def and class multiline Debug directive - code ignored unless debug on  
     2# assumes debug default on 
     3class DbgDir 
     4    def main is shared 
     5        a = .normX(80) 
     6        assert a == 81 
     7     
     8        @debug a = .dbgX(80) 
     9        assert a == 90 
     10         
     11    @debug 
     12        def dbgX(a as int) as int is shared 
     13            return a+10 
     14 
     15    def normX(a as int) as int is shared 
     16        return  a+1 
     17         
     18     
     19             
  • Tests/200-misc/880-debug-directive/200-statement-off.cobra

     
     1#.args. -d:0 
     2# single line Debug directive - code ignored when debug off 
     3class DbgDir 
     4    def main is shared 
     5        a = 1099 
     6        @debug print a 
     7        a = 100 
     8        @debug a = 40 
     9        assert a == 100  
  • Tests/200-misc/880-debug-directive/100-statement-on.cobra

     
     1# single line Debug directive - code ignored unless debug on  
     2# assumes debug default on 
     3class DbgDir 
     4    def main is shared 
     5        a = 99 
     6        @debug print a 
     7        a = 100 
     8        @debug a = 40 
     9        assert a == 40  
  • Tests/200-misc/880-debug-directive/601-class-off.cobra

     
     1#.args. -d:0 
     2# def and class multiline Debug directive - code ignored unless debug on  
     3class DbgDir 
     4    def main is shared 
     5        a = .normX(80) 
     6        assert a == 81 
     7     
     8        a = 80 
     9        @debug a = DbgClass.inc10(a) 
     10        assert a == 80 
     11     
     12        a = X().xx(80)  
     13        assert a == 91 
     14 
     15    def normX(a as int) as int is shared 
     16        return  a+1 
     17         
     18@debug  
     19    class DbgClass 
     20        def inc10(a as int) as int is shared 
     21            return a+10 
     22             
     23class X 
     24    def xx(a as int) as int 
     25        return a+11 
     26         
  • Tests/200-misc/880-debug-directive/501-def-and-call-off.cobra

     
     1#.args. -d:0 
     2# def and class multiline Debug directive - code ignored unless debug on  
     3class DbgDir 
     4    def main is shared 
     5        a = .normX(80) 
     6        assert a == 81 
     7     
     8        a = .dbgX(80) # .error. Cannot find a definition 
     9        assert a == 90 
     10         
     11    @debug 
     12        def dbgX(a as int) as int is shared 
     13            return a+10 
     14 
     15    def normX(a as int) as int is shared 
     16        return  a+1 
     17             
  • Tests/200-misc/880-debug-directive/600-class-on.cobra

     
     1# def and class multiline Debug directive - code ignored unless debug on  
     2# assumes debug default on 
     3class DbgDir 
     4    def main is shared 
     5        a = .normX(80) 
     6        assert a == 81 
     7     
     8        @debug a = DbgClass.x(80) 
     9        assert a == 90 
     10     
     11        a = X().xx(80) 
     12        assert a == 91 
     13 
     14    def normX(a as int) as int is shared 
     15        return  a+1 
     16         
     17@debug 
     18    class DbgClass 
     19        def x(a as int) as int is shared 
     20            return a+10 
     21             
     22class X 
     23    def xx(a as int) as int 
     24        return a+11 
  • Tests/200-misc/880-debug-directive/500-def-and-call-on.cobra

     
     1# def and class multiline Debug directive - code ignored unless debug on  
     2# assumes debug default on 
     3class DbgDir 
     4    def main is shared 
     5        a = .normX(80) 
     6        assert a == 81 
     7     
     8        a = .dbgX(80) 
     9        assert a == 90 
     10         
     11    @debug 
     12        def dbgX(a as int) as int is shared 
     13            return a+10 
     14 
     15    def normX(a as int) as int is shared 
     16        return  a+1 
  • Tests/200-misc/880-debug-directive/604-class-off.cobra

     
     1#.args. -d:0 
     2# def and class multiline Debug directive - code ignored unless debug on  
     3class DbgDir 
     4    def main is shared 
     5        a = .normX(80) 
     6        assert a == 81 
     7     
     8        @debug a = DbgClass.inc10(80) 
     9        assert a == 81 
     10     
     11        @debug a = DbgClass1().dec1(80) 
     12        assert a == 81 
     13         
     14        a = X().xx(80) 
     15        assert a == 91 
     16 
     17    def normX(a as int) as int is shared 
     18        return  a+1 
     19         
     20@debug  
     21    class DbgClass 
     22        def inc10(a as int) as int is shared 
     23            return a+10 
     24             
     25    class DbgClass1 
     26        def dec1(a as int) as int 
     27            return a-1 
     28 
     29class X 
     30    def xx(a as int) as int 
     31        return a+11 
  • Tests/200-misc/880-debug-directive/400-clause-off.cobra

     
     1#.args. -d:0 
     2# multi line Debug directive - code ignored unless debug on  
     3class DbgDir 
     4    def main is shared 
     5        a = a1 = 'standard' 
     6        @debug 
     7            print a 
     8            a = 'debug' 
     9        assert a == a1 
     10         
     11         
  • Tests/200-misc/880-debug-directive/603-class-on.cobra

     
     1# def and class multiline Debug directive - code ignored unless debug on  
     2# assumes debug default on 
     3class DbgDir 
     4    def main is shared 
     5        a = .normX(80) 
     6        assert a == 81 
     7     
     8        @debug a = DbgClass.inc10(80) 
     9        assert a == 90 
     10     
     11        @debug a = DbgClass1.dec1(80) 
     12        assert a == 79 
     13         
     14        a = X().xx(80) 
     15        assert a == 91 
     16 
     17    def normX(a as int) as int is shared 
     18        return  a+1 
     19         
     20@debug  
     21    class DbgClass 
     22        def inc10(a as int) as int is shared 
     23            return a+10 
     24             
     25    class DbgClass1 
     26        def dec1(a as int) as int is shared 
     27            return a-1 
     28 
     29class X 
     30    def xx(a as int) as int 
     31        return a+11 
     32         
  • Tests/200-misc/880-debug-directive/605-class-off.cobra

     
     1#.args. -d:0 
     2# def and class multiline Debug directive - code ignored unless debug on  
     3class DbgDir 
     4    def main is shared 
     5        a = .normX(80) 
     6        assert a == 81 
     7     
     8        @debug  
     9            a = DbgClass().inc10(80) 
     10            assert a == 90 
     11     
     12        @debug  
     13            a = DbgClass1().dec1(80) 
     14            assert a == 79 
     15 
     16#       @debugOff   
     17        assert a == 81 
     18             
     19        a = X().xx(80) 
     20        assert a == 91 
     21 
     22    def normX(a as int) as int is shared 
     23        return  a+1 
     24         
     25@debug  
     26    class DbgClass 
     27        def inc10(a as int) as int 
     28            return a+10 
     29             
     30    class DbgClass1 
     31        def dec1(a as int) as int 
     32            return a-1 
     33 
     34class X 
     35    def xx(a as int) as int 
     36        return a+11 
  • Tests/200-misc/880-debug-directive/300-clause-on.cobra

     
     1# multi line Debug directive - code ignored unless debug on  
     2# assumes debug default on 
     3class DbgDir 
     4    def main is shared 
     5        a = 99 
     6        @debug 
     7            print a 
     8            a = 40 
     9        assert a == 40  
     10         
     11# is this a better ( easier to modify in and out of debug ) format ? 
     12#       a = 99 
     13#       @debug 
     14#       print a 
     15#       a = 40 
     16#       @debugOff 
     17#       assert a == 40  
  • Tests/200-misc/880-debug-directive/606-class-off.cobra

     
     1#.args. -d:0 
     2# def and class multiline Debug directive - code ignored unless debug on  
     3class DbgDir 
     4    def main is shared 
     5        a = .normX(80) 
     6        assert a == 81 
     7     
     8        a = b = 80 
     9        @debug  
     10            s = DbgClass.inc10(a) 
     11            assert s == 'PrettyPrt:90' 
     12            b = 90 
     13        assert a == b 
     14     
     15        @debug print DbgClass.dec10(a) 
     16        assert a == b 
     17         
     18        a = X().xx(80)  
     19        assert a == 91 
     20 
     21    def normX(a as int) as int is shared 
     22        return  a+1 
     23         
     24@debug  
     25    class DbgClass 
     26        def inc10(a as int) as String is shared 
     27            a= a+10 
     28            return 'PrettyPrt:[a]' 
     29             
     30        def dec10(a as int) as String is shared 
     31            a= a-10 
     32            return 'PrettyPrt-:[a]' 
     33             
     34class X 
     35    def xx(a as int) as int 
     36        return a+11 
     37         
  • Tests/200-misc/890-cond-compile-directive/400-classes.cobra

     
     1# class multiline Ns level condCompile directive 
     2class CondCompile 
     3    def main is shared 
     4        a = .normX(80) 
     5        assert a == 81 
     6     
     7        @ver.always a = AllwaysClass.x(80) 
     8        assert a == 90 
     9     
     10        a = X().xx(80) 
     11        assert a == 91 
     12 
     13    def normX(a as int) as int is shared 
     14        return  a+1 
     15         
     16@ver.always 
     17    class AllwaysClass 
     18        def x(a as int) as int is shared 
     19            return a+10 
     20             
     21class X 
     22    def xx(a as int) as int 
     23        return a+11 
  • Tests/200-misc/890-cond-compile-directive/600-unk.cobra

     
     1# unknown version value 
     2class CondComp 
     3    def main is shared 
     4        a='ok' 
     5        @ver._x86 a='x86' # .error. unknown compiler directive version value 
     6        assert a == 'ok' 
  • Tests/200-misc/890-cond-compile-directive/610-unk.cobra

     
     1# unknown version value block  
     2class CondComp 
     3    def main is shared 
     4        a='ok' 
     5        @ver._x86  # .error. unknown compiler directive version value 
     6            a='x86' 
     7            a = '...[a]....' 
     8             
     9        assert a == 'ok' 
  • Tests/200-misc/890-cond-compile-directive/620-unk-class.cobra

     
     1# class multiline Ns level condCompile directive 
     2class CondCompile 
     3    def main is shared 
     4     
     5        @ver.always a = AllwaysClass.x(80) 
     6        assert a == 90 
     7     
     8@ver.always 
     9    class AllwaysClass 
     10        def x(a as int) as int is shared 
     11            return a+10 
     12             
     13@ver._sparc #.error. unknown compiler directive version value 
     14    def xx(a as int) as int 
     15        return a+11 
  • Tests/200-misc/890-cond-compile-directive/100-statement-builtin.cobra

     
     1# single line cond compile  directive  
     2class DbgDir 
     3     
     4    def main is shared 
     5        a = 99 
     6        @ver.never a=44 
     7        assert a == 99  
     8        a = 0 
     9        @ver.always a = 40 
     10        assert a == 40  
     11         
     12        a=0 
     13        @ver.clr a=50 
     14        if CobraCore.runtimePlatform == 'clr', assert a == 50 
     15        else, assert a ==0 
     16             
     17        a = 0 
     18        @ver.jvm a = 60 
     19        if CobraCore.runtimePlatform == 'jvm', assert a == 60 
     20        else, assert a == 0  
     21         
     22        a = 0 
     23        @ver.objc a = 71 
     24        if CobraCore.runtimePlatform == 'objc', assert a == 71 
     25        else, assert a == 0  
     26             
     27        a = 0 
     28        @ver.dotnet a = 60 
     29        if CobraCore.runtimePlatform =='clr' and not CobraCore.isRunningOnMono 
     30            assert a == 60 
     31        else, assert a == 0  
     32         
     33        a = 0 
     34        @ver.mono a = 90 
     35        if CobraCore.isRunningOnMono, assert a == 90 
     36        else, assert a == 0  
     37             
     38             
     39        a=0 
     40        @ver.windows a = 50 
     41        @ver.mac a = 60 
     42        @ver.unix a = 70 
     43        if CobraCore.isRunningOnWindows, assert a == 50 
     44        if CobraCore.isRunningOnMac, assert a == 60 
     45        if CobraCore.isRunningOnUnix, assert a == 70 
     46             
     47        a = 0 
     48        @ver.contracts a =40 
     49        if CobraCore.hasContracts, assert a == 40 
     50        else, assert a == 0  
     51             
     52        #s = 'none' 
     53        #@ver.tests s='tests' 
     54        #if CobraCore.??, assert s == 'tests' 
     55        #else, assert s == 'none'    
     56             
  • Tests/200-misc/890-cond-compile-directive/410-classes-off.cobra

     
     1# class multiline CondCompile directive - code ignored  
     2class CondCompile 
     3    def main is shared 
     4        a = .normX(80) 
     5        assert a == 81 
     6     
     7        a = 80 
     8        @ver.never a = NoClass.inc10(a) 
     9        assert a == 80 
     10     
     11        a = X().xx(80)  
     12        assert a == 91 
     13 
     14    def normX(a as int) as int is shared 
     15        return  a+1 
     16         
     17@ver.never 
     18    class NoClass 
     19        def inc10(a as int) as int is shared 
     20            return a+10 
     21             
     22class X 
     23    def xx(a as int) as int 
     24        return a+11 
     25         
  • Tests/200-misc/890-cond-compile-directive/300-box-decls.cobra

     
     1# def multiline condCompile directive - on 
     2class CondCompile 
     3    def main is shared 
     4        a = .normX(80) 
     5        assert a == 81 
     6     
     7        a = .dbgX(80) 
     8        assert a == 90 
     9         
     10    @ver.always 
     11        def dbgX(a as int) as int is shared 
     12            return a+10 
     13 
     14    def normX(a as int) as int is shared 
     15        return  a+1 
  • Tests/200-misc/890-cond-compile-directive/320-box-decls.cobra

     
     1# multi line condCompile box decls (methods) 
     2class CondCompile 
     3     
     4    @ver.always 
     5        def always(a as int) as int 
     6            return 44 
     7         
     8    @ver.clr 
     9        def clr(a as int) as int 
     10            return a + 1 
     11         
     12    @ver.jvm 
     13        def jvm(a as int) as int 
     14            return a + 1 
     15         
     16    @ver.dotnet 
     17        def dotNet(a as int) as int 
     18            return a + 10 
     19         
     20    @ver.mono 
     21        def mono(a as int) as int 
     22            return a + 2 
     23         
     24    @ver.windows 
     25        def wdws( a as int) as int 
     26            return a + 1 
     27         
     28    @ver.mac 
     29        def mac( a as int) as int 
     30            return a + 2 
     31             
     32    @ver.unix 
     33        def unix( a as int) as int 
     34            return a + 3 
     35         
     36    @ver.tests 
     37        def tests( a as int) as int 
     38            return a  
     39             
     40    @env.HOME 
     41        def envHomeTst( a as int) as int 
     42            return 99 
     43             
     44    def main is shared 
     45        cc = CondCompile() 
     46         
     47        a = 99 
     48        @ver.never  
     49            a = cc.never(40) 
     50        assert a == 99  
     51 
     52        a = 0 
     53        @ver.always 
     54            a = cc.always(40) 
     55        assert a == 44  
     56         
     57        a=0 
     58        @ver.clr  
     59            a = cc.clr(50) 
     60        if CobraCore.runtimePlatform == 'clr', assert a == 51 
     61        else, assert a ==0 
     62             
     63        a = 0 
     64        @ver.jvm  
     65            a = cc.jvm(60) 
     66        if CobraCore.runtimePlatform == 'jvm', assert a == 61 
     67        else, assert a == 0  
     68         
     69        a = 0 
     70        @ver.dotnet  
     71            a = cc.dotNet(50) 
     72        if CobraCore.runtimePlatform =='clr' and not CobraCore.isRunningOnMono 
     73            assert a == 60 
     74        else, assert a == 0  
     75         
     76        a = 0 
     77        @ver.mono  
     78            a = cc.mono(88) 
     79        if CobraCore.isRunningOnMono, assert a == 90 
     80        else, assert a == 0  
     81             
     82             
     83        a=0 
     84        @ver.windows a = cc.wdws(50) 
     85        @ver.mac     a = cc.mac(60) 
     86        @ver.unix    a = cc.unix(70) 
     87        if CobraCore.isRunningOnWindows, assert a == 51 
     88        if CobraCore.isRunningOnMac,  assert a == 62 
     89        if CobraCore.isRunningOnUnix, assert a == 73 
     90        assert a <> 0 
     91         
     92        a = 0 
     93        @ver.tests 
     94            a = cc.tests(47) 
     95            assert a == 47 
     96        assert a <> 0 
     97             
     98             
     99        a = 0 
     100        @env.HOME 
     101            a = cc.envHomeTst(0) 
     102        assert a == 99   
     103         
     104        a = 0 
     105        @env.HOME.'THIS_IS_SPARTA' 
     106            a = cc.envHomeTst(99) 
     107        assert a == 0    
     108         
  • Tests/200-misc/890-cond-compile-directive/560-clr-ver.cobra

     
     1# test cobra version 
     2class CondCompClrVer 
     3     
     4    def main is shared 
     5        vv=Environment.version.toString 
     6        v = int.parse(vv.before('.')) 
     7 
     8        a = 0 
     9        @ver.clr 
     10            print 'version on clr'   
     11            a = 100 
     12        assert a == 100  
     13         
     14     
     15        a = 0 
     16        @ver.clr.50 
     17            print 'clr version >= 5.0'   
     18            a = 50 
     19        if v >= 5, assert a ==50 
     20        else, assert a == 0  
     21     
     22        a = 0 
     23        @ver.clr.40 
     24            print 'clr version >= 4.0'   
     25            a = 40 
     26        if v >= 4, assert a == 40 
     27        else, assert a == 0  
     28         
     29     
     30        a = 0 
     31        @ver.clr.35 
     32            print 'version >= 3.5' 
     33            a = 35 
     34        if v >= 3, assert a == 35 
     35        else, assert a == 0  
     36     
     37        a = 0 
     38        @ver.clr.20 
     39            print 'clr version > 2.0'    
     40            a = 20 
     41        if v >= 2, assert a == 20 
     42        else, assert a == 0  
     43     
     44 
     45        a = 0 
     46        @ver.clr.10 
     47            print 'clr version > 1.0'    
     48            a = 10 
     49        if v >= 1, assert a == 10 
     50        else, assert a == 0  
  • Tests/200-misc/890-cond-compile-directive/700-user.cobra

     
     1# .args.  -define:XX 
     2# User defined version tag 
     3class CondCompUsr 
     4    def main is shared 
     5        a='ok' 
     6        @ver.XX a='xx'  
     7        assert a == 'xx' 
     8         
     9        a='ok' 
     10        @ver.XX 
     11            print 'XX tag specified' 
     12            a = 'XX'     
     13        assert a == 'XX'     
  • Tests/200-misc/890-cond-compile-directive/500-other.cobra

     
     1# other conditional compile  directive for 'other/else' cases 
     2class CondCompOther 
     3     
     4    def main is shared 
     5        a=0 
     6        @ver.windows a = 50 
     7        @ver.mac a = 60 
     8        @ver.unix a = 70 
     9        @ver.otherThan.windows.mac.unix a = 999 
     10     
     11#    @ver.other(windows,mac,unix) a = 999 
     12#    @ver.otherThan.'windows|mac|unix' a = 999 
     13         
     14        if CobraCore.isRunningOnWindows, assert a == 50 
     15        else if CobraCore.isRunningOnMac, assert a == 60 
     16        else if CobraCore.isRunningOnUnix, assert a == 70 
     17        else, assert a == 999 
     18     
     19        a=0 
     20        @ver.otherThan.mac.unix a = 888 
     21        if CobraCore.isRunningOnWindows, assert a == 888 
     22        else, assert a == 0 
     23     
     24        a=0 
     25        @ver.otherThan.windows.mac a = 777 
     26        if CobraCore.isRunningOnUnix, assert a == 777 
     27        else, assert a == 0 
     28 
     29        a=0 
     30        @ver.otherThan.windows.unix a = 666 
     31        if CobraCore.isRunningOnMac, assert a == 666 
     32        else, assert a == 0 
     33     
     34        a=0 
     35        @ver.clr  
     36            a = 50 
     37            a += 1 
     38        @ver.otherThan.clr 
     39            a = 550 
     40            a += 1 
     41        if CobraCore.runtimePlatform == 'clr', assert a == 51 
     42        else, assert a ==551 
     43 
     44        a=0 
     45        @ver.mono  
     46            a = 50 
     47            a += 1 
     48        @ver.otherThan.mono  
     49            a = 500 
     50            a += 1 
     51        if CobraCore.isRunningOnMono, assert a == 51 
     52        else, assert a == 501    
  • Tests/200-misc/890-cond-compile-directive/710-user.cobra

     
     1# .args.  -versionTag:DEMO 
     2# User defined version tag 
     3class CondCompUsr 
     4    def main is shared 
     5        a='prodn' 
     6        @ver.DEMO a='demo'  
     7        assert a == 'demo' 
     8         
     9        a='Production' 
     10        @ver.DEMO 
     11            print 'DEMO specified' 
     12            a = 'demo(lition)'   
     13        assert a.startsWith('demo') 
  • Tests/200-misc/890-cond-compile-directive/720-user.cobra

     
     1# User defined version tag - not defined 
     2class CondCompUsr 
     3    def main is shared 
     4        a='Production' 
     5        @ver.DEMO 
     6            print 'DEMO specified' 
     7            a = 'demo(lition)'   
     8        @ver.otherThan.DEMO 
     9            print 'DEMO NOT specified' 
     10            a = 'nodemo' 
     11 
     12        assert not a.startsWith('demo') 
  • Tests/200-misc/890-cond-compile-directive/550-cobra-ver.cobra

     
     1# test cobra version 
     2class CondCompCobraVer 
     3     
     4    def main is shared 
     5        #tested cobra post 0.9.3 (93) 
     6         
     7        a = 0 
     8        @ver.cobra.100 
     9            print 'version > 1.0.0'  
     10            a = 100 
     11        assert a == 0    
     12         
     13     
     14        a = 0 
     15        @ver.cobra.94 
     16            print 'version > 0.9.4'  
     17            a = 94 
     18        assert a == 0    
     19     
     20        a = 0 
     21        @ver.cobra.93 
     22            print 'version > 0.9.3'  
     23            a = 93 
     24        assert a == 93   
     25         
     26     
     27        a = 0 
     28        @ver.cobra.92 
     29            print 'version > 0.9.2'  
     30            a = 92 
     31        assert a == 92   
     32     
     33        a = 0 
     34        @ver.cobra.90 
     35            print 'version > 0.9.0'  
     36            a = 90 
     37        assert a == 90   
     38     
     39 
     40        a = 0 
     41        @ver.cobra.10 
     42            print 'version > 0.1.0'  
     43            a = 10 
     44        assert a == 10   
     45         
  • Tests/200-misc/890-cond-compile-directive/200-block.cobra

     
     1# multi line cond compile blocks 
     2class CondCompile 
     3     
     4    def main is shared 
     5        a = 99 
     6        @ver.never  
     7            a=40 
     8            a += 4 
     9        assert a == 99  
     10 
     11        a = 0 
     12        @ver.always 
     13            a = 40 
     14            a += 4 
     15        assert a == 44  
     16         
     17        a=0 
     18        @ver.clr  
     19            a = 50 
     20            a += 1 
     21        if CobraCore.runtimePlatform == 'clr', assert a == 51 
     22        else, assert a ==0 
     23             
     24        a = 0 
     25        @ver.jvm  
     26            a = 60 
     27            a +=1 
     28        if CobraCore.runtimePlatform == 'jvm', assert a == 61 
     29        else, assert a == 0  
     30         
     31        a = 0 
     32        @ver.objc  
     33            a = 70 
     34            a += 1 
     35        if CobraCore.runtimePlatform == 'objc', assert a == 71 
     36        else, assert a == 0  
     37             
     38        a = 0 
     39        @ver.dotnet  
     40            a = 60 
     41        if CobraCore.runtimePlatform =='clr' and not CobraCore.isRunningOnMono 
     42            assert a == 60 
     43        else, assert a == 0  
     44         
     45        a = 0 
     46        @ver.mono  
     47            a = 90 
     48        if CobraCore.isRunningOnMono, assert a == 90 
     49        else, assert a == 0  
     50             
     51             
     52        a=0 
     53        @ver.windows  
     54            a = 50 
     55            a += 1 
     56        @ver.mac  
     57            a = 60 
     58            a += 2 
     59        @ver.unix  
     60            a = 70 
     61            a += 3 
     62        if CobraCore.isRunningOnWindows, assert a == 51 
     63        if CobraCore.isRunningOnMac, assert a == 62 
     64        if CobraCore.isRunningOnUnix, assert a == 73 
     65             
     66        a = 0 
     67        @ver.contracts  
     68            a = 40 
     69        if CobraCore.hasContracts, assert a == 40 
     70        else, assert a == 0  
     71             
     72        #s = 'none' 
     73        #@ver.tests s='tests' 
     74        #if CobraCore.??, assert s == 'tests' 
     75        #else, assert s == 'none'    
     76             
     77        @env.HOME 
     78            assert nil <> Environment.getEnvironmentVariable('COBRA_HOPS_TWEAK') 
     79             
     80        #print '#' 
     81        @env.HOME.'/Users/hops' 
     82            print Environment.getEnvironmentVariable('HOME') 
  • Tests/200-misc/890-cond-compile-directive/310-box-decls-off.cobra

     
     1# def multiline condcompile directive - off method ignored 
     2class CondCompile 
     3    def main is shared 
     4        a = .normX(80) 
     5        assert a == 81 
     6     
     7        a = .dbgX(80) # .error. Cannot find a definition 
     8        assert a == 90 
     9         
     10    @ver.never 
     11        def dbgX(a as int) as int is shared 
     12            return a+10 
     13 
     14    def normX(a as int) as int is shared 
     15        return  a+1 
     16             
  • Tests/200-misc/890-cond-compile-directive/552-cobra-ver.cobra

     
     1# test cobra version - tag elided 
     2class CondCompCobraVer 
     3     
     4    def main is shared 
     5        #tested cobra post 0.9.3 (93) 
     6         
     7        a = 0 
     8        @ver.100 
     9            print 'version > 1.0.0'  
     10            a = 100 
     11        assert a == 0    
     12         
     13     
     14        a = 0 
     15        @ver.94 
     16            print 'version > 0.9.4'  
     17            a = 94 
     18        assert a == 0    
     19     
     20        a = 0 
     21        @ver.93 
     22            print 'version > 0.9.3'  
     23            a = 93 
     24        assert a == 93   
     25         
     26     
     27        a = 0 
     28        @ver.92 
     29            print 'version > 0.9.2'  
     30            a = 92 
     31        assert a == 92   
     32     
     33        a = 0 
     34        @ver.90 
     35            print 'version > 0.9.0'  
     36            a = 90 
     37        assert a == 90   
     38     
     39 
     40        a = 0 
     41        @ver.10 
     42            print 'version > 0.1.0'  
     43            a = 10 
     44        assert a == 10   
     45