/// <summary> /// Creates a new type reference. /// /// <param name="symbol">unresolved type symbol</param> /// <param name="source">reference to source code</param> /// <returns>newly created type reference</returns> /// </summary> public static UnresolvedType from_symbol(UnresolvedSymbol symbol, SourceReference source = null) { UnresolvedType @this = new UnresolvedType(); @this.unresolved_symbol = symbol; @this.source_reference = source; return(@this); }
/// <summary> /// Creates a new type reference from a code expression. /// /// <param name="expr">member access expression</param> /// <returns>newly created type reference</returns> /// </summary> public static UnresolvedType new_from_expression(Expression expr) { var sym = UnresolvedSymbol.new_from_expression(expr); if (sym != null) { var type_ref = UnresolvedType.from_symbol(sym, expr.source_reference); type_ref.value_owned = true; var ma = (MemberAccess)expr; foreach (DataType arg in ma.get_type_arguments()) { type_ref.add_type_argument(arg); } return(type_ref); } return(null); }
private Symbol resolve_symbol(UnresolvedSymbol unresolved_symbol) { if (unresolved_symbol.qualified) { // qualified access to global symbol return(root_symbol.scope.lookup(unresolved_symbol.name)); } else if (unresolved_symbol.inner == null) { Symbol sym = null; Scope scope = current_scope; while (sym == null && scope != null) { sym = scope.lookup(unresolved_symbol.name); // only look for types and type containers if (!(sym is Namespace || sym is TypeSymbol || sym is TypeParameter)) { sym = null; } scope = scope.parent_scope; } if (sym == null && unresolved_symbol.source_reference != null) { foreach (UsingDirective ns in unresolved_symbol.source_reference.using_directives) { if (ns.error || ns.namespace_symbol is UnresolvedSymbol) { continue; } var local_sym = ns.namespace_symbol.scope.lookup(unresolved_symbol.name); // only look for types and type containers if (!(local_sym is Namespace || local_sym is TypeSymbol || sym is TypeParameter)) { local_sym = null; } if (local_sym != null) { if (sym != null && sym != local_sym) { unresolved_symbol.error = true; Report.error(unresolved_symbol.source_reference, "`%s' is an ambiguous reference between `%s' and `%s'".printf(unresolved_symbol.name, sym.get_full_name(), local_sym.get_full_name())); return(null); } sym = local_sym; } } } return(sym); } else { var parent_symbol = resolve_symbol(unresolved_symbol.inner); if (parent_symbol == null) { unresolved_symbol.error = true; Report.error(unresolved_symbol.inner.source_reference, "The symbol `%s' could not be found".printf(unresolved_symbol.inner.name)); return(null); } parent_symbol.used = true; return(parent_symbol.scope.lookup(unresolved_symbol.name)); } }