Changeset 1759

Show
Ignore:
Timestamp:
11/12/08 02:36:16 (8 weeks ago)
Author:
Chuck.Esterbrook
Message:

More -correct-case support including generics and qualified types.
Fix problems in ticket:62

Location:
cobra/trunk
Files:
3 modified

Legend:

Unmodified
Added
Removed
  • cobra/trunk/Source/Compiler.cobra

    r1754 r1759  
    297297                .parseFilesNamed(paths) 
    298298                .bindUse 
     299                .writeSourceCodeCorrections 
    299300                .bindInh 
     301                .writeSourceCodeCorrections 
    300302                .bindInt 
     303                .writeSourceCodeCorrections 
    301304                if stopAfterBindInt, return  # in support of the -doc option 
    302305                .bindImp 
     
    11321135                # original next, but then this isn't needed right now since the only type of correction 
    11331136                # being done is case correction 
     1137                if _sourceCorrections.count == 0, return 
    11341138                v = .verbosity 
    11351139                for fileName, lineToReplacements in _sourceCorrections 
     
    11541158                        catch exc as Exception 
    11551159                                .warning(CobraWarning(fileName, nil, 'Cannot write source code corrections due to: [exc.message] ([exc.getType.name]).')) 
    1156          
     1160                _sourceCorrections.clear 
     1161 
    11571162        ## 
    11581163        ## Important system library types 
  • cobra/trunk/Source/TypeProxies.cobra

    r1746 r1759  
    368368                """ 
    369369 
    370  
    371 class WrappedTypeIdentifier 
    372         is abstract 
    373         inherits AbstractTypeIdentifier 
    374  
    375         var _typeId as AbstractTypeIdentifier 
    376  
    377         def init(token as IToken, typeId as AbstractTypeIdentifier) 
    378                 require 
    379                         token.text.length 
    380                 ensure 
    381                         .name.length 
    382                 body 
    383                         base.init(token, token.text) 
    384                         _typeId = typeId 
    385  
    386         def addMinFields 
    387                 base.addMinFields 
    388                 .addField('typeId', _typeId) 
    389  
    390         get theWrappedTypeIdentifier from _typeId 
    391  
    392         def _bindInt is override 
    393                 _typeId.bindInt 
    394                 base._bindInt 
    395  
    396         def _bindImp is override 
    397                 _typeId.bindImp 
    398                 base._bindImp 
    399  
    400  
    401 class ArrayTypeIdentifier 
    402         inherits WrappedTypeIdentifier 
    403  
    404         def init(token as IToken, typeId as AbstractTypeIdentifier) 
    405                 base.init(token, typeId) 
    406  
    407         def memberFrom(container as IContainer) as IMember? is override 
    408                 return container.memberForName(.theWrappedTypeIdentifier.name) 
    409  
    410         def _resolveType as IType is override 
    411                 return ArrayType(_typeId.realType) 
    412  
    413  
    414 class NilableTypeIdentifier 
    415         inherits WrappedTypeIdentifier 
    416  
    417         def init(token as IToken, typeId as AbstractTypeIdentifier) 
    418                 base.init(token, typeId) 
    419  
    420         def _resolveType as IType is override 
    421                 return NilableType(_typeId.realType) 
    422  
    423         get name as String is override 
    424                 return _typeId.name + '?' 
    425  
    426         def memberFrom(container as IContainer) as IMember? is override 
    427                 m = container.memberForName(.name[:-1]) 
    428                 if m inherits IType 
    429                         return NilableType(m) 
    430                 else 
    431                         return m 
    432  
    433  
    434 class VariTypeIdentifier 
    435         inherits WrappedTypeIdentifier 
    436  
    437         def init(token as IToken, typeId as AbstractTypeIdentifier) 
    438                 base.init(token, typeId) 
    439  
    440         def _resolveType as IType is override 
    441                 return VariType(_typeId.realType) 
    442  
    443  
    444 class TypeIdentifier 
    445         inherits AbstractTypeIdentifier 
    446         """ 
    447         Created by CobraParser.type for identifiers found where types are 
    448         expected. 
    449  
    450         Cobra allows forward references so even though types are expected in 
    451         places like the return type of a method, they cannot be turned into 
    452         actual types until the bindInt phase (or bindImp for expressions). 
    453         """ 
    454  
    455         def init(token as IToken) 
    456                 require 
    457                         token.which=='ID' 
    458                         token.text.length 
    459                 ensure 
    460                         .name.length 
    461                 body 
    462                         base.init(token, token.text) 
    463  
    464         def init(token as IToken, type as IType) 
    465                 require 
    466                         token.text.length 
    467                 ensure 
    468                         .name.length 
    469                 body 
    470                         base.init(token, token.text, type) 
    471  
    472         def init(token as IToken, name as String, type as IType) 
    473                 """ 
    474                 Use this to dictate a name other than what is specified by the token. 
    475                 Used for QualifiedTypes, for example, that are created from multiple tokens. 
    476                 """ 
    477                 require 
    478                         name.length 
    479                 ensure 
    480                         .name.length 
    481                 body 
    482                         base.init(token, name, type) 
    483                         assert name == token.text 
    484  
    485         def _resolveType as IType is override 
     370        def _symbolForName(name as String) as IMember 
     371                """ 
     372                Returns the symbol for this nodes name or .throwError. 
     373                Also, implements -correct-case or suggests it if it is off, but would have resolved. 
     374                """ 
    486375                # don't need to check "basic types" like int, bool, etc. here. the parser does those. 
    487                 name = .name 
    488376                if Utils.isCapped(name) 
    489377                        symbol = .compiler.symbolForName(name, true, false)  # nested enum and class types are capped and can be members of the current class 
     
    498386                                        symbol = .compiler.symbolForName(name, true, false) 
    499387                                        if symbol is not nil 
     388                                                if '<' in name  # handle generics 
     389                                                        # 'dictionary<of ' vs. 'Dictionary<of,>' 
     390                                                        name = name[:name.indexOf('<')] + .token.text[.token.text.indexOf('<'):] 
     391                                                        assert name.length == .token.text.length 
    500392                                                .compiler.correctSource(.token, name) 
    501393                        if symbol is nil 
    502394                                sugg = '' 
    503                                 if not Utils.isCapped(_name) 
     395                                if not Utils.isCapped(name) 
    504396                                        sugg = name.capped 
    505397                                        other = .compiler.symbolForName(sugg, true, false) 
    506398                                        sugg = if(other, ' Try "[sugg]". Also, consider the -correct-case option (see cobra -h for details).', '') 
    507399                                .throwError('Cannot find type for "[_name]".[sugg]') 
     400                return symbol to ! 
     401 
     402 
     403class WrappedTypeIdentifier 
     404        is abstract 
     405        inherits AbstractTypeIdentifier 
     406 
     407        var _typeId as AbstractTypeIdentifier 
     408 
     409        def init(token as IToken, typeId as AbstractTypeIdentifier) 
     410                require 
     411                        token.text.length 
     412                ensure 
     413                        .name.length 
     414                body 
     415                        base.init(token, token.text) 
     416                        _typeId = typeId 
     417 
     418        def addMinFields 
     419                base.addMinFields 
     420                .addField('typeId', _typeId) 
     421 
     422        get theWrappedTypeIdentifier from _typeId 
     423 
     424        def _bindInt is override 
     425                _typeId.bindInt 
     426                base._bindInt 
     427 
     428        def _bindImp is override 
     429                _typeId.bindImp 
     430                base._bindImp 
     431 
     432 
     433class ArrayTypeIdentifier 
     434        inherits WrappedTypeIdentifier 
     435 
     436        def init(token as IToken, typeId as AbstractTypeIdentifier) 
     437                base.init(token, typeId) 
     438 
     439        def memberFrom(container as IContainer) as IMember? is override 
     440                return container.memberForName(.theWrappedTypeIdentifier.name) 
     441 
     442        def _resolveType as IType is override 
     443                return ArrayType(_typeId.realType) 
     444 
     445 
     446class NilableTypeIdentifier 
     447        inherits WrappedTypeIdentifier 
     448 
     449        def init(token as IToken, typeId as AbstractTypeIdentifier) 
     450                base.init(token, typeId) 
     451 
     452        def _resolveType as IType is override 
     453                return NilableType(_typeId.realType) 
     454 
     455        get name as String is override 
     456                return _typeId.name + '?' 
     457 
     458        def memberFrom(container as IContainer) as IMember? is override 
     459                m = container.memberForName(.name[:-1]) 
     460                if m inherits IType 
     461                        return NilableType(m) 
     462                else 
     463                        return m 
     464 
     465 
     466class VariTypeIdentifier 
     467        inherits WrappedTypeIdentifier 
     468 
     469        def init(token as IToken, typeId as AbstractTypeIdentifier) 
     470                base.init(token, typeId) 
     471 
     472        def _resolveType as IType is override 
     473                return VariType(_typeId.realType) 
     474 
     475 
     476class TypeIdentifier 
     477        inherits AbstractTypeIdentifier 
     478        """ 
     479        Created by CobraParser.type for identifiers found where types are 
     480        expected. 
     481 
     482        Cobra allows forward references so even though types are expected in 
     483        places like the return type of a method, they cannot be turned into 
     484        actual types until the bindInt phase (or bindImp for expressions). 
     485        """ 
     486 
     487        def init(token as IToken) 
     488                require 
     489                        token.which=='ID' 
     490                        token.text.length 
     491                ensure 
     492                        .name.length 
     493                body 
     494                        base.init(token, token.text) 
     495 
     496        def init(token as IToken, type as IType) 
     497                require 
     498                        token.text.length 
     499                ensure 
     500                        .name.length 
     501                body 
     502                        base.init(token, token.text, type) 
     503 
     504        def init(token as IToken, name as String, type as IType) 
     505                """ 
     506                Use this to dictate a name other than what is specified by the token. 
     507                Used for QualifiedTypes, for example, that are created from multiple tokens. 
     508                """ 
     509                require 
     510                        name.length 
     511                ensure 
     512                        .name.length 
     513                body 
     514                        base.init(token, name, type) 
     515                        assert name == token.text 
     516 
     517        def _resolveType as IType is override 
     518                symbol = _symbolForName(.name) to dynamic 
    508519                if symbol inherits ITypeProxy 
    509520                        return symbol.realType 
     
    550561 
    551562        def _resolveType as IType is override 
    552                 genericType = .compiler.symbolForName(_typeRefName, Utils.isCapped(_name), false) 
    553                 if genericType is nil 
    554                         .throwError('Cannot find a generic type named "[_typeRefName]".') 
    555                 return _locateType(genericType to !) 
     563                symbol = _symbolForName(.name) 
     564                return _locateType(symbol) 
    556565 
    557566        def _locateType(genericType as IMember) as IType 
     
    600609 
    601610        def _resolveType as IType is override 
    602                 member = .compiler.symbolForName(_typeNodes[0].name, true, false) 
     611                member = _symbolForName(_typeNodes[0].name) to ? 
    603612                i = 1 
    604613                while i < _typeNodes.count and member <> nil 
  • cobra/trunk/Tests/700-command-line/850-correct-case.cobra

    r1746 r1759  
    1111                                print '        s = s.trim' 
    1212                                print '        print s' 
     13                                print '    def foo(d as dictionary<of String, int>)' 
     14                                print '        pass' 
     15                                print '    def bar(b as system.Object)' 
     16                                print '        pass' 
    1317                                print '    def main is shared' 
    1418                                print '        print "hello"'