Anonymous avatar Anonymous committed 0cc697e

better handling of unnamed scopes and values/types

Comments (0)

Files changed (4)

pkg/cxxtypes/gccxml/ifaces.go

 	kind() cxxtypes.TypeKind
 }
 
+type i_idkind interface {
+	i_id
+	idkind() cxxtypes.IdKind
+}
+
 type i_field interface {
 	i_name
+	idkind() cxxtypes.IdKind
 	kind() cxxtypes.TypeKind
 	typename() string
 	access() cxxtypes.AccessSpecifier

pkg/cxxtypes/gccxml/xmlstructs.go

 
 	// classes and structs
 	for _, v := range x.Classes {
+		v.fixup_name() // side-effects into fixing empty names...
 		patchTemplateName(v)
 		v.Members = strings.TrimSpace(v.Members)
 	}
 	for _, v := range x.Structs {
+		v.fixup_name() // side-effects into fixing empty names...
 		patchTemplateName(v)
 		v.Members = strings.TrimSpace(v.Members)
 	}
 	// 	}
 	// }
 
+	// fields
+	for _, v := range x.Fields {
+		v.fixup_name()
+	}
+
 	// builtins
 	for _, v := range x.FundamentalTypes {
 		alltmpl := false
 	return cxxtypes.TK_ConstantArray
 }
 
+func (x *xmlArray) idkind() cxxtypes.IdKind {
+	return cxxtypes.IK_Typ
+}
+
 func (x *xmlArray) size() uintptr {
 	return str_to_uintptr(x.Size)
 }
 
+func (x *xmlArray) typename() string {
+	return genTypeName(x.Id, gtnCfg{})
+}
+
 type xmlBase struct {
 	Type    string `xml:"type,attr"`
 	Access  string `xml:"access,attr"`
 	return x.Id
 }
 
+func (x *xml_record) fixup_name() {
+	if x.Name == "" && x.Demangled != "" {
+		x.Name = x.Demangled
+	}
+}
+
 func (x *xml_record) name() string {
 	return x.Name
 }
 	return cxxtypes.TK_Record
 }
 
+func (x *xml_record) idkind() cxxtypes.IdKind {
+	return cxxtypes.IK_Typ
+}
+
 func (x *xml_record) typename() string {
 	return genTypeName(x.id(), gtnCfg{})
 }
 	return cxxtypes.TK_FunctionProto
 }
 
+func (x *xmlConstructor) idkind() cxxtypes.IdKind {
+	return cxxtypes.IK_Fct
+}
+
 func (x *xmlConstructor) typename() string {
 	return genTypeName(x.Id, gtnCfg{})
 }
 	return cxxtypes.TK_FunctionProto
 }
 
+func (x *xmlConverter) idkind() cxxtypes.IdKind {
+	return cxxtypes.IK_Fct
+}
+
 func (x *xmlConverter) typename() string {
 	return genTypeName(x.Id, gtnCfg{})
 }
 	return t.(i_name).name()
 }
 
+func (x *xmlCvQualifiedType) typename() string {
+	return genTypeName(x.Id, gtnCfg{})
+}
+
 func (x *xmlCvQualifiedType) set_name(n string) {
 	panic("fixme: can set the name of a cv-qualified type - yet")
 }
 	return t.(i_kind).kind()
 }
 
+func (x *xmlCvQualifiedType) idkind() cxxtypes.IdKind {
+	return cxxtypes.IK_Typ
+}
+
 func (x *xmlCvQualifiedType) size() uintptr {
 	return str_to_uintptr(x.Size)
 }
 	return cxxtypes.TK_FunctionProto
 }
 
+func (x *xmlDestructor) idkind() cxxtypes.IdKind {
+	return cxxtypes.IK_Fct
+}
+
 func (x *xmlDestructor) typename() string {
 	return genTypeName(x.Id, gtnCfg{})
 }
 	return cxxtypes.TK_Enum
 }
 
+func (x *xmlEnumeration) idkind() cxxtypes.IdKind {
+	return cxxtypes.IK_Typ
+}
+
 func (x *xmlEnumeration) typename() string {
 	return genTypeName(x.Id, gtnCfg{})
 }
 	return x.Id
 }
 
+func (x *xmlField) fixup_name() {
+	//TODO: figure out why we get such weirdos...
+	// ex: struct __vmi_class_type_info_pseudo1 
+	//     has a number of unnamed fields
+	if x.Name == "" && x.Demangled == "" {
+		x.Name = "__fake__name__"+x.Id+"__"
+		x.Demangled = x.Name
+	}
+}
+
 func (x *xmlField) name() string {
 	return x.Name
 }
 	return t.(i_kind).kind()
 }
 
+func (x *xmlField) idkind() cxxtypes.IdKind {
+	t := g_ids[x.Type]
+	return t.(i_idkind).idkind()
+}
+
 func (x *xmlField) typename() string {
 	return genTypeName(x.Type, gtnCfg{})
 }
 	x.Name = n
 }
 
+func (x *xmlFunction) typename() string {
+	return genTypeName(x.Id, gtnCfg{})
+}
+
 func (x *xmlFunction) mangled() string {
 	return x.Mangled
 }
 	return cxxtypes.TK_FunctionProto
 }
 
+func (x *xmlFunction) idkind() cxxtypes.IdKind {
+	return cxxtypes.IK_Fct
+}
+
 func (x xmlFunction) String() string {
 	return fmt.Sprintf(`Function{%s, returns=%s, nargs=%d, ellipsis=%s}`,
 		x.Name,
 	return cxxtypes.TK_FunctionProto
 }
 
+func (x *xmlFunctionType) idkind() cxxtypes.IdKind {
+	return cxxtypes.IK_Typ
+}
+
 func (x *xmlFunctionType) name() string {
 	//FIXME - we should perhaps return "id-name (argtype...)"
 	return x.Id
 	panic("cannot set name of a functiontype")
 }
 
+func (x *xmlFunctionType) typename() string {
+	return genTypeName(x.Id, gtnCfg{})
+}
+
 func (x *xmlFunctionType) context() string {
 	return g_globalns_id
 }
 	return g_n2tk[x.name()]
 }
 
+func (x *xmlFundamentalType) idkind() cxxtypes.IdKind {
+	return cxxtypes.IK_Typ
+}
+
 func (x *xmlFundamentalType) size() uintptr {
 	return str_to_uintptr(x.Size)
 }
 	return cxxtypes.TK_FunctionProto
 }
 
+func (x *xmlMethod) idkind() cxxtypes.IdKind {
+	return cxxtypes.IK_Fct
+}
+
 func (x *xmlMethod) typename() string {
 	return genTypeName(x.Id, gtnCfg{})
 }
 	return cxxtypes.TK_FunctionProto
 }
 
+func (x *xmlMethodType) idkind() cxxtypes.IdKind {
+	return cxxtypes.IK_Typ
+}
+
 func (x *xmlMethodType) name() string {
 	return genTypeName(x.id(), gtnCfg{})
 }
 	panic("gccxml: cannot set name on MethodType")
 }
 
+func (x *xmlMethodType) typename() string {
+	return genTypeName(x.Id, gtnCfg{})
+}
+
 type xmlNamespace struct {
 	Attributes string `xml:"attributes,attr"`
 	Context    string `xml:"context,attr"`
 	return x.Demangled
 }
 
+func (x *xmlNamespace) typename() string {
+	return genTypeName(x.Id, gtnCfg{})
+}
+
 func (x *xmlNamespace) set_demangled(n string) {
 	x.Demangled = n
 }
 	x.Name = n
 }
 
+func (x *xmlOperatorFunction) typename() string {
+	return genTypeName(x.Id, gtnCfg{})
+}
+
 func (x *xmlOperatorFunction) mangled() string {
 	return x.Mangled
 }
 	return cxxtypes.TK_FunctionProto
 }
 
+func (x *xmlOperatorFunction) idkind() cxxtypes.IdKind {
+	return cxxtypes.IK_Fct
+}
+
 type xmlOperatorMethod struct {
 	xmlMethod
 }
 
+func (x *xmlOperatorMethod) idkind() cxxtypes.IdKind {
+	return cxxtypes.IK_Fct
+}
+
+
 type xmlPointerType struct {
 	Align      string `xml:"align,attr"`
 	Attributes string `xml:"attributes,attr"` // implied
 	panic("fixme: can set a name for a pointer-type - yet")
 }
 
+func (x *xmlPointerType) typename() string {
+	return genTypeName(x.Id, gtnCfg{})
+}
+
 func (x *xmlPointerType) context() string {
 	t := g_ids[x.Type]
 	return t.(i_context).context()
 	return cxxtypes.TK_Ptr
 }
 
+func (x *xmlPointerType) idkind() cxxtypes.IdKind {
+	return cxxtypes.IK_Typ
+}
+
 func (x *xmlPointerType) size() uintptr {
 	return str_to_uintptr(x.Size)
 }
 	panic("fixme: can set a name for a ref-type - yet")
 }
 
+func (x *xmlReferenceType) typename() string {
+	return genTypeName(x.Id, gtnCfg{})
+}
+
 func (x *xmlReferenceType) context() string {
 	t := g_ids[x.Type]
 	return t.(i_context).context()
 	return cxxtypes.TK_LValueRef
 }
 
+func (x *xmlReferenceType) idkind() cxxtypes.IdKind {
+	return cxxtypes.IK_Typ
+}
+
 func (x *xmlReferenceType) size() uintptr {
 	return str_to_uintptr(x.Size)
 }
 	return cxxtypes.TK_Typedef
 }
 
+func (x *xmlTypedef) idkind() cxxtypes.IdKind {
+	return cxxtypes.IK_Typ
+}
+
 func (x *xmlTypedef) typename() string {
 	return genTypeName(x.Id, gtnCfg{})
 }
 	return cxxtypes.TK_Record
 }
 
+func (x *xmlUnion) idkind() cxxtypes.IdKind {
+	return cxxtypes.IK_Typ
+}
+
 func (x *xmlUnion) typename() string {
 	return genTypeName(x.Id, gtnCfg{})
 }
 	return t.(i_kind).kind()
 }
 
+func (x *xmlVariable) idkind() cxxtypes.IdKind {
+	return cxxtypes.IK_Var
+}
+
 func (x *xmlVariable) typename() string {
 	return genTypeName(x.Type, gtnCfg{})
 }
 
 func genScopeName(id string, cfg gtnCfg) string {
 	s := ""
-	var node i_id
-	// climb the context tree up as long as the embedding context is unnamed
-	for {
-		node = g_ids[id]
-		t, ok := node.(i_context)
-		if ok {
-			id = t.context()
-			node = g_ids[id]
-			tn, ok := node.(i_name)
-			if ok && tn.name() != "" && strings.Index(tn.name(), ".") == -1 {
-				break
-			}
-		} else {
-			break
-		}
+	if t,ok := g_ids[id].(i_context); ok {
+		id = t.context()
+	} else {
+		panic("gccxml: no context for id="+id+"!!")
 	}
+
 	ns := ""
 	if id != "" {
 		ns = genTypeName(id, cfg)
 			}
 			name := genTypeName(tmbr.id(), gtnCfg{})
 			mbr := tmbr.(i_field)
+			mbr_idkind := mbr.idkind()
+			if _, ok := tmbr.(*xmlField); ok{
+				mbr_idkind = cxxtypes.IK_Var
+			}
 			members = append(members,
 				cxxtypes.NewMember(
 					name,
 					mbr.typename(),
+					mbr_idkind,
 					mbr.kind(),
 					mbr.access(),
 					mbr.offset(),
 				cxxtypes.NewMember(
 					n,
 					typ,
+				cxxtypes.IK_Var,
 					cxxtypes.TK_Int,
 					cxxtypes.AS_Public,
 					uintptr(0),

pkg/cxxtypes/types.go

 	if err != nil {
 		return err
 	}
+	for i,_ := range t.Members {
+		mbr := &t.Members[i]
+		if mbr.IsDataMember() {
+			add_id(mbr)
+		}
+	}
 	return nil
 }
 
 	if err != nil {
 		return err
 	}
+	for i,_ := range t.Members {
+		mbr := &t.Members[i]
+		if mbr.IsDataMember() {
+			add_id(mbr)
+		}
+	}
 	return nil
 }
 
 }
 
 // NewMember creates a new member for a struct, class, enum or union
-func NewMember(name string, tn string, kind TypeKind, access AccessSpecifier, offset uintptr, scope string) Member {
+func NewMember(name string, tn string, idkind IdKind, kind TypeKind, access AccessSpecifier, offset uintptr, scope string) Member {
 	mbr := Member{
 		BaseId: BaseId{
 			Name:  name,
-			Kind:  id_kind_from_tk(kind),
+			Kind:  idkind,
 			Scope: scope,
 		},
 		Type:   tn,
 }
 
 func (m *Member) IsDataMember() bool {
-	return !m.IsFunctionMember() && !m.IsEnumMember()
+	return (m.IdKind() == IK_Var)
 }
 
 func (m *Member) IsEnumMember() bool {
-	return m.Kind == TK_Enum
+	return m.IsDataMember() && (m.Kind == TK_Enum)
 }
 
 func (m *Member) IsFunctionMember() bool {
 	return (m.Kind == TK_FunctionProto) ||
-		(m.Kind == TK_FunctionNoProto)
+	 	(m.Kind == TK_FunctionNoProto)
 }
 
 func id_kind_from_tk(tk TypeKind) IdKind {

pkg/wrapper/plugins/cxxgo/cxxgo.go

 	}
 
 	// members
-	for i,_ := range id.Members {
-		if !p.mbr_filter(&id.Members[i]) {
+	for i,mbr := range id.Members {
+		if !p.mbr_filter(&mbr) {
 			continue
 		}
-		mid := cxxtypes.IdByName(id.Member(i).Name)
+		mid := cxxtypes.IdByName(mbr.Name)
+		if mid == nil {
+			fmt.Printf("==[%s]==\n", mbr.Name)
+			fmt.Printf("==dmbr: %v\n", mbr.IsDataMember())
+			fmt.Printf("==fmbr: %v\n", mbr.IsFunctionMember())
+			fmt.Printf("==embr: %v\n", mbr.IsEnumMember())
+			fmt.Printf("==mkind: %v\n", mbr.Kind)
+			fmt.Printf("==mdind: %v\n", mbr.IdKind())
+			return fmt.Errorf("cxxgo: could not retrieve identifier [%s]\n%s", mbr.Name, mbr)
+		}
 		fmt.Printf("--> [%s]...\n", id.Member(i))
 		fmt.Printf("<-- [%s]...\n", mid)
 	}
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.