Exemplo n.º 1
0
        private static IConstruct ParseOthers(string module, IList <Symbol> header, Lexer lexer, ref IList <Symbol> next)
        {
            Symbol current = lexer.NextNonEOLSymbol;

            if (current == Symbol.Sequence)
            {
                return(new Sequence(module, header[0].ToString(), lexer));
            }

            if (current == Symbol.Choice)
            {
                return(new Choice(module, header[0].ToString(), lexer));
            }

            if (current == Symbol.Integer)
            {
                return(new Integer(module, header[0].ToString(), lexer));
            }

            if (current == Symbol.TextualConvention)
            {
                return(new TextualConvention(module, header[0].ToString(), lexer));
            }

            TypeAssignment result = new TypeAssignment(module, header[0].ToString(), current, lexer);

            next.Add(result.Left);
            return(result);
        }
Exemplo n.º 2
0
        private Definition CreateSelf(IEntity node)
        {
            ObjectType o = node as ObjectType;

            if (o != null)
            {
                TypeAssignment syn = o.Syntax as TypeAssignment;
                if (syn != null && _types.ContainsKey(syn.Value))
                {
                    o.Syntax = _types[syn.Value];
                }
            }

            /* algorithm 2: slower, dropped
             * IDefinition parent = Find(node.Parent);
             * if (parent == null)
             * {
             *  return null;
             * }
             *
             * return ((Definition)parent).Add(node);
             * // */

            // * algorithm 1
            return(_root.Add(node));

            // */
        }
        private static void CheckTypeReferrer(IModule module, ITypeReferrer typeReferringEntity)
        {
            TypeAssignment unknownType = typeReferringEntity.ReferredType as TypeAssignment;

            if (unknownType != null)
            {
                typeReferringEntity.ReferredType = ResolveType(module, unknownType);

                if (typeReferringEntity.ReferredType is TypeAssignment)
                {
                    Console.WriteLine(String.Format("Could not resolve type '{0}' declared in module '{1}'", (typeReferringEntity.ReferredType as TypeAssignment).Type, typeReferringEntity.ReferredType.Module.Name));
                }
            }

            ITypeReferrer nextTypeReferringEntity = typeReferringEntity.ReferredType as ITypeReferrer;

            if (nextTypeReferringEntity != null)
            {
                CheckTypeReferrer(module, nextTypeReferringEntity);
            }
        }
Exemplo n.º 4
0
        private static ITypeAssignment ParseSyntax(string module, string name, IEnumerator <Symbol> enumerator, ref Symbol temp)
        {
            ITypeAssignment syntax;

            temp.Expect(Symbol.Syntax);
            temp = enumerator.NextNonEOLSymbol();

            if (temp == Symbol.Bits)
            {
                syntax = new BitsType(string.Empty, string.Empty, enumerator);
                temp   = enumerator.NextNonEOLSymbol();
            }
            else if (temp == Symbol.Integer || temp == Symbol.Integer32)
            {
                syntax = new IntegerType(module, name, enumerator, ref temp);
            }
            else if (temp == Symbol.Octet)
            {
                temp = enumerator.NextNonEOLSymbol();

                temp.Expect(Symbol.String);
                syntax = new OctetStringType(string.Empty, string.Empty, enumerator, ref temp);
            }
            else if (temp == Symbol.Opaque)
            {
                syntax = new OctetStringType(string.Empty, string.Empty, enumerator, ref temp);
            }
            else if (temp == Symbol.IpAddress)
            {
                syntax = new IpAddressType(string.Empty, string.Empty, enumerator);
                temp   = enumerator.NextNonEOLSymbol();
            }
            else if (temp == Symbol.Counter64)
            {
                syntax = new Counter64Type(string.Empty, string.Empty, enumerator);
                temp   = enumerator.NextNonEOLSymbol();
            }
            else if (temp == Symbol.Unsigned32 || temp == Symbol.Counter32 || temp == Symbol.Gauge32 || temp == Symbol.TimeTicks)
            {
                syntax = new UnsignedType(string.Empty, string.Empty, enumerator, ref temp);
            }
            else if (temp == Symbol.Object)
            {
                temp = enumerator.NextNonEOLSymbol();

                temp.Expect(Symbol.Identifier);
                syntax = new ObjectIdentifierType(string.Empty, string.Empty, enumerator);
                temp   = enumerator.NextNonEOLSymbol();
            }
            else if (temp == Symbol.Sequence)
            {
                temp = enumerator.NextNonEOLSymbol();

                if (temp == Symbol.Of)
                {
                    temp   = enumerator.NextNonEOLSymbol();
                    syntax = new TypeAssignment(string.Empty, string.Empty, enumerator, ref temp);
                }
                else
                {
                    syntax = new Sequence(string.Empty, string.Empty, enumerator);
                    temp   = enumerator.NextNonEOLSymbol();
                }
            }
            else
            {
                syntax = new TypeAssignment(string.Empty, string.Empty, enumerator, ref temp);
            }

            return(syntax);
        }
        public static ITypeAssignment ResolveType(IModule module, TypeAssignment type)
        {
            ITypeAssignment result = ResolveDeclaration(module, type.Type) as ITypeAssignment;

            return((result != null) ? result : type);
        }
Exemplo n.º 6
0
        private static IConstruct ParseOthers(string module, IList<Symbol> header, Lexer lexer, ref IList<Symbol> next)
        {
            Symbol current = lexer.NextNonEOLSymbol;
            
            if (current == Symbol.Sequence)
            {
                return new Sequence(module, header[0].ToString(), lexer);
            }

            if (current == Symbol.Choice)
            {
                return new Choice(module, header[0].ToString(), lexer);
            }

            if (current == Symbol.Integer)
            {
                return new Integer(module, header[0].ToString(), lexer);
            }

            if (current == Symbol.TextualConvention)
            {
                return new TextualConvention(module, header[0].ToString(), lexer);
            }

            TypeAssignment result = new TypeAssignment(module, header[0].ToString(), current, lexer);
            next.Add(result.Left);
            return result;
        }
Exemplo n.º 7
0
        private static ITypeAssignment ParseSyntax(string module, string name, IEnumerator<Symbol> enumerator, ref Symbol temp)
        {
            ITypeAssignment syntax;

            temp.Expect(Symbol.Syntax);
            temp = enumerator.NextNonEOLSymbol();

            if (temp == Symbol.Bits)
            {
                syntax = new BitsType(string.Empty, string.Empty, enumerator);
                temp = enumerator.NextNonEOLSymbol();
            }
            else if (temp == Symbol.Integer || temp == Symbol.Integer32)
            {
                syntax = new IntegerType(module, name, enumerator, ref temp);
            }
            else if (temp == Symbol.Octet)
            {
                temp = enumerator.NextNonEOLSymbol();

                temp.Expect(Symbol.String);
                syntax = new OctetStringType(string.Empty, string.Empty, enumerator, ref temp);
            }
            else if (temp == Symbol.Opaque)
            {
                syntax = new OctetStringType(string.Empty, string.Empty, enumerator, ref temp);
            }
            else if (temp == Symbol.IpAddress)
            {
                syntax = new IpAddressType(string.Empty, string.Empty, enumerator);
                temp = enumerator.NextNonEOLSymbol();
            }
            else if (temp == Symbol.Counter64)
            {
                syntax = new Counter64Type(string.Empty, string.Empty, enumerator);
                temp = enumerator.NextNonEOLSymbol();
            }
            else if (temp == Symbol.Unsigned32 || temp == Symbol.Counter32 || temp == Symbol.Gauge32 || temp == Symbol.TimeTicks)
            {
                syntax = new UnsignedType(string.Empty, string.Empty, enumerator, ref temp);
            }
            else if (temp == Symbol.Object)
            {
                temp = enumerator.NextNonEOLSymbol();

                temp.Expect(Symbol.Identifier);
                syntax = new ObjectIdentifierType(string.Empty, string.Empty, enumerator);
                temp = enumerator.NextNonEOLSymbol();
            }
            else if (temp == Symbol.Sequence)
            {
                temp = enumerator.NextNonEOLSymbol();

                if (temp == Symbol.Of)
                {
                    temp = enumerator.NextNonEOLSymbol();
                    syntax = new TypeAssignment(string.Empty, string.Empty, enumerator, ref temp);
                }
                else
                {
                    syntax = new Sequence(string.Empty, string.Empty, enumerator);
                    temp = enumerator.NextNonEOLSymbol();
                }
            }
            else
            {
                syntax = new TypeAssignment(string.Empty, string.Empty, enumerator, ref temp);
            }

            return syntax;
        }