public Parameter AddParameter(Result result, CircuitMap circuitMap, Jam jam, int bitNumber)
            {
                Tracer.Assert(CircuitMap.IsPrimitive(jam.CircuitSymbol.Circuit));
                SymbolMap map = this.AddSymbol(circuitMap, (CircuitSymbol)jam.CircuitSymbol);

                return(map.AddParameter(result, circuitMap, jam, bitNumber));
            }
            public Result AddResult(CircuitMap circuitMap, Jam jam, int bitNumber)
            {
                Tracer.Assert(CircuitMap.IsPrimitive(jam.CircuitSymbol.Circuit));
                SymbolMap map = this.AddSymbol(circuitMap, (CircuitSymbol)jam.CircuitSymbol);

                return(map.AddResult(circuitMap, jam, bitNumber));
            }
Exemplo n.º 3
0
        private static SymbolicTransform GenerateOneTimesXToXTransform()
        {
            var constraint = new BasicSymbolicConstraint(
                s => s.Type == SymbolType.Multiplication,
                new BasicSymbolicConstraint[] {
                new BasicSymbolicConstraint(
                    s => s.Type == SymbolType.Number && (Number)s == Numbers.One),
                new BasicSymbolicConstraint()
            }
                );
            var varName  = "value";
            var inputMap = new SymbolMap(
                new SymbolMap[]
            {
                new SymbolMap(),     // placeholder for left part
                new SymbolMap(new SymbolName(varName))
            }
                );
            var context = inputMap.GenerateContext();

            var outputExpression = new Variable(varName);
            var outputFunction   = new Function(outputExpression, context);

            return(SymbolicTransform.New(constraint, inputMap, outputFunction));
        }
Exemplo n.º 4
0
        private static SymbolicTransform GenerateAdditionForceValuesLeftTransform()
        {
            // constraint where value is on the right, and
            // some non-left subtree is on the left
            var constraint = new BasicSymbolicConstraint(
                s => s.Type == SymbolType.Addition,
                new BasicSymbolicConstraint[] {
                new BasicSymbolicConstraint(
                    s => !s.Type.IsValue()
                    ),
                new BasicSymbolicConstraint(
                    s => s.Type.IsValue()
                    )
            }
                );

            var leftName  = "left";
            var rightName = "right";
            var inputMap  = new SymbolMap(new SymbolMap[]
            {
                new SymbolMap(new SymbolName(leftName)),
                new SymbolMap(new SymbolName(rightName))
            });
            var context = inputMap.GenerateContext();

            var outputExpression = new Addition(
                new Variable(rightName),
                new Variable(leftName)
                );
            var outputFunction = new Function(outputExpression, context);

            return(SymbolicTransform.New(constraint, inputMap, outputFunction));
        }
Exemplo n.º 5
0
        private Quotation ToQuotation(string message)
        {
            var c             = message.Split('|');
            var time          = Convert.ToInt32(c[0]);
            var quotationInfo = c[1].Split(',');
            var symbolIndex   = quotationInfo[0];

            if (!SymbolMap.ContainsKey(symbolIndex))
            {
                return(null);
            }
            var symbol = SymbolMap[symbolIndex];

            var sclare = Convert.ToDecimal(Math.Pow(10, symbol.Scale));

            var quotation = new Quotation(symbol, time)
            {
                Bid       = Convert.ToDecimal(quotationInfo[1]) / sclare,
                Direction = (Direction)Enum.ToObject(typeof(Direction), Convert.ToInt32(quotationInfo[2]))
            };

            //方向
            if (quotationInfo.Length >= 4)
            {
                quotation.Spread = Convert.ToInt32(quotationInfo[3]);
            }

            return(quotation);

            ;
        }
Exemplo n.º 6
0
        private static int GetAttributeDescriptorsCount(SymbolMap symbols)
        {
            const int SizeOfAttributeDescriptor = 40;
            var       maxPlus1 = symbols.BestMatch("AttributeDescriptors.MaxName++");
            var       first    = symbols.BestMatch("AttributeDescriptors.FirstName");

            if (first == 0 || maxPlus1 == 0)
            {
                return(0);
            }
            return((int)(maxPlus1 - first) / SizeOfAttributeDescriptor);
        }
            public SymbolMap AddSymbol(CircuitMap circuitMap, CircuitSymbol circuitSymbol)
            {
                SymbolMapKey key = new SymbolMapKey(circuitMap, circuitSymbol);
                SymbolMap    map;

                if (!this.symbols.TryGetValue(key, out map))
                {
                    map = new SymbolMap(key);
                    this.symbols.Add(key, map);
                }
                return(map);
            }
Exemplo n.º 8
0
        public Score Calculate(SymbolMap map)
        {
            var score = 0;

            var winLinesBuilder = new WinLinesBuilder(map);

            score += new CherryRules(ref winLinesBuilder).GetScore();
            score += new SevenRules(ref winLinesBuilder).GetScore();
            score += new BarRules(ref winLinesBuilder).GetScore();
            score += new CombinationRules(ref winLinesBuilder).GetScore();

            return(new Score {
                Value = score
            });
        }
Exemplo n.º 9
0
        private static uint GetStatic_LevelArea(byte[] data, SymbolMap symbols)
        {
            const string key = "LevelArea";

            var match = symbols.BestMatch(key);

            if (match != 0)
            {
                return(match);
            }

            if (Engine.Current == null)
            {
                return(0);
            }

            try
            {
                var pe    = new PEHeaderReader(data);
                var rdata = pe.ImageSectionHeaders.FirstOrDefault(h => h.Section.TrimEnd('\0') == ".rdata");
                var text  = pe.ImageSectionHeaders.FirstOrDefault(h => h.Section.TrimEnd('\0') == ".text");

                uint offset = rdata.VirtualAddress - rdata.PointerToRawData + pe.OptionalHeader32.ImageBase;

                var pName = (uint)(offset + new BinaryPattern(Encoding.ASCII.GetBytes("UIMinimapToggle")).NextMatch(data, (int)rdata.PointerToRawData, (int)rdata.SizeOfRawData));

                var pMethod = BitConverter.ToUInt32(data, BinaryPattern.Parse(
                                                        $"68{pName.ToPattern()}" +
                                                        "A3........" +
                                                        "C705................" +
                                                        "C705................" +
                                                        "E8........" +
                                                        "68........" +
                                                        "A3........" +
                                                        "C705........|........|").NextMatch(data, (int)text.PointerToRawData, (int)text.SizeOfRawData) + 51);

                if (Engine.Current.Memory.Reader.Read <byte>(pMethod + 0x00) == 0x8B &&
                    Engine.Current.Memory.Reader.Read <byte>(pMethod + 0x01) == 0x0D)
                {
                    var address = Engine.Current.Memory.Reader.Read <uint>(pMethod + 0x02);
                    symbols.Override(key, address);
                    return(address);
                }
            }
            catch { }

            return(0);
        }
Exemplo n.º 10
0
        private static uint GetStatic_LevelArea(byte[] data, SymbolMap symbols)
        {
            const string key = "LevelArea";

            var match = symbols.BestMatch(key);

            if (match != 0)
            {
                return(match);
            }

            if (Engine.Current == null)
            {
                return(0);
            }

            try
            {
                // TODO: Calculate offset from PE info.
                const uint offset = 0x801600;

                // TODO: Search in .rdata segment only.
                var pName = (uint)(offset + new BinaryPattern(Encoding.ASCII.GetBytes("UIMinimapToggle")).NextMatch(data, 0));

                // TODO: Search in .text segment only
                var pMethod = BitConverter.ToUInt32(data, BinaryPattern.Parse(
                                                        $"68{pName.ToPattern()}" +
                                                        "A3........" +
                                                        "C705................" +
                                                        "C705................" +
                                                        "E8........" +
                                                        "68........" +
                                                        "A3........" +
                                                        "C705........|........|").NextMatch(data, 0) + 51);

                if (Engine.Current.Memory.Reader.Read <byte>(pMethod + 0x00) == 0x8B &&
                    Engine.Current.Memory.Reader.Read <byte>(pMethod + 0x01) == 0x0D)
                {
                    var address = Engine.Current.Memory.Reader.Read <uint>(pMethod + 0x02);
                    symbols.Override(key, address);
                    return(address);
                }
            }
            catch { }

            return(0);
        }
Exemplo n.º 11
0
        public WinLinesBuilder(SymbolMap symbolMap)
        {
            TopLine = new List <Symbol>();
            TopLine.Add(symbolMap.TopLine.LeftSymbol);
            TopLine.Add(symbolMap.TopLine.CenterSymbol);
            TopLine.Add(symbolMap.TopLine.RightSymbol);

            CenterLine = new List <Symbol>();
            CenterLine.Add(symbolMap.CenterLine.LeftSymbol);
            CenterLine.Add(symbolMap.CenterLine.CenterSymbol);
            CenterLine.Add(symbolMap.CenterLine.RightSymbol);

            BottomLine = new List <Symbol>();
            BottomLine.Add(symbolMap.BottomLine.LeftSymbol);
            BottomLine.Add(symbolMap.BottomLine.CenterSymbol);
            BottomLine.Add(symbolMap.BottomLine.RightSymbol);
        }
Exemplo n.º 12
0
        private static uint GetStatic_LevelAreaName(byte[] data, SymbolMap symbols)
        {
            const string key = "LevelAreaName";

            var match = symbols.BestMatch(key);

            if (match != 0)
            {
                return(match);
            }

            var levelarea = symbols.BestMatch("LevelArea");

            if (levelarea != 0)
            {
                return(levelarea + 0x30);
            }

            return(0);
        }
Exemplo n.º 13
0
 private MainDeclaration()
 {
     LimFactory        = new Factory(new StrTable());
     ClassStack        = new Stack <ClassInfo>();
     MethodStack       = new Stack <MethodInfo>();
     NamespaceStack    = new Stack <uint>();
     LocalMap          = new SymbolMap <uint>();
     FileMap           = new Dictionary <uint, uint>();
     TypeMap           = new SymbolMap <Columbus.Lim.Asg.Nodes.Type.Type>();
     CgiMap            = new Dictionary <string, ClassGenericInstance>();
     UsesStack         = new Stack <HashSet <uint> >();
     MgiMap            = new Dictionary <string, MethodGenericInstance>();
     LLOCMap           = new LLOCMapType();
     ComponentTLOCMap  = new Dictionary <uint, Dictionary <uint, ulong> >();
     LimOrigin         = new LimOrigin();
     MainWatch         = new Stopwatch();
     RoslynWatch       = new Stopwatch();
     CSSIWatch         = new Stopwatch();
     LIMWatch          = new Stopwatch();
     Statistics        = new Statistic[1];
     Statistics[0]     = new Statistic();
     OverrideRelations = new OverrideRelations(LimFactory);
     FxCopTasks        = new LinkedList <Task>();
 }
 public void Remove(SymbolMap map)
 {
     this.symbols.Remove(new SymbolMapKey(map.CircuitMap, map.CircuitSymbol));
 }
Exemplo n.º 15
0
 public ActionResult <Score> Start(SymbolMap symbolMap)
 {
     return(_scoreRepo.Calculate(symbolMap));
 }
Exemplo n.º 16
0
        private void ProcessJavaScript(IList <InputGroup> inputGroups, SwitchParser switchParser, string outputPath, SymbolMap symbolMap, Encoding outputEncoding)
        {
            var        settings  = switchParser.JSSettings;
            TextWriter mapWriter = null;
            ISourceMap sourceMap = null;

            try
            {
                // if we want a symbols map, we need to set it up now
                if (symbolMap != null && !settings.PreprocessOnly)
                {
                    // if we specified the path, use it. Otherwise just use the output path with
                    // ".map" appended to the end. Eg: output.js => output.js.map
                    var symbolMapPath = symbolMap.Path.IsNullOrWhiteSpace()
                        ? outputPath + ".map"
                        : symbolMap.Path;

                    // create the map writer and the source map implementation.
                    // look at the Name attribute and implement the proper one.
                    // the encoding needs to be UTF-8 WITHOUT a BOM or it won't work.
                    if (!FileWriteOperation(symbolMapPath, switchParser.Clobber, () =>
                    {
                        mapWriter = new StreamWriter(symbolMapPath, false, new UTF8Encoding(false));
                        sourceMap = SourceMapFactory.Create(mapWriter, symbolMap.Name);
                        if (sourceMap != null)
                        {
                            // if we get here, the symbol map now owns the stream and we can null it out so
                            // we don't double-close it
                            mapWriter = null;
                            settings.SymbolsMap = sourceMap;

                            // copy some property values
                            sourceMap.SourceRoot = symbolMap.SourceRoot.IfNullOrWhiteSpace(null);
                            sourceMap.SafeHeader = symbolMap.SafeHeader.GetValueOrDefault(false);

                            // start the package
                            sourceMap.StartPackage(outputPath, symbolMapPath);
                        }

                        return(true);
                    }))
                    {
                        // could not write file
                        Log.LogError(Strings.CouldNotWriteOutputFile, symbolMapPath);
                    }
                }

                // save the original term settings. We'll make sure to set this back again
                // for the last item in the group, but we'll make sure it's TRUE for all the others.
                var originalTermSetting = settings.TermSemicolons;
                var currentSourceOrigin = SourceOrigin.Project;

                var parser = new JSParser();
                parser.CompilerError += (sender, ea) =>
                {
                    // if the input group isn't project, then we only want to report sev-0 errors.
                    // regardless, don't show any errors that have a severity lower (greater numeric value)
                    // than the warning level specified.
                    if ((currentSourceOrigin == SourceOrigin.Project || ea.Error.Severity == 0) &&
                        ea.Error.Severity <= switchParser.WarningLevel)
                    {
                        LogContextError(ea.Error);
                    }
                };

                var outputBuilder = new StringBuilder(8192);
                using (var writer = new StringWriter(outputBuilder, CultureInfo.InvariantCulture))
                {
                    for (var inputGroupIndex = 0; inputGroupIndex < inputGroups.Count; ++inputGroupIndex)
                    {
                        var inputGroup = inputGroups[inputGroupIndex];
                        currentSourceOrigin = inputGroup.Origin;

                        // for all but the last item, we want the term-semicolons setting to be true.
                        // but for the last entry, set it back to its original value
                        settings.TermSemicolons = inputGroupIndex < inputGroups.Count - 1 ? true : originalTermSetting;

                        if (settings.PreprocessOnly)
                        {
                            parser.EchoWriter = writer;

                            if (inputGroupIndex > 0)
                            {
                                // not the first group, so output the appropriate newline
                                // sequence before we output the group.
                                writer.Write(settings.LineTerminator);
                            }
                        }
                        else
                        {
                            // not preprocess-only, so make sure the echo writer is null
                            parser.EchoWriter = null;
                        }

                        // parse the input
                        var block = parser.Parse(inputGroup.Source, settings);
                        if (block != null && !settings.PreprocessOnly)
                        {
                            if (inputGroupIndex > 0)
                            {
                                // not the first group, so output the appropriate newline
                                // sequence before we output the group.
                                writer.Write(settings.LineTerminator);
                            }

                            // minify the AST to the output
                            if (settings.Format == JavaScriptFormat.JSON)
                            {
                                if (!JSONOutputVisitor.Apply(writer, block, settings))
                                {
                                    Log.LogError(Strings.InvalidJSONOutput);
                                }
                            }
                            else
                            {
                                OutputVisitor.Apply(writer, block, settings);
                            }
                        }
                    }
                }

                // write output
                if (!Log.HasLoggedErrors)
                {
                    if (!FileWriteOperation(outputPath, switchParser.Clobber, () =>
                    {
                        using (var writer = new StreamWriter(outputPath, false, outputEncoding))
                        {
                            // write the combined minified code
                            writer.Write(outputBuilder.ToString());

                            if (!settings.PreprocessOnly)
                            {
                                // give the map (if any) a chance to add something
                                settings.SymbolsMap.IfNotNull(m => m.EndFile(
                                                                  writer,
                                                                  settings.LineTerminator));
                            }
                        }

                        return(true);
                    }))
                    {
                        // could not write file
                        Log.LogError(Strings.CouldNotWriteOutputFile, outputPath);
                    }
                }
                else
                {
                    Log.LogWarning(Strings.DidNotMinify, outputPath, Strings.ThereWereErrors);
                    if (File.Exists(outputPath))
                    {
                        File.Delete(outputPath);
                    }
                }
            }
            finally
            {
                if (sourceMap != null)
                {
                    mapWriter           = null;
                    settings.SymbolsMap = null;
                    sourceMap.EndPackage();
                    sourceMap.Dispose();
                }

                if (mapWriter != null)
                {
                    mapWriter.Close();
                }
            }
        }
Exemplo n.º 17
0
        /// <summary>
        /// Main method for transliteration.
        /// </summary>
        /// <param name="input">The Unicode text to translate.</param>
        /// <param name="lang">Optional. If a language specific transliterates are available it will be used.</param>
        public static string Translate(string input, string lang = "en")
        {
            //setup defaults.
            if (!LangCharMap.TryGetValue(lang, out var langChar))
            {
                langChar = EmptyDictionary;
            }

            if (!SymbolMap.TryGetValue(lang, out var symbols))
            {
                symbols = SymbolMap["en"];
            }


            var sb = new StringBuilder(input.Length);

            //Loop though each character in the input string.
            for (var i = 0; i < input.Length; i++)
            {
                //Try direct langChar translation
                var ch = input.Substring(i, 1);
                if (langChar.TryGetValue(ch, out var foundLangChar))
                {
                    sb.Append(foundLangChar);
                    continue;
                }

                //Try using Char Map
                var used      = 0;
                var chCharMap = WalkTrie(i, input, CharMap, ref used);
                if (chCharMap is not null)
                {
                    //After walking the trie, we found a match,
                    //use what we found instead.
                    sb.Append(chCharMap);
                    //then update the number of characters
                    //we consumed in the input for this
                    //match to take place
                    i += used - 1;
                    continue;
                }

                //Try Diatric Map
                used = 0;
                var chDiatric = WalkTrie(i, input, DiatricMap, ref used);
                if (chDiatric is not null)
                {
                    sb.Append(chDiatric);
                    i += used - 1;
                    continue;
                }

                //Try symbol map
                if (symbols.TryGetValue(ch, out var foundSymbol))
                {
                    sb.Append(foundSymbol);
                    continue;
                }

                //otherwise, there's no mapping translation from the
                //current character to US-ASCII
                sb.Append(ch);
            }

            return(sb.ToString());
        }