Skip to content

Commit

Permalink
Add Type class
Browse files Browse the repository at this point in the history
  • Loading branch information
Vincent Rasquier committed Dec 14, 2017
1 parent 96bf68c commit fc95a96
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 2 deletions.
4 changes: 2 additions & 2 deletions asm/classreader.go
Original file line number Diff line number Diff line change
Expand Up @@ -1607,11 +1607,11 @@ func (c ClassReader) readConst(constantPoolEntryIndex int, charBuffer []rune) (i
case byte(symbol.CONSTANT_DOUBLE_TAG):
return float64(c.readLong(cpInfoOffset)), nil
case byte(symbol.CONSTANT_CLASS_TAG):
return 0, nil //Type.getObjectType(c.readUTF8(cpInfoOffset, charBuffer))
return getObjectType(c.readUTF8(cpInfoOffset, charBuffer)), nil
case byte(symbol.CONSTANT_STRING_TAG):
return c.readUTF8(cpInfoOffset, charBuffer), nil
case byte(symbol.CONSTANT_METHOD_TYPE_TAG):
return 0, nil //Type.getMethodType(c.readUTF8(cpInfoOffset, charBuffer))
return getMethodType(c.readUTF8(cpInfoOffset, charBuffer)), nil
case byte(symbol.CONSTANT_METHOD_HANDLE_TAG):
referenceKind := c.readByte(cpInfoOffset)
referenceCpInfoOffset := c.cpInfoOffsets[c.readUnsignedShort(cpInfoOffset+1)]
Expand Down
34 changes: 34 additions & 0 deletions asm/type.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package asm

import "github.com/leaklessgfy/asm/asm/typed"

type Type struct {
sort int
valueBuffer []rune
valueOffset int
valueLength int
}

func getObjectType(internalName string) *Type {
valueBuffer := []rune(internalName)
typ := typed.INTERNAL
if valueBuffer[0] == '[' {
typ = typed.ARRAY
}
return &Type{
sort: typ,
valueBuffer: valueBuffer,
valueOffset: 0,
valueLength: len(valueBuffer),
}
}

func getMethodType(methodDescriptor string) *Type {
valueBuffer := []rune(methodDescriptor)
return &Type{
typed.METHOD,
valueBuffer,
0,
len(valueBuffer),
}
}
20 changes: 20 additions & 0 deletions asm/typed/type.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package typed

const (
VOID = 0
BOOLEAN = 1
CHAR = 2
BYTE = 3
SHORT = 4
INT = 5
FLOAT = 6
LONG = 7
DOUBLE = 8
ARRAY = 9
OBJECT = 10
METHOD = 11
INTERNAL = 12
)

var PRIMITIVE_DESCRIPTORS = []rune{'V', 'Z', 'C', 'B', 'S', 'I', 'F', 'J', 'D'}

0 comments on commit fc95a96

Please sign in to comment.