Show
Ignore:
Timestamp:
08/28/08 07:55:03 (4 months ago)
Author:
Chuck.Esterbrook
Message:

Code cleanup.
Retire BoxMember?.box in favor of the more explicitly named .parentBox

Files:
1 modified

Legend:

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

    r1599 r1606  
    2929                        """ 
    3030 
    31         var _box as Box 
     31        var _parentBox as Box 
    3232        var _docString as String? 
    3333        var _isNames as List<of String>? 
     
    4040        var _binaryName as String? 
    4141 
    42         def init(token as IToken, box as Box, name as String, isNames as List<of String>, attribs as AttributeList) 
    43                 .init(token, box, name, isNames, attribs, nil) 
    44  
    45         def init(token as IToken, box as Box, name as String, isNames as List<of String>, attribs as AttributeList, docString as String?) 
     42        def init(token as IToken, parentBox as Box, name as String, isNames as List<of String>, attribs as AttributeList) 
     43                .init(token, parentBox, name, isNames, attribs, nil) 
     44 
     45        def init(token as IToken, parentBox as Box, name as String, isNames as List<of String>, attribs as AttributeList, docString as String?) 
    4646                base.init(token, name) 
    4747                _isNames = isNames 
    4848                _attribs = attribs 
    49                 _box = box 
     49                _parentBox = parentBox 
    5050                _docString = docString 
    5151 
     
    5454        get attributes from _attribs 
    5555 
    56         get box from var  # CC: axe in favor of using .parentBox 
    57  
    58         get parentBox from _box 
     56        get parentBox from var 
    5957 
    6058        get canHaveMatchingBaseMember as bool 
     
    136134 
    137135        get isClassMember as bool 
    138                 return _box inherits Class or (_box inherits Extension and (_box to Extension).extendedBox inherits Class) 
     136                return _parentBox inherits Class or (_parentBox inherits Extension and (_parentBox to Extension).extendedBox inherits Class) 
    139137 
    140138        get isInterfaceMember as bool 
    141                 return _box inherits Interface or (_box inherits Extension and (_box to Extension).extendedBox inherits Interface) 
     139                return _parentBox inherits Interface or (_parentBox inherits Extension and (_parentBox to Extension).extendedBox inherits Interface) 
    142140 
    143141        get isStructMember as bool 
    144                 return _box inherits Struct or (_box inherits Extension and (_box to Extension).extendedBox inherits Struct) 
     142                return _parentBox inherits Struct or (_parentBox inherits Extension and (_parentBox to Extension).extendedBox inherits Struct) 
    145143 
    146144        get isExtensionMember as bool 
    147                 return _box inherits Extension 
     145                return _parentBox inherits Extension 
    148146 
    149147        pro matchingBaseMember as BoxMember? 
     
    184182        def mergedIntoPartialBox(newBox as Box) 
    185183                require 
    186                         newBox is not .box 
    187                         newBox.name == .box.name 
     184                        newBox is not .parentBox 
     185                        newBox.name == .parentBox.name 
    188186                body 
    189                         _box = newBox 
     187                        _parentBox = newBox 
    190188 
    191189 
     
    231229 
    232230        def bindImp as dynamic 
    233                 if not _box.isConstructed 
     231                if not .parentBox.isConstructed 
    234232                        return base.bindImp 
    235233                else 
     
    240238                base._bindImp 
    241239                assert .didBindInt  # class members should have always received a bindInt first 
    242 # TODO:         assert not _box.isConstructed  # not expecting to bindImp on a constructed type 
     240# TODO:         assert not .parentBox.isConstructed  # not expecting to bindImp on a constructed type 
    243241                for attrib in _attribs 
    244242                        attrib.bindImp 
     
    252250                # using base implies override, but only if the method sig in the base class is the same 
    253251                # (otherwise it's just an overload) 
    254                 if _box inherits Class 
    255                         assert _box.baseClass 
     252                parentBox = _parentBox 
     253                if parentBox inherits Class 
     254                        assert parentBox.baseClass 
    256255                        # Why not use .matchingBaseMember? Because currently that's only method-to-method. Does not work for properties. 
    257                         baseMember = _box.baseClass.memberForName(_name) 
     256                        baseMember = parentBox.baseClass.memberForName(_name) 
    258257                        if baseMember inherits BoxMember 
    259258                                if baseMember inherits MemberOverload 
     
    291290        def addRefFields is override 
    292291                base.addRefFields 
    293                 .addField('box', _box) 
     292                .addField('parentBox', .parentBox) 
    294293 
    295294        def addSubFields is override 
     
    305304                require .didBindInt 
    306305                newMember = .memberwiseClone to BoxMember 
    307                 newMember._box = box 
     306                newMember._parentBox = box 
    308307                newMember._overloadGroup = nil 
    309308                return newMember 
     
    316315        get sharpThis as String 
    317316                # sigh. I wish .NET had metaclasses instead of this instance vs. static crap 
    318                 return if(.isShared, 'typeof([.box.sharpName])', .box.sharpThis) 
     317                return if(.isShared, 'typeof([.parentBox.sharpName])', .parentBox.sharpThis) 
    319318 
    320319        def writeSharpNotNull(sw as SharpWriter) 
     
    765764 
    766765        get canHaveDetailedStackTrace as bool 
    767                 return .box.canHaveDetailedStackTrace and not .hasYieldStmt 
     766                return .parentBox.canHaveDetailedStackTrace and not .hasYieldStmt 
    768767 
    769768        get willRequire as bool 
     
    787786                .compiler.codeMemberStack.push(this) 
    788787                try 
    789                         assert .box.didUnNilReturnTypes 
     788                        assert .parentBox.didUnNilReturnTypes 
    790789                        for param in _params 
    791790                                param.bindInt 
     
    852851                if _matchingBaseMember, return 
    853852                if not .canHaveMatchingBaseMember, return 
    854                 if _box inherits Class 
    855                         if _box.baseClass 
    856                                 baseMember = _box.baseClass.memberForName(_name) 
     853                parentBox = .parentBox 
     854                if parentBox inherits Class 
     855                        if parentBox.baseClass 
     856                                baseMember = parentBox.baseClass.memberForName(_name) 
    857857                                if baseMember is nil 
    858858                                        pass 
     
    872872                                        # TODO: FIXME: the message uses .englishName twice. one of them needs to change 
    873873                                        .recordError('Cannot declare a [.englishName] named "[.name]" because the base member "[.name]" is a [.englishName]. this=[.getType.name], baseMember=[baseMember.getType.name]') 
    874                                 if _matchingBaseMember and _matchingBaseMember.box inherits Interface 
     874                                if _matchingBaseMember and _matchingBaseMember.parentBox inherits Interface 
    875875                                        # not really a base member in the "base class" sense of the word. 
    876876                                        # would not require marking as "is override" for example 
     
    10821082                        return 
    10831083                # could be a neat option, -trace-methods, but maybe done with events: 
    1084                 # sw.writeLine('Console.WriteLine(">> [.box.name].[.name]");') 
    1085                 sw.write('CobraImp.PushFrame("[.box.name]", "[.name]", [Utils.sharpStringLiteralFor(.token.fullPathName)], [.token.lineNum]') 
     1084                # sw.writeLine('Console.WriteLine(">> [.parentBox.name].[.name]");') 
     1085                sw.write('CobraImp.PushFrame("[.parentBox.name]", "[.name]", [Utils.sharpStringLiteralFor(.token.fullPathName)], [.token.lineNum]') 
    10861086                if not .isShared 
    10871087                        sw.write(', "this", [.compiler.curBox.sharpThis]') 
     
    10951095                if not .canHaveDetailedStackTrace 
    10961096                        return 
    1097                 # sw.writeLine('Console.WriteLine("<< [.box.name].[.name]");') 
     1097                # sw.writeLine('Console.WriteLine("<< [.parentBox.name].[.name]");') 
    10981098                # this catch all clashes with yield statements. which is why .canHaveDetailedStackTrace returns false if a method has a yield statement. 
    10991099                sw.dedentAndWrite('} catch {\n') 
     
    11491149                                token.incLineNum 
    11501150                                stmts = List<of Stmt>() 
    1151                                 for decl in _box.declsInOrder 
     1151                                for decl in .parentBox.declsInOrder 
    11521152                                        if decl inherits BoxVar 
    11531153                                                assert decl.type 
     
    12001200                                                didSetInInitCall = true 
    12011201                .writeSharpIsNames(sw) 
    1202                 sw.write(' [.box.rootName]') 
     1202                sw.write(' [.parentBox.rootName]') 
    12031203                .writeSharpParams(sw) 
    12041204                if callInitializer 
     
    13701370                        typeForParam = TypeUtil.dictionaryOf(.genericParams, typeArgs) 
    13711371                        for param in .params 
    1372                                 c._params.add(param.constructedFor(.box, typeForParam)) 
    1373                         c._returnType = c._returnType.secondaryConstructedTypeFor(.box, typeForParam) 
     1372                                c._params.add(param.constructedFor(.parentBox, typeForParam)) 
     1373                        c._returnType = c._returnType.secondaryConstructedTypeFor(.parentBox, typeForParam) 
    13741374                        c.bindInt 
    13751375                        return c 
     
    13981398                        _implementsType = _implementsTypeNode.realType 
    13991399                        # TODO: make sure the type is among the interfaces of the box 
    1400                 if .compiler.errors.count==numErrors and _returnType is not .compiler.voidType and not .hasReturnStmt and not .hasYieldStmt and not .hasThrowStmt and not .isAbstract and not .box.isFake and not .box inherits Interface 
     1400                if .compiler.errors.count==numErrors and _returnType is not .compiler.voidType and not .hasReturnStmt and not .hasYieldStmt and not .hasThrowStmt and not .isAbstract and not .parentBox.isFake and not .parentBox inherits Interface 
    14011401                        .throwError('Missing return statement for method "[_name]" which returns [_returnType.name].') 
    14021402                # check for `return` and `yield` in the same method 
     
    16411641 
    16421642        def init(token as IToken, parent as ProperDexer, isNames as List<of String>) 
    1643                 base.init(token, parent.box, parent.name, List<of Param>(), isNames, AttributeList(), '')  # TODO: should be docString, right? 
     1643                base.init(token, parent.parentBox, parent.name, List<of Param>(), isNames, AttributeList(), '')  # TODO: should be docString, right? 
    16441644                _name = parent.name + '.' + .xetPartName  # CC: somewhat awkward. belongs in the base.init() call 
    16451645                _parent = parent 
     
    16891689                        .members[0] == member 
    16901690                body 
    1691                         base.init(member.token, member.box, member.name, member.isNames, AttributeList()) 
     1691                        base.init(member.token, member.parentBox, member.name, member.isNames, AttributeList()) 
    16921692                        member.overloadGroup = this 
    16931693                        _members = [member] 
     
    17291729                        member.overloadGroup = this 
    17301730                        _members.add(member) 
    1731                         .box.addDeclFromOverload(member, this) 
     1731                        .parentBox.addDeclFromOverload(member, this) 
    17321732 
    17331733        def addInheritedMember(member as BoxMember) 
     
    17361736                        not member inherits MemberOverload 
    17371737                        member.name==.name 
    1738                         member.box is not .box 
     1738                        member.parentBox is not .parentBox 
    17391739                        member not in .members 
    17401740                        member.getType is .members[0].getType 
     
    18001800                        member.name.length 
    18011801                body 
    1802                         base.init(token, member.box, 'test_'+member.name.capped, List<of Param>(), .getCompiler.voidType, nil, ['shared'], AttributeList(), '') 
     1802                        base.init(token, member.parentBox, 'test_'+member.name.capped, List<of Param>(), .getCompiler.voidType, nil, ['shared'], AttributeList(), '') 
    18031803                        _forMember = member 
    18041804 
     
    19241924                        # TODO: having the serial number in the name avoids problem with overloads, but it's ugly and it can change from run-to-run. 
    19251925                        #               would be nice if each member of an overload had an overload number. 
    1926                         name = '[prefix]_[_codeMember.sharpName][_codeMember.sharpGenericParams]_[_codeMember.serialNum]_[_codeMember.box.name]' 
     1926                        name = '[prefix]_[_codeMember.sharpName][_codeMember.sharpGenericParams]_[_codeMember.serialNum]_[_codeMember.parentBox.name]' 
    19271927                        name = name.replace(r'[]', 'Item') # indexer # TODO: maybe Indexer should return 'Item' in the first place 
    19281928                        # properindexers like "name.get" have a '.' 
     
    19841984                        n = 1 
    19851985                        post while curCodeMember 
    1986                                 if not curCodeMember.box.isFake and curCodeMember.requirePart and (not curCodeMember.requirePart.isImplicit or curCodeMember.matchingBaseMember is nil) 
     1986                                if not curCodeMember.parentBox.isFake and curCodeMember.requirePart and (not curCodeMember.requirePart.isImplicit or curCodeMember.matchingBaseMember is nil) 
    19871987                                        count += 1 
    19881988                                        sw.write('try {\n') 
     
    20422042                        return 
    20432043                static = if(_codeMember.isShared, 'static ', '') 
    2044                 access = if(_codeMember.box inherits Struct, 'private', 'protected') 
     2044                access = if(_codeMember.parentBox inherits Struct, 'private', 'protected') 
    20452045                sw.write('[static][access] void [.sharpMethodName][_codeMember.sharpGenericParams](') 
    20462046                _codeMember.writeSharpRequireParamDecls(sw) 
     
    20772077 
    20782078        get haveConditions as bool is override 
    2079                 if _codeMember.box.hasInvariants 
     2079                if _codeMember.parentBox.hasInvariants 
    20802080                        return true 
    20812081                have = false 
     
    21172117                        curCodeMember = _codeMember to ? 
    21182118                        post while curCodeMember 
    2119                                 if not curCodeMember.box.isFake and curCodeMember.ensurePart # TODO: axe: and (not codeMember.ensurePart.isImplicit or codeMember.matchingBaseMember is nil) 
     2119                                if not curCodeMember.parentBox.isFake and curCodeMember.ensurePart 
    21202120                                        if willInline 
    21212121                                                curCodeMember.ensurePart.writeSharpChecks(sw) 
     
    21462146                        return 
    21472147                static = if(_codeMember.isShared, 'static ', '') 
    2148                 access = if(_codeMember.box inherits Struct, 'private', 'protected') 
     2148                access = if(_codeMember.parentBox inherits Struct, 'private', 'protected') 
    21492149                sw.write('[static][access] void [.sharpMethodName][_codeMember.sharpGenericParams](') 
    21502150                _codeMember.writeSharpEnsureParamDecls(sw) 
     
    21722172                        sw.indent 
    21732173                        if .willInlineSharp 
    2174                                 .codeMember.box.writeAllSharpInvariantChecks(sw) 
     2174                                .codeMember.parentBox.writeAllSharpInvariantChecks(sw) 
    21752175                        else 
    2176                                 sw.write('invariant_[_codeMember.box.rootName]();') 
     2176                                sw.write('invariant_[_codeMember.parentBox.rootName]();') 
    21772177                        sw.dedent 
    21782178                        sw.write('} finally { _ih_invariantGuard -= 1; }\n')