Skip to content

Commit

Permalink
Extend jvm_field_is to support type-annotated field names.
Browse files Browse the repository at this point in the history
JVM allows classes to have multiple fields with the same name
but different types. (Although it is unlikely to come across
such fields in programs compiled from Java, which disallows this.)

This change allows saw-script users to disambiguate this case
by adding a type annotation to a field name using type descriptor
notation. For example, "x:J" specifies a field named "x" of type
`long`. (This is the same field syntax used in the disassembly
output from `javap -c`.)
  • Loading branch information
Brian Huffman committed Nov 18, 2020
1 parent c6e4974 commit b5a749d
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/SAWScript/Utils.hs
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,8 @@ findField cb site tp@(JSS.ClassType clName) nm = impl [] =<< lift (lookupClass c
where
names f =
do prefix <- ["", JSS.unClassName (JSS.className cl) ++ "."]
pure (prefix ++ JSS.fieldName f)
suffix <- ["", ":" ++ unparseTypeDescriptor (JSS.fieldType f)]
pure (prefix ++ JSS.fieldName f ++ suffix)

findField _ _ _ _ =
throwE "Primitive types cannot be dereferenced."
Expand Down

0 comments on commit b5a749d

Please sign in to comment.