Changeset 1746
- Timestamp:
- 11/08/08 20:53:13 (2 months ago)
- Location:
- cobra/trunk
- Files:
-
- 1 added
- 5 modified
-
Developer/IntermediateReleaseNotes.text (modified) (1 diff)
-
Source/CommandLine.cobra (modified) (1 diff)
-
Source/Compiler.cobra (modified) (3 diffs)
-
Source/TestifyRunner.cobra (modified) (1 diff)
-
Source/TypeProxies.cobra (modified) (1 diff)
-
Tests/700-command-line/850-correct-case.cobra (added)
Legend:
- Unmodified
- Added
- Removed
-
cobra/trunk/Developer/IntermediateReleaseNotes.text
r1745 r1746 29 29 30 30 Adding the extension (.exe or .dll) is neither required nor problematic. 31 32 * Added command line option -correct-case (or -cc) to change the case of types to the correct cases in situations that are not ambiguous. 31 33 32 34 * Modified commandline options so -r becomes synonym for -run rather -
cobra/trunk/Source/CommandLine.cobra
r1738 r1746 149 149 'args': 'none|inline|methods', 150 150 'default': 'inline', 151 }, 152 { 153 'name': 'correct-case', 154 'synonyms': ['cc'], 155 'description': 'Rewrite source files with case corrected where the correction is unambiguous. For example, "string" --> "String". If possible, you should set your editor to automatically reload files when using this option.', 156 'type': 'bool', 151 157 }, 152 158 { -
cobra/trunk/Source/Compiler.cobra
r1723 r1746 285 285 if stopAfterBindInt, return # in support of the -doc option 286 286 .bindImp 287 .writeSourceCodeCorrections 287 288 .writeSharp 288 289 if writeTestInvocation … … 1099 1100 1100 1101 ## 1102 ## Source Code Corrections 1103 ## 1104 1105 var _sourceCorrections = Dictionary<of String, Dictionary<of int, List<of Replacement>>>() 1106 """ 1107 The first key of type String is filename. 1108 The second key of type int is line number. 1109 """ 1110 1111 def correctSource(token as IToken, replace as String) 1112 if not _sourceCorrections.containsKey(token.fileName) 1113 _sourceCorrections[token.fileName] = Dictionary<of int, List<of Replacement>>() 1114 file = _sourceCorrections[token.fileName] 1115 if not file.containsKey(token.lineNum) 1116 file[token.lineNum] = List<of Replacement>() 1117 file[token.lineNum].add(Replacement(token.colNum, token.text, replace)) 1118 1119 def writeSourceCodeCorrections 1120 # TODO: this doesn't properly handle when the replacements are a different length than the 1121 # original next, but then this isn't needed right now since the only type of correction 1122 # being done is case correction 1123 v = .verbosity 1124 for fileName, lineToReplacements in _sourceCorrections 1125 if v, print 'Correcting source:', fileName 1126 lineNums = List<of int>(lineToReplacements.keys) 1127 lineNums.sort 1128 lines = File.readAllLines(fileName) 1129 for lineNum in lineNums 1130 for rep in lineToReplacements[lineNum] 1131 assert rep.oldText.length == rep.newText.length # see TODO above 1132 if v >= 2, print 'Correct: Line [lineNum], Column [rep.colNum], Old "[rep.oldText]", New "[rep.newText]"' 1133 i = lineNum - 1 1134 line = lines[i] 1135 # print line 1136 oldLen = line.length 1137 col = rep.colNum - 1 1138 lines[i] = line[:col] + rep.newText + line[col+rep.oldText.length:] 1139 # print lines[i] 1140 assert lines[i].length == oldLen 1141 try 1142 File.writeAllLines(fileName, lines) 1143 catch exc as Exception 1144 .warning(CobraWarning(fileName, nil, 'Cannot write source code corrections due to: [exc.message] ([exc.getType.name]).')) 1145 1146 ## 1101 1147 ## Important system library types 1102 1148 ## … … 1529 1575 1530 1576 1577 class Replacement 1578 1579 def init(colNum as int, oldText as String, newText as String) 1580 _colNum = colNum 1581 _oldText = oldText 1582 _newText = newText 1583 1584 get colNum from var as int 1585 1586 get oldText from var as String 1587 1588 get newText from var as String 1589 1590 1531 1591 class TestCompiler 1532 1592 inherits Compiler -
cobra/trunk/Source/TestifyRunner.cobra
r1723 r1746 197 197 for baseName in paths 198 198 baseName = Utils.normalizePath(baseName) 199 if baseName.startsWith('_'), continue 199 200 if baseName.endsWith('.cobra') or baseName.endsWith('.COBRA') 200 201 _testifyCount += .testifyFile(baseName) -
cobra/trunk/Source/TypeProxies.cobra
r1718 r1746 485 485 def _resolveType as IType is override 486 486 # don't need to check "basic types" like int, bool, etc. here. the parser does those. 487 if Utils.isCapped(_name) 488 symbol = .compiler.symbolForName(.name, true, false) # nested enum and class types are capped and can be members of the current class 487 name = .name 488 if Utils.isCapped(name) 489 symbol = .compiler.symbolForName(name, true, false) # nested enum and class types are capped and can be members of the current class 489 490 else 490 491 symbol = nil 491 492 if symbol is nil 492 sugg = '' 493 if not Utils.isCapped(_name) 494 sugg = _name.capped 495 other = .compiler.symbolForName(sugg, true, false) 496 sugg = if(other, ' Try "[sugg]".', '') 497 .throwError('Cannot find type for "[_name]".[sugg]') 493 correctCase = .compiler.options.boolValue('correct-case') 494 if correctCase 495 if not Utils.isCapped(name) 496 # not very sophisticated, but catches 'string', 'object', etc. 497 name = name.capped 498 symbol = .compiler.symbolForName(name, true, false) 499 if symbol is not nil 500 .compiler.correctSource(.token, name) 501 if symbol is nil 502 sugg = '' 503 if not Utils.isCapped(_name) 504 sugg = name.capped 505 other = .compiler.symbolForName(sugg, true, false) 506 sugg = if(other, ' Try "[sugg]". Also, consider the -correct-case option (see cobra -h for details).', '') 507 .throwError('Cannot find type for "[_name]".[sugg]') 498 508 if symbol inherits ITypeProxy 499 509 return symbol.realType
