コード例 #1
0
        public override bool Walk(Block node) {
            var prevScope = _scope;
            var prevSuite = _curSuite;
            _curSuite = node;

            try {
                // recursively walk the statements in the suite
                for (int i = 0; i < node.Count; i++) {
                    if (DDG.IsGwtCode(node, i)) {
                        return false;
                    }
                    node[i].Walk(this);
                }
            } finally {
                _curSuite = prevSuite;
                while (_scope != prevScope) {
                    StatementEnvironmentRecord stmtRec = _scope as StatementEnvironmentRecord;
                    if (stmtRec != null) {
                        stmtRec.EndIndex = node.GetEndIndex(_tree.LocationResolver);
                    }
                    _scope = _scope.Parent;
                }
            }
            return false;
        }
コード例 #2
0
 public override void PostWalk(Block node) {
     base.PostWalk(node);
 }
コード例 #3
0
 public override bool Walk(Block node) { AddNode(node); return true; }
コード例 #4
0
 public IsInstanceScope(int startIndex, Block effectiveSuite, InterpreterScope outerScope)
     : base(null, null, outerScope) {
     _startIndex = _endIndex = startIndex;
     _effectiveSuite = effectiveSuite;
 }
コード例 #5
0
        public override bool Walk(Block node)
        {
            if (node != null)
            {
                if (GetScope(node) == null
                    && node.Parent != null
                    && !(node.Parent is SwitchCase)
                    && !(node.Parent is FunctionObject))
                {
                    SetScope(
                        node,
                        new BlockScope(node, CurrentLexicalScope, _errorSink)
                        {
                            IsInWithScope = m_withDepth > 0
                        }
                    );
                }

                if (GetScope(node) != null)
                {
                    m_lexicalStack.Push(GetScope(node));
                }

                try
                {
                    // recurse the block statements
                    for (var ndx = 0; ndx < node.Count; ++ndx)
                    {
                        var statement = node[ndx];
                        if (statement != null)
                        {
                            statement.Walk(this);
                        }
                    }
                }
                finally
                {

                    if (GetScope(node) != null)
                    {
                        Debug.Assert(CurrentLexicalScope == GetScope(node));
                        m_lexicalStack.Pop();
                    }
                }

                // now, if the block has no lex-decls, we really don't need a separate scope.
                if (GetScope(node) != null
                    && !(GetScope(node) is WithScope)
                    && !(GetScope(node) is CatchScope)
                    && GetScope(node).LexicallyDeclaredNames.Count == 0)
                {
                    CollapseBlockScope(GetScope(node));
                    SetScope(node, null);
                }
            }
            return false;
        }
コード例 #6
0
        private void ParseBuffers(BufferParser bufferParser, params ITextSnapshot[] snapshots) {
            IProjectEntry entry = bufferParser._currentProjEntry;

            IJsProjectEntry jsProjEntry = entry as IJsProjectEntry;
            List<JsAst> asts = new List<JsAst>();
            foreach (var snapshot in snapshots) {
                if (snapshot.TextBuffer.Properties.ContainsProperty(NodejsReplEvaluator.InputBeforeReset)) {
                    continue;
                }

                if (snapshot.IsReplBufferWithCommand()) {
                    continue;
                }

                if (jsProjEntry != null && snapshot.TextBuffer.ContentType.IsOfType(NodejsConstants.Nodejs)) {
                    JsAst ast;
                    CollectingErrorSink errorSink;

                    var reader = new SnapshotSpanSourceCodeReader(new SnapshotSpan(snapshot, new Span(0, snapshot.Length)));
                    ParseNodejsCode(reader, out ast, out errorSink);

                    if (ast != null) {
                        asts.Add(ast);
                    }

                    // update squiggles for the buffer
                    UpdateErrorsAndWarnings(entry, snapshot, errorSink);
                } else {
                    // other file such as XAML
                    IExternalProjectEntry externalEntry;
                    if ((externalEntry = (entry as IExternalProjectEntry)) != null) {
                        var snapshotContent = new SnapshotSpanSourceCodeReader(new SnapshotSpan(snapshot, new Span(0, snapshot.Length)));
                        externalEntry.ParseContent(snapshotContent, new SnapshotCookie(snapshotContent.Snapshot));
                        if (ShouldEnqueue()) {
                            _analysisQueue.Enqueue(entry, AnalysisPriority.High);
                        }
                    }
                }
            }

            if (jsProjEntry != null) {
                if (asts.Count > 0) {
                    JsAst finalAst;
                    if (asts.Count == 1) {
                        finalAst = asts[0];
                    } else {
                        // multiple ASTs, merge them together
                        var block = new Block(default(EncodedSpan));
                        var statements = new List<Statement>();
                        foreach (var code in asts) {
                            statements.Add(code.Block);
                        }
                        block.Statements = statements.ToArray();
                        finalAst = asts.Last().CloneWithNewBlock(block);
                    }

                    jsProjEntry.UpdateTree(finalAst, new SnapshotCookie(snapshots[0])); // SnapshotCookie is not entirely right, we should merge the snapshots
                    if (ShouldEnqueue()) {
                        _analysisQueue.Enqueue(entry, AnalysisPriority.High);
                    }
                } else {
                    // indicate that we are done parsing.
                    JsAst prevTree;
                    IAnalysisCookie prevCookie;
                    jsProjEntry.GetTreeAndCookie(out prevTree, out prevCookie);
                    jsProjEntry.UpdateTree(prevTree, prevCookie);
                }
            }
        }
コード例 #7
0
 private bool CheckBlock(Block block) {
     if (_typedChar == '}' && 
         block != null && 
         block.Braces != BraceState.None && 
         block.GetEndIndex(_tree.LocationResolver) == _position) {
         return true;
     }
     return false;
 }
コード例 #8
0
ファイル: JsAst.cs プロジェクト: lioaphy/nodejstools
 public JsAst CloneWithNewBlock(Block block) {
     return new JsAst(EncodedSpan, _locationResolver) {
         Block = block
     };
 }
コード例 #9
0
 public override bool Walk(Block block) {
     if (CheckBlock(block)) {
         Span = GetTargetStatement(block).GetSpan(_tree.LocationResolver);
         return false;
     }
     return true;
 }
コード例 #10
0
        /// <summary>
        /// Reformats a block node.  If the block has braces then the formatting will be updated
        /// appropriately, if forceNewLine
        /// </summary>
        /// <param name="block"></param>
        /// <param name="braceOnNewline"></param>
        private void WalkBlock(Block block) {
            Debug.Assert(block == null || block.Braces != BraceState.None);
            if (block != null && block.Braces != BraceState.None) {
                bool isMultiLine = ContainsLineFeed(block.GetStartIndex(_tree.LocationResolver), block.GetEndIndex(_tree.LocationResolver));
                bool isComment = FollowedBySingleLineComment(block.GetStartIndex(_tree.LocationResolver), false);
                if (block.Count > 0 && isMultiLine && !isComment) {
                    // multiline block statement, make sure the 1st statement
                    // starts on a new line. If this is a comment it can stay on the same line as the brace
                    EnsureNewLineFollowing(block.GetStartIndex(_tree.LocationResolver) + "{".Length);
                }

                var parent = block.Parent;
                Indent();

                WalkStatements(block, block.Statements, isMultiLine);

                Dedent();

                if (block.Braces == BraceState.StartAndEnd) {
                    if (isMultiLine) {
                        EnsureNewLinePreceeding(block.GetEndIndex(_tree.LocationResolver) - 1);
                    } else {
                        ReplacePreceedingWhiteSpaceMaybeMultiline(block.GetEndIndex(_tree.LocationResolver) - 1);
                    }
                }
            }
        }
コード例 #11
0
 public override bool Walk(Block node) {
     Debug.Assert(node.Braces != BraceState.None);
     WalkBlock(node);
     return false;
 }
コード例 #12
0
        private void WalkFlowControlBlockWithOptionalParens(Block block, int startIndex, int previousExpressionEnd, bool inParens) {
            if (block != null) {
                if (block.Braces == BraceState.None) {
                    // braces are omitted...

                    // if (foo) 
                    //      blah
                    // vs
                    // if (foo) blah

                    // TODO: https://nodejstools.codeplex.com/workitem/1475 causes a failure as our end < start.  Parser is failing and until fixed will cause a failure here.
                    bool multiLine = ContainsLineFeed(previousExpressionEnd, block.GetStartIndex(_tree.LocationResolver));
                    if (multiLine) {
                        // remove trailing whitespace at the end of this line
                        bool followedBySingleLineComment;
                        int startOfWhiteSpace, whiteSpaceCount;
                        ParseEndOfLine(previousExpressionEnd, inParens, out followedBySingleLineComment, out startOfWhiteSpace, out whiteSpaceCount);
                        if (startOfWhiteSpace != -1) {
                            _edits.Add(new Edit(startOfWhiteSpace, whiteSpaceCount, ""));
                        }
                        Indent();
                    }

                    WalkStatements(startIndex, block.Statements, false);
                    if (multiLine) {
                        Dedent();
                    }
                } else {
                    var blockStart = block.GetStartIndex(_tree.LocationResolver);
                    if (_code[blockStart] == '{') {
                        ReplacePreceedingIncludingNewLines(blockStart, GetFlowControlBraceInsertion(previousExpressionEnd, false, blockStart));
                    } else {
                        ReplacePreceedingIncludingNewLines(blockStart, GetFlowControlBraceInsertion(previousExpressionEnd, false, -1));
                    }
                    WalkBlock(block);
                }
            }
        }
コード例 #13
0
 private void WalkFlowControlBlockWithOptionalParens(Block block, int previousExpressionEnd, bool inParens) {
     WalkFlowControlBlockWithOptionalParens(block, ((Statement)block.Parent).GetStartIndex(_tree.LocationResolver), previousExpressionEnd, inParens);
 }