001: /***** BEGIN LICENSE BLOCK *****
002: * Version: CPL 1.0/GPL 2.0/LGPL 2.1
003: *
004: * The contents of this file are subject to the Common Public
005: * License Version 1.0 (the "License"); you may not use this file
006: * except in compliance with the License. You may obtain a copy of
007: * the License at http://www.eclipse.org/legal/cpl-v10.html
008: *
009: * Software distributed under the License is distributed on an "AS
010: * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
011: * implied. See the License for the specific language governing
012: * rights and limitations under the License.
013: *
014: * Copyright (C) 2001-2002 Benoit Cerrina <b.cerrina@wanadoo.fr>
015: * Copyright (C) 2001-2002 Jan Arne Petersen <jpetersen@uni-bonn.de>
016: * Copyright (C) 2002-2004 Anders Bengtsson <ndrsbngtssn@yahoo.se>
017: * Copyright (C) 2004 Thomas E Enebo <enebo@acm.org>
018: * Copyright (C) 2004 Stefan Matthias Aust <sma@3plus4.de>
019: *
020: * Alternatively, the contents of this file may be used under the terms of
021: * either of the GNU General Public License Version 2 or later (the "GPL"),
022: * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
023: * in which case the provisions of the GPL or the LGPL are applicable instead
024: * of those above. If you wish to allow use of your version of this file only
025: * under the terms of either the GPL or the LGPL, and not to allow others to
026: * use your version of this file under the terms of the CPL, indicate your
027: * decision by deleting the provisions above and replace them with the notice
028: * and other provisions required by the GPL or the LGPL. If you do not delete
029: * the provisions above, a recipient may use your version of this file under
030: * the terms of any one of the CPL, the GPL or the LGPL.
031: ***** END LICENSE BLOCK *****/package org.jruby.ast;
032:
033: import java.io.IOException;
034: import java.util.List;
035: import org.jruby.ast.types.INameNode;
036: import org.jruby.ast.visitor.NodeVisitor;
037: import org.jruby.evaluator.Instruction;
038: import org.jruby.lexer.yacc.ISourcePosition;
039: import org.jruby.runtime.MethodIndex;
040:
041: /**
042: * Represents a method call with self as an implicit receiver.
043: */
044: public class FCallNode extends Node implements INameNode,
045: IArgumentNode, BlockAcceptingNode {
046: static final long serialVersionUID = 3590332973770104094L;
047:
048: private String name;
049: public final int index;
050: private Node argsNode;
051: private Node iterNode;
052:
053: public FCallNode(ISourcePosition position, String name,
054: Node argsNode) {
055: this (position, name, argsNode, null);
056: }
057:
058: public FCallNode(ISourcePosition position, String name,
059: Node argsNode, Node iterNode) {
060: super (position, NodeTypes.FCALLNODE);
061: this .name = name.intern();
062: setArgsNode(argsNode);
063: this .iterNode = iterNode;
064: this .index = MethodIndex.getIndex(this .name);
065: }
066:
067: private void readObject(java.io.ObjectInputStream in)
068: throws IOException, ClassNotFoundException {
069: in.defaultReadObject();
070:
071: // deserialized strings are not interned; intern it now
072: name = name.intern();
073: }
074:
075: /**
076: * Accept for the visitor pattern.
077: * @param iVisitor the visitor
078: **/
079: public Instruction accept(NodeVisitor iVisitor) {
080: return iVisitor.visitFCallNode(this );
081: }
082:
083: /**
084: * Get the node that represents a block or a block variable.
085: */
086: public Node getIterNode() {
087: return iterNode;
088: }
089:
090: public void setIterNode(Node iterNode) {
091: this .iterNode = iterNode;
092: }
093:
094: /**
095: * Gets the argsNode.
096: * @return Returns a Node
097: */
098: public Node getArgsNode() {
099: return argsNode;
100: }
101:
102: /**
103: * Set the argsNode
104: *
105: * @param argsNode set the arguments for this node.
106: */
107: public void setArgsNode(Node argsNode) {
108: this .argsNode = argsNode;
109: // If we have more than one arg, make sure the array created to contain them is not ObjectSpaced
110: if (argsNode instanceof ArrayNode) {
111: ((ArrayNode) argsNode).setLightweight(true);
112: }
113: }
114:
115: /**
116: * Gets the name.
117: * @return Returns a String
118: */
119: public String getName() {
120: return name;
121: }
122:
123: public List childNodes() {
124: return createList(argsNode, iterNode);
125: }
126:
127: public String toString() {
128: return "FCallNode: " + getName();
129: }
130: }
|