Ticket #312: cond-compile-directive.patch
File cond-compile-directive.patch, 45.0 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
1475 1475 def _computeArgImplications(options as OptionValues) 1476 1476 if options.getDefault('target', '') == 'lib' and not options.isSpecified('compile') 1477 1477 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') 1482 1479 options['debugging-tips'] = false 1483 1480 if options.boolValue('turbo') 1484 1481 options['contracts'] = 'none' … … 1656 1653 get buildStandardLibrary as bool 1657 1654 return .boolValue('build-standard-library') 1658 1655 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 1659 1664 def addExtraUse(useSource as String) 1660 1665 es = .getDefault('extra-source', '') to String 1661 1666 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> - 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 2152 2245 def assertStmt as Stmt 2153 2246 token = .expect('ASSERT') 2154 2247 expr = .expression -
Source/BackEndJvm/JavaGenerator.cobra
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 … … 506 506 return 0 507 507 on 'clr' # mono or dotNet 508 508 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) 510 512 return 0 511 513 on 'jvm' 512 514 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) 514 518 return 0 515 519 else 516 520 if what.endsWith('.dll') … … 552 556 comment = firstLine[firstLine.indexOf('.skip.')+6:].trim 553 557 if comment.length, comment = '"' + comment + '"' 554 558 msg = 'Skipping test because of directive. [comment]'.trim 555 _statusWriter.indent 556 _statusWriter.writeLine(msg) 557 _statusWriter.dedent 559 _showSkipMsg(msg) 558 560 print msg 559 561 return 0 560 562 … … 571 573 throw Exception('Bad first line: [lines[0]]') 572 574 573 575 return 1 # continue processing in caller 576 577 def _showSkipMsg( msg as String) 578 _statusWriter.indent 579 _statusWriter.writeLine(msg) 580 _statusWriter.dedent 574 581 575 582 def _getInlineMessages(lines as List<of String>, offset as int, expectingError as out bool) as Dictionary<of int, String> 576 583 """ 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/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/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/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