protected AbstractMessage(AbstractMessage aMsg) { this.code = aMsg.code; this.location = aMsg.location; this.message = aMsg.message; this.extra_info = aMsg.extra_info; }
public void FeatureIsNotAvailable (CompilerContext compiler, Location loc, string feature) { string version; switch (compiler.Settings.Version) { case LanguageVersion.ISO_1: version = "1.0"; break; case LanguageVersion.ISO_2: version = "2.0"; break; case LanguageVersion.V_3: version = "3.0"; break; case LanguageVersion.V_4: version = "4.0"; break; case LanguageVersion.V_5: version = "5.0"; break; default: throw new InternalErrorException ("Invalid feature version", compiler.Settings.Version); } Error (1644, loc, "Feature `{0}' cannot be used because it is not part of the C# {1} language specification", feature, version); }
public static TypeSpec CreateDelegateType (ResolveContext rc, AParametersCollection parameters, TypeSpec returnType, Location loc) { Namespace type_ns = rc.Module.GlobalRootNamespace.GetNamespace ("System", true); if (type_ns == null) { return null; } if (returnType == rc.BuiltinTypes.Void) { var actArgs = parameters.Types; var actionSpec = type_ns.LookupType (rc.Module, "Action", actArgs.Length, LookupMode.Normal, loc).ResolveAsType(rc); if (actionSpec == null) { return null; } if (actArgs.Length == 0) return actionSpec; else return actionSpec.MakeGenericType(rc, actArgs); } else { TypeSpec[] funcArgs = new TypeSpec[parameters.Types.Length + 1]; parameters.Types.CopyTo(funcArgs, 0); funcArgs[parameters.Types.Length] = returnType; var funcSpec = type_ns.LookupType (rc.Module, "Func", funcArgs.Length, LookupMode.Normal, loc).ResolveAsType(rc); if (funcSpec == null) return null; return funcSpec.MakeGenericType(rc, funcArgs); } }
public static FlowBranching CreateBranching (FlowBranching parent, BranchingType type, Block block, Location loc) { switch (type) { case BranchingType.Exception: case BranchingType.Labeled: case BranchingType.Toplevel: case BranchingType.TryCatch: throw new InvalidOperationException (); case BranchingType.Switch: return new FlowBranchingBreakable (parent, type, SiblingType.SwitchSection, block, loc); case BranchingType.Block: return new FlowBranchingBlock (parent, type, SiblingType.Block, block, loc); case BranchingType.Loop: return new FlowBranchingBreakable (parent, type, SiblingType.Conditional, block, loc); case BranchingType.Embedded: return new FlowBranchingContinuable (parent, type, SiblingType.Conditional, block, loc); default: return new FlowBranchingBlock (parent, type, SiblingType.Conditional, block, loc); } }
public FieldSpec DefineInitializedData (byte[] data, Location loc) { Struct size_type; if (!size_types.TryGetValue (data.Length, out size_type)) { // // Build common type for this data length. We cannot use // DefineInitializedData because it creates public type, // and its name is not unique among modules // size_type = new Struct (this, new MemberName ("$ArrayType=" + data.Length, loc), Modifiers.PRIVATE | Modifiers.COMPILER_GENERATED, null); size_type.CreateContainer (); size_type.DefineContainer (); size_types.Add (data.Length, size_type); // It has to work even if StructLayoutAttribute does not exist size_type.TypeBuilder.__SetLayout (1, data.Length); } var name = "$field-" + fields.ToString ("X"); ++fields; const Modifiers fmod = Modifiers.STATIC | Modifiers.INTERNAL; var fbuilder = TypeBuilder.DefineField (name, size_type.CurrentType.GetMetaInfo (), ModifiersExtensions.FieldAttr (fmod) | FieldAttributes.HasFieldRVA); fbuilder.__SetDataAndRVA (data); return new FieldSpec (CurrentType, null, size_type.CurrentType, fbuilder, fmod); }
public DynamicTypeExpr (Location loc) { this.loc = loc; type = InternalType.Dynamic; eclass = ExprClass.Type; }
public virtual Type LookupTypeReflection (CompilerContext ctx, string name, Location loc, bool must_be_unique) { Type found_type = null; foreach (Assembly a in referenced_assemblies) { Type t = GetTypeInAssembly (a, name); if (t == null) continue; if (!must_be_unique) return t; if (found_type == null) { found_type = t; continue; } // When type is forwarded if (t.Assembly == found_type.Assembly) continue; ctx.Report.SymbolRelatedToPreviousError (found_type); ctx.Report.SymbolRelatedToPreviousError (t); if (loc.IsNull) { Error_AmbiguousPredefinedType (ctx, loc, name, found_type); } else { ctx.Report.Error (433, loc, "The imported type `{0}' is defined multiple times", name); } return found_type; } return found_type; }
public MemberName (string name, TypeParameters tparams, Location loc) { this.Name = name; this.Location = loc; this.TypeParameters = tparams; }
private MemberName (MemberName left, string name, bool is_double_colon, TypeArguments args, Location loc) : this (left, name, is_double_colon, loc) { if (args != null && args.Count > 0) this.TypeArguments = args; }
/// <summary> /// Performs an explicit conversion of the expression `expr' whose /// type is expr.Type to `target_type'. /// </summary> public static Expression ExplicitConversion(ResolveContext ec, Expression expr, TypeSpec target_type, Location loc) { Expression e = ExplicitConversionCore (ec, expr, target_type, loc); if (e != null) { // // Don't eliminate explicit precission casts // if (e == expr) { if (target_type.BuiltinType == BuiltinTypeSpec.Type.Float) return new OpcodeCast (expr, target_type, OpCodes.Conv_R4); if (target_type.BuiltinType == BuiltinTypeSpec.Type.Double) return new OpcodeCast (expr, target_type, OpCodes.Conv_R8); } return e; } TypeSpec expr_type = expr.Type; if (target_type.IsNullableType) { TypeSpec target; if (expr_type.IsNullableType) { target = Nullable.NullableInfo.GetUnderlyingType (target_type); Expression unwrap = Nullable.Unwrap.Create (expr); e = ExplicitConversion (ec, unwrap, target, expr.Location); if (e == null) return null; return new Nullable.LiftedConversion (e, unwrap, target_type).Resolve (ec); } if (expr_type.BuiltinType == BuiltinTypeSpec.Type.Object) { return new UnboxCast (expr, target_type); } target = TypeManager.GetTypeArguments (target_type) [0]; e = ExplicitConversionCore (ec, expr, target, loc); if (e != null) return TypeSpec.IsReferenceType (expr.Type) ? new UnboxCast (expr, target_type) : Nullable.Wrap.Create (e, target_type); } else if (expr_type.IsNullableType) { e = ImplicitBoxingConversion (expr, Nullable.NullableInfo.GetUnderlyingType (expr_type), target_type); if (e != null) return e; e = Nullable.Unwrap.Create (expr, false); e = ExplicitConversionCore (ec, e, target_type, loc); if (e != null) return EmptyCast.Create (e, target_type); } e = ExplicitUserConversion (ec, expr, target_type, loc); if (e != null) return e; expr.Error_ValueCannotBeConverted (ec, target_type, true); return null; }
public Accessor(ToplevelBlock b, Modifiers mod, Attributes attrs, ParametersCompiled p, Location loc) { Block = b; Attributes = attrs; Location = loc; Parameters = p; ModFlags = ModifiersExtensions.Check (AllowedModifiers, mod, 0, loc, RootContext.ToplevelTypes.Compiler.Report); }
public MemberName (string name, TypeArguments args, Location loc) { this.Name = name; this.Location = loc; if (args != null && args.Count > 0) this.TypeArguments = args; }
public BoolConstant(TypeSpec type, bool val, Location loc) : base(loc) { eclass = ExprClass.Value; this.type = type; Value = val; }
public Const (DeclSpace parent, FullNamedExpression type, string name, Expression expr, int mod_flags, Attributes attrs, Location loc) : base (parent, type, mod_flags, AllowedModifiers, new MemberName (name, loc), attrs) { initializer = expr; ModFlags |= Modifiers.STATIC; }
private MemberName (MemberName left, string name, bool is_double_colon, Location loc) { this.Name = name; this.Location = loc; this.is_double_colon = is_double_colon; this.Left = left; }
public Constant ImplicitConversionRequired (ResolveContext ec, TypeSpec type, Location loc) { Constant c = ConvertImplicitly (type); if (c == null) Error_ValueCannotBeConverted (ec, type, false); return c; }
public EnumMember (Enum parent, EnumMember prev_member, string name, Expression expr, Attributes attrs, Location loc) : base (parent, new EnumTypeExpr (parent), name, expr, Modifiers.PUBLIC, attrs, loc) { this.ParentEnum = parent; this.ValueExpr = expr; this.prev_member = prev_member; }
public StaticCallExpr (MethodInfo m, ArrayList a, Location l) { mi = m; args = a; type = m.ReturnType; eclass = ExprClass.Value; loc = l; }
public ReturnParameter (MethodBuilder mb, Location location) { try { builder = mb.DefineParameter (0, ParameterAttributes.None, ""); } catch (ArgumentOutOfRangeException) { RootContext.ToplevelTypes.Compiler.Report.RuntimeMissingSupport (location, "custom attributes on the return type"); } }
/// <summary> /// Performs an explicit conversion of the expression `expr' whose /// type is expr.Type to `target_type'. /// </summary> public static Expression ExplicitConversion(ResolveContext ec, Expression expr, TypeSpec target_type, Location loc) { Expression e = ExplicitConversionCore (ec, expr, target_type, loc); if (e != null) { // // Don't eliminate explicit precission casts // if (e == expr) { if (target_type == TypeManager.float_type) return new OpcodeCast (expr, target_type, OpCodes.Conv_R4); if (target_type == TypeManager.double_type) return new OpcodeCast (expr, target_type, OpCodes.Conv_R8); } return e; } TypeSpec expr_type = expr.Type; if (TypeManager.IsNullableType (target_type)) { if (TypeManager.IsNullableType (expr_type)) { TypeSpec target = Nullable.NullableInfo.GetUnderlyingType (target_type); Expression unwrap = Nullable.Unwrap.Create (expr); e = ExplicitConversion (ec, unwrap, target, expr.Location); if (e == null) return null; return new Nullable.Lifted (e, unwrap, target_type).Resolve (ec); } else if (expr_type == TypeManager.object_type) { return new UnboxCast (expr, target_type); } else { TypeSpec target = TypeManager.GetTypeArguments (target_type) [0]; e = ExplicitConversionCore (ec, expr, target, loc); if (e != null) return Nullable.Wrap.Create (e, target_type); } } else if (TypeManager.IsNullableType (expr_type)) { bool use_class_cast; if (ImplicitBoxingConversionExists (Nullable.NullableInfo.GetUnderlyingType (expr_type), target_type, out use_class_cast)) return new BoxedCast (expr, target_type); e = Nullable.Unwrap.Create (expr, false); e = ExplicitConversionCore (ec, e, target_type, loc); if (e != null) return EmptyCast.Create (e, target_type); } e = ExplicitUserConversion (ec, expr, target_type, loc); if (e != null) return e; expr.Error_ValueCannotBeConverted (ec, loc, target_type, true); return null; }
// TODO: merge method and mb public ReturnParameter (MemberCore method, MethodBuilder mb, Location location) { this.method = method; try { builder = mb.DefineParameter (0, ParameterAttributes.None, ""); } catch (ArgumentOutOfRangeException) { method.Compiler.Report.RuntimeMissingSupport (location, "custom attributes on the return type"); } }
public static void Error_InvalidConstantType(TypeSpec t, Location loc, Report Report) { if (t.IsGenericParameter) { Report.Error (1959, loc, "Type parameter `{0}' cannot be declared const", TypeManager.CSharpName (t)); } else { Report.Error (283, loc, "The type `{0}' cannot be declared const", TypeManager.CSharpName (t)); } }
public ReturnParameter (MethodBuilder mb, Location location): base (null) { try { builder = mb.DefineParameter (0, ParameterAttributes.None, ""); } catch (ArgumentOutOfRangeException) { Report.RuntimeMissingSupport (location, "custom attributes on the return type"); } }
public UserOperatorCall (MethodGroupExpr mg, Arguments args, ExpressionTreeExpression expr_tree, Location loc) { this.mg = mg; this.arguments = args; this.expr_tree = expr_tree; type = TypeManager.TypeToCoreType (((MethodInfo) mg).ReturnType); eclass = ExprClass.Value; this.loc = loc; }
public Const(DeclSpace parent, FullNamedExpression type, string name, Expression expr, Modifiers mod_flags, Attributes attrs, Location loc) : base(parent, type, mod_flags, AllowedModifiers, new MemberName (name, loc), attrs) { if (expr != null) initializer = new ConstInitializer (this, expr); ModFlags |= Modifiers.STATIC; }
public override void Error_ValueCannotBeConverted (ResolveContext ec, Location loc, TypeSpec target, bool expl) { if (!expl && IsLiteral && (TypeManager.IsPrimitiveType (target) || type == TypeManager.decimal_type) && (TypeManager.IsPrimitiveType (type) || type == TypeManager.decimal_type)) { ec.Report.Error (31, loc, "Constant value `{0}' cannot be converted to a `{1}'", AsString (), TypeManager.CSharpName (target)); } else { base.Error_ValueCannotBeConverted (ec, loc, target, expl); } }
public static bool CheckContext (ResolveContext ec, Location loc) { if (!ec.CurrentAnonymousMethod.IsIterator) { ec.Report.Error (1621, loc, "The yield statement cannot be used inside " + "anonymous method blocks"); return false; } return true; }
public override void Error_ValueCannotBeConverted (EmitContext ec, Location loc, Type t, bool expl) { if (TypeManager.IsGenericParameter (t)) { Report.Error(403, loc, "Cannot convert null to the type parameter `{0}' because it could be a value " + "type. Consider using `default ({0})' instead", t.Name); } else { Report.Error(37, loc, "Cannot convert null to `{0}' because it is a value type", TypeManager.CSharpName(t)); } }
protected AbstractMessage(int code, Location loc, string msg, List<string> extraInfo) { this.code = code; if (code < 0) this.code = 8000 - code; this.location = loc; this.message = msg; if (extraInfo.Count != 0) { this.extra_info = extraInfo.ToArray (); } }
// // Makes const data field inside internal type container // public FieldSpec MakeStaticData(byte[] data, Location loc) { if (static_data == null) { static_data = new StaticDataContainer (this); static_data.CreateContainer (); static_data.DefineContainer (); AddCompilerGeneratedClass (static_data); } return static_data.DefineInitializedData (data, loc); }
public SimpleAssign(Expression target, Expression source, Location loc) : base(target, source, loc) { }
public WarningMessage(int code, Location loc, string message, List <string> extra_info) : base(code, loc, message, extra_info) { }
public ImplicitDelegateCreation(TypeSpec delegateType, MethodGroupExpr mg, Location loc) { type = delegateType; this.method_group = mg; this.loc = loc; }
public DelegateInvocation(Expression instance_expr, Arguments args, bool conditionalAccessReceiver, Location loc) { this.InstanceExpr = instance_expr; this.arguments = args; this.conditionalAccessReceiver = conditionalAccessReceiver; this.loc = loc; }
public Compiler.FullNamedExpression LookupNamespaceOrType(string name, int arity, Mono.CSharp.LookupMode mode, bool absolute_ns, Mono.CSharp.Location loc) { throw new NotImplementedException(); }
public void Error(int code, Location loc, string format, params string[] args) { Error(code, loc, String.Format(format, args)); }
public void RuntimeMissingSupport(Location loc, string feature) { Error(-88, loc, "Your .NET Runtime does not support `{0}'. Please use the latest Mono runtime instead.", feature); }
public ArrayInitializer CreateDynamicBinderArguments(ResolveContext rc) { Location loc = Location.Null; var all = new ArrayInitializer(args.Count, loc); MemberAccess binder = DynamicExpressionStatement.GetBinderNamespace(loc); foreach (Argument a in args) { Arguments dargs = new Arguments(2); // CSharpArgumentInfoFlags.None = 0 const string info_flags_enum = "CSharpArgumentInfoFlags"; Expression info_flags = new IntLiteral(rc.BuiltinTypes, 0, loc); if (a.Expr is Constant) { info_flags = new Binary(Binary.Operator.BitwiseOr, info_flags, new MemberAccess(new MemberAccess(binder, info_flags_enum, loc), "Constant", loc)); } else if (a.ArgType == Argument.AType.Ref) { info_flags = new Binary(Binary.Operator.BitwiseOr, info_flags, new MemberAccess(new MemberAccess(binder, info_flags_enum, loc), "IsRef", loc)); info_flags = new Binary(Binary.Operator.BitwiseOr, info_flags, new MemberAccess(new MemberAccess(binder, info_flags_enum, loc), "UseCompileTimeType", loc)); } else if (a.ArgType == Argument.AType.Out) { info_flags = new Binary(Binary.Operator.BitwiseOr, info_flags, new MemberAccess(new MemberAccess(binder, info_flags_enum, loc), "IsOut", loc)); info_flags = new Binary(Binary.Operator.BitwiseOr, info_flags, new MemberAccess(new MemberAccess(binder, info_flags_enum, loc), "UseCompileTimeType", loc)); } else if (a.ArgType == Argument.AType.DynamicTypeName) { info_flags = new Binary(Binary.Operator.BitwiseOr, info_flags, new MemberAccess(new MemberAccess(binder, info_flags_enum, loc), "IsStaticType", loc)); } var arg_type = a.Expr.Type; if (arg_type.BuiltinType != BuiltinTypeSpec.Type.Dynamic && arg_type != InternalType.NullLiteral) { MethodGroupExpr mg = a.Expr as MethodGroupExpr; if (mg != null) { rc.Report.Error(1976, a.Expr.Location, "The method group `{0}' cannot be used as an argument of dynamic operation. Consider using parentheses to invoke the method", mg.Name); } else if (arg_type == InternalType.AnonymousMethod) { rc.Report.Error(1977, a.Expr.Location, "An anonymous method or lambda expression cannot be used as an argument of dynamic operation. Consider using a cast"); } else if (arg_type.Kind == MemberKind.Void || arg_type == InternalType.Arglist || arg_type.IsPointer) { rc.Report.Error(1978, a.Expr.Location, "An expression of type `{0}' cannot be used as an argument of dynamic operation", arg_type.GetSignatureForError()); } info_flags = new Binary(Binary.Operator.BitwiseOr, info_flags, new MemberAccess(new MemberAccess(binder, info_flags_enum, loc), "UseCompileTimeType", loc)); } string named_value; NamedArgument na = a as NamedArgument; if (na != null) { info_flags = new Binary(Binary.Operator.BitwiseOr, info_flags, new MemberAccess(new MemberAccess(binder, info_flags_enum, loc), "NamedArgument", loc)); named_value = na.Name; } else { named_value = null; } dargs.Add(new Argument(info_flags)); dargs.Add(new Argument(new StringLiteral(rc.BuiltinTypes, named_value, loc))); all.Add(new Invocation(new MemberAccess(new MemberAccess(binder, "CSharpArgumentInfo", loc), "Create", loc), dargs)); } return(all); }
public void FeatureIsNotSupported(Location loc, string feature) { Error(1644, loc, "Feature `{0}' is not supported in Mono mcs1 compiler. Consider using the `gmcs' compiler instead", feature); }
public void Warning(int code, int level, Location loc, string format, string arg1, string arg2) { Warning(code, level, loc, String.Format(format, arg1, arg2)); }
public Compiler.FullNamedExpression LookupNamespaceOrType(string name, Mono.CSharp.Location loc, bool ignore_cs0104) { throw new NotImplementedException(); }
public Compiler.ExtensionMethodGroupExpr LookupExtensionMethod(Type extensionType, string name, Mono.CSharp.Location loc) { throw new NotImplementedException(); }
public InternalErrorException(Exception e, Location loc) : base(loc.ToString(), e) { }
public override void SetAlgorithmId (uint value, Location loc) { builder.__SetAssemblyAlgorithmId ((AssemblyHashAlgorithm) value); }
public bool CheckWarningCode(string code, Location loc) { Warning(1691, 1, loc, "`{0}' is not a valid warning number", code); return(false); }
public override void AddTypeForwarder (TypeSpec type, Location loc) { builder.__AddTypeForwarder (type.GetMetaInfo ()); }
public void Error(int code, Location loc, string format, string arg1, string arg2) { Error(code, loc, String.Format(format, arg1, arg2)); }
public NamedArgument(string name, Location loc, Expression expr, AType modifier) : base(expr, modifier) { this.Name = name; this.loc = loc; }
public override void SetVersion (Version version, Location loc) { builder.__SetAssemblyVersion (version); }
public NamedArgument(string name, Location loc, Expression expr) : this(name, loc, expr, AType.None) { }
public ErrorMessage(int code, Location loc, string message, List <string> extraInfo) : base(code, loc, message, extraInfo) { }
// // This constructor is invoked from the `New' expression // public NewDelegate(TypeSpec type, Arguments Arguments, Location loc) { this.type = type; this.Arguments = Arguments; this.loc = loc; }
public override void SetFlags (uint flags, Location loc) { builder.__SetAssemblyFlags ((AssemblyNameFlags) flags); }
public static Arguments CreateDelegateMethodArguments(ResolveContext rc, AParametersCollection pd, TypeSpec[] types, Location loc) { Arguments delegate_arguments = new Arguments(pd.Count); for (int i = 0; i < pd.Count; ++i) { Argument.AType atype_modifier; switch (pd.FixedParameters [i].ModFlags & Parameter.Modifier.RefOutMask) { case Parameter.Modifier.REF: atype_modifier = Argument.AType.Ref; break; case Parameter.Modifier.OUT: atype_modifier = Argument.AType.Out; break; default: atype_modifier = 0; break; } var ptype = types[i]; if (ptype.BuiltinType == BuiltinTypeSpec.Type.Dynamic) { ptype = rc.BuiltinTypes.Object; } delegate_arguments.Add(new Argument(new TypeExpression(ptype, loc), atype_modifier)); } return(delegate_arguments); }
public override void SetCulture (string culture, Location loc) { builder.__SetAssemblyCulture (culture); }
public void Warning(int code, int level, Location loc, string format, params object[] args) { Warning(code, level, loc, String.Format(format, args)); }
public void ExtraInformation(Location loc, string msg) { extra_information.Add(String.Format("{0} {1}", loc, msg)); }
protected Assign(Expression target, Expression source, Location loc) { this.target = target; this.source = source; this.loc = loc; }
/// <summary> /// In most error cases is very useful to have information about symbol that caused the error. /// Call this method before you call Report.Error when it makes sense. /// </summary> public void SymbolRelatedToPreviousError(Location loc, string symbol) { SymbolRelatedToPreviousError(loc.ToString()); }