From 96bf68c49a86dac8a05ee7a24798b11b2d30bd14 Mon Sep 17 00:00:00 2001 From: Vincent Rasquier Date: Thu, 14 Dec 2017 17:19:26 +0100 Subject: [PATCH] Add Edge type + Fix slice of pointer Attribute --- asm/classreader.go | 6 +++--- asm/context.go | 2 +- asm/edge.go | 17 +++++++++++++++++ asm/label.go | 2 +- 4 files changed, 22 insertions(+), 5 deletions(-) create mode 100644 asm/edge.go diff --git a/asm/classreader.go b/asm/classreader.go index fabf73c..f128d5a 100644 --- a/asm/classreader.go +++ b/asm/classreader.go @@ -158,11 +158,11 @@ func (c ClassReader) GetInterfaces() []string { // Accept Makes the given visitor visit the JVMS ClassFile structure passed to the constructor of this {@link ClassReader}. func (c ClassReader) Accept(classVisitor ClassVisitor, parsingOptions int) { - c.AcceptB(classVisitor, make([]Attribute, 0), parsingOptions) + c.AcceptB(classVisitor, make([]*Attribute, 0), parsingOptions) } // AcceptB Makes the given visitor visit the JVMS ClassFile structure passed to the constructor of this {@link ClassReader}. -func (c ClassReader) AcceptB(classVisitor ClassVisitor, attributePrototypes []Attribute, parsingOptions int) { +func (c ClassReader) AcceptB(classVisitor ClassVisitor, attributePrototypes []*Attribute, parsingOptions int) { context := &Context{ attributePrototypes: attributePrototypes, parsingOptions: parsingOptions, @@ -1480,7 +1480,7 @@ func (c ClassReader) getFirstAttributeOffset() int { return currentOffset + 2 } -func (c ClassReader) readAttribute(attributePrototypes []Attribute, typed string, offset int, length int, charBuffer []rune, codeAttributeOffset int, labels []*Label) *Attribute { +func (c ClassReader) readAttribute(attributePrototypes []*Attribute, typed string, offset int, length int, charBuffer []rune, codeAttributeOffset int, labels []*Label) *Attribute { for i := 0; i < len(attributePrototypes); i++ { if attributePrototypes[i].typed == typed { return attributePrototypes[i].read(&c, offset, length, charBuffer, codeAttributeOffset, labels) diff --git a/asm/context.go b/asm/context.go index c7f9686..a432b97 100644 --- a/asm/context.go +++ b/asm/context.go @@ -2,7 +2,7 @@ package asm // Context information about a class being parsed in a {@link ClassReader}. type Context struct { - attributePrototypes []Attribute + attributePrototypes []*Attribute parsingOptions int charBuffer []rune bootstrapMethodOffsets []int diff --git a/asm/edge.go b/asm/edge.go new file mode 100644 index 0000000..3414e20 --- /dev/null +++ b/asm/edge.go @@ -0,0 +1,17 @@ +package asm + +const ( + JUMP = 0 + EXCEPTION = 0x7FFFFFFF +) + +// Edge An edge in the control flow graph of a method. Each node of this graph is a basic block, +// represented with the Label corresponding to its first instruction. Each edge goes from one node +// to another, i.e. from one basic block to another (called the predecessor and successor blocks, +// respectively). An edge corresponds either to a jump or ret instruction or to an exception +// handler. +type Edge struct { + info int + successor *Label + nextEdge *Edge +} diff --git a/asm/label.go b/asm/label.go index fc89905..0cc5a43 100644 --- a/asm/label.go +++ b/asm/label.go @@ -32,7 +32,7 @@ type Label struct { outputStackMax int16 frame *Frame nextBasicBlock *Label - outgoingEdges interface{} //Edge + outgoingEdges *Edge nextListElement *Label }