Wiki

root/cobra/trunk/Source/Indexer.cobra

Revision 2631, 3.5 KB (checked in by Charles.Esterbrook, 5 months ago)

JVM back-end progress.
credit:hopscc

  • Property svn:eol-style set to native
Line 
1class Indexer inherits ProperDexer is partial
2    implements IOverloadable
3
4    var _params as List<of Param>
5
6    # TODO: add implements support. initializer param will be:
7    # implementsList as List<of INode>,
8
9    cue init(token as IToken, idToken as IToken, box as Box, name as String, paramsList as List<of Param>, isNames as List<of String>, attribs as AttributeList, coverVar as BoxVar, coverAccess as String, docString as String)
10        base.init(token, idToken, box, name, isNames, attribs, docString)
11        _params = paramsList
12        _coverVar = coverVar
13        _coverAccess = coverAccess
14        _isNames = isNames
15
16    cue init(token as IToken, idToken as IToken, box as Box, name as String, paramsList as List<of Param>, returnTypeOrNode as INode, isNames as List<of String>, attribs as AttributeList, docString as String)
17        base.init(token, idToken, box, name, returnTypeOrNode, isNames, attribs, docString)
18        _params = paramsList
19       
20    get params as IList<of Param> is override
21        return _params
22
23    get isCallable as bool is override
24        return false
25
26    get englishName as String is override
27        return 'indexer'
28
29    def _bindInt
30        base._bindInt
31        for param in .params, param.bindInt
32       
33    def makeGetPart(token as IToken) as AbstractMethod is override
34        _getPart = IndexerGetter(token, this)
35        return _getPart to !
36
37    def makeSetPart(token as IToken) as AbstractMethod is override
38        _setPart = IndexerSetter(token, this)
39        return _setPart to !
40
41    def constructedFor(box as Box, gpToType as Dictionary<of GenericParam, IType>) as BoxMember  # CC: as same
42        newMember = base.constructedFor(box, gpToType) to Indexer  # CC: this = base. ...
43        newMember._params = for p in _params get p.constructedFor(box, gpToType)
44        return newMember
45
46    def cobraSourceSignature as String is override
47        return .cobraSourceSignature(true)
48
49    def cobraSourceSignature(includeShared as bool) as String
50        keyword = if(.getPart and .setPart, 'pro', if(.getPart, 'get', 'set'))
51        sb = StringBuilder('[keyword] \[')
52        if .params.count > 0
53            sep = ''
54            for param in .params
55                sb.append('[sep][param.name] as ')
56                branch param.direction
57                    on Direction.In, pass
58                    on Direction.InOut, sb.append('inout ')
59                    on Direction.Out, sb.append('out ')
60                sb.append('[param.type.name]')
61                sep = ', '
62        sb.append('] as [.resultType.name]')
63        if includeShared and .isShared
64            # TODO: other is names
65            sb.append(' is shared')
66        return sb.toString
67
68
69class IndexerGetter inherits ProperDexerXetter
70
71    cue init(token as IToken, indexer as Indexer)
72        base.init(token, indexer, List<of String>())  # to-do: take in docString
73
74    get englishName as String is override
75        return 'indexer getter'
76
77    get xetPartName as String is override
78        return 'get'
79
80    def _bindInt
81        _returnType = .parent.returnType  # must be before base
82        base._bindInt
83        assert _returnType
84        for param in .parent.params, _params.add(param)
85
86
87class IndexerSetter inherits ProperDexerXetter
88
89    cue init(token as IToken, indexer as Indexer)
90        base.init(token, indexer, List<of String>())  # to-do: take in docString
91
92        # make a token for the Param()
93        t = token.copy
94        t.which, t.text, t.value = 'ID', 'value', 'value'
95
96        if indexer.returnType
97            p = Param(t, indexer.returnType, isImplicit=true)
98        else if indexer.returnTypeNode
99            p = Param(t, indexer.returnTypeNode, isImplicit=true)
100        else
101            throw FallThroughException(indexer)
102        _params.add(p)
103
104    get englishName as String is override
105        return 'indexer setter'
106
107    get xetPartName as String is override
108        return 'set'
109
110    def _bindInt
111        base._bindInt
112        _returnType = .compiler.voidType
113        assert _returnType
114        for param in .parent.params, _params.add(param)
Note: See TracBrowser for help on using the browser.