public abstract class CompilerGeneratedClass : Class
{
- protected CompilerGeneratedClass (DeclSpace parent, MemberName name, Modifiers mod)
+ protected CompilerGeneratedClass (TypeContainer parent, MemberName name, Modifiers mod)
: base (parent.NamespaceEntry, parent, name, mod | Modifiers.COMPILER_GENERATED, null)
{
}
protected TypeParameterMutator mutator;
- public HoistedStoreyClass (DeclSpace parent, MemberName name, TypeParameter[] tparams, Modifiers mod)
+ public HoistedStoreyClass (TypeContainer parent, MemberName name, TypeParameter[] tparams, Modifiers mod)
: base (parent, name, mod | Modifiers.PRIVATE)
{
if (tparams != null) {
// A copy is not enough, inflate any type parameter constraints
// using a new type parameters
- var inflator = new TypeParameterInflator (null, src, dst);
+ var inflator = new TypeParameterInflator (this, null, src, dst);
for (int i = 0; i < type_params.Length; ++i) {
src[i].InflateConstraints (inflator, dst[i]);
}
+
+ mutator = new TypeParameterMutator (tparams, type_params);
}
}
: base (parent, MakeMemberName (host, name, unique_id, tparams, block.StartLocation),
tparams, Modifiers.SEALED)
{
- Parent = parent;
OriginalSourceBlock = block;
ID = unique_id++;
}
// Inflated type instance has to be updated manually
if (Instance.Type is InflatedTypeSpec) {
- var inflator = new TypeParameterInflator (Instance.Type, TypeParameterSpec.EmptyTypes, TypeSpec.EmptyTypes);
+ var inflator = new TypeParameterInflator (this, Instance.Type, TypeParameterSpec.EmptyTypes, TypeSpec.EmptyTypes);
Instance.Type.MemberCache.AddMember (f.Spec.InflateMember (inflator));
- inflator = new TypeParameterInflator (f.Parent.CurrentType, TypeParameterSpec.EmptyTypes, TypeSpec.EmptyTypes);
+ inflator = new TypeParameterInflator (this, f.Parent.CurrentType, TypeParameterSpec.EmptyTypes, TypeSpec.EmptyTypes);
f.Parent.CurrentType.MemberCache.AddMember (f.Spec.InflateMember (inflator));
}
}
public override Expression CreateExpressionTree (ResolveContext ec)
{
- throw new NotSupportedException ("ET");
+ return hv.CreateExpressionTree ();
}
protected override Expression DoResolve (ResolveContext ec)
{
eclass = ExprClass.Value;
- type = ec.Module.PredefinedTypes.Expression.Resolve (Location);
+ type = ec.Module.PredefinedTypes.Expression.Resolve ();
return this;
}
if (delegate_type.IsDelegate)
return delegate_type;
- if (delegate_type.IsGeneric && delegate_type.GetDefinition () == TypeManager.expression_type) {
+ if (delegate_type.IsExpressionTreeType) {
delegate_type = delegate_type.TypeArguments [0];
if (delegate_type.IsDelegate)
return delegate_type;
return false;
if (!delegate_type.IsDelegate) {
- if (delegate_type.GetDefinition () != TypeManager.expression_type)
+ if (!delegate_type.IsExpressionTreeType)
return false;
delegate_type = TypeManager.GetTypeArguments (delegate_type) [0];
return false;
}
- AParametersCollection d_params = Delegate.GetParameters (ec.Compiler, delegate_type);
+ AParametersCollection d_params = Delegate.GetParameters (delegate_type);
if (d_params.Count != Parameters.Count)
return false;
// needed for the anonymous method. We create the method here.
//
- var invoke_mb = Delegate.GetInvokeMethod (ec.Compiler, delegate_type);
+ var invoke_mb = Delegate.GetInvokeMethod (delegate_type);
TypeSpec return_type = invoke_mb.ReturnType;
//
protected virtual ParametersCompiled ResolveParameters (ResolveContext ec, TypeInferenceContext tic, TypeSpec delegate_type)
{
- var delegate_parameters = Delegate.GetParameters (ec.Compiler, delegate_type);
+ var delegate_parameters = Delegate.GetParameters (delegate_type);
if (Parameters == ParametersCompiled.Undefined) {
//
public static void Error_AddressOfCapturedVar (ResolveContext ec, IVariableReference var, Location loc)
{
ec.Report.Error (1686, loc,
- "Local variable or parameter `{0}' cannot have their address taken and be used inside an anonymous method or lambda expression",
+ "Local variable or parameter `{0}' cannot have their address taken and be used inside an anonymous method, lambda expression or query expression",
var.Name);
}
var hoisted_tparams = ec.CurrentTypeParameters;
var type_params = new TypeParameter[hoisted_tparams.Length];
for (int i = 0; i < type_params.Length; ++i) {
- type_params[i] = hoisted_tparams[i].CreateHoistedCopy (null, null);
+ type_params[i] = hoisted_tparams[i].CreateHoistedCopy (parent, null);
}
generic_method = new GenericMethod (parent.NamespaceEntry, parent, member_name, type_params,
ec.Emit (OpCodes.Ldftn, TypeBuilder.GetMethod (t.GetMetaInfo (), (MethodInfo) delegate_method.GetMetaInfo ()));
} else {
if (delegate_method.IsGeneric)
- delegate_method = delegate_method.MakeGenericMethod (method.TypeParameters);
+ delegate_method = delegate_method.MakeGenericMethod (ec.MemberContext, method.TypeParameters);
ec.Emit (OpCodes.Ldftn, delegate_method);
}
- var constructor_method = Delegate.GetConstructor (ec.MemberContext.Compiler, ec.CurrentType, type);
+ var constructor_method = Delegate.GetConstructor (type);
ec.Emit (OpCodes.Newobj, constructor_method);
if (am_cache != null) {
//
public class AnonymousTypeClass : CompilerGeneratedClass
{
- // TODO: Merge with AnonymousTypeParameter
- public class GeneratedParameter : Parameter
- {
- public GeneratedParameter (FullNamedExpression type, AnonymousTypeParameter p)
- : base (type, p.Name, Modifier.NONE, null, p.Location)
- {
- }
- }
-
static int types_counter;
public const string ClassNamePrefix = "<>__AnonType";
public const string SignatureForError = "anonymous type";
readonly IList<AnonymousTypeParameter> parameters;
- private AnonymousTypeClass (DeclSpace parent, MemberName name, IList<AnonymousTypeParameter> parameters, Location loc)
- : base (parent, name, (RootContext.EvalMode ? Modifiers.PUBLIC : 0) | Modifiers.SEALED)
+ private AnonymousTypeClass (TypeContainer parent, MemberName name, IList<AnonymousTypeParameter> parameters, Location loc)
+ : base (parent, name, (parent.Module.Evaluator != null ? Modifiers.PUBLIC : 0) | Modifiers.SEALED)
{
this.parameters = parameters;
}
- public static AnonymousTypeClass Create (CompilerContext ctx, TypeContainer parent, IList<AnonymousTypeParameter> parameters, Location loc)
+ public static AnonymousTypeClass Create (TypeContainer parent, IList<AnonymousTypeParameter> parameters, Location loc)
{
string name = ClassNamePrefix + types_counter++;
Parameter[] ctor_params = new Parameter[parameters.Count];
for (int i = 0; i < parameters.Count; ++i) {
AnonymousTypeParameter p = parameters[i];
+ for (int ii = 0; ii < i; ++ii) {
+ if (parameters[ii].Name == p.Name) {
+ parent.Compiler.Report.Error (833, parameters[ii].Location,
+ "`{0}': An anonymous type cannot have multiple properties with the same name",
+ p.Name);
+
+ p = new AnonymousTypeParameter (null, "$" + i.ToString (), p.Location);
+ parameters[i] = p;
+ break;
+ }
+ }
t_args[i] = new SimpleName ("<" + p.Name + ">__T", p.Location);
t_params[i] = new TypeParameterName (t_args[i].Name, null, p.Location);
- ctor_params[i] = new GeneratedParameter (t_args[i], p);
+ ctor_params[i] = new Parameter (t_args[i], p.Name, Parameter.Modifier.NONE, null, p.Location);
}
all_parameters = new ParametersCompiled (ctor_params);
Constructor c = new Constructor (a_type, name, Modifiers.PUBLIC | Modifiers.DEBUGGER_HIDDEN,
null, all_parameters, null, loc);
- c.Block = new ToplevelBlock (ctx, c.ParameterInfo, loc);
+ c.Block = new ToplevelBlock (parent.Module.Compiler, c.ParameterInfo, loc);
//
// Create fields and contructor body with field initialization
new SimpleAssign (new MemberAccess (new This (p.Location), f.Name),
c.Block.GetParameterReference (i, p.Location))));
- ToplevelBlock get_block = new ToplevelBlock (ctx, p.Location);
+ ToplevelBlock get_block = new ToplevelBlock (parent.Module.Compiler, p.Location);
get_block.AddStatement (new Return (
new MemberAccess (new This (p.Location), f.Name), p.Location));
Location loc = Location;
var equals_parameters = ParametersCompiled.CreateFullyResolved (
- new Parameter (new TypeExpression (TypeManager.object_type, loc), "obj", 0, null, loc), TypeManager.object_type);
+ new Parameter (new TypeExpression (Compiler.BuiltinTypes.Object, loc), "obj", 0, null, loc), Compiler.BuiltinTypes.Object);
- Method equals = new Method (this, null, new TypeExpression (TypeManager.bool_type, loc),
+ Method equals = new Method (this, null, new TypeExpression (Compiler.BuiltinTypes.Bool, loc),
Modifiers.PUBLIC | Modifiers.OVERRIDE | Modifiers.DEBUGGER_HIDDEN, new MemberName ("Equals", loc),
equals_parameters, null);
equals_parameters[0].Resolve (equals, 0);
- Method tostring = new Method (this, null, new TypeExpression (TypeManager.string_type, loc),
+ Method tostring = new Method (this, null, new TypeExpression (Compiler.BuiltinTypes.String, loc),
Modifiers.PUBLIC | Modifiers.OVERRIDE | Modifiers.DEBUGGER_HIDDEN, new MemberName ("ToString", loc),
Mono.CSharp.ParametersCompiled.EmptyReadOnlyParameters, null);
new QualifiedAliasMember ("global", "System", loc), "Collections", loc), "Generic", loc);
Expression rs_equals = null;
- Expression string_concat = new StringConstant ("{", loc);
- Expression rs_hashcode = new IntConstant (-2128831035, loc);
+ Expression string_concat = new StringConstant (Compiler.BuiltinTypes, "{", loc);
+ Expression rs_hashcode = new IntConstant (Compiler.BuiltinTypes, -2128831035, loc);
for (int i = 0; i < parameters.Count; ++i) {
var p = parameters [i];
var f = Fields [i];
Expression field_hashcode = new Invocation (new MemberAccess (equality_comparer,
"GetHashCode", loc), arguments_hashcode);
- IntConstant FNV_prime = new IntConstant (16777619, loc);
+ IntConstant FNV_prime = new IntConstant (Compiler.BuiltinTypes, 16777619, loc);
rs_hashcode = new Binary (Binary.Operator.Multiply,
new Binary (Binary.Operator.ExclusiveOr, rs_hashcode, field_hashcode, loc),
FNV_prime, loc);
new MemberAccess (new This (f.Location), f.Name), new NullLiteral (loc), loc)),
new Invocation (new MemberAccess (
new MemberAccess (new This (f.Location), f.Name), "ToString"), null),
- new StringConstant (string.Empty, loc), loc);
+ new StringConstant (Compiler.BuiltinTypes, string.Empty, loc), loc);
if (rs_equals == null) {
rs_equals = field_equal;
string_concat = new Binary (Binary.Operator.Addition,
string_concat,
new Binary (Binary.Operator.Addition,
- new StringConstant (" " + p.Name + " = ", loc),
+ new StringConstant (Compiler.BuiltinTypes, " " + p.Name + " = ", loc),
field_to_string,
loc),
loc);
string_concat = new Binary (Binary.Operator.Addition,
new Binary (Binary.Operator.Addition,
string_concat,
- new StringConstant (", " + p.Name + " = ", loc),
+ new StringConstant (Compiler.BuiltinTypes, ", " + p.Name + " = ", loc),
loc),
field_to_string,
loc);
string_concat = new Binary (Binary.Operator.Addition,
string_concat,
- new StringConstant (" }", loc),
+ new StringConstant (Compiler.BuiltinTypes, " }", loc),
loc);
//
//
// GetHashCode () override
//
- Method hashcode = new Method (this, null, new TypeExpression (TypeManager.int32_type, loc),
+ Method hashcode = new Method (this, null, new TypeExpression (Compiler.BuiltinTypes.Int, loc),
Modifiers.PUBLIC | Modifiers.OVERRIDE | Modifiers.DEBUGGER_HIDDEN,
new MemberName ("GetHashCode", loc),
Mono.CSharp.ParametersCompiled.EmptyReadOnlyParameters, null);
Block hashcode_block = new Block (hashcode_top, loc, loc);
hashcode_top.AddStatement (new Unchecked (hashcode_block, loc));
- var li_hash = LocalVariable.CreateCompilerGenerated (TypeManager.int32_type, hashcode_top, loc);
+ var li_hash = LocalVariable.CreateCompilerGenerated (Compiler.BuiltinTypes.Int, hashcode_top, loc);
hashcode_block.AddStatement (new BlockVariableDeclaration (new TypeExpression (li_hash.Type, loc), li_hash));
LocalVariableReference hash_variable_assign = new LocalVariableReference (li_hash, loc);
hashcode_block.AddStatement (new StatementExpression (
var hash_variable = new LocalVariableReference (li_hash, loc);
hashcode_block.AddStatement (new StatementExpression (
new CompoundAssign (Binary.Operator.Addition, hash_variable,
- new Binary (Binary.Operator.LeftShift, hash_variable, new IntConstant (13, loc), loc), loc)));
+ new Binary (Binary.Operator.LeftShift, hash_variable, new IntConstant (Compiler.BuiltinTypes, 13, loc), loc), loc)));
hashcode_block.AddStatement (new StatementExpression (
new CompoundAssign (Binary.Operator.ExclusiveOr, hash_variable,
- new Binary (Binary.Operator.RightShift, hash_variable, new IntConstant (7, loc), loc), loc)));
+ new Binary (Binary.Operator.RightShift, hash_variable, new IntConstant (Compiler.BuiltinTypes, 7, loc), loc), loc)));
hashcode_block.AddStatement (new StatementExpression (
new CompoundAssign (Binary.Operator.Addition, hash_variable,
- new Binary (Binary.Operator.LeftShift, hash_variable, new IntConstant (3, loc), loc), loc)));
+ new Binary (Binary.Operator.LeftShift, hash_variable, new IntConstant (Compiler.BuiltinTypes, 3, loc), loc), loc)));
hashcode_block.AddStatement (new StatementExpression (
new CompoundAssign (Binary.Operator.ExclusiveOr, hash_variable,
- new Binary (Binary.Operator.RightShift, hash_variable, new IntConstant (17, loc), loc), loc)));
+ new Binary (Binary.Operator.RightShift, hash_variable, new IntConstant (Compiler.BuiltinTypes, 17, loc), loc), loc)));
hashcode_block.AddStatement (new StatementExpression (
new CompoundAssign (Binary.Operator.Addition, hash_variable,
- new Binary (Binary.Operator.LeftShift, hash_variable, new IntConstant (5, loc), loc), loc)));
+ new Binary (Binary.Operator.LeftShift, hash_variable, new IntConstant (Compiler.BuiltinTypes, 5, loc), loc), loc)));
hashcode_block.AddStatement (new Return (hash_variable, loc));
hashcode.Block = hashcode_top;