Wiki

root/cobra/trunk/Source/Attributes.cobra

Revision 2486, 3.9 KB (checked in by Charles.Esterbrook, 15 months ago)

Fixed: Cobra binds XmlAttribute to the wrong class.
reported-by:terenced

  • Property svn:eol-style set to native
Line 
1class AttributeList inherits List<of AttributeDecl>
2   
3    pass
4
5
6class AttributeDecl inherits NamedNode is partial
7
8    var _expr as Expr
9
10    cue init(expr as Expr)
11        require expr inherits IdentifierExpr or expr inherits PostCallExpr or expr inherits DotExpr
12        .init(expr, false)
13       
14    cue init(expr as Expr, isReturnTarget as bool)
15        require expr inherits IdentifierExpr or expr inherits PostCallExpr or expr inherits DotExpr
16        base.init(expr.token)
17        if expr inherits IdentifierExpr
18            # making a PostCallExpr is one less class to worry about later
19            expr = PostCallExpr(expr.token, IdentifierExpr(expr.token, expr.name), List<of Expr>())
20        _expr = expr
21        _isReturnTarget = isReturnTarget
22
23    get expr from var
24
25    get isReturnTarget from var as bool
26        # TODO: may need to generalize this in the future to various targets
27
28    get name as String is override
29        if _expr inherits PostCallExpr
30            return _expr.name
31        else if _expr inherits DotExpr
32            return _expr.dotRight.name
33        else
34            return '(noname)'
35
36    def _bindInt
37        base._bindInt
38        _expr.bindInt
39
40    def _bindImp
41        base._bindImp
42
43        # support using 'Foo' when the real attribute class name is 'FooAttribute'
44
45        if _expr inherits DotExpr
46            _expr.left.bindImp  # Could cause a transformation. Handled in .replaceChild
47            name = _expr.dotRight.name
48            defi = _expr.left.definition.memberForName(name+'Attribute')
49            if defi is nil
50                defi = _expr.left.definition.memberForName(name)
51            if defi is nil
52                _expr.throwCannotFindMemberError(_expr.left, '[name]Attribute or [name]')
53            if defi inherits IType
54                _expr = PostCallExpr(_expr.right.token, TypeExpr(_expr.right.token, defi), _expr.dotRight.args)
55            else
56                .throwError('Expecting an attribute class instead of a [defi.englishName].')
57        else if _expr inherits PostCallExpr
58            name = _expr.name
59            if name.canBeUndottedMemberName
60                if .compiler.symbolForName(name+'Attribute', false)
61                    _expr = PostCallExpr(_expr.token, IdentifierExpr(_expr.token, name+'Attribute'), _expr.args)
62        assert _expr inherits PostCallExpr
63        (_expr to PostCallExpr).isForAttribute = true
64        _expr.bindImp
65
66    get typeForIdentifier as IType is override
67        throw ShouldNotCallException(.getType)
68
69    get typeForReceiver as IType is override
70        throw ShouldNotCallException(.getType)
71
72    def replaceChild(find as INode, replace as INode) as bool is override
73        if _expr is find
74            _expr = replace to PostCallExpr
75            return true
76        else if _expr inherits DotExpr
77            # handle transformation from _expr.left.bindImp in _bindImp
78            if find is _expr.left
79                e = _expr
80                _expr = DotExpr(e.token, e.op, replace to Expr, e.dotRight to Expr)
81                return true
82        return false
83
84
85class AssemblyDecl
86    is partial
87    inherits NamedNode
88    implements INameSpaceMember
89    """
90    The only purpose of an assembly declaration is to hold assembly level attributes.
91    """
92   
93    var _parentNameSpace as NameSpace?
94    var _attribs as AttributeList
95
96    cue init(token as IToken, attribs as AttributeList)
97        base.init(token)
98        _attribs = attribs
99
100    get attributes from _attribs
101
102    get englishName as String
103        return 'assembly'
104
105    get isFromBinaryLibrary as bool
106        return true
107   
108    get isNames as String*
109        return List<of String>()
110
111    get typeForIdentifier as IType? is override
112        assert false
113        return nil
114   
115    get typeForReceiver as IType? is override
116        assert false
117        return nil
118
119    pro parentNameSpace from var
120   
121    def extensionMemberFor(box as Box, name as String) as IMember?
122        return nil
123
124    def _bindInt
125        base._bindInt
126        for attrib in _attribs
127            try
128                attrib.bindInt
129            catch ne as NodeException
130                .compiler.recordError(ne)
131
132    def _bindImp
133        base._bindImp
134        for attrib in _attribs
135            try
136                attrib.bindImp
137            catch ne as NodeException
138                .compiler.recordError(ne)
139   
140    # TODO: shouldn't need these, but INameSpaceMember forces it on us (mostly/entirely through inheriting IMember)
141   
142    def unNilReturnType
143        pass
144   
145    get isCallable as bool
146        return false
147   
148    get isShared as bool
149        return false
150
151    get requiresThis as bool
152        return false
153       
154    get resultType as IType?
155        return nil
Note: See TracBrowser for help on using the browser.