static bool IsAccessible(MethodSymbol m, VisibilityScope scope) { return( m.DeclaredAccessibility != Accessibility.ProtectedAndInternal && // C# 7.2 "private protected" m.DeclaredAccessibility != Accessibility.Internal && // "internal" (scope.ScopeIsDynamic || m.IsAccessible(scope.Scope)) && // method is accessible (or might be in runtime) !m.IsFieldsOnlyConstructor() // method is not a special .ctor which is not accessible from user's code ); }
/// <summary> /// Removes methods that are inaccessible for sure. /// </summary> static void RemoveInaccessible(List <MethodSymbol> methods, VisibilityScope scope) { for (int i = methods.Count - 1; i >= 0; i--) { if (!IsAccessible(methods[i], scope)) { methods.RemoveAt(i); } } }
/// <summary> /// Removes methods that are inaccessible for sure. /// </summary> static void RemoveInaccessible(List <MethodSymbol> methods, VisibilityScope scope) { for (int i = methods.Count - 1; i >= 0; i--) { var m = methods[i]; if ((!scope.ScopeIsDynamic && !m.IsAccessible(scope.Scope)) || // method is not accessible for sure m.IsFieldsOnlyConstructor()) // method is special .ctor which is not accessible from user's code { methods.RemoveAt(i); } } }
public void Print(Program prog) { Flush(); var pathName = ArmadaOptions.O.ArmadaOutputDir + "/" + this.PathName; Console.Out.WriteLine($"Printing proof to {pathName}"); var tw = new System.IO.StreamWriter(pathName); var pr = new Printer(tw, ArmadaOptions.O.PrintMode); var fileBeingPrinted = Path.GetFullPath(prog.FullName); VisibilityScope scope = null; foreach (var includePath in module.ArmadaIncludes) { pr.PrintInclude(includePath); } pr.PrintModuleDefinition(module.ArmadaTranslation, scope, 0, new List <Microsoft.Boogie.IToken>(), fileBeingPrinted); tw.Flush(); }
public static void PrintLevels(Program program) { foreach (TopLevelDecl d in program.DefaultModuleDef.TopLevelDecls) { if (d is LiteralModuleDecl) { var def = ((LiteralModuleDecl)d).ModuleDef; var pathName = ArmadaOptions.O.ArmadaOutputDir + "/" + def.Name + ".dfy"; if (def.ModuleType == ArmadaModuleType.ArmadaLevel) { Console.Out.WriteLine("Printing level to {0}", pathName); } else if (def.ModuleType == ArmadaModuleType.ArmadaStructs) { Console.Out.WriteLine("Printing structs to {0}", pathName); } else { continue; } var tw = new System.IO.StreamWriter(pathName); var pr = new Printer(tw, ArmadaOptions.O.PrintMode); var fileBeingPrinted = Path.GetFullPath(program.FullName); VisibilityScope scope = null; var ld = (LiteralModuleDecl)d; if (ld.Signature != null) { scope = ld.Signature.VisibilityScope; } foreach (var includePath in def.ArmadaIncludes) { pr.PrintInclude(includePath); } pr.PrintModuleDefinition(def.ArmadaTranslation, scope, 0, new List <Bpl.IToken>(), fileBeingPrinted); tw.Flush(); } } }
/// <summary> /// Tries to resolve method in design time. /// </summary> /// <returns> /// Might return one of following: /// - resolved single <see cref="MethodSymbol"/> /// - <see cref="MissingMethodSymbol"/> /// - <see cref="AmbiguousMethodSymbol"/> /// - <see cref="InaccessibleMethodSymbol"/> /// </returns> public MethodSymbol /*!*/ Resolve(TypeRefContext typeCtx, ImmutableArray <BoundArgument> args, VisibilityScope scope) { if (_methods.Count == 0) { return(new MissingMethodSymbol()); } if (_methods.Count == 1 && _methods[0].IsErrorMethodOrNull()) { return(_methods[0] ?? new MissingMethodSymbol()); } // see Pchp.Core.Dynamic.OverloadBinder // collect valid methods: var result = new List <MethodSymbol>(_methods.Where(MethodSymbolExtensions.IsValidMethod)); // only visible methods: RemoveInaccessible(result, scope); if (result.Count == 0) { return(new InaccessibleMethodSymbol(_methods.AsImmutable())); } if (scope.ScopeIsDynamic && result.Any(IsNonPublic)) { // we have to postpone the resolution to runtime: return(new AmbiguousMethodSymbol(result.AsImmutable(), false)); } if (result.Count == 1) { return(result[0]); } // TODO: cost of args convert operation // by params count var result2 = new List <MethodSymbol>(); foreach (var m in result) { var nmandatory = 0; var hasoptional = false; var hasparams = false; var match = true; var hasunpacking = false; var expectedparams = m.GetExpectedArguments(typeCtx); foreach (var p in expectedparams) { hasoptional |= p.DefaultValue != null; hasparams |= p.IsVariadic; if (!hasoptional && !hasparams) { nmandatory++; } if (p.Index < args.Length) { hasunpacking |= args[p.Index].IsUnpacking; // TODO: check args[i] is convertible to p.Type var p_type = typeCtx.WithoutNull(p.Type); var a_type = typeCtx.WithoutNull(args[p.Index].Value.TypeRefMask); match &= a_type == p_type && !hasunpacking; // check types match (ignoring NULL flag) } } // if ((args.Length >= nmandatory || hasunpacking) && (hasparams || args.Length <= expectedparams.Length)) { // TODO: this is naive implementation of overload resolution, // make it properly using Conversion Cost if (match && !hasparams) { return(m); // perfect match } // result2.Add(m); } } // return((result2.Count == 1) ? result2[0] : new AmbiguousMethodSymbol(result.AsImmutable(), true)); }
/// <summary> /// Tries to resolve method in design time. /// </summary> /// <returns> /// Might return one of following: /// - resolved single <see cref="MethodSymbol"/> /// - <see cref="MissingMethodSymbol"/> /// - <see cref="AmbiguousMethodSymbol"/> /// - <see cref="InaccessibleMethodSymbol"/> /// </returns> public MethodSymbol /*!*/ Resolve(TypeRefContext typeCtx, ImmutableArray <BoundArgument> args, VisibilityScope scope, bool isInstanceMethodCall) { if (_single != null) { return(IsAccessible(_single, scope) ? scope.ScopeIsDynamic && IsNonPublic(_single) ? new AmbiguousMethodSymbol(ImmutableArray.Create(_single), false) // TODO: find a way on how to disable this check in CLR : _single : new InaccessibleMethodSymbol(ImmutableArray.Create(_single))); } if (_methods == null || _methods.Length == 0) { return(new MissingMethodSymbol()); } // see Pchp.Core.Dynamic.OverloadBinder // collect valid methods: var result = new List <MethodSymbol>(_methods.Where(MethodSymbolExtensions.IsValidMethod)); // only visible methods: RemoveInaccessible(result, scope); if (result.Count == 0) { return(new InaccessibleMethodSymbol(_methods.AsImmutable())); } // if there are both instance and static methods, // take the right ones preferably: var statics = result.Count(m => m.IsStatic); if (statics > 0 && statics < result.Count) { if (isInstanceMethodCall) { result.RemoveAll(m => m.IsStatic); } else { result.RemoveAll(m => !m.IsStatic); } } else { // otherwise, // PHP allows that static methods to be called non-statically and vice versa // let the compiler to deal with it } // if (scope.ScopeIsDynamic && result.Any(IsNonPublic)) { // we have to postpone the resolution to runtime: return(new AmbiguousMethodSymbol(result.AsImmutable(), false)); } if (result.Count == 1) { return(result[0]); } // TODO: cost of args convert operation // by params count var result2 = new List <MethodSymbol>(); foreach (var m in result) { var nmandatory = 0; var hasoptional = false; var hasparams = false; var match = true; var hasunpacking = false; var expectedparams = m.GetExpectedArguments(typeCtx); for (int i = 0; i < expectedparams.Count; i++) { var p = expectedparams[i]; hasoptional |= p.DefaultValue != null; hasparams |= p.IsVariadic; if (!hasoptional && !hasparams) { nmandatory++; } if (p.Index < args.Length) { hasunpacking |= args[p.Index].IsUnpacking; // TODO: check args[i] is convertible to p.Type var p_type = typeCtx.WithoutNull(p.Type); var a_type = typeCtx.WithoutNull(args[p.Index].Value.TypeRefMask); match &= a_type == p_type && !hasunpacking; // check types match (ignoring NULL flag) } } // if ((args.Length >= nmandatory || hasunpacking) && (hasparams || args.Length <= expectedparams.Count)) { // TODO: this is naive implementation of overload resolution, // make it properly using Conversion Cost if (match && !hasparams) { return(m); // perfect match } // result2.Add(m); } } // return((result2.Count == 1) ? result2[0] : new AmbiguousMethodSymbol(result.AsImmutable(), true)); }
public void PrintModuleDefinition(ModuleDefinition module, VisibilityScope scope, int indent, string fileBeingPrinted) { Contract.Requires(module != null); Contract.Requires(0 <= indent); Type.PushScope(scope); if (module.IsAbstract) { wr.Write("abstract "); } if (module.IsProtected) { wr.Write("protected "); } wr.Write("module"); PrintAttributes(module.Attributes); wr.Write(" {0} ", module.Name); if (module.RefinementBaseName != null) { if (module.IsExclusiveRefinement) { wr.Write("exclusively "); } wr.Write("refines {0} ", module.RefinementBaseName.val); } if (module.TopLevelDecls.Count == 0) { wr.WriteLine("{ }"); } else { wr.WriteLine("{"); PrintCallGraph(module, indent + IndentAmount); PrintTopLevelDeclsOrExportedView(module, indent, fileBeingPrinted); Indent(indent); wr.WriteLine("}"); } Type.PopScope(scope); }
public bool Equals(DestinyVendorItemDefinition input) { if (input == null) { return(false); } return (( VendorItemIndex == input.VendorItemIndex || (VendorItemIndex.Equals(input.VendorItemIndex)) ) && ( ItemHash == input.ItemHash || (ItemHash.Equals(input.ItemHash)) ) && ( Quantity == input.Quantity || (Quantity.Equals(input.Quantity)) ) && ( FailureIndexes == input.FailureIndexes || (FailureIndexes != null && FailureIndexes.SequenceEqual(input.FailureIndexes)) ) && ( Currencies == input.Currencies || (Currencies != null && Currencies.SequenceEqual(input.Currencies)) ) && ( RefundPolicy == input.RefundPolicy || (RefundPolicy != null && RefundPolicy.Equals(input.RefundPolicy)) ) && ( RefundTimeLimit == input.RefundTimeLimit || (RefundTimeLimit.Equals(input.RefundTimeLimit)) ) && ( CreationLevels == input.CreationLevels || (CreationLevels != null && CreationLevels.SequenceEqual(input.CreationLevels)) ) && ( DisplayCategoryIndex == input.DisplayCategoryIndex || (DisplayCategoryIndex.Equals(input.DisplayCategoryIndex)) ) && ( CategoryIndex == input.CategoryIndex || (CategoryIndex.Equals(input.CategoryIndex)) ) && ( OriginalCategoryIndex == input.OriginalCategoryIndex || (OriginalCategoryIndex.Equals(input.OriginalCategoryIndex)) ) && ( MinimumLevel == input.MinimumLevel || (MinimumLevel.Equals(input.MinimumLevel)) ) && ( MaximumLevel == input.MaximumLevel || (MaximumLevel.Equals(input.MaximumLevel)) ) && ( Action == input.Action || (Action != null && Action.Equals(input.Action)) ) && ( DisplayCategory == input.DisplayCategory || (DisplayCategory != null && DisplayCategory.Equals(input.DisplayCategory)) ) && ( InventoryBucketHash == input.InventoryBucketHash || (InventoryBucketHash.Equals(input.InventoryBucketHash)) ) && ( VisibilityScope == input.VisibilityScope || (VisibilityScope != null && VisibilityScope.Equals(input.VisibilityScope)) ) && ( PurchasableScope == input.PurchasableScope || (PurchasableScope != null && PurchasableScope.Equals(input.PurchasableScope)) ) && ( Exclusivity == input.Exclusivity || (Exclusivity != null && Exclusivity.Equals(input.Exclusivity)) ) && ( IsOffer == input.IsOffer || (IsOffer != null && IsOffer.Equals(input.IsOffer)) ) && ( IsCrm == input.IsCrm || (IsCrm != null && IsCrm.Equals(input.IsCrm)) ) && ( SortValue == input.SortValue || (SortValue.Equals(input.SortValue)) ) && ( ExpirationTooltip == input.ExpirationTooltip || (ExpirationTooltip != null && ExpirationTooltip.Equals(input.ExpirationTooltip)) ) && ( RedirectToSaleIndexes == input.RedirectToSaleIndexes || (RedirectToSaleIndexes != null && RedirectToSaleIndexes.SequenceEqual(input.RedirectToSaleIndexes)) ) && ( SocketOverrides == input.SocketOverrides || (SocketOverrides != null && SocketOverrides.SequenceEqual(input.SocketOverrides)) ) && ( Unpurchasable == input.Unpurchasable || (Unpurchasable != null && Unpurchasable.Equals(input.Unpurchasable)) )); }