Esempio n. 1
0
 internal void Add(ObjectLiteralItem item)
 {
     elems.Add(item);
 }
Esempio n. 2
0
 internal void Add(ObjectLiteralItem item)
 {
     elems.Add (item);
 }
Esempio n. 3
0
        AST PrimaryExpr(AST parent)
        {
            int tt;
            AST pn;

            ts.allow_reg_exp = true;
            tt = ts.GetToken ();
            ts.allow_reg_exp = false;

            if (tt == Token.FUNCTION) {
                return Function (parent, FunctionType.Expression);
            } else if (tt == Token.LB) {
                ASTList elems = new ASTList (parent, new Location (ts.SourceName, ts.LineNumber));
                int skip_count = 0;
                decompiler.AddToken (Token.LB);
                bool after_lb_or_comma = true;
                for (;;) {
                    ts.allow_reg_exp = true;
                    tt = ts.PeekToken ();
                    ts.allow_reg_exp = false;

                    if (tt == Token.COMMA) {
                        ts.GetToken ();
                        decompiler.AddToken (Token.COMMA);
                        if (!after_lb_or_comma)
                            after_lb_or_comma = true;
                        else {
                            elems.Add (null);
                            ++skip_count;
                        }
                    } else if (tt == Token.RB) {
                        ts.GetToken ();
                        decompiler.AddToken (Token.RB);
                        break;
                    } else {
                        if (!after_lb_or_comma)
                            ReportError ("msg.no.bracket.arg");
                        elems.Add (AssignExpr (parent, false));
                        after_lb_or_comma = false;
                    }
                }
                // FIXME: pass a real Context
                return new ArrayLiteral (null, elems, skip_count, new Location (ts.SourceName, ts.LineNumber));
            } else if (tt == Token.LC) {
                Location location = new Location (ts.SourceName, ts.LineNumber);
                ArrayList elems = new ArrayList ();
                decompiler.AddToken (Token.LC);

                if (!ts.MatchToken (Token.RC)) {
                    bool first = true;

                    commaloop: {
                    do {
                        ObjectLiteralItem property;

                        if (!first)
                            decompiler.AddToken (Token.COMMA);
                        else
                            first = false;

                        tt = ts.GetToken ();

                        if (tt == Token.NAME || tt == Token.STRING) {
                            string s = ts.GetString;
                            if (tt == Token.NAME)
                                decompiler.AddName (s);
                            else
                                decompiler.AddString (s);
                            property = new ObjectLiteralItem (s);
                        } else if (tt == Token.NUMBER) {
                            double n = ts.GetNumber;
                            decompiler.AddNumber (n);
                            property = new ObjectLiteralItem (n);
                        } else if (tt == Token.RC) {
                            // trailing comma is OK
                            ts.UnGetToken (tt);
                            goto leave_commaloop;
                        } else {
                            ReportError ("msg.bad.prop");
                            goto leave_commaloop;
                        }
                        MustMatchToken (Token.COLON, "msg.no.colon.prop");
                        // OBJLIT is used as ':' in object literal for
                        // decompilation to solve spacing ambiguity.
                        decompiler.AddToken (Token.OBJECTLIT);
                        property.exp = AssignExpr (parent, false);
                        elems.Add (property);
                    } while (ts.MatchToken (Token.COMMA));
                    MustMatchToken (Token.RC, "msg.no.brace.prop");
                    }
                    leave_commaloop:
                    ;
                }
                return new ObjectLiteral (elems, location);
            } else if (tt == Token.LP) {
                decompiler.AddToken (Token.LP);
                pn = Expr (parent, false);
                decompiler.AddToken (Token.RP);
                MustMatchToken (Token.RP, "msg.no.paren");
                decompiler.AddToken (Token.RP);
                return pn;
            } else if (tt == Token.NAME) {
                string name = ts.GetString;
                decompiler.AddName (name);
                return new Identifier (parent, name, new Location (ts.SourceName, ts.LineNumber));
            } else if (tt == Token.NUMBER) {
                double n = ts.GetNumber;
                decompiler.AddNumber (n);

                Location location = new Location (ts.SourceName, ts.LineNumber);

                if (HasNoDecimals (n)) {
                    if (InRangeOf (n, Byte.MinValue, Byte.MaxValue))
                        return new ByteConstant (parent, (byte) n, location);
                    else if (InRangeOf (n, Int16.MinValue, Int16.MaxValue))
                        return new ShortConstant (parent, (short) n, location);
                    else if (InRangeOf (n, Int32.MinValue, Int32.MaxValue))
                        return new IntConstant (parent, (int) n, location);
                    else if (InRangeOf (n, Int64.MinValue, Int64.MaxValue))
                        return new LongConstant (parent, (long) n, location);
                    else
                        return new DoubleConstant (parent, n, location);
                } else {
                    if (InRangeOf (n, Single.MinValue, Single.MaxValue))
                        return new FloatConstant (parent, (float) n, location);
                    else if (InRangeOf (n, Double.MinValue, Double.MaxValue))
                        return new DoubleConstant (parent, n, location);
                    else
                        return new DoubleConstant (parent, n, location);
                }
            } else if (tt == Token.STRING) {
                string s = ts.GetString;
                decompiler.AddString (s);
                return new StringLiteral (null, s, new Location (ts.SourceName, ts.LineNumber));
            } else if (tt == Token.REGEXP) {
                string flags = ts.reg_exp_flags;
                ts.reg_exp_flags = null;
                string re = ts.GetString;
                decompiler.AddRegexp (re, flags);
                return new RegExpLiteral (parent, re, flags, new Location (ts.SourceName, ts.LineNumber));
            } else if (tt == Token.NULL) {
                decompiler.AddToken (tt);
                // FIXME, build the null object;
                return null;
            } else if (tt ==  Token.THIS) {
                decompiler.AddToken (tt);
                return new This (parent, new Location (ts.SourceName, ts.LineNumber));
            } else if (tt == Token.FALSE || tt == Token.TRUE) {
                decompiler.AddToken (tt);
                bool v;
                if (tt == Token.FALSE)
                    v = false;
                else
                    v = true;
                return new BooleanConstant (null, v, new Location (ts.SourceName, ts.LineNumber));
            } else if (tt == Token.RESERVED) {
                ReportError ("msg.reserved.id");
            } else if (tt == Token.ERROR) {
                /* the scanner or one of its subroutines reported the error. */
            } else
                ReportError ("msg.syntax");
            return null; // should never reach here
        }