var anchor: nullable MClassType
# Make a new Int literal
- fun make_int(value: Int): AIntExpr
+ fun make_int(value: Int): AIntegerExpr
do
- return new ADecIntExpr.make(value, mmodule.int_type)
+ return new AIntegerExpr.make(value, mmodule.int_type)
end
# Make a new instatiation
end
end
-redef class ADecIntExpr
+redef class AIntegerExpr
private init make(value: Int, t: MType)
do
self.value = value
- self._n_number = new TNumber # dummy
+ self._n_integer = new TInteger # dummy
self.mtype = t
end
end
end
end
-redef class AIntExpr
- redef fun accept_printer(v)
- do
- v.write(value.to_s)
- end
-end
-
-redef class AByteExpr
+redef class AIntegerExpr
redef fun accept_printer(v)
do
v.write(value.to_s)
end
end
-redef class AIntExpr
- redef fun expr(v) do return v.int_instance(self.value.as(not null))
-end
-
-redef class AByteExpr
- redef fun expr(v) do return v.byte_instance(self.value.as(not null))
+redef class AIntegerExpr
+ redef fun expr(v) do
+ if value isa Int then return v.int_instance(value.as(Int))
+ if value isa Byte then return v.byte_instance(value.as(Byte))
+ # Should never happen
+ abort
+ end
end
redef class AFloatExpr
end
end
-redef class AIntExpr
- redef fun expr(v) do return v.int_instance(self.value.as(not null))
-end
-
-redef class AByteExpr
- redef fun expr(v) do return v.byte_instance(self.value.as(not null))
+redef class AIntegerExpr
+ redef fun expr(v) do
+ if value isa Int then
+ return v.int_instance(self.value.as(Int))
+ else if value isa Byte then
+ return v.byte_instance(self.value.as(Byte))
+ else
+ # Should not happen
+ abort
+ end
+ end
end
redef class AFloatExpr
# 2. The second operand must be an integer literal
var op2 = node.n_expr2
- if not op2 isa AIntExpr then return
+ if not op2 isa AIntegerExpr then return
# 3. Its value must be 0
# Note: because of `literal_phase` the `value` method exists
end
end
-redef class AIntExpr
+redef class AIntegerExpr
redef fun expr(v)
do
- return v.int_instance(self.value.as(not null))
- end
-end
-
-redef class AByteExpr
- redef fun expr(v)
- do
- return v.byte_instance(self.value.as(not null))
+ if value isa Int then return v.int_instance(value.as(Int))
+ if value isa Byte then return v.byte_instance(value.as(Byte))
+ return null
end
end
# Return null if not an integer.
fun as_int: nullable Int
do
- if not self isa AIntExpr then return null
- return self.value.as(not null)
+ if not self isa AIntegerExpr then return null
+ return self.value.as(not null).to_i
end
end
-redef class AIntExpr
+redef class AIntegerExpr
# The value of the literal int once computed.
- var value: nullable Int
+ var value: nullable Numeric
- redef fun accept_literal(v)
- do
- if not text.is_int then
- v.toolcontext.error(hot_location, "Error: invalid literal `{text}`")
- return
+ redef fun accept_literal(v) do
+ value = n_integer.text.to_num
+ if value == null then
+ v.toolcontext.error(hot_location, "Error: invalid literal `{n_integer.text}`")
end
- value = text.to_i
end
-
- private fun text: String is abstract
-end
-
-redef class ADecIntExpr
- redef fun text do return self.n_number.text
-end
-
-redef class AHexIntExpr
- redef fun text do return self.n_hex_number.text
-end
-
-redef class ABinIntExpr
- redef fun text do return self.n_bin_number.text
-end
-
-redef class AOctIntExpr
- redef fun text do return self.n_oct_number.text
-end
-
-redef class AByteExpr
- # The value of the literal int once computed.
- var value: nullable Byte
-
- redef fun accept_literal(v)
- do
- var s = text.substring(0, text.length - 2)
- if not s.is_int then
- v.toolcontext.error(hot_location, "Error: invalid byte literalĀ `{text}`")
- return
- end
- value = s.to_i.to_b
- end
-
- private fun text: String is abstract
-end
-
-redef class ADecByteExpr
- redef fun text do return self.n_bytenum.text
-end
-
-redef class AHexByteExpr
- redef fun text do return self.n_hex_bytenum.text
-end
-
-redef class ABinByteExpr
- redef fun text do return self.n_bin_bytenum.text
-end
-
-redef class AOctByteExpr
- redef fun text do return self.n_oct_bytenum.text
end
redef class AFloatExpr
if nexpr != null then
if nexpr isa ANewExpr then
mtype = modelbuilder.resolve_mtype_unchecked(mmodule, mclassdef, nexpr.n_type, true)
- else if nexpr isa AIntExpr then
- var cla = modelbuilder.try_get_mclass_by_name(nexpr, mmodule, "Int")
- if cla != null then mtype = cla.mclass_type
- else if nexpr isa AByteExpr then
- var cla = modelbuilder.try_get_mclass_by_name(nexpr, mmodule, "Byte")
+ else if nexpr isa AIntegerExpr then
+ var cla: nullable MClass = null
+ if nexpr.value isa Int then
+ cla = modelbuilder.try_get_mclass_by_name(nexpr, mmodule, "Int")
+ else if nexpr.value isa Byte then
+ cla = modelbuilder.try_get_mclass_by_name(nexpr, mmodule, "Byte")
+ else
+ # Should not happen, and should be updated as new types are added
+ abort
+ end
if cla != null then mtype = cla.mclass_type
else if nexpr isa AFloatExpr then
var cla = modelbuilder.try_get_mclass_by_name(nexpr, mmodule, "Float")
end
end
-redef class AIntExpr
- redef fun accept_rapid_type_visitor(v)
- do
- allocate_mtype(v)
- end
-end
-
-redef class AByteExpr
+redef class AIntegerExpr
redef fun accept_rapid_type_visitor(v)
do
allocate_mtype(v)
import modelize
import local_var_init
+import literal
redef class ToolContext
var typing_phase: Phase = new TypingPhase(self, [flow_phase, modelize_property_phase, local_var_init_phase])
end
end
-redef class AIntExpr
+redef class AIntegerExpr
redef fun accept_typing(v)
do
- var mclass = v.get_mclass(self, "Int")
- if mclass == null then return # Forward error
- self.mtype = mclass.mclass_type
- end
-end
-
-redef class AByteExpr
- redef fun accept_typing(v)
- do
- var mclass = v.get_mclass(self, "Byte")
+ var mclass: nullable MClass = null
+ if value isa Byte then
+ mclass = v.get_mclass(self, "Byte")
+ else if value isa Int then
+ mclass = v.get_mclass(self, "Int")
+ end
if mclass == null then return # Forward error
self.mtype = mclass.mclass_type
end