PageRenderTime 18ms CodeModel.GetById 13ms app.highlight 3ms RepoModel.GetById 1ms app.codeStats 0ms

/interpreter/tags/at2dist130208/src/edu/vub/at/objects/natives/NATFieldSelection.java

http://ambienttalk.googlecode.com/
Java | 100 lines | 49 code | 9 blank | 42 comment | 0 complexity | cfbaf04836e352391e8de69fc718f355 MD5 | raw file
  1/**
  2 * AmbientTalk/2 Project
  3 * NATFieldSelection.java created on 31-jul-2006 at 12:40:42
  4 * (c) Programming Technology Lab, 2006 - 2007
  5 * Authors: Tom Van Cutsem & Stijn Mostinckx
  6 * 
  7 * Permission is hereby granted, free of charge, to any person
  8 * obtaining a copy of this software and associated documentation
  9 * files (the "Software"), to deal in the Software without
 10 * restriction, including without limitation the rights to use,
 11 * copy, modify, merge, publish, distribute, sublicense, and/or
 12 * sell copies of the Software, and to permit persons to whom the
 13 * Software is furnished to do so, subject to the following
 14 * conditions:
 15 *
 16 * The above copyright notice and this permission notice shall be
 17 * included in all copies or substantial portions of the Software.
 18 *
 19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 20 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
 21 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 22 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
 23 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
 24 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 25 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
 26 * OTHER DEALINGS IN THE SOFTWARE.
 27 */
 28package edu.vub.at.objects.natives;
 29
 30import java.util.LinkedList;
 31import java.util.Vector;
 32
 33import edu.vub.at.exceptions.InterpreterException;
 34import edu.vub.at.objects.ATFieldSelection;
 35import edu.vub.at.objects.ATMessage;
 36import edu.vub.at.objects.ATObject;
 37import edu.vub.at.objects.ATTable;
 38import edu.vub.at.objects.ATTypeTag;
 39import edu.vub.at.objects.coercion.NativeTypeTags;
 40import edu.vub.at.objects.grammar.ATSymbol;
 41
 42/**
 43 * Instances of this class represent first-class field selections.
 44 * They encapsulate a selector and may be turned into an actual field access by invoking meta_sendTo.
 45 * This method provides the invocation with a receiver to apply itself to.
 46 * 
 47 * @author tvcutsem
 48 */
 49public final class NATFieldSelection extends NATMessage implements ATFieldSelection {
 50
 51	public NATFieldSelection(ATSymbol sel, ATTable annotations) throws InterpreterException {
 52		super(sel, NATTable.EMPTY, annotations, NativeTypeTags._FIELDSEL_);
 53	}
 54	
 55    /**
 56     * Copy constructor.
 57     */
 58    private NATFieldSelection(FieldMap map,
 59            Vector state,
 60            LinkedList originalCustomFields,
 61            MethodDictionary methodDict,
 62            ATObject dynamicParent,
 63            ATObject lexicalParent,
 64            byte flags,
 65            ATTypeTag[] types) throws InterpreterException {
 66    	super(map, state, originalCustomFields, methodDict, dynamicParent, lexicalParent, flags, types);
 67    }
 68
 69	/**
 70	 * To evaluate a field selection, invoke a field accessor method on the receiver.
 71	 * 
 72	 * @return the return value of the invoked method.
 73	 */
 74	public ATObject prim_sendTo(ATMessage self, ATObject receiver, ATObject sender) throws InterpreterException {
 75		return receiver.meta_invokeField(receiver, self.base_selector());
 76	}
 77	
 78	public NATText meta_print() throws InterpreterException {
 79		return NATText.atValue("<field selection:"+base_selector().toString()+">");
 80	}
 81	
 82	protected NATObject createClone(FieldMap map,
 83			Vector state,
 84			LinkedList originalCustomFields,
 85			MethodDictionary methodDict,
 86			ATObject dynamicParent,
 87			ATObject lexicalParent,
 88			byte flags,
 89			ATTypeTag[] types) throws InterpreterException {
 90		return new NATFieldSelection(map,
 91				state,
 92				originalCustomFields,
 93				methodDict,
 94				dynamicParent,
 95				lexicalParent,
 96				flags,
 97				types);
 98	}
 99	
100}