ParserContextBaseNode.java revision 1423:c13179703f65
11539Srgrimes/*
21539Srgrimes * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
31539Srgrimes * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
41539Srgrimes *
51539Srgrimes * This code is free software; you can redistribute it and/or modify it
61539Srgrimes * under the terms of the GNU General Public License version 2 only, as
71539Srgrimes * published by the Free Software Foundation.  Oracle designates this
81539Srgrimes * particular file as subject to the "Classpath" exception as provided
91539Srgrimes * by Oracle in the LICENSE file that accompanied this code.
101539Srgrimes *
111539Srgrimes * This code is distributed in the hope that it will be useful, but WITHOUT
121539Srgrimes * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
131539Srgrimes * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
141539Srgrimes * version 2 for more details (a copy is included in the LICENSE file that
151539Srgrimes * accompanied this code).
161539Srgrimes *
171539Srgrimes * You should have received a copy of the GNU General Public License version
181539Srgrimes * 2 along with this work; if not, write to the Free Software Foundation,
191539Srgrimes * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
201539Srgrimes *
211539Srgrimes * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
221539Srgrimes * or visit www.oracle.com if you need additional information or have any
231539Srgrimes * questions.
241539Srgrimes */
251539Srgrimespackage jdk.nashorn.internal.parser;
261539Srgrimes
271539Srgrimesimport java.util.ArrayList;
281539Srgrimesimport java.util.List;
291539Srgrimesimport jdk.nashorn.internal.ir.Statement;
301539Srgrimes
311539Srgrimes/**
321539Srgrimes * Base class for parser context nodes
331539Srgrimes */
341539Srgrimesabstract class ParserContextBaseNode implements ParserContextNode {
358858Srgrimes    /**
361539Srgrimes     * Flags for this node
371539Srgrimes     */
381539Srgrimes    protected int flags;
391539Srgrimes
401539Srgrimes    private List<Statement> statements;
411539Srgrimes
428858Srgrimes    /**
431539Srgrimes     * Constructor
441539Srgrimes     */
451539Srgrimes    public ParserContextBaseNode() {
461539Srgrimes        this.statements = new ArrayList<>();
471539Srgrimes    }
481539Srgrimes
491539Srgrimes    /**
501539Srgrimes     * @return The flags for this node
511539Srgrimes     */
521539Srgrimes    @Override
533070Spst    public int getFlags() {
543070Spst        return flags;
553070Spst    }
5610132Speter
571539Srgrimes    /**
581539Srgrimes     * Returns a single flag
591539Srgrimes     * @param flag flag
601539Srgrimes     * @return A single flag
611539Srgrimes     */
623070Spst    protected int getFlag(final int flag) {
631539Srgrimes        return (flags & flag);
643070Spst    }
653070Spst
663070Spst    /**
671539Srgrimes     * @param flag flag
683070Spst     * @return the new flags
693070Spst     */
703070Spst    @Override
713070Spst    public int setFlag(final int flag) {
723070Spst        flags |= flag;
733070Spst        return flags;
743070Spst    }
7510132Speter
763070Spst    /**
773070Spst     * @return The list of statements that belongs to this node
781539Srgrimes     */
791539Srgrimes    @Override
801539Srgrimes    public List<Statement> getStatements() {
811539Srgrimes        return statements;
821539Srgrimes    }
831539Srgrimes
843070Spst    /**
851539Srgrimes     * @param statements statements
861539Srgrimes     */
871539Srgrimes    @Override
881539Srgrimes    public void setStatements(final List<Statement> statements) {
891539Srgrimes        this.statements = statements;
901539Srgrimes    }
911539Srgrimes
921539Srgrimes    /**
931539Srgrimes     * Adds a statement at the end of the statement list
941539Srgrimes     * @param statement The statement to add
951539Srgrimes     */
963070Spst    @Override
973070Spst    public void appendStatement(final Statement statement) {
981539Srgrimes        this.statements.add(statement);
991539Srgrimes    }
1001539Srgrimes
1011539Srgrimes    /**
1023070Spst     * Adds a statement at the beginning of the statement list
1031539Srgrimes     * @param statement The statement to add
1043070Spst     */
1053070Spst    @Override
1061539Srgrimes    public void prependStatement(final Statement statement) {
1071539Srgrimes        this.statements.add(0, statement);
1081539Srgrimes    }
1091539Srgrimes}
1103070Spst