-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathReferenceType.zu
164 lines (145 loc) · 4.09 KB
/
ReferenceType.zu
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
#
# The Zimbu compiler written in Zimbu
#
# ReferenceType class.
#
# A Type used for variables with "pass by reference" semantics
#
# Copyright 2011 Bram Moolenaar All Rights Reserved.
# Licensed under the Apache License, Version 2.0. See the LICENSE file or
# obtain a copy at: http://www.apache.org/licenses/LICENSE-2.0
#
IMPORT "ClassType.zu"
IMPORT "Declaration.zu"
IMPORT "MethodType.zu"
IMPORT "SContext.zu"
IMPORT "Type.zu"
CLASS ReferenceType EXTENDS Type @items=public
# What this type refers to, for Type.Enum.byRef, Type.Enum.procRef and
# Type.Enum.funcRef
Type $reference
NEW(Type.Enum type, Type reference, string name) @default
PARENT.NEW(type, name)
IF type != Type.Enum.byRef
LOG.internal("Setting reference for type that is not ref")
}
$reference = reference
}
FUNC $isValueType() bool @replace
RETURN FALSE
}
FUNC $typeToString() string @replace @default
string s = PARENT.typeToString()
IF $ttype == Type.Enum.byRef
s ..= " reference: " .. $reference.typeToString()
}
RETURN s
}
# Make a copy of this Type. Every subclass must redefine it.
FUNC $copyType() Type @replace @default
ReferenceType.C ret = NEW($ttype, $name)
$copyReferenceValues(ret)
RETURN ret
}
# Copy the values of this object into |ret|.
PROC $copyReferenceValues(ReferenceType ret) @default
$copyTypeValues(ret)
ret.reference = $reference
}
# Return the name for the object declaration table.
# Return an empty string if this is a reference to a value that is not
# allocated.
FUNC $getTypeName(SContext ctx) string @replace @default
SWITCH $ttype
CASE Enum.string
RETURN "string"
CASE Enum.byteString
RETURN "byteString"
CASE Enum.varString
RETURN "varString"
CASE Enum.varByteString
RETURN "varByteString"
}
IF $reference == NIL
LOG.internal("Unknown reference type: \($ttype.ToString())")
}
# Name will not be used.
RETURN ""
}
# Return TRUE for types that use managed memory. This excludes pointers to
# callbacks, these are in static memory. Also exclude references, e.g. an
# "&undef" argument.
FUNC $isManaged() bool @replace @default
SWITCH $ttype
CASE Enum.string
CASE Enum.byteString
CASE Enum.varString
CASE Enum.varByteString
RETURN TRUE
}
RETURN FALSE
}
# Return something nicer than "ref".
FUNC $typeName(bool long) string @replace @default
SWITCH $ttype
CASE Type.Enum.byRef
CASE Type.Enum.procRef
CASE Type.Enum.funcRef
IF $reference != NIL
RETURN $reference.typeName(long) .. " &"
}
}
RETURN PARENT.typeName(long)
}
# Return the type of the referenced declaration
FUNC $getReferencedType() Type
RETURN $reference
}
# Set the type of the referenced declaration.
PROC $setReferencedType(Type ref)
$reference = ref
}
# Turn the referenced type into a ValueType, if needed.
PROC $makeValueType(SContext ctx)
IF $reference != NIL && $reference.needCopyValue()
$reference = $reference.getValueType(ctx)
}
}
# For a proc, func, procRef, funcRef: return the method type.
# Otherwise return NIL
FUNC $getMethod() MethodType @replace @default
IF $reference != NIL
RETURN $reference.getMethod()
}
RETURN NIL
}
# For a method reference return the argument list.
# Otherwise return NIL
FUNC $getArgList() list<Declaration.C> @replace @default
IF $reference != NIL
RETURN $reference.getArgList()
}
RETURN NIL
}
# For a method reference return the return type.
# Otherwise return NIL
FUNC $getReturnType() Type @replace @default
IF $reference != NIL
RETURN $reference.getReturnType()
}
RETURN NIL
}
# Return the extra return types.
FUNC $getMoreReturnTypes() list<Type> @replace @default
IF $reference != NIL
RETURN $reference.getMoreReturnTypes()
}
RETURN NIL
}
FUNC $getTypespecType(int idx) Type @replace @default
IF $reference != NIL
RETURN $reference.getTypespecType(idx)
}
RETURN NIL
}
}