Skip to content

Commit

Permalink
reverted obj field ignore changes (#29)
Browse files Browse the repository at this point in the history
  • Loading branch information
pandurangpatil authored Aug 25, 2023
1 parent d53c1a4 commit 43a5df6
Showing 1 changed file with 37 additions and 43 deletions.
80 changes: 37 additions & 43 deletions goastgen/libgoastgen.go
Original file line number Diff line number Diff line change
Expand Up @@ -343,52 +343,46 @@ func processStruct(node interface{}, objPtrValue reflect.Value, fset *token.File
// We will iterate through each field process each field according to its reflect.Kind type.
for i := 0; i < elementType.NumField(); i++ {
field := elementType.Field(i)
if field.Name != "Obj" {
// It looks like "Obj" field refers to the original method node from inside call expression node.
// In the event call expression node gets encountered earlier than the FuncDecl node.
// We process this object inside Call Expression and refer to this node inside FuncDecl node.
// However, while processing the AST, we need to process the Function Declaration with FuncDecl Node.
// As we don't use the "Obj" for any reference
value := elementValueObj.Field(i)
fieldKind := value.Type().Kind()

// If object is defined with field type as interface{} and assigned with pointer value.
// We need to first fetch the element from the interface
if fieldKind == reflect.Interface {
fieldKind = value.Elem().Kind()
value = value.Elem()
}

var ptrValue reflect.Value
value := elementValueObj.Field(i)
fieldKind := value.Type().Kind()

if fieldKind == reflect.Pointer {
// NOTE: This handles only one level of pointer. At this moment we don't expect to get pointer to pointer.
// This will fetch the reflect.Kind of object pointed to by this field pointer
fieldKind = value.Type().Elem().Kind()
// This will fetch the reflect.Value of object pointed to by this field pointer.
ptrValue = value
// capturing the reflect.Value of the pointer if it's a pointer to be passed to recursive processStruct method.
value = value.Elem()
}
// In case the node is pointer, it will check if given Value contains valid pointer address.
if value.IsValid() {
switch fieldKind {
case reflect.String, reflect.Int, reflect.Bool, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64, reflect.Float32, reflect.Float64, reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64:
if value.Type().String() == "token.Token" {
objectMap[field.Name] = value.Interface().(token.Token).String()
} else {
objectMap[field.Name] = value.Interface()
}
case reflect.Struct:
objectMap[field.Name] = processStruct(value.Interface(), ptrValue, fset, lastNodeId, nodeAddressMap)
case reflect.Map:
objectMap[field.Name] = processMap(value.Interface(), fset, lastNodeId, nodeAddressMap)
case reflect.Array, reflect.Slice:
objectMap[field.Name] = processArrayOrSlice(value.Interface(), fset, lastNodeId, nodeAddressMap)
default:
log.SetPrefix("[WARNING]")
log.Println(getLogPrefix(), field.Name, "- of Kind ->", fieldKind, "- not handled")
// If object is defined with field type as interface{} and assigned with pointer value.
// We need to first fetch the element from the interface
if fieldKind == reflect.Interface {
fieldKind = value.Elem().Kind()
value = value.Elem()
}

var ptrValue reflect.Value

if fieldKind == reflect.Pointer {
// NOTE: This handles only one level of pointer. At this moment we don't expect to get pointer to pointer.
// This will fetch the reflect.Kind of object pointed to by this field pointer
fieldKind = value.Type().Elem().Kind()
// This will fetch the reflect.Value of object pointed to by this field pointer.
ptrValue = value
// capturing the reflect.Value of the pointer if it's a pointer to be passed to recursive processStruct method.
value = value.Elem()
}
// In case the node is pointer, it will check if given Value contains valid pointer address.
if value.IsValid() {
switch fieldKind {
case reflect.String, reflect.Int, reflect.Bool, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64, reflect.Float32, reflect.Float64, reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64:
if value.Type().String() == "token.Token" {
objectMap[field.Name] = value.Interface().(token.Token).String()
} else {
objectMap[field.Name] = value.Interface()
}
case reflect.Struct:
objectMap[field.Name] = processStruct(value.Interface(), ptrValue, fset, lastNodeId, nodeAddressMap)
case reflect.Map:
objectMap[field.Name] = processMap(value.Interface(), fset, lastNodeId, nodeAddressMap)
case reflect.Array, reflect.Slice:
objectMap[field.Name] = processArrayOrSlice(value.Interface(), fset, lastNodeId, nodeAddressMap)
default:
log.SetPrefix("[WARNING]")
log.Println(getLogPrefix(), field.Name, "- of Kind ->", fieldKind, "- not handled")
}
}
}
Expand Down

0 comments on commit 43a5df6

Please sign in to comment.