Wiki

Ticket #184: access-lc-namespace.patch

File access-lc-namespace.patch, 10.2 KB (added by hopscc, 15 years ago)
  • Source/TypeProxies.cobra

     
    390390        """ 
    391391        # don't need to check "basic types" like int, bool, etc. here. the parser does those. 
    392392        if name.isCapitalized 
    393             symbol = .compiler.symbolForName(name, true, false)  # nested enum and class types are capitalized and can be members of the current class 
     393            symbol = .compiler.symbolForName(name, false)  # nested enum and class types are capitalized and can be members of the current class 
     394        else if name == name.toLower # all lowercase 
     395            symbol = .compiler.symbolForName(name, false, true) 
    394396        else 
    395397            symbol = nil 
    396398        if symbol is nil 
     
    399401                if not name.isCapitalized 
    400402                    # not very sophisticated, but catches 'string', 'object', etc. 
    401403                    name = name.capitalized 
    402                     symbol = .compiler.symbolForName(name, true, false) 
     404                    symbol = .compiler.symbolForName(name, false) 
    403405                    if symbol is not nil 
    404406                        if '<' in name  # handle generics 
    405407                            # 'dictionary<of ' vs. 'Dictionary<of,>' 
     
    409411            if symbol is nil 
    410412                sugg = Compiler.suggestionFor(name) ? '' 
    411413                if sugg == '' and not name.isCapitalized 
    412                     other = .compiler.symbolForName(name.capitalized, true, false) 
     414                    other = .compiler.symbolForName(name.capitalized, false) 
    413415                    if other, sugg = name.capitalized 
    414416                if sugg <> '', sugg = ' Try "[sugg]". Also, consider the -correct-source option (see cobra -h for details).' 
    415417                .throwError('Cannot find type for "[_name]".[sugg]') 
  • Source/Expr.cobra

     
    832832    def _bindImp 
    833833        base._bindImp 
    834834        if not _definition 
    835             possible = .compiler.symbolForName(.name, true, false) 
     835            possible = .compiler.symbolForName(.name, false) 
    836836            if not possible 
    837837                .throwError('Cannot locate enumeration type "[.name]".') 
    838838            else if possible inherits EnumDecl 
     
    10021002            canBeUndottedMember = _name.canBeUndottedMemberName 
    10031003            if canBeUndottedMember 
    10041004                # assert .compiler.boxStack.count TODO: identifier expr is being used by PostCallExpr which is used for attribute calls 
    1005                 _definition = .compiler.symbolForName(_name, canBeUndottedMember, false) 
     1005                _definition = .compiler.symbolForName(_name, false) 
    10061006            else 
    10071007                # local var ref: foo 
    10081008                if .compiler.codeMemberStack.count  # could be: var _x = y   or: has foo 
    10091009                    _definition = .compiler.findLocal(_name) 
    10101010                if _definition is nil 
    1011                     _definition  = .compiler.symbolForName(_name, false, false, true)  # 3rd party DLLs have lowercase class names like iConnection 
     1011                    _definition  = .compiler.symbolForName(_name, false, true)  # 3rd party DLLs have lowercase class names like iConnection 
    10121012            if _definition is nil and not canBeUndottedMember 
    10131013                if _superNode inherits BinaryOpExpr 
    10141014                    if _superNode.right is this 
     
    16151615        expr = .expr 
    16161616 
    16171617        if expr inherits IdentifierExpr 
    1618             if expr.name.startsWith('_') and not .compiler.symbolForName(expr.name, true, false) inherits BoxVar 
     1618            if expr.name.startsWith('_') and not .compiler.symbolForName(expr.name, false) inherits BoxVar 
    16191619                # method invocation 
    16201620                # _foo(x) --> ._foo(x) 
    16211621                newCall = CallExpr(.token, .name, .args, true) 
     
    17771777    def _handleClassInitializer 
    17781778        initCall as Initializer? 
    17791779        if .args.count > 0 
    1780             theClass = .compiler.symbolForName(.name, true, false, true) to ClassOrStruct? 
     1780            theClass = .compiler.symbolForName(.name, false, true) to ClassOrStruct? 
    17811781            if theClass is not nil 
    17821782                possibleCalls = theClass.memberForName("cue.init") 
    17831783                if possibleCalls is nil 
  • Source/Statements.cobra

     
    6060            usingExistingLocal = false 
    6161            if canBeUndottedMember 
    6262                assert .compiler.boxStack.count 
    63                 definition = .compiler.symbolForName(ve.name, canBeUndottedMember, false) to passthrough 
     63                definition = .compiler.symbolForName(ve.name, false) to passthrough 
    6464                if definition is nil 
    6565                    ve.throwUnknownIdError 
    6666            else 
  • Source/Compiler.cobra

     
    832832                    _basicTypes.add(.intType(signed, size)) 
    833833        return _basicTypes to ! 
    834834 
    835     def symbolForName(name as String, canBeMember as bool, haveThis as bool) as IMember? 
    836         return .symbolForName(name, canBeMember, haveThis, false) 
     835    def symbolForName(name as String, haveThis as bool) as IMember? 
     836        return .symbolForName(name, haveThis, false) 
    837837 
    838     def symbolForName(name as String, canBeMember as bool, haveThis as bool, isLowerOkay as bool) as IMember? 
     838    def symbolForName(name as String, haveThis as bool, isLowerOkay as bool) as IMember? 
    839839        """ 
    840840        name - obvious. 
    841         canBeMember - the symbol can be a member of the current box 
    842             TODO: can this be retired now that there is findLocal? 
    843841        haveThis - if false, symbols like methods, properties, etc. will not be returned while enums, nested classes, etc. could be. 
     842        isLowerOkay - true if a lowercase name (non capCased) is allowed.    
    844843        """ 
    845844        require 
    846845            name.length 
     
    856855 
    857856            # check the current box which will ask its namespace which will ask its `use` directives 
    858857            if _boxStack.count 
    859                 #print '>> .compiler.symbolForName([name], [canBeMember], [haveThis])' 
     858                #print '>> .compiler.symbolForName([name], [haveThis])' 
    860859                if not isLowerOkay and name[0].isLower 
    861860                    assert false, 'use findLocal instead. [name]' 
    862861                    return nil 
  • Source/Node.cobra

     
    11461146     
    11471147    def findLocal(name as String) as AbstractLocalVar? 
    11481148    def suggestionForUnknown(word as String) as String? 
    1149     def symbolForName(name as String, canBeMember as bool, haveThis as bool) as IMember? 
    1150     def symbolForName(name as String, canBeMember as bool, haveThis as bool, isLowerOkay as bool) as IMember? 
     1149    def symbolForName(name as String, haveThis as bool) as IMember? 
     1150    def symbolForName(name as String, haveThis as bool, isLowerOkay as bool) as IMember? 
    11511151 
    11521152 
    11531153    ## Current objects 
  • Source/Attributes.cobra

     
    5656                .throwError('Expecting an attribute class instead of a [defi.englishName].') 
    5757        else if _expr inherits PostCallExpr 
    5858            name = _expr.name 
    59             if not name.endsWith('Attribute') and name.canBeUndottedMemberName and not .compiler.symbolForName(name, true, false) 
    60                 if .compiler.symbolForName(name+'Attribute', true, false) 
     59            if not name.endsWith('Attribute') and name.canBeUndottedMemberName and not .compiler.symbolForName(name, false) 
     60                if .compiler.symbolForName(name+'Attribute', false) 
    6161                    _expr = PostCallExpr(_expr.token, IdentifierExpr(_expr.token, name+'Attribute'), _expr.args, isForAttribute=true) 
    6262            else 
    6363                _expr.isForAttribute = true 
  • Tests/720-libraries/400-other/lcase.cs

     
     1/* 
     2lcase namespace in  lib test - Library 
     3cobra -t:lib lcase.cs 
     4gmcs -t:library -out:lcase.dll lcase.cs 
     5csc /t:library /out:lcase.dll lcase.cs 
     6*/ 
     7namespace lcase { 
     8   public class A { 
     9      string _what = "class A"; 
     10       
     11      public int One = 1; 
     12 
     13      public string what { 
     14        get { return _what; } 
     15        set { _what = value;} 
     16      } 
     17      public string getWho() { 
     18        return "lc"; 
     19      } 
     20   } 
     21} 
  • Tests/720-libraries/400-other/109-compile-lcase.cobra

     
     1# compile lowercase lib lcase.cs 
     2class CobC 
     3    def main is shared 
     4     
     5        output = .runCobraExe('-t:lib lcase.cs') 
     6        try 
     7            assert 'Compilation succeeded' in output 
     8            assert File.exists('lcase.dll')  
     9        success 
     10            print 'lcase.cs compile' 
     11         
     12    def runCobraExe(args as String) as String is shared 
     13        p as System.Diagnostics.Process? 
     14        return CobraCore.runCobraExe(args, out p) 
     15         
  • Tests/720-libraries/400-other/110-access-lc-namespace.cobra

     
     1# .args. -reference:./lcase 
     2# Test access to classes/Types in a lowercase named namespace 
     3# numbered lines were errors pre ticket:184 fix 
     4use lcase  
     5 
     6class Asub inherits lcase.A    # /1 cannot find type for lcase.A 
     7 
     8    def main 
     9        a = lcase.A() 
     10        assert a.one == 1 
     11        a = A() 
     12        assert a.one == 1 
     13     
     14        aa as lcase.A = lcase.A()  # /3 cannot find type for lcase.A 
     15        assert aa.one == 1 
     16        .x(aa) 
     17     
     18        assert aa.getWho == 'lc' 
     19        assert aa.what == 'class A' 
     20        aa.what = 'Ksrsly' 
     21        assert a.what == 'class A' 
     22        assert aa.what == 'Ksrsly' 
     23         
     24    def x(a as lcase.A)     # /2 cannot find type for lcase.A 
     25        assert a.one == 1 
     26     
  • Developer/IntermediateReleaseNotes.text

     
    404404* Fixed: Numeric for expression broken for `get` expressions with types other than `int`  ticket:158 
    405405 
    406406* Fixed: Operators `?` and `?=` give error if left hand expression is not nilable.  ticket:117 
     407 
     408* Fixed: Better handling of access to items in lowercased namespaces (libs) : ticket:184 
     409