Ticket #312: cond-compile-directive-ver.patch
File cond-compile-directive-ver.patch, 59.9 KB (added by hopscc, 12 years ago) |
---|
-
Source/BackEndObjC/ObjcGenerator.cobra
892 892 get newForObjcTest as String is override 893 893 return if(not _baseClass.isExtern, ' new', '') 894 894 895 class 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 '' 895 903 904 get objcInvariantVisibility as String is override 905 throw ShouldNotCallException(.getType) 906 907 get objcKeyWord as String is override 908 return '' 909 910 911 896 912 class Interface is partial 897 913 898 914 get objcInit as String is override … … 1126 1142 1127 1143 pass # to-do 1128 1144 1145 class SuppressibleStmt is partial 1146 1147 pass # to-do 1129 1148 1130 1149 class ExpectStmt is partial 1131 1150 -
Source/Boxes.cobra
1650 1650 m = _baseClass.memberForName(name) 1651 1651 return m 1652 1652 1653 class 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) 1653 1662 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 1654 1679 class Struct 1655 1680 is partial 1656 1681 inherits ClassOrStruct -
Source/CommandLine.cobra
519 519 'description': 'Print just the version number.', # ([.versionString]).', 520 520 'type': 'main', 521 521 }, 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 }, 522 530 ] 523 531 524 532 … … 544 552 545 553 """ 546 554 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 547 563 get versionString as String is shared 548 564 ensure result.count(c'.') >= 2 or result.startsWith('svn:') 549 565 … … 551 567 # not the current Source directory. And Snapshot can be a final release such as '0.7.4' for a 552 568 # period of time where this Cobra source represents an svn-post-RELEASE. 553 569 # 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]' 556 572 # ver += ', informal release 2009-03-01' 557 573 return ver 558 574 559 575 get platformString as String is shared 560 return .clrVersion + ' on ' + .opSysString576 return .clrVersion + ' on ' + CobraCore.operatingSystemDescription 561 577 562 578 get clrVersion as String is shared 563 579 """ Get runtime version, like '.NET CLR v4.0.30319' or 'Mono 2.6.7 CLR v2.0.50727'. """ … … 571 587 pass # if the above fails for any reason, that's okay 572 588 else 573 589 ver = '.NET' 574 ver += ' CLR ' + Assembly.getAssembly(Object).imageRuntimeVersion590 ver += ' CLR ' + .clrVersionNumber 575 591 return ver 576 592 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 624 597 def _getCommandOutput(command as String, args as String) as String is shared 625 598 p = System.Diagnostics.Process() 626 599 p.startInfo.fileName = command … … 926 899 927 900 exeFileName as String? = nil 928 901 runArgs = .options.getStringList('run-args') 929 # TODO: what's this?930 # exeArgs = .options.getDefaultLOStr('exe-args')931 # if exeArgs.count932 # exeFileName = exeArgs[0]933 # runArgs = exeArgs[1:]934 902 p = c.runProcess(exeFileName, runArgs) 935 903 if _verbosity >= 1 936 904 print 'Running: [p.startInfo.fileName] [p.startInfo.arguments]' … … 1475 1443 def _computeArgImplications(options as OptionValues) 1476 1444 if options.getDefault('target', '') == 'lib' and not options.isSpecified('compile') 1477 1445 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') 1482 1447 options['debugging-tips'] = false 1483 1448 if options.boolValue('turbo') 1484 1449 options['contracts'] = 'none' … … 1656 1621 get buildStandardLibrary as bool 1657 1622 return .boolValue('build-standard-library') 1658 1623 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 1659 1635 def addExtraUse(useSource as String) 1660 1636 es = .getDefault('extra-source', '') to String 1661 1637 useSource = useSource.trim -
Source/NameSpace.cobra
7 7 def extensionMemberFor(box as Box, name as String) as IMember? 8 8 get isFromBinaryLibrary as bool 9 9 get isNames as String* 10 11 10 12 11 class NameSpace 13 12 is partial 14 13 inherits Container<of INameSpaceMember> … … 341 340 if _superNameSpace 342 341 _superNameSpace._symbolsForNameFromUseDirectives(name, members) 343 342 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 344 350 def addDecl(decl as INameSpaceMember) is override 345 351 base.addDecl(decl) 346 352 if decl inherits NameSpace … … 399 405 decl._unifyInto(newUniForDecl) 400 406 else 401 407 uni.addDecl(decl) 408 409 class 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 402 421 403 404 422 class UseDirective 405 423 is partial 406 424 inherits SyntaxNode -
Source/BackEndClr/SharpGenerator.cobra
243 243 sourceDir = Path.getDirectoryName(Assembly.getEntryAssembly.location) ? '' 244 244 outDir = Path.getDirectoryName(outName) ? '' 245 245 _copyFile(sourceDir, outDir, 'Cobra.Core.dll') 246 if .options. getDefault('debug', '') not in ['', '-', '0', 0, false]246 if .options.debugOn 247 247 if CobraCore.isRunningOnMono and File.exists(Path.combine(sourceDir, 'Cobra.Core.dll.mdb')) 248 248 _copyFile(sourceDir, outDir, 'Cobra.Core.dll.mdb') 249 249 else if File.exists(Path.combine(sourceDir, 'Cobra.Core.pdb')) … … 604 604 is partial 605 605 606 606 get sharpInit as String is abstract 607 607 """ initialised unset value - initial value to init an item of this type to """ 608 608 609 get sharpNameComponent as String 609 610 """ 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. 611 613 """ 612 614 ensure result.length > 0 # TODO? Move to interface 613 615 return .sharpRef … … 1032 1034 return 'this' 1033 1035 1034 1036 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 1036 1042 get sharpName as String is override 1037 1043 return _name.replace('<of', '<') 1038 1044 … … 1151 1157 pass 1152 1158 1153 1159 get sharpInvariantVisibility as String is abstract 1154 1160 """ Default visibility for invariant guard methods in Box of this type""" 1161 1155 1162 def writeSharpInvariantMethod(sw as CurlyWriter) 1156 1163 if .compiler.options['contracts'] <> 'none' 1157 1164 sw.write('\nint _ih_invariantGuard;\n\n') … … 1234 1241 1235 1242 get newForSharpTest as String is override 1236 1243 return if(not _baseClass.isExtern, ' new', '') 1244 1245 class 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 '' 1237 1253 1254 get sharpInvariantVisibility as String is override 1255 throw ShouldNotCallException(.getType) 1238 1256 1257 get sharpKeyWord as String is override 1258 throw ShouldNotCallException(.getType) 1259 #return '' 1260 1261 1239 1262 class Interface is partial 1240 1263 1241 1264 get sharpInit as String is override … … 2505 2528 _ifInheritsVar.ifInheritsStack.pop 2506 2529 if close 2507 2530 sw.dedent 2508 sw.write(' }\n')2531 sw.write(' }\n') 2509 2532 2510 2533 2511 2534 class BreakStmt … … 2524 2547 sw.write('continue;\n') 2525 2548 2526 2549 2550 class 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 2527 2557 class ExpectStmt 2528 2558 is partial 2529 2559 -
Source/CobraParser.cobra
372 372 topNS = _module.topNameSpace 373 373 if not _fileName.endsWith('SystemInterfaces.cobra') 374 374 .backEnd.setDefaultUseDirectives(topNS) 375 while .peek, .parseTopLevel 375 while .peek, .parseTopLevel(topNS) 376 376 finally 377 377 _nameSpaceStack.pop 378 378 return _module to ! 379 380 def parseTopLevel as ISyntaxNode?379 380 def parseTopLevel(ns as NameSpace) as ISyntaxNode? 381 381 """ Returns the node that was parsed, but will return nil for EOL, EOF and compiler directives. """ 382 382 what as ISyntaxNode? 383 383 tok = .peek 384 if tok is nil, return nil 384 if tok is nil, return nil # EOF 385 385 isGood = true 386 386 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 413 401 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 420 406 if not isGood 421 407 sugg = if(tok.text.length, Compiler.suggestionFor(tok.text), nil) 422 408 sugg = if(sugg, ' Try "[sugg]".', '') 423 409 .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 428 411 return what 429 430 def compilerDirective 412 413 def compilerDirective(ns as NameSpace) 431 414 if .peek.which == 'AT_ID' 432 415 token = .grab 433 416 else … … 437 420 branch token.value to String 438 421 on 'help' 439 422 if .peek is nil, .throwError(ErrorMessages.unexpectedEndOfFile) 440 node = .parseTopLevel 423 node = .parseTopLevel(ns) 441 424 if node is nil, _warning(token, '@help is not implemented for this element.') 442 425 else, node.isHelpRequested = true 426 on 'debug' or 'ver' or 'env' # '@debug', '@ver', '@env' 427 .suppressibleNSDecls(ns, token to !) 443 428 on 'throw' 444 429 # throw an internal error. used for testing that the compiler will catch and report these as internal errors 445 430 .expect('EOL') … … 515 500 .throwError('Cannot set command line arguments from directive because no arguments parser is available.') 516 501 else 517 502 .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 519 520 def useDirective as UseDirective 520 521 """ 521 522 Example source: … … 1050 1051 else 1051 1052 parent = .curNameSpace to IParentSpace 1052 1053 return EnumDecl(parent, wordToken, idToken, name, isNames, attribs, storageType, docString, enumMembers) 1053 1054 1054 1055 def extendDecl as Extension 1055 1056 # TODO: extend Qualified.Name 1056 1057 wordToken = .expect('EXTEND') … … 1137 1138 try 1138 1139 indented = .optionalIndent 1139 1140 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) 1161 1142 finally 1162 1143 for tok in idTokens, _nameSpaceStack.pop 1163 1144 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 1165 1170 def _nameSpaceAddDecl(ns as NameSpace, decl as INameSpaceMember) as INameSpaceMember 1166 1171 """ 1167 1172 Adds the decl to the given namespace or throws an error for duplicate declarations. … … 1171 1176 # TODO: complain if inheritance or is-names are different. at least for inheritance, that needs to be done post-parsing 1172 1177 checkForDups = true 1173 1178 if 'partial' in decl.isNames 1179 # otherDecl = _chkPartialDecl(ns, decl, inout checkForDups) 1180 # if otherDecl 1181 # return otherDecl 1174 1182 box = decl to? Box 1175 1183 if box is nil, .throwError(decl.token, '[decl.englishName.capitalized] cannot be "partial".') 1176 1184 if not (box inherits Class or box inherits Struct or box inherits Interface) … … 1210 1218 if checkForDups 1211 1219 if ns.declForName(decl.name) 1212 1220 .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) 1214 1222 .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 1215 1223 ns.addDecl(decl) 1216 1224 return decl … … 1236 1244 on 'VAR', .addDecl(box, .boxFieldDecl(true)) 1237 1245 on 'CONST', .addDecl(box, .boxFieldDecl(false)) 1238 1246 on 'INVARIANT', .declareInvariant 1239 on 'EOL', .endOfLine1240 on 'ENUM', .addDecl(box, .enumDecl)1247 on 'EOL', .endOfLine 1248 on 'ENUM', .addDecl(box, .enumDecl) 1241 1249 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 1248 1259 branch .peek.text 1249 1260 on 'ensure', sugg = 'invariant' 1250 1261 on 'void', sugg = 'def' … … 1271 1282 finally 1272 1283 _isNamesStack.pop 1273 1284 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 1274 1302 def classPass 1275 1303 if .curBox.declsInOrder.count 1276 1304 _warning('Encountered "pass" in a class that already has declared members.') # TODO: change to an error … … 2028 2056 expectEOL = true 2029 2057 branch token.which 2030 2058 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) 2036 2060 on 'ASSERT' 2037 2061 s = .assertStmt 2038 2062 on 'BRANCH' … … 2148 2172 ## 2149 2173 ## Individual Statements 2150 2174 ## 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 2151 2182 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 2152 2289 def assertStmt as Stmt 2153 2290 token = .expect('ASSERT') 2154 2291 expr = .expression -
Source/BackEndJvm/JavaGenerator.cobra
182 182 # above should be something non platform dependent (COBRA_HOME ?) 183 183 outDir = Path.getDirectoryName(outName) ? '' 184 184 _copyFile(sourceDir, outDir, 'Cobra.Core.jar') 185 #if .options. getDefault('debug', '') not in ['', '-', '0', 0, false]185 #if .options.debugOn 186 186 # copy any debug files 187 187 # TODO: probably also need to adjust Manifest File Class-Path for cobra RTL 188 188 … … 1151 1151 return if(not _baseClass.isExtern, ' new', '') 1152 1152 1153 1153 1154 class 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 1154 1170 class Interface is partial 1155 1171 1156 1172 get javaInit as String is override … … 2130 2146 _ifInheritsVar.ifInheritsStack.pop 2131 2147 if close 2132 2148 sw.dedent 2133 sw.write(' }\n')2149 sw.write(' }\n') 2134 2150 2135 2151 2136 2152 class BranchStmt is partial … … 2201 2217 base.writeJavaDef(sw) 2202 2218 sw.write('continue;\n') 2203 2219 2220 class SuppressibleStmt is partial 2221 def writeJavaDef(sw as CurlyWriter) 2222 base.writeJavaDef(sw) 2223 sw.write('// Suppressible Stmt - enabled\n') 2224 _stmt.writeJavaStmt(sw) 2204 2225 2205 2226 class ExpectStmt is partial 2206 2227 -
Source/TestifyRunner.cobra
267 267 duration = DateTime.now.subtract(_startTime) 268 268 print 269 269 print 'Finished at', DateTime.now 270 print '[_testifyCount ] Tests in [duration].'270 print '[_testifyCount + _failureCount] Tests in [duration].' 271 271 if _failureCount 272 272 print '[_failureCount] Failures.' 273 273 print … … 364 364 365 365 def _runtimePlatform(options as OptionValues?) as String 366 366 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 369 368 370 369 def _runSetupScript 371 370 setUpScript = if(Utils.isRunningOnUnix, 'testify-set-up', 'testify-set-up.bat') … … 506 505 return 0 507 506 on 'clr' # mono or dotNet 508 507 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) 510 511 return 0 511 512 on 'jvm' 512 513 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) 514 517 return 0 515 518 else 516 519 if what.endsWith('.dll') … … 552 555 comment = firstLine[firstLine.indexOf('.skip.')+6:].trim 553 556 if comment.length, comment = '"' + comment + '"' 554 557 msg = 'Skipping test because of directive. [comment]'.trim 555 _statusWriter.indent 556 _statusWriter.writeLine(msg) 557 _statusWriter.dedent 558 _showSkipMsg(msg) 558 559 print msg 559 560 return 0 560 561 … … 571 572 throw Exception('Bad first line: [lines[0]]') 572 573 573 574 return 1 # continue processing in caller 575 576 def _showSkipMsg( msg as String) 577 _statusWriter.indent 578 _statusWriter.writeLine(msg) 579 _statusWriter.dedent 574 580 575 581 def _getInlineMessages(lines as List<of String>, offset as int, expectingError as out bool) as Dictionary<of int, String> 576 582 """ Walk lines and accumulate inline warnings and error messages. """ -
Source/Statements.cobra
362 362 cue init(tok as IToken) 363 363 base.init(tok) 364 364 365 class 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 365 386 387 366 388 class ExpectStmt inherits Stmt is partial 367 389 368 390 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 3 class 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 23 class 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 3 class 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 3 class 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 3 class 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 3 class 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 3 class 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 23 class 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 3 class 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 3 class 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 22 class 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 3 class 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 3 class 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 29 class 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 3 class 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 3 class 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 29 class 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 3 class 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 34 class 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 3 class 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 3 class 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 34 class 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 2 class 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 21 class 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 2 class 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 2 class 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 2 class 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 2 class 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 2 class 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 22 class 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 2 class 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) 2 class 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 2 class 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 3 class 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 2 class 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 3 class 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 2 class 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 2 class 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 2 class 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 2 class 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 2 class 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