Imported Upstream version 4.8.1
[platform/upstream/gcc48.git] / libgo / go / encoding / xml / typeinfo.go
index 8e2e450..bbeb28d 100644 (file)
@@ -66,10 +66,14 @@ func getTypeInfo(typ reflect.Type) (*typeInfo, error) {
 
                        // For embedded structs, embed its fields.
                        if f.Anonymous {
-                               if f.Type.Kind() != reflect.Struct {
+                               t := f.Type
+                               if t.Kind() == reflect.Ptr {
+                                       t = t.Elem()
+                               }
+                               if t.Kind() != reflect.Struct {
                                        continue
                                }
-                               inner, err := getTypeInfo(f.Type)
+                               inner, err := getTypeInfo(t)
                                if err != nil {
                                        return nil, err
                                }
@@ -150,6 +154,9 @@ func structFieldInfo(typ reflect.Type, f *reflect.StructField) (*fieldInfo, erro
                        // This will also catch multiple modes in a single field.
                        valid = false
                }
+               if finfo.flags&fMode == fAny {
+                       finfo.flags |= fElement
+               }
                if finfo.flags&fOmitEmpty != 0 && finfo.flags&(fElement|fAttr) == 0 {
                        valid = false
                }
@@ -327,3 +334,22 @@ type TagPathError struct {
 func (e *TagPathError) Error() string {
        return fmt.Sprintf("%s field %q with tag %q conflicts with field %q with tag %q", e.Struct, e.Field1, e.Tag1, e.Field2, e.Tag2)
 }
+
+// value returns v's field value corresponding to finfo.
+// It's equivalent to v.FieldByIndex(finfo.idx), but initializes
+// and dereferences pointers as necessary.
+func (finfo *fieldInfo) value(v reflect.Value) reflect.Value {
+       for i, x := range finfo.idx {
+               if i > 0 {
+                       t := v.Type()
+                       if t.Kind() == reflect.Ptr && t.Elem().Kind() == reflect.Struct {
+                               if v.IsNil() {
+                                       v.Set(reflect.New(v.Type().Elem()))
+                               }
+                               v = v.Elem()
+                       }
+               }
+               v = v.Field(x)
+       }
+       return v
+}