JavaFieldRef2.st
changeset 749 e898eaeff091
child 2152 1cbdfbcc685c
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/JavaFieldRef2.st	Fri Aug 19 08:58:19 2011 +0000
@@ -0,0 +1,205 @@
+"
+ COPYRIGHT (c) 1996-2011 by Claus Gittinger
+ COPYRIGHT (c) 2010-2011 by Jan Vrany, Jan Kurs and Marcel Hlopko
+                            SWING Research Group, Czech Technical University in Prague
+
+ Parts of the code written by Claus Gittinger are under following
+ license:
+
+ This software is furnished under a license and may be used
+ only in accordance with the terms of that license and with the
+ inclusion of the above copyright notice.   This software may not
+ be provided or otherwise made available to, or used by, any
+ other person.  No title to or ownership of the software is
+ hereby transferred.
+
+ Parts of the code written at SWING Reasearch Group [1] are MIT licensed:
+
+ Permission is hereby granted, free of charge, to any person
+ obtaining a copy of this software and associated documentation
+ files (the 'Software'), to deal in the Software without
+ restriction, including without limitation the rights to use,
+ copy, modify, merge, publish, distribute, sublicense, and/or sell
+ copies of the Software, and to permit persons to whom the
+ Software is furnished to do so, subject to the following
+ conditions:
+
+ The above copyright notice and this permission notice shall be
+ included in all copies or substantial portions of the Software.
+
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+ OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+ HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ OTHER DEALINGS IN THE SOFTWARE.
+
+ [1] Code written at SWING Research Group contain a signature
+     of one of the above copright owners.
+"
+"{ Package: 'stx:libjava' }"
+
+JavaClassContentRef2 subclass:#JavaFieldRef2
+	instanceVariableNames:'offset type'
+	classVariableNames:'T_LONG T_DOUBLE'
+	poolDictionaries:''
+	category:'Languages-Java-Reader-Support-new'
+!
+
+!JavaFieldRef2 class methodsFor:'documentation'!
+
+copyright
+"
+ COPYRIGHT (c) 1996-2011 by Claus Gittinger
+ COPYRIGHT (c) 2010-2011 by Jan Vrany, Jan Kurs and Marcel Hlopko
+                            SWING Research Group, Czech Technical University in Prague
+
+ Parts of the code written by Claus Gittinger are under following
+ license:
+
+ This software is furnished under a license and may be used
+ only in accordance with the terms of that license and with the
+ inclusion of the above copyright notice.   This software may not
+ be provided or otherwise made available to, or used by, any
+ other person.  No title to or ownership of the software is
+ hereby transferred.
+
+ Parts of the code written at SWING Reasearch Group [1] are MIT licensed:
+
+ Permission is hereby granted, free of charge, to any person
+ obtaining a copy of this software and associated documentation
+ files (the 'Software'), to deal in the Software without
+ restriction, including without limitation the rights to use,
+ copy, modify, merge, publish, distribute, sublicense, and/or sell
+ copies of the Software, and to permit persons to whom the
+ Software is furnished to do so, subject to the following
+ conditions:
+
+ The above copyright notice and this permission notice shall be
+ included in all copies or substantial portions of the Software.
+
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+ OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+ HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ OTHER DEALINGS IN THE SOFTWARE.
+
+ [1] Code written at SWING Research Group contain a signature
+     of one of the above copright owners.
+
+"
+! !
+
+!JavaFieldRef2 class methodsFor:'initialization'!
+
+initialize
+    T_LONG := 1.
+    T_DOUBLE := 2.
+
+    "Created: / 15-05-2011 / 22:31:19 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
+! !
+
+!JavaFieldRef2 methodsFor:'accessing'!
+
+isJavaFieldRef
+^true.
+
+    "Created: / 11-04-2011 / 21:47:51 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
+!
+
+offset
+    ^ offset.
+
+    "Created: / 15-05-2011 / 22:26:08 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
+!
+
+type
+    type == T_LONG ifTrue: [ ^ #long. ].
+    type == T_DOUBLE ifTrue: [ ^ #double ].
+    ^ type.
+
+    "Created: / 15-05-2011 / 22:29:05 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
+! !
+
+!JavaFieldRef2 methodsFor:'private - resolving'!
+
+findResolvedStaticValue
+    valueCache := JavaResolver uniqueInstance 
+                resolveStaticFieldIndentifiedByRef: self.
+    "/Use javaClass of the field, not the class ref!!
+    classCache := valueCache javaClass. 
+    classCache ifNil: [ self breakPoint: #mh ].
+    self resolveStaticOffset.
+    nameAndTypeCache := (constantPool at: nameAndTypeIndex) resolve.
+    self resolveType.
+    nameAndTypeCache ifNil: [ self breakPoint: #mh ].
+
+    "Created: / 28-04-2011 / 22:05:10 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
+    "Modified: / 18-05-2011 / 12:44:13 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
+    "Modified: / 24-05-2011 / 14:05:13 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+findResolvedValue
+    valueCache := JavaResolver uniqueInstance 
+                resolveFieldIndentifiedByRef: self.
+    classCache := (constantPool at: classRefIndex) resolve.
+    classCache ifNil: [ self breakPoint: #mh ].
+    self resolveOffset.
+    nameAndTypeCache := (constantPool at: nameAndTypeIndex) resolve.
+    self resolveType.
+    nameAndTypeCache ifNil: [ self breakPoint: #mh ].
+
+    "Modified: / 18-05-2011 / 12:44:17 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
+!
+
+resolveOffset
+    "fieldRef must be resolved before calling me"
+    
+    | currentClass |
+
+    currentClass := classCache.
+    
+    [ offset := currentClass instVarOffsetOf: self name.
+    offset isNil and: [ currentClass superclass ~= JavaObject ]. ] whileTrue: [ currentClass := currentClass superclass. ].
+
+    "Modified: / 20-05-2011 / 20:36:17 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
+!
+
+resolveStaticOffset
+    "fieldRef must be resolved before calling me"
+    
+    | currentClass |
+
+    currentClass := classCache.
+    
+    [ offset := currentClass class instVarOffsetOf: self name.
+    offset isNil and: [ currentClass superclass ~= JavaObject ]. ] whileTrue: [ currentClass := currentClass superclass. ].
+
+    "Modified: / 20-05-2011 / 20:36:11 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
+!
+
+resolveType
+    type := JavaMethod typeFromSignature:((constantPool at: nameAndTypeIndex) descriptor) in:nil.
+    type == #long ifTrue:[
+        type := T_LONG.
+    ] ifFalse:[
+        type == #double ifTrue:[
+            type := T_DOUBLE
+        ]
+    ].
+
+    "Created: / 15-05-2011 / 22:29:02 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
+! !
+
+!JavaFieldRef2 class methodsFor:'documentation'!
+
+version_SVN
+    ^ '$Id$'
+! !
+
+JavaFieldRef2 initialize!
\ No newline at end of file