PageRenderTime 25ms CodeModel.GetById 15ms app.highlight 8ms RepoModel.GetById 1ms app.codeStats 0ms

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

http://ambienttalk.googlecode.com/
Java | 113 lines | 61 code | 10 blank | 42 comment | 1 complexity | bf54737b67f9251f9edd78ab0f331d69 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.Set;
 32import java.util.Vector;
 33
 34import edu.vub.at.exceptions.InterpreterException;
 35import edu.vub.at.objects.ATFieldSelection;
 36import edu.vub.at.objects.ATMessage;
 37import edu.vub.at.objects.ATObject;
 38import edu.vub.at.objects.ATTable;
 39import edu.vub.at.objects.ATTypeTag;
 40import edu.vub.at.objects.coercion.NativeTypeTags;
 41import edu.vub.at.objects.grammar.ATSymbol;
 42import edu.vub.util.TempFieldGenerator;
 43
 44/**
 45 * Instances of this class represent first-class field selections.
 46 * They encapsulate a selector and may be turned into an actual field access by invoking meta_sendTo.
 47 * This method provides the invocation with a receiver to apply itself to.
 48 * 
 49 * @author tvcutsem
 50 */
 51public final class NATFieldSelection extends NATMessage implements ATFieldSelection {
 52
 53	public NATFieldSelection(ATSymbol sel, ATTable annotations) throws InterpreterException {
 54		super(sel, NATTable.EMPTY, annotations, NativeTypeTags._FIELDSEL_);
 55	}
 56	
 57    /**
 58     * Copy constructor.
 59     */
 60    private NATFieldSelection(FieldMap map,
 61            Vector state,
 62            LinkedList originalCustomFields,
 63            MethodDictionary methodDict,
 64            ATObject dynamicParent,
 65            ATObject lexicalParent,
 66            byte flags,
 67            ATTypeTag[] types,
 68            Set freeVars) throws InterpreterException {
 69    	super(map, state, originalCustomFields, methodDict, dynamicParent, lexicalParent, flags, types, freeVars);
 70    }
 71
 72	/**
 73	 * To evaluate a field selection, invoke a field accessor method on the receiver.
 74	 * 
 75	 * @return the return value of the invoked method.
 76	 */
 77	public ATObject prim_sendTo(ATMessage self, ATObject receiver, ATObject sender) throws InterpreterException {
 78		return receiver.meta_invokeField(receiver, self.base_selector());
 79	}
 80	
 81	public NATText meta_print() throws InterpreterException {
 82		return NATText.atValue("<field selection:"+base_selector().toString()+">");
 83	}
 84	
 85	public NATText impl_asCode(TempFieldGenerator objectMap) throws InterpreterException {
 86		if (objectMap.contains(this)) {
 87			return objectMap.getName(this);
 88		}
 89		NATText name = objectMap.put(this, NATText.atValue("." + base_selector().meta_print().javaValue));
 90		return name;
 91	}
 92	
 93	protected NATObject createClone(FieldMap map,
 94			Vector state,
 95			LinkedList originalCustomFields,
 96			MethodDictionary methodDict,
 97			ATObject dynamicParent,
 98			ATObject lexicalParent,
 99			byte flags,
100			ATTypeTag[] types,
101			Set freeVars) throws InterpreterException {
102		return new NATFieldSelection(map,
103				state,
104				originalCustomFields,
105				methodDict,
106				dynamicParent,
107				lexicalParent,
108				flags,
109				types,
110				freeVars);
111	}
112	
113}