Ejemplo n.º 1
0
func (pp *packageParser) getOrAddPointer(base st.ITypeSymbol) (result *st.PointerTypeSymbol) {

	nameToFind := base.Name()

	//anonymous type
	if base.Name() == st.NO_NAME {
		result = st.MakePointerType(base.Scope(), base)
		if s, ok := base.(*st.StructTypeSymbol); ok {
			result.Fields = s.Fields
		}
		return
	}

	pd, found := 0, false
	if p, ok := base.(*st.PointerTypeSymbol); ok {
		pd = p.Depth()
		nameToFind = p.BaseName()
	}

	var toLookUp *st.SymbolTable
	if base.PackageFrom() == pp.Package || base.PackageFrom() == nil {
		toLookUp = pp.Package.Symbols
	} else {
		toLookUp = base.PackageFrom().Symbols
	}
	// 	if base.Name() == "typesVisitor" {
	// 		fmt.Printf("goap %v and pp is in %v.  toLookUp is from %s\n", base.PackageFrom().AstPackage.Name, pp.Package.AstPackage.Name, toLookUp.Package.AstPackage.Name)
	// 	}

	if result, found = toLookUp.LookUpPointerType(nameToFind, pd+1); found {
		// 		fmt.Printf("Searched Pointer Type %s (%p) ,%d, from package %s\n", nameToFind, result, pd+1, func(p *st.Package) string {
		// 			if p == nil {
		// 				return "nil"
		// 			}
		// 			return p.AstPackage.Name
		// 		}(result.PackageFrom()))
		return
	}

	result = st.MakePointerType(toLookUp, base)
	if s, ok := base.(*st.StructTypeSymbol); ok {
		result.Fields = s.Fields
	}
	// 	fmt.Printf("Adding Pointer Type %s to %s at file of %s\n", result.Name(), func(p *st.Package) string {
	// 		if p == nil {
	// 			return "nil"
	// 		}
	// 		return p.AstPackage.Name
	// 	}(base.PackageFrom()),
	// 		pp.Package.AstPackage.Name)

	toLookUp.AddSymbol(result)
	return
}