/interpreter/tags/at2dist110511/src/edu/vub/at/objects/grammar/ATDefExternalMethod.java
Java | 99 lines | 10 code | 7 blank | 82 comment | 0 complexity | 1df9188f908ad62452a425c02ac50cf2 MD5 | raw file
1/** 2 * AmbientTalk/2 Project 3 * ATDefExternalMethod.java created on 15-nov-2006 at 19:23:51 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.grammar; 29 30import edu.vub.at.objects.ATTable; 31import edu.vub.at.objects.natives.NATClosureMethod; 32 33/** 34 * The public interface to an external method definition AG element. 35 * 36 * <p> 37 * Example: <code>def o.m() { body }</code> 38 * </p><p> 39 * There are three ways to evaluate such expressions with respect to what context should be 40 * active when the method is invoked upon the object: 41 * <ol> 42 * <li> The newly defined method is wrapped in a closure thereby fixing the lexical scope that was 43 * active at method definition/addition time, as well as the values of 'self' and 'super'. 44 * This has the advantage that within the externally added method body: 45 * a) the adding object can still access its lexical scope. 46 * b) the adding object can *not* access the scope of the object it is adding a method to. 47 * This has the disadvantage that within the externally added method body, 48 * 'self' and 'super' keep on referring to the lexically active self and super. This has the 49 * disadvantage that the newly added method cannot perform 'super sends', nor is the value of 50 * 'self' correct when the method is invoked through a child of o.</li> 51 * <li> The newly defined method is added as-is to the object. This has roughly the reverse 52 * effects of option 1: the adding object loses its lexical scope (error-prone and dangerous!) 53 * but the values for self and super are correct. It is as if the method was really defined 54 * in the scope of the original object.</li> 55 * <li> The newly defined method is wrapped in a special 'objectless' closure that captures the 56 * lexical scope of the adding object but *not* the values of 'self' and 'super'. When the 57 * added method is subsequently invoked, its lexical scope will still be that of the adding 58 * object (hence, having the benefits of option 1) while the values of 'self' and 'super' 59 * will be correct with respect to the method invocation on o (or a child of o) (hence, 60 * having the benefits of option 2.</li> 61 * </ol> 62 * </p><p> 63 * AmbientTalk implements the third option, by means of a {@link NATClosureMethod}. 64 * </p> 65 * 66 * @author tvc 67 */ 68public interface ATDefExternalMethod extends ATDefinition { 69 70 /** 71 * Example: <code>`{ def o.m() { 5 } }.statements[1].receiver == `o</code> 72 * @return the receiver on which the method will be defined 73 */ 74 public ATSymbol base_receiver(); 75 76 /** 77 * Example: <code>`{ def o.m() { 5 } }.statements[1].selector == `m</code> 78 * @return the selector of the new method 79 */ 80 public ATSymbol base_selector(); 81 82 /** 83 * Example: <code>`{ def o.m(a, @b) { b } }.statements[1].arguments == `[a, @b]</code> 84 * @return the argument list of the new method 85 */ 86 public ATTable base_arguments(); 87 88 /** 89 * Example: <code>`{ def o.m() { o.n(); 1+2+3 } }.statements[1].bodyExpression == `{o.n(); 1.+(2).+(3)}</code> 90 * @return the body of the new method 91 */ 92 public ATBegin base_bodyExpression(); 93 94 /** 95 * Example: <code>`{ def o.m() @[Getter] { 5 } }.statements[1].annotations == `[Getter]</code> 96 * @return the annotations of the new method 97 */ 98 public ATExpression base_annotationExpression(); 99}