1 # This file is part of NIT ( http://www.nitlanguage.org ).
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
7 # http://www.apache.org/licenses/LICENSE-2.0
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
15 # Typing and parameters.
16 module model
::type_entity
21 # Base class of all types and signatures.
22 abstract class TypeEntity
27 self.labels
.add
("MType")
31 # A type parameter or a type argument.
33 # Note : The class relationship and the rank are set by `MClassType.put_edges`.
40 self.labels
.add
("MParameterType")
45 # A type described by a text.
52 self.labels
.add
("MRawType")
55 redef fun create_link
(rank
, refid
) do return new TypeLink(graph
, refid
)
58 # A link in a `RawType`.
64 self.labels
.add
("MTypePart")
69 # A signature of a method.
74 var parameters
= new Array[MemberParameter]
76 # The static type of the returned value.
77 var return_type
: nullable TypeEntity = null is writable
81 self.labels
.add
("MSignature")
84 redef fun put_in_graph
do
86 if return_type
isa TypeEntity then
87 return_type
.as(TypeEntity).put_in_graph
89 for p
in parameters
do
94 redef fun put_edges
do
96 if parameters
.length
> 0 then
97 var names
= new JsonArray
99 for i
in [0..parameters
.length
[ do
100 var p
= parameters
[i
]
103 graph
.add_edge
(self, "PARAMETER", p
)
105 self["parameter_names"] = names
107 if return_type
!= null then
108 graph
.add_edge
(self, "RETURNTYPE", return_type
.as(not null))
113 # A parameter or an argument.
114 abstract class Parameter
117 # The static type of the parameter.
118 var static_type
: nullable TypeEntity = null is writable
122 self["is_vararg"] = false
126 # Is the parameter a “vararg”?
127 fun is_vararg
=(is_vararg
: Bool) do
128 self["is_vararg"] = is_vararg
131 # Is the parameter a “vararg”?
132 fun is_vararg
: Bool do
133 var value
= self["is_vararg"]
134 assert value
isa Bool
138 # Set the rank (index) of the parameter in the signature.
139 fun rank
=(rank
: Int) do
143 redef fun put_in_graph
do
145 if static_type
!= null then
146 static_type
.as(not null).put_in_graph
150 redef fun put_edges
do
152 graph
.add_edge
(self, "TYPE", static_type
.as(not null))
156 # A parameter of a member.
158 # Note : The rank are set by `Signature.put_edges`.
159 class MemberParameter
164 self.labels
.add
("MParameter")