public static bool ScanForConstructors(NewExpression sr, IBlockNode scope, UserDefinedType udt, List <AbstractType> _ctors, out bool explicitCtorFound) { explicitCtorFound = false; var ct = new CtorScan(sr, new ResolutionContext(new Misc.ParseCacheView(new RootPackage[] {}), null, scope)); ct.DeepScanClass(udt, MemberFilter.Methods, false); _ctors.AddRange(ct.matches_types); var rawList = (udt.Definition as DClassLike)[DMethod.ConstructorIdentifierHash]; if (rawList != null) { foreach (var n in rawList) { var dm = n as DMethod; if (dm == null || dm.IsStatic || dm.SpecialType != DMethod.MethodType.Constructor) { continue; } explicitCtorFound = true; break; } } return(ct.matches_types.Count != 0); }
private static void HandleNewExpression_Ctor(NewExpression nex, IBlockNode curBlock, List <AbstractType> _ctors, AbstractType t) { var udt = t as TemplateIntermediateType; if (udt is ClassType || udt is StructType) { bool explicitCtorFound; if (!CtorScan.ScanForConstructors(nex, curBlock, udt, _ctors, out explicitCtorFound)) { if (explicitCtorFound) { // TODO: Somehow inform the user that the current class can't be instantiated } else { // Introduce default constructor _ctors.Add(new MemberSymbol(new DMethod(DMethod.MethodType.Constructor) { Description = "Default constructor for " + udt.Name, Parent = udt.Definition }, udt, nex)); } } } }
public static bool ScanForConstructors(NewExpression sr, IBlockNode scope, UserDefinedType udt, List<AbstractType> _ctors, out bool explicitCtorFound) { explicitCtorFound = false; var ct = new CtorScan(sr, new ResolutionContext(new Misc.LegacyParseCacheView(new RootPackage[] {}), null, scope)); ct.DeepScanClass(udt, new ItemCheckParameters(MemberFilter.Methods), false); _ctors.AddRange(ct.matches_types); var rawList = (udt.Definition as DClassLike)[DMethod.ConstructorIdentifierHash]; if(rawList != null) { foreach(var n in rawList) { var dm = n as DMethod; if(dm == null || dm.IsStatic || dm.SpecialType != DMethod.MethodType.Constructor) continue; explicitCtorFound = true; break; } } return ct.matches_types.Count != 0; }