Changeset 1741

Show
Ignore:
Timestamp:
11/07/08 19:55:56 (2 months ago)
Author:
Chuck.Esterbrook
Message:

Fix bug from previous checkin.
Code cleanup.

Files:
1 modified

Legend:

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

    r1740 r1741  
    199199                        sugg = '' 
    200200                return sugg 
     201 
     202        def whoseTypeIsMessage as String 
     203                """ 
     204                Returns a suffix for member-not-found error messages. 
     205                Returns ' whose type is "[.receiverType.name]"' 
     206                Overridden by IdentifierExpr to return '' when accessing types. 
     207                """ 
     208                return ' whose type is "[.receiverType.name]"' 
     209         
     210        def throwCannotFindMemberError(receiverExpr as Expr, memberName as String) 
     211                __throwOrRecordCannotFindMemberError(receiverExpr, memberName, 1) 
     212 
     213        def recordCannotFindMemberError(receiverExpr as Expr, memberName as String) 
     214                __throwOrRecordCannotFindMemberError(receiverExpr, memberName, 2) 
     215 
     216        def __throwOrRecordCannotFindMemberError(receiverExpr as Expr, memberName as String, throwOrRecord as int) is nonvirtual 
     217                require throwOrRecord in [1, 2] 
     218                suggs = _suggestionsMessage(receiverExpr.suggestionsForBadMemberName(memberName)) 
     219                errorMsg = 'Cannot find a definition for "[memberName]" in "[receiverExpr.toCobraSource]"[receiverExpr.whoseTypeIsMessage].[suggs]' 
     220                branch throwOrRecord 
     221                        on 1, .throwError(errorMsg) 
     222                        on 2, .recordError(errorMsg) 
     223                        else, throw FallThroughException(throwOrRecord) 
    201224 
    202225 
     
    506529                                        type = .compiler.passThroughType 
    507530                        else 
    508                                 left = dotNode.left 
    509                                 suggs = left.suggestionsForBadMemberName(_name) 
    510                                 isBoxAccess = left inherits IdentifierExpr and (left to IdentifierExpr).definition inherits Box  # like "Console.writeLine" where the receiver is a literal class or struct reference 
    511                                 whoseTypeIs = if(isBoxAccess, '', ' whose type is "[left.receiverType.name]"') 
    512                                 .throwError('Cannot find a definition for "[_name]" in "[left.toCobraSource]"[whoseTypeIs].[_suggestionsMessage(suggs)]') 
     531                                .throwCannotFindMemberError(dotNode.left, _name) 
    513532                else 
    514533                        if not possibleDefinition.isCallable 
     
    956975        def toCobraSource as String is override 
    957976                return _name 
     977 
     978        def whoseTypeIsMessage as String 
     979                """ 
     980                Customized to return '' for boxes. 
     981                """ 
     982                # TODO: should cover other types like `int`. maybe that's a TypeExpr? 
     983                return if(.definition inherits Box, '', base.whoseTypeIsMessage) 
    958984 
    959985 
     
    12821308                                        _type = .compiler.nilableDynamicType 
    12831309                                        return 
    1284                                 suggs = .binarySuperNode.left.suggestionsForBadMemberName(_name) 
    1285                                 isBoxAccess = left inherits IdentifierExpr and (left to IdentifierExpr).definition inherits Box  # like "Console.writeLine" where the receiver is a literal class or struct reference 
    1286                                 whoseTypeIs = if(isBoxAccess, '', ' whose type is "[left.receiverType.name]"') 
    1287                                 .throwError('Cannot find a definition for "[_name]" in "[left.toCobraSource]"[whoseTypeIs].[_suggestionsMessage(suggs)]') 
     1310                                .throwCannotFindMemberError(left, _name) 
    12881311                        assert _definition 
    12891312                        if _definition inherits IType 
     
    13111334                         
    13121335                        if _definition inherits BoxMember 
    1313                                 _bindImpBoxMember(_definition, isBoxAccess, left)                       # resolve overloads 
     1336                                _bindImpBoxMember(_definition, left)  # resolve overloads 
    13141337                        else 
    13151338                                # TODO: type access like enum, class, delegate 
     
    13171340                assert _type 
    13181341 
    1319         def _bindImpBoxMember(defn as BoxMember, isBoxAccess as bool, left as Expr) 
     1342        def _bindImpBoxMember(defn as BoxMember, left as Expr) 
    13201343                # resolve overloads 
    13211344                if defn inherits MemberOverload 
     
    13401363                else if defn.isProtected 
    13411364                        if not .compiler.curBox.isDescendantOf(defn.parentBox) 
    1342                                 whoseTypeIs = if(isBoxAccess, '', ' whose type is "[left.receiverType.name]"') 
    1343                                 .throwError('Cannot access protected "[_name]" in "[left.toCobraSource]"[whoseTypeIs].') 
     1365                                .throwError('Cannot access protected "[_name]" in "[left.toCobraSource]"[left.whoseTypeIsMessage].') 
    13441366                else if defn.isPrivate 
    13451367                        if not .compiler.curBox is defn.parentBox 
    1346                                 whoseTypeIs = if(isBoxAccess, '', ' whose type is "[left.receiverType.name]"') 
    1347                                 .throwError('Cannot access private "[_name]" in "[left.toCobraSource]"[whoseTypeIs].') 
     1368                                .throwError('Cannot access private "[_name]" in "[left.toCobraSource]"[left.whoseTypeIsMessage].') 
    13481369                else if defn.isInternal 
    13491370                        # TODO 
     
    15091530                                        if not arg.left inherits IdentifierExpr 
    15101531                                                .recordError('General purpose assignments are not allowed as arguments. Assignment syntax can only be used for keyword arguments.') 
    1511                                         if not expr.receiverType.isDynamicOrPassThrough 
     1532                                        else if not expr.receiverType.isDynamicOrPassThrough 
    15121533                                                propertyName = (arg.left to IdentifierExpr).name 
    15131534                                                if expr.memberForName(propertyName) is nil 
    1514                                                         suggs = .expr.suggestionsForBadMemberName(propertyName) 
    1515                                                         isBoxAccess = expr inherits IdentifierExpr and (expr to IdentifierExpr).definition inherits Box  # like "Console.writeLine" where the receiver is a literal class or struct reference 
    1516                                                         whoseTypeIs = if(isBoxAccess, '', ' whose type is "[expr.receiverType.name]"') 
    1517                                                         .recordError('Cannot find a definition for "[propertyName]" in "[expr.toCobraSource]"[whoseTypeIs].[_suggestionsMessage(suggs)]') 
     1535                                                        .recordCannotFindMemberError(expr, propertyName) 
    15181536                                        arg.right.bindImp  # 'x=y' has special treatment in arguments 
    15191537                                else