protected virtual void SetupConstructor(NewExpression newExpr, ConstructorInfo constructor, TypeData type) { if (!constructor.IsPublic && currentClass.TypeData != type) { report.Error(newExpr.Location, "cannot call private constructor"); return; } newExpr.Constructor = constructor; newExpr.NodeType = type; ParameterInfo[] parameters = typeManager.GetParameters(constructor); int i = 0; foreach (ModalExpression arg in newExpr.Arguments) { ParameterInfo param = parameters[i++]; if (arg.NodeType == null) // void expression arg.NodeType = typeManager.GetTypeData(param.ParameterType); } }
public override void VisitNew(NewExpression newExpr) { ParameterInfo[] parameters = typeManager.GetParameters(newExpr.Constructor); ModalExpression arg = (ModalExpression) newExpr.Arguments.First; foreach (ParameterInfo param in parameters) { if (arg == null) break; arg.Accept(this); BoxIfNecessary(arg.RawType, param.ParameterType); arg = (ModalExpression) arg.Next; } ilGenerator.Emit(OpCodes.Newobj, newExpr.Constructor); }
public override void VisitNew(NewExpression newExpr) { newExpr.TypeSpecifier.Accept(this); if (newExpr.TypeSpecifier.NodeType == null) return; newExpr.Arguments.Accept(this); TypeData type = newExpr.TypeSpecifier.NodeType; try { ConstructorData constructor = type.LookupConstructor(newExpr.Arguments); SetupConstructor(newExpr, constructor.ConstructorInfo, type); } catch (LookupMethodException e) { string ctorInfo = type.FullName + "::.ctor"; if (newExpr.Arguments.Length > 0) { ctorInfo += "("; foreach (ModalExpression arg in newExpr.Arguments) { if (arg != newExpr.Arguments.First) ctorInfo += ","; ctorInfo += arg.NodeType.FullName; } ctorInfo += ")"; } report.Error(newExpr.Location, "{0} for {1}", e.Message, ctorInfo); } }
public virtual void VisitNew(NewExpression newExpr) { }