Ejemplo n.º 1
0
        private void VisitField(BaseFieldDeclarationSyntax baseNode)
        {
            foreach (var variable in baseNode.Declaration.Variables)
            {
                MainDeclaration.Instance.RoslynWatch.Start( );
                var symbol = MainDeclaration.Instance.Model.GetDeclaredSymbol(variable);
                variable.CreateCommentNode(symbol);
                MainDeclaration.Instance.RoslynWatch.Stop( );

                if (symbol is IEventSymbol)
                {
                    var type     = symbol.GetType( );
                    var property = type.GetProperty("AssociatedField", BindingFlags.NonPublic |
                                                    BindingFlags.Instance);
                    symbol = ( IFieldSymbol )property.GetValue(symbol, null);
                }

                if (symbol != null)
                {
                    var limNode = SymbolBuilder.BuildDispatch <Attribute, IFieldSymbol>(symbol as IFieldSymbol);
                    MainDeclaration.Instance.LimOrigin.addCompIdCsharpIdLimIdToMap(
                        MainDeclaration.Instance.Component.Id, _map[variable], limNode.Id);
                    MainDeclaration.Instance.UsesStack.Pop( );
                }
            }
        }
        //Create a CIMSymbol from style item selected in the results gallery list box and
        //apply this newly created symbol to the feature layer currently selected in Contents pane
        private async void ApplyTheSelectedSymbol(StyleItem selectedStyleItemToApply)
        {
            if (selectedStyleItemToApply == null || string.IsNullOrEmpty(selectedStyleItemToApply.Key))
            {
                return;
            }

            await QueuedTask.Run(() =>
            {
                //Get the feature layer currently selected in the Contents pane
                FeatureLayer ftrLayer = MappingModule.ActiveTOC.MostRecentlySelectedLayer as FeatureLayer;

                if (ftrLayer == null)
                {
                    return;
                }

                //Create symbol from style item.
                CIMSymbol symbolFromStyleItem = selectedStyleItemToApply.GetObject() as CIMSymbol;

                //Set real world setting for created symbol = feature layer's setting
                //so that there isn't a mismatch between symbol and feature layer
                SymbolBuilder.SetRealWorldUnits(symbolFromStyleItem, ftrLayer.UsesRealWorldSymbolSizes);

                //Get simple renderer from feature layer
                CIMSimpleRenderer currentRenderer = ftrLayer.GetRenderer() as CIMSimpleRenderer;

                //Set current renderer's symbol reference = symbol reference of the newly created symbol
                currentRenderer.Symbol = SymbolBuilder.MakeSymbolReference(symbolFromStyleItem);

                //Update feature layer renderer with new symbol
                ftrLayer.SetRenderer(currentRenderer);
            });
        }
        public override void VisitNamespaceDeclaration(NamespaceDeclarationSyntax node)
        {
            MainDeclaration.Instance.RoslynWatch.Start();
            INamespaceSymbol namescpaceSymbol = MainDeclaration.Instance.Model.GetDeclaredSymbol(node);

            MainDeclaration.Instance.RoslynWatch.Stop();

            INamespaceSymbol actualNamespaceFromMergedNamespace = GetActualNamespaceFromMergedNamespace(namescpaceSymbol, node);

            Package limNode = SymbolBuilder.BuildDispatch <Package, INamespaceSymbol>(actualNamespaceFromMergedNamespace);

            MainDeclaration.Instance.LimOrigin.addCompIdCsharpIdLimIdToMap(MainDeclaration.Instance.Component.Id, _map[node], limNode.Id);

            node.CreateCommentNode(actualNamespaceFromMergedNamespace);
            node.CreateCommentForCU();

            base.VisitNamespaceDeclaration(node);

            if (MainDeclaration.Instance.NamespaceStack.Peek() > 0 && MainDeclaration.Instance.UsesStack.Count > 0)
            {
                Package package = (Package)MainDeclaration.Instance.LimFactory.getRef(
                    MainDeclaration.Instance.NamespaceStack.Peek()
                    );
                Commons.Common.AddUses(package);
                MainDeclaration.Instance.UsesStack.Pop();
            }

            limNode.SetCLOC(node);
            var location = node.GetLocation();

            location.CalculateFileLevelCommentLines();
            location.CalculateFileLevelNumberOfBranches();
        }
        private void AddPitchToSymbol(int keyCode)
        {
            Tone       tone = Tone.C;
            Accidental acc  = Accidental.None;

            int toneNumber = keyCode % Constants.TONES_IN_OCTAVE;

            var values = Enum.GetValues(typeof(Tone)).Cast <int>();

            for (int i = 0; i <= toneNumber; i++)
            {
                if (values.Contains(i))
                {
                    tone = (Tone)i;
                    acc  = Accidental.None;
                }
                else
                {
                    acc = Accidental.Sharp;
                }
            }

            if (currentSymbolBuilder == null)
            {
                currentSymbolBuilder = new SymbolBuilder();
            }
            currentSymbolBuilder.WithPitch(tone, acc, GetOctaveOffset(keyCode));
        }
        private void InsertRest(int deltaTicks)
        {
            SymbolBuilder symbolBuilder = new SymbolBuilder();

            symbolBuilder = AddLengthToSymbol(deltaTicks, symbolBuilder);
            Symbol rest = symbolBuilder.Build();

            composition.Tokens.Add(rest);
        }
Ejemplo n.º 6
0
        public void BuildAnonymousMethod <T>(T node, VisitNode <T> visit)
            where T : AnonymousFunctionExpressionSyntax
        {
            MainDeclaration.Instance.RoslynWatch.Start();
            IMethodSymbol symbol = MainDeclaration.Instance.Model.GetSymbolInfo(node).Symbol as IMethodSymbol;

            MainDeclaration.Instance.RoslynWatch.Stop();

            Method limNode = null;

            if (symbol != null)
            {
                var anonymousObjectMemberDeclaration = node.GetParent <AnonymousObjectMemberDeclaratorSyntax>();
                limNode = SymbolBuilder.BuildDispatch <Method, IMethodSymbol>(symbol, anonymousObjectMemberDeclaration == null);
                MainDeclaration.Instance.LimOrigin.addCompIdCsharpIdLimIdToMap(MainDeclaration.Instance.Component.Id, _map[node], limNode.Id);
                node.CreateCommentNode(symbol);

                limNode.Name = _crossEdgeFiller.GetOrCreateNode <Csharp.Asg.Nodes.Expression.AnonymousFunctionExpressionSyntax>(node).Identifier;
                var   temp   = MainDeclaration.Instance.MethodStack.Pop();
                Scope parent = (Scope)MainDeclaration.Instance.LimFactory.getRef(MainDeclaration.Instance.MethodStack.Peek().Id);
                MainDeclaration.Instance.MethodStack.Push(temp);
                limNode.MangledName = parent.MangledName + "." + limNode.Name;
                if (anonymousObjectMemberDeclaration != null)
                {
                    Commons.Common.Safe_Edge(parent, "HasMember", limNode.Id);
                }

                limNode.DemangledName       = limNode.MangledName;
                limNode.IsCompilerGenerated = true;
            }
            else
            {
                //TODO write warning/error
                return;
            }

            visit(node as T);

            if (MainDeclaration.Instance.MethodStack.Count > 1)
            {
                Utils.Info.MethodInfo mi = MainDeclaration.Instance.MethodStack.Pop();
                if (node.Body.Kind() == SyntaxKind.Block)
                {
                    mi = Commons.Common.FillMethodMetrics(node.Body, mi);
                }
                else
                {
                    mi.NOB = 1;
                    mi.NOS = 1;
                }
                Commons.Common.FillFromMethodStack(mi);
            }

            limNode.SetCLOC(node);
        }
Ejemplo n.º 7
0
        public override void VisitArrowExpressionClause(ArrowExpressionClauseSyntax node)
        {
            if (node.Parent.Kind( ) != SyntaxKind.PropertyDeclaration ||
                node.Parent.Kind( ) != SyntaxKind.IndexerDeclaration)
            {
                return;
            }
            MainDeclaration.Instance.RoslynWatch.Start( );
            var propertySymbol = ( IPropertySymbol )MainDeclaration.Instance.Model.GetDeclaredSymbol(node.Parent);

            MainDeclaration.Instance.RoslynWatch.Stop( );
            var limNode = SymbolBuilder.BuildDispatch <Method, IMethodSymbol>(propertySymbol.GetMethod);

            if (propertySymbol.GetMethod.OverriddenMethod != null)
            {
                if (propertySymbol.GetMethod.OverriddenMethod.IsInMetadata( ))
                {
                    MainDeclaration.Instance
                    .OverrideRelations.AddOverride(
                        ( Method )propertySymbol.GetMethod.OverriddenMethod.ConvertToLimNode( ),
                        limNode
                        );
                }
                else
                {
                    SyntaxNode dummyNode;
                    var        overriddenMethodDefinition =
                        propertySymbol.GetMethod.OverriddenMethod.GetDefinition(out dummyNode);
                    if (overriddenMethodDefinition != null &&
                        overriddenMethodDefinition.Kind == propertySymbol.GetMethod.OverriddenMethod.Kind)
                    {
                        var overriddenMethodSymbol = ( Method )overriddenMethodDefinition.ConvertToLimNode( );
                        MainDeclaration.Instance
                        .OverrideRelations.AddOverride(
                            overriddenMethodSymbol,
                            limNode
                            );
                    }
                }
            }
            limNode.SetCLOC(node);

            MainDeclaration.Instance.LimOrigin.addCompIdCsharpIdLimIdToMap(MainDeclaration.Instance.Component.Id,
                                                                           _map[node], limNode.Id);
            node.CreateCommentNode(propertySymbol.GetMethod);

            base.VisitArrowExpressionClause(node);

            if (MainDeclaration.Instance.MethodStack.Count > 0)
            {
                Commons.Common.SetMetrics(node);
            }
        }
        private void EndCurrentNote(MidiEvent evt)
        {
            if (currentSymbolBuilder == null)
            {
                return;
            }

            AddLengthToSymbol(evt.DeltaTicks, currentSymbolBuilder);
            Symbol note = currentSymbolBuilder.Build();

            composition.Tokens.Add(note);
            currentSymbolBuilder = null;
        }
Ejemplo n.º 9
0
        public override void VisitEnumMemberDeclaration(EnumMemberDeclarationSyntax node)
        {
            MainDeclaration.Instance.RoslynWatch.Start( );
            var symbol = MainDeclaration.Instance.Model.GetDeclaredSymbol(node);

            MainDeclaration.Instance.RoslynWatch.Stop( );
            node.CreateCommentNode(symbol);
            var limNode = SymbolBuilder.BuildDispatch <Attribute, IFieldSymbol>(symbol);

            MainDeclaration.Instance.LimOrigin.addCompIdCsharpIdLimIdToMap(MainDeclaration.Instance.Component.Id,
                                                                           _map[node], limNode.Id);
            MainDeclaration.Instance.UsesStack.Pop( );
        }
Ejemplo n.º 10
0
        private void PharmaOne()
        {
            ulong         tester;
            List <char>   intermediate = new List <char>();   /* 131070 -> 17 bits */
            StringBuilder rowPattern   = new StringBuilder(); /* 17 * 2 + 1 */
            int           inputLength  = barcodeData.Length;

            if (inputLength > 6)
            {
                throw new InvalidDataLengthException("Pharmacode: Input data too long.");
            }

            tester = ulong.Parse(barcodeMessage, CultureInfo.CurrentCulture);
            if ((tester < 3) || (tester > 131070))
            {
                throw new InvalidDataException("Pharmacode: Input data out of range.");
            }

            do
            {
                if ((tester & 1) == 0)
                {
                    intermediate.Add('W');
                    tester = (tester - 2) / 2;
                }

                else
                {
                    intermediate.Add('N');
                    tester = (tester - 1) / 2;
                }
            } while (tester != 0);

            int iLength = intermediate.Count;

            for (int c = iLength - 1; c >= 0; c--)
            {
                if (intermediate[c] == 'W')
                {
                    rowPattern.Append("32");
                }

                else
                {
                    rowPattern.Append("12");
                }
            }

            // Expand row into the symbol data.
            SymbolBuilder.ExpandSymbolRow(Symbol, rowPattern, 0.0f);
        }
Ejemplo n.º 11
0
        private void Code39()
        {
            int           index;
            char          checkDigit;
            int           inputLength = barcodeData.Length;
            StringBuilder rowPattern  = new StringBuilder();

            if (inputLength > 74)
            {
                throw new InvalidDataLengthException("Code 39: Input data too long.");
            }

            for (int i = 0; i < inputLength; i++)
            {
                if (CharacterSets.Code39Set.IndexOf(barcodeData[i]) == -1)
                {
                    throw new InvalidDataException("Code 39: Invalid characters in input data.");
                }
            }

            rowPattern.Append(Code39Table[43]);
            for (int i = 0; i < inputLength; i++)
            {
                index = CharacterSets.Code39Set.IndexOf(barcodeData[i]);
                rowPattern.Append(Code39Table[index]);
            }

            if (optionalCheckDigit)
            {
                checkDigit = CheckSum.Mod43CheckDigit(barcodeData);
                index      = CharacterSets.Code39Set.IndexOf(checkDigit);
                rowPattern.Append(Code39Table[index]);
                checkDigitText = checkDigit.ToString();
            }

            rowPattern.Append(Code39Table[43]);

            if (symbolId == Symbology.LOGMARS || encodingMode == EncodingMode.HIBC)
            {
                rowPattern.Replace('2', '3');
            }

            barcodeText = barcodeMessage;

            // Expand the row pattern into the symbol data.
            SymbolBuilder.ExpandSymbolRow(Symbol, rowPattern, 0.0f);
        }
Ejemplo n.º 12
0
        /// <summary>
        /// </summary>
        /// <param name="symbol"></param>
        /// <param name="calledSymbol"></param>
        /// <param name="nodeFilter"></param>
        public static void CreateMethodCallEdge(ISymbol symbol, ISymbol calledSymbol, NodeFilter nodeFilter = null)
        {
            var  isNeedToFilter = nodeFilter != null;
            var  methodSymbol   = symbol as IMethodSymbol;
            Base node;

            if (methodSymbol != null && methodSymbol.IsGenericMethod)
            {
                node = methodSymbol.GetMGI(calledSymbol as IMethodSymbol);
                var id = MainDeclaration.Instance.LimFactory.createTypeFormerType(node.Id).Id;
                MainDeclaration.Instance.LimFactory.addTypeFormer(id);
                var type = MainDeclaration.Instance.LimFactory.endType( );
                if (isNeedToFilter)
                {
                    nodeFilter(id);
                    nodeFilter(type.Id);
                }
            }
            else
            {
                if (isNeedToFilter)
                {
                    node = SymbolBuilder.BuildDispatch <Method, IMethodSymbol>(( IMethodSymbol )calledSymbol);
                    (( Member )node).IsCompilerGenerated = true;
                    Commons.Common.FillFromMethodStack(MainDeclaration.Instance.MethodStack.Pop( ));
                }
                else
                {
                    node = calledSymbol.ConvertToLimNode( );
                }
            }
            if (isNeedToFilter)
            {
                nodeFilter(node.Id);
            }
            var methodCall = MainDeclaration.Instance.LimFactory.createMethodCall(node.Id);

            if (isNeedToFilter)
            {
                nodeFilter(methodCall.Id);
            }
            MainDeclaration.Instance.MethodStack.Peek( )
            .Calls.Add(new KeyValuePair <uint, bool>(methodCall.Id, isNeedToFilter));
        }
Ejemplo n.º 13
0
        private void Flattermarken()
        {
            StringBuilder rowPattern  = new StringBuilder();
            int           inputLength = barcodeData.Length;

            if (inputLength > 90)
            {
                throw new InvalidDataLengthException("Flattermarken: Input data too long.");
            }

            for (int l = 0; l < inputLength; l++)
            {
                int value = barcodeData[l] - '0';
                rowPattern.Append(FlatTable[value]);
            }

            // Expand the row pattern into the symbol data.
            SymbolBuilder.ExpandSymbolRow(Symbol, rowPattern, 0.0f);
        }
Ejemplo n.º 14
0
        private void KoreaPost()
        {
            int           sum = 0;
            int           checkValue;
            int           value;
            int           inputLength = barcodeData.Length;
            StringBuilder rowPattern  = new StringBuilder();

            if (inputLength > 6)
            {
                throw new InvalidDataLengthException("Korean Post: Input data too long.");
            }

            if (inputLength < 6)
            {
                string zeros = new String('0', 6 - inputLength);
                barcodeData = ArrayExtensions.Insert(barcodeData, 0, zeros);
                inputLength = barcodeData.Length;
            }

            sum = 0;
            for (int l = 0; l < 6; l++)
            {
                sum += barcodeData[l] - '0';
            }

            checkValue  = (10 - (sum % 10)) % 10;
            barcodeData = ArrayExtensions.Insert(barcodeData, barcodeData.Length, checkValue.ToString(CultureInfo.CurrentCulture));
            for (int l = 5; l >= 0; l--)
            {
                value = barcodeData[l] - '0';
                rowPattern.Append(KoreanTable[value]);
            }

            value = barcodeData[6] - '0';
            rowPattern.Append(KoreanTable[value]);
            barcodeText = new string(barcodeData);

            // Expand the row pattern into the symbol data.
            SymbolBuilder.ExpandSymbolRow(Symbol, rowPattern, 0.0f);
        }
Ejemplo n.º 15
0
        private void FIM()
        {
            StringBuilder rowPattern  = new StringBuilder();
            int           inputLength = barcodeData.Length;

            if (inputLength > 1)
            {
                throw new InvalidDataLengthException("FIM Code: Input data too long.");
            }

            switch ((char)barcodeData[0])
            {
            case 'a':
            case 'A':
                rowPattern.Append("111515111");
                break;

            case 'b':
            case 'B':
                rowPattern.Append("13111311131");
                break;

            case 'c':
            case 'C':
                rowPattern.Append("11131313111");
                break;

            case 'd':
            case 'D':
                rowPattern.Append("1111131311111");
                break;

            default:
                throw new InvalidDataException("FIM Code: Invalid characters in input data.");
            }

            // Expand the row pattern into the symbol data.
            SymbolBuilder.ExpandSymbolRow(Symbol, rowPattern, 0.0f);
        }
Ejemplo n.º 16
0
        public override void VisitDelegateDeclaration(DelegateDeclarationSyntax node)
        {
            MainDeclaration.Instance.RoslynWatch.Start();
            INamedTypeSymbol symbol = MainDeclaration.Instance.Model.GetDeclaredSymbol(node);

            MainDeclaration.Instance.RoslynWatch.Stop();

            Class limNode = SymbolBuilder.BuildDispatch <Class, INamedTypeSymbol>(symbol);

            MainDeclaration.Instance.LimOrigin.addCompIdCsharpIdLimIdToMap(MainDeclaration.Instance.Component.Id, _map[node], limNode.Id);

            node.CreateCommentNode(symbol);

            base.VisitDelegateDeclaration(node);

            if (MainDeclaration.Instance.ClassStack.Count > 0)
            {
                Commons.Common.FillFromClassStack();
            }

            limNode.SetCLOC(node);
        }
Ejemplo n.º 17
0
        private void Telepen()
        {
            int           check_digit;
            int           count       = 0;
            StringBuilder rowPattern  = new StringBuilder();
            int           inputLength = barcodeData.Length;

            if (inputLength > 30)
            {
                throw new InvalidDataLengthException("Telepen: Input data too long.");
            }

            // Start character.
            rowPattern.Append(TeleTable['_']);

            for (int i = 0; i < inputLength; i++)
            {
                if (barcodeData[i] > 126)
                {
                    throw new InvalidDataException("Telpen: Invalid characters in input data.");   // Cannot encode extended ASCII.
                }
                rowPattern.Append(TeleTable[barcodeData[i]]);
                count += barcodeData[i];
            }

            check_digit = 127 - (count % 127);
            if (check_digit == 127)
            {
                check_digit = 0;
            }

            rowPattern.Append(TeleTable[check_digit]);
            // Stop character.
            rowPattern.Append(TeleTable['z']);

            // Expand row into the symbol data.
            SymbolBuilder.ExpandSymbolRow(Symbol, rowPattern, 0.0f);
        }
        private SymbolBuilder AddLengthToSymbol(int deltaTicks, SymbolBuilder builder)
        {
            double amountOfBeatNotes = (double)deltaTicks / (double)sequence.Division;
            double amountOfFullNotes = amountOfBeatNotes / currentTimeSignature.Denominator.Value;

            int n           = 0;
            int denominator = (int)Math.Pow(2, n);

            while (1f / denominator > amountOfFullNotes)
            {
                n++;
                denominator = (int)Math.Pow(2, n);
            }
            double baseNoteLength = 1f / denominator;
            int    amountOfDots   = Math.Min(4, (int)Math.Log(-baseNoteLength / (amountOfFullNotes - 2 * baseNoteLength), 2));

            if (builder == null)
            {
                builder = new SymbolBuilder();
            }
            builder.WithLength(denominator, amountOfDots);
            return(builder);
        }
Ejemplo n.º 19
0
        private void VisitNamedType <T>(BaseTypeDeclarationSyntax node, VisitNode <T> visitor)
            where T : CSharpSyntaxNode
        {
            MainDeclaration.Instance.RoslynWatch.Start();
            INamedTypeSymbol symbol = MainDeclaration.Instance.Model.GetDeclaredSymbol(node);

            MainDeclaration.Instance.RoslynWatch.Stop();

            Class limNode = SymbolBuilder.BuildDispatch <Class, INamedTypeSymbol>(symbol);

            MainDeclaration.Instance.LimOrigin.addCompIdCsharpIdLimIdToMap(MainDeclaration.Instance.Component.Id, _map[node], limNode.Id);

            node.CreateCommentNode(symbol);

            visitor(node as T);


            if (MainDeclaration.Instance.ClassStack.Count > 0)
            {
                Commons.Common.FillFromClassStack();
            }

            limNode.SetCLOC(node);
        }
Ejemplo n.º 20
0
        public Token Convert(LilypondTokenEnumerator enumerator)
        {
            var input = enumerator.Current;
            var match = noteRegex.Match(input.TokenText);

            if (match.Success)
            {
                SymbolBuilder builder    = new SymbolBuilder();
                var           tone       = GetToneFromLetter(match.Groups[1].Value);
                Accidental    accidental = Accidental.None;
                if (match.Groups[2].Success)
                {
                    accidental = match.Groups[2].Value == "is" ? Accidental.Sharp : Accidental.Flat;
                }
                // determine octave
                MoveToClosestOctaveOffset(tone);
                previousNoteTone = tone;
                if (match.Groups[3].Success)
                {
                    UpdateOctaveOffset(match.Groups[3].Value);
                }
                // set pitch
                builder.WithPitch(tone, accidental, octaveOffset);
                // determine length
                if (int.TryParse(match.Groups[4].Value, out int denominator))
                {
                    int dots = match.Groups[5].Length;
                    builder.WithLength(denominator, dots);
                }
                return(builder.Build());
            }
            else
            {
                throw new InvalidOperationException("Not a note that can be read");
            }
        }
Ejemplo n.º 21
0
        /// <summary>
        /// LIM ASG building phase
        /// </summary>
        /// <param name="map">Roslyn node and C# ASG ids map</param>
        /// <param name="crossEdgeFiller">C# ASG cross edge filler object</param>
        private static void BuildLIMASG(Dictionary <Microsoft.CodeAnalysis.CSharp.CSharpSyntaxNode, uint> map, CrossEdgeFiller crossEdgeFiller)
        {
            if (!MainDeclaration.Instance.LocalMap.ContainsKey(MainDeclaration.Instance.Model.Compilation.Assembly.GlobalNamespace))
            {
                MainDeclaration.Instance.LocalMap.Add(MainDeclaration.Instance.Model.Compilation.Assembly.GlobalNamespace, MainDeclaration.Instance.LimFactory.Root);
                MainDeclaration.Instance.Root = MainDeclaration.Instance.LimFactory.getRef(MainDeclaration.Instance.LimFactory.Root) as Lim.Asg.Nodes.Logical.Package;
                SymbolBuilder.BuildDispatch <Lim.Asg.Nodes.Logical.Package, INamespaceSymbol>(MainDeclaration.Instance.Model.Compilation.Assembly.GlobalNamespace);
                MainDeclaration.Instance.UsesStack.Pop();
            }

            Commons.Common.Safe_Edge(MainDeclaration.Instance.Root, "BelongsTo", MainDeclaration.Instance.Component.Id);

            if (!GetAlreadyContain(MainDeclaration.Instance.Component))
            {
                MainDeclaration.Instance.LimFactory.ComponentRootRef.addContains(MainDeclaration.Instance.Component);
            }

            MainDeclaration.Instance.RoslynWatch.Start();
            var root = MainDeclaration.Instance.Model.SyntaxTree.GetRoot();

            MainDeclaration.Instance.RoslynWatch.Stop();
            //Visitor.Visit(root, ref map, crossEdgeFiller);
            RoslynVisitor.GetInstance(map, crossEdgeFiller).Visit(root);
        }
Ejemplo n.º 22
0
        public Token Convert(LilypondTokenEnumerator enumerator)
        {
            var input = enumerator.Current;
            var match = regex.Match(input.TokenText);

            if (match.Success)
            {
                SymbolBuilder builder = new SymbolBuilder();
                if (int.TryParse(match.Groups[1].Value, out int denominator))
                {
                    int dots = match.Groups[2].Length;
                    builder.WithLength(denominator, dots);
                    return(builder.Build());
                }
                else
                {
                    throw new InvalidOperationException("Not a rest that can be converted");
                }
            }
            else
            {
                throw new InvalidOperationException("Not a rest that can be converted");
            }
        }
Ejemplo n.º 23
0
        private void Codabar()
        {
            StringBuilder rowPattern  = new StringBuilder();
            int           inputLength = barcodeData.Length;

            for (int i = 0; i < inputLength; i++)
            {
                if (CharacterSets.CodaBarSet.IndexOf(barcodeData[i]) == -1)
                {
                    throw new InvalidDataException("Codabar: Invalid characters in input data.");
                }
            }

            // Codabar must begin and end with the characters A, B, C or D
            if ((barcodeData[0] != 'A') && (barcodeData[0] != 'B') && (barcodeData[0] != 'C') && (barcodeData[0] != 'D'))
            {
                throw new InvalidDataException("Codabar: Invalid start character in input data.");
            }

            if ((barcodeData[inputLength - 1] != 'A') && (barcodeData[inputLength - 1] != 'B') &&
                (barcodeData[inputLength - 1] != 'C') && (barcodeData[inputLength - 1] != 'D'))
            {
                throw new InvalidDataException("Codabar: Invalid stop character in input data.");
            }

            for (int i = 0; i < inputLength; i++)
            {
                int iValue = CharacterSets.CodaBarSet.IndexOf(barcodeData[i]);
                rowPattern.Append(CodabarTable[iValue]);
            }

            barcodeText = new String(barcodeData);

            // Expand row into the symbol data.
            SymbolBuilder.ExpandSymbolRow(Symbol, rowPattern, 0.0f);
        }
Ejemplo n.º 24
0
        private void Code16K()
        {
            int  rowsRequired;
            int  padding;
            bool fState;
            int  mode, lastSet, currentSet;

            char[] set = new char[160];
            char[] fset = new char[160];
            int    m, position;

            int[]         values = new int[160];
            int           barCharacters;
            float         glyphCount;
            int           glyphs;
            int           checkValue1, checkValue2;
            int           checkSum1, checkSum2;
            int           inputLength;
            int           j = 0;
            StringBuilder rowPattern;

            inputLength = barcodeData.Length;
            if (inputLength > 157)
            {
                throw new InvalidDataLengthException("Code 16K: Input data too long.");
            }

            // Initialise set and fset to spaces.
            for (int i = 0; i < set.Length; i++)
            {
                set[i]  = ' ';
                fset[i] = ' ';
            }

            barCharacters = 0;
            // Detect extended ASCII characters.
            for (int i = 0; i < inputLength; i++)
            {
                if (barcodeData[i] >= 128)
                {
                    fset[i] = 'f';
                }
            }

            // Decide when to latch to extended mode - Annex E note 3.
            for (int i = 0; i < inputLength; i++)
            {
                if (fset[i] == 'f')
                {
                    j++;
                }

                else
                {
                    j = 0;
                }

                if (j >= 5)
                {
                    for (int k = i; k > (i - 5); k--)
                    {
                        fset[k] = 'F';
                    }
                }

                if ((j >= 3) && (i == (inputLength - 1)))
                {
                    for (int k = i; k > (i - 3); k--)
                    {
                        fset[k] = 'F';
                    }
                }
            }

            // Decide if it is worth reverting to 646 encodation for a few characters as described in 4.3.4.2 (d).
            for (int i = 1; i < inputLength; i++)
            {
                if ((fset[i - 1] == 'F') && (fset[i] == ' '))
                {
                    // Detected a change from 8859-1 to 646 - count how long for.
                    for (j = 0; (fset[i + j] == ' ') && ((i + j) < inputLength); j++)
                    {
                        ;
                    }
                    if ((j < 5) || ((j < 3) && ((i + j) == (inputLength - 1))))
                    {
                        // Uses the same figures recommended by Annex E note 3.
                        // Change to shifting back rather than latching back.
                        for (int k = 0; k < j; k++)
                        {
                            fset[i + k] = 'n';
                        }
                    }
                }
            }

            // Decide on mode using of ISO 15417 Annex E
            int listIndex   = 0;
            int sourceIndex = 0;

            mode = GetMode(barcodeData[sourceIndex]);
            if (barcodeData[sourceIndex] == '[')
            {
                mode = ABORC;
            }

            for (int i = 0; i < 170; i++)
            {
                encodingList[0, i] = 0;
            }

            do
            {
                encodingList[1, listIndex] = mode;
                while ((encodingList[1, listIndex] == mode) && (sourceIndex < inputLength))
                {
                    encodingList[0, listIndex]++;
                    sourceIndex++;
                    if (sourceIndex >= inputLength)
                    {
                        break;
                    }

                    mode = GetMode(barcodeData[sourceIndex]);
                    if (isGS1 && barcodeData[sourceIndex] == '[')
                    {
                        mode = ABORC;
                    }
                }

                listIndex++;
            } while (sourceIndex < inputLength);

            DxSmooth(ref listIndex);
            // Put set data into set[].
            position = 0;
            for (int i = 0; i < listIndex; i++)
            {
                for (j = 0; j < encodingList[0, i]; j++)
                {
                    switch (encodingList[1, i])
                    {
                    case SHIFTA:
                        set[position] = 'a';
                        break;

                    case LATCHA:
                        set[position] = 'A';
                        break;

                    case SHIFTB:
                        set[position] = 'b';
                        break;

                    case LATCHB:
                        set[position] = 'B';
                        break;

                    case LATCHC:
                        set[position] = 'C';
                        break;
                    }

                    position++;
                }
            }

            // Adjust for strings which start with shift characters - make them latch instead.
            if (set[0] == 'a')
            {
                int idx = 0;
                do
                {
                    set[idx] = 'A';
                    idx++;
                } while (set[idx] == 'a');
            }

            if (set[0] == 'b')
            {
                int idx = 0;
                do
                {
                    set[idx] = 'B';
                    idx++;
                } while (set[idx] == 'b');
            }

            // Watch out for odd-length Mode C blocks.
            int count = 0;
            int x;

            for (x = 0; x < position; x++)
            {
                if (set[x] == 'C')
                {
                    if (barcodeData[x] == '[')
                    {
                        if ((count & 1) > 0)
                        {
                            if ((x - count) != 0)
                            {
                                set[x - count] = 'B';
                            }

                            else
                            {
                                set[x - 1] = 'B';
                            }
                        }

                        count = 0;
                    }

                    else
                    {
                        count++;
                    }
                }

                else
                {
                    if ((count & 1) > 0)
                    {
                        if ((x - count) != 0)
                        {
                            set[x - count] = 'B';
                        }

                        else
                        {
                            set[x - 1] = 'B';
                        }
                    }

                    count = 0;
                }
            }

            if ((count & 1) > 0)
            {
                if ((x - count) != 0)
                {
                    set[x - count] = 'B';
                }

                else
                {
                    set[x - 1] = 'B';
                }
            }

            for (x = 1; x < position - 1; x++)
            {
                if ((set[x] == 'C') && ((set[x - 1] == 'B') && (set[x + 1] == 'B')))
                {
                    set[x] = 'B';
                }
            }

            // Now we can calculate how long the barcode is going to be - and stop it from being too long.
            lastSet    = ' ';
            glyphCount = 0.0f;

            for (int i = 0; i < inputLength; i++)
            {
                if ((set[i] == 'a') || (set[i] == 'b'))
                {
                    glyphCount = glyphCount + 1.0f;
                }

                if ((fset[i] == 'f') || (fset[i] == 'n'))
                {
                    glyphCount = glyphCount + 1.0f;
                }

                if (((set[i] == 'A') || (set[i] == 'B')) || (set[i] == 'C'))
                {
                    if (set[i] != lastSet)
                    {
                        lastSet    = set[i];
                        glyphCount = glyphCount + 1.0f;
                    }
                }

                if ((set[i] == 'C') && (barcodeData[i] != '['))
                {
                    glyphCount = glyphCount + 0.5f;
                }

                else
                {
                    glyphCount = glyphCount + 1.0f;
                }
            }

            if (isGS1 && (set[0] != 'A'))   // FNC1 can be integrated with mode character.
            {
                glyphCount--;
            }

            if (glyphCount > 77.0)
            {
                throw new InvalidDataLengthException("Code 16K: Input data too long.");
            }

            // Calculate how tall the symbol will be.
            glyphCount   = glyphCount + 2.0f;
            glyphs       = (int)glyphCount;
            rowsRequired = (glyphs / 5);
            if (glyphs % 5 > 0)
            {
                rowsRequired++;
            }

            if (rowsRequired == 1)
            {
                rowsRequired = 2;
            }

            // Start with the mode character - Table 2.
            m = 0;
            switch (set[0])
            {
            case 'A':
                m = 0;
                break;

            case 'B':
                m = 1;
                break;

            case 'C':
                m = 2;
                break;
            }

            /*if (symbol->output_options & READER_INIT)
             * {
             *  if (m == 2)
             *      m = 5;
             *
             *  if (isGS1)
             *  {
             *      strcpy(symbol->errtxt, "Cannot use both GS1 mode and Reader Initialisation (D22)");
             *      return ZINT_ERROR_INVALID_OPTION;
             *  }
             *
             *  else
             *  {
             *      if ((set[0] == 'B') && (set[1] == 'C'))
             *          m = 6;
             *  }
             *
             *  values[bar_characters] = (7 * (rowsRequired - 2)) + m; // See 4.3.4.2
             *  values[bar_characters + 1] = 96; // FNC3.
             *  bar_characters += 2;
             *  }
             *
             * else
             * {*/
            if (isGS1)
            {
                // Integrate FNC1.
                switch (set[0])
                {
                case 'B':
                    m = 3;
                    break;

                case 'C':
                    m = 4;
                    break;
                }
            }

            else
            {
                if ((set[0] == 'B') && (set[1] == 'C'))
                {
                    m = 5;
                }

                if (((set[0] == 'B') && (set[1] == 'B')) && (set[2] == 'C'))
                {
                    m = 6;
                }
            }

            values[barCharacters] = (7 * (rowsRequired - 2)) + m; // See 4.3.4.2
            barCharacters++;

            currentSet = set[0];
            fState     = false; // fState remembers if we are in Extended ASCII mode (value true) or in ISO/IEC 646 mode (value false)

            if (fset[0] == 'F')
            {
                switch (currentSet)
                {
                case 'A':
                    values[barCharacters]     = 101;
                    values[barCharacters + 1] = 101;
                    break;

                case 'B':
                    values[barCharacters]     = 100;
                    values[barCharacters + 1] = 100;
                    break;
                }

                barCharacters += 2;
                fState         = true;
            }

            position = 0;

            // Encode the data.
            do
            {
                if ((position != 0) && (set[position] != set[position - 1]))
                {
                    /* Latch different code set */
                    switch (set[position])
                    {
                    case 'A':
                        values[barCharacters] = 101;
                        barCharacters++;
                        currentSet = 'A';
                        break;

                    case 'B':
                        values[barCharacters] = 100;
                        barCharacters++;
                        currentSet = 'B';
                        break;

                    case 'C':
                        if (!((position == 1) && (set[0] == 'B')))
                        {
                            // Not Mode C, Shift B.
                            if (!((position == 2) && ((set[0] == 'B') && (set[1] == 'B'))))
                            {
                                // Not Mode C, Double Shift B.
                                values[barCharacters] = 99;
                                barCharacters++;
                            }
                        }

                        currentSet = 'C';
                        break;
                    }
                }

                if (position != 0)
                {
                    if ((fset[position] == 'F') && (fState == false))
                    {
                        // Latch beginning of extended mode.
                        switch (currentSet)
                        {
                        case 'A':
                            values[barCharacters]     = 101;
                            values[barCharacters + 1] = 101;
                            break;

                        case 'B':
                            values[barCharacters]     = 100;
                            values[barCharacters + 1] = 100;
                            break;
                        }

                        barCharacters += 2;
                        fState         = true;
                    }

                    if ((fset[position] == ' ') && (fState == true))
                    {
                        // Latch end of extended mode.
                        switch (currentSet)
                        {
                        case 'A':
                            values[barCharacters]     = 101;
                            values[barCharacters + 1] = 101;
                            break;

                        case 'B':
                            values[barCharacters]     = 100;
                            values[barCharacters + 1] = 100;
                            break;
                        }

                        barCharacters += 2;
                        fState         = false;
                    }
                }

                if ((fset[glyphs] == 'f') || (fset[glyphs] == 'n'))
                {
                    // Shift extended mode.
                    switch (currentSet)
                    {
                    case 'A':
                        values[barCharacters] = 101;     /* FNC 4 */
                        break;

                    case 'B':
                        values[barCharacters] = 100;     /* FNC 4 */
                        break;
                    }

                    barCharacters++;
                }

                if ((set[glyphs] == 'a') || (set[glyphs] == 'b'))
                {
                    // Insert shift character.
                    values[barCharacters] = 98;
                    barCharacters++;
                }

                if (!((isGS1) && (barcodeData[position] == '[')))
                {
                    switch (set[position])
                    { /* Encode data characters */
                    case 'A':
                    case 'a':
                        Code16KSetA(barcodeData[position], values, ref barCharacters);
                        position++;
                        break;

                    case 'B':
                    case 'b':
                        Code16KSetB(barcodeData[position], values, ref barCharacters);
                        position++;
                        break;

                    case 'C': Code16KSetC(barcodeData[position], barcodeData[position + 1], values, ref barCharacters);
                        position += 2;
                        break;
                    }
                }

                else
                {
                    values[barCharacters] = 102;
                    barCharacters++;
                    position++;
                }
            } while (position < inputLength);

            padding = 5 - ((barCharacters + 2) % 5);
            if (padding == 5)
            {
                padding = 0;
            }

            if ((barCharacters + padding) < 8)
            {
                padding += 8 - (barCharacters + padding);
            }

            for (int i = 0; i < padding; i++)
            {
                values[barCharacters] = 106;
                barCharacters++;
            }

            // Calculate check digits.
            checkSum1 = 0;
            checkSum2 = 0;
            for (int i = 0; i < barCharacters; i++)
            {
                checkSum1 += (i + 2) * values[i];
                checkSum2 += (i + 1) * values[i];
            }

            checkValue1               = checkSum1 % 107;
            checkSum2                += checkValue1 * (barCharacters + 1);
            checkValue2               = checkSum2 % 107;
            values[barCharacters]     = checkValue1;
            values[barCharacters + 1] = checkValue2;
            barCharacters            += 2;

            for (int row = 0; row < rowsRequired; row++)
            {
                rowPattern = new StringBuilder();
                rowPattern.Append(C16KStartStop[C16KStartValues[row]]);
                rowPattern.Append("1");
                for (int i = 0; i < 5; i++)
                {
                    rowPattern.Append(Code16KTable[values[(row * 5) + i]]);
                }

                rowPattern.Append(C16KStartStop[C16KStopValues[row]]);

                // Expand row into the symbol data.
                SymbolBuilder.ExpandSymbolRow(Symbol, rowPattern, 10.0f);
            }
        }
Ejemplo n.º 25
0
        private void Code93()
        {
            int cWeight     = 0;
            int kWeight     = 0;
            int cCount      = 1;
            int kCount      = 2;
            int checkDigitC = 0;
            int checkDigitK = 0;

            StringBuilder inputBuffer = new StringBuilder();
            StringBuilder rowPattern  = new StringBuilder();
            int           inputLength = barcodeData.Length;

            // Check for valid characters and expand the input data.
            for (int i = 0; i < inputLength; i++)
            {
                if (barcodeData[i] > 127)
                {
                    throw new InvalidDataException("Code 93: Invalid characters in input data.");
                }

                inputBuffer.Append(C93Expanded[barcodeData[i]]);
            }

            inputLength = inputBuffer.Length;
            if (inputLength > 107)
            {
                throw new InvalidDataLengthException("Code 93: Input data too long.");
            }

            int[] values = new int[inputLength];
            for (int i = 0; i < inputLength; i++)
            {
                values[i] = CharacterSets.Code93Set.IndexOf(inputBuffer[i]);
            }

            // Calculate the check characters starting from the right most position.
            for (int i = values.Length - 1; i >= 0; i--)
            {
                cWeight += (values[i] * cCount);
                cCount++;
                if (cCount == 21)
                {
                    cCount = 1;
                }

                kWeight += (values[i] * kCount);
                kCount++;
                if (kCount == 16)
                {
                    kCount = 1;
                }
            }

            checkDigitC = (cWeight % 47);
            kWeight    += checkDigitC;
            checkDigitK = (kWeight % 47);

            rowPattern.Append(Code93Table[47]); // Add the start character.
            for (int i = 0; i < inputLength; i++)
            {
                rowPattern.Append(Code93Table[values[i]]);
            }

            // Add the "C" and "K" check digits, stop character and termination bar
            rowPattern.Append(Code93Table[checkDigitC]);
            rowPattern.Append(Code93Table[checkDigitK]);
            rowPattern.Append(Code93Table[47] + "1");
            barcodeText     = new string(barcodeData);
            checkDigitText += CharacterSets.Code93Set[checkDigitC];
            checkDigitText += CharacterSets.Code93Set[checkDigitK];

            // Expand the row pattern into the symbol data.
            SymbolBuilder.ExpandSymbolRow(Symbol, rowPattern, 0.0f);
        }
Ejemplo n.º 26
0
        private void visitMethod <T>(BaseMethodDeclarationSyntax node, VisitNode <T> visitor)
            where T : CSharpSyntaxNode
        {
            MainDeclaration.Instance.RoslynWatch.Start( );
            var symbol = MainDeclaration.Instance.Model.GetDeclaredSymbol(node);

            MainDeclaration.Instance.RoslynWatch.Stop( );

            HalsteadAnalyzer halsteadAnalyzer = new HalsteadAnalyzer();
            var halstedMetrics = halsteadAnalyzer.Calculate(node);

            var limNode = SymbolBuilder.BuildDispatch <Method, IMethodSymbol>(symbol);

            limNode.TotalOperands     = halstedMetrics.TotalOperands;
            limNode.TotalOperators    = halstedMetrics.TotalOperators;
            limNode.DistinctOperands  = halstedMetrics.DistinctOperands;
            limNode.DistinctOperators = halstedMetrics.DistinctOperators;
            if (symbol.OverriddenMethod != null)
            {
                if (symbol.OverriddenMethod.IsInMetadata( ))
                {
                    MainDeclaration.Instance
                    .OverrideRelations.AddOverride(
                        ( Method )symbol.OverriddenMethod.ConvertToLimNode( ),
                        limNode
                        );
                }
                else
                {
                    SyntaxNode dummyNode;
                    var        asd = symbol.OverriddenMethod.GetDefinition(out dummyNode);
                    if (asd != null && asd.Kind == symbol.OverriddenMethod.Kind)
                    {
                        var overriddenMethodSymbol = ( Method )asd.ConvertToLimNode( );
                        MainDeclaration.Instance
                        .OverrideRelations.AddOverride(
                            overriddenMethodSymbol,
                            limNode
                            );
                    }
                }
            }
            if (symbol.ContainingType.TypeKind == TypeKind.Interface)
            {
                Commons.Common.ChangeRealizationLevel(limNode);
            }
            if (symbol.PartialImplementationPart != null)
            {
                Commons.Common.ChangeRealizationLevel(limNode);
                var method = symbol.PartialImplementationPart.IsGenericMethod
                    ? SymbolBuilder.BuildDispatch <MethodGeneric, IMethodSymbol>(symbol.PartialImplementationPart)
                    : SymbolBuilder.BuildDispatch <Method, IMethodSymbol>(symbol.PartialImplementationPart);
                method.NumberOfBranches = 0;
                limNode.setDeclares(method.Id);
                Commons.Common.FillFromMethodStack(MainDeclaration.Instance.MethodStack.Pop( ));
            }

            if (node.Kind( ) == SyntaxKind.ConstructorDeclaration)
            {
                var init = (( ConstructorDeclarationSyntax )node).Initializer;
                if (init != null)
                {
                    MainDeclaration.Instance.RoslynWatch.Start( );
                    var calleeSymbol = MainDeclaration.Instance.Model.GetSymbolInfo(init).Symbol;
                    MainDeclaration.Instance.RoslynWatch.Stop( );
                    if (calleeSymbol != null)
                    {
                        SyntaxNode calledCtor;
                        calleeSymbol.GetDefinition(out calledCtor);
                        EdgeBuilder.CreateMethodCallEdge(symbol, calleeSymbol);
                        if (calledCtor != null && calledCtor.Kind( ) == SyntaxKind.ConstructorDeclaration)
                        {
                            // if the called constructor doesn't exist in the code e.x.: default constructor
                            _crossEdgeFiller.ConstructorCallFiller(( ConstructorDeclarationSyntax )calledCtor, init);
                        }
                    }
                }
            }

            MainDeclaration.Instance.LimOrigin.addCompIdCsharpIdLimIdToMap(MainDeclaration.Instance.Component.Id,
                                                                           _map[node], limNode.Id);
            node.CreateCommentNode(symbol);

            visitor(node as T);

            if (MainDeclaration.Instance.MethodStack.Count > 0)
            {
                Commons.Common.SetMetrics(node);
            }

            limNode.SetCLOC(node);
        }
Ejemplo n.º 27
0
        private void IntellgentMail()
        {
            int       index;
            int       value;
            string    zip      = String.Empty;
            string    tracker  = String.Empty;
            BitVector zipAdder = new BitVector();

            short[] accumulator = new short[112];
            short[] xRegister   = new short[112];
            short[] yRegister   = new short[112];
            byte[]  byteData    = new byte[13];
            uint    uspsCRC;

            int[]         codeword    = new int[10];
            uint[]        characters  = new uint[10];
            int[]         barMap      = new int[130];
            StringBuilder barPattern  = new StringBuilder();
            int           inputLength = barcodeData.Length;

            if (inputLength > 31)
            {
                throw new InvalidDataLengthException("USPS: Input data too long.");
            }

            if (inputLength < 20)
            {
                throw new InvalidDataLengthException("USPS: Invalid tracking code length.");
            }

            // Separate the tracking code from the routing code.
            tracker = new string(barcodeData, 0, 20);
            if (inputLength > 20)
            {
                zip = new string(barcodeData, 20, inputLength - tracker.Length);
            }

            if (zip.Length != 11 && zip.Length != 9 && zip.Length != 5 && zip.Length != 0)
            {
                throw new InvalidDataException("USPS: Invalid ZIP code.");
            }

            Array.Clear(accumulator, 0, 112);
            for (index = 0; index < zip.Length; index++)
            {
                BinaryMath.BinaryMultiply(accumulator, "10");
                BinaryMath.BinaryLoad(xRegister, "0");
                for (int i = 0; i < 4; i++)
                {
                    value = zip[index] - '0';
                    if ((value & (0x01 << i)) > 0)
                    {
                        xRegister[i] = 1;
                    }
                }

                BinaryMath.BinaryAdd(accumulator, xRegister);
            }

            // Add weight to routing code.
            Array.Copy(accumulator, xRegister, 112);
            if (zip.Length > 9)
            {
                zipAdder.AppendBits(545, 10);       // 1000100001
            }
            else
            {
                if (zip.Length > 5)
                {
                    zipAdder.AppendBits(33, 6);     // 100001
                }
                else
                {
                    if (zip.Length > 0)
                    {
                        zipAdder.AppendBit(1);      // 1
                    }
                    else
                    {
                        zipAdder.AppendBit(0);      // 0
                    }
                }
            }

            Array.Clear(accumulator, 0, 112);
            for (index = 0; index < zipAdder.SizeInBits; index++)
            {
                BinaryMath.BinaryMultiply(accumulator, "10");
                BinaryMath.BinaryLoad(yRegister, "0");
                for (int i = 0; i < 4; i++)
                {
                    value = zipAdder[index] - '0';
                    if ((value & (0x01 << i)) > 0)
                    {
                        yRegister[i] = 1;
                    }
                }

                BinaryMath.BinaryAdd(accumulator, yRegister);
            }

            BinaryMath.BinaryAdd(accumulator, xRegister);

            // Tracking code.
            // Multiply by 10.
            BinaryMath.BinaryMultiply(accumulator, "10");
            BinaryMath.BinaryLoad(yRegister, "0");
            for (int i = 0; i < 4; i++)
            {
                value = tracker[0] - '0';
                if ((value & (0x01 << i)) > 0)
                {
                    yRegister[i] = 1;
                }
            }

            BinaryMath.BinaryAdd(accumulator, yRegister);

            // Multiply by 5.
            BinaryMath.BinaryMultiply(accumulator, "5");
            BinaryMath.BinaryLoad(yRegister, "0");
            // Add second digit.
            for (int i = 0; i < 4; i++)
            {
                value = tracker[1] - '0';
                if ((value & (0x01 << i)) > 0)
                {
                    yRegister[i] = 1;
                }
            }

            BinaryMath.BinaryAdd(accumulator, yRegister);

            // And then the rest.
            for (index = 2; index < tracker.Length; index++)
            {
                BinaryMath.BinaryMultiply(accumulator, "10");
                BinaryMath.BinaryLoad(yRegister, "0");
                for (int i = 0; i < 4; i++)
                {
                    value = tracker[index] - '0';
                    if ((value & (0x01 << i)) > 0)
                    {
                        yRegister[i] = 1;
                    }
                }

                BinaryMath.BinaryAdd(accumulator, yRegister);
            }

            // Step 2 - Generation of 11-bit CRC on Binary Data.
            accumulator[103] = 0;
            accumulator[102] = 0;

            for (int i = 0; i < 13; i++)
            {
                int j = 96 - (8 * i);
                byteData[i]  = 0;
                byteData[i] += (byte)accumulator[j];
                byteData[i] += (byte)(2 * accumulator[j + 1]);
                byteData[i] += (byte)(4 * accumulator[j + 2]);
                byteData[i] += (byte)(8 * accumulator[j + 3]);
                byteData[i] += (byte)(16 * accumulator[j + 4]);
                byteData[i] += (byte)(32 * accumulator[j + 5]);
                byteData[i] += (byte)(64 * accumulator[j + 6]);
                byteData[i] += (byte)(128 * accumulator[j + 7]);
            }

            uspsCRC = CRC11GenerateFrameCheckSequence(byteData);

            // Step 3 - Conversion from Binary Data to Codewords.
            // Start with codeword J which is base 636
            Array.Clear(xRegister, 0, 112);
            Array.Clear(yRegister, 0, 112);

            xRegister[101] = 1;
            xRegister[98]  = 1;
            xRegister[97]  = 1;
            xRegister[96]  = 1;
            xRegister[95]  = 1;
            xRegister[94]  = 1;

            for (int i = 92; i >= 0; i--)
            {
                yRegister[i] = BinaryMath.IsLarger(accumulator, xRegister);
                if (yRegister[i] == 1)
                {
                    BinaryMath.BinarySubtract(accumulator, xRegister);
                }

                BinaryMath.ShiftDown(xRegister);
            }

            codeword[9] = (accumulator[9] * 512) + (accumulator[8] * 256) + (accumulator[7] * 128) + (accumulator[6] * 64) +
                          (accumulator[5] * 32) + (accumulator[4] * 16) + (accumulator[3] * 8) + (accumulator[2] * 4) +
                          (accumulator[1] * 2) + accumulator[0];

            // Then codewords I to B with base 1365.
            for (int j = 8; j > 0; j--)
            {
                for (int i = 0; i < 112; i++)
                {
                    accumulator[i] = yRegister[i];
                    yRegister[i]   = 0;
                    xRegister[i]   = 0;
                }

                xRegister[101] = 1;
                xRegister[99]  = 1;
                xRegister[97]  = 1;
                xRegister[95]  = 1;
                xRegister[93]  = 1;
                xRegister[91]  = 1;
                for (int i = 91; i >= 0; i--)
                {
                    yRegister[i] = BinaryMath.IsLarger(accumulator, xRegister);
                    if (yRegister[i] == 1)
                    {
                        BinaryMath.BinarySubtract(accumulator, xRegister);
                    }

                    BinaryMath.ShiftDown(xRegister);
                }

                codeword[j] = (accumulator[10] * 1024) + (accumulator[9] * 512) + (accumulator[8] * 256) +
                              (accumulator[7] * 128) + (accumulator[6] * 64) + (accumulator[5] * 32) +
                              (accumulator[4] * 16) + (accumulator[3] * 8) + (accumulator[2] * 4) +
                              (accumulator[1] * 2) + accumulator[0];
            }

            codeword[0] = (yRegister[10] * 1024) + (yRegister[9] * 512) + (yRegister[8] * 256) +
                          (yRegister[7] * 128) + (yRegister[6] * 64) + (yRegister[5] * 32) +
                          (yRegister[4] * 16) + (yRegister[3] * 8) + (yRegister[2] * 4) +
                          (yRegister[1] * 2) + yRegister[0];

            for (int i = 0; i < 8; i++)
            {
                if (codeword[i] == 1365)
                {
                    codeword[i] = 0;
                    codeword[i + 1]++;
                }
            }

            // Step 4 - Inserting Additional Information into Codewords.
            codeword[9] = codeword[9] * 2;
            if (uspsCRC >= 1024)
            {
                codeword[0] += 659;
            }

            // Step 5 - Conversion from Codewords to Characters.
            for (int i = 0; i < 10; i++)
            {
                if (codeword[i] < 1287)
                {
                    characters[i] = AppendixD1[codeword[i]];
                }

                else
                {
                    characters[i] = AppendixD2[codeword[i] - 1287];
                }
            }

            for (int i = 0; i < 10; i++)
            {
                if ((uspsCRC & (1 << i)) > 0)
                {
                    characters[i] = 0x1FFF - characters[i];
                }
            }

            // Step 6 - Conversion from Characters to the Intelligent Mail Barcode.
            for (int i = 0; i < 10; i++)
            {
                for (int j = 0; j < 13; j++)
                {
                    if ((characters[i] & (1 << j)) > 0)
                    {
                        barMap[AppendixD4[(13 * i) + j] - 1] = 1;
                    }

                    else
                    {
                        barMap[AppendixD4[(13 * i) + j] - 1] = 0;
                    }
                }
            }

            for (int i = 0; i < 65; i++)
            {
                int j = 0;
                if (barMap[i] == 0)
                {
                    j += 1;
                }

                if (barMap[i + 65] == 0)
                {
                    j += 2;
                }

                barPattern.Append(j);
            }

            SymbolBuilder.BuildFourStateSymbol(Symbol, barPattern);
            // Format the barcodes text.
            barcodeText = new string(barcodeData);
            if (zip.Length > 0)
            {
                if (zip.Length == 11)
                {
                    barcodeText = barcodeText.Insert(29, " ");
                }

                if (zip.Length >= 9)
                {
                    barcodeText = barcodeText.Insert(25, " ");
                }

                if (zip.Length >= 5)
                {
                    barcodeText = barcodeText.Insert(20, " ");
                }
            }

            if (tracker[5] < '9')
            {
                barcodeText = barcodeText.Insert(11, " ");
            }

            else
            {
                barcodeText = barcodeText.Insert(14, " ");
            }

            barcodeText = barcodeText.Insert(5, " ");
            barcodeText = barcodeText.Insert(2, " ");
        }
Ejemplo n.º 28
0
        private void AusPost()
        {
            /* Handles Australia Posts's 4 State Codes
             * The contents of data pattern conform to the following standard:
             * 0 = Tracker, Ascender and Descender
             * 1 = Tracker and Ascender
             * 2 = Tracker and Descender
             * 3 = Tracker only */

            int             inputLength  = barcodeData.Length;
            StringBuilder   barPattern   = new StringBuilder();
            AusPostEncoding encodingMode = AusPostEncoding.Numeric;
            string          fcc          = String.Empty; // Format Control Code
            string          dpid         = String.Empty; // Delivery Point ID.
            string          cif          = string.Empty; // Customer Information Field.
            int             cifLength    = 0;

            // Do all of the length and integrity checking first.
            if (inputLength >= 10)
            {
                // Check valid FCC and DPID.
                for (int i = 0; i < 10; i++)
                {
                    if (CharacterSets.NumberOnlySet.IndexOf(barcodeData[i]) == -1)
                    {
                        throw new InvalidDataException("AusPost: FCC and DPID must be numeric data.");
                    }
                }

                fcc  = new string(barcodeData, 0, 2);
                dpid = new string(barcodeData, 2, 8);

                // Check for CIF.
                if (inputLength > 10)
                {
                    cif       = new string(barcodeData, 10, inputLength - 10);
                    cifLength = cif.Length;
                }
            }

            else
            {
                throw new InvalidDataLengthException("AusPost: Input data wrong length.");
            }

            if (symbolId == Symbology.AusPostStandard)
            {
                if (fcc != "11" && fcc != "59" && fcc != "62")
                {
                    throw new InvalidDataFormatException("AusPost Standard: Invalid Format Control Code (" + fcc + ").");
                }

                if (fcc == "11" && inputLength != 10)
                {
                    throw new InvalidDataLengthException("AusPost Standard: Input is wrong length for Format Control Code 11.");
                }

                if (fcc == "59")
                {
                    if (cifLength > 5 && cifLength < 9)
                    {
                        for (int i = 0; i < cifLength; i++)
                        {
                            if (CharacterSets.NumberOnlySet.IndexOf(cif[i]) == -1)
                            {
                                throw new InvalidDataException("AusPost Standard: Invalid data for Numeric encoding.");
                            }
                        }

                        encodingMode = AusPostEncoding.Numeric;
                    }

                    else if (cifLength < 6)
                    {
                        for (int i = 0; i < cifLength; i++)
                        {
                            if (CharacterSets.AusPostSet.IndexOf(cif[i]) == -1)
                            {
                                throw new InvalidDataException("AusPost Standard: Invalid data for Character encoding.");
                            }
                        }

                        encodingMode = AusPostEncoding.Character;
                    }

                    else
                    {
                        throw new InvalidDataLengthException("AusPost Standard: Input is wrong length for Customer Information Field.");
                    }
                }

                if (fcc == "62")
                {
                    if (cifLength > 10 && cifLength < 16)
                    {
                        for (int i = 0; i < cifLength; i++)
                        {
                            if (CharacterSets.NumberOnlySet.IndexOf(cif[i]) == -1)
                            {
                                throw new InvalidDataException("AusPost Standard: Invalid data for Numeric encoding.");
                            }
                        }

                        encodingMode = AusPostEncoding.Numeric;
                    }

                    else if (cifLength < 11)
                    {
                        for (int i = 0; i < cifLength; i++)
                        {
                            if (CharacterSets.AusPostSet.IndexOf(cif[i]) == -1)
                            {
                                throw new InvalidDataException("AusPost Standard: Invalid data for Character encoding.");
                            }
                        }

                        encodingMode = AusPostEncoding.Character;
                    }

                    else
                    {
                        throw new InvalidDataLengthException("AusPost Standard: Input is wrong length for Customer Information Field.");
                    }
                }
            }

            else
            {
                if (inputLength != 10)
                {
                    throw new InvalidDataLengthException("AusPost: Input is wrong length for selected AusPost symbol.");
                }

                switch (symbolId)
                {
                case Symbology.AusPostReplyPaid:
                    if (fcc != "45")
                    {
                        throw new InvalidDataException("AusPost Reply Paid: Invalid Format Control Code.");
                    }
                    break;

                case Symbology.AusPostRouting:
                    if (fcc != "87")
                    {
                        throw new InvalidDataException("AusPost Routing: Invalid Format Control Code.");
                    }
                    break;

                case Symbology.AusPostRedirect:
                    if (fcc != "92")
                    {
                        throw new InvalidDataException("AusPost Redirect: Invalid Format Control Code.");
                    }
                    break;
                }
            }

            // Encode the Format Control Code.
            for (int i = 0; i < 2; i++)
            {
                int index = CharacterSets.NumberOnlySet.IndexOf(fcc[i]);
                barPattern.Append(AusNTable[index]);
            }

            // Delivery Point Identifier.
            for (int i = 0; i < 8; i++)
            {
                int index = CharacterSets.NumberOnlySet.IndexOf(dpid[i]);
                barPattern.Append(AusNTable[index]);
            }

            if (encodingMode == AusPostEncoding.Character)
            {
                for (int i = 0; i < cif.Length; i++)
                {
                    int index = CharacterSets.AusPostSet.IndexOf(cif[i]);
                    barPattern.Append(AusCTable[index]);
                }
            }

            else
            {
                for (int i = 0; i < cif.Length; i++)
                {
                    int index = CharacterSets.NumberOnlySet.IndexOf(cif[i]);
                    barPattern.Append(AusNTable[index]);
                }
            }

            // Filler bars.
            int patternLength = barPattern.Length;

            if (fcc == "59" && patternLength < 36)
            {
                barPattern.Append(fillCharacter, 36 - patternLength);
            }

            else if (fcc == "62" && patternLength < 51)
            {
                barPattern.Append(fillCharacter, 51 - patternLength);
            }

            if (fcc == "11")
            {
                barPattern.Append(fillCharacter);
            }

            AddErrorCorrection(barPattern);

            // Add start & stop characters.
            barPattern.Insert(0, "13");
            barPattern.Append("13");

            SymbolBuilder.BuildFourStateSymbol(Symbol, barPattern);
            barcodeText = new string(barcodeData);
            if (cifLength > 0)
            {
                barcodeText = barcodeText.Insert(10, " ");
            }

            barcodeText = barcodeText.Insert(2, " ");
        }
Ejemplo n.º 29
0
        /// <summary>
        ///     In this section it'll be create:
        ///     - Instantiate edge from object creation expression
        ///     - MethodCall edge from object creation expression
        ///     These edges add to the acutal method from the MethodStack
        /// </summary>
        /// <param name="node"></param>
        public override void VisitObjectCreationExpression(ObjectCreationExpressionSyntax node)
        {
            base.VisitObjectCreationExpression(node);

            //if (node.IsParent<AnonymousObjectMemberDeclaratorSyntax>()) return;
            MainDeclaration.Instance.RoslynWatch.Start( );
            ISymbol symbol = null;

            if (node.Type.Kind( ) != SyntaxKind.NullableType)
            {
                MainDeclaration.Instance.RoslynWatch.Start( );
                symbol = MainDeclaration.Instance.Model.GetSymbolInfo(node.Type).Symbol;
                MainDeclaration.Instance.RoslynWatch.Stop( );
            }
            else
            {
                MainDeclaration.Instance.RoslynWatch.Start( );
                symbol =
                    MainDeclaration.Instance.Model.GetSymbolInfo((node.Type as NullableTypeSyntax)?.ElementType)
                    .Symbol;
                MainDeclaration.Instance.RoslynWatch.Stop( );
            }

            MainDeclaration.Instance.RoslynWatch.Stop( );
            SyntaxNode synNode = null;

            if (symbol != null && MainDeclaration.Instance.MethodStack.Count > 0)
            {
                var calledSymbol = symbol.GetDefinition(out synNode);
                if (calledSymbol != null && calledSymbol.Kind == symbol.Kind)
                {
                    uint id = 0;
                    if (calledSymbol.Kind == SymbolKind.NamedType && (calledSymbol as INamedTypeSymbol).IsGenericType)
                    {
                        id = symbol.GetLimType(calledSymbol).Id;
                    }
                    else
                    {
                        id = calledSymbol.GetLimType( ).Id;
                    }

                    var pair = new KeyValuePair <uint, bool>(id, false);
                    if (!MainDeclaration.Instance.MethodStack.Peek( ).CanThrow.Contains(pair))
                    {
                        MainDeclaration.Instance.MethodStack.Peek( ).Instantiates.Add(pair);
                    }
                    if (symbol.Kind == SymbolKind.NamedType && synNode.Kind( ) != SyntaxKind.DelegateDeclaration)
                    {
                        _crossEdgeFiller.OriginalDefinitionFiller(synNode as MemberDeclarationSyntax, node.Type);
                    }
                }
                else if (symbol.IsInMetadata( ))
                {
                    var namedTypeSymbol = symbol as INamedTypeSymbol;
                    if (namedTypeSymbol != null)
                    {
                        var id = namedTypeSymbol.GetLimType( ).Id;
                        MainDeclaration.Instance.LimFactory.setFiltered(id);
                        var pair = new KeyValuePair <uint, bool>(id, true);
                        if (!MainDeclaration.Instance.MethodStack.Peek( ).CanThrow.Contains(pair))
                        {
                            MainDeclaration.Instance.MethodStack.Peek( ).Instantiates.Add(pair);
                        }
                    }
                }
            }
            MainDeclaration.Instance.RoslynWatch.Start( );
            symbol = MainDeclaration.Instance.Model.GetSymbolInfo(node).Symbol;
            MainDeclaration.Instance.RoslynWatch.Stop( );
            if (symbol != null && MainDeclaration.Instance.MethodStack.Count > 0)
            {
                var calledSymbol = symbol.GetDefinition(out synNode);
                if (calledSymbol != null && calledSymbol.Kind == symbol.Kind)
                {
                    if (calledSymbol.Kind == SymbolKind.Method)
                    {
                        var methodCall =
                            MainDeclaration.Instance.LimFactory.createMethodCall(calledSymbol.ConvertToLimNode( ).Id);
                        MainDeclaration.Instance.MethodStack.Peek( )
                        .Calls.Add(new KeyValuePair <uint, bool>(methodCall.Id, false));
                        _crossEdgeFiller.ConstructorCallFiller(( ConstructorDeclarationSyntax )synNode, node);
                    }
                }
                else if (symbol.IsInMetadata( ))
                {
                    var methodSymbol = symbol as IMethodSymbol;
                    if (methodSymbol != null)
                    {
                        Method method = null;
                        if (methodSymbol.IsGenericMethod)
                        {
                            method = SymbolBuilder.BuildDispatch <MethodGeneric, IMethodSymbol>(methodSymbol);
                        }
                        else
                        {
                            method = SymbolBuilder.BuildDispatch <Method, IMethodSymbol>(methodSymbol);
                        }

                        Commons.Common.FillFromMethodStack(MainDeclaration.Instance.MethodStack.Pop( ));
                        MainDeclaration.Instance.LimFactory.setFiltered(method.Id);
                        var methodCall = MainDeclaration.Instance.LimFactory.createMethodCall(method.Id);
                        MainDeclaration.Instance.LimFactory.setFiltered(methodCall.Id);
                        MainDeclaration.Instance.MethodStack.Peek( )
                        .Calls.Add(new KeyValuePair <uint, bool>(methodCall.Id, true));
                    }
                }
            }
        }
Ejemplo n.º 30
0
        public override void VisitAccessorDeclaration(AccessorDeclarationSyntax node)
        {
            MainDeclaration.Instance.RoslynWatch.Start( );
            var symbol = MainDeclaration.Instance.Model.GetDeclaredSymbol(node);

            MainDeclaration.Instance.RoslynWatch.Stop( );

            HalsteadAnalyzer halsteadAnalyzer = new HalsteadAnalyzer( );
            var halstedMetrics = halsteadAnalyzer.Calculate(node);

            var nodeParent = node.GetParent <BasePropertyDeclarationSyntax>( );

            _isAutoProperty = nodeParent.Kind( ) == SyntaxKind.PropertyDeclaration &&
                              IsAutoProperty(nodeParent as PropertyDeclarationSyntax,
                                             symbol.AssociatedSymbol as IPropertySymbol);

            var limNode = SymbolBuilder.BuildDispatch <Method, IMethodSymbol>(symbol);

            limNode.TotalOperands     = halstedMetrics.TotalOperands;
            limNode.TotalOperators    = halstedMetrics.TotalOperators;
            limNode.DistinctOperands  = halstedMetrics.DistinctOperands;
            limNode.DistinctOperators = halstedMetrics.DistinctOperators;
            if (symbol.OverriddenMethod != null)
            {
                if (symbol.OverriddenMethod.IsInMetadata( ))
                {
                    MainDeclaration.Instance
                    .OverrideRelations.AddOverride(
                        ( Method )symbol.OverriddenMethod.ConvertToLimNode( ),
                        limNode
                        );
                }
                else
                {
                    SyntaxNode dummyNode;
                    var        overriddenMethodDefinition = symbol.OverriddenMethod.GetDefinition(out dummyNode);
                    if (overriddenMethodDefinition != null &&
                        overriddenMethodDefinition.Kind == symbol.OverriddenMethod.Kind)
                    {
                        var overriddenMethodSymbol = ( Method )overriddenMethodDefinition.ConvertToLimNode( );
                        MainDeclaration.Instance
                        .OverrideRelations.AddOverride(
                            overriddenMethodSymbol,
                            limNode
                            );
                    }
                }
            }
            limNode.SetCLOC(node);
            limNode.SetCLOC(node.Parent.Parent);

            if (_isAutoProperty)
            {
                CreateAttributeWithAccessEdge(nodeParent, symbol.AssociatedSymbol, limNode);
            }

            MainDeclaration.Instance.LimOrigin.addCompIdCsharpIdLimIdToMap(MainDeclaration.Instance.Component.Id,
                                                                           _map[node], limNode.Id);

            node.CreateCommentNode(symbol);
            node.Parent.Parent.CreateCommentNode(symbol);

            base.VisitAccessorDeclaration(node);

            if (MainDeclaration.Instance.MethodStack.Count > 0)
            {
                Commons.Common.SetMetrics(node);
            }
        }