From f59e2a1c01b4be9daab7058207e99c7e7d14d0bd Mon Sep 17 00:00:00 2001 From: Jean Privat Date: Tue, 1 May 2012 14:24:40 -0400 Subject: [PATCH] modelbuilder: easy attribute typing Signed-off-by: Jean Privat --- src/modelbuilder.nit | 33 +++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/src/modelbuilder.nit b/src/modelbuilder.nit index a6efbe2..1386781 100644 --- a/src/modelbuilder.nit +++ b/src/modelbuilder.nit @@ -1289,10 +1289,39 @@ redef class AAttrPropdef end if mtype == null then - modelbuilder.warning(self, "Error: Untyped attribute {mpropdef}") - return + var nexpr = self.n_expr + if nexpr != null then + if nexpr isa ANewExpr then + mtype = modelbuilder.resolve_mtype(nclassdef, nexpr.n_type) + 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 AFloatExpr then + var cla = modelbuilder.try_get_mclass_by_name(nexpr, mmodule, "Float") + if cla != null then mtype = cla.mclass_type + else if nexpr isa ACharExpr then + var cla = modelbuilder.try_get_mclass_by_name(nexpr, mmodule, "Char") + if cla != null then mtype = cla.mclass_type + else if nexpr isa ABoolExpr then + var cla = modelbuilder.try_get_mclass_by_name(nexpr, mmodule, "Bool") + if cla != null then mtype = cla.mclass_type + else if nexpr isa ASuperstringExpr then + var cla = modelbuilder.try_get_mclass_by_name(nexpr, mmodule, "String") + if cla != null then mtype = cla.mclass_type + else if nexpr isa AStringFormExpr then + var cla = modelbuilder.try_get_mclass_by_name(nexpr, mmodule, "String") + if cla != null then mtype = cla.mclass_type + else + modelbuilder.error(self, "Error: Untyped attribute {mpropdef}. Implicit typing allowed only for literals and new.") + end + + else + modelbuilder.error(self, "Error: Untyped attribute {mpropdef}") + end end + if mtype == null then return + mpropdef.static_mtype = mtype var mreadpropdef = self.mreadpropdef -- 1.7.9.5