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));
        }
Exemple #2
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);
        }
Exemple #3
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));
        }