Esempio n. 1
0
 public PackageScope(ScriptObject parent)
   : base(parent) {
   this.fast = true;
   this.name = null;
   this.owner = null;
   this.isKnownAtCompileTime = true;
 }
 internal void MergeWith(Package p)
 {
     int num = 0;
     int count = p.classList.count;
     while (num < count)
     {
         this.classList.Append(p.classList[num]);
         num++;
     }
     this.scope.MergeWith(p.scope);
 }
Esempio n. 3
0
 internal void MergeWith(Package p){
   for (int i = 0, n = p.classList.count; i < n; i++)
     this.classList.Append(p.classList[i]);
   this.scope.MergeWith(p.scope);
 }
        private AST ParsePackage(Context packageContext)
        {
            AST ast4;
            this.GetNextToken();
            AST expression = null;
            bool flag = this.scanner.GotEndOfLine();
            if (JSToken.Identifier != this.currentToken.token)
            {
                if (JSScanner.CanParseAsExpression(this.currentToken.token))
                {
                    bool flag2;
                    this.ReportError(JSError.KeywordUsedAsIdentifier, packageContext.Clone(), true);
                    expression = new Lookup("package", packageContext);
                    expression = this.MemberExpression(expression, null);
                    expression = this.ParsePostfixExpression(expression, out flag2);
                    expression = this.ParseExpression(expression, false, flag2, JSToken.None);
                    return new Expression(expression.context.Clone(), expression);
                }
                if (flag)
                {
                    this.ReportError(JSError.KeywordUsedAsIdentifier, packageContext.Clone(), true);
                    return new Lookup("package", packageContext);
                }
                if ((JSToken.Increment == this.currentToken.token) || (JSToken.Decrement == this.currentToken.token))
                {
                    bool flag3;
                    this.ReportError(JSError.KeywordUsedAsIdentifier, packageContext.Clone(), true);
                    expression = new Lookup("package", packageContext);
                    expression = this.ParsePostfixExpression(expression, out flag3);
                    expression = this.ParseExpression(expression, false, false, JSToken.None);
                    return new Expression(expression.context.Clone(), expression);
                }
            }
            else
            {
                this.errorToken = this.currentToken;
                expression = this.ParseQualifiedIdentifier(JSError.NoIdentifier);
            }
            Context context = null;
            if ((JSToken.LeftCurly != this.currentToken.token) && (expression == null))
            {
                context = this.currentToken.Clone();
                this.GetNextToken();
            }
            if (JSToken.LeftCurly == this.currentToken.token)
            {
                if (expression == null)
                {
                    if (context == null)
                    {
                        context = this.currentToken.Clone();
                    }
                    this.ReportError(JSError.NoIdentifier, context, true);
                }
            }
            else if (expression == null)
            {
                this.ReportError(JSError.SyntaxError, packageContext);
                if (JSScanner.CanStartStatement(context.token))
                {
                    this.currentToken = context;
                    return this.ParseStatement();
                }
                if (JSScanner.CanStartStatement(this.currentToken.token))
                {
                    this.errorToken = null;
                    return this.ParseStatement();
                }
                this.ReportError(JSError.SyntaxError);
                this.SkipTokensAndThrow();
            }
            else
            {
                if (flag)
                {
                    bool flag4;
                    this.ReportError(JSError.KeywordUsedAsIdentifier, packageContext.Clone(), true);
                    Block block = new Block(packageContext.Clone());
                    block.Append(new Lookup("package", packageContext));
                    expression = this.MemberExpression(expression, null);
                    expression = this.ParsePostfixExpression(expression, out flag4);
                    expression = this.ParseExpression(expression, false, true, JSToken.None);
                    block.Append(new Expression(expression.context.Clone(), expression));
                    block.context.UpdateWith(expression.context);
                    return block;
                }
                this.ReportError(JSError.NoLeftCurly);
            }
            PackageScope item = new PackageScope(this.Globals.ScopeStack.Peek());
            this.Globals.ScopeStack.Push(item);
            try
            {
                string name = (expression != null) ? expression.ToString() : "anonymous package";
                item.name = name;
                packageContext.UpdateWith(this.currentToken);
                ASTList classList = new ASTList(packageContext);
                this.GetNextToken();
                this.noSkipTokenSet.Add(NoSkipTokenSet.s_BlockNoSkipTokenSet);
                this.noSkipTokenSet.Add(NoSkipTokenSet.s_PackageBodyNoSkipTokenSet);
                try
                {
                    while (this.currentToken.token != JSToken.RightCurly)
                    {
                        AST statement = null;
                        try
                        {
                            switch (this.currentToken.token)
                            {
                                case JSToken.Identifier:
                                {
                                    bool flag6;
                                    bool canBeAttribute = true;
                                    statement = this.ParseUnaryExpression(out flag6, ref canBeAttribute, false);
                                    if (canBeAttribute)
                                    {
                                        bool flag8;
                                        statement = this.ParseAttributes(statement, true, false, out flag8);
                                        if (flag8 && (statement is Class))
                                        {
                                            classList.Append(statement);
                                            continue;
                                        }
                                    }
                                    this.ReportError(JSError.OnlyClassesAllowed, statement.context.Clone(), true);
                                    this.SkipTokensAndThrow();
                                    continue;
                                }
                                case JSToken.Interface:
                                case JSToken.Class:
                                {
                                    classList.Append(this.ParseClass(FieldAttributes.PrivateScope, false, this.currentToken.Clone(), false, false, null));
                                    continue;
                                }
                                case JSToken.Enum:
                                {
                                    classList.Append(this.ParseEnum(FieldAttributes.PrivateScope, this.currentToken.Clone(), null));
                                    continue;
                                }
                                case JSToken.Import:
                                {
                                    this.ReportError(JSError.InvalidImport, true);
                                    try
                                    {
                                        this.ParseImportStatement();
                                    }
                                    catch (RecoveryTokenException)
                                    {
                                    }
                                    continue;
                                }
                                case JSToken.Package:
                                {
                                    Context context2 = this.currentToken.Clone();
                                    if (this.ParsePackage(context2) is Package)
                                    {
                                        this.ReportError(JSError.PackageInWrongContext, context2, true);
                                    }
                                    continue;
                                }
                                case JSToken.Internal:
                                case JSToken.Abstract:
                                case JSToken.Public:
                                case JSToken.Static:
                                case JSToken.Private:
                                case JSToken.Protected:
                                case JSToken.Final:
                                {
                                    bool flag5;
                                    statement = this.ParseAttributes(null, true, false, out flag5);
                                    if (!flag5 || !(statement is Class))
                                    {
                                        break;
                                    }
                                    classList.Append(statement);
                                    continue;
                                }
                                case JSToken.Semicolon:
                                {
                                    this.GetNextToken();
                                    continue;
                                }
                                case JSToken.EndOfFile:
                                    this.EOFError(JSError.ErrEOF);
                                    throw new EndOfFile();

                                default:
                                    goto Label_04D9;
                            }
                            this.ReportError(JSError.OnlyClassesAllowed, statement.context.Clone(), true);
                            this.SkipTokensAndThrow();
                            continue;
                        Label_04D9:
                            this.ReportError(JSError.OnlyClassesAllowed, (statement != null) ? statement.context.Clone() : this.CurrentPositionContext(), true);
                            this.SkipTokensAndThrow();
                            continue;
                        }
                        catch (RecoveryTokenException exception)
                        {
                            if ((exception._partiallyComputedNode != null) && (exception._partiallyComputedNode is Class))
                            {
                                classList.Append((Class) exception._partiallyComputedNode);
                                exception._partiallyComputedNode = null;
                            }
                            if (this.IndexOfToken(NoSkipTokenSet.s_PackageBodyNoSkipTokenSet, exception) == -1)
                            {
                                throw exception;
                            }
                            continue;
                        }
                    }
                }
                catch (RecoveryTokenException exception2)
                {
                    if (this.IndexOfToken(NoSkipTokenSet.s_BlockNoSkipTokenSet, exception2) == -1)
                    {
                        this.ReportError(JSError.NoRightCurly, this.CurrentPositionContext());
                        exception2._partiallyComputedNode = new Package(name, expression, classList, packageContext);
                        throw exception2;
                    }
                }
                finally
                {
                    this.noSkipTokenSet.Remove(NoSkipTokenSet.s_PackageBodyNoSkipTokenSet);
                    this.noSkipTokenSet.Remove(NoSkipTokenSet.s_BlockNoSkipTokenSet);
                }
                this.GetNextToken();
                ast4 = new Package(name, expression, classList, packageContext);
            }
            finally
            {
                this.Globals.ScopeStack.Pop();
            }
            return ast4;
        }