Example #1
0
        public CTFFloatType(List <CTFAssignmentExpression> cae)
        {
            foreach (CTFAssignmentExpression ae in cae)
            {
                //CTFUnaryExpression cue = ae.dst; // It must be identifier
                string             name = ae.GetName();
                CTFUnaryExpression src  = ae.Src;
                switch (name)
                {
                case "exp_dig":
                    exp_dig = src.Calculate();
                    break;

                case "mant_dig":
                    mant_dig = src.Calculate();
                    break;

                case "align":
                    talign = src.Calculate();
                    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);
        }
Example #3
0
        internal static CTFEnumElem Parse(TokParser tp)
        {
            string name = tp.GetIden();

            tp.MustBe(Token.EnumId.ASSIGNMENT);
            CTFUnaryExpression first = CTFUnaryExpression.Parse(tp);
            CTFEnumElem        ce    = new CTFEnumElem(name, first.Calculate());

            if (tp.Match(Token.EnumId.ELIPSES))
            {
                ce.Second = CTFUnaryExpression.Parse(tp).Calculate();
            }

            return(ce);
        }
        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));
        }
Example #5
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));
        }
 private CTFAssignmentExpression(CTFUnaryExpression cue, CTFTypeSpecifier cts)
 {
     Dst      = cue;
     this.Cts = cts;
 }
 private CTFAssignmentExpression(CTFUnaryExpression cue, CTFUnaryExpression cue2)
 {
     Dst = cue;
     Src = cue2;
 }
Example #8
0
        public CTFIntType(List <CTFAssignmentExpression> cae)
        {
            foreach (CTFAssignmentExpression ae in cae)
            {
                string             name = ae.GetName();
                CTFUnaryExpression src  = ae.Src;
                switch (name)
                {
                case "size":
                    size = src.Calculate();
                    break;

                case "align":
                    talign = src.Calculate();
                    break;

                case "base":
                    ibase = src.Calculate();
                    break;

                case "encoding":
                    string value = src.GetValue().GetString();
                    switch (value)
                    {
                    case "none":
                        encoding = 0;
                        break;

                    case "UTF8":
                        encoding = 1;
                        break;
                    }

                    break;

                case "signed":
                    string v = src.GetValue().GetString();
                    switch (v)
                    {
                    case "false":
                        signed = false;
                        break;

                    case "0":
                        signed = false;
                        break;

                    case "1":
                        signed = true;
                        break;

                    case "true":
                        signed = true;
                        break;

                    default:
                        throw new CTFException();
                    }

                    break;

                case "map":     // TODO
                    break;

                default:
                    throw new CTFException();
                }
            }
        }
 private CTFVaraintSpecifier(Token.EnumId id, CTFUnaryExpression cue, List <CTFStructOrVariantDeclaration> list)
 {
     this.Cue  = cue;
     this.List = list;
 }