Wiki

Ticket #312: cond-compile-directive.patch

File cond-compile-directive.patch, 45.0 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

     
    14751475    def _computeArgImplications(options as OptionValues) 
    14761476        if options.getDefault('target', '') == 'lib' and not options.isSpecified('compile') 
    14771477            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 
     1478        if options.debugOn and not options.isSpecified('debugging-tips') 
    14821479            options['debugging-tips'] = false 
    14831480        if options.boolValue('turbo') 
    14841481            options['contracts'] = 'none' 
     
    16561653    get buildStandardLibrary as bool 
    16571654        return .boolValue('build-standard-library') 
    16581655 
     1656    get debugOn as bool 
     1657        return .getDefault('debug', '-') not in ['-', '0', 0, false] 
     1658        # set values are '+', '1', 'pdbOnly', 'full' 
     1659     
     1660    get runtimePlatform 
     1661        bkend = .getDefault('back-end', 'none') to String 
     1662        return if(bkend == 'none', CobraCore.runtimePlatform, bkend) 
     1663     
    16591664    def addExtraUse(useSource as String) 
    16601665        es = .getDefault('extra-source', '') to String 
    16611666        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>  - 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                rtp = .backEnd.compiler.options.runtimePlatform 
     2212                branch ver.text # builtin platform environmental version identifiers 
     2213                    on 'clr',     enableBlock = (rtp == 'clr') 
     2214                    on 'jvm',     enableBlock = (rtp == 'jvm') 
     2215                    on 'objc',    enableBlock = (rtp == 'objc') # NYI 
     2216                    on 'mono',    enableBlock = (rtp == 'clr' and CobraCore.isRunningOnMono) 
     2217                    on 'dotnet',  enableBlock = (rtp == 'clr' and not CobraCore.isRunningOnMono) 
     2218                    on 'windows', enableBlock = CobraCore.isRunningOnWindows 
     2219                    on 'unix',    enableBlock = CobraCore.isRunningOnUnix 
     2220                    on 'mac',     enableBlock = CobraCore.isRunningOnMac 
     2221                    on 'asserts', enableBlock = CobraCore.willCheckAssert 
     2222                    on 'contracts', enableBlock = CobraCore.hasContracts 
     2223                    on 'tests',   enableBlock = .backEnd.compiler.options.boolValue('include-tests') 
     2224                    on 'never',   enableBlock = false  # disable section of code 
     2225                    on 'always',  enableBlock = true   # always enabled 
     2226                    else 
     2227                        # TODO: support arbitrary value passed on compiler cmdlime ( -define:<verValue>) 
     2228                        sugg='Known version values include "clr", "jvm","objc", "mono", "dotnet", "windows", "linux", "mac", "tests", "asserts", "contracts", "never", "always".' 
     2229                        .throwError(token, 'Unknown compiler directive version value "[ver.text]" in "@ver.[ver.text]". [sugg]') 
     2230            on 'env'    # '@env'    @env.<envVar>[.<value>]  e.g. @env.HOME and @env.OS.Windows_NT 
     2231                .expect('DOT') 
     2232                envVar = .grab.text  
     2233                envValue as String? = nil 
     2234                if .optional('DOT')  # has value to check 
     2235                    envValue = .grab.value to String 
     2236                val = Environment.getEnvironmentVariable(envVar) 
     2237                enableBlock = (val <> nil) 
     2238                if enableBlock and envValue 
     2239                    val = Environment.getEnvironmentVariable(envVar)  
     2240                    enableBlock = (val == envValue) 
     2241            else     
     2242                .throwError(token, 'Unexpected compiler directive "[token.text]". Expecting conditional compile directive using "@debug", "@ver.VALUE" or "@env.VAR" ') 
     2243        return enableBlock 
     2244         
    21522245    def assertStmt as Stmt 
    21532246        token = .expect('ASSERT') 
    21542247        expr = .expression 
  • Source/BackEndJvm/JavaGenerator.cobra

     
    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 
     
    506506                            return 0 
    507507                    on 'clr' # mono or dotNet 
    508508                        if  rtPlatform <> 'clr'  
    509                             print 'Skipping test because requirement for "clr" is not met.' 
     509                            msg = 'Skipping test because requirement for "clr" is not met.' 
     510                            print msg 
     511                            _showSkipMsg(msg) 
    510512                            return 0 
    511513                    on 'jvm' 
    512514                        if  rtPlatform <> 'jvm' 
    513                             print 'Skipping test because requirement for "jvm" is not met.' 
     515                            msg = 'Skipping test because requirement for "jvm" is not met.' 
     516                            print msg    
     517                            _showSkipMsg(msg) 
    514518                            return 0 
    515519                    else 
    516520                        if what.endsWith('.dll') 
     
    552556                comment = firstLine[firstLine.indexOf('.skip.')+6:].trim 
    553557                if comment.length, comment = '"' + comment + '"' 
    554558                msg = 'Skipping test because of directive. [comment]'.trim 
    555                 _statusWriter.indent 
    556                 _statusWriter.writeLine(msg) 
    557                 _statusWriter.dedent 
     559                _showSkipMsg(msg) 
    558560                print msg 
    559561                return 0 
    560562 
     
    571573            throw Exception('Bad first line: [lines[0]]') 
    572574 
    573575        return 1 # continue processing in caller 
     576     
     577    def _showSkipMsg( msg as String) 
     578        _statusWriter.indent 
     579        _statusWriter.writeLine(msg) 
     580        _statusWriter.dedent 
    574581         
    575582    def _getInlineMessages(lines as List<of String>, offset as int, expectingError as out bool) as Dictionary<of int, String> 
    576583        """ 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/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/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/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