Changeset 1569

Show
Ignore:
Timestamp:
08/06/08 02:23:08 (4 months ago)
Author:
Chuck.Esterbrook
Message:

Added support for a Cobra compiler directive to specify the type for number
credit:hopscc
ticket:21

Location:
cobra/trunk
Files:
1 added
3 modified

Legend:

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

    r1566 r1569  
    11Post 0.8 
    22 
     3* Added support for a Cobra compiler directive to specify the type for `number` 
     4    type of number and integer literals same as command line -number option 
     5    %% number  'decimal' | 'float' | 'float32' | 'float64' 
     6     
    37* Added a new built-in doc tool accessible via "cobra -doc ...". The documentation is generated to local HTML files using your declarations, doc strings, contracts, etc. 
    48 
  • cobra/trunk/Source/CobraParser.cobra

    r1564 r1569  
    522522                                                isGood = false 
    523523                                if not isGood 
    524                                         sugg = Compiler.suggestionFor(tok.text) 
     524                                        sugg = if(tok.text.length, Compiler.suggestionFor(tok.text), nil) 
    525525                                        sugg = if(sugg, ' Try "[sugg]".', '') 
    526526                                        .throwError('Expecting use, assembly, namespace, class, interface or enum, but got [tok].[sugg]') 
     
    543543                                # TODO: throw AssertException(SourceSite sourceSite, object[] expressions, object thiss, object info) 
    544544                                assert false, IdentifierExpr(token, 'throw') 
     545                        on 'number' 
     546                                # number 'decimal' | 'float' | 'float32' | 'float64' 
     547                                typeName = .grab 
     548                                if typeName.text not in ['decimal', 'float', 'float32', 'float64'] 
     549                                        .throwError('Compiler directive "number": unrecognized type "[typeName.text]". Must be one of "decimal", "float", "float32" or "float64".') 
     550                                .expect('EOL') 
     551                                comp = .typeProvider to Compiler? 
     552                                if comp, comp.numberTypeName = typeName.text 
    545553                        else 
    546554                                .throwError('Unknown compiler directive.') 
  • cobra/trunk/Source/Compiler.cobra

    r1542 r1569  
    516516                                else, throw FallThroughException(.options['number']) 
    517517                return _numberType to ! 
    518                  
     518 
     519        set numberTypeName as String 
     520                """ 
     521                Set `number` type from a string/name. 
     522                """ 
     523                require value in ['decimal', 'float', 'float32', 'float64'] 
     524                branch value 
     525                        on 'decimal', _numberType = .decimalType 
     526                        on 'float',   _numberType = .floatType 
     527                        on 'float32', _numberType = .floatType(32) 
     528                        on 'float64', _numberType = .floatType(64) 
     529                        else, throw FallThroughException(value) 
     530 
    519531        get passThroughType as PassThroughType 
    520532                if _passThroughType is nil