public string GetSignatureForDocumentation() { var s = Basename; if (ExplicitInterface != null) s = ExplicitInterface.GetSignatureForError () + "." + s; if (Left == null) return s; return Left.GetSignatureForDocumentation () + "." + s; }
public override FullNamedExpression Resolve(IResolveContext rc) { if (resolved != null || value == null) { return(resolved); } resolved = value.GetTypeExpression().ResolveAsTypeStep(rc, false); if (resolved == null) { value = null; return(null); } TypeExpr te = resolved as TypeExpr; if (te != null) { if (!te.CheckAccessLevel(rc.DeclContainer)) { Report.SymbolRelatedToPreviousError(te.Type); Expression.ErrorIsInaccesible(resolved.Location, resolved.GetSignatureForError()); } } return(resolved); }
static void Error_AmbiguousTypeReference(Location loc, string name, FullNamedExpression t1, FullNamedExpression t2) { Report.SymbolRelatedToPreviousError(t1.Type); Report.SymbolRelatedToPreviousError(t2.Type); Report.Error(104, loc, "`{0}' is an ambiguous reference between `{1}' and `{2}'", name, t1.GetSignatureForError(), t2.GetSignatureForError()); }
// <summary> // Resolve is used in method definitions // </summary> public virtual TypeSpec Resolve(IMemberContext rc, int index) { if (parameter_type != null) { return(parameter_type); } if (attributes != null) { attributes.AttachTo(this, rc); } parameter_type = texpr.ResolveAsType(rc); if (parameter_type == null) { return(null); } this.idx = index; if ((modFlags & Parameter.Modifier.RefOutMask) != 0 && parameter_type.IsSpecialRuntimeType) { rc.Module.Compiler.Report.Error(1601, Location, "Method or delegate parameter cannot be of type `{0}'", GetSignatureForError()); return(null); } TypeManager.CheckTypeVariance(parameter_type, (modFlags & Parameter.Modifier.RefOutMask) != 0 ? Variance.None : Variance.Contravariant, rc); if (parameter_type.IsStatic) { rc.Module.Compiler.Report.Error(721, Location, "`{0}': static types cannot be used as parameters", texpr.GetSignatureForError()); return(parameter_type); } if ((modFlags & Modifier.This) != 0 && (parameter_type.IsPointer || parameter_type.BuiltinType == BuiltinTypeSpec.Type.Dynamic)) { rc.Module.Compiler.Report.Error(1103, Location, "The extension method cannot be of type `{0}'", TypeManager.CSharpName(parameter_type)); } return(parameter_type); }
public static void Error_TypeArgumentsCannotBeUsed(FullNamedExpression expr, Location loc) { if (expr is TypeExpr) { Report.SymbolRelatedToPreviousError(expr.Type); Error_TypeArgumentsCannotBeUsed(loc, "type", expr.GetSignatureForError()); } else { expr.Error_ExpressionCannotBeGeneric(loc); } }
public virtual string GetSignatureForError() { string type_name; if (parameter_type != null) { type_name = TypeManager.CSharpName(parameter_type); } else { type_name = texpr.GetSignatureForError(); } string mod = GetModifierSignature(modFlags); if (mod.Length > 0) { return(String.Concat(mod, " ", type_name)); } return(type_name); }
/// <summary> /// This function computes the Base class and also the /// list of interfaces that the class or struct @c implements. /// /// The return value is an array (might be null) of /// interfaces implemented (as Types). /// /// The @base_class argument is set to the base object or null /// if this is `System.Object'. /// </summary> protected virtual TypeSpec[] ResolveBaseTypes (out FullNamedExpression base_class) { base_class = null; if (type_bases == null) return null; int count = type_bases.Count; TypeSpec[] ifaces = null; var base_context = new BaseContext (this); for (int i = 0, j = 0; i < count; i++){ FullNamedExpression fne = type_bases [i]; var fne_resolved = fne.ResolveAsType (base_context); if (fne_resolved == null) continue; if (i == 0 && Kind == MemberKind.Class && !fne_resolved.IsInterface) { if (fne_resolved.BuiltinType == BuiltinTypeSpec.Type.Dynamic) { Report.Error (1965, Location, "Class `{0}' cannot derive from the dynamic type", GetSignatureForError ()); continue; } base_type = fne_resolved; base_class = fne; continue; } if (ifaces == null) ifaces = new TypeSpec [count - i]; if (fne_resolved.IsInterface) { for (int ii = 0; ii < j; ++ii) { if (fne_resolved == ifaces [ii]) { Report.Error (528, Location, "`{0}' is already listed in interface list", fne_resolved.GetSignatureForError ()); break; } } if (Kind == MemberKind.Interface && !IsAccessibleAs (fne_resolved)) { Report.Error (61, fne.Location, "Inconsistent accessibility: base interface `{0}' is less accessible than interface `{1}'", fne_resolved.GetSignatureForError (), GetSignatureForError ()); } } else { Report.SymbolRelatedToPreviousError (fne_resolved); if (Kind != MemberKind.Class) { Report.Error (527, fne.Location, "Type `{0}' in interface list is not an interface", fne_resolved.GetSignatureForError ()); } else if (base_class != null) Report.Error (1721, fne.Location, "`{0}': Classes cannot have multiple base classes (`{1}' and `{2}')", GetSignatureForError (), base_class.GetSignatureForError (), fne_resolved.GetSignatureForError ()); else { Report.Error (1722, fne.Location, "`{0}': Base class `{1}' must be specified as first", GetSignatureForError (), fne_resolved.GetSignatureForError ()); } } ifaces [j++] = fne_resolved; } return ifaces; }
void Error_AmbiguousReference(string name, FullNamedExpression a, FullNamedExpression b, Location loc) { var report = Compiler.Report; report.SymbolRelatedToPreviousError (a.Type); report.SymbolRelatedToPreviousError (b.Type); report.Error (104, loc, "`{0}' is an ambiguous reference between `{1}' and `{2}'", name, a.GetSignatureForError (), b.GetSignatureForError ()); }
// // Processes "see" or "seealso" elements from cref attribute. // void HandleXrefCommon(MemberCore mc, XmlElement xref) { string cref = xref.GetAttribute("cref"); // when, XmlReader, "if (cref == null)" if (!xref.HasAttribute("cref")) { return; } // Nothing to be resolved the reference is marked explicitly if (cref.Length > 2 && cref [1] == ':') { return; } // Additional symbols for < and > are allowed for easier XML typing cref = cref.Replace('{', '<').Replace('}', '>'); var encoding = module.Compiler.Settings.Encoding; var s = new MemoryStream(encoding.GetBytes(cref)); var source_file = new CompilationSourceFile(doc_module, mc.Location.SourceFile); var report = new Report(doc_module.Compiler, new NullReportPrinter()); if (session == null) { session = new ParserSession { UseJayGlobalArrays = true } } ; SeekableStreamReader seekable = new SeekableStreamReader(s, encoding, session.StreamReaderBuffer); var parser = new CSharpParser(seekable, source_file, report, session); ParsedParameters = null; ParsedName = null; ParsedBuiltinType = null; ParsedOperator = null; parser.Lexer.putback_char = Tokenizer.DocumentationXref; parser.Lexer.parsing_generic_declaration_doc = true; parser.parse(); if (report.Errors > 0) { Report.Warning(1584, 1, mc.Location, "XML comment on `{0}' has syntactically incorrect cref attribute `{1}'", mc.GetSignatureForError(), cref); xref.SetAttribute("cref", "!:" + cref); return; } MemberSpec member; string prefix = null; FullNamedExpression fne = null; // // Try built-in type first because we are using ParsedName as identifier of // member names on built-in types // if (ParsedBuiltinType != null && (ParsedParameters == null || ParsedName != null)) { member = ParsedBuiltinType.Type; } else { member = null; } if (ParsedName != null || ParsedOperator.HasValue) { TypeSpec type = null; string member_name = null; if (member == null) { if (ParsedOperator.HasValue) { type = mc.CurrentType; } else if (ParsedName.Left != null) { fne = ResolveMemberName(mc, ParsedName.Left); if (fne != null) { var ns = fne as NamespaceExpression; if (ns != null) { fne = ns.LookupTypeOrNamespace(mc, ParsedName.Name, ParsedName.Arity, LookupMode.Probing, Location.Null); if (fne != null) { member = fne.Type; } } else { type = fne.Type; } } } else { fne = ResolveMemberName(mc, ParsedName); if (fne == null) { type = mc.CurrentType; } else if (ParsedParameters == null) { member = fne.Type; } else if (fne.Type.MemberDefinition == mc.CurrentType.MemberDefinition) { member_name = Constructor.ConstructorName; type = fne.Type; } } } else { type = (TypeSpec)member; member = null; } if (ParsedParameters != null) { var old_printer = mc.Module.Compiler.Report.SetPrinter(new NullReportPrinter()); try { var context = new DocumentationMemberContext(mc, ParsedName ?? MemberName.Null); foreach (var pp in ParsedParameters) { pp.Resolve(context); } } finally { mc.Module.Compiler.Report.SetPrinter(old_printer); } } if (type != null) { if (member_name == null) { member_name = ParsedOperator.HasValue ? Operator.GetMetadataName(ParsedOperator.Value) : ParsedName.Name; } int parsed_param_count; if (ParsedOperator == Operator.OpType.Explicit || ParsedOperator == Operator.OpType.Implicit) { parsed_param_count = ParsedParameters.Count - 1; } else if (ParsedParameters != null) { parsed_param_count = ParsedParameters.Count; } else { parsed_param_count = 0; } int parameters_match = -1; do { var members = MemberCache.FindMembers(type, member_name, true); if (members != null) { foreach (var m in members) { if (ParsedName != null && m.Arity != ParsedName.Arity) { continue; } if (ParsedParameters != null) { IParametersMember pm = m as IParametersMember; if (pm == null) { continue; } if (m.Kind == MemberKind.Operator && !ParsedOperator.HasValue) { continue; } var pm_params = pm.Parameters; int i; for (i = 0; i < parsed_param_count; ++i) { var pparam = ParsedParameters[i]; if (i >= pm_params.Count || pparam == null || pparam.TypeSpec == null || !TypeSpecComparer.Override.IsEqual(pparam.TypeSpec, pm_params.Types[i]) || (pparam.Modifier & Parameter.Modifier.RefOutMask) != (pm_params.FixedParameters[i].ModFlags & Parameter.Modifier.RefOutMask)) { if (i > parameters_match) { parameters_match = i; } i = -1; break; } } if (i < 0) { continue; } if (ParsedOperator == Operator.OpType.Explicit || ParsedOperator == Operator.OpType.Implicit) { if (pm.MemberType != ParsedParameters[parsed_param_count].TypeSpec) { parameters_match = parsed_param_count + 1; continue; } } else { if (parsed_param_count != pm_params.Count) { continue; } } } if (member != null) { Report.Warning(419, 3, mc.Location, "Ambiguous reference in cref attribute `{0}'. Assuming `{1}' but other overloads including `{2}' have also matched", cref, member.GetSignatureForError(), m.GetSignatureForError()); break; } member = m; } } // Continue with parent type for nested types if (member == null) { type = type.DeclaringType; } else { type = null; } } while (type != null); if (member == null && parameters_match >= 0) { for (int i = parameters_match; i < parsed_param_count; ++i) { Report.Warning(1580, 1, mc.Location, "Invalid type for parameter `{0}' in XML comment cref attribute `{1}'", (i + 1).ToString(), cref); } if (parameters_match == parsed_param_count + 1) { Report.Warning(1581, 1, mc.Location, "Invalid return type in XML comment cref attribute `{0}'", cref); } } } } if (member == null) { Report.Warning(1574, 1, mc.Location, "XML comment on `{0}' has cref attribute `{1}' that could not be resolved", mc.GetSignatureForError(), cref); cref = "!:" + cref; } else if (member == InternalType.Namespace) { cref = "N:" + fne.GetSignatureForError(); } else { prefix = GetMemberDocHead(member); cref = prefix + member.GetSignatureForDocumentation(); } xref.SetAttribute("cref", cref); }
public static void Error_TypeArgumentsCannotBeUsed (FullNamedExpression expr, Location loc) { if (expr is TypeExpr) { RootContext.ToplevelTypes.Compiler.Report.SymbolRelatedToPreviousError (expr.Type); Error_TypeArgumentsCannotBeUsed (loc, "type", expr.GetSignatureForError ()); } else { RootContext.ToplevelTypes.Compiler.Report.Error (307, loc, "The {0} `{1}' cannot be used with type arguments", expr.ExprClassName, expr.GetSignatureForError ()); } }
void Error_AmbiguousTypeReference (Location loc, string name, FullNamedExpression t1, FullNamedExpression t2) { Compiler.Report.SymbolRelatedToPreviousError (t1.Type); Compiler.Report.SymbolRelatedToPreviousError (t2.Type); Compiler.Report.Error (104, loc, "`{0}' is an ambiguous reference between `{1}' and `{2}'", name, t1.GetSignatureForError (), t2.GetSignatureForError ()); }
// <summary> // Resolve is used in method definitions // </summary> public virtual TypeSpec Resolve (IMemberContext rc, int index) { if (parameter_type != null) return parameter_type; if (attributes != null) attributes.AttachTo (this, rc); var expr = texpr.ResolveAsTypeTerminal (rc, false); if (expr == null) return null; this.idx = index; texpr = expr; parameter_type = texpr.Type; if ((modFlags & Parameter.Modifier.ISBYREF) != 0 && TypeManager.IsSpecialType (parameter_type)) { rc.Compiler.Report.Error (1601, Location, "Method or delegate parameter cannot be of type `{0}'", GetSignatureForError ()); return null; } TypeManager.CheckTypeVariance (parameter_type, (modFlags & Parameter.Modifier.ISBYREF) != 0 ? Variance.None : Variance.Contravariant, rc); if (parameter_type.IsStatic) { rc.Compiler.Report.Error (721, Location, "`{0}': static types cannot be used as parameters", texpr.GetSignatureForError ()); return parameter_type; } if ((modFlags & Modifier.This) != 0 && (parameter_type.IsPointer || parameter_type == InternalType.Dynamic)) { rc.Compiler.Report.Error (1103, Location, "The extension method cannot be of type `{0}'", TypeManager.CSharpName (parameter_type)); } return parameter_type; }
protected virtual void Error_IdentifierNotFound (IMemberContext rc, FullNamedExpression expr_type, string identifier) { Expression member_lookup = MemberLookup (rc.Compiler, rc.CurrentType, expr_type.Type, expr_type.Type, SimpleName.RemoveGenericArity (identifier), MemberTypes.NestedType, BindingFlags.Public | BindingFlags.NonPublic, loc); if (member_lookup != null) { expr_type = member_lookup.ResolveAsTypeTerminal (rc, false); if (expr_type == null) return; Namespace.Error_TypeArgumentsCannotBeUsed (expr_type, loc); return; } member_lookup = MemberLookup (rc.Compiler, rc.CurrentType, expr_type.Type, expr_type.Type, identifier, MemberTypes.All, BindingFlags.Public | BindingFlags.NonPublic, loc); if (member_lookup == null) { rc.Compiler.Report.Error (426, loc, "The nested type `{0}' does not exist in the type `{1}'", Name, expr_type.GetSignatureForError ()); } else { // TODO: Report.SymbolRelatedToPreviousError member_lookup.Error_UnexpectedKind (rc.Compiler.Report, null, "type", loc); } }
public override FullNamedExpression Resolve (IResolveContext rc) { if (resolved != null || value == null) return resolved; resolved = value.GetTypeExpression ().ResolveAsTypeStep (rc, false); if (resolved == null) { value = null; return null; } TypeExpr te = resolved as TypeExpr; if (te != null) { if (!te.CheckAccessLevel (rc.DeclContainer)) { Report.SymbolRelatedToPreviousError (te.Type); Expression.ErrorIsInaccesible (resolved.Location, resolved.GetSignatureForError ()); } } return resolved; }
public static void Error_TypeArgumentsCannotBeUsed (FullNamedExpression expr, Location loc) { if (expr is TypeExpr) { Report.SymbolRelatedToPreviousError (expr.Type); Error_TypeArgumentsCannotBeUsed (loc, "type", expr.GetSignatureForError ()); } else { expr.Error_ExpressionCannotBeGeneric (loc); } }