Index: uspace/app/sbi/src/run_texpr.c
===================================================================
--- uspace/app/sbi/src/run_texpr.c	(revision 38aaacc20a85af2361a0240ac2e7d643e086ecfa)
+++ uspace/app/sbi/src/run_texpr.c	(revision 051bc69a7034999d45c93c61a56e515474aa78e3)
@@ -31,4 +31,5 @@
 #include <assert.h>
 #include <stdlib.h>
+#include "cspan.h"
 #include "debug.h"
 #include "list.h"
@@ -102,4 +103,7 @@
 	tdata_deleg_t *tdeleg;
 	stree_csi_t *base_csi;
+	stree_deleg_t *deleg;
+	stree_enum_t *enum_d;
+	tdata_enum_t *tenum;
 
 #ifdef DEBUG_RUN_TRACE
@@ -115,5 +119,7 @@
 
 	if (targ_i->tic != tic_tobject) {
-		printf("Error: Using '.' with type which is not an object.\n");
+		cspan_print(taccess->texpr->cspan);
+		printf(" Error: Using '.' with type which is not an "
+		    "object.\n");
 		*res = tdata_item_new(tic_ignore);
 		return;
@@ -125,5 +131,6 @@
 	sym = symbol_lookup_in_csi(prog, base_csi, taccess->member_name);
 	if (sym == NULL) {
-		printf("Error: CSI '");
+		cspan_print(taccess->member_name->cspan);
+		printf(" Error: CSI '");
 		symbol_print_fqn(csi_to_symbol(base_csi));
 		printf("' has no member named '%s'.\n",
@@ -142,172 +149,9 @@
 		tobject->static_ref = b_false;
 		tobject->csi = sym->u.csi;
-		list_init(&tobject->targs); /* XXX */
-		break;
-	case sc_deleg:
-		/* Construct type item. */
-		titem = tdata_item_new(tic_tdeleg);
-		tdeleg = tdata_deleg_new();
-		titem->u.tdeleg = tdeleg;
-
-		tdeleg->deleg = sym->u.deleg;
-		break;
-	case sc_fun:
-	case sc_var:
-	case sc_prop:
-		printf("Error: Symbol '");
-		symbol_print_fqn(sym);
-		printf("' is not a type.\n");
-		titem = tdata_item_new(tic_ignore);
-		break;
-	}
-
-	*res = titem;
-}
-
-/** Evaluate type indexing expression.
- *
- * Evaluate operation per the type indexing ('[', ']') operator.
- * A type indexing operation may have extents specified or only rank
- * specified.
- *
- * @param prog		Program
- * @param ctx		Current CSI (context)
- * @param tindex	Type indexing expression to evaluate
- * @param res		Place to store type result
- */
-static void run_tindex(stree_program_t *prog, stree_csi_t *ctx,
-    stree_tindex_t *tindex, tdata_item_t **res)
-{
-	tdata_item_t *base_ti;
-	tdata_item_t *titem;
-	tdata_array_t *tarray;
-	stree_expr_t *arg_expr;
-	list_node_t *arg_node;
-
-#ifdef DEBUG_RUN_TRACE
-	printf("Evaluating type index operation.\n");
-#endif
-	/* Evaluate base type. */
-	run_texpr(prog, ctx, tindex->base_type, &base_ti);
-
-	if (base_ti->tic == tic_ignore) {
-		*res = tdata_item_new(tic_ignore);
-		return;
-	}
-
-	/* Construct type item. */
-	titem = tdata_item_new(tic_tarray);
-	tarray = tdata_array_new();
-	titem->u.tarray = tarray;
-
-	tarray->base_ti = base_ti;
-	tarray->rank = tindex->n_args;
-
-	/* Copy extents. */
-	list_init(&tarray->extents);
-	arg_node = list_first(&tindex->args);
-
-	while (arg_node != NULL) {
-		arg_expr = list_node_data(arg_node, stree_expr_t *);
-		list_append(&tarray->extents, arg_expr);
-		arg_node = list_next(&tindex->args, arg_node);
-	}
-
-	*res = titem;
-}
-
-/** Evaluate type literal expression.
- *
- * @param prog		Program
- * @param ctx		Current CSI (context)
- * @param tliteral	Type literal
- * @param res		Place to store type result
- */
-static void run_tliteral(stree_program_t *prog, stree_csi_t *ctx,
-    stree_tliteral_t *tliteral, tdata_item_t **res)
-{
-	tdata_item_t *titem;
-	tdata_primitive_t *tprimitive;
-	tprimitive_class_t tpc;
-
-#ifdef DEBUG_RUN_TRACE
-	printf("Evaluating type literal.\n");
-#endif
-	(void) prog;
-	(void) ctx;
-	(void) tliteral;
-
-	switch (tliteral->tlc) {
-	case tlc_bool: tpc = tpc_bool; break;
-	case tlc_char: tpc = tpc_char; break;
-	case tlc_int: tpc = tpc_int; break;
-	case tlc_string: tpc = tpc_string; break;
-	case tlc_resource: tpc = tpc_resource; break;
-	}
-
-	/* Construct type item. */
-	titem = tdata_item_new(tic_tprimitive);
-	tprimitive = tdata_primitive_new(tpc);
-	titem->u.tprimitive = tprimitive;
-
-	*res = titem;
-}
-
-static void run_tnameref(stree_program_t *prog, stree_csi_t *ctx,
-    stree_tnameref_t *tnameref, tdata_item_t **res)
-{
-	stree_symbol_t *sym;
-	tdata_item_t *titem;
-	tdata_object_t *tobject;
-	stree_targ_t *targ;
-	tdata_vref_t *tvref;
-	stree_deleg_t *deleg;
-	tdata_deleg_t *tdeleg;
-
-#ifdef DEBUG_RUN_TRACE
-	printf("Evaluating type name reference.\n");
-	printf("'%s'\n", strtab_get_str(tnameref->name->sid));
-#endif
-	/* In interactive mode we are not in a class */
-	if (ctx != NULL) {
-		/* Look for type argument */
-		targ = stree_csi_find_targ(ctx, tnameref->name);
-
-		if (targ != NULL) {
-			/* Found type argument */
-#ifdef DEBUG_RUN_TRACE
-			printf("Found type argument '%s'.\n",
-			    strtab_get_str(tnameref->name->sid));
-#endif
-			titem = tdata_item_new(tic_tvref);
-			tvref = tdata_vref_new();
-			titem->u.tvref = tvref;
-			tvref->targ = targ;
-
-			*res = titem;
-			return;
-		}
-	}
-
-	/* Look for symbol */
-	sym = symbol_lookup_in_csi(prog, ctx, tnameref->name);
-	if (sym == NULL) {
-		printf("Error: Symbol '%s' not found.\n",
-		    strtab_get_str(tnameref->name->sid));
-		*res = tdata_item_new(tic_ignore);
-		return;
-	}
-
-	switch (sym->sc) {
-	case sc_csi:
-		/* Construct type item. */
-		titem = tdata_item_new(tic_tobject);
-		tobject = tdata_object_new();
-		titem->u.tobject = tobject;
-
-		tobject->static_ref = b_false;
-		tobject->csi = sym->u.csi;
-		list_init(&tobject->targs); /* XXX */
-		break;
+		list_init(&tobject->targs);
+		break;
+	case sc_ctor:
+		/* It is not possible to reference a constructor explicitly. */
+		assert(b_false);
 	case sc_deleg:
 		/* Fetch stored delegate type. */
@@ -330,8 +174,228 @@
 		}
 		break;
+	case sc_enum:
+		/* Fetch stored enum type. */
+		enum_d = symbol_to_enum(sym);
+		assert(enum_d != NULL);
+		if (enum_d->titem == NULL) {
+			/*
+			 * Prepare a partial enum whic will be completed
+			 * later.
+			 */
+			titem = tdata_item_new(tic_tenum);
+			tenum = tdata_enum_new();
+			titem->u.tenum = tenum;
+			tenum->enum_d = enum_d;
+		} else {
+			titem = enum_d->titem;
+		}
+		break;
 	case sc_fun:
 	case sc_var:
 	case sc_prop:
-		printf("Error: Symbol '");
+		cspan_print(taccess->member_name->cspan);
+		printf(" Error: Symbol '");
+		symbol_print_fqn(sym);
+		printf("' is not a type.\n");
+		titem = tdata_item_new(tic_ignore);
+		break;
+	}
+
+	*res = titem;
+}
+
+/** Evaluate type indexing expression.
+ *
+ * Evaluate operation per the type indexing ('[', ']') operator.
+ * A type indexing operation may have extents specified or only rank
+ * specified.
+ *
+ * @param prog		Program
+ * @param ctx		Current CSI (context)
+ * @param tindex	Type indexing expression to evaluate
+ * @param res		Place to store type result
+ */
+static void run_tindex(stree_program_t *prog, stree_csi_t *ctx,
+    stree_tindex_t *tindex, tdata_item_t **res)
+{
+	tdata_item_t *base_ti;
+	tdata_item_t *titem;
+	tdata_array_t *tarray;
+	stree_expr_t *arg_expr;
+	list_node_t *arg_node;
+
+#ifdef DEBUG_RUN_TRACE
+	printf("Evaluating type index operation.\n");
+#endif
+	/* Evaluate base type. */
+	run_texpr(prog, ctx, tindex->base_type, &base_ti);
+
+	if (base_ti->tic == tic_ignore) {
+		*res = tdata_item_new(tic_ignore);
+		return;
+	}
+
+	/* Construct type item. */
+	titem = tdata_item_new(tic_tarray);
+	tarray = tdata_array_new();
+	titem->u.tarray = tarray;
+
+	tarray->base_ti = base_ti;
+	tarray->rank = tindex->n_args;
+
+	/* Copy extents. */
+	list_init(&tarray->extents);
+	arg_node = list_first(&tindex->args);
+
+	while (arg_node != NULL) {
+		arg_expr = list_node_data(arg_node, stree_expr_t *);
+		list_append(&tarray->extents, arg_expr);
+		arg_node = list_next(&tindex->args, arg_node);
+	}
+
+	*res = titem;
+}
+
+/** Evaluate type literal expression.
+ *
+ * @param prog		Program
+ * @param ctx		Current CSI (context)
+ * @param tliteral	Type literal
+ * @param res		Place to store type result
+ */
+static void run_tliteral(stree_program_t *prog, stree_csi_t *ctx,
+    stree_tliteral_t *tliteral, tdata_item_t **res)
+{
+	tdata_item_t *titem;
+	tdata_primitive_t *tprimitive;
+	tprimitive_class_t tpc;
+
+#ifdef DEBUG_RUN_TRACE
+	printf("Evaluating type literal.\n");
+#endif
+	(void) prog;
+	(void) ctx;
+	(void) tliteral;
+
+	switch (tliteral->tlc) {
+	case tlc_bool: tpc = tpc_bool; break;
+	case tlc_char: tpc = tpc_char; break;
+	case tlc_int: tpc = tpc_int; break;
+	case tlc_string: tpc = tpc_string; break;
+	case tlc_resource: tpc = tpc_resource; break;
+	}
+
+	/* Construct type item. */
+	titem = tdata_item_new(tic_tprimitive);
+	tprimitive = tdata_primitive_new(tpc);
+	titem->u.tprimitive = tprimitive;
+
+	*res = titem;
+}
+
+static void run_tnameref(stree_program_t *prog, stree_csi_t *ctx,
+    stree_tnameref_t *tnameref, tdata_item_t **res)
+{
+	stree_symbol_t *sym;
+	tdata_item_t *titem;
+	tdata_object_t *tobject;
+	stree_targ_t *targ;
+	tdata_vref_t *tvref;
+	stree_deleg_t *deleg;
+	tdata_deleg_t *tdeleg;
+	stree_enum_t *enum_d;
+	tdata_enum_t *tenum;
+
+#ifdef DEBUG_RUN_TRACE
+	printf("Evaluating type name reference.\n");
+	printf("'%s'\n", strtab_get_str(tnameref->name->sid));
+#endif
+	/* In interactive mode we are not in a class */
+	if (ctx != NULL) {
+		/* Look for type argument */
+		targ = stree_csi_find_targ(ctx, tnameref->name);
+
+		if (targ != NULL) {
+			/* Found type argument */
+#ifdef DEBUG_RUN_TRACE
+			printf("Found type argument '%s'.\n",
+			    strtab_get_str(tnameref->name->sid));
+#endif
+			titem = tdata_item_new(tic_tvref);
+			tvref = tdata_vref_new();
+			titem->u.tvref = tvref;
+			tvref->targ = targ;
+
+			*res = titem;
+			return;
+		}
+	}
+
+	/* Look for symbol */
+	sym = symbol_lookup_in_csi(prog, ctx, tnameref->name);
+	if (sym == NULL) {
+		cspan_print(tnameref->texpr->cspan);
+		printf(" Error: Symbol '%s' not found.\n",
+		    strtab_get_str(tnameref->name->sid));
+		*res = tdata_item_new(tic_ignore);
+		return;
+	}
+
+	switch (sym->sc) {
+	case sc_csi:
+		/* Construct type item. */
+		titem = tdata_item_new(tic_tobject);
+		tobject = tdata_object_new();
+		titem->u.tobject = tobject;
+
+		tobject->static_ref = b_false;
+		tobject->csi = sym->u.csi;
+		list_init(&tobject->targs);
+		break;
+	case sc_ctor:
+		/* It is not possible to reference a constructor explicitly. */
+		assert(b_false);
+	case sc_deleg:
+		/* Fetch stored delegate type. */
+		deleg = symbol_to_deleg(sym);
+		assert(deleg != NULL);
+		if (deleg->titem == NULL) {
+			/*
+			 * Prepare a partial delegate which will be completed
+			 * later.
+			 */
+			titem = tdata_item_new(tic_tdeleg);
+			tdeleg = tdata_deleg_new();
+			titem->u.tdeleg = tdeleg;
+			tdeleg->deleg = deleg;
+			tdeleg->tsig = NULL;
+
+			deleg->titem = titem;
+		} else {
+			titem = deleg->titem;
+		}
+		break;
+	case sc_enum:
+		/* Fetch stored enum type. */
+		enum_d = symbol_to_enum(sym);
+		assert(enum_d != NULL);
+		if (enum_d->titem == NULL) {
+			/*
+			 * Prepare a partial enum whic will be completed
+			 * later.
+			 */
+			titem = tdata_item_new(tic_tenum);
+			tenum = tdata_enum_new();
+			titem->u.tenum = tenum;
+			tenum->enum_d = enum_d;
+		} else {
+			titem = enum_d->titem;
+		}
+		break;
+	case sc_fun:
+	case sc_var:
+	case sc_prop:
+		cspan_print(tnameref->texpr->cspan);
+		printf(" Error: Symbol '");
 		symbol_print_fqn(sym);
 		printf("' is not a type.\n");
@@ -379,5 +443,6 @@
 
 	if (base_ti->tic != tic_tobject) {
-		printf("Error: Base type of generic application is not "
+		cspan_print(tapply->gtype->cspan);
+		printf(" Error: Base type of generic application is not "
 		    "a CSI.\n");
 		*res = tdata_item_new(tic_ignore);
@@ -410,5 +475,6 @@
 
 	if (farg_n != NULL || arg_n != NULL) {
-		printf("Error: Incorrect number of type arguments.\n");
+		cspan_print(tapply->texpr->cspan);
+		printf(" Error: Incorrect number of type arguments.\n");
 		*res = tdata_item_new(tic_ignore);
 		return;
