src/jdk/nashorn/internal/ir/LexicalContextNode.java

Tue, 07 May 2013 14:36:57 +0200

author
lagergren
date
Tue, 07 May 2013 14:36:57 +0200
changeset 252
544e17632e96
parent 247
5a3f7867e19c
child 253
fb1d7ea3e1b6
permissions
-rw-r--r--

8013913: Removed Source field from all nodes except FunctionNode in order to save footprint
Reviewed-by: jlaskey, attila

     1 /*
     2  * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.  Oracle designates this
     8  * particular file as subject to the "Classpath" exception as provided
     9  * by Oracle in the LICENSE file that accompanied this code.
    10  *
    11  * This code is distributed in the hope that it will be useful, but WITHOUT
    12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    14  * version 2 for more details (a copy is included in the LICENSE file that
    15  * accompanied this code).
    16  *
    17  * You should have received a copy of the GNU General Public License version
    18  * 2 along with this work; if not, write to the Free Software Foundation,
    19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    20  *
    21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    22  * or visit www.oracle.com if you need additional information or have any
    23  * questions.
    24  */
    25 package jdk.nashorn.internal.ir;
    27 import jdk.nashorn.internal.ir.visitor.NodeVisitor;
    29 /**
    30  * Superclass for nodes that can be part of the lexical context
    31  * @see LexicalContext
    32  */
    33 public abstract class LexicalContextNode extends Node {
    34     /**
    35      * Constructor
    36      *
    37      * @param token  token
    38      * @param finish finish
    39      */
    40     protected LexicalContextNode(final long token, final int finish) {
    41         super(token, finish);
    42     }
    44     /**
    45      * Copy constructor
    46      *
    47      * @param node source node
    48      */
    49     protected LexicalContextNode(final LexicalContextNode node) {
    50         super(node);
    51     }
    53     /**
    54      * Accept function for the node given a lexical context. It must be prepared
    55      * to replace itself if present in the lexical context
    56      *
    57      * @param lc      lexical context
    58      * @param visitor node visitor
    59      *
    60      * @return new node or same node depending on state change
    61      */
    62     protected abstract Node accept(final LexicalContext lc, final NodeVisitor visitor);
    64     @Override
    65     public Node accept(final NodeVisitor visitor) {
    66         final LexicalContext lc = visitor.getLexicalContext();
    67         lc.push(this);
    68         final LexicalContextNode newNode = (LexicalContextNode)accept(lc, visitor);
    69         return lc.pop(newNode);
    70     }
    72     /**
    73      * Set the symbol and replace in lexical context if applicable
    74      * @param lc     lexical context
    75      * @param symbol symbol
    76      * @return new node if symbol changed
    77      */
    78     @Override
    79     public Node setSymbol(final LexicalContext lc, final Symbol symbol) {
    80         return Node.replaceInLexicalContext(lc, this, (LexicalContextNode)super.setSymbol(null, symbol));
    81     }
    83 }

mercurial