0

I have an instance of the object VMemRead (let's call it r). The constructor for VMemRead looks like

VMemRead(SourcePos sourcePos, VVarRef dest, VMemRef source)

with fields dest and source. I know when I want to access dest, I can just do r.dest. However, I want to go "deeper" into source.

VMRef has two nested classes VMemRef.Global and VMemRef.Stack. VMemRef.Global has the constructor

VMemRef.Global(SourcePos sourcePos, VAddr<VDataSegment> base, int byteOffset)  

I want to access the int byteOffset. In effect, I want to do something like r.source.Global.byteOffset but Java doesn't let me do this.

Is there any way I can access that value?

Documentation: VMemRead: http://cs.ucla.edu/classes/spring11/cs132/kannan/vapor-parser/vapor-parser-javadoc/cs132/vapor/ast/VMemRead.html#source

VMemRef: http://cs.ucla.edu/classes/spring11/cs132/kannan/vapor-parser/vapor-parser-javadoc/cs132/vapor/ast/VMemRef.html

VMemRef.Global: http://cs.ucla.edu/classes/spring11/cs132/kannan/vapor-parser/vapor-parser-javadoc/cs132/vapor/ast/VMemRef.Global.html

Thank you very much!

7
  • 4
    format your question, and format it good, don't just slap random code blocks around words Commented Dec 4, 2012 at 5:16
  • How so? I thought I marked the code as code appropriately. Commented Dec 4, 2012 at 5:17
  • Also I am confused by what you mean nested? Inner class or you literally extend it by saying extends VMemRef...? Because saying r.source.Global.byteOffset is definitely wrong no matter which way it is. Just don't know which you exactly you have it. Commented Dec 4, 2012 at 5:18
  • @pauliwago Make it look less like an ugly pile of text. Use less run-on sentences. Just read it to yourself. You'll find that it's very hard to follow Commented Dec 4, 2012 at 5:20
  • Literally extend VMemRef....but it's in the same class file/surrounded by brackets of VMemRef..if that makes sense. Please let me know if you need more clarification. Commented Dec 4, 2012 at 5:21

1 Answer 1

1

Those nested classes are static. For each of them, you need a reference to an instance in order to access the field values. An instance of VMemRef does not have (documented) member fields of type VMemRef.Global or VMemRef.Stack. You'll have to look somewhere else than in r for data from those classes.

In other words, simply because you have an instance of VMemRef in r, it doesn't mean that there are any instances of VMemRef.Global or VMemRef.Stack around. So there's no way to access "those values" because "those values" don't necessarily exist!

EDIT After re-reading the API, I see that VMemRef is an abstract class and r.source is an instance of either VMemRef.Global or VMemRef.Static. That changes the story. You can do something like this:

if (r.source instanceof VMemRef.Global) {
    VMemRef.Global source = (VMemRef.Global) r.source;
    // access fields specific to VMemRef.Global
} else if (r.source instanceof VMemRef.Stack) {
    VMemRef.Stack source = (VMemRef.Stack) r.source;
    // access fields specific to VMemRef.Stack
}
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks for your help! That actually makes a lot of sense, but what is being printed out then when I print out r.source.toString() then?
@pauliwago - Ah. It looks like you never have an instance of VMemRef; it's always an instance of VMemRef.Global or VMemRef.Stack. I updated my answer to show how to deal with that.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.