ANEW ANN m_str tl2str(const Env, const Type_List); // in type_decl.c
ANN m_bool compat_func(const __restrict__ Func_Def, const __restrict__ Func_Def);
ANN Type known_type(const Env env, const Type_Decl*);
+ANN Type known_type_noref(const Env env, const Type_Decl* td);
+ANN Type prim_ref(const Env env, const Type t, const Type_Decl* td);
ANN m_bool env_access(const Env env, const ae_flag flag, const loc_t pos);
ANN m_bool env_storage(const Env env, ae_flag flag, const loc_t pos);
ANN void env_add_type(const Env, const Type);
ANN static m_bool scan1_stmt(const Env env, Stmt stmt);
ANN static Type void_type(const Env env, const Type_Decl* td) {
- DECL_OO(const Type, t, = known_type(env, td))
+ DECL_OO(const Type, t, = known_type_noref(env, td))
if(t->e->def && !GET_FLAG(t, scan1))
CHECK_BO(scan1_cdef(env, t->e->def))
if(t->size)
if(!GET_FLAG(decl->td, static))
SET_FLAG(decl->td, member);
}
-// if(GET_FLAG(t, abstract) && !GET_FLAG(decl->td, ref))
-// ERR_O(exp_self(decl)->pos, _("Type '%s' is abstract, declare as ref. (use @)"), t->name)
if(GET_FLAG(t, private) && t->e->owner != env->curr)
ERR_O(exp_self(decl)->pos, _("can't use private type %s"), t->name)
if(GET_FLAG(t, protect) && (!env->class_def || isa(t, env->class_def) < 0))
s_name(var->xid))
if(var->array) {
if(var->array->exp) {
-// if(GET_FLAG(decl->td, ref))
- if(GET_FLAG(decl->td, ref) && isa(t, t_object) < 0)
+ if(GET_FLAG(decl->td, ref))
ERR_B(td_pos(decl->td), _("ref array must not have array expression.\n"
"e.g: int @my_array[];\nnot: int @my_array[2];"))
CHECK_BB(scan1_exp(env, var->array->exp))
t = array_type(env, decl->type, var->array->depth);
} else if(GET_FLAG(t, abstract) && !GET_FLAG(decl->td, ref))
ERR_B(exp_self(decl)->pos, _("Type '%s' is abstract, declare as ref. (use @)"), t->name)
-
+ CHECK_OB(prim_ref(env, t, decl->td))
//assert(!var->value);
const Value v = var->value = former ?: new_value(env->gwion->mp, t, s_name(var->xid));
nspc_add_value(nspc, var->xid, v);
const Var_Decl var = list->var_decl;
if(var->xid)
CHECK_BB(isres(env, var->xid, var->pos))
- if(list->td)
+ if(list->td) {
CHECK_OB((list->type = void_type(env, list->td)))
+ CHECK_OB(prim_ref(env, list->type, list->td))
+ }
} while((list = list->next));
return GW_OK;
}
return NULL;
}
-ANN static inline Type prim_ref(const Env env, const Type t, const Type_Decl* td) {
+ANN Type prim_ref(const Env env, const Type t, const Type_Decl* td) {
if(GET_FLAG(td, ref) && isa(t, t_object) < 0 && isa(t, t_class) < 0)
ERR_O(td->xid->pos, _("primitive types cannot be used as reference (@)...\n"))
return t;
const Type t = type_decl_resolve(env, td);
return t ? prim_ref(env, t, td) : type_unknown(env, td->xid);
}
+
+ANN Type known_type_noref(const Env env, const Type_Decl* td) {
+ if(!td->xid)
+ return t_undefined;
+ return type_decl_resolve(env, td) ?: type_unknown(env, td->xid);
+}