protected override bool TryGetSymbol(int operand, ref Instruction instruction, ulong address, int addressSize, out SymbolResult symbol, ref NumberFormattingOptions options) { if (owner.cachedSymbolResolver.TryResolve(address, out var symResult, out bool fakeSymbol)) { if (!fakeSymbol || owner.AddLabels) { Debug.Assert(symResult.Address == address, "Symbol address != orig address: NYI"); if (symResult.Address == address) { symbol = new SymbolResult(symResult.Symbol, SymbolKindUtils.ToFormatterOutputTextKind(symResult.Kind), SymbolFlags.Address); return(true); } } } return(base.TryGetSymbol(operand, ref instruction, address, addressSize, out symbol, ref options)); }
public static object SYMBOL( [ExcelArgument(Description = "の銘柄情報を取得する", Name = "銘柄コード")] string Symbol, [ExcelArgument(Description = "の銘柄情報を取得する", Name = "市場コード")] string Exchange) { string ret = null; try { string ResultMessage = Validate.ValidateRequired(Symbol, Exchange); if (!string.IsNullOrEmpty(ResultMessage)) { return(ResultMessage); } Tuple <DateTime, string> tpl; var tplKey = Symbol + "-" + Exchange; if (_symbolCache.TryGetValue(tplKey, out tpl)) { if ((DateTime.Now - tpl.Item1).TotalSeconds < 1) { ret = tpl.Item2; } } if (String.IsNullOrEmpty(ret)) { ret = middleware.GetSymbol(Symbol, Exchange); _symbolCache[tplKey] = Tuple.Create(DateTime.Now, ret); } object array; array = SymbolResult.SymbolCheck(ret); return(XlCall.Excel(XlCall.xlUDF, "Resize", array)); } catch (Exception exception) { if (exception.InnerException == null) { return(exception.Message); } else { return(exception.InnerException.Message); } } }
void DisplInBrackets(string hexBytes, int bitness, string formattedString, Flags flags) { var decoder = Decoder.Create(bitness, new ByteArrayCodeReader(hexBytes)); switch (bitness) { case 16: decoder.IP = DecoderConstants.DEFAULT_IP16; break; case 32: decoder.IP = DecoderConstants.DEFAULT_IP32; break; case 64: decoder.IP = DecoderConstants.DEFAULT_IP64; break; default: throw new InvalidOperationException(); } decoder.Decode(out var instr); var resolver = new TestSymbolResolver { tryGetSymbol = (in Instruction instruction, int operand, int instructionOperand, ulong address, int addressSize, out SymbolResult symbol) => { if (instructionOperand == 1 && (flags & Flags.Symbol) != 0) { symbol = new SymbolResult(address, "symbol", FormatterOutputTextKind.Data, (flags & Flags.Signed) != 0 ? SymbolFlags.Signed : SymbolFlags.None); return(true); } symbol = default; return(false); }, }; var formatter = (MasmFormatter)MasmFormatterFactory.Create_Resolver(resolver).formatter; formatter.MasmOptions.SymbolDisplInBrackets = (flags & Flags.SymbolDisplInBrackets) != 0; formatter.MasmOptions.DisplInBrackets = (flags & Flags.DisplInBrackets) != 0; formatter.MasmOptions.RipRelativeAddresses = (flags & Flags.Rip) != 0; formatter.MasmOptions.ShowZeroDisplacements = (flags & Flags.ShowZeroDisplacements) != 0; formatter.MasmOptions.AddDsPrefix32 = (flags & Flags.NoAddDsPrefix32) == 0; var output = new StringBuilderFormatterOutput(); formatter.Format(instr, output); var actualFormattedString = output.ToStringAndReset(); #pragma warning disable xUnit2006 // Do not use invalid string equality check // Show the full string without ellipses by using Equal<string>() instead of Equal() Assert.Equal <string>(formattedString, actualFormattedString); #pragma warning restore xUnit2006 // Do not use invalid string equality check }
/// <summary> /// Validates that only one of the option from given options is present in the symbol /// </summary> /// <param name="symbol">The symbol representing the execution of the tool</param> /// <param name="mutuallyExclusiveOptions">The list of mutually exclusive options</param> /// <param name="validationErrorMessage">The message to show if only one of the option is not present</param> /// <returns>A string to show the users if there is a validation error</returns> public static string Validate(SymbolResult symbol, IEnumerable <Option> mutuallyExclusiveOptions, string validationErrorMessage) { EnsureArg.IsNotNull(symbol, nameof(symbol)); EnsureArg.IsNotNull(mutuallyExclusiveOptions, nameof(mutuallyExclusiveOptions)); EnsureArg.IsNotNull(validationErrorMessage, nameof(validationErrorMessage)); int count = 0; foreach (Option mutuallyExclusiveOption in mutuallyExclusiveOptions) { if (mutuallyExclusiveOption.Aliases.Any(alias => symbol.Children.Contains(alias))) { count++; } } return((count != 1) ? validationErrorMessage : null); }
private static string GetSymbolResultValue(ParseResult parseResult, SymbolResult symbolResult) { if (symbolResult.Token() == null) { return(parseResult.FindResultFor(Parser.DotnetSubCommand)?.GetValueOrDefault <string>()); } else if (symbolResult.Token().Type.Equals(TokenType.Command)) { return(symbolResult.Symbol.Name); } else if (symbolResult.Token().Type.Equals(TokenType.Argument)) { return(symbolResult.Token().Value); } else { return(string.Empty); } }
protected override bool TryGetSymbol(int operand, ref Instruction instruction, ulong address, int addressSize, out SymbolResult symbol, ref NumberFormattingOptions options) { if (owner.cachedSymbolResolver.TryResolve(address, out var symResult, out bool fakeSymbol)) { if (!fakeSymbol || owner.AddLabels) { bool isBranch = symResult.Kind == SymbolKind.Function && instruction.FlowControl is var flowControl && (flowControl == FlowControl.UnconditionalBranch || flowControl == FlowControl.ConditionalBranch || flowControl == FlowControl.Call || flowControl == FlowControl.XbeginXabortXend); if (!isBranch || !IsCurrentMethod(symResult.Address)) { //TODO: need to support 'symResult.Address != address' (add a displacement to the symbol, eg. func+123) symbol = new SymbolResult(symResult.Symbol, SymbolKindUtils.ToFormatterOutputTextKind(symResult.Kind), SymbolFlags.Address); return(true); } } } return(base.TryGetSymbol(operand, ref instruction, address, addressSize, out symbol, ref options)); }
internal static ArgumentConversionResult ConvertIfNeeded( this ArgumentConversionResult conversionResult, SymbolResult symbolResult, Type toType) { if (conversionResult is null) { throw new ArgumentNullException(nameof(conversionResult)); } switch (conversionResult) { case SuccessfulArgumentConversionResult successful when !toType.IsInstanceOfType(successful.Value): return(ConvertObject( conversionResult.Argument, toType, successful.Value)); case SuccessfulArgumentConversionResult successful when toType == typeof(object) && conversionResult.Argument.Arity.MaximumNumberOfValues > 1 && successful.Value is string: return(ConvertObject( conversionResult.Argument, typeof(IEnumerable <string>), successful.Value)); case NoArgumentConversionResult _ when toType == typeof(bool): return(Success(conversionResult.Argument, true)); case NoArgumentConversionResult _ when conversionResult.Argument.Arity.MinimumNumberOfValues > 0: return(new MissingArgumentConversionResult( conversionResult.Argument, ValidationMessages.Instance.RequiredArgumentMissing(symbolResult))); case NoArgumentConversionResult _ when conversionResult.Argument.Arity.MaximumNumberOfValues > 1: return(Success( conversionResult.Argument, Array.Empty <string>())); default: return(conversionResult); } }
public void BuildGraph3D(string symbolSource, string firstParameterName, string secondParameterName) { SymbolResult input = SymbolResult.Load(symbolSource); foreach (TestResult currTestResult in input.testResults) { foreach (OnePeriodResult currOnePeriodResult in currTestResult.listOnePeriodresult) { Graph3DAnalyzer graph3DAnalyzer = new Graph3DAnalyzer(); foreach (var currSRS in currOnePeriodResult.ISResult) { graph3DAnalyzer.Process(currSRS.Key[firstParameterName], currSRS.Key[secondParameterName], currSRS.Value.CalculateConfidenceIntervalLow); } Graph3DScript graph3DScript = new Graph3DScript(firstParameterName, secondParameterName, "CalculateConfidenceIntervalLow", graph3DAnalyzer, Path.Combine(currOnePeriodResult.RoorDirectory, typeof(Graph3DScript).ToString())); graph3DScript.Save(); } } }
public bool TryGetSymbol(int operand, int instructionOperand, ref Instruction instruction, ulong address, int addressSize, out SymbolResult symbol) { if (tryGetSymbol != null) { if (!tryGetSymbol(operand, instructionOperand, ref instruction, address, addressSize, out symbol)) { return(false); } if (symbol.HasSymbolSize) { symbol = new SymbolResult(address + (ulong)resultDispl, symbol.Text, symbol.Flags, symbol.SymbolSize); } else { symbol = new SymbolResult(address + (ulong)resultDispl, symbol.Text, symbol.Flags); } return(true); } symbol = default; return(false); }
private void VisitInternal(SymbolResult node) { switch (node) { case ArgumentResult argumentResult: VisitArgumentResult(argumentResult); break; case RootCommandResult rootCommandResult: VisitRootCommandResult(rootCommandResult); for (var i = 0; i < rootCommandResult.Children.Count; i++) { VisitInternal(rootCommandResult.Children[i]); } break; case CommandResult commandResult: VisitCommandResult(commandResult); for (var i = 0; i < commandResult.Children.Count; i++) { VisitInternal(commandResult.Children[i]); } break; case OptionResult optionResult: VisitOptionResult(optionResult); for (var i = 0; i < optionResult.Children.Count; i++) { VisitInternal(optionResult.Children[i]); } break; } }
public async Task <ImmutableArray <SymbolResult <ISymbol> > > FindDeclarationsAsync( string name, TSimpleNameSyntax nameNode, SymbolFilter filter) { if (name != null && string.IsNullOrWhiteSpace(name)) { return(ImmutableArray <SymbolResult <ISymbol> > .Empty); } using (var query = this.Exact ? SearchQuery.Create(name, ignoreCase: true) : SearchQuery.CreateFuzzy(name)) { var symbols = await FindDeclarationsAsync(filter, query).ConfigureAwait(false); if (Exact) { // We did an exact, case insensitive, search. Case sensitive matches should // be preferred though over insensitive ones. return(symbols.SelectAsArray(s => SymbolResult.Create(s.Name, nameNode, s, weight: s.Name == name ? 0 : 1))); } // TODO(cyrusn): It's a shame we have to compute this twice. However, there's no // great way to store the original value we compute because it happens deep in the // compiler bowels when we call FindDeclarations. var similarityChecker = WordSimilarityChecker.Allocate(name, substringsAreSimilar: false); var result = symbols.SelectAsArray(s => { var areSimilar = similarityChecker.AreSimilar(s.Name, out var matchCost); Debug.Assert(areSimilar); return(SymbolResult.Create(s.Name, nameNode, s, matchCost)); }); similarityChecker.Free(); return(result); } }
public int CompareTo(SymbolResult other) { Debug.Assert( Symbol is INamespaceSymbol || !((INamedTypeSymbol)Symbol).IsGenericType ); Debug.Assert( other.Symbol is INamespaceSymbol || !((INamedTypeSymbol)other.Symbol).IsGenericType ); var diff = Weight - other.Weight; if (diff != 0) { return(diff); } return(INamespaceOrTypeSymbolExtensions.CompareNameParts( NameParts, other.NameParts, placeSystemNamespaceFirst: true )); }
public override SymbolReference CreateReference <T>(SymbolResult <T> symbol) { return(new ProjectSymbolReference( provider, symbol.WithSymbol <INamespaceOrTypeSymbol>(symbol.Symbol), _project)); }
static public void RunCalculatePortfolio2(string pathString, PortfolioCalculationType portType, IAbstractLogger logger) { double initialDeposit = Double.Parse(ConfigurationManager.AppSettings["InitialDeposit"]); double reliability = Double.Parse(ConfigurationManager.AppSettings["Reliability"]); int loss = Int32.Parse(ConfigurationManager.AppSettings["Loss"]); double minVolume = Double.Parse(ConfigurationManager.AppSettings["MinVolume"]); double minMarginLevel = Double.Parse(ConfigurationManager.AppSettings["MinMarginLevel"]); PortfolioRawData portRawData = new PortfolioRawData(); foreach (string path in Directory.GetDirectories(pathString)) { logger.AddLog(string.Format("Loading {0}", path), IAbstractLoggerMessageType.General); SymbolResult input = SymbolResult.Load(path); foreach (TestResult currTestResult in input.testResults) { try { string testResultName = Path.GetFileName(path) + "_" + currTestResult.Name; logger.AddLog(string.Format("Analyzing {0}", testResultName), IAbstractLoggerMessageType.General); PairAdapter adapter = new PairAdapter(testResultName, currTestResult, "TP", "OpenOrderShift"); portRawData.AddPortfolioRawItems(adapter.ProcessAndFill()); } catch (ArgumentException exc) { logger.AddLog("Exception: " + exc.Message, IAbstractLoggerMessageType.Error); } } } logger.AddLog(string.Format("Calculating Portfolio"), IAbstractLoggerMessageType.General); double[,] equity, margin; // portRawData.AddInversePortfolioRawItem(); portRawData.FillArraysForScienceStyleGuys(out equity, out margin); Mathematics.Portfolio theBestPortfolio = null; int iterationsNumber = 100; double lossResult = 0; for (int iteration = 1; iteration < iterationsNumber; ++iteration) { double calculatedLoss = loss * iteration / iterationsNumber; Mathematics.Portfolio portfolio; switch (portType) { case PortfolioCalculationType.CalculateLinearFast: portfolio = Mathematics.Portfolio.CalculateLinearFast(equity, margin, initialDeposit, reliability, calculatedLoss, minMarginLevel, minVolume); break; case PortfolioCalculationType.CalculateLinearFastWithoutCorrelation: Mathematics.PortfolioInput pInput = new Mathematics.PortfolioInput(); pInput.Equity = equity; pInput.Reliability = reliability; pInput.MaximumLoss = calculatedLoss; pInput.InitialDeposit = initialDeposit; pInput.MarginLevelThreshold = minMarginLevel; pInput.Margin = margin; pInput.MinimumCoefficientValue = minVolume; portfolio = Mathematics.Portfolio.CalculateLinearFastWithoutCorrelation(pInput); break; default: throw new ApplicationException("Not supported PortfolioCalculationType"); } if (portfolio.Coefficients.Count(p => p > 0) < 5) { continue; } if (null == theBestPortfolio) { theBestPortfolio = portfolio; lossResult = calculatedLoss; } else if (theBestPortfolio.Profit < portfolio.Profit) { theBestPortfolio = portfolio; lossResult = calculatedLoss; } } logger.AddLog(string.Format("Writing portfolio to file"), IAbstractLoggerMessageType.General); using (StreamWriter stream = new StreamWriter(Path.Combine(pathString, "portfolio.txt"))) { double[] coefficients = theBestPortfolio.Coefficients; int i = 0; foreach (PortfolioRawItem currPortfolioRawItem in portRawData.portfolioRawItems) { stream.WriteLine("[Symbol = {0}; {1}] = {2}", currPortfolioRawItem.Symbol, currPortfolioRawItem.StrategyParameter.ToString(';'), coefficients[i++]); } stream.WriteLine("daily profit = {0}", theBestPortfolio.Profit); stream.WriteLine("When = {0}", theBestPortfolio.When); stream.WriteLine("Loss = {0}", lossResult); } }
private static bool WasPassedChildren(SymbolResult result) { return(result.Children.Count > 0); }
public MetadataSymbolReference(AbstractAddImportCodeFixProvider <TSimpleNameSyntax> provider, SymbolResult <INamespaceOrTypeSymbol> symbolResult, PortableExecutableReference reference) : base(provider, symbolResult) { _reference = reference; }
public bool TryGetSymbol(int operand, int instructionOperand, ref Instruction instruction, ulong address, int addressSize, out SymbolResult symbol) { if (owner.cachedSymbolResolver.TryResolve(address, out var symResult, out bool fakeSymbol)) { if (!fakeSymbol || owner.AddLabels) { symbol = new SymbolResult(symResult.Address, symResult.Symbol, SymbolKindUtils.ToFormatterOutputTextKind(symResult.Kind), SymbolFlags.None); if (instruction.OpCount == 1 && (instruction.Op0Kind == OpKind.Memory || instruction.Op0Kind == OpKind.Memory64)) { var code = instruction.Code; if (code == Code.Call_rm32 || code == Code.Jmp_rm32) { symbol = new SymbolResult(symbol.Address, symbol.Text, symbol.Flags, MemorySize.DwordOffset); } else if (code == Code.Call_rm64 || code == Code.Jmp_rm64) { symbol = new SymbolResult(symbol.Address, symbol.Text, symbol.Flags, MemorySize.QwordOffset); } } return(true); } } symbol = default; return(false); }
public override string ExpectsOneArgument(SymbolResult symbolResult) => symbolResult is CommandResult ? string.Format(LocalizableStrings.CommandAcceptsOnlyOneArgument, symbolResult.Token().Value, symbolResult.Tokens.Count) : string.Format(LocalizableStrings.OptionAcceptsOnlyOneArgument, symbolResult.Token().Value, symbolResult.Tokens.Count);
public abstract SymbolReference CreateReference <T>(SymbolResult <T> symbol) where T : INamespaceOrTypeSymbol;
public override string ExpectsOneArgument(SymbolResult symbolResult) => message;
public override string NoArgumentProvided(SymbolResult symbolResult) => symbolResult is CommandResult ? string.Format(LocalizableStrings.RequiredArgumentMissingForCommand, symbolResult.Token().Value) : string.Format(LocalizableStrings.RequiredArgumentMissingForOption, symbolResult.Token().Value);
public SymbolReference(AbstractAddImportCodeFixProvider <TSimpleNameSyntax> provider, SymbolResult <INamespaceOrTypeSymbol> symbolResult) : base(provider, new SearchResult(symbolResult)) { this.SymbolResult = symbolResult; }
public bool TryGetSymbol(int operand, int instructionOperand, ref Instruction instruction, ulong address, int addressSize, out SymbolResult symbol) { if (owner.cachedSymbolResolver.TryResolve(address, out var symResult, out bool fakeSymbol)) { if (!fakeSymbol || owner.AddLabels) { symbol = new SymbolResult(symResult.Address, symResult.Symbol, SymbolKindUtils.ToFormatterOutputTextKind(symResult.Kind), SymbolFlags.None); return(true); } } symbol = default; return(false); }
public override string RequiredArgumentMissing(SymbolResult symbolResult) => symbolResult is CommandResult ? string.Format(LocalizableStrings.RequiredCommandArgumentMissing, symbolResult.Token().Value) : string.Format(LocalizableStrings.RequiredOptionArgumentMissing, symbolResult.Token().Value);
bool ISymbolResolver.TryGetSymbol(int operand, int instructionOperand, ref Instruction instruction, ulong address, int addressSize, out SymbolResult symbol) { if (targets.TryGetValue(address, out var addrInfo) && addrInfo.Name != null) { symbol = new SymbolResult(address, addrInfo.Name); return(true); } if (knownSymbols.TryGetSymbol(address, out symbol)) { if (instruction.OpCount == 1 && (instruction.Op0Kind == OpKind.Memory || instruction.Op0Kind == OpKind.Memory64)) { var code = instruction.Code; if (code == Code.Call_rm32 || code == Code.Jmp_rm32) { symbol = new SymbolResult(symbol.Address, symbol.Text, symbol.Flags, MemorySize.DwordOffset); } else if (code == Code.Call_rm64 || code == Code.Jmp_rm64) { symbol = new SymbolResult(symbol.Address, symbol.Text, symbol.Flags, MemorySize.QwordOffset); } } return(true); } if (Diffable && instructionOperand >= 0) { bool createDiffableSym; var opKind = instruction.GetOpKind(instructionOperand); if (opKind == OpKind.Memory) { long signedAddr; switch (addressSize) { case 0: signedAddr = (long)address; break; case 1: signedAddr = (sbyte)address; break; case 2: signedAddr = (short)address; break; case 4: signedAddr = (int)address; break; case 8: signedAddr = (long)address; break; default: throw new InvalidOperationException(); } if (signedAddr < 0) { signedAddr = -signedAddr; } createDiffableSym = IsDiffableSymbolAddress((ulong)signedAddr); } else { switch (instruction.Code) { case Code.Mov_rm32_imm32: case Code.Mov_r32_imm32: createDiffableSym = bitness == 32 && IsDiffableSymbolAddress(address) && instruction.Op0Kind == OpKind.Register; break; case Code.Mov_r64_imm64: createDiffableSym = IsDiffableSymbolAddress(address); break; default: switch (opKind) { case OpKind.FarBranch16: case OpKind.FarBranch32: case OpKind.NearBranch16: case OpKind.NearBranch32: case OpKind.NearBranch64: createDiffableSym = true; break; default: // eg. 'and eax,12345678' createDiffableSym = false; break; } break; } } if (createDiffableSym) { symbol = new SymbolResult(address, DIFFABLE_ADDRESS); return(true); } } return(false); }
public override bool TryGetFarBranchSymbol(int operand, Code code, ushort selector, uint address, out SymbolResult symbolSelector, out SymbolResult symbol, ref bool showBranchSize, ref NumberFormattingOptions options) { if (tryGetFarBranchSymbol != null) { return(tryGetFarBranchSymbol(selector, address, out symbolSelector, out symbol, ref showBranchSize, ref options)); } return(base.TryGetFarBranchSymbol(operand, code, selector, address, out symbolSelector, out symbol, ref showBranchSize, ref options)); }
public override string RequiredArgumentMissing(SymbolResult symbolResult) => message;
public override bool TryGetImmediateSymbol(int operand, Code code, ulong immediate, out SymbolResult symbol, ref NumberFormattingOptions options) { if (tryGetImmediateSymbol != null) { return(tryGetImmediateSymbol(immediate, out symbol, ref options)); } return(base.TryGetImmediateSymbol(operand, code, immediate, out symbol, ref options)); }
public override bool TryGetBranchSymbol(int operand, Code code, ulong address, out SymbolResult symbol, ref bool showBranchSize, ref NumberFormattingOptions options) { if (tryGetBranchSymbol != null) { return(tryGetBranchSymbol(address, out symbol, ref showBranchSize, ref options)); } return(base.TryGetBranchSymbol(operand, code, address, out symbol, ref showBranchSize, ref options)); }
public override bool TryGetDisplSymbol(int operand, Code code, ulong displacement, ref bool ripRelativeAddresses, out SymbolResult symbol, ref NumberFormattingOptions options) { if (tryGetDisplSymbol != null) { return(tryGetDisplSymbol(displacement, ref ripRelativeAddresses, out symbol, ref options)); } return(base.TryGetDisplSymbol(operand, code, displacement, ref ripRelativeAddresses, out symbol, ref options)); }