Wiki

Changeset 2315

Show
Ignore:
Timestamp:
03/12/10 09:25:11 (2 years ago)
Author:
Chuck.Esterbrook
Message:

An above error about numeric types indicates that you may want to set the default numeric type with "@number [expectedType]" in a source file or "cobra -number:[expectedType]" at the command line.

Location:
cobra/trunk
Files:
6 added
8 modified

Legend:

Unmodified
Added
Removed
  • cobra/trunk/Developer/IntermediateReleaseNotes.text

    r2301 r2315  
    5454 
    5555* Added support for chain comparisons such as `0 <= i < 9`. 
     56 
     57* Cobra's use of `decimal` has advantages around accuracy, but can also cause confusion when using libraries that are centered around `float`. The compiler now detects this situation and suggests, via warning: 
     58 
     59    An above error about numeric types indicates that you may want to set the default numeric type with "@number [expectedType]" in a source file or "cobra -number:[expectedType]" at the command line. 
    5660 
    5761 
  • cobra/trunk/Source/BackEndClr/SharpGenerator.cobra

    r2295 r2315  
    232232                _compileSharpWithProcessCSC(optChar, .joinOptions(backEndOptions), sharpFileNameList) 
    233233            else 
    234                 print 'Unknown -native-compiler:[nativeCompiler]' 
    235                 _exitFromErrors 
    236  
    237             if .errors.count 
    238                 _exitFromErrors 
     234                .recordError(SourceException('Unknown -native-compiler:[nativeCompiler]')) 
    239235 
    240236            _deleteIntermediateFiles 
  • cobra/trunk/Source/CobraTokenizer.cobra

    r2196 r2315  
    880880                on 'skip', pass 
    881881                on 'warning', pass 
     882                on 'warning-lax', pass 
    882883                else, .throwError('Unrecognized compiler directive "[name]".') 
    883884            return true 
  • cobra/trunk/Source/Compiler.cobra

    r2304 r2315  
    286286            BindImplementationPhase, 
    287287            IdentifyMainPhase, 
     288            SuggestDefaultNumberPhase, 
    288289        ] 
    289290 
     
    297298        if .options.boolValue('timeit') 
    298299            phases.add(CountNodesPhase(this)) 
     300        for i, phase in phases.numbered, phase.stableOrder = i 
     301        phases.sort  # see Phase.order and .compareTo 
    299302        return phases 
    300303 
    301     def runPhase(phaseType as Type) 
     304    def runPhase(phaseType as Type) as bool 
    302305        require phaseType.isSubclassOf(Phase) 
    303         .runPhase(phaseType(this) to Phase) 
    304  
    305     def runPhase(phase as Phase) 
     306        ensure result implies .errors.count > old .errors.count 
     307        return .runPhase(phaseType(this) to Phase) 
     308 
     309    def runPhase(phase as Phase) as bool 
    306310        require 
    307311            phase.compiler is this 
     
    311315            not phase.isRunning 
    312316            .lastPhase is phase 
     317            result implies .errors.count > old .errors.count 
    313318        body 
    314319            oldErrorCount = .errors.count 
     
    317322                phase.run 
    318323                .writeSourceCodeCorrections 
     324                return .errors.count > oldErrorCount 
    319325            finally 
    320326                _curPhase = nil 
    321327                _lastPhase = phase 
    322             if .errors.count > oldErrorCount, _exitFromErrors 
    323328 
    324329 
     
    372377        .willWriteTestInvocation = writeTestInvocation 
    373378        _pathsToCompile = paths 
     379        # now, essentially, do this: 
     380        #     for phase in .makePhases, runPhase(phase) 
     381        # but pay attention to things like errors and stopCompilation 
     382        hasErrors = false 
    374383        for phase in .makePhases 
    375384            if stopCompilation and stopCompilation(this), break 
    376             .runPhase(phase) 
    377      
     385            if not hasErrors or phase.willRunWithErrors 
     386                if .runPhase(phase), hasErrors = true 
     387        if hasErrors, _exitFromErrors 
     388 
    378389    def testifyFilesNamed(fileNames as IList<of String>, options as OptionValues, resultsWriter as IndentedWriter, verbose as bool) 
    379390        """ 
     
    387398        .defaultOutName = if(.options.buildStandardLibrary, 'Cobra.Lang.dll', fileNames[0]) 
    388399        _pathsToCompile = fileNames 
     400        hasErrors = false 
    389401        for phase in .makePhases 
    390402            if verbose, print 'Testify phase:', phase.description 
    391             .runPhase(phase) 
     403            if not hasErrors or phase.willRunWithErrors 
     404                if .runPhase(phase), hasErrors = true 
    392405            if verbose 
    393406                .dumpModulesForTestify(resultsWriter, 'Modules after: [phase.description]') 
    394407                print bar 
     408        if hasErrors, throw StopCompilation(this)  # testify runner wants this 
    395409        # TODO: to display the intermediate source: 
    396410        #   for module in .modules 
     
    9991013 
    10001014    def _exitFromErrors 
    1001         # TODO 2009-12 Having problems with this in same cases. Not important to enforce right now. 
     1015        # TODO 2009-12 Having problems with this requirement in same cases. Not important to enforce right now. 
    10021016        # require .errors.count 
     1017        """ 
     1018        This method should not be invoked from partial classes found in phases or back-ends. Some 
     1019        phases want to run even when there are errors from previous phases. This is managed by 
     1020        the compiler's execution of the phases. 
     1021        """ 
    10031022        .printMessages 
    10041023        _deleteIntermediateFiles 
  • cobra/trunk/Source/files-to-compile.text

    r2221 r2315  
    4747Phases/BindImplementationPhase.cobra 
    4848Phases/CountNodesPhase.cobra 
     49Phases/SuggestDefaultNumberPhase.cobra 
    4950 
    5051BackEndCommon/CurlyWriter 
  • cobra/trunk/Source/Misc.cobra

    r2006 r2315  
    1212     
    1313    var _fileName as String? 
     14    var _lineNum as int? 
    1415    var _token as IToken? 
    1516 
    1617    cue init(message as String?) 
    1718        .init(nil, nil, message) 
     19 
     20    cue init(fileName as String, lineNum as int, message as String) 
     21        base.init(message) 
     22        _fileName, _lineNum = fileName, lineNum 
    1823 
    1924    cue init(fileName as String?, token as IToken?, message as String) 
     
    3136         
    3237    get hasSourceSite as bool is override 
    33         return _token is not nil 
     38        return _token or (_fileName and _lineNum) 
    3439 
    3540    get fileName as String is override 
    36         return _token.fileName 
     41        return _fileName ? _token.fileName 
    3742         
    3843    get lineNum as int is override 
    39         return _token.lineNum 
     44        return _lineNum ? _token.lineNum 
    4045 
    4146 
  • cobra/trunk/Source/Phases/Phase.cobra

    r2188 r2315  
    1 class Phase is abstract 
     1class Phase implements IComparable<of Phase> is abstract 
    22    """ 
    33    A phase of the compiler. 
     
    2222        return .compiler.options 
    2323 
     24    get order as int 
     25        """ 
     26        Subclasses can override to change their order with respect to other phases. 
     27        Consecutive phases in the initial list of phases are kept in sequence with a "stable sort". 
     28        Default is 100. 
     29        """ 
     30        return 100 
     31 
     32    pro stableOrder from var as int 
     33        """ 
     34        Used to implement a "stable sort". 
     35        """ 
     36 
     37    get willRunWithErrors as bool 
     38        """ 
     39        Returns true if the phase will run correctly even if previously run phases produced errors. 
     40        Typically, phases will not want to run with errors because the AST nodes will in an 
     41        incomplete state that the phase cannot rely on. Hence, the default is false. 
     42        However, subclasses may override to return true if appropriate. 
     43        """ 
     44        return false 
     45 
    2446    get verbosity as int 
    2547        return .compiler.verbosity 
    2648 
     49    def compareTo(other as Phase) as int 
     50        diff = .order - other.order 
     51        if diff == 0, diff = .stableOrder - other.stableOrder 
     52        return diff 
     53         
    2754    var _didSucceed as bool 
    2855 
  • cobra/trunk/Source/TestifyRunner.cobra

    r2252 r2315  
    419419            index = firstLine.indexOf('.warning.') 
    420420            warning = firstLine.substring(index+9).trim.toLower 
    421             return _testifyHeadWarning(warning, compilerVerbosity, fileNames, options, verbose)  
     421            return _testifyHeadWarning(warning, false, compilerVerbosity, fileNames, options, verbose)  
     422 
     423        if firstLineInsensitive.startsWith('#.warning-lax.') 
     424            # deprecated: put warnings on the lines where they occur. the "hasInlineMessages" code above will detect them. 
     425            index = firstLine.indexOf('.warning-lax.') 
     426            warning = firstLine.substring(index+13).trim.toLower 
     427            return _testifyHeadWarning(warning, true, compilerVerbosity, fileNames, options, verbose)  
    422428 
    423429        return _testifyStd(compilerVerbosity, fileNames, options, verbose) 
     
    509515                return 0 
    510516                 
    511             if firstLineInsensitive.startsWith('#.error.') or firstLineInsensitive.startsWith('#.warning.') 
     517            if firstLineInsensitive.startsWith('#.error.') or firstLineInsensitive.startsWith('#.warning.') or firstLineInsensitive.startsWith('#.warning-lax.') 
    512518                # these are handled below 
    513519                break 
     
    639645        return 1 
    640646 
    641     def _testifyHeadWarning(warning as String, compilerVerbosity as int, fileNames as IList<of String>, 
     647    def _testifyHeadWarning(warning as String, lax as bool, compilerVerbosity as int, fileNames as IList<of String>, 
    642648                            options as OptionValues, verbose as bool) as int  
    643649        # TODO: the following code both checks for warnings to be thrown as well as going through a list of warnings. Seems like it should just need to do one or the other. 
     
    646652            c.testifyFilesNamed(fileNames, options, _resultsWriter to !, verbose) 
    647653        catch StopCompilation 
    648             print 'Expecting warning substring: "[warning]"' 
    649             print 'But got errors.' 
    650             .failed 
    651             return 0 
     654            if not lax 
     655                print 'Expecting warning substring: "[warning]"' 
     656                print 'But got errors.' 
     657                .failed 
     658                return 0 
    652659        catch exc as Exception 
    653660            print 'Internal exception: [exc]'