001: /*=============================================================================
002: * Copyright Texas Instruments 2003-2004. All Rights Reserved.
003: *
004: * This program is free software; you can redistribute it and/or
005: * modify it under the terms of the GNU Lesser General Public
006: * License as published by the Free Software Foundation; either
007: * version 2 of the License, or (at your option) any later version.
008: *
009: * This program is distributed in the hope that it will be useful,
010: * but WITHOUT ANY WARRANTY; without even the implied warranty of
011: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
012: * Lesser General Public License for more details.
013: *
014: * You should have received a copy of the GNU Lesser General Public
015: * License along with this library; if not, write to the Free Software
016: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
017: *
018: * $ProjectHeader: OSCRIPT 0.155 Fri, 20 Dec 2002 18:34:22 -0800 rclark $
019: */
020:
021: package oscript.data;
022:
023: import oscript.exceptions.*;
024: import oscript.util.StackFrame;
025: import oscript.util.MemberTable;
026:
027: /**
028: * An abstract reference, which forwards requests to the referent, returned
029: * by {@link #get}.
030: *
031: * @author Rob Clark (rob@ti.com)
032: */
033: public abstract class AbstractReference extends Value {
034: /*=======================================================================*/
035: /**
036: * Class Constructor.
037: */
038: public AbstractReference() {
039: super ();
040: }
041:
042: /*=======================================================================*/
043: /**
044: * Get the type of this object. The returned type doesn't have to take
045: * into account the possibility of a script type extending a built-in
046: * type, since that is handled by {@link #getType}.
047: *
048: * @return the object's type
049: */
050: protected Value getTypeImpl() {
051: return Type.HIDDEN_TYPE;
052: }
053:
054: /*=======================================================================*/
055: /**
056: * Return a hash code value for this object.
057: *
058: * @return a hash code value
059: * @see java.lang.Object#hashCode()
060: */
061: public int hashCode() {
062: return get().hashCode();
063: }
064:
065: /*=======================================================================*/
066: /**
067: * Compare two objects for equality.
068: *
069: * @param obj the object to compare to this object
070: * @return <code>true</code> if equals, else <code>false</code>
071: * @see java.lang.Object#equals(java.lang.Object)
072: */
073: public boolean equals(Object obj) {
074: return get().equals(obj);
075: }
076:
077: /*=======================================================================*/
078: /**
079: * For references to an object (ie variables), this returns the actual
080: * value this is a reference to, otherwise this return <code>this</code>.
081: *
082: * @return the actual object
083: */
084: public Value unhand() {
085: return get().unhand();
086: }
087:
088: /*=======================================================================*/
089: /**
090: * Return the object used for implementing <i>synchronized</i>. For a
091: * normal script object, the object is it's own monitor. For a java
092: * object, it is the java object rather than the {@link JavaObjectWrapper}.
093: *
094: * @return the object to synchronize on
095: */
096: public Object getMonitor() {
097: return get().getMonitor();
098: }
099:
100: /*=======================================================================*/
101: /**
102: * If this object is a type, determine if an instance of this type is
103: * an instance of the specified type, ie. if this is <code>type</code>,
104: * or a subclass.
105: *
106: * @param type the type to compare this type to
107: * @return <code>true</code> or <code>false</code>
108: * @throws PackagedScriptObjectException(NoSuchMemberException)
109: */
110: public boolean isA(Value type) {
111: return get().isA(type);
112: }
113:
114: /*=======================================================================*/
115: /**
116: * Get the type of this object. A reference doesn't actually have a type,
117: * but instead is the type of whatever it contains... really I am not sure
118: * if a reference is a first class type, or perhaps could be implemented
119: * as an inner-class for OArray and ScriptObject. Perhaps Value should be
120: * an interface, and what is now Value becomes some sort of adapter
121: * class?
122: *
123: * @return the object's type
124: */
125: public Value getType() {
126: return get().getType();
127: }
128:
129: /*=======================================================================*/
130: /* Casting methods:
131: */
132:
133: /*=======================================================================*/
134: /**
135: * Convert this object to a native java <code>boolean</code> value.
136: *
137: * @return a boolean value
138: * @throws PackagedScriptObjectException(NoSuchMemberException)
139: */
140: public boolean castToBoolean() throws PackagedScriptObjectException {
141: return get().castToBoolean();
142: }
143:
144: /*=======================================================================*/
145: /**
146: * Convert this object to a native java <code>String</code> value.
147: *
148: * @return a String value
149: * @throws PackagedScriptObjectException(NoSuchMemberException)
150: */
151: public String castToString() throws PackagedScriptObjectException {
152: return get().castToString();
153: }
154:
155: /*=======================================================================*/
156: /**
157: * Convert this object to a native java <code>long</code> value.
158: *
159: * @return a long value
160: * @throws PackagedScriptObjectException(NoSuchMemberException)
161: */
162: public long castToExactNumber()
163: throws PackagedScriptObjectException {
164: return get().castToExactNumber();
165: }
166:
167: /*=======================================================================*/
168: /**
169: * Convert this object to a native java <code>double</code> value.
170: *
171: * @return a double value
172: * @throws PackagedScriptObjectException(NoSuchMemberException)
173: */
174: public double castToInexactNumber()
175: throws PackagedScriptObjectException {
176: return get().castToInexactNumber();
177: }
178:
179: /*=======================================================================*/
180: /**
181: * Convert this object to a native java <code>Object</code> value.
182: *
183: * @return a java object
184: * @throws PackagedScriptObjectException(NoSuchMemberException)
185: */
186: public Object castToJavaObject()
187: throws PackagedScriptObjectException {
188: return get().castToJavaObject();
189: }
190:
191: /*=======================================================================*/
192: /* The binary operators:
193: */
194:
195: /*=======================================================================*/
196: /**
197: * Perform the cast operation, <code>(a)b</code> is equivalent to <code>a.bopCast(b)</code>
198: *
199: * @param val the other value
200: * @return the result
201: * @throws PackagedScriptObjectException(NoSuchMemberException)
202: */
203: public Value bopCast(Value val)
204: throws PackagedScriptObjectException {
205: return get().bopCast(val);
206: }
207:
208: public Value bopCastR(Value val, PackagedScriptObjectException e)
209: throws PackagedScriptObjectException {
210: return get().bopCastR(val, e);
211: }
212:
213: /*=======================================================================*/
214: /**
215: * Perform the instanceof operation.
216: *
217: * @param val the other value
218: * @return the result
219: * @throws PackagedScriptObjectException(NoSuchMemberException)
220: */
221: public Value bopInstanceOf(Value val)
222: throws PackagedScriptObjectException {
223: return get().bopInstanceOf(val);
224: }
225:
226: public Value bopInstanceOfR(Value val,
227: PackagedScriptObjectException e)
228: throws PackagedScriptObjectException {
229: return get().bopInstanceOfR(val, e);
230: }
231:
232: /*=======================================================================*/
233: /**
234: * Perform the logical OR operation.
235: *
236: * @param val the other value
237: * @return the result
238: * @throws PackagedScriptObjectException(NoSuchMemberException)
239: */
240: public Value bopLogicalOr(Value val)
241: throws PackagedScriptObjectException {
242: return get().bopLogicalOr(val);
243: }
244:
245: public Value bopLogicalOrR(Value val,
246: PackagedScriptObjectException e)
247: throws PackagedScriptObjectException {
248: return get().bopLogicalOrR(val, e);
249: }
250:
251: /*=======================================================================*/
252: /**
253: * Perform the logical AND operation.
254: *
255: * @param val the other value
256: * @return the result
257: * @throws PackagedScriptObjectException(NoSuchMemberException)
258: */
259: public Value bopLogicalAnd(Value val)
260: throws PackagedScriptObjectException {
261: return get().bopLogicalAnd(val);
262: }
263:
264: public Value bopLogicalAndR(Value val,
265: PackagedScriptObjectException e)
266: throws PackagedScriptObjectException {
267: return get().bopLogicalAndR(val, e);
268: }
269:
270: /*=======================================================================*/
271: /**
272: * Perform the bitwise OR operation.
273: *
274: * @param val the other value
275: * @return the result
276: * @throws PackagedScriptObjectException(NoSuchMemberException)
277: */
278: public Value bopBitwiseOr(Value val)
279: throws PackagedScriptObjectException {
280: return get().bopBitwiseOr(val);
281: }
282:
283: public Value bopBitwiseOrR(Value val,
284: PackagedScriptObjectException e)
285: throws PackagedScriptObjectException {
286: return get().bopBitwiseOrR(val, e);
287: }
288:
289: /*=======================================================================*/
290: /**
291: * Perform the bitwise XOR operation.
292: *
293: * @param val the other value
294: * @return the result
295: * @throws PackagedScriptObjectException(NoSuchMemberException)
296: */
297: public Value bopBitwiseXor(Value val)
298: throws PackagedScriptObjectException {
299: return get().bopBitwiseXor(val);
300: }
301:
302: public Value bopBitwiseXorR(Value val,
303: PackagedScriptObjectException e)
304: throws PackagedScriptObjectException {
305: return get().bopBitwiseXorR(val, e);
306: }
307:
308: /*=======================================================================*/
309: /**
310: * Perform the bitwise AND operation.
311: *
312: * @param val the other value
313: * @return the result
314: * @throws PackagedScriptObjectException(NoSuchMemberException)
315: */
316: public Value bopBitwiseAnd(Value val)
317: throws PackagedScriptObjectException {
318: return get().bopBitwiseAnd(val);
319: }
320:
321: public Value bopBitwiseAndR(Value val,
322: PackagedScriptObjectException e)
323: throws PackagedScriptObjectException {
324: return get().bopBitwiseAndR(val, e);
325: }
326:
327: /*=======================================================================*/
328: /**
329: * Perform the "==" operation.
330: *
331: * @param val the other value
332: * @return the result
333: * @throws PackagedScriptObjectException(NoSuchMemberException)
334: */
335: public Value bopEquals(Value val)
336: throws PackagedScriptObjectException {
337: return get().bopEquals(val);
338: }
339:
340: public Value bopEqualsR(Value val, PackagedScriptObjectException e)
341: throws PackagedScriptObjectException {
342: return get().bopEqualsR(val, e);
343: }
344:
345: /*=======================================================================*/
346: /**
347: * Perform the "!=" operation.
348: *
349: * @param val the other value
350: * @return the result
351: * @throws PackagedScriptObjectException(NoSuchMemberException)
352: */
353: public Value bopNotEquals(Value val)
354: throws PackagedScriptObjectException {
355: return get().bopNotEquals(val);
356: }
357:
358: public Value bopNotEqualsR(Value val,
359: PackagedScriptObjectException e)
360: throws PackagedScriptObjectException {
361: return get().bopNotEqualsR(val, e);
362: }
363:
364: /*=======================================================================*/
365: /**
366: * Perform the "<" operation.
367: *
368: * @param val the other value
369: * @return the result
370: * @throws PackagedScriptObjectException(NoSuchMemberException)
371: */
372: public Value bopLessThan(Value val)
373: throws PackagedScriptObjectException {
374: return get().bopLessThan(val);
375: }
376:
377: public Value bopLessThanR(Value val, PackagedScriptObjectException e)
378: throws PackagedScriptObjectException {
379: return get().bopLessThanR(val, e);
380: }
381:
382: /*=======================================================================*/
383: /**
384: * Perform the ">" operation.
385: *
386: * @param val the other value
387: * @return the result
388: * @throws PackagedScriptObjectException(NoSuchMemberException)
389: */
390: public Value bopGreaterThan(Value val)
391: throws PackagedScriptObjectException {
392: return get().bopGreaterThan(val);
393: }
394:
395: public Value bopGreaterThanR(Value val,
396: PackagedScriptObjectException e)
397: throws PackagedScriptObjectException {
398: return get().bopGreaterThanR(val, e);
399: }
400:
401: /*=======================================================================*/
402: /**
403: * Perform the "<=" operation.
404: *
405: * @param val the other value
406: * @return the result
407: * @throws PackagedScriptObjectException(NoSuchMemberException)
408: */
409: public Value bopLessThanOrEquals(Value val)
410: throws PackagedScriptObjectException {
411: return get().bopLessThanOrEquals(val);
412: }
413:
414: public Value bopLessThanOrEqualsR(Value val,
415: PackagedScriptObjectException e)
416: throws PackagedScriptObjectException {
417: return get().bopLessThanOrEqualsR(val, e);
418: }
419:
420: /*=======================================================================*/
421: /**
422: * Perform the ">=" operation.
423: *
424: * @param val the other value
425: * @return the result
426: * @throws PackagedScriptObjectException(NoSuchMemberException)
427: */
428: public Value bopGreaterThanOrEquals(Value val)
429: throws PackagedScriptObjectException {
430: return get().bopGreaterThanOrEquals(val);
431: }
432:
433: public Value bopGreaterThanOrEqualsR(Value val,
434: PackagedScriptObjectException e)
435: throws PackagedScriptObjectException {
436: return get().bopGreaterThanOrEqualsR(val, e);
437: }
438:
439: /*=======================================================================*/
440: /**
441: * Perform the "<<" operation.
442: *
443: * @param val the other value
444: * @return the result
445: * @throws PackagedScriptObjectException(NoSuchMemberException)
446: */
447: public Value bopLeftShift(Value val)
448: throws PackagedScriptObjectException {
449: return get().bopLeftShift(val);
450: }
451:
452: public Value bopLeftShiftR(Value val,
453: PackagedScriptObjectException e)
454: throws PackagedScriptObjectException {
455: return get().bopLeftShiftR(val, e);
456: }
457:
458: /*=======================================================================*/
459: /**
460: * Perform the ">>" operation.
461: *
462: * @param val the other value
463: * @return the result
464: * @throws PackagedScriptObjectException(NoSuchMemberException)
465: */
466: public Value bopSignedRightShift(Value val)
467: throws PackagedScriptObjectException {
468: return get().bopSignedRightShift(val);
469: }
470:
471: public Value bopSignedRightShiftR(Value val,
472: PackagedScriptObjectException e)
473: throws PackagedScriptObjectException {
474: return get().bopSignedRightShiftR(val, e);
475: }
476:
477: /*=======================================================================*/
478: /**
479: * Perform the ">>>" operation.
480: *
481: * @param val the other value
482: * @return the result
483: * @throws PackagedScriptObjectException(NoSuchMemberException)
484: */
485: public Value bopUnsignedRightShift(Value val)
486: throws PackagedScriptObjectException {
487: return get().bopUnsignedRightShift(val);
488: }
489:
490: public Value bopUnsignedRightShiftR(Value val,
491: PackagedScriptObjectException e)
492: throws PackagedScriptObjectException {
493: return get().bopUnsignedRightShiftR(val, e);
494: }
495:
496: /*=======================================================================*/
497: /**
498: * Perform the "+" operation.
499: *
500: * @param val the other value
501: * @return the result
502: * @throws PackagedScriptObjectException(NoSuchMemberException)
503: */
504: public Value bopPlus(Value val)
505: throws PackagedScriptObjectException {
506: return get().bopPlus(val);
507: }
508:
509: public Value bopPlusR(Value val, PackagedScriptObjectException e)
510: throws PackagedScriptObjectException {
511: return get().bopPlusR(val, e);
512: }
513:
514: /*=======================================================================*/
515: /**
516: * Perform the "-" operation.
517: *
518: * @param val the other value
519: * @return the result
520: * @throws PackagedScriptObjectException(NoSuchMemberException)
521: */
522: public Value bopMinus(Value val)
523: throws PackagedScriptObjectException {
524: return get().bopMinus(val);
525: }
526:
527: public Value bopMinusR(Value val, PackagedScriptObjectException e)
528: throws PackagedScriptObjectException {
529: return get().bopMinusR(val, e);
530: }
531:
532: /*=======================================================================*/
533: /**
534: * Perform the "*" operation.
535: *
536: * @param val the other value
537: * @return the result
538: * @throws PackagedScriptObjectException(NoSuchMemberException)
539: */
540: public Value bopMultiply(Value val)
541: throws PackagedScriptObjectException {
542: return get().bopMultiply(val);
543: }
544:
545: public Value bopMultiplyR(Value val, PackagedScriptObjectException e)
546: throws PackagedScriptObjectException {
547: return get().bopMultiplyR(val, e);
548: }
549:
550: /*=======================================================================*/
551: /**
552: * Perform the "/" operation.
553: *
554: * @param val the other value
555: * @return the result
556: * @throws PackagedScriptObjectException(NoSuchMemberException)
557: */
558: public Value bopDivide(Value val)
559: throws PackagedScriptObjectException {
560: return get().bopDivide(val);
561: }
562:
563: public Value bopDivideR(Value val, PackagedScriptObjectException e)
564: throws PackagedScriptObjectException {
565: return get().bopDivideR(val, e);
566: }
567:
568: /*=======================================================================*/
569: /**
570: * Perform the "%" operation.
571: *
572: * @param val the other value
573: * @return the result
574: * @throws PackagedScriptObjectException(NoSuchMemberException)
575: */
576: public Value bopRemainder(Value val)
577: throws PackagedScriptObjectException {
578: return get().bopRemainder(val);
579: }
580:
581: public Value bopRemainderR(Value val,
582: PackagedScriptObjectException e)
583: throws PackagedScriptObjectException {
584: return get().bopRemainderR(val, e);
585: }
586:
587: /*=======================================================================*/
588: /* The unary operators:
589: */
590:
591: /*=======================================================================*/
592: /**
593: * Perform the "++" operation.
594: *
595: * @param val the other value
596: * @return the result
597: * @throws PackagedScriptObjectException(NoSuchMemberException)
598: */
599: public Value uopIncrement() throws PackagedScriptObjectException {
600: return get().uopIncrement();
601: }
602:
603: /*=======================================================================*/
604: /**
605: * Perform the "--" operation.
606: *
607: * @param val the other value
608: * @return the result
609: * @throws PackagedScriptObjectException(NoSuchMemberException)
610: */
611: public Value uopDecrement() throws PackagedScriptObjectException {
612: return get().uopDecrement();
613: }
614:
615: /*=======================================================================*/
616: /**
617: * Perform the "+" operation.
618: *
619: * @param val the other value
620: * @return the result
621: * @throws PackagedScriptObjectException(NoSuchMemberException)
622: */
623: public Value uopPlus() throws PackagedScriptObjectException {
624: return get().uopPlus();
625: }
626:
627: /*=======================================================================*/
628: /**
629: * Perform the "-" operation.
630: *
631: * @param val the other value
632: * @return the result
633: * @throws PackagedScriptObjectException(NoSuchMemberException)
634: */
635: public Value uopMinus() throws PackagedScriptObjectException {
636: return get().uopMinus();
637: }
638:
639: /*=======================================================================*/
640: /**
641: * Perform the "~" operation.
642: *
643: * @param val the other value
644: * @return the result
645: * @throws PackagedScriptObjectException(NoSuchMemberException)
646: */
647: public Value uopBitwiseNot() throws PackagedScriptObjectException {
648: return get().uopBitwiseNot();
649: }
650:
651: /*=======================================================================*/
652: /**
653: * Perform the "!" operation.
654: *
655: * @param val the other value
656: * @return the result
657: * @throws PackagedScriptObjectException(NoSuchMemberException)
658: */
659: public Value uopLogicalNot() throws PackagedScriptObjectException {
660: return get().uopLogicalNot();
661: }
662:
663: /*=======================================================================*/
664: /* The misc operators:
665: */
666:
667: /*=======================================================================*/
668: /**
669: * Call this object as a function.
670: *
671: * @param sf the current stack frame
672: * @param args the arguments to the function
673: * @return the value returned by the function
674: * @throws PackagedScriptObjectException
675: * @see Function
676: */
677: public Value callAsFunction(StackFrame sf, MemberTable args)
678: throws PackagedScriptObjectException {
679: return get().callAsFunction(sf, args);
680: }
681:
682: /*=======================================================================*/
683: /**
684: * Call this object as a constructor.
685: *
686: * @param sf the current stack frame
687: * @param args the arguments to the function
688: * @return the newly constructed object
689: * @throws PackagedScriptObjectException
690: * @see Function
691: */
692: public Value callAsConstructor(StackFrame sf, MemberTable args)
693: throws PackagedScriptObjectException {
694: return get().callAsConstructor(sf, args);
695: }
696:
697: /*=======================================================================*/
698: /**
699: * Call this object as a parent class constructor.
700: *
701: * @param sf the current stack frame
702: * @param scope the object
703: * @param args the arguments to the function
704: * @return the value returned by the function
705: * @throws PackagedScriptObjectException
706: * @see Function
707: */
708: public Value callAsExtends(StackFrame sf, Scope scope,
709: MemberTable args) throws PackagedScriptObjectException {
710: return get().callAsExtends(sf, scope, args);
711: }
712:
713: /*=======================================================================*/
714: /**
715: * Get a member of this object.
716: *
717: * @param id the id of the symbol that maps to the member
718: * @param exception whether an exception should be thrown if the
719: * member object is not resolved
720: * @return a reference to the member
721: * @throws PackagedScriptObjectException(NoSuchMethodException)
722: * @throws PackagedScriptObjectException(NoSuchMemberException)
723: */
724: public Value getMember(int id, boolean exception)
725: throws PackagedScriptObjectException {
726: return get().getMember(id, exception);
727: }
728:
729: /*=======================================================================*/
730: /**
731: * Get a member of this type. This is used to interface to the java
732: * method of having members be attributes of a type. Regular object-
733: * script object's members are attributes of the object, but in the
734: * case of java types (including built-in types), the members are
735: * attributes of the type.
736: *
737: * @param obj an object of this type
738: * @param id the id of the symbol that maps to the member
739: * @return a reference to the member, or null
740: */
741: protected Value getTypeMember(Value obj, int id) {
742: return get().getTypeMember(obj, id);
743: }
744:
745: /*=======================================================================*/
746: /**
747: * For types that implement <code>elementAt</code>, this returns the
748: * number of elements.
749: *
750: * @return an integer length
751: * @throws PackagedScriptObjectException(NoSuchMemberException)
752: * @see #elementAt
753: * @see #elementsAt
754: */
755: public int length() throws PackagedScriptObjectException {
756: return get().length();
757: }
758:
759: /*=======================================================================*/
760: /**
761: * Get the specified index of this object, if this object is an array. If
762: * needed, the array is grown to the appropriate size.
763: *
764: * @param idx the index to get
765: * @return a reference to the member
766: * @throws PackagedScriptObjectException(NoSuchMemberException)
767: * @see #length
768: * @see #elementsAt
769: */
770: public Value elementAt(Value idx)
771: throws PackagedScriptObjectException {
772: return get().elementAt(idx);
773: }
774:
775: /*=======================================================================*/
776: /**
777: * Get the specified range of this object, if this object is an array.
778: * This returns a copy of a range of the array.
779: *
780: * @param idx1 the index index of the beginning of the range, inclusive
781: * @param idx2 the index of the end of the range, inclusive
782: * @return a copy of the specified range of this array
783: * @throws PackagedScriptObjectException(NoSuchMemberException)
784: * @see #length
785: * @see #elementAt
786: */
787: public Value elementsAt(Value idx1, Value idx2)
788: throws PackagedScriptObjectException {
789: return get().elementsAt(idx1, idx2);
790: }
791:
792: /*=======================================================================*/
793: /**
794: * Returns the names of the members of this object.
795: *
796: * @return a collection view of the names of the members of this object
797: */
798: public final java.util.Set memberSet() {
799: return get().memberSet();
800: }
801:
802: /*=======================================================================*/
803: /**
804: * Get the referent
805: *
806: * @return the value this reference refers to
807: */
808: protected abstract Value get();
809: }
810:
811: /*
812: * Local Variables:
813: * tab-width: 2
814: * indent-tabs-mode: nil
815: * mode: java
816: * c-indentation-style: java
817: * c-basic-offset: 2
818: * eval: (c-set-offset 'substatement-open '0)
819: * eval: (c-set-offset 'case-label '+)
820: * eval: (c-set-offset 'inclass '+)
821: * eval: (c-set-offset 'inline-open '0)
822: * End:
823: */
|