Index: uspace/app/sbi/src/symbol.c
===================================================================
--- uspace/app/sbi/src/symbol.c	(revision 074444f189ee9356421b26e70454fae61c81def3)
+++ uspace/app/sbi/src/symbol.c	(revision 883fedc17e531dbc742cf77dc44e3bff56c53dce)
@@ -44,5 +44,16 @@
 static stree_ident_t *symbol_get_ident(stree_symbol_t *symbol);
 
-/** Lookup symbol in CSI using a type expression. */
+/** Lookup symbol in CSI using a type expression.
+ *
+ * XXX This should be removed in favor of full type expression evaluation
+ * (run_texpr). This cannot work properly with generics.
+ *
+ * @param prog		Program
+ * @param scope		CSI used as base for relative references
+ * @param texpr		Type expression
+ *
+ * @return		Symbol referenced by type expression or @c NULL
+ *			if not found
+ */
 stree_symbol_t *symbol_xlookup_in_csi(stree_program_t *prog,
     stree_csi_t *scope, stree_texpr_t *texpr)
@@ -77,9 +88,9 @@
 /** Lookup symbol reference in CSI.
  *
- * @param prog	Program to look in.
- * @param scope CSI in @a prog which is the base for references.
- * @param name	Identifier of the symbol.
- *
- * @return	Symbol or @c NULL if symbol not found.
+ * @param prog	Program to look in
+ * @param scope CSI in @a prog which is the base for references
+ * @param name	Identifier of the symbol
+ *
+ * @return	Symbol or @c NULL if symbol not found
  */
 stree_symbol_t *symbol_lookup_in_csi(stree_program_t *prog, stree_csi_t *scope,
@@ -107,4 +118,10 @@
  * Look for symbol in definition of a CSI and its ancestors. (But not
  * in lexically enclosing CSI.)
+ *
+ * @param prog	Program to look in
+ * @param scope CSI in which to look
+ * @param name	Identifier of the symbol
+ *
+ * @return	Symbol or @c NULL if symbol not found.
  */
 stree_symbol_t *symbol_search_csi(stree_program_t *prog,
@@ -125,10 +142,14 @@
 	while (node != NULL) {
 		csimbr = list_node_data(node, stree_csimbr_t *);
+
+		/* Keep compiler happy. */
+		mbr_name = NULL;
+
 		switch (csimbr->cc) {
 		case csimbr_csi: mbr_name = csimbr->u.csi->name; break;
+		case csimbr_deleg: mbr_name = csimbr->u.deleg->name; break;
 		case csimbr_fun: mbr_name = csimbr->u.fun->name; break;
 		case csimbr_var: mbr_name = csimbr->u.var->name; break;
 		case csimbr_prop: mbr_name = csimbr->u.prop->name; break;
-		default: assert(b_false);
 		}
 
@@ -138,4 +159,7 @@
 			case csimbr_csi:
 				symbol = csi_to_symbol(csimbr->u.csi);
+				break;
+			case csimbr_deleg:
+				symbol = deleg_to_symbol(csimbr->u.deleg);
 				break;
 			case csimbr_fun:
@@ -170,4 +194,11 @@
 }
 
+/** Look for symbol in global scope.
+ *
+ * @param prog	Program to look in
+ * @param name	Identifier of the symbol
+ *
+ * @return	Symbol or @c NULL if symbol not found.
+ */
 static stree_symbol_t *symbol_search_global(stree_program_t *prog,
     stree_ident_t *name)
@@ -197,5 +228,13 @@
 }
 
-/** Find entry point. */
+/** Find entry point.
+ *
+ * Perform a walk of all CSIs and look for a function with the name @a name.
+ *
+ * @param prog	Program to look in
+ * @param name	Name of entry point
+ *
+ * @return	Symbol or @c NULL if symbol not found.
+ */
 stree_symbol_t *symbol_find_epoint(stree_program_t *prog, stree_ident_t *name)
 {
@@ -225,4 +264,13 @@
 }
 
+/** Find entry point under CSI.
+ *
+ * Internal part of symbol_find_epoint() that recursively walks CSIs.
+ *
+ * @param prog	Program to look in
+ * @param name	Name of entry point
+ *
+ * @return	Symbol or @c NULL if symbol not found.
+ */
 static stree_symbol_t *symbol_find_epoint_rec(stree_program_t *prog,
     stree_ident_t *name, stree_csi_t *csi)
@@ -267,4 +315,40 @@
 }
 
+/*
+ * The notion of symbol is designed as a common base class for several
+ * types of declarations with global and CSI scope. Here we simulate
+ * conversion from this base class (symbol) to derived classes (CSI,
+ * fun, ..) and vice versa.
+ */
+
+/** Convert symbol to delegate (base to derived).
+ *
+ * @param symbol	Symbol
+ * @return		Delegate or @c NULL if symbol is not a delegate
+ */
+stree_deleg_t *symbol_to_deleg(stree_symbol_t *symbol)
+{
+	if (symbol->sc != sc_deleg)
+		return NULL;
+
+	return symbol->u.deleg;
+}
+
+/** Convert delegate to symbol (derived to base).
+ *
+ * @param deleg		Delegate
+ * @return		Symbol
+ */
+stree_symbol_t *deleg_to_symbol(stree_deleg_t *deleg)
+{
+	assert(deleg->symbol);
+	return deleg->symbol;
+}
+
+/** Convert symbol to CSI (base to derived).
+ *
+ * @param symbol	Symbol
+ * @return		CSI or @c NULL if symbol is not a CSI
+ */
 stree_csi_t *symbol_to_csi(stree_symbol_t *symbol)
 {
@@ -275,4 +359,9 @@
 }
 
+/** Convert CSI to symbol (derived to base).
+ *
+ * @param csi		CSI
+ * @return		Symbol
+ */
 stree_symbol_t *csi_to_symbol(stree_csi_t *csi)
 {
@@ -281,4 +370,9 @@
 }
 
+/** Convert symbol to function (base to derived).
+ *
+ * @param symbol	Symbol
+ * @return		Function or @c NULL if symbol is not a function
+ */
 stree_fun_t *symbol_to_fun(stree_symbol_t *symbol)
 {
@@ -289,4 +383,9 @@
 }
 
+/** Convert function to symbol (derived to base).
+ *
+ * @param fun		Function
+ * @return		Symbol
+ */
 stree_symbol_t *fun_to_symbol(stree_fun_t *fun)
 {
@@ -295,4 +394,9 @@
 }
 
+/** Convert symbol to member variable (base to derived).
+ *
+ * @param symbol	Symbol
+ * @return		Variable or @c NULL if symbol is not a member variable
+ */
 stree_var_t *symbol_to_var(stree_symbol_t *symbol)
 {
@@ -303,4 +407,9 @@
 }
 
+/** Convert variable to symbol (derived to base).
+ *
+ * @param fun		Variable
+ * @return		Symbol
+ */
 stree_symbol_t *var_to_symbol(stree_var_t *var)
 {
@@ -309,4 +418,9 @@
 }
 
+/** Convert symbol to property (base to derived).
+ *
+ * @param symbol	Symbol
+ * @return		Property or @c NULL if symbol is not a property
+ */
 stree_prop_t *symbol_to_prop(stree_symbol_t *symbol)
 {
@@ -317,4 +431,9 @@
 }
 
+/** Convert property to symbol (derived to base).
+ *
+ * @param fun		Property
+ * @return		Symbol
+ */
 stree_symbol_t *prop_to_symbol(stree_prop_t *prop)
 {
@@ -323,5 +442,8 @@
 }
 
-/** Print fully qualified name of symbol. */
+/** Print fully qualified name of symbol.
+ *
+ * @param symbol	Symbol
+ */
 void symbol_print_fqn(stree_symbol_t *symbol)
 {
@@ -339,4 +461,9 @@
 }
 
+/** Return symbol identifier.
+ *
+ * @param symbol	Symbol
+ * @return 		Symbol identifier
+ */
 static stree_ident_t *symbol_get_ident(stree_symbol_t *symbol)
 {
@@ -345,4 +472,5 @@
 	switch (symbol->sc) {
 	case sc_csi: ident = symbol->u.csi->name; break;
+	case sc_deleg: ident = symbol->u.deleg->name; break;
 	case sc_fun: ident = symbol->u.fun->name; break;
 	case sc_var: ident = symbol->u.var->name; break;
