Пример #1
0
        public CTFTStream(CTFScope scope, List <CTFAssignmentExpression> lcae)
        {
            foreach (CTFAssignmentExpression cae in lcae)
            {
                string name = cae.GetFullName();
                switch (name)
                {
                case "id":
                    id = cae.Src.Calculate();
                    break;

                case "event.header":
                    eventHeader = cae.GetType(scope);
                    break;

                case "packet.context":
                    PacketContext = cae.GetType(scope);
                    break;

                case "event.context":
                    eventContext = cae.GetType(scope);
                    break;

                default:
                    throw new CTFException();
                }
            }
        }
Пример #2
0
        internal static CTFITypeSpecifier Parse(CTFScope scope, TokParser tp)
        {
            if (!tp.Match(Token.EnumId.ENUM))
            {
                return(null);
            }

            tp.MustBe(Token.EnumId.COLON);

            List <CTFTypeSpecifier> cds = ParseList(scope, tp);

            tp.MustBe(Token.EnumId.LCURL);

            List <CTFEnumElem> list = new List <CTFEnumElem>();

            do
            {
                CTFEnumElem ce = CTFEnumElem.Parse(tp);
                list.Add(ce);
            }while (tp.Match(Token.EnumId.SEPARATOR));

            tp.MustBe(Token.EnumId.RCURL);

            return(new CTFEnumSpecifier(Token.EnumId.ENUM, cds, list));
        }
Пример #3
0
        public CTFTEvent(CTFScope scope, List <CTFAssignmentExpression> lcae)
        {
            foreach (CTFAssignmentExpression cae in lcae)
            {
                string tname = cae.GetName();
                switch (tname)
                {
                case "name":
                    Name = cae.Src.GetValue().GetString();
                    break;

                case "id":
                    Id = (uint)cae.Src.Calculate();
                    break;

                case "stream_id":
                    stream_id = cae.Src.Calculate();
                    break;

                case "loglevel":
                    loglevel = cae.Src.Calculate();
                    break;

                case "fields":
                    Fields = cae.GetType(scope);
                    break;

                default:
                    throw new CTFException();
                }
            }
        }
        private static CTFAssignmentExpression Parse(CTFScope scope, TokParser tp)
        {
            CTFUnaryExpression cue = CTFUnaryExpression.Parse(tp);

            if (cue != null)
            {
                if (tp.Match(Token.EnumId.ASSIGNMENT))
                {
                    CTFUnaryExpression cue2 = CTFUnaryExpression.Parse(tp);
                    if (cue2 == null)
                    {
                        throw new CTFException();
                    }

                    return(new CTFAssignmentExpression(cue, cue2));
                }

                if (tp.Match(Token.EnumId.TYPE_ASSIGNMENT))
                {
                    CTFTypeSpecifier cs = CTFITypeSpecifier.ParseTypeSpecifier(scope, tp);
                    if (cs == null)
                    {
                        throw new CTFException();
                    }

                    return(new CTFAssignmentExpression(cue, cs));
                }
            }

            return(null);
        }
Пример #5
0
        internal static CTFTypeSpecifier ParseTypeSpecifier(CTFScope scope, TokParser tp)
        {
            Token.EnumId id = tp.Token.Id;
            switch (id)
            {
            case Token.EnumId.VOID:
            case Token.EnumId.CHAR:
            case Token.EnumId.SHORT:
            case Token.EnumId.INT:
            case Token.EnumId.FLOAT:
            case Token.EnumId.DOUBLE:
            case Token.EnumId.SIGNED:
            case Token.EnumId.BOOL:
            case Token.EnumId.COMPLEX:
            case Token.EnumId.IMAGINARY:
                throw new CTFException();     // unsupported

            case Token.EnumId.LONG:
            case Token.EnumId.UNSIGNED:
                tp.Next();
                return(Get(id));

            case Token.EnumId.STRUCT:
                return(CTFStructSpecifier.Parse(scope, tp));

            case Token.EnumId.VARIANT:
                return(CTFVaraintSpecifier.Parse(scope, tp));

            case Token.EnumId.ENUM:
                return(CTFEnumSpecifier.Parse(scope, tp));

            // ctf-type-specifier
            case Token.EnumId.FLOATING_POINT:
            case Token.EnumId.INTEGER:
                tp.Next();
                tp.MustBe(Token.EnumId.LCURL);
                List <CTFAssignmentExpression> cael = CTFAssignmentExpression.ParseList(scope, tp);
                tp.MustBe(Token.EnumId.RCURL);
                return(new CTFATypeSpecifier(id, cael));

            case Token.EnumId.STRING:
                tp.Next();
                return(Get(Token.EnumId.STRING));

            case Token.EnumId.IDEN:     // must be a type in a scope
                CTFTypeSpecifier ct = CTFNTypeSpecifier.Get(scope, tp.Token.Buffer);
                if (ct == null)
                {
                    return(null);
                }

                tp.Next();
                return(ct);
            }

            return(null);
        }
Пример #6
0
        public static CTFNTypeSpecifier Get(CTFScope scope, string name)
        {
            CTFSymbol s = scope.FindTypeSymbol(name);

            if (s == null)
            {
                return(null);
            }

            return(new CTFNTypeSpecifier(name, s.CtfType));
        }
Пример #7
0
        public CTFVariantType(CTFScope scope, CTFVaraintSpecifier vs)
        {
            tag   = vs.Cue.GetName();
            elems = new CTFVElem[vs.List.Count];
            int i = 0;

            foreach (CTFStructOrVariantDeclaration cd in vs.List)
            {
                CTFType ct   = GetType(scope, cd.List);
                string  name = cd.Cd.Name;
                elems[i++] = new CTFVElem(name, ct);
            }
        }
Пример #8
0
        public static CTFStructType GetStructType(CTFScope scope, List <CTFStructOrVariantDeclaration> list, int align)
        {
            if (list == null)
            {
                return(new CTFStructType());
            }

            int             count  = list.Count; // Is it OK ?
            List <CTFSElem> lelems = new List <CTFSElem>();
            Dictionary <string, CTFStructType> subtypes = new Dictionary <string, CTFStructType>();
            bool hasVariants = false;

            foreach (CTFStructOrVariantDeclaration csvd in list)
            {
                CTFType       ctfType = GetType(scope, csvd.List);
                CTFDeclarator cd      = csvd.Cd; // can be name or array, arry can have dynamic size
                if (cd.Cue != null)
                {
                    // It is array
                    if (cd.Cue.IsNumber())
                    {
                        lelems.Add(new CTFSSElem(cd.Name, ctfType, cd.Cue.Calculate()));
                    }
                    else // dynamic array with local variable size
                    {
                        int j;
                        if (!FindName(cd.Cue.GetName(), lelems, out j))
                        {
                            throw new CTFException();
                        }

                        lelems.Add(new CTFDSElem(cd.Name, ctfType, j));
                    }
                }
                else
                {
                    if (ctfType is CTFVariantType)
                    {
                        CTFVariantType variantType = (CTFVariantType)ctfType;
                        hasVariants = true;
                        variantType.Process(subtypes, lelems, align);
                    }
                    else
                    {
                        lelems.Add(new CTFSElem(cd.Name, ctfType));
                    }
                }
            }

            return(hasVariants ? new CTFVariantStructType(subtypes, lelems, align) : new CTFStructType(lelems, align));
        }
Пример #9
0
        protected static CTFType GetType(CTFScope scope, List <CTFTypeSpecifier> cds)
        {
            // cases:
            // standard combinatons "unsigned long" - really as a special identifier
            // some kind of struct/variant/enum
            // integer/floating_point
            // string
            if (cds.Count == 1) // standard case
            {
                return(cds[0].GetType(scope));
            }
            // Non trivial situation, something like "unsigned long"
            string name = FullName(cds);

            return(scope.FindTypeSymbol(name).CtfType);
        }
Пример #10
0
        public override CTFType GetType(CTFScope scope)
        {
            switch (Id)
            {
            case Token.EnumId.INTEGER:
            {
                return(new CTFIntType(cael));
            }

            case Token.EnumId.FLOATING_POINT:
            {
                return(new CTFFloatType(cael));
            }
            }

            throw new CTFException();
        }
Пример #11
0
        internal static CTFType GetStructType(CTFScope scope, string name, List <CTFStructOrVariantDeclaration> list, int align)
        {
            if (list == null)
            {
                // Already defined or empty ?
                return((name == null) ? EmptyStruct : scope.FindStructSymbol(name).CtfType);
            }

            CTFStructType cst = CTFStructType.GetStructType(scope, list, align);

            if (name != null)
            {
                scope.AddStruct(new CTFSymbol(name, cst));
            }

            return(cst);
        }
Пример #12
0
        public CTFTTrace(CTFScope scope, List <CTFAssignmentExpression> lcae)
        {
            foreach (CTFAssignmentExpression cae in lcae)
            {
                string name = cae.GetFullName();
                switch (name)
                {
                case "major":
                    major = cae.Src.Calculate();
                    break;

                case "minor":
                    minor = cae.Src.Calculate();
                    break;

                case "uuid":
                    uuid = cae.Src.GetValue().GetString();
                    break;

                case "byte_order":
                    switch (cae.Src.GetValue().GetString())
                    {
                    case "le":
                        msb = false;
                        break;

                    case "be":
                        msb = true;
                        break;

                    default:
                        throw new CTFException();
                    }

                    break;

                case "packet.header":
                    Header = cae.GetType(scope);
                    break;

                default:
                    throw new CTFException();
                }
            }
        }
Пример #13
0
        internal static CTFTypeSpecifier Parse(CTFScope scope, TokParser tp)
        {
            tp.MustBe(Token.EnumId.VARIANT);
            tp.MustBe(Token.EnumId.LT);
            CTFUnaryExpression cue = CTFUnaryExpression.Parse(tp);

            if (cue == null)
            {
                throw new CTFException();
            }

            tp.MustBe(Token.EnumId.GT);
            tp.MustBe(Token.EnumId.LCURL);
            List <CTFStructOrVariantDeclaration> list = CTFStructOrVariantDeclaration.ParseList(scope, tp);

            tp.MustBe(Token.EnumId.RCURL);
            return(new CTFVaraintSpecifier(Token.EnumId.VARIANT, cue, list));
        }
Пример #14
0
        internal static void AddType(CTFScope scope, List <CTFTypeSpecifier> cds, List <CTFTypeSpecifier> cds2, CTFDeclarator cd)
        {
            // used by typealias
            CTFType ct = GetType(scope, cds);

            if (cds2 != null)
            {
                // Special case (unsigned long and so on)
                string    name = FullName(cds2);
                CTFSymbol cs   = new CTFSymbol(name, ct);
                scope.AddType(cs);
            }

            if (cd != null)
            {
                CTFSymbol cs = new CTFSymbol(cd.Name, ct);
                scope.AddType(cs);
            }
        }
Пример #15
0
        internal static List <CTFTypeSpecifier> ParseList(CTFScope scope, TokParser tp)
        {
            List <CTFTypeSpecifier> specifiers = new List <CTFTypeSpecifier>();

            for (;;)
            {
                CTFTypeSpecifier cts = ParseTypeSpecifier(scope, tp);
                if (cts == null)
                {
                    break;
                }

                specifiers.Add(cts);
            }

            if (specifiers.Count == 0)
            {
                return(null);
            }

            return(specifiers);
        }
Пример #16
0
        internal static List <CTFStructOrVariantDeclaration> ParseList(CTFScope scope, TokParser tp)
        {
            List <CTFStructOrVariantDeclaration> list = new List <CTFStructOrVariantDeclaration>();

            for (;;)
            {
                CTFStructOrVariantDeclaration item = Parse(scope, tp);
                if (item == null)
                {
                    break;
                }

                tp.MustBe(Token.EnumId.TERM);
                list.Add(item);
            }

            if (list.Count == 0)
            {
                return(null);
            }

            return(list);
        }
        internal static List <CTFAssignmentExpression> ParseList(CTFScope scope, TokParser tp)
        {
            List <CTFAssignmentExpression> cael = new List <CTFAssignmentExpression>();

            while (true)
            {
                CTFAssignmentExpression cae = Parse(scope, tp);
                if (cae == null)
                {
                    break;
                }

                tp.MustBe(Token.EnumId.TERM);
                cael.Add(cae);
            }

            if (cael.Count == 0)
            {
                return(null);
            }

            return(cael);
        }
Пример #18
0
        private static CTFStructOrVariantDeclaration Parse(CTFScope scope, TokParser tp)
        {
            List <CTFTypeSpecifier> list = new List <CTFTypeSpecifier>();

            for (;;)
            {
                CTFTypeSpecifier s = CTFITypeSpecifier.ParseTypeSpecifier(scope, tp);
                if (s == null)
                {
                    break;
                }

                list.Add(s);
            }

            if (list.Count == 0)
            {
                return(null);
            }

            CTFDeclarator cd = CTFDeclarator.Parse(tp);

            return(new CTFStructOrVariantDeclaration(list, cd));
        }
Пример #19
0
        internal static CTFTypeSpecifier Parse(CTFScope scope, TokParser tp)
        {
            string name = null;
            List <CTFStructOrVariantDeclaration> list = null;

            if (!tp.Match(Token.EnumId.STRUCT))
            {
                return(null);
            }

            if (tp.Token.Id == Token.EnumId.IDEN)
            {
                name = tp.Token.Buffer;
                tp.Next();
            }

            if (tp.Match(Token.EnumId.LCURL))
            {
                list = CTFStructOrVariantDeclaration.ParseList(scope, tp);
                tp.MustBe(Token.EnumId.RCURL);
            }

            int align = 0;

            if (tp.Match(Token.EnumId.ALIGN))
            {
                tp.MustBe(Token.EnumId.LPAREN);
                CTFUnaryExpression cue = CTFUnaryExpression.Parse(tp);
                tp.MustBe(Token.EnumId.RPAREN);
                align = cue.Calculate();
            }

            CTFType ct = CTFType.GetStructType(scope, name, list, align);

            return(new CTFStructSpecifier(ct));
        }
 public CTFType GetType(CTFScope scope) => Cts.GetType(scope);
Пример #21
0
 public override CTFType GetType(CTFScope scope)
 {
     return(new CTFEnumType(scope, this));
 }
Пример #22
0
 public override CTFType GetType(CTFScope scope) => CTFType.StringType;
Пример #23
0
 public override CTFType GetType(CTFScope scope) => ct;
Пример #24
0
 public virtual CTFType GetType(CTFScope scope)
 {
     throw new CTFException();
 }
Пример #25
0
 public CTFEnumType(CTFScope scope, CTFEnumSpecifier ces)
 {
     ctfType = GetType(scope, ces.Cds);
     elems   = ces.List.ToArray();
 }
Пример #26
0
 internal CTFFile()
 {
     scope  = new CTFScope();
     Events = new Dictionary <uint, CTFTEvent>();
     CTFITypeSpecifier.Init();
 }